Re: [Cluster-devel] [gfs2:extents 14/14] fs/gfs2/extents.c:123:23-27: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-elem

2023-10-20 Thread Andrew Price

On 19/10/2023 06:27, Julia Lawall wrote:



-- Forwarded message --
Date: Thu, 19 Oct 2023 05:56:44 +0800
From: kernel test robot 
To: oe-kbu...@lists.linux.dev
Cc: l...@intel.com, Julia Lawall 
Subject: [gfs2:extents 14/14] fs/gfs2/extents.c:123:23-27: WARNING use
 flexible-array member instead
 
(https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-
 and-one-element-arrays)

BCC: l...@intel.com
CC: oe-kbuild-...@lists.linux.dev
CC: cluster-devel@redhat.com


The lkp-tests contact info is out of date. I've opened a PR to fix it at 
https://github.com/intel/lkp-tests/pull/319 but it should probably use 
the latest MAINTAINERS file always. CCing the new gfs2 list.


Thanks,
Andy


TO: Andreas Gruenbacher 

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2.git 
extents
head:   86474c69cac46872bd311318c02fb8e9e25abd10
commit: 86474c69cac46872bd311318c02fb8e9e25abd10 [14/14] gfs2: Add some initial 
extents-based inode code
:: branch date: 9 days ago
:: commit date: 9 days ago
config: x86_64-randconfig-101-20231018 
(https://download.01.org/0day-ci/archive/20231019/202310190541.0impmnl4-...@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: 
(https://download.01.org/0day-ci/archive/20231019/202310190541.0impmnl4-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Reported-by: Julia Lawall 
| Closes: https://lore.kernel.org/r/202310190541.0impmnl4-...@intel.com/

cocci warnings: (new ones prefixed by >>)

fs/gfs2/extents.c:123:23-27: WARNING use flexible-array member instead 
(https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)


vim +123 fs/gfs2/extents.c

86474c69cac468 Andreas Gruenbacher 2021-03-25  115
86474c69cac468 Andreas Gruenbacher 2021-03-25  116  /*
86474c69cac468 Andreas Gruenbacher 2021-03-25  117   * The path components in struct 
gfs2_extent_path are stored in "reverse"
86474c69cac468 Andreas Gruenbacher 2021-03-25  118   * order: the leaf is 
stored first, and when the tree grows at the root,
86474c69cac468 Andreas Gruenbacher 2021-03-25  119   * this happens at the end 
of the array.
86474c69cac468 Andreas Gruenbacher 2021-03-25  120   */
86474c69cac468 Andreas Gruenbacher 2021-03-25  121  struct gfs2_extent_path {
86474c69cac468 Andreas Gruenbacher 2021-03-25  122  unsigned int p_height;
86474c69cac468 Andreas Gruenbacher 2021-03-25 @123  struct gfs2_extent_pc 
p_pc[1];
86474c69cac468 Andreas Gruenbacher 2021-03-25  124  };
86474c69cac468 Andreas Gruenbacher 2021-03-25  125





[Cluster-devel] [ANNOUNCE] cluster-devel@redhat.com list shutdown

2023-10-04 Thread Andrew Price

Hi all,

Following on from the previous notices about the new list replacing 
cluster-devel, this list will shortly be discontinued.


The list archives have been preserved at 
https://lore.kernel.org/cluster-devel/


If you haven't already done so, please subscribe to the new list for 
gfs2 and dlm development, g...@lists.linux.dev, by sending an empty 
message to gfs2+subscr...@lists.linux.dev


Many thanks,
Andy



[Cluster-devel] Reminder: New mailing list for gfs2 and dlm

2023-09-19 Thread Andrew Price

Hi all,

For those of you still reading cluster-devel, please be aware that gfs2 
and dlm development have now moved to g...@lists.linux.dev


Please subscribe to the new list to avoid missing new developments, by 
sending a message to:


  gfs2+subscr...@lists.linux.dev

The new list is hosted at kernel.org. There is more information about it 
here:


   https://subspace.kernel.org/lists.linux.dev.html

Thanks,
Andy



Re: [Cluster-devel] [ANNOUNCE] Goodbye cluster-devel, hello g...@lists.linux.dev

2023-09-06 Thread Andrew Price

On 29/08/2023 18:07, Andrew Price wrote:

Hi all,

As cluster-devel is now only used for gfs2 and dlm development, we will 
be moving them to a new list hosted by kernel.org alongside other Linux 
subsystems' lists. The new list is g...@lists.linux.dev and it will be 
used for both gfs2 and dlm development.


The Linux MAINTAINERS file and other references will be updated shortly 
to reflect the change. Information about the list hosting can be found 
here:


Updates to the MAINTAINERS file have now been merged into mainline so 
g...@lists.linux.dev is now the official mailing list for gfs2 and dlm 
development.


(CC+ linux-fsdevel for awareness.)

Thanks,
Andy



https://subspace.kernel.org/lists.linux.dev.html

To subscribe, send an email (the subject and body doesn't matter) to:

Subscribe:   gfs2+subscr...@lists.linux.dev
Unsubscribe: gfs2+unsubscr...@lists.linux.dev

If you prefer, the list can also be read via NNTP at:

nntp://nntp.lore.kernel.org/dev.linux.lists.gfs2

The archives can be found here:

https://lore.kernel.org/gfs2/

and filters can use the "List-Id: " header.

Thanks,
Andy




[Cluster-devel] [PATCH 1/2] MAINTAINERS: Update gfs2 mailing list

2023-08-31 Thread Andrew Price
Signed-off-by: Andrew Price 
---
 MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4b8d634f3a4e..caae31fb9741 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8725,7 +8725,7 @@ F:scripts/get_maintainer.pl
 GFS2 FILE SYSTEM
 M: Bob Peterson 
 M: Andreas Gruenbacher 
-L: cluster-devel@redhat.com
+L: g...@lists.linux.dev
 S: Supported
 B: 
https://bugzilla.kernel.org/enter_bug.cgi?product=File%20System=gfs2
 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2.git
-- 
2.41.0



[Cluster-devel] [PATCH 2/2] MAINTAINERS: Update dlm mailing list

2023-08-31 Thread Andrew Price
The new gfs2@ list will also be used for dlm development.

Signed-off-by: Andrew Price 
---
 MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index caae31fb9741..946fcf6c8d77 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6093,7 +6093,7 @@ F:include/video/udlfb.h
 DISTRIBUTED LOCK MANAGER (DLM)
 M: Christine Caulfield 
 M: David Teigland 
-L: cluster-devel@redhat.com
+L: g...@lists.linux.dev
 S: Supported
 W: http://sources.redhat.com/cluster/
 T: git git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm.git
-- 
2.41.0



[Cluster-devel] [ANNOUNCE] Goodbye cluster-devel, hello g...@lists.linux.dev

2023-08-29 Thread Andrew Price

Hi all,

As cluster-devel is now only used for gfs2 and dlm development, we will 
be moving them to a new list hosted by kernel.org alongside other Linux 
subsystems' lists. The new list is g...@lists.linux.dev and it will be 
used for both gfs2 and dlm development.


The Linux MAINTAINERS file and other references will be updated shortly 
to reflect the change. Information about the list hosting can be found here:


https://subspace.kernel.org/lists.linux.dev.html

To subscribe, send an email (the subject and body doesn't matter) to:

Subscribe:   gfs2+subscr...@lists.linux.dev
Unsubscribe: gfs2+unsubscr...@lists.linux.dev

If you prefer, the list can also be read via NNTP at:

nntp://nntp.lore.kernel.org/dev.linux.lists.gfs2

The archives can be found here:

https://lore.kernel.org/gfs2/

and filters can use the "List-Id: " header.

Thanks,
Andy



Re: [Cluster-devel] [PATCH 6/8] gfs2: Rework freeze / thaw logic

2023-06-13 Thread Andrew Price

On 12/06/2023 17:33, Andreas Gruenbacher wrote:

So far, at mount time, gfs2 would take the freeze glock in shared mode
and then immediately drop it again, turning it into a cached glock that
can be reclaimed at any time.  To freeze the filesystem cluster-wide,
the node initiating the freeze would take the freeze glock in exclusive
mode, which would cause the freeze glock's freeze_go_sync() callback to
run on each node.  There, gfs2 would freeze the filesystem and schedule
gfs2_freeze_func() to run.  gfs2_freeze_func() would re-acquire the
freeze glock in shared mode, thaw the filesystem, and drop the freeze
glock again.  The initiating node would keep the freeze glock held in
exclusive mode.  To thaw the filesystem, the initiating node would drop
the freeze glock again, which would allow gfs2_freeze_func() to resume
on all nodes, leaving the filesystem in the thawed state.

It turns out that in freeze_go_sync(), we cannot reliably and safely
freeze the filesystem.  This is primarily because the final unmount of a
filesystem takes a write lock on the s_umount rw semaphore before
calling into gfs2_put_super(), and freeze_go_sync() needs to call
freeze_super() which also takes a write lock on the same semaphore,
causing a deadlock.  We could work around this by trying to take an
active reference on the super block first, which would prevent unmount
from running at the same time.  But that can fail, and freeze_go_sync()
isn't actually allowed to fail.

To get around this, this patch changes the freeze glock locking scheme
as follows:

At mount time, each node takes the freeze glock in shared mode.  To
freeze a filesystem, the initiating node first freezes the filesystem
locally and then drops and re-acquires the freeze glock in exclusive
mode.  All other nodes notice that there is contention on the freeze
glock in their go_callback callbacks, and they schedule
gfs2_freeze_func() to run.  There, they freeze the filesystem locally
and drop and re-acquire the freeze glock before re-thawing the
filesystem.  This is happening outside of the glock state engine, so
there, we are allowed to fail.

 From a cluster point of view, taking and immediately dropping a glock is
indistinguishable from taking the glock and only dropping it upon
contention, so this new scheme is compatible with the old one.


Nice!


Signed-off-by: Andreas Gruenbacher 
---
  fs/gfs2/glops.c  |  52 +
  fs/gfs2/log.c|   2 -
  fs/gfs2/ops_fstype.c |   5 +-
  fs/gfs2/recovery.c   |  24 +++---
  fs/gfs2/super.c  | 179 ++-
  fs/gfs2/super.h  |   1 +
  fs/gfs2/util.c   |  32 +++-
  7 files changed, 185 insertions(+), 110 deletions(-)

diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index 01d433ed6ce7..7c48c7afd6a4 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -561,47 +561,33 @@ static void inode_go_dump(struct seq_file *seq, struct 
gfs2_glock *gl,
  }
  
  /**

- * freeze_go_sync - promote/demote the freeze glock
+ * freeze_go_callback - A cluster node is requesting a freeze
   * @gl: the glock
+ * @remote: true if this came from a different cluster node
   */
  
-static int freeze_go_sync(struct gfs2_glock *gl)

+static void freeze_go_callback(struct gfs2_glock *gl, bool remote)
  {
-   int error = 0;
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
+   struct super_block *sb = sdp->sd_vfs;
+
+   if (!remote ||
+   gl->gl_state != LM_ST_SHARED ||
+   gl->gl_demote_state != LM_ST_UNLOCKED)
+   return;
  
  	/*

-* We need to check gl_state == LM_ST_SHARED here and not gl_req ==
-* LM_ST_EXCLUSIVE. That's because when any node does a freeze,
-* all the nodes should have the freeze glock in SH mode and they all
-* call do_xmote: One for EX and the others for UN. They ALL must
-* freeze locally, and they ALL must queue freeze work. The freeze_work
-* calls freeze_func, which tries to reacquire the freeze glock in SH,
-* effectively waiting for the thaw on the node who holds it in EX.
-* Once thawed, the work func acquires the freeze glock in
-* SH and everybody goes back to thawed.
+* Try to get an active super block reference to prevent racing with
+* unmount (see trylock_super()).  But note that unmount isn't the only
+* place where a write lock on s_umount is taken, and we can fail here
+* because of things like remount as well.
 */
-   if (gl->gl_state == LM_ST_SHARED && !gfs2_withdrawn(sdp) &&
-   !test_bit(SDF_NORECOVERY, >sd_flags)) {
-   atomic_set(>sd_freeze_state, SFS_STARTING_FREEZE);
-   error = freeze_super(sdp->sd_vfs);
-   if (error) {
-   fs_info(sdp, "GFS2: couldn't freeze filesystem: %d\n",
-   error);
-   if (gfs2_withdrawn(sdp)) {
-   

[Cluster-devel] [RFC PATCH] fsck.gfs2: Fail on LVM PV detection

2023-06-06 Thread Andrew Price
If fsck.gfs2 is run against an LVM PV it will try its best to repair it
as a gfs2 fs. This is unlikely the best course of action as it's more
likely that the user executed fsck.gfs2 against the PV after stopping
the cluster (including the LVM activation resources).

In this situation other fscks try to look up backup superblocks before
failing but gfs2 does not keep backup superblocks so the safest thing to
do is fail with an operational error code when an LVM PV is detected.

A test is included that restores a PV signature to the test volume
before attempting to run fsck.gfs2 on it.

Signed-off-by: Andrew Price 
---
 gfs2/fsck/Makefile.am  |  5 -
 gfs2/fsck/initialize.c | 30 ++
 tests/Makefile.am  |  3 ++-
 tests/atlocal.in   |  1 +
 tests/fsck.at  |  7 +++
 tests/pv_sig.xxd   | 12 
 6 files changed, 56 insertions(+), 2 deletions(-)
 create mode 100644 tests/pv_sig.xxd

diff --git a/gfs2/fsck/Makefile.am b/gfs2/fsck/Makefile.am
index 405aabe1..543057b1 100644
--- a/gfs2/fsck/Makefile.am
+++ b/gfs2/fsck/Makefile.am
@@ -32,10 +32,13 @@ fsck_gfs2_SOURCES = \
util.c
 
 fsck_gfs2_CPPFLAGS = $(AM_CPPFLAGS)
-fsck_gfs2_CFLAGS = $(AM_CFLAGS)
+fsck_gfs2_CFLAGS = \
+   $(AM_CFLAGS) \
+   $(blkid_CFLAGS)
 fsck_gfs2_LDADD = \
$(top_builddir)/gfs2/libgfs2/libgfs2.la \
$(LTLIBINTL) \
+   $(blkid_LIBS) \
$(uuid_LIBS)
 
 if HAVE_CHECK
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index 62fb6107..8679dee9 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define _(String) gettext(String)
 
@@ -1555,6 +1556,33 @@ static int init_rindex(struct fsck_cx *cx)
return 0;
 }
 
+static int is_lvm_member(struct fsck_cx *cx)
+{
+   char lvm_member[] = "LVM2_member";
+   char *filter[] = {lvm_member, NULL};
+   int fd = cx->sdp->device_fd;
+   int ret;
+
+   blkid_probe pr = blkid_new_probe();
+   if (pr == NULL || blkid_probe_set_device(pr, fd, 0, 0) != 0
+  || blkid_probe_filter_superblocks_type(pr,
+  BLKID_FLTR_ONLYIN, filter)) {
+   log_err(_("Failed to create probe for %s\n"), cx->opts->device);
+   return -1;
+   }
+   ret = blkid_do_fullprobe(pr);
+   blkid_free_probe(pr);
+   if (ret == -1) {
+   log_err(_("Failed to probe device %s\n"), cx->opts->device);
+   return -1;
+   }
+   if (ret == 1)
+   return 0;
+   log_err(_("%s looks like an LVM physical volume.\n"), cx->opts->device);
+   log_err(_("fsck.gfs2 cannot check this device.\n"));
+   return 1;
+}
+
 /**
  * initialize - initialize superblock pointer
  *
@@ -1602,6 +1630,8 @@ int initialize(struct fsck_cx *cx, int *all_clean)
   from themselves. */
was_mounted_ro = 1;
}
+   if (is_lvm_member(cx)) /* True or error */
+   return FSCK_ERROR;
 
if (lgfs2_get_dev_info(sdp->device_fd, >dinfo)) {
perror(cx->opts->device);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 27a643a2..f8538942 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -8,7 +8,8 @@ EXTRA_DIST = \
$(TESTSCRIPTS) \
package.m4 \
gfs2-utils.spec.in \
-   atlocal.in
+   atlocal.in \
+   pv_sig.xxd
 
 DISTCLEANFILES = \
atlocal \
diff --git a/tests/atlocal.in b/tests/atlocal.in
index eed58b10..769b43cb 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -1,3 +1,4 @@
+GFS_TESTS_DIR="${abs_top_builddir}/tests"
 GFS_TGT="@testvol@"
 GFS_TGT_SZ=20
 GFS_MKFS="mkfs.gfs2 -O -D"
diff --git a/tests/fsck.at b/tests/fsck.at
index 538d41ad..bc8a6d1c 100644
--- a/tests/fsck.at
+++ b/tests/fsck.at
@@ -89,3 +89,10 @@ AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
 AT_CHECK([mkfs.gfs2 -O -p lock_nolock -o format=1802 ${GFS_TGT}], 0, [ignore], 
[ignore])
 AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
 AT_CLEANUP
+
+AT_SETUP([Detect LVM PV])
+AT_KEYWORDS(fsck.gfs2 fsck)
+GFS_TGT_REGEN
+AT_CHECK([xxd -r ${GFS_TESTS_DIR}/pv_sig.xxd ${GFS_TGT}], 0, [ignore], 
[ignore])
+AT_CHECK([fsck.gfs2 -y ${GFS_TGT}], 8, [ignore], [ignore])
+AT_CLEANUP
diff --git a/tests/pv_sig.xxd b/tests/pv_sig.xxd
new file mode 100644
index ..dc00faed
--- /dev/null
+++ b/tests/pv_sig.xxd
@@ -0,0 +1,12 @@
+0200: 4c41 4245 4c4f 4e45 0100     LABELONE
+0210: 22fb 8643 2000  4c56 4d32 2030 3031  "..C ...LVM2 001
+0220: 5061 6e73 586a 5632 6847 3641 7679 3854  PansXjV2hG6Avy8T
+0230: 5739 3236 786e 516a 5956 4154 5258 734d  W926xnQjYVATRXsM
+0240:  0040 0100   1000    ...@
+0250:       0

Re: [Cluster-devel] [PATCH] gfs2: ignore rindex_update failure in dinode_dealloc

2023-05-05 Thread Andrew Price

Hi Bob,

On 04/05/2023 18:43, Bob Peterson wrote:

Before this patch function gfs2_dinode_dealloc would abort if it got a
bad return code from gfs2_rindex_update. The problem is that it left the
dinode in the unlinked (not free) state, which meant subsequent fsck
would clean it up and flag an error. That meant some of our QE tests
would fail.


As I understand it the test is an interrupted rename loop workload and 
gfs2_grow at the same time, and the bad return code is -EINTR, right?



The sole purpose of gfs2_rindex_update, in this code path, is to read in
any newer rgrps added by gfs2_grow. But since this is a delete operation
it won't actually use any of those new rgrps. It can really only twiddle
the bits from "Unlinked" to "Free" in an existing rgrp. Therefore the
error should not prevent the transition from unlinked to free.

This patch makes gfs2_dinode_dealloc ignore the bad return code and
proceed with freeing the dinode so the QE tests will not be tripped up.


Is it really ok to ignore all potential errors here? I wonder if it 
should just ignore -EINTR (or whichever error the test produces) so that 
it can still fail well for errors like -EIO.


Cheers,
Andy



Signed-off-by: Bob Peterson 
---
  fs/gfs2/super.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index d3b5c6278be0..1f23d7845123 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -1131,9 +1131,7 @@ static int gfs2_dinode_dealloc(struct gfs2_inode *ip)
return -EIO;
}
  
-	error = gfs2_rindex_update(sdp);

-   if (error)
-   return error;
+   gfs2_rindex_update(sdp);




  
  	error = gfs2_quota_hold(ip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE);

if (error)




[Cluster-devel] gfs2-utils 3.5.1 released

2023-04-11 Thread Andrew Price
gfs2-utils contains the tools needed to create, check, modify and 
inspect gfs2 filesystems along with support scripts needed on every gfs2 
cluster node.


This minor release includes fixes for a small number of issues 
discovered in 3.5.0, including test failures that occur on 32-bit 
architectures and when compiling with specific gcc versions with 
link-time optimization enabled.


The full git shortlog is below.

Release tarballs and signed checksums can be found here:

https://releases.pagure.org/gfs2-utils/

Direct link for convenience:

https://releases.pagure.org/gfs2-utils/gfs2-utils-3.5.1.tar.gz

Please report bugs to the cluster-devel@redhat.com mailing list or at:

https://bugzilla.kernel.org/enter_bug.cgi?product=File%20System=gfs2

Patches or pull requests can be sent to the same list or submitted on 
Pagure:


https://pagure.io/gfs2-utils

Thanks,
Andy

gfs2-utils changes since 3.5.0:

Andrew Price (9):
  Update version for development
  gfs2_edit: Fix savemeta test failures in 32-bit environments
  gfs2_jadd: Fix format string warnings on 32-bit
  libgfs2: Fix strict-aliasing warning in lgfs2_rgrp_bitbuf_alloc
  gfs2_convert: Clean up strict-aliasing warnings
  Re-enable -Wstrict-aliasing
  libgfs2: Separate gfs and gfs2 code in lgfs2_sb_out()
  Don't use char arrays as temporary buffers
  Prepare for version 3.5.1



[Cluster-devel] [PATCH 3/3] gfs2: Remove ghs[] from gfs2_unlink

2023-03-14 Thread Andrew Price
Replace the 3-item array with three variables for readability.

Signed-off-by: Andrew Price 
---
 fs/gfs2/inode.c | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 9850267b9951..17c994a0c0d0 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -1143,7 +1143,7 @@ static int gfs2_unlink(struct inode *dir, struct dentry 
*dentry)
struct gfs2_sbd *sdp = GFS2_SB(dir);
struct inode *inode = d_inode(dentry);
struct gfs2_inode *ip = GFS2_I(inode);
-   struct gfs2_holder ghs[3];
+   struct gfs2_holder d_gh, r_gh, gh;
struct gfs2_rgrpd *rgd;
int error;
 
@@ -1153,21 +1153,21 @@ static int gfs2_unlink(struct inode *dir, struct dentry 
*dentry)
 
error = -EROFS;
 
-   gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
-   gfs2_holder_init(ip->i_gl,  LM_ST_EXCLUSIVE, 0, ghs + 1);
+   gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, _gh);
+   gfs2_holder_init(ip->i_gl,  LM_ST_EXCLUSIVE, 0, );
 
rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr, 1);
if (!rgd)
goto out_inodes;
 
-   gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, LM_FLAG_NODE_SCOPE, ghs + 
2);
+   gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, LM_FLAG_NODE_SCOPE, 
_gh);
 
 
-   error = gfs2_glock_nq(ghs); /* parent */
+   error = gfs2_glock_nq(_gh);
if (error)
goto out_parent;
 
-   error = gfs2_glock_nq(ghs + 1); /* child */
+   error = gfs2_glock_nq();
if (error)
goto out_child;
 
@@ -1181,7 +1181,7 @@ static int gfs2_unlink(struct inode *dir, struct dentry 
*dentry)
goto out_rgrp;
}
 
-   error = gfs2_glock_nq(ghs + 2); /* rgrp */
+   error = gfs2_glock_nq(_gh); /* rgrp */
if (error)
goto out_rgrp;
 
@@ -1197,16 +1197,16 @@ static int gfs2_unlink(struct inode *dir, struct dentry 
*dentry)
gfs2_trans_end(sdp);
 
 out_gunlock:
-   gfs2_glock_dq(ghs + 2);
+   gfs2_glock_dq(_gh);
 out_rgrp:
-   gfs2_glock_dq(ghs + 1);
+   gfs2_glock_dq();
 out_child:
-   gfs2_glock_dq(ghs);
+   gfs2_glock_dq(_gh);
 out_parent:
-   gfs2_holder_uninit(ghs + 2);
+   gfs2_holder_uninit(_gh);
 out_inodes:
-   gfs2_holder_uninit(ghs + 1);
-   gfs2_holder_uninit(ghs);
+   gfs2_holder_uninit();
+   gfs2_holder_uninit(_gh);
return error;
 }
 
-- 
2.39.2



[Cluster-devel] [PATCH 1/3] gfs2: Remove duplicate i_nlink check from gfs2_link()

2023-03-14 Thread Andrew Price
The duplication is:

struct gfs2_inode *ip = GFS2_I(inode);
[...]
error = -ENOENT;
if (inode->i_nlink == 0)
goto out_gunlock;
[...]
error = -EINVAL;
if (!ip->i_inode.i_nlink)
goto out_gunlock;

The second check is removed. ENOENT is the correct error code for
attempts to link a deleted inode (ref: link(2)).

If we support O_TMPFILE in future the check will need to be updated with
an exception for inodes flagged I_LINKABLE so sorting out this
duplication now will make it a slightly cleaner change.

Signed-off-by: Andrew Price 
---
 fs/gfs2/inode.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 1291b5ee3584..79eef9a0ebfc 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -992,9 +992,6 @@ static int gfs2_link(struct dentry *old_dentry, struct 
inode *dir,
error = -EPERM;
if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
goto out_gunlock;
-   error = -EINVAL;
-   if (!ip->i_inode.i_nlink)
-   goto out_gunlock;
error = -EMLINK;
if (ip->i_inode.i_nlink == (u32)-1)
goto out_gunlock;
-- 
2.39.2



[Cluster-devel] [PATCH 2/3] gfs2: Remove ghs[] from gfs2_link

2023-03-14 Thread Andrew Price
Replace the 2-item array with two variables for readability.

Signed-off-by: Andrew Price 
---
 fs/gfs2/inode.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 79eef9a0ebfc..9850267b9951 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -941,7 +941,7 @@ static int gfs2_link(struct dentry *old_dentry, struct 
inode *dir,
struct gfs2_sbd *sdp = GFS2_SB(dir);
struct inode *inode = d_inode(old_dentry);
struct gfs2_inode *ip = GFS2_I(inode);
-   struct gfs2_holder ghs[2];
+   struct gfs2_holder d_gh, gh;
struct buffer_head *dibh;
struct gfs2_diradd da = { .bh = NULL, .save_loc = 1, };
int error;
@@ -953,14 +953,14 @@ static int gfs2_link(struct dentry *old_dentry, struct 
inode *dir,
if (error)
return error;
 
-   gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
-   gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
+   gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, _gh);
+   gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, );
 
-   error = gfs2_glock_nq(ghs); /* parent */
+   error = gfs2_glock_nq(_gh);
if (error)
goto out_parent;
 
-   error = gfs2_glock_nq(ghs + 1); /* child */
+   error = gfs2_glock_nq();
if (error)
goto out_child;
 
@@ -1046,13 +1046,13 @@ static int gfs2_link(struct dentry *old_dentry, struct 
inode *dir,
gfs2_quota_unlock(dip);
 out_gunlock:
gfs2_dir_no_add();
-   gfs2_glock_dq(ghs + 1);
+   gfs2_glock_dq();
 out_child:
-   gfs2_glock_dq(ghs);
+   gfs2_glock_dq(_gh);
 out_parent:
gfs2_qa_put(dip);
-   gfs2_holder_uninit(ghs);
-   gfs2_holder_uninit(ghs + 1);
+   gfs2_holder_uninit(_gh);
+   gfs2_holder_uninit();
return error;
 }
 
-- 
2.39.2



[Cluster-devel] [PATCH 0/3] gfs2_(un)link cleanups

2023-03-14 Thread Andrew Price
Some trivial cleanups from my O_TMPFILE branch. That work isn't ready
yet but there was no reason not to send these patches.

Andy

Andrew Price (3):
  gfs2: Remove duplicate i_nlink check from gfs2_link()
  gfs2: Remove ghs[] from gfs2_link
  gfs2: Remove ghs[] from gfs2_unlink

 fs/gfs2/inode.c | 47 ++-
 1 file changed, 22 insertions(+), 25 deletions(-)

-- 
2.39.2



Re: [Cluster-devel] [ClusterLabs] gfs2-utils 3.5.0 released

2023-02-13 Thread Andrew Price

On 13/02/2023 09:58, Andrew Price wrote:

On 11/02/2023 17:16, Valentin Vidić wrote:

On Thu, Feb 09, 2023 at 01:12:58PM +, Andrew Price wrote:
gfs2-utils contains the tools needed to create, check, modify and 
inspect

gfs2 filesystems along with support scripts needed on every gfs2 cluster
node.


Hi,

Some tests seem to be failing for the new version in Debian:

gfs2_edit tests

  37: Save/restoremeta, defaults  FAILED (edit.at:14)
  38: Save/restoremeta, no compression    FAILED (edit.at:24)
  39: Save/restoremeta, min. block size   FAILED (edit.at:34)
  40: Save/restoremeta, 4 journals    FAILED (edit.at:44)
  41: Save/restoremeta, min. block size, 4 journals   FAILED (edit.at:54)
  42: Save metadata to /dev/null  ok

It seems this is all on 32-bit architectures, more info here:

https://buildd.debian.org/status/fetch.php?pkg=gfs2-utils=armel=3.5.0-1=1676127480=0
https://buildd.debian.org/status/fetch.php?pkg=gfs2-utils=armhf=3.5.0-1=1676127632=0
https://buildd.debian.org/status/fetch.php?pkg=gfs2-utils=i386=3.5.0-1=1676127477=0
https://buildd.debian.org/status/fetch.php?pkg=gfs2-utils=mipsel=3.5.0-1=1676130593=0

Can you check?



The smoking gun is

     "stderr:
     Error: File system is too small to restore this metadata.
     File system is 524287 blocks. Restore block = 537439"

It's caused by size_t being used for a variable relating to file size 
and it's too small in 32-bit environments.


It should be fixed by this commit: 
https://pagure.io/fork/andyp/gfs2-utils/c/a3f3aadc789f214cd24606808f5d8a6608e10219


It's waiting for the CI queue to flush after last week's outage but it 
should be in main shortly.


It's now in main: https://pagure.io/gfs2-utils/c/a3f3aadc

Andy

I doubt we have any users on 32-bit architectures but perhaps we can get 
a 32-bit test runner added to the CI pool to prevent these issues 
slipping through anyway.


Are you happy to carry the patch or do you think this is worth a 3.5.1?

Thanks,
Andy




Re: [Cluster-devel] [ClusterLabs] gfs2-utils 3.5.0 released

2023-02-13 Thread Andrew Price

On 11/02/2023 17:16, Valentin Vidić wrote:

On Thu, Feb 09, 2023 at 01:12:58PM +, Andrew Price wrote:

gfs2-utils contains the tools needed to create, check, modify and inspect
gfs2 filesystems along with support scripts needed on every gfs2 cluster
node.


Hi,

Some tests seem to be failing for the new version in Debian:

gfs2_edit tests

  37: Save/restoremeta, defaults  FAILED (edit.at:14)
  38: Save/restoremeta, no compressionFAILED (edit.at:24)
  39: Save/restoremeta, min. block size   FAILED (edit.at:34)
  40: Save/restoremeta, 4 journalsFAILED (edit.at:44)
  41: Save/restoremeta, min. block size, 4 journals   FAILED (edit.at:54)
  42: Save metadata to /dev/null  ok

It seems this is all on 32-bit architectures, more info here:

https://buildd.debian.org/status/fetch.php?pkg=gfs2-utils=armel=3.5.0-1=1676127480=0
https://buildd.debian.org/status/fetch.php?pkg=gfs2-utils=armhf=3.5.0-1=1676127632=0
https://buildd.debian.org/status/fetch.php?pkg=gfs2-utils=i386=3.5.0-1=1676127477=0
https://buildd.debian.org/status/fetch.php?pkg=gfs2-utils=mipsel=3.5.0-1=1676130593=0

Can you check?



The smoking gun is

"stderr:
Error: File system is too small to restore this metadata.
File system is 524287 blocks. Restore block = 537439"

It's caused by size_t being used for a variable relating to file size 
and it's too small in 32-bit environments.


It should be fixed by this commit: 
https://pagure.io/fork/andyp/gfs2-utils/c/a3f3aadc789f214cd24606808f5d8a6608e10219


It's waiting for the CI queue to flush after last week's outage but it 
should be in main shortly.


I doubt we have any users on 32-bit architectures but perhaps we can get 
a 32-bit test runner added to the CI pool to prevent these issues 
slipping through anyway.


Are you happy to carry the patch or do you think this is worth a 3.5.1?

Thanks,
Andy



[Cluster-devel] gfs2-utils 3.5.0 released

2023-02-09 Thread Andrew Price
gfs2-utils contains the tools needed to create, check, modify and 
inspect gfs2 filesystems along with support scripts needed on every gfs2 
cluster node.


The main themes in this release are improved testability and test 
coverage, with a number of bug fixes and a couple of new features thrown 
in too.


Some highlights visible to users and packagers:

- mkfs.gfs2 now has a -U option to provide your own UUID (added to 
support idempotent Ansible playbooks)

- gfs2_jadd now creates journals much faster
- The bzip2 configure check has been fixed to work on distros other than 
the Fedora family (which ship their own pkg-config file)

- Man pages have been improved

We now have CI testing enabled for gfs2-utils (thanks, Fabio!) which 
means that pull requests will be automatically tested across multiple 
distros and architectures. Static analysis will also now be more useful 
as the results are much less cluttered with false-positives. This all 
helps to ramp up the quality of the utils over time as we continue to 
add support for new gfs2 features.


There are also portability improvements included in this release which 
mean that building gfs2-utils against a non-glibc libc should not 
require much patching (probably just an rpmatch() replacement).


The full git shortlog is below.

The release tarballs and signed checksums can be found here:

https://releases.pagure.org/gfs2-utils/

Direct link for convenience:

https://releases.pagure.org/gfs2-utils/gfs2-utils-3.5.0.tar.gz

Please report bugs to the cluster-devel@redhat.com mailing list or at:

https://bugzilla.kernel.org/enter_bug.cgi?product=File%20System=gfs2

Patches or pull requests can be sent to the same list or submitted on 
Pagure:


https://pagure.io/gfs2-utils

Thanks,
Andy

gfs2-utils changes since 3.4.1:

Andreas Gruenbacher (7):
  fsck.gfs2: Clean up metawalk_check_data and undo_check_data 
argument passing

  fsck.gfs2: Minor data type cleanups
  fsck.gfs2: More flexible metalist handling in check_metatree
  fsck.gfs2: Move struct error_block into metawalk.c
  fsck.gfs2: Fix some endianness annotations
  fsck.gfs2: Factor out error handling in metawalk_check_data
  fsck.gfs2: Convert enum values to upper-case

Andrew Price (255):
  Update version string for dev
  gfs2_jadd: Use fallocate to preallocate journals
  gfs2_jadd: Don't fsync after each block written
  libgfs2: Move gfs1_ri_update() into gfs2_convert
  gfs2_convert: Remove fd parameter from gfs1_ri_update
  libgfs2: Fold __ri_update into ri_update
  libgfs2: Move ri_update() into fsck.gfs2
  libgfs2: Clean up rindex_read()
  Update some variable names for consistency
  libgfs2: Implement meta.c checks as unit tests
  libgfs2: Move build_rgrps into fsck.gfs2
  libgfs2: Remove fs_geometry.c
  libgfs2: Replace lgfs2_rgrps_root() with lgfs2_attach_rgrps()
  fsck.gfs2: Update an inaccessible web address
  libgfs2: Move block_list.c into fsck.gfs2
  fsck.gfs2: Refactor fetch_rgrps()
  fsck.gfs2: Call rindex_read() outside of ri_update()
  fsck.gfs2: Rename ri_update to read_rgrps
  fsck.gfs2: Fix bounds check in find_next_rgrp_dist()
  fsck.gfs2: Improve rindex consistency check
  configure: Don't define _FORTIFY_SOURCE for gcov builds
  Import linux/gfs2_ondisk.h
  Remove HAS_UUID conditionals
  Remove GFS2_HAS_LEAF_HINTS conditionals
  Remove GFS2_HAS_DE_RAHEAD/COOKIE conditionals
  Remove GFS2_HAS_RG_SKIP conditionals
  Remove GFS2_HAS_RG_RI_FIELDS conditionals
  Remove GFS2_HAS_LH_V2 conditionals
  Use PRI* when printing gfs2 structures
  Remove gfs2/include/linux_endian.h
  libgfs2: Add __force tags to endianness conversion macros
  fsck.gfs2: Fix declaration mismatch for invalidate_*
  Include asm/types.h in our linux/types.h
  libgfs2: Provide macros for printing on-disk fields
  libgfs2: Add a function for printing on-disk meta headers
  libgfs2: Expect big-endian data when printing log descriptors
  libgfs2: Remove gfs2_log_descriptor_{in,out}
  libgfs2: Remove gfs2_quota_change_{in,out}
  libgfs2: Remove gfs2_statfs_change_{in,out}
  libgfs2: Remove gfs2_ea_header_in
  libgfs2: Convert gfs2_leaf_print to accept big-endian data
  libgfs2: Remove gfs2_quota_{in,out}
  Convert rgrp printing functions to expect big-endian data
  libgfs2: Convert gfs2_sb_print to expect big-endian data
  gfs2_edit: Convert superblock printing to expect big-endian
  gfs2_edit: Store big-endian data in the global dinode
  libgfs2: Don't use on-disk structs with cpu-endian data in 
__init_dinode

  libgfs2: Fix endianness mismatches for struct gfs2_log_header
  gfs2_edit: Clean up display_gfs2()
  libgfs2: Add a cpu-endian log header struct
  libgfs2: Remove gfs2_dinode_print()
  libgfs2: Remove i_di from struct gfs2_inode
  libgfs2: Remove big-endian structs from

[Cluster-devel] [PATCH 0/6] gfs2-utils: Cleanups and fsck.gfs2 fixes

2023-01-30 Thread Andrew Price
This set is mainly cleanups but patches 5 and 6 are small fixes for
fsck.gfs2 which I would like to draw attention to.

PR is https://pagure.io/gfs2-utils/pull-request/14 awaiting CI testing
should you prefer to comment there.

Andy

Andrew Price (6):
  libgfs2: Return the inode from lgfs2_lookupi()
  libgfs2: Remove lgfs2_gfs_createi()
  libgfs2: Reorganise lgfs2_createi()
  fsck.gfs2: Remove de variable from dirref_find()
  fsck.gfs2: Fix wrong entry used in dentry comparison
  fsck.gfs2: fix_hashtable: Decrement i_blocks when freeing leaf blocks

 gfs2/convert/gfs2_convert.c |   7 +--
 gfs2/edit/hexedit.c |   2 +-
 gfs2/fsck/fs_recovery.c |  14 ++---
 gfs2/fsck/initialize.c  |  18 +++---
 gfs2/fsck/lost_n_found.c|   6 +-
 gfs2/fsck/pass2.c   |  22 +++
 gfs2/glocktop/glocktop.c|   6 +-
 gfs2/libgfs2/check_fs_ops.c |  18 +++---
 gfs2/libgfs2/fs_ops.c   | 121 +++-
 gfs2/libgfs2/gfs2l.c|   2 +-
 gfs2/libgfs2/lang.c |  10 +--
 gfs2/libgfs2/libgfs2.h  |   6 +-
 tests/nukerg.c  |   2 +-
 13 files changed, 113 insertions(+), 121 deletions(-)

-- 
2.39.0



[Cluster-devel] [PATCH 4/6] fsck.gfs2: Remove de variable from dirref_find()

2023-01-30 Thread Andrew Price
It always points to 'dentry' so it can be replaced in all uses.

Signed-off-by: Andrew Price 
---
 gfs2/fsck/pass2.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 0c2e0146..002bf2cb 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -621,18 +621,17 @@ static int dirref_find(struct fsck_cx *cx, struct 
lgfs2_inode *ip, struct gfs2_d
/* the metawalk_fxn's private field must be set to the dentry
 * block we want to clear */
struct lgfs2_inum *entry = private;
-   struct lgfs2_dirent dentry, *de;
+   struct lgfs2_dirent dentry;
char fn[MAX_FILENAME];
 
memset(, 0, sizeof(dentry));
lgfs2_dirent_in(, dent);
-   de = 
 
-   if (de->dr_inum.in_addr != entry->in_addr) {
+   if (dentry.dr_inum.in_addr != entry->in_addr) {
(*count)++;
return 0;
}
-   if (de->dr_inum.in_formal_ino == 
be64_to_cpu(dent->de_inum.no_formal_ino)) {
+   if (dentry.dr_inum.in_formal_ino == 
be64_to_cpu(dent->de_inum.no_formal_ino)) {
log_debug("Formal inode number matches; must be a hard "
  "link.\n");
goto out;
@@ -641,13 +640,13 @@ static int dirref_find(struct fsck_cx *cx, struct 
lgfs2_inode *ip, struct gfs2_d
  "directory %"PRIu64" (0x%"PRIx64") has the wrong 'formal' 
inode "
  "number.\n"), entry->in_addr, entry->in_addr, 
ip->i_num.in_addr, ip->i_num.in_addr);
memset(fn, 0, sizeof(fn));
-   if (de->dr_name_len < MAX_FILENAME)
-   strncpy(fn, filename, de->dr_name_len);
+   if (dentry.dr_name_len < MAX_FILENAME)
+   strncpy(fn, filename, dentry.dr_name_len);
else
strncpy(fn, filename, MAX_FILENAME - 1);
log_err(_("The bad reference '%s' had formal inode number: %"PRIu64
  " (0x%"PRIx64") but the correct value is: %"PRIu64" 
(0x%"PRIx64")\n"),
-   fn, de->dr_inum.in_formal_ino, de->dr_inum.in_formal_ino,
+   fn, dentry.dr_inum.in_formal_ino, dentry.dr_inum.in_formal_ino,
entry->in_formal_ino, entry->in_formal_ino);
if (!query(cx, _("Delete the bad directory entry? (y/n) "))) {
log_err(_("The corrupt directory entry was not fixed.\n"));
-- 
2.39.0



[Cluster-devel] [PATCH 6/6] fsck.gfs2: fix_hashtable: Decrement i_blocks when freeing leaf blocks

2023-01-30 Thread Andrew Price
fsck.gfs2 can leave i_blocks too large when it removes empty leaf
blocks, so decrease the count when freeing them.

Signed-off-by: Andrew Price 
---
 gfs2/fsck/pass2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 5327ee43..71459978 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1334,6 +1334,7 @@ static int fix_hashtable(struct fsck_cx *cx, struct 
lgfs2_inode *ip, __be64 *tbl
(dentry.dr_inum.in_formal_ino == 0)) {
lgfs2_brelse(lbh);
lgfs2_free_block(ip->i_sbd, leafblk);
+   ip->i_blocks--;
log_err(_("Out of place leaf block %"PRIu64" (0x%"PRIx64") had 
no "
"entries, so it was deleted.\n"),
leafblk, leafblk);
-- 
2.39.0



[Cluster-devel] [PATCH 5/6] fsck.gfs2: Fix wrong entry used in dentry comparison

2023-01-30 Thread Andrew Price
'dent' points to the on-disk data that 'dentry' was converted from, so
this comparison always evaluates to true. Compare to 'entry' instead.

Signed-off-by: Andrew Price 
---
 gfs2/fsck/pass2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 002bf2cb..5327ee43 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -631,7 +631,7 @@ static int dirref_find(struct fsck_cx *cx, struct 
lgfs2_inode *ip, struct gfs2_d
(*count)++;
return 0;
}
-   if (dentry.dr_inum.in_formal_ino == 
be64_to_cpu(dent->de_inum.no_formal_ino)) {
+   if (dentry.dr_inum.in_formal_ino == entry->in_formal_ino) {
log_debug("Formal inode number matches; must be a hard "
  "link.\n");
goto out;
-- 
2.39.0



[Cluster-devel] [PATCH 1/6] libgfs2: Return the inode from lgfs2_lookupi()

2023-01-30 Thread Andrew Price
Instead of returning a -errno with the inode set via a passed in
pointer, return the inode and use errno. This is more consistent and
simplifies some calling code.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c |  7 +++
 gfs2/edit/hexedit.c |  2 +-
 gfs2/fsck/fs_recovery.c | 14 ++
 gfs2/fsck/initialize.c  | 18 +-
 gfs2/fsck/pass2.c   |  8 
 gfs2/glocktop/glocktop.c|  6 +++---
 gfs2/libgfs2/check_fs_ops.c | 18 +++---
 gfs2/libgfs2/fs_ops.c   | 38 +++--
 gfs2/libgfs2/gfs2l.c|  2 +-
 gfs2/libgfs2/lang.c | 10 ++
 gfs2/libgfs2/libgfs2.h  |  3 +--
 tests/nukerg.c  |  2 +-
 12 files changed, 62 insertions(+), 66 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index e0ca7c71..bf9985ae 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2139,11 +2139,10 @@ static void copy_quotas(struct lgfs2_sbd *sdp)
 {
struct lgfs2_inum inum;
struct lgfs2_inode *oq_ip, *nq_ip;
-   int err;
 
-   err = lgfs2_lookupi(sdp->master_dir, "quota", 5, _ip);
-   if (err) {
-   fprintf(stderr, _("Couldn't lookup new quota file: %d\n"), err);
+   nq_ip = lgfs2_lookupi(sdp->master_dir, "quota", 5);
+   if (nq_ip == NULL) {
+   perror(_("Failed to look up new quota file"));
exit(1);
}
 
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 553b15a5..c779433c 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -925,7 +925,7 @@ static void read_superblock(int fd)
if (sbd.master_dir == NULL) {
sbd.md.riinode = NULL;
} else {
-   lgfs2_lookupi(sbd.master_dir, "rindex", 6, 
);
+   sbd.md.riinode = lgfs2_lookupi(sbd.master_dir, 
"rindex", 6);
}
}
lgfs2_brelse(bh);
diff --git a/gfs2/fsck/fs_recovery.c b/gfs2/fsck/fs_recovery.c
index 8e572523..47433eac 100644
--- a/gfs2/fsck/fs_recovery.c
+++ b/gfs2/fsck/fs_recovery.c
@@ -789,10 +789,9 @@ int ji_update(struct lgfs2_sbd *sdp)
return -1;
} else {
/* FIXME check snprintf return code */
-   snprintf(journal_name, JOURNAL_NAME_SIZE,
-"journal%u", i);
-   lgfs2_lookupi(sdp->md.jiinode, journal_name,
-strlen(journal_name), );
+   int len;
+   len = snprintf(journal_name, JOURNAL_NAME_SIZE, 
"journal%u", i);
+   jip = lgfs2_lookupi(sdp->md.jiinode, journal_name, len);
sdp->md.journal[i] = jip;
}
}
@@ -884,7 +883,7 @@ int init_jindex(struct fsck_cx *cx, int allow_ji_rebuild)
if (sdp->gfs1)
sdp->md.jiinode = lgfs2_inode_read(sdp, 
sdp->sd_jindex_di.in_addr);
else
-   lgfs2_lookupi(sdp->master_dir, "jindex", 6, >md.jiinode);
+   sdp->md.jiinode = lgfs2_lookupi(sdp->master_dir, "jindex", 6);
 
if (!sdp->md.jiinode) {
int err;
@@ -906,7 +905,7 @@ int init_jindex(struct fsck_cx *cx, int allow_ji_rebuild)
log_crit(_("Error %d rebuilding jindex\n"), err);
return err;
}
-   lgfs2_lookupi(sdp->master_dir, "jindex", 6, >md.jiinode);
+   sdp->md.jiinode = lgfs2_lookupi(sdp->master_dir, "jindex", 6);
}
 
/* check for irrelevant entries in jindex. Can't use check_dir because
@@ -938,8 +937,7 @@ int init_jindex(struct fsck_cx *cx, int allow_ji_rebuild)
  "index: Cannot continue.\n"));
return error;
}
-   lgfs2_lookupi(sdp->master_dir, "jindex", 6,
->md.jiinode);
+   sdp->md.jiinode = lgfs2_lookupi(sdp->master_dir, 
"jindex", 6);
}
}
 
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index edb0b7fd..e8a8cb8b 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -597,7 +597,7 @@ static void lookup_per_node(struct fsck_cx *cx, int 
allow_rebuild)
if (sdp->md.pinode)
return;
 
-   lgfs2_lookupi(sdp->master_dir, "per_node", 8, >md.pinode);
+   sdp->md.pinode = lgfs2_lookupi(sdp->master_dir, "per_node", 8);
if (sdp->md.pinode)
return;
if (!allow_rebuild) {
@@ -61

[Cluster-devel] [PATCH 3/6] libgfs2: Reorganise lgfs2_createi()

2023-01-30 Thread Andrew Price
Move the lookup for an existing inode to lgfs2_createi itself and then
create the inode in __createi (renamed to do_createi) unconditionally.

Signed-off-by: Andrew Price 
---
 gfs2/libgfs2/fs_ops.c | 80 ---
 1 file changed, 45 insertions(+), 35 deletions(-)

diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 5003c1ae..0df78e5a 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -1497,9 +1497,10 @@ int lgfs2_write_filemeta(struct lgfs2_inode *ip)
return 0;
 }
 
-static struct lgfs2_inode *__createi(struct lgfs2_inode *dip, const char 
*filename,
- unsigned int mode, uint32_t flags)
+static struct lgfs2_inode *do_createi(struct lgfs2_inode *dip, const char 
*filename,
+  unsigned int mode, uint32_t flags)
 {
+   struct lgfs2_inum parent = dip->i_num;
struct lgfs2_sbd *sdp = dip->i_sbd;
uint64_t bn;
struct lgfs2_inum inum;
@@ -1508,50 +1509,59 @@ static struct lgfs2_inode *__createi(struct lgfs2_inode 
*dip, const char *filena
int err = 0;
int is_dir;
 
-   ip = lgfs2_lookupi(dip, filename, strlen(filename));
-   if (!ip) {
-   struct lgfs2_inum parent = dip->i_num;
-
-   err = lgfs2_dinode_alloc(sdp, 1, );
-   if (err != 0)
-   return NULL;
-
-   if (sdp->gfs1)
-   inum.in_formal_ino = bn;
-   else
-   inum.in_formal_ino = sdp->md.next_inum++;
-   inum.in_addr = bn;
-
-   err = lgfs2_dir_add(dip, filename, strlen(filename), , 
IF2DT(mode));
-   if (err)
-   return NULL;
+   err = lgfs2_dinode_alloc(sdp, 1, );
+   if (err != 0)
+   return NULL;
 
-   if (sdp->gfs1)
-   is_dir = (IF2DT(mode) == GFS_FILE_DIR);
-   else
-   is_dir = S_ISDIR(mode);
-   if (is_dir) {
-   lgfs2_bmodified(dip->i_bh);
-   dip->i_nlink++;
-   }
+   if (sdp->gfs1)
+   inum.in_formal_ino = bn;
+   else
+   inum.in_formal_ino = sdp->md.next_inum++;
+   inum.in_addr = bn;
 
-   err = __init_dinode(sdp, , , mode, flags, , 
sdp->gfs1);
-   if (err != 0)
-   return NULL;
+   err = lgfs2_dir_add(dip, filename, strlen(filename), , 
IF2DT(mode));
+   if (err)
+   return NULL;
 
-   ip = lgfs2_inode_get(sdp, bh);
-   if (ip == NULL)
-   return NULL;
-   lgfs2_bmodified(bh);
+   if (sdp->gfs1)
+   is_dir = (IF2DT(mode) == GFS_FILE_DIR);
+   else
+   is_dir = S_ISDIR(mode);
+   if (is_dir) {
+   lgfs2_bmodified(dip->i_bh);
+   dip->i_nlink++;
}
+   err = __init_dinode(sdp, , , mode, flags, , sdp->gfs1);
+   if (err != 0)
+   return NULL;
+
+   ip = lgfs2_inode_get(sdp, bh);
+   if (ip == NULL)
+   return NULL;
+   lgfs2_bmodified(bh);
ip->bh_owned = 1;
return ip;
 }
 
+/**
+ * Create an inode and link it into a directory. If it already exists, return
+ * the existing inode. To create gfs1 inodes, dip->i_sbd->gfs1 must be set.
+ * @dip: The inode of the parent directory.
+ * @filename: The new inode's filename.
+ * @mode: The mode of the new inode.
+ * @flags: The flags of the new inode.
+ * Returns the new or existing inode on success or NULL on failure with errno 
set.
+ */
 struct lgfs2_inode *lgfs2_createi(struct lgfs2_inode *dip, const char 
*filename,
  unsigned int mode, uint32_t flags)
 {
-   return __createi(dip, filename, mode, flags);
+   struct lgfs2_inode *ip = lgfs2_lookupi(dip, filename, strlen(filename));
+
+   if (ip != NULL) {
+   ip->bh_owned = 1;
+   return ip;
+   }
+   return do_createi(dip, filename, mode, flags);
 }
 
 /**
-- 
2.39.0



[Cluster-devel] [PATCH 2/6] libgfs2: Remove lgfs2_gfs_createi()

2023-01-30 Thread Andrew Price
The one caller sets sdp->gfs1 and modifies the mode itself so we can use
sdp->gfs1 in __createi() and update the caller to use lgfs2_createi()
instead.

Signed-off-by: Andrew Price 
---
 gfs2/fsck/lost_n_found.c |  6 +-
 gfs2/libgfs2/fs_ops.c| 19 ++-
 gfs2/libgfs2/libgfs2.h   |  3 ---
 3 files changed, 7 insertions(+), 21 deletions(-)

diff --git a/gfs2/fsck/lost_n_found.c b/gfs2/fsck/lost_n_found.c
index ca5ab89e..97fc16b0 100644
--- a/gfs2/fsck/lost_n_found.c
+++ b/gfs2/fsck/lost_n_found.c
@@ -109,11 +109,7 @@ void make_sure_lf_exists(struct fsck_cx *cx, struct 
lgfs2_inode *ip)
if (sdp->gfs1)
sdp->md.next_inum = find_free_blk(sdp);
mode = (sdp->gfs1 ? DT2IF(GFS_FILE_DIR) : S_IFDIR) | 0700;
-   if (sdp->gfs1)
-   lf_dip = lgfs2_gfs_createi(sdp->md.rooti, "lost+found", mode, 
0);
-   else
-   lf_dip = lgfs2_createi(sdp->md.rooti, "lost+found",
-S_IFDIR | 0700, 0);
+   lf_dip = lgfs2_createi(sdp->md.rooti, "lost+found", mode, 0);
if (lf_dip == NULL) {
log_crit(_("Error creating lost+found: %s\n"),
 strerror(errno));
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index e72871ed..5003c1ae 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -1497,9 +1497,8 @@ int lgfs2_write_filemeta(struct lgfs2_inode *ip)
return 0;
 }
 
-static struct lgfs2_inode *__createi(struct lgfs2_inode *dip,
-   const char *filename, unsigned int mode,
-   uint32_t flags, int if_gfs1)
+static struct lgfs2_inode *__createi(struct lgfs2_inode *dip, const char 
*filename,
+ unsigned int mode, uint32_t flags)
 {
struct lgfs2_sbd *sdp = dip->i_sbd;
uint64_t bn;
@@ -1517,7 +1516,7 @@ static struct lgfs2_inode *__createi(struct lgfs2_inode 
*dip,
if (err != 0)
return NULL;
 
-   if (if_gfs1)
+   if (sdp->gfs1)
inum.in_formal_ino = bn;
else
inum.in_formal_ino = sdp->md.next_inum++;
@@ -1527,7 +1526,7 @@ static struct lgfs2_inode *__createi(struct lgfs2_inode 
*dip,
if (err)
return NULL;
 
-   if (if_gfs1)
+   if (sdp->gfs1)
is_dir = (IF2DT(mode) == GFS_FILE_DIR);
else
is_dir = S_ISDIR(mode);
@@ -1536,7 +1535,7 @@ static struct lgfs2_inode *__createi(struct lgfs2_inode 
*dip,
dip->i_nlink++;
}
 
-   err = __init_dinode(sdp, , , mode, flags, , 
if_gfs1);
+   err = __init_dinode(sdp, , , mode, flags, , 
sdp->gfs1);
if (err != 0)
return NULL;
 
@@ -1552,13 +1551,7 @@ static struct lgfs2_inode *__createi(struct lgfs2_inode 
*dip,
 struct lgfs2_inode *lgfs2_createi(struct lgfs2_inode *dip, const char 
*filename,
  unsigned int mode, uint32_t flags)
 {
-   return __createi(dip, filename, mode, flags, 0);
-}
-
-struct lgfs2_inode *lgfs2_gfs_createi(struct lgfs2_inode *dip, const char 
*filename,
- unsigned int mode, uint32_t flags)
-{
-   return __createi(dip, filename, mode, flags, 1);
+   return __createi(dip, filename, mode, flags);
 }
 
 /**
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index bcbc5e47..69a7552f 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -515,9 +515,6 @@ extern int lgfs2_init_dinode(struct lgfs2_sbd *sdp, struct 
lgfs2_buffer_head **b
unsigned int mode, uint32_t flags, struct lgfs2_inum 
*parent);
 extern struct lgfs2_inode *lgfs2_createi(struct lgfs2_inode *dip, const char 
*filename,
  unsigned int mode, uint32_t flags);
-extern struct lgfs2_inode *lgfs2_gfs_createi(struct lgfs2_inode *dip,
- const char *filename, unsigned int mode,
- uint32_t flags);
 extern void lgfs2_dirent2_del(struct lgfs2_inode *dip, struct 
lgfs2_buffer_head *bh,
struct gfs2_dirent *prev, struct gfs2_dirent *cur);
 extern int lgfs2_dir_search(struct lgfs2_inode *dip, const char *filename, int 
len,
-- 
2.39.0



[Cluster-devel] [PATCH] mkfs.gfs2: Add a root_inherit_jdata extended option

2023-01-20 Thread Andrew Price
Add an extended option to allow the GFS2_DIF_INHERIT_JDATA flag to be
set on the root dinode at mkfs time.

This option is only to be used for testing so it is not documented.

Signed-off-by: Andrew Price 
---
 gfs2/mkfs/main_mkfs.c | 27 +++
 tests/mkfs.at | 16 
 2 files changed, 43 insertions(+)

diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 7d5b8c25..c9c7a1fb 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -128,6 +128,7 @@ struct mkfs_opts {
const char *uuid;
struct mkfs_dev dev;
unsigned discard:1;
+   unsigned root_inherit_jd:1;
 
unsigned got_bsize:1;
unsigned got_qcsize:1;
@@ -312,6 +313,25 @@ static int parse_format(struct mkfs_opts *opts, char *str)
return 0;
 }
 
+static int parse_root_inherit_jd(struct mkfs_opts *opts, const char *str)
+{
+   unsigned long n = 0;
+
+   if (str == NULL) { /* -o root_inherit_jdata */
+   opts->root_inherit_jd = 1;
+   return 0;
+   }
+   /* -o root_inherit_jdata=N */
+   if (parse_ulong(opts, "root_inherit_jdata", str, ) != 0)
+   return -1;
+   if (n > 1) {
+   fprintf(stderr, _("Invalid root_inherit_jdata argument '%s'. 
Must be 0 or 1\n"), str);
+   return -1;
+   }
+   opts->root_inherit_jd = (unsigned)n;
+   return 0;
+}
+
 static int opt_parse_extended(char *str, struct mkfs_opts *opts)
 {
char *opt;
@@ -341,6 +361,9 @@ static int opt_parse_extended(char *str, struct mkfs_opts 
*opts)
} else if (strcmp("format", key) == 0) {
if (parse_format(opts, val) != 0)
return -1;
+   } else if (strcmp("root_inherit_jdata", key) == 0) {
+   if (parse_root_inherit_jd(opts, val) != 0)
+   return -1;
} else if (strcmp("help", key) == 0) {
print_ext_opts();
return 1;
@@ -1364,6 +1387,10 @@ int main(int argc, char *argv[])
printf("%s", _("Done\n"));
 
lgfs2_build_root();
+   if (opts.root_inherit_jd) {
+   sbd.md.rooti->i_flags |= GFS2_DIF_INHERIT_JDATA;
+   lgfs2_dinode_out(sbd.md.rooti, sbd.md.rooti->i_bh->b_data);
+   }
if (opts.debug) {
printf("\nRoot directory:\n");
dinode_print(sbd.md.rooti->i_bh->b_data);
diff --git a/tests/mkfs.at b/tests/mkfs.at
index 298daf3d..7064a9e2 100644
--- a/tests/mkfs.at
+++ b/tests/mkfs.at
@@ -198,3 +198,19 @@ AT_CHECK([$GFS_MKFS -p lock_nolock -U 
1b4e28ba-2fa1-11d2-883f-b9a761bde3fb4 $GFS
 AT_CHECK([$GFS_MKFS -p lock_nolock -U 1b4e28ba-2fa1-11d2-883f-b9a761bde3f 
$GFS_TGT], 255, [ignore], [ignore])
 GFS_FSCK_CHECK([$GFS_MKFS -p lock_nolock -U 
1b4e28ba-2fa1-11d2-883f-b9a761bde3fb $GFS_TGT])
 AT_CLEANUP
+
+AT_SETUP([Root jdata inheritance])
+AT_KEYWORDS(mkfs.gfs2 mkfs)
+GFS_TGT_REGEN
+AT_CHECK([$GFS_MKFS -p lock_nolock -o root_inherit_jdata= $GFS_TGT], 255, 
[ignore], [ignore])
+AT_CHECK([$GFS_MKFS -p lock_nolock -o root_inherit_jdata=42 $GFS_TGT], 255, 
[ignore], [ignore])
+AT_CHECK([$GFS_MKFS -p lock_nolock -o root_inherit_jdata=X $GFS_TGT], 255, 
[ignore], [ignore])
+AT_CHECK([$GFS_MKFS -p lock_nolock -o root_inherit_jdata $GFS_TGT], 0, 
[ignore], [ignore])
+AT_CHECK([gfs2_edit -x -p root field di_flags $GFS_TGT | tr -d '\n'], 0, 
[8001], [ignore])
+AT_CHECK([$GFS_MKFS -p lock_nolock -o root_inherit_jdata=1 $GFS_TGT], 0, 
[ignore], [ignore])
+AT_CHECK([gfs2_edit -x -p root field di_flags $GFS_TGT | tr -d '\n'], 0, 
[8001], [ignore])
+AT_CHECK([$GFS_MKFS -p lock_nolock -o root_inherit_jdata=0 $GFS_TGT], 0, 
[ignore], [ignore])
+AT_CHECK([gfs2_edit -x -p root field di_flags $GFS_TGT | tr -d '\n'], 0, [1], 
[ignore])
+AT_CHECK([$GFS_MKFS -p lock_nolock $GFS_TGT], 0, [ignore], [ignore])
+AT_CHECK([gfs2_edit -x -p root field di_flags $GFS_TGT | tr -d '\n'], 0, [1], 
[ignore])
+AT_CLEANUP
-- 
2.39.0



Re: [Cluster-devel] [syzbot] WARNING in gfs2_ri_update

2022-10-25 Thread Andrew Price

On 22/10/2022 12:11, syzbot wrote:

syzbot has found a reproducer for the following issue on:

HEAD commit:440b7895c990 Merge tag 'mm-hotfixes-stable-2022-10-20' of ..
git tree:   upstream
console+strace: https://syzkaller.appspot.com/x/log.txt?x=128087a488
kernel config:  https://syzkaller.appspot.com/x/.config?x=afc317c0f52ce670
dashboard link: https://syzkaller.appspot.com/bug?extid=f8bc4176e51e87e0928f
compiler:   Debian clang version 
13.0.1-++20220126092033+75e33f71c2da-1~exp1~20220126212112.63, GNU ld (GNU 
Binutils for Debian) 2.35.2
syz repro:  https://syzkaller.appspot.com/x/repro.syz?x=13ed90f288
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=16717fc288

Downloadable assets:
disk image: 
https://storage.googleapis.com/syzbot-assets/105038975fc9/disk-440b7895.raw.xz
vmlinux: 
https://storage.googleapis.com/syzbot-assets/edd7302c8fc8/vmlinux-440b7895.xz
mounted in repro: 
https://storage.googleapis.com/syzbot-assets/95d6d27d2d50/mount_0.gz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+f8bc4176e51e87e09...@syzkaller.appspotmail.com

gfs2: fsid=syz:syz: Now mounting FS (format 1801)...
gfs2: fsid=syz:syz.0: journal 0 mapped with 1 extents in 0ms
gfs2: fsid=syz:syz.0: first mount done, others may mount
[ cut here ]
WARNING: CPU: 0 PID: 3611 at mm/page_alloc.c:5530 __alloc_pages+0x30a/0x560 
mm/page_alloc.c:5530
Modules linked in:
CPU: 1 PID: 3611 Comm: syz-executor282 Not tainted 
6.1.0-rc1-syzkaller-00158-g440b7895c990 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 
10/11/2022
RIP: 0010:__alloc_pages+0x30a/0x560 mm/page_alloc.c:5530
Code: 5c 24 04 0f 85 f3 00 00 00 44 89 e1 81 e1 7f ff ff ff a9 00 00 04 00 41 0f 44 
cc 41 89 cc e9 e3 00 00 00 c6 05 a1 ab 29 0c 01 <0f> 0b 83 fb 0a 0f 86 c8 fd ff 
ff 31 db 48 c7 44 24 20 0e 36 e0 45
RSP: 0018:c90003c5f4a0 EFLAGS: 00010246
RAX: c90003c5f500 RBX: 0012 RCX: 
RDX: 0028 RSI:  RDI: c90003c5f528
RBP: c90003c5f5b8 R08: dc00 R09: c90003c5f500
R10: f5200078bea5 R11: 19200078bea0 R12: 00040d40
R13: 19200078be9c R14: dc00 R15: 19200078be98
FS:  55781300() GS:8880b9b0() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 005d84c8 CR3: 79874000 CR4: 003506e0
DR0:  DR1:  DR2: 
DR3:  DR6: fffe0ff0 DR7: 0400
Call Trace:
  
  __alloc_pages_node include/linux/gfp.h:223 [inline]
  alloc_pages_node include/linux/gfp.h:246 [inline]
  __kmalloc_large_node+0x8a/0x1a0 mm/slab_common.c:1098
  __do_kmalloc_node mm/slab_common.c:943 [inline]
  __kmalloc+0xfe/0x1a0 mm/slab_common.c:968
  kmalloc_array include/linux/slab.h:628 [inline]
  kcalloc include/linux/slab.h:659 [inline]
  compute_bitstructs fs/gfs2/rgrp.c:766 [inline]
  read_rindex_entry fs/gfs2/rgrp.c:931 [inline]


The fuzzer is writing 16777217 to an rindex entry's ri_length field so 
compute_bitstructs() is asking kmalloc for (16777217 * 40) bytes of 
memory, to which it says nope and dumps a warning.


Simpler version:
# mkfs.gfs2 -p lock_nolock -o align=0 /dev/vdc
# printf '\x01\x00\x00\x01' | dd of=/dev/vdc bs=1 seek=135676008 count=4
# mount /dev/vdc /mnt/test

I have some experimental code to add integrity checking to rindex 
entries[0] that would catch this but it would require an sb_fs_format 
bump before it can treat ri_crc == 0 usefully.


0. 
https://gitlab.com/andyprice/linux/-/commit/4e0557916733e59b2e6795775e94c9b733b51f6b


Andy


  gfs2_ri_update+0x537/0x17f0 fs/gfs2/rgrp.c:1001
  gfs2_rindex_update+0x313/0x3f0 fs/gfs2/rgrp.c:1051
  init_inodes+0x242/0x340 fs/gfs2/ops_fstype.c:917
  gfs2_fill_super+0x1bb2/0x2700 fs/gfs2/ops_fstype.c:1247
  get_tree_bdev+0x400/0x620 fs/super.c:1323
  gfs2_get_tree+0x50/0x210 fs/gfs2/ops_fstype.c:1330
  vfs_get_tree+0x88/0x270 fs/super.c:1530
  do_new_mount+0x289/0xad0 fs/namespace.c:3040
  do_mount fs/namespace.c:3383 [inline]
  __do_sys_mount fs/namespace.c:3591 [inline]
  __se_sys_mount+0x2d3/0x3c0 fs/namespace.c:3568
  do_syscall_x64 arch/x86/entry/common.c:50 [inline]
  do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
  entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fb4bd4a797a
Code: 83 c4 08 5b 5d c3 66 2e 0f 1f 84 00 00 00 00 00 c3 66 2e 0f 1f 84 00 00 00 00 
00 0f 1f 44 00 00 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 
c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:7ffc73f0a0b8 EFLAGS: 0282 ORIG_RAX: 00a5
RAX: ffda RBX: 0003 RCX: 7fb4bd4a797a
RDX: 2000 RSI: 2100 RDI: 7ffc73f0a0d0
RBP: 7ffc73f0a0d0 R08: 7ffc73f0a110 R09: 557812c0
R10:  R11: 0282 R12: 0004
R13: 7ffc73f0a110 R14: 

Re: [Cluster-devel] [syzbot] UBSAN: shift-out-of-bounds in gfs2_getbuf

2022-10-13 Thread Andrew Price

On 13/10/2022 14:31, syzbot wrote:

Hello,

syzbot found the following issue on:

HEAD commit:493ffd6605b2 Merge tag 'ucount-rlimits-cleanups-for-v5.19'..


$ git describe --contains 493ffd6605b2
next-20221011~172


git tree:   upstream


It would be useful to know the precise git tree.


console output: https://syzkaller.appspot.com/x/log.txt?x=1462025288
kernel config:  https://syzkaller.appspot.com/x/.config?x=d19f5d16783f901
dashboard link: https://syzkaller.appspot.com/bug?extid=87a187973530ac822e3c
compiler:   Debian clang version 
13.0.1-++20220126092033+75e33f71c2da-1~exp1~20220126212112.63, GNU ld (GNU 
Binutils for Debian) 2.35.2

Unfortunately, I don't have any reproducer for this issue yet.

Downloadable assets:
disk image: 
https://storage.googleapis.com/syzbot-assets/f1ff6481e26f/disk-493ffd66.raw.xz
vmlinux: 
https://storage.googleapis.com/syzbot-assets/101bd3c7ae47/vmlinux-493ffd66.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+87a187973530ac822...@syzkaller.appspotmail.com


UBSAN: shift-out-of-bounds in fs/gfs2/meta_io.c:128:16


shift = PAGE_SHIFT - sdp->sd_sb.sb_bsize_shift;
index = blkno >> shift; /* convert block to page */
bufnum = blkno - (index << shift);  /* block buf index within 
page */


So likely fixed by commit 670f8ce56dd0632dc29a0322e188cc73ce3c6b92 
"gfs2: Check sb_bsize_shift after reading superblock" which has just 
been merged into mainline, but doesn't appear in next-20221011~172


Andy


shift exponent 4294967293 is too large for 64-bit type 'u64' (aka 'unsigned 
long long')
CPU: 0 PID: 10195 Comm: syz-executor.3 Not tainted 
6.0.0-syzkaller-09423-g493ffd6605b2 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 
09/22/2022
Call Trace:
  
  __dump_stack lib/dump_stack.c:88 [inline]
  dump_stack_lvl+0x1b1/0x28e lib/dump_stack.c:106
  ubsan_epilogue lib/ubsan.c:151 [inline]
  __ubsan_handle_shift_out_of_bounds+0x33d/0x3b0 lib/ubsan.c:322
  gfs2_getbuf+0x759/0x7d0 fs/gfs2/meta_io.c:128
  gfs2_meta_read+0x153/0x910 fs/gfs2/meta_io.c:265
  gfs2_meta_buffer+0x153/0x3a0 fs/gfs2/meta_io.c:491
  gfs2_meta_inode_buffer fs/gfs2/meta_io.h:72 [inline]
  gfs2_inode_refresh+0xab/0xe90 fs/gfs2/glops.c:472
  gfs2_instantiate+0x15e/0x220 fs/gfs2/glock.c:515
  gfs2_glock_holder_ready fs/gfs2/glock.c:1303 [inline]
  gfs2_glock_wait+0x1d9/0x2a0 fs/gfs2/glock.c:1323
  gfs2_glock_nq_init fs/gfs2/glock.h:263 [inline]
  gfs2_lookupi+0x40c/0x650 fs/gfs2/inode.c:306
  gfs2_lookup_simple+0xec/0x170 fs/gfs2/inode.c:258
  init_journal+0x19b/0x22c0 fs/gfs2/ops_fstype.c:739
  init_inodes+0xdc/0x340 fs/gfs2/ops_fstype.c:882
  gfs2_fill_super+0x1ad8/0x2610 fs/gfs2/ops_fstype.c:1240
  get_tree_bdev+0x400/0x620 fs/super.c:1323
  gfs2_get_tree+0x50/0x210 fs/gfs2/ops_fstype.c:1323
  vfs_get_tree+0x88/0x270 fs/super.c:1530
  do_new_mount+0x289/0xad0 fs/namespace.c:3040
  do_mount fs/namespace.c:3383 [inline]
  __do_sys_mount fs/namespace.c:3591 [inline]
  __se_sys_mount+0x2d3/0x3c0 fs/namespace.c:3568
  do_syscall_x64 arch/x86/entry/common.c:50 [inline]
  do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
  entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f0eed68cada
Code: 48 c7 c2 b8 ff ff ff f7 d8 64 89 02 b8 ff ff ff ff eb d2 e8 b8 04 00 00 0f 1f 
84 00 00 00 00 00 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 
c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:7f0eee73cf88 EFLAGS: 0202 ORIG_RAX: 00a5
RAX: ffda RBX: 2200 RCX: 7f0eed68cada
RDX: 2000 RSI: 2100 RDI: 7f0eee73cfe0
RBP: 7f0eee73d020 R08: 7f0eee73d020 R09: 2000
R10: 0008 R11: 0202 R12: 2000
R13: 2100 R14: 7f0eee73cfe0 R15: 2080
  



---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkal...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.





Re: [Cluster-devel] [PATCH] gfs2: Check sb_bsize_shift after reading superblock

2022-09-20 Thread Andrew Price

I've pushed this patch to my git repo:

  git fetch https://gitlab.com/andyprice/linux.git bsize_shift_check
  git show FETCH_HEAD

Andy

On 17/08/2022 13:22, Andrew Price wrote:

Fuzzers like to scribble over sb_bsize_shift but in reality it's very
unlikely that this field would be corrupted on its own. Nevertheless it
should be checked to avoid the possibility of messy mount errors due to
bad calculations. It's always a fixed value based on the block size so
we can just check that it's the expected value.

Tested with:

 mkfs.gfs2 -O -p lock_nolock /dev/vdb
 for i in 0 -1 64 65 32 33; do
 gfs2_edit -p sb field sb_bsize_shift $i /dev/vdb
 mount /dev/vdb /mnt/test && umount /mnt/test
 done

Before this patch we get a withdraw after

[   76.413681] gfs2: fsid=loop0.0: fatal: invalid metadata block
[   76.413681]   bh = 19 (type: exp=5, found=4)
[   76.413681]   function = gfs2_meta_buffer, file = fs/gfs2/meta_io.c, line = 
492

and with UBSAN configured we also get complaints like

[   76.373395] UBSAN: shift-out-of-bounds in fs/gfs2/ops_fstype.c:295:19
[   76.373815] shift exponent 4294967287 is too large for 64-bit type 'long 
unsigned int'

After the patch, these complaints don't appear, mount fails immediately
and we get an explanation in dmesg.

Reported-by: syzbot+dcf33a7aae997956f...@syzkaller.appspotmail.com
Signed-off-by: Andrew Price 
---
  fs/gfs2/ops_fstype.c | 5 -
  1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 549879929c84..692e27f8f563 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -178,7 +178,10 @@ static int gfs2_check_sb(struct gfs2_sbd *sdp, int silent)
pr_warn("Invalid block size\n");
return -EINVAL;
}
-
+   if (sb->sb_bsize_shift != ffs(sb->sb_bsize) - 1) {
+   pr_warn("Invalid block size shift\n");
+   return -EINVAL;
+   }
return 0;
  }
  




Re: [Cluster-devel] [PATCH] gfs2: move from strlcpy with unused retval to strscpy

2022-08-25 Thread Andrew Price

On 24/08/2022 21:08, Wolfram Sang wrote:

Hi Andy.


-   strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN);
-   strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN);
+   strscpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN);
+   strscpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN);


Perhaps the size should be changed to GFS2_LOCKNAME_LEN to match the size of
the destination, too.

With that addition, this patch fixes this syzkaller report:

https://listman.redhat.com/archives/cluster-devel/2022-August/022755.html


Linus wrote another summary about strlcpy vs. strscpy use[1]. So, the
size argument should be the size of the smaller buffer if the buffers
are of different size. GFS2_LOCKNAME_LEN is smaller, so that looks
suitable. Shall I resend the patch with the suggested change?


Yes, please. I can't speak for the gfs2 maintainers but I think it would 
be a good plan, as the combination of strscpy and the size change fixes 
a bug.


Andy



All the best,

Wolfram

[1] 
https://lore.kernel.org/lkml/CAHk-=wi+xbvq++uqw9ygwphjybhnb8a-xad+xp23-b+eodl...@mail.gmail.com/





Re: [Cluster-devel] [PATCH] gfs2: move from strlcpy with unused retval to strscpy

2022-08-23 Thread Andrew Price

On 18/08/2022 22:01, Wolfram Sang wrote:

Follow the advice of the below link and prefer 'strscpy' in this
subsystem. Conversion is 1:1 because the return value is not used.
Generated by a coccinelle script.

Link: 
https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=v6a6g1ouzcprm...@mail.gmail.com/
Signed-off-by: Wolfram Sang 
---
  fs/gfs2/ops_fstype.c | 10 +-
  1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 549879929c84..b57d9bf4b123 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -381,8 +381,8 @@ static int init_names(struct gfs2_sbd *sdp, int silent)
if (!table[0])
table = sdp->sd_vfs->s_id;
  
-	strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN);

-   strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN);
+   strscpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN);
+   strscpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN);


Perhaps the size should be changed to GFS2_LOCKNAME_LEN to match the 
size of the destination, too.


With that addition, this patch fixes this syzkaller report:

https://listman.redhat.com/archives/cluster-devel/2022-August/022755.html

Andy

  
  	table = sdp->sd_table_name;

while ((table = strchr(table, '/')))
@@ -1439,13 +1439,13 @@ static int gfs2_parse_param(struct fs_context *fc, 
struct fs_parameter *param)
  
  	switch (o) {

case Opt_lockproto:
-   strlcpy(args->ar_lockproto, param->string, GFS2_LOCKNAME_LEN);
+   strscpy(args->ar_lockproto, param->string, GFS2_LOCKNAME_LEN);
break;
case Opt_locktable:
-   strlcpy(args->ar_locktable, param->string, GFS2_LOCKNAME_LEN);
+   strscpy(args->ar_locktable, param->string, GFS2_LOCKNAME_LEN);
break;
case Opt_hostdata:
-   strlcpy(args->ar_hostdata, param->string, GFS2_LOCKNAME_LEN);
+   strscpy(args->ar_hostdata, param->string, GFS2_LOCKNAME_LEN);
break;
case Opt_spectator:
args->ar_spectator = 1;




[Cluster-devel] [PATCH] gfs2: Check sb_bsize_shift after reading superblock

2022-08-17 Thread Andrew Price
Fuzzers like to scribble over sb_bsize_shift but in reality it's very
unlikely that this field would be corrupted on its own. Nevertheless it
should be checked to avoid the possibility of messy mount errors due to
bad calculations. It's always a fixed value based on the block size so
we can just check that it's the expected value.

Tested with:

mkfs.gfs2 -O -p lock_nolock /dev/vdb
for i in 0 -1 64 65 32 33; do
gfs2_edit -p sb field sb_bsize_shift $i /dev/vdb
mount /dev/vdb /mnt/test && umount /mnt/test
done

Before this patch we get a withdraw after

[   76.413681] gfs2: fsid=loop0.0: fatal: invalid metadata block
[   76.413681]   bh = 19 (type: exp=5, found=4)
[   76.413681]   function = gfs2_meta_buffer, file = fs/gfs2/meta_io.c, line = 
492

and with UBSAN configured we also get complaints like

[   76.373395] UBSAN: shift-out-of-bounds in fs/gfs2/ops_fstype.c:295:19
[   76.373815] shift exponent 4294967287 is too large for 64-bit type 'long 
unsigned int'

After the patch, these complaints don't appear, mount fails immediately
and we get an explanation in dmesg.

Reported-by: syzbot+dcf33a7aae997956f...@syzkaller.appspotmail.com
Signed-off-by: Andrew Price 
---
 fs/gfs2/ops_fstype.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 549879929c84..692e27f8f563 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -178,7 +178,10 @@ static int gfs2_check_sb(struct gfs2_sbd *sdp, int silent)
pr_warn("Invalid block size\n");
return -EINVAL;
}
-
+   if (sb->sb_bsize_shift != ffs(sb->sb_bsize) - 1) {
+   pr_warn("Invalid block size shift\n");
+   return -EINVAL;
+   }
return 0;
 }
 
-- 
2.37.1



[Cluster-devel] [PATCH] mkfs.gfs2: Add -U UUID option

2022-07-14 Thread Andrew Price
Allow the user to specify the filesystem UUID, similar to mkfs.ext4's -U
option.

Signed-off-by: Andrew Price 
---
 gfs2/man/mkfs.gfs2.8  |  6 ++
 gfs2/mkfs/main_mkfs.c | 19 +--
 tests/mkfs.at | 10 ++
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/gfs2/man/mkfs.gfs2.8 b/gfs2/man/mkfs.gfs2.8
index 58742dea..0ddc074e 100644
--- a/gfs2/man/mkfs.gfs2.8
+++ b/gfs2/man/mkfs.gfs2.8
@@ -123,6 +123,12 @@ unique file system name used to distinguish this gfs2 file 
system.  Valid
 \fIclustername\fRs and \fIlockspace\fRs may only contain alphanumeric
 characters, hyphens (-) and underscores (_).
 .TP
+\fB-U\fP \fIUUID\fR
+Specify the filesystem UUID. The argument must be string of hexadecimal digits
+separated by hyphens, of the form "1b4e28ba-2fa1-11d2-883f-b9a761bde3fb". If
+this option is omitted, the filesystem's UUID is randomly generated. Note that
+no attempt is made to prevent UUID clashes between filesystems on the system.
+.TP
 \fB-V\fP
 Print program version information, then exit.
 .TP
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 37ed5d08..f552f934 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -52,6 +52,7 @@ static void print_usage(const char *prog_name)
"-q", NULL,  _("Don't print anything"),
"-r", _(""),   _("Size of resource groups, in megabytes"),
"-t", _(""),   _("Name of the lock table"),
+   "-U", _(""),   _("The UUID of the file system"),
"-V", NULL,  _("Display program version information, then 
exit"),
NULL, NULL, NULL /* Must be kept at the end */
};
@@ -121,6 +122,7 @@ struct mkfs_opts {
int journals;
const char *lockproto;
const char *locktable;
+   const char *uuid;
struct mkfs_dev dev;
unsigned discard:1;
 
@@ -137,6 +139,7 @@ struct mkfs_opts {
unsigned got_device:1;
unsigned got_topol:1;
unsigned got_format:1;
+   unsigned got_uuid:1;
 
unsigned override:1;
unsigned quiet:1;
@@ -352,7 +355,7 @@ static int opts_get(int argc, char *argv[], struct 
mkfs_opts *opts)
int ret;
int c;
while (1) {
-   c = getopt(argc, argv, "-b:c:DhJ:j:KOo:p:qr:t:V");
+   c = getopt(argc, argv, "-b:c:DhJ:j:KOo:p:qr:t:U:V");
if (c == -1)
break;
 
@@ -405,6 +408,10 @@ static int opts_get(int argc, char *argv[], struct 
mkfs_opts *opts)
if (ret != 0)
return ret;
break;
+   case 'U':
+   opts->uuid = optarg;
+   opts->got_uuid = 1;
+   break;
case 'V':
printf("mkfs.gfs2 %s (built %s %s)\n", VERSION,
   __DATE__, __TIME__);
@@ -1062,7 +1069,15 @@ static int sbd_init(struct lgfs2_sbd *sdp, struct 
mkfs_opts *opts, unsigned bsiz
sdp->sd_multihost_format = GFS2_FORMAT_MULTI;
sdp->sd_bsize = bsize;
sdp->sd_bsize_shift = ffs(bsize) - 1;
-   uuid_generate(sdp->sd_uuid);
+
+   if (opts->got_uuid) {
+   int err = uuid_parse(opts->uuid, sdp->sd_uuid);
+   if (err != 0) {
+   fprintf(stderr, _("Failed to parse UUID option."));
+   return -1;
+   }
+   } else
+   uuid_generate(sdp->sd_uuid);
 
if (lgfs2_compute_constants(sdp)) {
perror(_("Failed to compute file system constants"));
diff --git a/tests/mkfs.at b/tests/mkfs.at
index 09a3ed29..298daf3d 100644
--- a/tests/mkfs.at
+++ b/tests/mkfs.at
@@ -188,3 +188,13 @@ GFS_TGT_SIZE(64M)
 AT_CHECK([$GFS_MKFS -p lock_nolock -j2 $GFS_TGT], 0, [ignore], [ignore])
 AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
 AT_CLEANUP
+
+AT_SETUP([UUID option])
+AT_KEYWORDS(mkfs.gfs2 mkfs)
+GFS_TGT_REGEN
+AT_CHECK([$GFS_MKFS -p lock_nolock $GFS_TGT -U], 255, [ignore], [ignore])
+AT_CHECK([$GFS_MKFS -p lock_nolock -U 42 $GFS_TGT], 255, [ignore], [ignore])
+AT_CHECK([$GFS_MKFS -p lock_nolock -U 1b4e28ba-2fa1-11d2-883f-b9a761bde3fb4 
$GFS_TGT], 255, [ignore], [ignore])
+AT_CHECK([$GFS_MKFS -p lock_nolock -U 1b4e28ba-2fa1-11d2-883f-b9a761bde3f 
$GFS_TGT], 255, [ignore], [ignore])
+GFS_FSCK_CHECK([$GFS_MKFS -p lock_nolock -U 
1b4e28ba-2fa1-11d2-883f-b9a761bde3fb $GFS_TGT])
+AT_CLEANUP
-- 
2.36.1



Re: [Cluster-devel] Mounting lock_nolock file systems?

2022-06-21 Thread Andrew Price

On 21/06/2022 10:14, Christoph Hellwig wrote:

I'm felling a little stupid, but in the past after a

mkfs.gfs2  -O -p lock_nolock

I could just mount the created file system locally.

On current mainline that does not seem to work any more, what am I
missing?


I can't reproduce the problem on current mainline. What version of 
gfs2-utils is your mkfs.gfs2 from?


Could you send your superblock?

  dd if=/dev/vdb bs=4k skip=16 count=1 status=none | xxd -a

will grab it.

Andy


Here is the output from the mount attempt:

oot@testvm:~# mount /dev/vdb /mnt/
[  154.745017] gfs2: fsid=vdb: Trying to join cluster "lock_nolock", "vdb"
[  154.745024] gfs2: fsid=vdb: Now mounting FS (format 1801)...
[  154.782279] gfs2: fsid=vdb.0: journal 0 mapped with 1 extents in 0ms
[  154.784878] gfs2: fsid=vdb.0: jid=0, already locked for use
[  154.784885] gfs2: fsid=vdb.0: jid=0: Looking at journal...
[  154.787474] gfs2: fsid=vdb.0: jid=0: Journal head lookup took 2ms
[  154.787482] gfs2: fsid=vdb.0: jid=0: Acquiring the transaction lock...
[  154.787513] gfs2: fsid=vdb.0: jid=0: Replaying journal...0x0 to 0x0
[  154.787522] gfs2: fsid=vdb.0: jid=0: Replayed 0 of 0 blocks
[  154.787525] gfs2: fsid=vdb.0: jid=0: Found 0 revoke tags
[  154.788116] gfs2: fsid=vdb.0: jid=0: Journal replayed in 3ms [jlck:0ms, 
jhead:2ms, tl]
[  154.788239] gfs2: fsid=vdb.0: jid=0: Done
[  154.789896] gfs2: fsid=vdb.0: first mount done, others may mount
[  154.802688] gfs2: fsid=vdb.0: fatal: filesystem consistency error - function 
= gfs2_m5
[  154.802700] gfs2: fsid=vdb.0: about to withdraw this file system
[  185.894949] gfs2: fsid=vdb.0: Journal recovery skipped for jid 0 until next 
mount.
[  185.894975] gfs2: fsid=vdb.0: Glock dequeues delayed: 0
[  185.895202] gfs2: fsid=vdb.0: File system withdrawn
[  185.895220] CPU: 1 PID: 2777 Comm: mount Not tainted 5.19.0-rc3+ #1713
[  185.895229] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
1.14.0-2 04/04
[  185.895239] Call Trace:
[  185.895247]  
[  185.895251]  dump_stack_lvl+0x45/0x5a
[  185.895276]  gfs2_withdraw.cold+0xdb/0x507
[  185.895305]  gfs2_fill_super+0xb5a/0xbe0
[  185.895312]  ? gfs2_fill_super+0x771/0xbe0
[  185.895319]  ? gfs2_fill_super+0xa22/0xbe0
[  185.895325]  ? gfs2_reconfigure+0x3c0/0x3c0
[  185.895330]  get_tree_bdev+0x169/0x270
[  185.895341]  gfs2_get_tree+0x19/0x80
[  185.895346]  vfs_get_tree+0x20/0xb0
[  185.895352]  path_mount+0x2b1/0xa70
[  185.895362]  __x64_sys_mount+0xfe/0x140
[  185.895370]  do_syscall_64+0x3b/0x90
[  185.895378]  entry_SYSCALL_64_after_hwframe+0x46/0xb0
[  185.895388] RIP: 0033:0x7fd8ba7269ea
[  185.895404] Code: 48 8b 0d a9 f4 0b 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 
0f 1f 84 08
[  185.895410] RSP: 002b:7ffea6838018 EFLAGS: 0246 ORIG_RAX: 
00a5
[  185.895419] RAX: ffda RBX: 7fd8ba849264 RCX: 7fd8ba7269ea
[  185.895423] RDX: 55669b2724e0 RSI: 55669b26dc50 RDI: 55669b26b370
[  185.895427] RBP: 55669b26b140 R08:  R09: 7fd8ba7e6be0
[  185.895431] R10:  R11: 0246 R12: 
[  185.895434] R13: 55669b26b370 R14: 55669b2724e0 R15: 55669b26b140
[  185.895443]  
[  185.895461] gfs2: fsid=vdb.0: can't make FS RW: -5






Re: [Cluster-devel] [PATCH RESEND] gfs2: Return more useful errors from gfs2_rgrp_send_discards()

2022-05-09 Thread Andrew Price

On 29/04/2022 15:08, Andrew Price wrote:

On 19/04/2022 16:49, Andrew Price wrote:

On 05/04/2022 13:08, Andrew Price wrote:

The bug that 27ca8273f ("gfs2: Make sure FITRIM minlen is rounded up to
fs block size") fixes was a little confusing as the user saw
"Input/output error" which masked the -EINVAL that sb_issue_discard()
returned.

sb_issue_discard() can fail for various reasons, so we should return its
return value from gfs2_rgrp_send_discards() to avoid all errors being
reported as IO errors.

This improves error reporting for FITRIM and makes no difference to the
-o discard code path because the return value from
gfs2_rgrp_send_discards() gets thrown away in that case (and the option
switches off). Presumably that's why it was ok to just return -EIO in
the past, before FITRIM was implemented.

Tested with xfstests.


Can I get a thumbs-up or thumbs-down for this patch? It's pretty 
straightforward. I just don't want it to get forgotten about.


Cheers,
Andy


Please could you take this patch?

Cheers,
Andy


For convenience, I've pushed this patch to gitlab:

  git fetch https://gitlab.com/andyprice/linux.git discard_errors
  git show FETCH_HEAD

Cheers,
Andy


Signed-off-by: Andrew Price 
---

I don't see this in for-next yet so I've updated the commit log to 
include more

details.

  fs/gfs2/rgrp.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 801ad9f4f2be..886343cc05ab 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1315,7 +1315,7 @@ int gfs2_rgrp_send_discards(struct gfs2_sbd 
*sdp, u64 offset,

  u64 blk;
  sector_t start = 0;
  sector_t nr_blks = 0;
-    int rv;
+    int rv = -EIO;
  unsigned int x;
  u32 trimmed = 0;
  u8 diff;
@@ -1371,7 +1371,7 @@ int gfs2_rgrp_send_discards(struct gfs2_sbd 
*sdp, u64 offset,

  if (sdp->sd_args.ar_discard)
  fs_warn(sdp, "error %d on discard request, turning discards 
off for this filesystem\n", rv);

  sdp->sd_args.ar_discard = 0;
-    return -EIO;
+    return rv;
  }
  /**








Re: [Cluster-devel] [PATCH RESEND] gfs2: Return more useful errors from gfs2_rgrp_send_discards()

2022-04-29 Thread Andrew Price

On 19/04/2022 16:49, Andrew Price wrote:

On 05/04/2022 13:08, Andrew Price wrote:

The bug that 27ca8273f ("gfs2: Make sure FITRIM minlen is rounded up to
fs block size") fixes was a little confusing as the user saw
"Input/output error" which masked the -EINVAL that sb_issue_discard()
returned.

sb_issue_discard() can fail for various reasons, so we should return its
return value from gfs2_rgrp_send_discards() to avoid all errors being
reported as IO errors.

This improves error reporting for FITRIM and makes no difference to the
-o discard code path because the return value from
gfs2_rgrp_send_discards() gets thrown away in that case (and the option
switches off). Presumably that's why it was ok to just return -EIO in
the past, before FITRIM was implemented.

Tested with xfstests.


Can I get a thumbs-up or thumbs-down for this patch? It's pretty 
straightforward. I just don't want it to get forgotten about.


Cheers,
Andy


Please could you take this patch?

Cheers,
Andy


Signed-off-by: Andrew Price 
---

I don't see this in for-next yet so I've updated the commit log to 
include more

details.

  fs/gfs2/rgrp.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 801ad9f4f2be..886343cc05ab 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1315,7 +1315,7 @@ int gfs2_rgrp_send_discards(struct gfs2_sbd 
*sdp, u64 offset,

  u64 blk;
  sector_t start = 0;
  sector_t nr_blks = 0;
-    int rv;
+    int rv = -EIO;
  unsigned int x;
  u32 trimmed = 0;
  u8 diff;
@@ -1371,7 +1371,7 @@ int gfs2_rgrp_send_discards(struct gfs2_sbd 
*sdp, u64 offset,

  if (sdp->sd_args.ar_discard)
  fs_warn(sdp, "error %d on discard request, turning discards 
off for this filesystem\n", rv);

  sdp->sd_args.ar_discard = 0;
-    return -EIO;
+    return rv;
  }
  /**






Re: [Cluster-devel] [PATCH RESEND] gfs2: Return more useful errors from gfs2_rgrp_send_discards()

2022-04-19 Thread Andrew Price

On 05/04/2022 13:08, Andrew Price wrote:

The bug that 27ca8273f ("gfs2: Make sure FITRIM minlen is rounded up to
fs block size") fixes was a little confusing as the user saw
"Input/output error" which masked the -EINVAL that sb_issue_discard()
returned.

sb_issue_discard() can fail for various reasons, so we should return its
return value from gfs2_rgrp_send_discards() to avoid all errors being
reported as IO errors.

This improves error reporting for FITRIM and makes no difference to the
-o discard code path because the return value from
gfs2_rgrp_send_discards() gets thrown away in that case (and the option
switches off). Presumably that's why it was ok to just return -EIO in
the past, before FITRIM was implemented.

Tested with xfstests.


Can I get a thumbs-up or thumbs-down for this patch? It's pretty 
straightforward. I just don't want it to get forgotten about.


Cheers,
Andy


Signed-off-by: Andrew Price 
---

I don't see this in for-next yet so I've updated the commit log to include more
details.

  fs/gfs2/rgrp.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 801ad9f4f2be..886343cc05ab 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1315,7 +1315,7 @@ int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 
offset,
u64 blk;
sector_t start = 0;
sector_t nr_blks = 0;
-   int rv;
+   int rv = -EIO;
unsigned int x;
u32 trimmed = 0;
u8 diff;
@@ -1371,7 +1371,7 @@ int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 
offset,
if (sdp->sd_args.ar_discard)
fs_warn(sdp, "error %d on discard request, turning discards off for 
this filesystem\n", rv);
sdp->sd_args.ar_discard = 0;
-   return -EIO;
+   return rv;
  }
  
  /**




[Cluster-devel] [PATCH RESEND] gfs2: Return more useful errors from gfs2_rgrp_send_discards()

2022-04-05 Thread Andrew Price
The bug that 27ca8273f ("gfs2: Make sure FITRIM minlen is rounded up to
fs block size") fixes was a little confusing as the user saw
"Input/output error" which masked the -EINVAL that sb_issue_discard()
returned.

sb_issue_discard() can fail for various reasons, so we should return its
return value from gfs2_rgrp_send_discards() to avoid all errors being
reported as IO errors.

This improves error reporting for FITRIM and makes no difference to the
-o discard code path because the return value from
gfs2_rgrp_send_discards() gets thrown away in that case (and the option
switches off). Presumably that's why it was ok to just return -EIO in
the past, before FITRIM was implemented.

Tested with xfstests.

Signed-off-by: Andrew Price 
---

I don't see this in for-next yet so I've updated the commit log to include more
details.

 fs/gfs2/rgrp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 801ad9f4f2be..886343cc05ab 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1315,7 +1315,7 @@ int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 
offset,
u64 blk;
sector_t start = 0;
sector_t nr_blks = 0;
-   int rv;
+   int rv = -EIO;
unsigned int x;
u32 trimmed = 0;
u8 diff;
@@ -1371,7 +1371,7 @@ int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 
offset,
if (sdp->sd_args.ar_discard)
fs_warn(sdp, "error %d on discard request, turning discards off 
for this filesystem\n", rv);
sdp->sd_args.ar_discard = 0;
-   return -EIO;
+   return rv;
 }
 
 /**
-- 
2.35.1



[Cluster-devel] [PATCH] gfs2: Return more useful errors from gfs2_rgrp_send_discards()

2022-03-23 Thread Andrew Price
sb_issue_discard() can fail for various reasons, so we should return its
return value from gfs2_rgrp_send_discards() to avoid reporting them all
as IO errors.

Signed-off-by: Andrew Price 
---

 (As far as I can tell there are no limitations on which errno's can be set by 
ioctl(FITRIM) )

 fs/gfs2/rgrp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 0fb3c01bc557..58f791ed7139 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1313,7 +1313,7 @@ int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 
offset,
u64 blk;
sector_t start = 0;
sector_t nr_blks = 0;
-   int rv;
+   int rv = -EIO;
unsigned int x;
u32 trimmed = 0;
u8 diff;
@@ -1369,7 +1369,7 @@ int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 
offset,
if (sdp->sd_args.ar_discard)
fs_warn(sdp, "error %d on discard request, turning discards off 
for this filesystem\n", rv);
sdp->sd_args.ar_discard = 0;
-   return -EIO;
+   return rv;
 }
 
 /**
-- 
2.35.1



Re: [Cluster-devel] [PATCH] gfs2: Make sure FITRIM minlen is rounded up to fs block size

2022-03-22 Thread Andrew Price

On 22/03/2022 19:05, Andrew Price wrote:

Per fstrim(8) we must round up the minlen argument to the fs block size.
The current calculation doesn't take into account devices that have a
discard granularity and requested minlen less than 1 fs block, so the
value can get shifted away to zero in the translation to fs blocks.

The zero minlen passed to gfs2_rgrp_send_discards() then allows
sb_issue_discard() to be called with nr_sects == 0 which returns -EINVAL
and results in gfs2_rgrp_send_discards() returning -EIO.


Adding test results. xfstests interprets fstrim failures as "FITRIM not 
supported" and doesn't run them, so I got these results:


5.17:

Ran: generic/260 generic/288 generic/537
Not run: generic/260 generic/288 generic/537
Passed all 3 tests

5.17 + patch:

Ran: generic/260 generic/288 generic/537
Passed all 3 tests

(Those 3 tests are in the ones in the 'quick' and 'trim' groups)

Andy


Make sure minlen is never < 1 fs block by taking the max of the
requested minlen and the fs block size before comparing to the device's
discard granularity and shifting to fs blocks.

Fixes: 076f0faa764ab ("GFS2: Fix FITRIM argument handling")
Signed-off-by: Andrew Price 
---
  fs/gfs2/rgrp.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 0fb3c01bc557..a34945cbf32a 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1415,7 +1415,8 @@ int gfs2_fitrim(struct file *filp, void __user *argp)
  
  	start = r.start >> bs_shift;

end = start + (r.len >> bs_shift);
-   minlen = max_t(u64, r.minlen,
+   minlen = max_t(u64, r.minlen, sdp->sd_sb.sb_bsize);
+   minlen = max_t(u64, minlen,
   q->limits.discard_granularity) >> bs_shift;
  
  	if (end <= start || minlen > sdp->sd_max_rg_data)




[Cluster-devel] [PATCH] gfs2: Make sure FITRIM minlen is rounded up to fs block size

2022-03-22 Thread Andrew Price
Per fstrim(8) we must round up the minlen argument to the fs block size.
The current calculation doesn't take into account devices that have a
discard granularity and requested minlen less than 1 fs block, so the
value can get shifted away to zero in the translation to fs blocks.

The zero minlen passed to gfs2_rgrp_send_discards() then allows
sb_issue_discard() to be called with nr_sects == 0 which returns -EINVAL
and results in gfs2_rgrp_send_discards() returning -EIO.

Make sure minlen is never < 1 fs block by taking the max of the
requested minlen and the fs block size before comparing to the device's
discard granularity and shifting to fs blocks.

Fixes: 076f0faa764ab ("GFS2: Fix FITRIM argument handling")
Signed-off-by: Andrew Price 
---
 fs/gfs2/rgrp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 0fb3c01bc557..a34945cbf32a 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1415,7 +1415,8 @@ int gfs2_fitrim(struct file *filp, void __user *argp)
 
start = r.start >> bs_shift;
end = start + (r.len >> bs_shift);
-   minlen = max_t(u64, r.minlen,
+   minlen = max_t(u64, r.minlen, sdp->sd_sb.sb_bsize);
+   minlen = max_t(u64, minlen,
   q->limits.discard_granularity) >> bs_shift;
 
if (end <= start || minlen > sdp->sd_max_rg_data)
-- 
2.35.1



[Cluster-devel] [PATCH 21/21] libgfs2: Namespace improvements - struct rgrp_tree

2022-01-19 Thread Andrew Price
Rename to struct lgfs2_rgrp_tree.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c | 22 +--
 gfs2/edit/extended.c|  2 +-
 gfs2/edit/hexedit.c | 24 ++---
 gfs2/edit/journal.c |  8 +++
 gfs2/edit/savemeta.c|  8 +++
 gfs2/fsck/fs_recovery.c |  4 ++--
 gfs2/fsck/fsck.h|  6 +++---
 gfs2/fsck/initialize.c  | 18 
 gfs2/fsck/main.c|  4 ++--
 gfs2/fsck/metawalk.c|  6 +++---
 gfs2/fsck/metawalk.h|  2 +-
 gfs2/fsck/pass1.c   | 12 +--
 gfs2/fsck/pass5.c   |  6 +++---
 gfs2/fsck/rgrepair.c| 42 ++---
 gfs2/fsck/util.c|  4 ++--
 gfs2/fsck/util.h|  2 +-
 gfs2/libgfs2/fs_bits.c  |  2 +-
 gfs2/libgfs2/fs_ops.c   | 12 +--
 gfs2/libgfs2/lang.c |  4 ++--
 gfs2/libgfs2/libgfs2.h  | 20 +-
 gfs2/libgfs2/rgrp.c | 28 -
 gfs2/libgfs2/structures.c   |  6 +++---
 gfs2/libgfs2/super.c|  6 +++---
 23 files changed, 124 insertions(+), 124 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 104f9812..3eb1bf24 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -119,7 +119,7 @@ int print_level = MSG_NOTICE;
 /*   Fixes all unallocated metadata bitmap states (which are */
 /*   valid in gfs1 but invalid in gfs2). */
 /* - */
-static void convert_bitmaps(struct lgfs2_sbd *sdp, struct rgrp_tree *rg)
+static void convert_bitmaps(struct lgfs2_sbd *sdp, struct lgfs2_rgrp_tree *rg)
 {
uint32_t blk;
int x, y;
@@ -148,7 +148,7 @@ static void convert_bitmaps(struct lgfs2_sbd *sdp, struct 
rgrp_tree *rg)
 /* - */
 static int convert_rgs(struct lgfs2_sbd *sbp)
 {
-   struct rgrp_tree *rgd;
+   struct lgfs2_rgrp_tree *rgd;
struct osi_node *n, *next = NULL;
int rgs = 0;
 
@@ -157,7 +157,7 @@ static int convert_rgs(struct lgfs2_sbd *sbp)
/* - */
for (n = osi_first(>rgtree); n; n = next) {
next = osi_next(n);
-   rgd = (struct rgrp_tree *)n;
+   rgd = (struct lgfs2_rgrp_tree *)n;
 
rgd->rt_free = rgd->rt_free + rgd->rt_freemeta;
/* Zero it out so we don't add it again in case something 
breaks */
@@ -949,7 +949,7 @@ err_freei:
return -1;
 } /* adjust_inode */
 
-static int next_rg_meta(struct rgrp_tree *rgd, uint64_t *block, int first)
+static int next_rg_meta(struct lgfs2_rgrp_tree *rgd, uint64_t *block, int 
first)
 {
struct lgfs2_bitmap *bits = NULL;
uint32_t length = rgd->rt_length;
@@ -981,7 +981,7 @@ static int next_rg_meta(struct rgrp_tree *rgd, uint64_t 
*block, int first)
return 0;
 }
 
-static int next_rg_metatype(struct lgfs2_sbd *sdp, struct rgrp_tree *rgd,
+static int next_rg_metatype(struct lgfs2_sbd *sdp, struct lgfs2_rgrp_tree *rgd,
 uint64_t *block, uint32_t type, int first)
 {
struct lgfs2_buffer_head *bh = NULL;
@@ -1008,7 +1008,7 @@ static int next_rg_metatype(struct lgfs2_sbd *sdp, struct 
rgrp_tree *rgd,
 /* - */
 static int inode_renumber(struct lgfs2_sbd *sbp, uint64_t root_inode_addr, 
osi_list_t *cdpn_to_fix)
 {
-   struct rgrp_tree *rgd;
+   struct lgfs2_rgrp_tree *rgd;
struct osi_node *n, *next = NULL;
uint64_t block = 0;
struct lgfs2_buffer_head *bh;
@@ -1026,7 +1026,7 @@ static int inode_renumber(struct lgfs2_sbd *sbp, uint64_t 
root_inode_addr, osi_l
/*  */
for (n = osi_first(>rgtree); n; n = next) {
next = osi_next(n);
-   rgd = (struct rgrp_tree *)n;
+   rgd = (struct lgfs2_rgrp_tree *)n;
rgs_processed++;
first = 1;
while (1) {/* for all inodes in the resource group */
@@ -1519,7 +1519,7 @@ static int sanity_check(struct lgfs2_sbd *sdp)
  */
 static int gfs1_ri_update(struct lgfs2_sbd *sdp, int *rgcount, int quiet)
 {
-   struct rgrp_tree *rgd;
+   struct lgfs2_rgrp_tree *rgd;
uint64_t count1 = 0, count2 = 0;
uint64_t errblock = 0;
uint64_t rmax = 0;
@@ -1530,7 +1530,7 @@ static int gfs1_ri_update(struct lgfs2_sbd *sdp, int 
*rgcount, int quiet)
goto fail;
for (n = osi_first(>rgtree); n; n = next) {
next = osi_next(n);
-   rgd = (struct rgrp_tree *)n;
+   rgd = (struct lgfs2_rgrp_tree *)n;
/* Read resource group header */
   

[Cluster-devel] [PATCH 10/21] libgfs2: Remove revoke function declarations from libgfs2.h

2022-01-19 Thread Andrew Price
These functions are actually defined in fsck.gfs2 code and can be made
static.

Signed-off-by: Andrew Price 
---
 gfs2/fsck/fs_recovery.c | 14 +++---
 gfs2/libgfs2/libgfs2.h  |  4 
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/gfs2/fsck/fs_recovery.c b/gfs2/fsck/fs_recovery.c
index bd0fd731..5bd46301 100644
--- a/gfs2/fsck/fs_recovery.c
+++ b/gfs2/fsck/fs_recovery.c
@@ -33,7 +33,7 @@ struct gfs2_revoke_replay {
unsigned int rr_where;
 };
 
-int gfs2_revoke_add(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int where)
+static int revoke_add(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int where)
 {
osi_list_t *tmp, *head = _revoke_list;
struct gfs2_revoke_replay *rr;
@@ -62,7 +62,7 @@ int gfs2_revoke_add(struct gfs2_sbd *sdp, uint64_t blkno, 
unsigned int where)
return 1;
 }
 
-int gfs2_revoke_check(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int where)
+static int revoke_check(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int 
where)
 {
osi_list_t *tmp;
struct gfs2_revoke_replay *rr;
@@ -86,7 +86,7 @@ int gfs2_revoke_check(struct gfs2_sbd *sdp, uint64_t blkno, 
unsigned int where)
return (wrap) ? (a || b) : (a && b);
 }
 
-void gfs2_revoke_clean(struct gfs2_sbd *sdp)
+static void revoke_clean(struct gfs2_sbd *sdp)
 {
osi_list_t *head = _revoke_list;
struct gfs2_revoke_replay *rr;
@@ -144,7 +144,7 @@ static int buf_lo_scan_elements(struct gfs2_inode *ip, 
unsigned int start,
 
blkno = be64_to_cpu(*ptr);
ptr++;
-   if (gfs2_revoke_check(sdp, blkno, start))
+   if (revoke_check(sdp, blkno, start))
continue;
 
error = gfs2_replay_read_block(ip, start, _log);
@@ -213,7 +213,7 @@ static int revoke_lo_scan_elements(struct gfs2_inode *ip, 
unsigned int start,
blkno = be64_to_cpu(*(__be64 *)(bh->b_data + offset));
log_info(_("Journal replay processing revoke for block 
#%"PRIu64" (0x%"PRIx64") for journal+0x%x\n"),
 blkno, blkno, start);
-   error = gfs2_revoke_add(sdp, blkno, start);
+   error = revoke_add(sdp, blkno, start);
if (error < 0)
return error;
else if (error)
@@ -255,7 +255,7 @@ static int databuf_lo_scan_elements(struct gfs2_inode *ip, 
unsigned int start,
 
sd_found_jblocks++;
 
-   if (gfs2_revoke_check(sdp, blkno, start))
+   if (revoke_check(sdp, blkno, start))
continue;
 
error = gfs2_replay_read_block(ip, start, _log);
@@ -578,7 +578,7 @@ static int gfs2_recover_journal(struct gfs2_inode *ip, int 
j, int preen,
}
}
log_info( _("jid=%u: Found %u revoke tags\n"), j, sd_found_revokes);
-   gfs2_revoke_clean(sdp);
+   revoke_clean(sdp);
error = lgfs2_clean_journal(ip, );
if (error)
goto out;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 5c2f1aa7..e9e0c184 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -733,10 +733,6 @@ extern int lgfs2_open_mnt_dir(const char *path, int flags, 
struct mntent **mnt);
 extern void gfs2_replay_incr_blk(struct gfs2_inode *ip, unsigned int *blk);
 extern int gfs2_replay_read_block(struct gfs2_inode *ip, unsigned int blk,
  struct gfs2_buffer_head **bh);
-extern int gfs2_revoke_add(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int 
where);
-extern int gfs2_revoke_check(struct gfs2_sbd *sdp, uint64_t blkno,
-unsigned int where);
-extern void gfs2_revoke_clean(struct gfs2_sbd *sdp);
 extern int lgfs2_get_log_header(struct gfs2_inode *ip, unsigned int blk,
 struct lgfs2_log_header *head);
 extern int lgfs2_find_jhead(struct gfs2_inode *ip, struct lgfs2_log_header 
*head);
-- 
2.34.1



[Cluster-devel] [PATCH 12/21] libgfs2: Namespace improvements - device_geometry.c

2022-01-19 Thread Andrew Price
Use the lgfs2_ prefix in libgfs2 interface names.

Signed-off-by: Andrew Price 
---
 gfs2/edit/hexedit.c| 2 +-
 gfs2/fsck/rgrepair.c   | 2 +-
 gfs2/libgfs2/device_geometry.c | 2 +-
 gfs2/libgfs2/gfs2l.c   | 2 +-
 gfs2/libgfs2/libgfs2.h | 2 +-
 gfs2/mkfs/main_grow.c  | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index fc1b5f4f..3415b41f 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -909,7 +909,7 @@ static void read_superblock(int fd)
else {
block = starting_blk = 0;
}
-   fix_device_geometry();
+   lgfs2_fix_device_geometry();
if(sbd.gfs1) {
sbd.sd_inptrs = (sbd.sd_bsize - sizeof(struct gfs_indirect)) /
sizeof(uint64_t);
diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index 333a77a5..37d20aed 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -818,7 +818,7 @@ static int gfs2_rindex_calculate(struct gfs2_sbd *sdp, int 
*num_rgs)
*num_rgs = sdp->md.riinode->i_size / sizeof(struct gfs2_rindex);
 
rgcalc.osi_node = NULL;
-   fix_device_geometry(sdp);
+   lgfs2_fix_device_geometry(sdp);
 
/* Try all possible rgrp sizes: 2048, 1024, 512, 256, 128, 64, 32 */
for (sdp->rgsize = GFS2_DEFAULT_RGSIZE; sdp->rgsize >= 32;
diff --git a/gfs2/libgfs2/device_geometry.c b/gfs2/libgfs2/device_geometry.c
index cb1ed6d5..86ad84bd 100644
--- a/gfs2/libgfs2/device_geometry.c
+++ b/gfs2/libgfs2/device_geometry.c
@@ -92,7 +92,7 @@ size_check:
  *
  */
 
-void fix_device_geometry(struct gfs2_sbd *sdp)
+void lgfs2_fix_device_geometry(struct gfs2_sbd *sdp)
 {
struct device *device = >device;
 
diff --git a/gfs2/libgfs2/gfs2l.c b/gfs2/libgfs2/gfs2l.c
index a247bed2..b8c4ca41 100644
--- a/gfs2/libgfs2/gfs2l.c
+++ b/gfs2/libgfs2/gfs2l.c
@@ -130,7 +130,7 @@ static int openfs(const char *path, struct gfs2_sbd *sdp)
perror("Failed to gather device info");
return 1;
}
-   fix_device_geometry(sdp);
+   lgfs2_fix_device_geometry(sdp);
 
ret = lgfs2_read_sb(sdp);
if (ret != 0) {
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index d091e180..39097e68 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -473,7 +473,7 @@ extern uint32_t lgfs2_get_block_type(const char *buf);
 
 /* device_geometry.c */
 extern int lgfs2_get_dev_info(int fd, struct lgfs2_dev_info *i);
-extern void fix_device_geometry(struct gfs2_sbd *sdp);
+extern void lgfs2_fix_device_geometry(struct gfs2_sbd *sdp);
 
 /* fs_bits.c */
 #define BFITNOENT (0x)
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 298ba2a6..b2959285 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -406,7 +406,7 @@ int main(int argc, char *argv[])
fprintf(stderr, _("cannot grow gfs1 filesystem\n"));
exit(EXIT_FAILURE);
}
-   fix_device_geometry(sdp);
+   lgfs2_fix_device_geometry(sdp);
mfs.context = copy_context_opt(mnt);
if (mount_gfs2_meta(, mnt->mnt_dir, (print_level > 
MSG_NOTICE))) {
perror(_("Failed to mount GFS2 meta file system"));
-- 
2.34.1



[Cluster-devel] [PATCH 08/21] libgfs2: Namespace improvements - super.c

2022-01-19 Thread Andrew Price
Use the lgfs2_ prefix in libgfs2 interface names.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c |  2 +-
 gfs2/edit/hexedit.c |  2 +-
 gfs2/edit/savemeta.c|  2 +-
 gfs2/fsck/initialize.c  |  6 +++---
 gfs2/fsck/rgrepair.c|  2 +-
 gfs2/libgfs2/gfs2l.c|  4 ++--
 gfs2/libgfs2/libgfs2.h  |  8 
 gfs2/libgfs2/super.c| 14 +++---
 gfs2/mkfs/main_grow.c   |  2 +-
 tests/nukerg.c  |  2 +-
 10 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 1608b1ad..c6b388a6 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -1526,7 +1526,7 @@ static int gfs1_ri_update(struct gfs2_sbd *sdp, int 
*rgcount, int quiet)
struct osi_node *n, *next = NULL;
int ok;
 
-   if (rindex_read(sdp, , ))
+   if (lgfs2_rindex_read(sdp, , ))
goto fail;
for (n = osi_first(>rgtree); n; n = next) {
next = osi_next(n);
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index b0f110c1..fc1b5f4f 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -939,7 +939,7 @@ static int read_rindex(void)
 
sbd.fssize = sbd.device.length;
if (sbd.md.riinode) /* If we found the rindex */
-   rindex_read(, , );
+   lgfs2_rindex_read(, , );
 
if (!OSI_EMPTY_ROOT()) {
struct rgrp_tree *rg = (struct rgrp_tree 
*)osi_last();
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 21c67989..ffb11342 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -1254,7 +1254,7 @@ static int restore_super(struct metafd *mfd, void *buf, 
int printonly)
int ret;
 
lgfs2_sb_in(, buf);
-   ret = check_sb(buf);
+   ret = lgfs2_check_sb(buf);
if (ret < 0) {
fprintf(stderr, "Error: Invalid superblock in metadata 
file.\n");
return -1;
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index 18522a35..2740fa7d 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -721,7 +721,7 @@ static int fetch_rgrps_level(struct gfs2_sbd *sdp, enum 
rgindex_trust_level lvl,
if (rindex_repair(sdp, lvl, ok) != 0)
goto fail;
 
-   if (rindex_read(sdp, count, ok) != 0 || !*ok)
+   if (lgfs2_rindex_read(sdp, count, ok) != 0 || !*ok)
goto fail;
 
ret = read_rgrps(sdp, *count);
@@ -1345,12 +1345,12 @@ static int fill_super_block(struct gfs2_sbd *sdp)
log_crit("%s\n", _("Failed to compute file system constants"));
return FSCK_ERROR;
}
-   ret = read_sb(sdp);
+   ret = lgfs2_read_sb(sdp);
if (ret < 0) {
if (sb_repair(sdp) != 0)
return -1; /* unrepairable, so exit */
/* Now that we've tried to repair it, re-read it. */
-   ret = read_sb(sdp);
+   ret = lgfs2_read_sb(sdp);
if (ret < 0)
return FSCK_ERROR;
}
diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index 8c2dd35d..333a77a5 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -999,7 +999,7 @@ int rindex_repair(struct gfs2_sbd *sdp, int trust_lvl, int 
*ok)
}
/* Read in the rindex */
sdp->rgtree.osi_node = NULL; /* Just to be safe */
-   rindex_read(sdp, >rgrps, ok);
+   lgfs2_rindex_read(sdp, >rgrps, ok);
if (sdp->md.riinode->i_size % sizeof(struct gfs2_rindex)) {
log_warn( _("WARNING: rindex file has an invalid size.\n"));
if (!query( _("Truncate the rindex size? (y/n)"))) {
diff --git a/gfs2/libgfs2/gfs2l.c b/gfs2/libgfs2/gfs2l.c
index 2ec4a1a1..a247bed2 100644
--- a/gfs2/libgfs2/gfs2l.c
+++ b/gfs2/libgfs2/gfs2l.c
@@ -132,7 +132,7 @@ static int openfs(const char *path, struct gfs2_sbd *sdp)
}
fix_device_geometry(sdp);
 
-   ret = read_sb(sdp);
+   ret = lgfs2_read_sb(sdp);
if (ret != 0) {
perror("Could not read sb");
return 1;
@@ -142,7 +142,7 @@ static int openfs(const char *path, struct gfs2_sbd *sdp)
lgfs2_lookupi(sdp->master_dir, "rindex", 6, >md.riinode);
sdp->fssize = sdp->device.length;
if (sdp->md.riinode) {
-   rindex_read(sdp, , );
+   lgfs2_rindex_read(sdp, , );
} else {
perror("Failed to look up rindex");
return 1;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index b204b763..aede5cda 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -778,10 +778,10 @@ extern struct gfs2_inode 
*lgfs2_build_statfs_change(struct gfs2_inode *per_node,
 extern struct gfs2_inode *lgfs2_build_quota_c

[Cluster-devel] [PATCH 01/21] libgfs2: Namespace improvements - structures.c

2022-01-19 Thread Andrew Price
Use the lgfs2_ prefix in libgfs2 interface names.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c | 28 ++--
 gfs2/edit/hexedit.c |  6 ++---
 gfs2/edit/savemeta.c|  2 +-
 gfs2/fsck/fs_recovery.c | 10 +++
 gfs2/fsck/initialize.c  | 24 -
 gfs2/fsck/main.c|  2 +-
 gfs2/fsck/metawalk.c|  8 +++---
 gfs2/fsck/pass1.c   | 52 ++---
 gfs2/fsck/pass2.c   | 30 ++---
 gfs2/fsck/pass5.c   |  2 +-
 gfs2/fsck/rgrepair.c| 10 +++
 gfs2/libgfs2/fs_ops.c   |  6 ++---
 gfs2/libgfs2/libgfs2.h  | 33 ---
 gfs2/libgfs2/rgrp.c |  2 +-
 gfs2/libgfs2/structures.c   | 40 ++--
 gfs2/libgfs2/super.c|  2 +-
 gfs2/mkfs/main_mkfs.c   | 22 
 17 files changed, 139 insertions(+), 140 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index dc011d05..07fa9a10 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -817,7 +817,7 @@ static int fix_xattr(struct gfs2_sbd *sbp, struct 
gfs2_buffer_head *bh, struct g
 
/* Read in the i_eattr block */
eabh = bread(sbp, ip->i_eattr);
-if (!gfs2_check_meta(eabh->b_data, GFS_METATYPE_IN)) {/* if it is an 
indirect block */
+if (!lgfs2_check_meta(eabh->b_data, GFS_METATYPE_IN)) {/* if it is an 
indirect block */
len = sbp->sd_bsize - sizeof(struct gfs_indirect);
buf = malloc(len);
if (!buf) {
@@ -993,7 +993,7 @@ static int next_rg_metatype(struct gfs2_sbd *sdp, struct 
rgrp_tree *rgd,
return -1;
bh = bread(sdp, *block);
first = 0;
-   } while(gfs2_check_meta(bh->b_data, type));
+   } while(lgfs2_check_meta(bh->b_data, type));
brelse(bh);
return 0;
 }
@@ -1052,7 +1052,7 @@ static int inode_renumber(struct gfs2_sbd *sbp, uint64_t 
root_inode_addr, osi_li
sbp->sd_root_dir.in_formal_ino = 
sbp->md.next_inum;
}
bh = bread(sbp, block);
-   if (!gfs2_check_meta(bh->b_data, GFS_METATYPE_DI)) {/* 
if it is an dinode */
+   if (!lgfs2_check_meta(bh->b_data, GFS_METATYPE_DI)) {/* 
if it is an dinode */
/* Skip the rindex and jindex inodes for now. */
if (block != rindex_addr && block != 
jindex_addr) {
error = adjust_inode(sbp, bh);
@@ -1982,8 +1982,8 @@ static int conv_build_jindex(struct gfs2_sbd *sdp)
sprintf(name, "journal%u", j);
sdp->md.journal[j] = createi(sdp->md.jiinode, name, S_IFREG |
 0600, GFS2_DIF_SYSTEM);
-   write_journal(sdp->md.journal[j], sdp->sd_bsize,
- sdp->jsize << 20 >> sdp->sd_bsize_shift);
+   lgfs2_write_journal(sdp->md.journal[j], sdp->sd_bsize,
+   sdp->jsize << 20 >> sdp->sd_bsize_shift);
inode_put(>md.journal[j]);
printf(_("done.\n"));
fflush(stdout);
@@ -2100,7 +2100,7 @@ static int build_per_node(struct gfs2_sbd *sdp)
for (j = 0; j < sdp->md.journals; j++) {
struct gfs2_inode *ip;
 
-   ip = build_inum_range(per_node, j);
+   ip = lgfs2_build_inum_range(per_node, j);
if (ip == NULL) {
log_crit(_("Error building '%s': %s\n"), "inum_range",
 strerror(errno));
@@ -2108,7 +2108,7 @@ static int build_per_node(struct gfs2_sbd *sdp)
}
inode_put();
 
-   ip = build_statfs_change(per_node, j);
+   ip = lgfs2_build_statfs_change(per_node, j);
if (ip == NULL) {
log_crit(_("Error building '%s': %s\n"), 
"statfs_change",
 strerror(errno));
@@ -2116,7 +2116,7 @@ static int build_per_node(struct gfs2_sbd *sdp)
}
inode_put();
 
-   ip = build_quota_change(per_node, j);
+   ip = lgfs2_build_quota_change(per_node, j);
if (ip == NULL) {
log_crit(_("Error building '%s': %s\n"), "quota_change",
 strerror(errno));
@@ -2314,7 +2314,7 @@ int main(int argc, char **argv)
log_notice(_("Reduced journal size to %u MB to 
accommodate "
   "GFS2 file system structures.\n"), 
sb2.jsize

[Cluster-devel] [PATCH 02/21] libgfs2: Namespace improvements - buf.c

2022-01-19 Thread Andrew Price
Use the lgfs2_ prefix in libgfs2 interface names.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c   |  76 +++
 gfs2/edit/extended.c  |  26 ++---
 gfs2/edit/gfs2hex.c   |   4 +-
 gfs2/edit/hexedit.c   |  48 +-
 gfs2/edit/journal.c   |  40 
 gfs2/fsck/afterpass1_common.c |   8 +-
 gfs2/fsck/fs_recovery.c   |  62 ++--
 gfs2/fsck/initialize.c|  44 -
 gfs2/fsck/lost_n_found.c  |   6 +-
 gfs2/fsck/metawalk.c  |  44 -
 gfs2/fsck/pass1.c |  58 +--
 gfs2/fsck/pass1b.c|  40 
 gfs2/fsck/pass2.c |  76 +++
 gfs2/fsck/pass4.c |   6 +-
 gfs2/fsck/pass5.c |   4 +-
 gfs2/fsck/rgrepair.c  |  44 -
 gfs2/libgfs2/buf.c|  18 ++--
 gfs2/libgfs2/fs_ops.c | 176 +-
 gfs2/libgfs2/gfs1.c   |  28 +++---
 gfs2/libgfs2/libgfs2.h|  16 ++--
 gfs2/libgfs2/recovery.c   |  10 +-
 gfs2/libgfs2/structures.c |  24 ++---
 gfs2/libgfs2/super.c  |  10 +-
 23 files changed, 434 insertions(+), 434 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 07fa9a10..5bfe8acd 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -285,15 +285,15 @@ static void fix_metatree(struct gfs2_sbd *sbp, struct 
gfs2_inode *ip,
new = 0;
lookup_block(ip, bh, h, >mp, 1, , );
if (bh != ip->i_bh)
-   brelse(bh);
+   lgfs2_brelse(bh);
if (!block)
break;
 
-   bh = bread(sbp, block);
+   bh = lgfs2_bread(sbp, block);
if (new)
memset(bh->b_data, 0, sbp->sd_bsize);
memcpy(bh->b_data, , sizeof(mh));
-   bmodified(bh);
+   lgfs2_bmodified(bh);
}
 
hdrsize = blk->height ? sizeof(struct gfs2_meta_header) :
@@ -304,9 +304,9 @@ static void fix_metatree(struct gfs2_sbd *sbp, struct 
gfs2_inode *ip,
 
memcpy(bh->b_data + hdrsize + ptramt, (char *)srcptr, amount);
srcptr += amount;
-   bmodified(bh);
+   lgfs2_bmodified(bh);
if (bh != ip->i_bh)
-   brelse(bh);
+   lgfs2_brelse(bh);
 
copied += amount;
 
@@ -443,16 +443,16 @@ static uint64_t fix_jdatatree(struct gfs2_sbd *sbp, 
struct gfs2_inode *ip,
new = 0;
lookup_block(ip, bh, h, >mp, 1, , );
if (bh != ip->i_bh)
-   brelse(bh);
+   lgfs2_brelse(bh);
if (!block)
break;
 
-   bh = bread(sbp, block);
+   bh = lgfs2_bread(sbp, block);
if (new)
memset(bh->b_data, 0, sbp->sd_bsize);
if (h < (blk->height - 1)) {
memcpy(bh->b_data, , sizeof(mh));
-   bmodified(bh);
+   lgfs2_bmodified(bh);
}
}
 
@@ -461,9 +461,9 @@ static uint64_t fix_jdatatree(struct gfs2_sbd *sbp, struct 
gfs2_inode *ip,
 
memcpy(bh->b_data + ptramt, (char *)srcptr, amount);
srcptr += amount;
-   bmodified(bh);
+   lgfs2_bmodified(bh);
if (bh != ip->i_bh)
-   brelse(bh);
+   lgfs2_brelse(bh);
 
copied += amount;
 
@@ -554,12 +554,12 @@ static int get_inode_metablocks(struct gfs2_sbd *sbp, 
struct gfs2_inode *ip, str
/* Queue it to be processed later on in the loop. */
osi_list_add_prev(>list, >list);
/* read the new metadata block's pointers */
-   bh = bread(sbp, block);
+   bh = lgfs2_bread(sbp, block);
memcpy(newblk->ptrbuf, bh->b_data + sizeof(struct 
gfs_indirect), bufsize);
/* Zero the buffer so we can fill it in later */
memset(bh->b_data + sizeof(struct gfs_indirect), 0, 
bufsize);
-   bmodified(bh);
-   brelse(bh);
+   lgfs2_bmodified(bh);
+   lgfs2_brelse(bh);
/* Free the block so we can reuse it. This allows us to
   convert a "full" file system. */
 

[Cluster-devel] [PATCH 20/21] libgfs2: Namespace improvements - constants

2022-01-19 Thread Andrew Price
Use the LGFS2_ prefix for preprocessor #defines.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c | 12 ++--
 gfs2/edit/hexedit.c | 12 ++--
 gfs2/fsck/fs_recovery.c |  4 ++--
 gfs2/fsck/initialize.c  | 20 ++--
 gfs2/fsck/rgrepair.c|  6 +++---
 gfs2/libgfs2/fs_bits.c  |  2 +-
 gfs2/libgfs2/fs_ops.c   | 12 ++--
 gfs2/libgfs2/libgfs2.h  | 29 +
 gfs2/libgfs2/rgrp.c |  6 +++---
 gfs2/libgfs2/structures.c   |  2 +-
 gfs2/libgfs2/super.c|  4 ++--
 gfs2/mkfs/main_grow.c   | 10 +-
 gfs2/mkfs/main_jadd.c   |  4 ++--
 gfs2/mkfs/main_mkfs.c   | 24 
 gfs2/tune/super.c   |  6 +++---
 15 files changed, 75 insertions(+), 78 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 50df7f5f..104f9812 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -970,7 +970,7 @@ static int next_rg_meta(struct rgrp_tree *rgd, uint64_t 
*block, int first)
bits = >bits[i];
blk = lgfs2_bitfit((uint8_t *)bits->bi_data + bits->bi_offset,
   bits->bi_len, blk, GFS2_BLKST_DINODE);
-   if(blk != BFITNOENT){
+   if(blk != LGFS2_BFITNOENT){
*block = blk + (bits->bi_start * GFS2_NBBY) + 
rgd->rt_data0;
break;
}
@@ -1132,7 +1132,7 @@ static int process_dirent_info(struct lgfs2_inode *dip, 
struct lgfs2_sbd *sbp,
int de; /* directory entry index */

error = lgfs2_dirent_first(dip, bh, );
-   if (error != IS_LEAF && error != IS_DINODE) {
+   if (error != LGFS2_IS_LEAF && error != LGFS2_IS_DINODE) {
log_crit(_("Error retrieving directory.\n"));
return -1;
}
@@ -1576,14 +1576,14 @@ static int init(struct lgfs2_sbd *sbp, struct 
gfs2_options *opts)
/* -- */
/* Initialize lists and read in the superblock.   */
/* -- */
-   sbp->jsize = GFS2_DEFAULT_JSIZE;
-   sbp->rgsize = GFS2_DEFAULT_RGSIZE;
-   sbp->qcsize = GFS2_DEFAULT_QCSIZE;
+   sbp->jsize = LGFS2_DEFAULT_JSIZE;
+   sbp->rgsize = LGFS2_DEFAULT_RGSIZE;
+   sbp->qcsize = LGFS2_DEFAULT_QCSIZE;
sbp->sd_time = time(NULL);
sbp->blks_total = 0;   /* total blocks - total them up later */
sbp->blks_alloced = 0; /* blocks allocated - total them up later */
sbp->dinodes_alloced = 0; /* dinodes allocated - total them up later */
-   sbp->sd_bsize = GFS2_DEFAULT_BSIZE;
+   sbp->sd_bsize = LGFS2_DEFAULT_BSIZE;
sbp->rgtree.osi_node = NULL;
if (lgfs2_compute_constants(sbp)) {
log_crit("%s\n", _("Failed to compute file system constants"));
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 90140391..9a90587f 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -874,12 +874,12 @@ static void read_superblock(int fd)
 
ioctl(fd, BLKFLSBUF, 0);
memset(, 0, sizeof(struct lgfs2_sbd));
-   sbd.sd_bsize = GFS2_DEFAULT_BSIZE;
+   sbd.sd_bsize = LGFS2_DEFAULT_BSIZE;
sbd.device_fd = fd;
bh = lgfs2_bread(, 0x10);
-   sbd.jsize = GFS2_DEFAULT_JSIZE;
-   sbd.rgsize = GFS2_DEFAULT_RGSIZE;
-   sbd.qcsize = GFS2_DEFAULT_QCSIZE;
+   sbd.jsize = LGFS2_DEFAULT_JSIZE;
+   sbd.rgsize = LGFS2_DEFAULT_RGSIZE;
+   sbd.qcsize = LGFS2_DEFAULT_QCSIZE;
sbd.sd_time = time(NULL);
sbd.rgtree.osi_node = NULL;
lgfs2_sb_in(, bh->b_data);
@@ -894,7 +894,7 @@ static void read_superblock(int fd)
else
sbd.gfs1 = FALSE;
if (!sbd.sd_bsize)
-   sbd.sd_bsize = GFS2_DEFAULT_BSIZE;
+   sbd.sd_bsize = LGFS2_DEFAULT_BSIZE;
if (lgfs2_get_dev_info(fd, )) {
perror(device);
exit(-1);
@@ -905,7 +905,7 @@ static void read_superblock(int fd)
}
if (sbd.gfs1 || (be32_to_cpu(mh->mh_magic) == GFS2_MAGIC &&
 be32_to_cpu(mh->mh_type) == GFS2_METATYPE_SB))
-   block = 0x10 * (GFS2_DEFAULT_BSIZE / sbd.sd_bsize);
+   block = 0x10 * (LGFS2_DEFAULT_BSIZE / sbd.sd_bsize);
else {
block = starting_blk = 0;
}
diff --git a/gfs2/fsck/fs_recovery.c b/gfs2/fsck/fs_recovery.c
index 45bd213a..f65c4a33 100644
--- a/gfs2/fsck/fs_recovery.c
+++ b/gfs2/fsck/fs_recovery.c
@@ -683,7 +683,7 @@ int replay_journals(struct lgfs2_sbd *sdp, int preen, int 
force_check,
 
*clean_journals = 0;
 
-   sdp->jsize = GFS2_DEFAULT_JSIZE;
+   sdp->jsize = LGFS2_DEFAULT_JSIZE;
 
for(i = 0; i

[Cluster-devel] [PATCH 15/21] libgfs2: Namespace improvements - struct gfs2_sbd

2022-01-19 Thread Andrew Price
Rename to struct lgfs2_sbd.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c| 76 +++---
 gfs2/edit/gfs2hex.c|  2 +-
 gfs2/edit/hexedit.c|  2 +-
 gfs2/edit/hexedit.h|  2 +-
 gfs2/edit/journal.c|  2 +-
 gfs2/edit/savemeta.c   |  6 +--
 gfs2/fsck/afterpass1_common.c  |  4 +-
 gfs2/fsck/afterpass1_common.h  |  2 +-
 gfs2/fsck/fs_recovery.c| 26 +--
 gfs2/fsck/fs_recovery.h| 10 ++--
 gfs2/fsck/fsck.h   | 30 ++--
 gfs2/fsck/initialize.c | 50 ++--
 gfs2/fsck/lost_n_found.c   |  6 +--
 gfs2/fsck/main.c   |  8 ++--
 gfs2/fsck/metawalk.c   | 22 -
 gfs2/fsck/metawalk.h   |  6 +--
 gfs2/fsck/pass1.c  | 50 ++--
 gfs2/fsck/pass1b.c | 16 +++
 gfs2/fsck/pass2.c  | 22 -
 gfs2/fsck/pass3.c  |  6 +--
 gfs2/fsck/pass4.c  | 12 ++---
 gfs2/fsck/pass5.c  |  6 +--
 gfs2/fsck/rgrepair.c   | 26 +--
 gfs2/fsck/util.c   |  2 +-
 gfs2/fsck/util.h   |  6 +--
 gfs2/glocktop/glocktop.c   |  6 +--
 gfs2/libgfs2/buf.c |  8 ++--
 gfs2/libgfs2/check_ondisk.c|  6 +--
 gfs2/libgfs2/check_rgrp.c  |  4 +-
 gfs2/libgfs2/device_geometry.c |  2 +-
 gfs2/libgfs2/fs_bits.c |  4 +-
 gfs2/libgfs2/fs_ops.c  | 52 ++---
 gfs2/libgfs2/gfs1.c| 10 ++--
 gfs2/libgfs2/gfs2l.c   |  4 +-
 gfs2/libgfs2/lang.c| 22 -
 gfs2/libgfs2/lang.h|  2 +-
 gfs2/libgfs2/libgfs2.h | 84 +-
 gfs2/libgfs2/misc.c|  2 +-
 gfs2/libgfs2/ondisk.c  |  4 +-
 gfs2/libgfs2/rgrp.c| 20 
 gfs2/libgfs2/rgrp.h|  2 +-
 gfs2/libgfs2/structures.c  | 26 +--
 gfs2/libgfs2/super.c   |  8 ++--
 gfs2/mkfs/main_grow.c  | 16 +++
 gfs2/mkfs/main_jadd.c  | 18 
 gfs2/mkfs/main_mkfs.c  | 22 -
 tests/nukerg.c | 10 ++--
 47 files changed, 366 insertions(+), 366 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 06815380..e1c6a3c6 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -95,7 +95,7 @@ struct gfs2_options {
 };
 
 static struct gfs_sb gfs1_sb;
-static struct gfs2_sbd sb2;
+static struct lgfs2_sbd sb2;
 static struct inode_block dirs_to_fix;  /* linked list of directories to fix */
 static struct inode_dir_block cdpns_to_fix; /* linked list of cdpn symlinks */
 static int seconds;
@@ -119,7 +119,7 @@ int print_level = MSG_NOTICE;
 /*   Fixes all unallocated metadata bitmap states (which are */
 /*   valid in gfs1 but invalid in gfs2). */
 /* - */
-static void convert_bitmaps(struct gfs2_sbd *sdp, struct rgrp_tree *rg)
+static void convert_bitmaps(struct lgfs2_sbd *sdp, struct rgrp_tree *rg)
 {
uint32_t blk;
int x, y;
@@ -146,7 +146,7 @@ static void convert_bitmaps(struct gfs2_sbd *sdp, struct 
rgrp_tree *rg)
 /* convert_rgs - Convert gfs1 resource groups to gfs2.   */
 /* Returns: 0 on success, -1 on failure  */
 /* - */
-static int convert_rgs(struct gfs2_sbd *sbp)
+static int convert_rgs(struct lgfs2_sbd *sbp)
 {
struct rgrp_tree *rgd;
struct osi_node *n, *next = NULL;
@@ -218,7 +218,7 @@ static unsigned int calc_gfs2_tree_height(struct 
lgfs2_inode *ip, uint64_t size)
 /* - */
 /* mp_gfs1_to_gfs2 - convert a gfs1 metapath to a gfs2 metapath. */
 /* - */
-static void mp_gfs1_to_gfs2(struct gfs2_sbd *sbp, int gfs1_h, int gfs2_h,
+static void mp_gfs1_to_gfs2(struct lgfs2_sbd *sbp, int gfs1_h, int gfs2_h,
 struct metapath *gfs1mp, struct metapath *gfs2mp)
 {
uint64_t lblock;
@@ -258,7 +258,7 @@ static void mp_gfs1_to_gfs2(struct gfs2_sbd *sbp, int 
gfs1_h, int gfs2_h,
 /*interested in rearranging the metadata while leaving the   */
 /*actual data blocks intact. */
 /* - */
-static void fix_metatree(struct gfs2_sbd *sbp, struct lgfs2_inode *ip,
+static void fix_metatree(struct lgfs2_sbd *sbp, struct lgfs2_inode *ip,
  struct blocklist *blk, __be64 *first_nonzero_ptr,
  unsigned int size)
 {
@@ -377,7 +377,7 @@ static void fix_metatree(struct gfs2_sbd *sbp, struct 
lgfs2_inode *ip,
 /* Adapted from

[Cluster-devel] [PATCH 18/21] libgfs2: Namespace improvements - struct device

2022-01-19 Thread Andrew Price
Rename to struct lgfs2_device.

Signed-off-by: Andrew Price 
---
 gfs2/fsck/rgrepair.c   | 4 ++--
 gfs2/libgfs2/device_geometry.c | 2 +-
 gfs2/libgfs2/libgfs2.h | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index 5bfbb7da..b74eaa4a 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -696,7 +696,7 @@ out:
  *
  * Returns: the number of RGs
  */
-static uint64_t how_many_rgrps(struct lgfs2_sbd *sdp, struct device *dev)
+static uint64_t how_many_rgrps(struct lgfs2_sbd *sdp, struct lgfs2_device *dev)
 {
uint64_t nrgrp;
uint32_t rgblocks1, rgblocksn, bitblocks1, bitblocksn;
@@ -732,7 +732,7 @@ static uint64_t how_many_rgrps(struct lgfs2_sbd *sdp, 
struct device *dev)
  */
 static struct osi_root compute_rgrp_layout(struct lgfs2_sbd *sdp)
 {
-   struct device *dev;
+   struct lgfs2_device *dev;
struct rgrp_tree *rl, *rlast = NULL;
unsigned int rgrp = 0, nrgrp, rglength;
struct osi_root rgtree = {NULL};
diff --git a/gfs2/libgfs2/device_geometry.c b/gfs2/libgfs2/device_geometry.c
index c6c00c95..1950d017 100644
--- a/gfs2/libgfs2/device_geometry.c
+++ b/gfs2/libgfs2/device_geometry.c
@@ -94,7 +94,7 @@ size_check:
 
 void lgfs2_fix_device_geometry(struct lgfs2_sbd *sdp)
 {
-   struct device *device = >device;
+   struct lgfs2_device *device = >device;
 
device->length = sdp->dinfo.size / sdp->sd_bsize;
 }
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 3673182b..2fc831e4 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -156,7 +156,7 @@ struct lgfs2_dev_info {
uint64_t size;
 };
 
-struct device {
+struct lgfs2_device {
uint64_t length;
 };
 
@@ -361,7 +361,7 @@ struct lgfs2_sbd {
int64_t sd_time;
 
struct lgfs2_dev_info dinfo;
-   struct device device;
+   struct lgfs2_device device;
 
int device_fd;
int path_fd;
-- 
2.34.1



[Cluster-devel] [PATCH 19/21] libgfs2: Namespace improvements - struct gfs2_bitmap

2022-01-19 Thread Andrew Price
Rename to struct lgfs2_bitmap.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c |  6 +++---
 gfs2/edit/hexedit.c |  2 +-
 gfs2/fsck/pass5.c   |  2 +-
 gfs2/libgfs2/fs_bits.c  |  4 ++--
 gfs2/libgfs2/fs_ops.c   |  2 +-
 gfs2/libgfs2/libgfs2.h  |  4 ++--
 gfs2/libgfs2/rgrp.c | 12 ++--
 gfs2/libgfs2/rgrp.h |  2 +-
 gfs2/libgfs2/structures.c   |  2 +-
 9 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index f6c7d3a7..50df7f5f 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -126,7 +126,7 @@ static void convert_bitmaps(struct lgfs2_sbd *sdp, struct 
rgrp_tree *rg)
unsigned char state;
 
for (blk = 0; blk < rg->rt_length; blk++) {
-   struct gfs2_bitmap *bi;
+   struct lgfs2_bitmap *bi;
x = (blk) ? sizeof(struct gfs2_meta_header) :
sizeof(struct gfs2_rgrp);
 
@@ -951,7 +951,7 @@ err_freei:
 
 static int next_rg_meta(struct rgrp_tree *rgd, uint64_t *block, int first)
 {
-   struct gfs2_bitmap *bits = NULL;
+   struct lgfs2_bitmap *bits = NULL;
uint32_t length = rgd->rt_length;
uint32_t blk = (first)? 0: (uint32_t)((*block + 1) - rgd->rt_data0);
int i;
@@ -1070,7 +1070,7 @@ static int inode_renumber(struct lgfs2_sbd *sbp, uint64_t 
root_inode_addr, osi_l
byte_bit = (block - rgd->rt_data0) % GFS2_NBBY;
/* Now figure out which bitmap block the byte 
is on */
for (blk = 0; blk < rgd->rt_length; blk++) {
-   struct gfs2_bitmap *bi = 
>bits[blk];
+   struct lgfs2_bitmap *bi = 
>bits[blk];
/* figure out offset of first bitmap 
byte for this map: */
buf_offset = (blk) ? sizeof(struct 
gfs2_meta_header) :
sizeof(struct gfs2_rgrp);
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 17ed5062..90140391 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -1610,7 +1610,7 @@ static void find_print_block_rg(int bitmap)
if (rgd) {
rgblock = rgd->rt_addr;
if (bitmap) {
-   struct gfs2_bitmap *bits = NULL;
+   struct lgfs2_bitmap *bits = NULL;
 
for (i = 0; i < rgd->rt_length; i++) {
bits = &(rgd->bits[i]);
diff --git a/gfs2/fsck/pass5.c b/gfs2/fsck/pass5.c
index 55ede8db..302ebaf2 100644
--- a/gfs2/fsck/pass5.c
+++ b/gfs2/fsck/pass5.c
@@ -117,7 +117,7 @@ static void update_rgrp(struct lgfs2_sbd *sdp, struct 
rgrp_tree *rgp,
struct gfs2_bmap *bl, uint32_t *count)
 {
uint32_t i;
-   struct gfs2_bitmap *bits;
+   struct lgfs2_bitmap *bits;
uint64_t rg_block = 0;
int update = 0;
 
diff --git a/gfs2/libgfs2/fs_bits.c b/gfs2/libgfs2/fs_bits.c
index b95732ef..a75c1aa5 100644
--- a/gfs2/libgfs2/fs_bits.c
+++ b/gfs2/libgfs2/fs_bits.c
@@ -127,7 +127,7 @@ int lgfs2_set_bitmap(lgfs2_rgrp_t rgd, uint64_t blkno, int 
state)
 {
int   buf;
uint32_trgrp_block;
-   struct gfs2_bitmap *bits = NULL;
+   struct lgfs2_bitmap *bits = NULL;
unsigned char *byte, cur_state;
unsigned int bit;
 
@@ -180,7 +180,7 @@ int lgfs2_get_bitmap(struct lgfs2_sbd *sdp, uint64_t blkno, 
struct rgrp_tree *rg
uint32_t i = 0;
char *byte;
unsigned int bit;
-   struct gfs2_bitmap *bi;
+   struct lgfs2_bitmap *bi;
 
if (rgd == NULL) {
rgd = lgfs2_blk2rgrpd(sdp, blkno);
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 0f94c09b..9083b811 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -119,7 +119,7 @@ static uint64_t find_free_block(struct rgrp_tree *rgd)
 
for (bm = 0; bm < rgd->rt_length; bm++) {
unsigned long blk = 0;
-   struct gfs2_bitmap *bits = >bits[bm];
+   struct lgfs2_bitmap *bits = >bits[bm];
 
blk = lgfs2_bitfit((uint8_t *)bits->bi_data + bits->bi_offset,
  bits->bi_len, blk, GFS2_BLKST_FREE);
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 2fc831e4..1fc04926 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -160,7 +160,7 @@ struct lgfs2_device {
uint64_t length;
 };
 
-struct gfs2_bitmap
+struct lgfs2_bitmap
 {
char *bi_data;
uint32_t bi_offset;  /* The offset in the buffer of the first byte */
@@ -175,7 +175,7 @@ typedef struct _lgfs2_rgrps *lgfs2_rgrps_t;
 
 struct rgrp

[Cluster-devel] [PATCH 17/21] libgfs2: Namespace improvements - struct master_dir

2022-01-19 Thread Andrew Price
Rename to struct lgfs2_meta_dir.

Signed-off-by: Andrew Price 
---
 gfs2/fsck/initialize.c | 2 +-
 gfs2/libgfs2/libgfs2.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index 2bde52ab..ec9a8eef 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -32,7 +32,7 @@
 
 static int was_mounted_ro = 0;
 static uint64_t possible_root = HIGHEST_BLOCK;
-static struct master_dir fix_md;
+static struct lgfs2_meta_dir fix_md;
 static uint64_t blks_2free = 0;
 
 /**
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 00deb455..3673182b 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -300,7 +300,7 @@ struct lgfs2_inode {
};
 };
 
-struct master_dir
+struct lgfs2_meta_dir
 {
struct lgfs2_inode *inum;
uint64_t next_inum;
@@ -375,7 +375,7 @@ struct lgfs2_sbd {
struct osi_root rgtree;
 
struct lgfs2_inode *master_dir;
-   struct master_dir md;
+   struct lgfs2_meta_dir md;
 
unsigned int gfs1:1;
 };
-- 
2.34.1



[Cluster-devel] [PATCH 16/21] libgfs2: Namespace improvements - struct metapath

2022-01-19 Thread Andrew Price
Rename to struct lgfs2_metapath.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c | 14 +++---
 gfs2/edit/extended.c|  4 ++--
 gfs2/edit/hexedit.c |  4 ++--
 gfs2/edit/hexedit.h |  4 ++--
 gfs2/libgfs2/fs_ops.c   | 12 ++--
 gfs2/libgfs2/gfs1.c |  6 +++---
 gfs2/libgfs2/libgfs2.h  |  8 
 7 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index e1c6a3c6..f6c7d3a7 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -82,7 +82,7 @@ struct inode_block {
 struct blocklist {
osi_list_t list;
uint64_t block;
-   struct metapath mp;
+   struct lgfs2_metapath mp;
int height;
char *ptrbuf;
 };
@@ -219,7 +219,7 @@ static unsigned int calc_gfs2_tree_height(struct 
lgfs2_inode *ip, uint64_t size)
 /* mp_gfs1_to_gfs2 - convert a gfs1 metapath to a gfs2 metapath. */
 /* - */
 static void mp_gfs1_to_gfs2(struct lgfs2_sbd *sbp, int gfs1_h, int gfs2_h,
-struct metapath *gfs1mp, struct metapath *gfs2mp)
+struct lgfs2_metapath *gfs1mp, struct lgfs2_metapath 
*gfs2mp)
 {
uint64_t lblock;
int h;
@@ -378,7 +378,7 @@ static void fix_metatree(struct lgfs2_sbd *sbp, struct 
lgfs2_inode *ip,
 /* - */
 
 static void jdata_mp_gfs1_to_gfs2(struct lgfs2_sbd *sbp, int gfs1_h, int 
gfs2_h,
-  struct metapath *gfs1mp, struct metapath *gfs2mp,
+  struct lgfs2_metapath *gfs1mp, struct lgfs2_metapath 
*gfs2mp,
   unsigned int *len, uint64_t dinode_size)
 {
uint64_t offset;
@@ -575,7 +575,7 @@ static int fix_ind_reg_or_dir(struct lgfs2_sbd *sbp, struct 
lgfs2_inode *ip, uin
unsigned int len, bufsize;
__be64 *ptr1, *ptr2;
int ptrnum;
-   struct metapath gfs2mp;
+   struct lgfs2_metapath gfs2mp;
 
bufsize = sbp->sd_bsize - sizeof(struct gfs_indirect);
len = bufsize;
@@ -601,7 +601,7 @@ static int fix_ind_reg_or_dir(struct lgfs2_sbd *sbp, struct 
lgfs2_inode *ip, uin
}
blk->mp.mp_list[di_height - 1] = ptrnum;
mp_gfs1_to_gfs2(sbp, di_height, gfs2_hgt, >mp, );
-   memcpy(>mp, , sizeof(struct metapath));
+   memcpy(>mp, , sizeof(struct lgfs2_metapath));
blk->height -= di_height - gfs2_hgt;
if (len) {
fix_metatree(sbp, ip, blk, ptr1, len);
@@ -621,7 +621,7 @@ static int fix_ind_jdata(struct lgfs2_sbd *sbp, struct 
lgfs2_inode *ip, uint32_t
uint64_t block;
__be64 *ptr1;
int ptrnum, h;
-   struct metapath gfs2mp;
+   struct lgfs2_metapath gfs2mp;
struct lgfs2_buffer_head *bh;
 
bufsize = sbp->sd_bsize - sizeof(struct gfs2_meta_header);
@@ -670,7 +670,7 @@ static int fix_ind_jdata(struct lgfs2_sbd *sbp, struct 
lgfs2_inode *ip, uint32_t
len = bufsize;
jdata_mp_gfs1_to_gfs2(sbp, di_height, gfs2_hgt, >mp, 
,
  , dinode_size);
-   memcpy(>mp, , sizeof(struct metapath));
+   memcpy(>mp, , sizeof(struct lgfs2_metapath));
newblk->height -= di_height - gfs2_hgt;
if (len)
ip->i_goal_meta = fix_jdatatree(sbp, ip, newblk,
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index 98c0dfce..81548939 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -97,7 +97,7 @@ static int dinode_valid(void)
return 0;
 }
 
-static uint64_t metapath_to_lblock(struct metapath *mp, int hgt)
+static uint64_t metapath_to_lblock(struct lgfs2_metapath *mp, int hgt)
 {
int h;
uint64_t lblock = 0;
@@ -401,7 +401,7 @@ static void print_block_details(struct iinfo *ind, int 
level, int cur_height,
for (x = 0; x < 512; x++) {
memcpy(_indir->ii[x].mp,
   >ii[pndx].mp,
-  sizeof(struct metapath));
+  sizeof(struct lgfs2_metapath));
more_indir->ii[x].mp.mp_list[cur_height+1] = x;
}
more_ind = _do_indirect_extended(tmpbuf, more_indir,
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 4eb1a839..17ed5062 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -1032,7 +1032,7 @@ int display(int identify_only, int trunc_zeros, uint64_t 
flagref,
for (i = 0; i < 512; i++)
memcpy(>ii[i].mp,
   [blockhist - 1].mp,
-  

[Cluster-devel] [PATCH 13/21] libgfs2: Namespace improvements - struct gfs2_inode

2022-01-19 Thread Andrew Price
Rename to struct lgfs2_inode.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c   |  46 ++--
 gfs2/edit/extended.c  |  14 ++--
 gfs2/edit/hexedit.c   |   4 +-
 gfs2/edit/journal.c   |   8 +--
 gfs2/edit/savemeta.c  |   4 +-
 gfs2/fsck/afterpass1_common.c |  24 +++
 gfs2/fsck/afterpass1_common.h |  12 ++--
 gfs2/fsck/fs_recovery.c   |  28 
 gfs2/fsck/fsck.h  |  10 +--
 gfs2/fsck/initialize.c|  20 +++---
 gfs2/fsck/link.c  |   6 +-
 gfs2/fsck/link.h  |   4 +-
 gfs2/fsck/lost_n_found.c  |   8 +--
 gfs2/fsck/lost_n_found.h  |   4 +-
 gfs2/fsck/main.c  |   2 +-
 gfs2/fsck/metawalk.c  |  58 +++
 gfs2/fsck/metawalk.h  |  48 ++---
 gfs2/fsck/pass1.c | 112 ++---
 gfs2/fsck/pass1b.c|  34 -
 gfs2/fsck/pass2.c |  74 +--
 gfs2/fsck/pass3.c |   4 +-
 gfs2/fsck/pass4.c |   6 +-
 gfs2/fsck/rgrepair.c  |   2 +-
 gfs2/fsck/util.c  |  10 +--
 gfs2/fsck/util.h  |  14 ++--
 gfs2/glocktop/glocktop.c  |   4 +-
 gfs2/libgfs2/fs_ops.c |  98 -
 gfs2/libgfs2/gfs1.c   |  22 +++---
 gfs2/libgfs2/lang.c   |   2 +-
 gfs2/libgfs2/libgfs2.h| 130 +-
 gfs2/libgfs2/ondisk.c |   4 +-
 gfs2/libgfs2/recovery.c   |  14 ++--
 gfs2/libgfs2/rgrp.c   |   2 +-
 gfs2/libgfs2/structures.c |  44 ++--
 gfs2/mkfs/main_mkfs.c |  10 +--
 35 files changed, 443 insertions(+), 443 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index c6b388a6..21611b1a 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -186,7 +186,7 @@ static int convert_rgs(struct gfs2_sbd *sbp)
 /* This is similar to lgfs2_calc_tree_height in libgfs2 but at the point this  
*/
 /* function is called, I have the wrong (gfs1 not gfs2) constants in place.  */
 /* - */
-static unsigned int calc_gfs2_tree_height(struct gfs2_inode *ip, uint64_t size)
+static unsigned int calc_gfs2_tree_height(struct lgfs2_inode *ip, uint64_t 
size)
 {
uint64_t *arr;
unsigned int max, height;
@@ -258,7 +258,7 @@ static void mp_gfs1_to_gfs2(struct gfs2_sbd *sbp, int 
gfs1_h, int gfs2_h,
 /*interested in rearranging the metadata while leaving the   */
 /*actual data blocks intact. */
 /* - */
-static void fix_metatree(struct gfs2_sbd *sbp, struct gfs2_inode *ip,
+static void fix_metatree(struct gfs2_sbd *sbp, struct lgfs2_inode *ip,
  struct blocklist *blk, __be64 *first_nonzero_ptr,
  unsigned int size)
 {
@@ -416,7 +416,7 @@ static void jdata_mp_gfs1_to_gfs2(struct gfs2_sbd *sbp, int 
gfs1_h, int gfs2_h,
}
 }
 
-static uint64_t fix_jdatatree(struct gfs2_sbd *sbp, struct gfs2_inode *ip,
+static uint64_t fix_jdatatree(struct gfs2_sbd *sbp, struct lgfs2_inode *ip,
  struct blocklist *blk, char *srcptr,
  unsigned int size)
 {
@@ -485,7 +485,7 @@ static uint64_t fix_jdatatree(struct gfs2_sbd *sbp, struct 
gfs2_inode *ip,
return block;
 }
 
-static int get_inode_metablocks(struct gfs2_sbd *sbp, struct gfs2_inode *ip, 
struct blocklist *blocks)
+static int get_inode_metablocks(struct gfs2_sbd *sbp, struct lgfs2_inode *ip, 
struct blocklist *blocks)
 {
struct blocklist *blk, *newblk;
struct gfs2_buffer_head *bh, *dibh = ip->i_bh;
@@ -569,7 +569,7 @@ static int get_inode_metablocks(struct gfs2_sbd *sbp, 
struct gfs2_inode *ip, str
return 0;
 }
 
-static int fix_ind_reg_or_dir(struct gfs2_sbd *sbp, struct gfs2_inode *ip, 
uint32_t di_height,
+static int fix_ind_reg_or_dir(struct gfs2_sbd *sbp, struct lgfs2_inode *ip, 
uint32_t di_height,
   uint32_t gfs2_hgt, struct blocklist *blk, struct 
blocklist *blocks)
 {
unsigned int len, bufsize;
@@ -611,7 +611,7 @@ static int fix_ind_reg_or_dir(struct gfs2_sbd *sbp, struct 
gfs2_inode *ip, uint3
return 0;
 }
 
-static int fix_ind_jdata(struct gfs2_sbd *sbp, struct gfs2_inode *ip, uint32_t 
di_height, 
+static int fix_ind_jdata(struct gfs2_sbd *sbp, struct lgfs2_inode *ip, 
uint32_t di_height, 
  uint32_t gfs2_hgt, uint64_t dinode_size, struct blocklist 
*blk, 
  struct blocklist *blocks)
 {
@@ -681,7 +681,7 @@ static int fix_ind_jdata(struct gfs2_sbd *sbp, struct 
gfs2_inode *ip, uint32_t d
return 0;
 }
 
-static int adjust_indirect_blocks(struct gfs2_sbd *sbp, struct gfs2_inode *ip)
+static int adjust_indirect_blocks(struct gfs2_sbd *sbp, struct lgfs2_inode 

[Cluster-devel] [PATCH 14/21] libgfs2: Namespace improvements - struct gfs2_buffer_head

2022-01-19 Thread Andrew Price
Rename to struct lgfs2_buffer_head.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c   | 30 +++---
 gfs2/edit/extended.c  |  2 +-
 gfs2/edit/gfs2hex.c   |  2 +-
 gfs2/edit/hexedit.c   | 20 +-
 gfs2/edit/journal.c   | 14 +++
 gfs2/fsck/afterpass1_common.c | 18 -
 gfs2/fsck/afterpass1_common.h | 12 +++---
 gfs2/fsck/fs_recovery.c   | 18 -
 gfs2/fsck/fsck.h  |  2 +-
 gfs2/fsck/initialize.c| 14 +++
 gfs2/fsck/metawalk.c  | 50 +++
 gfs2/fsck/metawalk.h  | 22 +--
 gfs2/fsck/pass1.c | 68 
 gfs2/fsck/pass1b.c| 28 ++---
 gfs2/fsck/pass2.c | 40 +--
 gfs2/fsck/pass5.c |  2 +-
 gfs2/fsck/rgrepair.c  | 12 +++---
 gfs2/libgfs2/buf.c| 18 -
 gfs2/libgfs2/fs_ops.c | 74 +--
 gfs2/libgfs2/gfs1.c   |  8 ++--
 gfs2/libgfs2/libgfs2.h| 34 
 gfs2/libgfs2/recovery.c   |  6 +--
 gfs2/libgfs2/structures.c | 12 +++---
 gfs2/libgfs2/super.c  |  4 +-
 24 files changed, 255 insertions(+), 255 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 21611b1a..06815380 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -263,7 +263,7 @@ static void fix_metatree(struct gfs2_sbd *sbp, struct 
lgfs2_inode *ip,
  unsigned int size)
 {
uint64_t block;
-   struct gfs2_buffer_head *bh;
+   struct lgfs2_buffer_head *bh;
unsigned int amount, ptramt;
int hdrsize, h, copied = 0, new;
struct gfs2_meta_header mh = {0};
@@ -421,7 +421,7 @@ static uint64_t fix_jdatatree(struct gfs2_sbd *sbp, struct 
lgfs2_inode *ip,
  unsigned int size)
 {
uint64_t block;
-   struct gfs2_buffer_head *bh;
+   struct lgfs2_buffer_head *bh;
unsigned int amount, ptramt;
int h, copied = 0, new = 0;
struct gfs2_meta_header mh = {0};
@@ -488,7 +488,7 @@ static uint64_t fix_jdatatree(struct gfs2_sbd *sbp, struct 
lgfs2_inode *ip,
 static int get_inode_metablocks(struct gfs2_sbd *sbp, struct lgfs2_inode *ip, 
struct blocklist *blocks)
 {
struct blocklist *blk, *newblk;
-   struct gfs2_buffer_head *bh, *dibh = ip->i_bh;
+   struct lgfs2_buffer_head *bh, *dibh = ip->i_bh;
osi_list_t *tmp;
uint64_t block;
__be64 *ptr1;
@@ -622,7 +622,7 @@ static int fix_ind_jdata(struct gfs2_sbd *sbp, struct 
lgfs2_inode *ip, uint32_t
__be64 *ptr1;
int ptrnum, h;
struct metapath gfs2mp;
-   struct gfs2_buffer_head *bh;
+   struct lgfs2_buffer_head *bh;
 
bufsize = sbp->sd_bsize - sizeof(struct gfs2_meta_header);
/*
@@ -774,7 +774,7 @@ static int has_cdpn(const char *str)
return 0;
 }
 
-static int fix_cdpn_symlink(struct gfs2_sbd *sbp, struct gfs2_buffer_head *bh, 
struct lgfs2_inode *ip)
+static int fix_cdpn_symlink(struct gfs2_sbd *sbp, struct lgfs2_buffer_head 
*bh, struct lgfs2_inode *ip)
 {
char *linkptr = NULL;
 
@@ -809,10 +809,10 @@ static int fix_cdpn_symlink(struct gfs2_sbd *sbp, struct 
gfs2_buffer_head *bh, s
  * to fix the header. gfs1 uses gfs_indirect as the header which is 64 bytes
  * bigger than gfs2_meta_header that gfs2 uses.
  */
-static int fix_xattr(struct gfs2_sbd *sbp, struct gfs2_buffer_head *bh, struct 
lgfs2_inode *ip)
+static int fix_xattr(struct gfs2_sbd *sbp, struct lgfs2_buffer_head *bh, 
struct lgfs2_inode *ip)
 {
int len, old_hdr_sz, new_hdr_sz;
-   struct gfs2_buffer_head *eabh;
+   struct lgfs2_buffer_head *eabh;
char *buf;
 
/* Read in the i_eattr block */
@@ -843,7 +843,7 @@ static int fix_xattr(struct gfs2_sbd *sbp, struct 
gfs2_buffer_head *bh, struct l
 /*   */
 /* Returns: 0 on success, -1 on failure  */
 /* - */
-static int adjust_inode(struct gfs2_sbd *sbp, struct gfs2_buffer_head *bh)
+static int adjust_inode(struct gfs2_sbd *sbp, struct lgfs2_buffer_head *bh)
 {
struct lgfs2_inode *inode;
struct inode_block *fixdir;
@@ -984,7 +984,7 @@ static int next_rg_meta(struct rgrp_tree *rgd, uint64_t 
*block, int first)
 static int next_rg_metatype(struct gfs2_sbd *sdp, struct rgrp_tree *rgd,
 uint64_t *block, uint32_t type, int first)
 {
-   struct gfs2_buffer_head *bh = NULL;
+   struct lgfs2_buffer_head *bh = NULL;
 
do{
if (bh)
@@ -1011,7 +1011,7 @@ static int inode_renumber(struct gfs2_sbd *sbp, uint64_t 
root_inode_addr, osi_li
struct rgrp_tree *rgd;
struct osi_node *n, *next = NULL;
uint6

[Cluster-devel] [PATCH 11/21] libgfs2: Namespace improvements - recovery.c

2022-01-19 Thread Andrew Price
Use the lgfs2_ prefix in libgfs2 interface names.

Signed-off-by: Andrew Price 
---
 gfs2/fsck/fs_recovery.c | 22 +++---
 gfs2/libgfs2/libgfs2.h  |  4 ++--
 gfs2/libgfs2/recovery.c |  8 
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/gfs2/fsck/fs_recovery.c b/gfs2/fsck/fs_recovery.c
index 5bd46301..4a2d1259 100644
--- a/gfs2/fsck/fs_recovery.c
+++ b/gfs2/fsck/fs_recovery.c
@@ -135,9 +135,9 @@ static int buf_lo_scan_elements(struct gfs2_inode *ip, 
unsigned int start,
if (pass != 1 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_METADATA)
return 0;
 
-   gfs2_replay_incr_blk(ip, );
+   lgfs2_replay_incr_blk(ip, );
 
-   for (; blks; gfs2_replay_incr_blk(ip, ), blks--) {
+   for (; blks; lgfs2_replay_incr_blk(ip, ), blks--) {
struct gfs2_meta_header *mhp;
 
sd_found_metablocks++;
@@ -147,7 +147,7 @@ static int buf_lo_scan_elements(struct gfs2_inode *ip, 
unsigned int start,
if (revoke_check(sdp, blkno, start))
continue;
 
-   error = gfs2_replay_read_block(ip, start, _log);
+   error = lgfs2_replay_read_block(ip, start, _log);
if (error)
return error;
 
@@ -200,8 +200,8 @@ static int revoke_lo_scan_elements(struct gfs2_inode *ip, 
unsigned int start,
 
offset = sizeof(struct gfs2_log_descriptor);
 
-   for (; blks; gfs2_replay_incr_blk(ip, ), blks--) {
-   error = gfs2_replay_read_block(ip, start, );
+   for (; blks; lgfs2_replay_incr_blk(ip, ), blks--) {
+   error = lgfs2_replay_read_block(ip, start, );
if (error)
return error;
 
@@ -246,8 +246,8 @@ static int databuf_lo_scan_elements(struct gfs2_inode *ip, 
unsigned int start,
if (pass != 1 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_JDATA)
return 0;
 
-   gfs2_replay_incr_blk(ip, );
-   for (; blks; gfs2_replay_incr_blk(ip, ), blks--) {
+   lgfs2_replay_incr_blk(ip, );
+   for (; blks; lgfs2_replay_incr_blk(ip, ), blks--) {
blkno = be64_to_cpu(*ptr);
ptr++;
esc = be64_to_cpu(*ptr);
@@ -258,7 +258,7 @@ static int databuf_lo_scan_elements(struct gfs2_inode *ip, 
unsigned int start,
if (revoke_check(sdp, blkno, start))
continue;
 
-   error = gfs2_replay_read_block(ip, start, _log);
+   error = lgfs2_replay_read_block(ip, start, _log);
if (error)
return error;
 
@@ -313,7 +313,7 @@ static int foreach_descriptor(struct gfs2_inode *ip, 
unsigned int start,
while (start != end) {
struct gfs2_meta_header *mhp;
 
-   error = gfs2_replay_read_block(ip, start, );
+   error = lgfs2_replay_read_block(ip, start, );
if (error)
return error;
mhp = (struct gfs2_meta_header *)bh->b_data;
@@ -330,7 +330,7 @@ static int foreach_descriptor(struct gfs2_inode *ip, 
unsigned int start,
 
error = lgfs2_get_log_header(ip, start, );
if (!error) {
-   gfs2_replay_incr_blk(ip, );
+   lgfs2_replay_incr_blk(ip, );
lgfs2_bmodified(bh);
lgfs2_brelse(bh);
continue;
@@ -369,7 +369,7 @@ static int foreach_descriptor(struct gfs2_inode *ip, 
unsigned int start,
}
 
while (length--)
-   gfs2_replay_incr_blk(ip, );
+   lgfs2_replay_incr_blk(ip, );
 
lgfs2_bmodified(bh);
lgfs2_brelse(bh);
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index e9e0c184..d091e180 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -730,8 +730,8 @@ extern int lgfs2_open_mnt_dev(const char *path, int flags, 
struct mntent **mnt);
 extern int lgfs2_open_mnt_dir(const char *path, int flags, struct mntent 
**mnt);
 
 /* recovery.c */
-extern void gfs2_replay_incr_blk(struct gfs2_inode *ip, unsigned int *blk);
-extern int gfs2_replay_read_block(struct gfs2_inode *ip, unsigned int blk,
+extern void lgfs2_replay_incr_blk(struct gfs2_inode *ip, unsigned int *blk);
+extern int lgfs2_replay_read_block(struct gfs2_inode *ip, unsigned int blk,
  struct gfs2_buffer_head **bh);
 extern int lgfs2_get_log_header(struct gfs2_inode *ip, unsigned int blk,
 struct lgfs2_log_header *head);
diff --git a/gfs2/libgfs2/recovery.c b/gfs2/libgfs2/recovery.c
index 3984e1e3..483661e4 100644
--- a/gfs2/libgfs2/recovery.c
+++ b/gfs2/libgfs2/recovery.c
@@ -14,7 +14,7 @@
 #include 
 #include "libgfs2.h"
 
-void gfs2_replay_incr_blk(struct gfs2_inode *ip

[Cluster-devel] [PATCH 07/21] libgfs2: Namespace improvements - rgrp.c

2022-01-19 Thread Andrew Price
Use the lgfs2_ prefix in libgfs2 interface names.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c | 10 +++---
 gfs2/edit/hexedit.c | 60 +-
 gfs2/edit/journal.c |  2 +-
 gfs2/edit/savemeta.c|  2 +-
 gfs2/fsck/fs_recovery.c |  2 +-
 gfs2/fsck/fsck.h|  2 +-
 gfs2/fsck/initialize.c  |  6 ++--
 gfs2/fsck/metawalk.c|  2 +-
 gfs2/fsck/pass1.c   |  2 +-
 gfs2/fsck/pass5.c   |  4 +--
 gfs2/fsck/rgrepair.c| 64 ++---
 gfs2/fsck/util.h|  2 +-
 gfs2/libgfs2/fs_bits.c  |  2 +-
 gfs2/libgfs2/fs_ops.c   |  8 ++---
 gfs2/libgfs2/gfs2l.c|  2 +-
 gfs2/libgfs2/lang.c |  6 ++--
 gfs2/libgfs2/libgfs2.h  | 22 +
 gfs2/libgfs2/rgrp.c | 22 ++---
 gfs2/libgfs2/super.c|  4 +--
 19 files changed, 109 insertions(+), 115 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 90964ae1..1608b1ad 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -1532,7 +1532,7 @@ static int gfs1_ri_update(struct gfs2_sbd *sdp, int 
*rgcount, int quiet)
next = osi_next(n);
rgd = (struct rgrp_tree *)n;
/* Read resource group header */
-   errblock = gfs2_rgrp_read(sdp, rgd);
+   errblock = lgfs2_rgrp_read(sdp, rgd);
if (errblock)
return errblock;
count2++;
@@ -1552,7 +1552,7 @@ static int gfs1_ri_update(struct gfs2_sbd *sdp, int 
*rgcount, int quiet)
return 0;
 
  fail:
-   gfs2_rgrp_free(sdp, >rgtree);
+   lgfs2_rgrp_free(sdp, >rgtree);
return -1;
 }
 
@@ -1848,7 +1848,7 @@ static int journ_space_to_rg(struct gfs2_sbd *sdp)
 ji_addr, rgdhigh->rt_addr);
ri_addr = ji_addr;
/* Allocate a new rgd entry which includes rg and ri. */
-   rgd = rgrp_insert(>rgtree, ri_addr);
+   rgd = lgfs2_rgrp_insert(>rgtree, ri_addr);
/* convert the gfs1 rgrp into a new gfs2 rgrp */
size = ji_nsegs * be32_to_cpu(gfs1_sb.sb_seg_size);
rgd->rt_flags = 0;
@@ -1866,7 +1866,7 @@ static int journ_space_to_rg(struct gfs2_sbd *sdp)
rgd->rt_free = rgd->rt_data;
rgd->rt_bitbytes = rgd->rt_data / GFS2_NBBY;
 
-   if (gfs2_compute_bitstructs(sdp->sd_bsize, rgd)) {
+   if (lgfs2_compute_bitstructs(sdp->sd_bsize, rgd)) {
log_crit(_("gfs2_convert: Error converting 
bitmaps.\n"));
exit(-1);
}
@@ -2382,7 +2382,7 @@ int main(int argc, char **argv)
fsync(sb2.device_fd); /* write the buffers to disk */
 
/* Now free all the in memory */
-   gfs2_rgrp_free(, );
+   lgfs2_rgrp_free(, );
log_notice(_("Committing changes to disk.\n"));
fflush(stdout);
/* Set filesystem type in superblock to gfs2.  We do this at 
the */
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index ffb714bf..b0f110c1 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -350,9 +350,9 @@ int display_block_type(char *buf, uint64_t addr, int 
from_restore)
int type;
struct rgrp_tree *rgd;
 
-   rgd = gfs2_blk2rgrpd(, block);
+   rgd = lgfs2_blk2rgrpd(, block);
if (rgd) {
-   gfs2_rgrp_read(, rgd);
+   lgfs2_rgrp_read(, rgd);
if ((be32_to_cpu(mh->mh_type) == GFS2_METATYPE_RG) ||
(be32_to_cpu(mh->mh_type) == GFS2_METATYPE_RB))
type = 4;
@@ -428,7 +428,7 @@ int display_block_type(char *buf, uint64_t addr, int 
from_restore)
}
}
if (rgd)
-   gfs2_rgrp_relse(, rgd);
+   lgfs2_rgrp_relse(, rgd);
}
if (block == sbd.sd_root_dir.in_addr)
print_gfs2("--- Root directory --");
@@ -693,7 +693,7 @@ static void rgcount(void)
printf("%"PRId64" RGs in this file system.\n",
   sbd.md.riinode->i_size / sizeof(struct gfs2_rindex));
lgfs2_inode_put();
-   gfs2_rgrp_free(, );
+   lgfs2_rgrp_free(, );
exit(EXIT_SUCCESS);
 }
 
@@ -1154,7 +1154,7 @@ static uint64_t find_metablockoftype_slow(uint64_t 
startblk, int metatype, int p
else
printf("%"PRIu64"\n", blk);
}
-   gfs2_rgrp_free(, );
+   lgfs2_rgrp_free(, );
if (print)
exit(0);
return blk;
@@ -121

[Cluster-devel] [PATCH 09/21] libgfs2: Namespace improvements - gfs2_disk_hash.c

2022-01-19 Thread Andrew Price
Use the lgfs2_ prefix in libgfs2 interface names.

Signed-off-by: Andrew Price 
---
 gfs2/fsck/pass2.c |  2 +-
 gfs2/libgfs2/fs_ops.c | 12 ++--
 gfs2/libgfs2/gfs2_disk_hash.c |  5 ++---
 gfs2/libgfs2/libgfs2.h|  7 +++
 gfs2/libgfs2/rgrp.c   |  4 ++--
 gfs2/libgfs2/structures.c |  2 +-
 6 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 3d732772..d394f6bf 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -470,7 +470,7 @@ static int basic_dentry_checks(struct gfs2_inode *ip, 
struct gfs2_dirent *dent,
return 1;
}
 
-   calculated_hash = gfs2_disk_hash(tmp_name, d->dr_name_len);
+   calculated_hash = lgfs2_disk_hash(tmp_name, d->dr_name_len);
if (d->dr_hash != calculated_hash){
log_err( _("Dir entry with bad hash or name length\n"
   "\tHash found = %u (0x%x)\n"
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 4e10ab4f..4e3736ca 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -1148,7 +1148,7 @@ static int dir_e_add(struct gfs2_inode *dip, const char 
*filename, int len,
uint64_t leaf_no, bn;
int err = 0;
 
-   hash = gfs2_disk_hash(filename, len);
+   hash = lgfs2_disk_hash(filename, len);
 restart:
/* Have to kludge because (hash >> 32) gives hash for some reason. */
if (dip->i_depth)
@@ -1313,7 +1313,7 @@ static int dir_l_add(struct gfs2_inode *dip, const char 
*filename, int len,
}
 
lgfs2_inum_out(inum, >de_inum);
-   de_hash = gfs2_disk_hash(filename, len);
+   de_hash = lgfs2_disk_hash(filename, len);
dent->de_hash = cpu_to_be32(de_hash);
dent->de_type = cpu_to_be16(type);
memcpy((char *)(dent + 1), filename, len);
@@ -1376,7 +1376,7 @@ static int __init_dinode(struct gfs2_sbd *sdp, struct 
gfs2_buffer_head **bhp, st
uint32_t hash;
uint16_t len;
 
-   hash = gfs2_disk_hash(".", 1);
+   hash = lgfs2_disk_hash(".", 1);
len = GFS2_DIRENT_SIZE(1);
de.de_inum = di->di_num;
de.de_hash = cpu_to_be32(hash);
@@ -1387,7 +1387,7 @@ static int __init_dinode(struct gfs2_sbd *sdp, struct 
gfs2_buffer_head **bhp, st
p[sizeof(de)] = '.';
p += len;
 
-   hash = gfs2_disk_hash("..", 2);
+   hash = lgfs2_disk_hash("..", 2);
len = sdp->sd_bsize - (p - bh->b_data);
de.de_inum.no_formal_ino = cpu_to_be64(parent->in_formal_ino);
de.de_inum.no_addr = cpu_to_be64(parent->in_addr);
@@ -1598,7 +1598,7 @@ static int leaf_search(struct gfs2_inode *dip, struct 
gfs2_buffer_head *bh,
else
return -1;
 
-   hash = gfs2_disk_hash(filename, len);
+   hash = lgfs2_disk_hash(filename, len);
 
do{
if (!dent->de_inum.no_formal_ino){
@@ -1650,7 +1650,7 @@ static int linked_leaf_search(struct gfs2_inode *dip, 
const char *filename,
 
/*  Figure out the address of the leaf node.  */
 
-   hash = gfs2_disk_hash(filename, len);
+   hash = lgfs2_disk_hash(filename, len);
lindex = hash >> (32 - dip->i_depth);
 
error = get_first_leaf(dip, lindex, _next);
diff --git a/gfs2/libgfs2/gfs2_disk_hash.c b/gfs2/libgfs2/gfs2_disk_hash.c
index 959f5ddc..07632a28 100644
--- a/gfs2/libgfs2/gfs2_disk_hash.c
+++ b/gfs2/libgfs2/gfs2_disk_hash.c
@@ -40,7 +40,7 @@ static const uint32_t crc_32_tab[] =
 };
 
 /**
- * gfs2_disk_hash - hash an array of data
+ * lgfs2_disk_hash - hash an array of data
  * @data: the data to be hashed
  * @len: the length of data to be hashed
  *
@@ -59,7 +59,7 @@ static const uint32_t crc_32_tab[] =
  * Returns: the hash
  */
 
-uint32_t gfs2_disk_hash(const char *data, int len)
+uint32_t lgfs2_disk_hash(const char *data, int len)
 {
uint32_t hash = 0x;
 
@@ -71,4 +71,3 @@ uint32_t gfs2_disk_hash(const char *data, int len)
return hash;
 }
 
-
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index aede5cda..5c2f1aa7 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -783,11 +783,10 @@ extern int lgfs2_read_sb(struct gfs2_sbd *sdp);
 extern int lgfs2_rindex_read(struct gfs2_sbd *sdp, uint64_t *rgcount, int *ok);
 extern int lgfs2_write_sb(struct gfs2_sbd *sdp);
 
-/* ondisk.c */
-extern uint32_t gfs2_disk_hash(const char *data, int len);
-
-/* Translation functions */
+/* gfs2_disk_hash.c */
+extern uint32_t lgfs2_disk_hash(const char *data, int len);
 
+/* ondisk.c */
 extern void lgfs2_inum_in(struct lgfs2_inum *i, void *inp);
 extern void lgfs2_inum_out(const struct lgfs2_inum *i, void *inp);
 extern void lgfs2_sb_in(struct gfs2_sbd *sdp, void *buf);
diff

[Cluster-devel] [PATCH 05/21] libgfs2: Namespace improvements - gfs1.c

2022-01-19 Thread Andrew Price
Use the lgfs2_ prefix in libgfs2 interface names.

Signed-off-by: Andrew Price 
---
 gfs2/fsck/pass1.c  |  2 +-
 gfs2/fsck/pass2.c  |  2 +-
 gfs2/fsck/util.h   |  2 +-
 gfs2/libgfs2/fs_ops.c  | 12 ++--
 gfs2/libgfs2/gfs1.c| 16 
 gfs2/libgfs2/libgfs2.h |  8 
 6 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index c2d6cae4..2b3379a7 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -152,7 +152,7 @@ static int pass1_repair_leaf(struct gfs2_inode *ip, 
uint64_t *leaf_no,
  " (0x%"PRIx64") at index: 0x%x for 0x%x pointers.\n"),
ip->i_num.in_addr, ip->i_num.in_addr, lindex, ref_count);
if (ip->i_sbd->gfs1)
-   gfs1_writei(ip, padbuf, lindex * sizeof(uint64_t), pad_size);
+   lgfs2_gfs1_writei(ip, padbuf, lindex * sizeof(uint64_t), 
pad_size);
else
lgfs2_writei(ip, padbuf, lindex * sizeof(uint64_t), pad_size);
free(padbuf);
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 71e10e96..3d732772 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1000,7 +1000,7 @@ static int write_new_leaf(struct gfs2_inode *dip, int 
start_lindex,
dip->i_num.in_addr, dip->i_num.in_addr,
start_lindex, (unsigned long)pad_size / sizeof(uint64_t));
if (dip->i_sbd->gfs1)
-   count = gfs1_writei(dip, padbuf, start_lindex *
+   count = lgfs2_gfs1_writei(dip, padbuf, start_lindex *
sizeof(uint64_t), pad_size);
else
count = lgfs2_writei(dip, padbuf, start_lindex *
diff --git a/gfs2/fsck/util.h b/gfs2/fsck/util.h
index 5f9c488b..ae654bf4 100644
--- a/gfs2/fsck/util.h
+++ b/gfs2/fsck/util.h
@@ -82,7 +82,7 @@ static const inline char *block_type_string(int q)
 
 static inline int is_dir(struct gfs2_inode *ip, int gfs1)
 {
-   if (gfs1 && is_gfs_dir(ip))
+   if (gfs1 && lgfs2_is_gfs_dir(ip))
return 1;
if (S_ISDIR(ip->i_mode))
return 1;
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 077677a4..1d5ef8e6 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -235,7 +235,7 @@ void lgfs2_unstuff_dinode(struct gfs2_inode *ip)
struct gfs2_sbd *sdp = ip->i_sbd;
struct gfs2_buffer_head *bh;
uint64_t block = 0;
-   int isdir = S_ISDIR(ip->i_mode) || is_gfs_dir(ip);
+   int isdir = S_ISDIR(ip->i_mode) || lgfs2_is_gfs_dir(ip);
 
if (ip->i_size) {
if (lgfs2_meta_alloc(ip, ))
@@ -612,7 +612,7 @@ int lgfs2_readi(struct gfs2_inode *ip, void *buf, uint64_t 
offset, unsigned int
 
if (!extlen) {
if (sdp->gfs1)
-   gfs1_block_map(ip, lblock, _new, ,
+   lgfs2_gfs1_block_map(ip, lblock, _new, 
,
   , 0);
else
lgfs2_block_map(ip, lblock, _new, ,
@@ -935,7 +935,7 @@ void lgfs2_dir_split_leaf(struct gfs2_inode *dip, uint32_t 
start, uint64_t leaf_
lp[x] = cpu_to_be64(bn);
 
if (dip->i_sbd->gfs1)
-   count = gfs1_writei(dip, (char *)lp, start * sizeof(uint64_t),
+   count = lgfs2_gfs1_writei(dip, (char *)lp, start * 
sizeof(uint64_t),
half_len * sizeof(uint64_t));
else
count = lgfs2_writei(dip, (char *)lp, start * sizeof(uint64_t),
@@ -1043,7 +1043,7 @@ static void dir_double_exhash(struct gfs2_inode *dip)
}
 
if (sdp->gfs1)
-   count = gfs1_writei(dip, (char *)buf +
+   count = lgfs2_gfs1_writei(dip, (char *)buf +
sdp->sd_hash_bsize,
block * sdp->sd_bsize, 
sdp->sd_bsize);
else
@@ -1763,7 +1763,7 @@ int lgfs2_dir_search(struct gfs2_inode *dip, const char 
*filename, int len,
 {
int error;
 
-   if(!S_ISDIR(dip->i_mode) && !is_gfs_dir(dip))
+   if(!S_ISDIR(dip->i_mode) && !lgfs2_is_gfs_dir(dip))
return -1;
 
if (dip->i_flags & GFS2_DIF_EXHASH)
@@ -1851,7 +1851,7 @@ int lgfs2_dirent_del(struct gfs2_inode *dip, const char 
*filename, int len)
 {
int error;
 
-   if(!S_ISDIR(dip->i_mode) && !is_gfs_dir(dip))
+   if(!S_ISDIR(dip->i_mode) && !lgfs2_is_gfs_dir(dip))
return -1;
 
if (dip->i_flags & GFS2_DIF_EXHASH)
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index 5cee3df8..2b864137 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -31,14 +31,14 @@ gfs1_metapointer(char *buf, unsig

[Cluster-devel] [PATCH 06/21] libgfs2: Namespace improvements - misc.c

2022-01-19 Thread Andrew Price
Use the lgfs2_ prefix in libgfs2 interface names.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c | 12 ++--
 gfs2/edit/hexedit.c |  2 +-
 gfs2/fsck/initialize.c  |  2 +-
 gfs2/libgfs2/check_rgrp.c   |  2 +-
 gfs2/libgfs2/gfs2l.c|  2 +-
 gfs2/libgfs2/libgfs2.h  |  4 ++--
 gfs2/libgfs2/misc.c |  8 
 gfs2/mkfs/main_grow.c   |  2 +-
 gfs2/mkfs/main_jadd.c   |  2 +-
 gfs2/mkfs/main_mkfs.c   |  2 +-
 tests/nukerg.c  |  2 +-
 11 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 9bf92ed4..90964ae1 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -1585,7 +1585,7 @@ static int init(struct gfs2_sbd *sbp, struct gfs2_options 
*opts)
sbp->dinodes_alloced = 0; /* dinodes allocated - total them up later */
sbp->sd_bsize = GFS2_DEFAULT_BSIZE;
sbp->rgtree.osi_node = NULL;
-   if (compute_constants(sbp)) {
+   if (lgfs2_compute_constants(sbp)) {
log_crit("%s\n", _("Failed to compute file system constants"));
exit(-1);
}
@@ -1605,13 +1605,13 @@ static int init(struct gfs2_sbd *sbp, struct 
gfs2_options *opts)
sizeof(uint64_t);
sbp->sd_jbsize = sbp->sd_bsize - sizeof(struct gfs2_meta_header);
lgfs2_brelse(bh);
-   if (compute_heightsize(sbp->sd_bsize, sbp->sd_heightsize, 
>sd_max_height,
+   if (lgfs2_compute_heightsize(sbp->sd_bsize, sbp->sd_heightsize, 
>sd_max_height,
sbp->sd_bsize, sbp->sd_diptrs, sbp->sd_inptrs)) 
{
log_crit("%s\n", _("Failed to compute file system constants"));
exit(-1);
}
 
-   if (compute_heightsize(sbp->sd_bsize, sbp->sd_jheightsize, 
>sd_max_jheight,
+   if (lgfs2_compute_heightsize(sbp->sd_bsize, sbp->sd_jheightsize, 
>sd_max_jheight,
sbp->sd_jbsize, sbp->sd_diptrs, 
sbp->sd_inptrs)) {
log_crit("%s\n", _("Failed to compute file system constants"));
exit(-1);
@@ -1622,13 +1622,13 @@ static int init(struct gfs2_sbd *sbp, struct 
gfs2_options *opts)
gfs2_inptrs = (sbp->sd_bsize - sizeof(struct gfs2_meta_header)) /
 sizeof(uint64_t); /* How many ptrs can we fit on a block? */
memset(gfs2_heightsize, 0, sizeof(gfs2_heightsize));
-   if (compute_heightsize(sbp->sd_bsize, gfs2_heightsize, _max_height,
+   if (lgfs2_compute_heightsize(sbp->sd_bsize, gfs2_heightsize, 
_max_height,
sbp->sd_bsize, sbp->sd_diptrs, gfs2_inptrs)) {
log_crit("%s\n", _("Failed to compute file system constants"));
exit(-1);
}
memset(gfs2_jheightsize, 0, sizeof(gfs2_jheightsize));
-   if (compute_heightsize(sbp->sd_bsize, gfs2_jheightsize, 
_max_jheight,
+   if (lgfs2_compute_heightsize(sbp->sd_bsize, gfs2_jheightsize, 
_max_jheight,
sbp->sd_jbsize, sbp->sd_diptrs, gfs2_inptrs)) {
log_crit("%s\n", _("Failed to compute file system constants"));
exit(-1);
@@ -2299,7 +2299,7 @@ int main(int argc, char **argv)
int jreduce = 0;
 
/* Now we've got to treat it as a gfs2 file system */
-   if (compute_constants()) {
+   if (lgfs2_compute_constants()) {
log_crit("%s\n", _("Failed to compute file system 
constants"));
exit(-1);
}
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index ab5fa933..ffb714bf 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -899,7 +899,7 @@ static void read_superblock(int fd)
perror(device);
exit(-1);
}
-   if(compute_constants()) {
+   if(lgfs2_compute_constants()) {
fprintf(stderr, "Failed to compute constants.\n");
exit(-1);
}
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index 63024a87..f1586374 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -1341,7 +1341,7 @@ static int fill_super_block(struct gfs2_sbd *sdp)
sdp->rgtree.osi_node = NULL;
 
sdp->sd_bsize = GFS2_DEFAULT_BSIZE;
-   if (compute_constants(sdp)) {
+   if (lgfs2_compute_constants(sdp)) {
log_crit("%s\n", _("Failed to compute file system constants"));
return FSCK_ERROR;
}
diff --git a/gfs2/libgfs2/check_rgrp.c b/gfs2/libgfs2/check_rgrp.c
index 2dc2e7be..d2e7b4fb 100644
--- a/gfs2/libgfs2/check_rgrp.c
+++ b/gfs2/libgfs2/check_rgrp.c
@@ -35,

[Cluster-devel] [PATCH 04/21] libgfs2: Namespace improvements - fs_bits.c

2022-01-19 Thread Andrew Price
Use the lgfs2_ prefix in libgfs2 interface names.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c |  2 +-
 gfs2/edit/hexedit.c |  2 +-
 gfs2/edit/savemeta.c|  4 ++--
 gfs2/fsck/metawalk.c|  2 +-
 gfs2/fsck/pass5.c   |  4 ++--
 gfs2/fsck/rgrepair.c|  2 +-
 gfs2/libgfs2/check_rgrp.c   |  2 +-
 gfs2/libgfs2/fs_bits.c  | 22 +++---
 gfs2/libgfs2/fs_ops.c   |  8 
 gfs2/libgfs2/lang.c |  2 +-
 gfs2/libgfs2/libgfs2.h  |  9 +++--
 gfs2/libgfs2/rgrp.c |  8 
 gfs2/libgfs2/structures.c   |  2 +-
 gfs2/libgfs2/super.c|  2 +-
 14 files changed, 34 insertions(+), 37 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index bef0cf6f..9bf92ed4 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -968,7 +968,7 @@ static int next_rg_meta(struct rgrp_tree *rgd, uint64_t 
*block, int first)
}
for (; i < length; i++){
bits = >bits[i];
-   blk = gfs2_bitfit((uint8_t *)bits->bi_data + bits->bi_offset,
+   blk = lgfs2_bitfit((uint8_t *)bits->bi_data + bits->bi_offset,
   bits->bi_len, blk, GFS2_BLKST_DINODE);
if(blk != BFITNOENT){
*block = blk + (bits->bi_start * GFS2_NBBY) + 
rgd->rt_data0;
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 22e70830..ab5fa933 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -1664,7 +1664,7 @@ static void find_change_block_alloc(int *newval)
if (rgd) {
gfs2_rgrp_read(, rgd);
if (newval) {
-   if (gfs2_set_bitmap(rgd, ablock, *newval))
+   if (lgfs2_set_bitmap(rgd, ablock, *newval))
printf("-1 (block invalid or part of an 
rgrp).\n");
else
printf("%d\n", *newval);
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 3b2152df..1d22df2e 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -804,7 +804,7 @@ static int save_leaf_chain(struct metafd *mfd, struct 
gfs2_sbd *sdp, char *buf)
uint64_t blk = be64_to_cpu(leaf->lf_next);
ssize_t r;
 
-   if (gfs2_check_range(sdp, blk) != 0)
+   if (lgfs2_check_range(sdp, blk) != 0)
return 0;
 
r = pread(sdp->device_fd, buf, sdp->sd_bsize, sdp->sd_bsize * 
blk);
@@ -1041,7 +1041,7 @@ static char *rgrp_read(struct gfs2_sbd *sdp, uint64_t 
addr, unsigned blocks)
off_t off = addr * sdp->sd_bsize;
char *buf;
 
-   if (blocks == 0 || gfs2_check_range(sdp, addr))
+   if (blocks == 0 || lgfs2_check_range(sdp, addr))
return NULL;
 
buf = calloc(1, len);
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index a5b3fe36..a401e792 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -77,7 +77,7 @@ int check_n_fix_bitmap(struct gfs2_sbd *sdp, struct rgrp_tree 
*rgd,
   bitmap state was free (and therefore it no longer is) we have to
   subtract to the free space.  If the type changed from dinode to 
   data or data to dinode, no change in free space. */
-   gfs2_set_bitmap(rgd, blk, new_state);
+   lgfs2_set_bitmap(rgd, blk, new_state);
if (new_state == GFS2_BLKST_FREE) {
rgd->rt_free++;
rewrite_rgrp = 1;
diff --git a/gfs2/fsck/pass5.c b/gfs2/fsck/pass5.c
index 9b8f8375..976c8641 100644
--- a/gfs2/fsck/pass5.c
+++ b/gfs2/fsck/pass5.c
@@ -69,7 +69,7 @@ static int check_block_status(struct gfs2_sbd *sdp,  struct 
gfs2_bmap *bl,
if (query(_("Do you want to reclaim the block? "
   "(y/n) "))) {
lgfs2_rgrp_t rg = gfs2_blk2rgrpd(sdp, block);
-   if (gfs2_set_bitmap(rg, block, GFS2_BLKST_FREE))
+   if (lgfs2_set_bitmap(rg, block, 
GFS2_BLKST_FREE))
log_err(_("Unlinked block %"PRIu64" 
(0x%"PRIx64") bitmap not fixed.\n"),
block, block);
else {
@@ -94,7 +94,7 @@ static int check_block_status(struct gfs2_sbd *sdp,  struct 
gfs2_bmap *bl,
if (query(_("Fix bitmap for block %"PRIu64" 
(0x%"PRIx64")? (y/n) "),
  block, block)) {
lgfs2_rgrp_t rg = gfs2_blk2rgrpd(sdp, block);
-   if (gfs2_set_bitmap(rg, block, q))
+   

[Cluster-devel] [PATCH 00/21] libgfs2: Namespace improvements

2022-01-19 Thread Andrew Price
In libgfs2 we have a mix of function names prefixed with gfs2_, lgfs2_ or 
nothing at all that denotes where they are defined. This patch set addresses 
that problem by more strictly enforcing a prefix namespace scheme on the 
symbols exposed by libgfs2. So now we (mostly) have these prefix conventions:

GFS2_/gfs2_   - kernel code
LGFS2_/lgfs2_ - libgfs2 interfaces
No prefix - application/internal code

This means we can tell at a glance where names are defined, which makes the 
code easier to work with.

Some changes that were not made in this set are:

- gfs(1) on-disk structures defined in libgfs2.h for compatibility were not 
renamed as they're essentially kernel-defined.
- The endianness conversion macros (be64_to_cpu(), etc.) were not renamed but 
they will likely be renamed once a concise naming scheme has been decided upon.

This is obviously a large amount of churn but it pays off a lot of technical 
debt and I think it's worth getting it out of the way in one go. Many of the 
changes were scripted but each patch was reviewed by eye and tested with 'make 
check'.

Andrew Price (21):
  libgfs2: Namespace improvements - structures.c
  libgfs2: Namespace improvements - buf.c
  libgfs2: Namespace improvements - fs_ops.c
  libgfs2: Namespace improvements - fs_bits.c
  libgfs2: Namespace improvements - gfs1.c
  libgfs2: Namespace improvements - misc.c
  libgfs2: Namespace improvements - rgrp.c
  libgfs2: Namespace improvements - super.c
  libgfs2: Namespace improvements - gfs2_disk_hash.c
  libgfs2: Remove revoke function declarations from libgfs2.h
  libgfs2: Namespace improvements - recovery.c
  libgfs2: Namespace improvements - device_geometry.c
  libgfs2: Namespace improvements - struct gfs2_inode
  libgfs2: Namespace improvements - struct gfs2_buffer_head
  libgfs2: Namespace improvements - struct gfs2_sbd
  libgfs2: Namespace improvements - struct metapath
  libgfs2: Namespace improvements - struct master_dir
  libgfs2: Namespace improvements - struct device
  libgfs2: Namespace improvements - struct gfs2_bitmap
  libgfs2: Namespace improvements - constants
  libgfs2: Namespace improvements - struct rgrp_tree

 gfs2/convert/gfs2_convert.c| 398 +++
 gfs2/edit/extended.c   |  72 ++---
 gfs2/edit/gfs2hex.c|   8 +-
 gfs2/edit/hexedit.c| 198 ++--
 gfs2/edit/hexedit.h|   6 +-
 gfs2/edit/journal.c|  84 ++---
 gfs2/edit/savemeta.c   |  32 +-
 gfs2/fsck/afterpass1_common.c  |  54 ++--
 gfs2/fsck/afterpass1_common.h  |  26 +-
 gfs2/fsck/fs_recovery.c| 206 ++--
 gfs2/fsck/fs_recovery.h|  10 +-
 gfs2/fsck/fsck.h   |  46 +--
 gfs2/fsck/initialize.c | 278 
 gfs2/fsck/link.c   |   6 +-
 gfs2/fsck/link.h   |   4 +-
 gfs2/fsck/lost_n_found.c   |  34 +-
 gfs2/fsck/lost_n_found.h   |   4 +-
 gfs2/fsck/main.c   |  38 +--
 gfs2/fsck/metawalk.c   | 178 +--
 gfs2/fsck/metawalk.h   |  70 ++---
 gfs2/fsck/pass1.c  | 356 ++---
 gfs2/fsck/pass1b.c | 118 +++
 gfs2/fsck/pass2.c  | 278 
 gfs2/fsck/pass3.c  |  14 +-
 gfs2/fsck/pass4.c  |  24 +-
 gfs2/fsck/pass5.c  |  28 +-
 gfs2/fsck/rgrepair.c   | 222 ++---
 gfs2/fsck/util.c   |  18 +-
 gfs2/fsck/util.h   |  26 +-
 gfs2/glocktop/glocktop.c   |  18 +-
 gfs2/libgfs2/buf.c |  28 +-
 gfs2/libgfs2/check_ondisk.c|   6 +-
 gfs2/libgfs2/check_rgrp.c  |   8 +-
 gfs2/libgfs2/device_geometry.c |   4 +-
 gfs2/libgfs2/fs_bits.c |  32 +-
 gfs2/libgfs2/fs_ops.c  | 557 -
 gfs2/libgfs2/gfs1.c|  82 ++---
 gfs2/libgfs2/gfs2_disk_hash.c  |   5 +-
 gfs2/libgfs2/gfs2l.c   |  20 +-
 gfs2/libgfs2/lang.c|  40 +--
 gfs2/libgfs2/lang.h|   2 +-
 gfs2/libgfs2/libgfs2.h | 319 +--
 gfs2/libgfs2/misc.c|   8 +-
 gfs2/libgfs2/ondisk.c  |   8 +-
 gfs2/libgfs2/recovery.c|  38 +--
 gfs2/libgfs2/rgrp.c|  88 +++---
 gfs2/libgfs2/rgrp.h|   4 +-
 gfs2/libgfs2/structures.c  | 168 +-
 gfs2/libgfs2/super.c   |  48 +--
 gfs2/mkfs/main_grow.c  |  32 +-
 gfs2/mkfs/main_jadd.c  |  24 +-
 gfs2/mkfs/main_mkfs.c  | 104 +++---
 gfs2/tune/super.c  |   6 +-
 tests/nukerg.c |  22 +-
 54 files changed, 2243 insertions(+), 2264 deletions(-)

-- 
2.34.1



[Cluster-devel] [PATCH 18/18] libgfs2: Remove print_it extern requirement

2022-01-12 Thread Andrew Price
Now that libgfs2 doesn't depend on a print_it() function being provided
by the utils, the extern declaration can be removed from libgfs2.h. The
print_it functions in mkfs.gfs2 and gfs2_edit are moved into their
struct_print.c files and made static. All other print_it definitions are
removed or made static.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c  |  13 ---
 gfs2/edit/extended.c |   7 --
 gfs2/edit/gfs2hex.c  | 135 ---
 gfs2/edit/hexedit.c  |  33 --
 gfs2/edit/hexedit.h  |   4 +-
 gfs2/edit/struct_print.c | 200 +++
 gfs2/edit/struct_print.h |   4 +
 gfs2/fsck/main.c |  11 --
 gfs2/glocktop/glocktop.c |   3 +-
 gfs2/libgfs2/check_libgfs2.c |   3 -
 gfs2/libgfs2/gfs2l.c |   3 -
 gfs2/libgfs2/libgfs2.h   |   2 -
 gfs2/mkfs/gfs2_mkfs.h|  11 --
 gfs2/mkfs/struct_print.c |  12 +++
 tests/nukerg.c   |   3 -
 15 files changed, 198 insertions(+), 246 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 5bfc616b..dc011d05 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -114,19 +114,6 @@ static unsigned orig_journals = 0;
 
 int print_level = MSG_NOTICE;
 
-/* - */
-/* This function is for libgfs's sake.   */
-/* - */
-void print_it(const char *label, const char *fmt, const char *fmt2, ...)
-{
-   va_list args;
-
-   va_start(args, fmt2);
-   printf("%s: ", label);
-   vprintf(fmt, args);
-   va_end(args);
-}
-
 /* - */
 /* convert_bitmaps - Convert gfs1 bitmaps to gfs2 bitmaps.   */
 /*   Fixes all unallocated metadata bitmap states (which are */
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index 8ba3da3b..6e2e16db 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -421,13 +421,6 @@ static void print_block_details(struct iinfo *ind, int 
level, int cur_height,
free(more_indir);
 }
 
-static void gfs_jindex_print(struct gfs_jindex *ji)
-{
-   print_it("  ji_addr", "%"PRIu64, "0x%"PRIx64, be64_to_cpu(ji->ji_addr));
-   print_it("  ji_nsegment", "%"PRIu32, "0x%"PRIx32, 
be32_to_cpu(ji->ji_nsegment));
-   print_it("  ji_pad", "%"PRIu32, "0x%"PRIx32, be32_to_cpu(ji->ji_pad));
-}
-
 static int print_gfs_jindex(struct gfs2_inode *dij)
 {
int error, start_line;
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index 9c71ac60..610c7d2a 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -18,16 +18,6 @@
 #include "gfs2hex.h"
 #include "struct_print.h"
 
-#define pv(struct, member, fmt, fmt2) do { \
-   print_it("  "#member, fmt, fmt2, struct->member);   \
-   } while (FALSE);
-#define pv2(struct, member, fmt, fmt2) do {\
-   print_it("  ", fmt, fmt2, struct->member);  \
-   } while (FALSE);
-#define printbe32(struct, member) do { \
-   print_it("  "#member, "%"PRIu32, "0x%"PRIx32, 
be32_to_cpu(struct->member)); \
-   } while(0)
-
 struct gfs2_dinode *di;
 int line, termlines;
 char edit_fmt[80];
@@ -107,107 +97,6 @@ void print_gfs2(const char *fmt, ...)
va_end(args);
 }
 
-static void check_highlight(int highlight)
-{
-   if (!termlines || line >= termlines) /* If printing or out of bounds */
-   return;
-   if (dmode == HEX_MODE) {
-   if (line == (edit_row[dmode] * lines_per_row[dmode]) + 4) {
-   if (highlight) {
-   COLORS_HIGHLIGHT;
-   last_entry_onscreen[dmode] = print_entry_ndx;
-   } else
-   COLORS_NORMAL;
-   }
-   } else {
-   if ((line * lines_per_row[dmode]) - 4 == 
-   (edit_row[dmode] - start_row[dmode]) * 
lines_per_row[dmode]) {
-   if (highlight) {
-   COLORS_HIGHLIGHT;
-   last_entry_onscreen[dmode] = print_entry_ndx;
-   }
-   else
-   COLORS_NORMAL;
-   }
-   }
-}
-
-void print_it(const char *label, const char *fmt, const char *fmt2, ...)
-{
-   va_list args;
-   char tmp_string[NAME_MAX];
-   const char *fmtstring;
-   int decimalsize;
-
-   if (!termlines || line < termlines) {
-   va_start(args, f

[Cluster-devel] [PATCH 17/18] libgfs2: Move struct printing functions out of libgfs2

2022-01-12 Thread Andrew Price
Now that libgfs2 itself doesn't use these functions, they can be moved
into the two utils that use them. This does duplicate the code but that
means the utils are free to change the way that they're printed to suit
their interfaces. We're still using the "print_it" extern that libgfs2.h
requires but that can be removed next.

Signed-off-by: Andrew Price 
---
 gfs2/edit/Makefile.am|   2 +
 gfs2/edit/extended.c |  11 ++-
 gfs2/edit/gfs2hex.c  |  33 ---
 gfs2/edit/hexedit.c  |   9 +-
 gfs2/edit/struct_print.c | 206 +++
 gfs2/edit/struct_print.h |  19 
 gfs2/libgfs2/libgfs2.h   |  15 ---
 gfs2/libgfs2/ondisk.c| 199 -
 gfs2/mkfs/Makefile.am|   2 +
 gfs2/mkfs/main_mkfs.c|  27 ++---
 gfs2/mkfs/struct_print.c | 206 +++
 gfs2/mkfs/struct_print.h |  19 
 12 files changed, 496 insertions(+), 252 deletions(-)
 create mode 100644 gfs2/edit/struct_print.c
 create mode 100644 gfs2/edit/struct_print.h
 create mode 100644 gfs2/mkfs/struct_print.c
 create mode 100644 gfs2/mkfs/struct_print.h

diff --git a/gfs2/edit/Makefile.am b/gfs2/edit/Makefile.am
index cee327a9..28a8908c 100644
--- a/gfs2/edit/Makefile.am
+++ b/gfs2/edit/Makefile.am
@@ -6,6 +6,7 @@ noinst_HEADERS = \
gfs2hex.h \
hexedit.h \
extended.h \
+   struct_print.h \
journal.h
 
 gfs2_edit_SOURCES = \
@@ -13,6 +14,7 @@ gfs2_edit_SOURCES = \
hexedit.c \
savemeta.c \
extended.c \
+   struct_print.c \
journal.c
 
 gfs2_edit_CPPFLAGS = \
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index 8d914681..8ba3da3b 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -17,13 +17,14 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "copyright.cf"
 
 #include "hexedit.h"
-#include "libgfs2.h"
 #include "extended.h"
 #include "gfs2hex.h"
+#include "struct_print.h"
 
 static void print_block_details(struct iinfo *ind, int level, int cur_height,
int pndx, uint64_t file_offset);
@@ -534,7 +535,7 @@ static int parse_rindex(struct gfs2_inode *dip, int 
print_rindex)
if (edit_row[dmode] == print_entry_ndx)
COLORS_NORMAL;
if (print_rindex)
-   lgfs2_rindex_print();
+   rindex_print();
else {
struct gfs2_rgrp r = {0};
ssize_t ret;
@@ -545,7 +546,7 @@ static int parse_rindex(struct gfs2_inode *dip, int 
print_rindex)
} else if (sbd.gfs1) {
gfs_rgrp_print();
} else {
-   lgfs2_rgrp_print();
+   rgrp_print();
}
}
last_entry_onscreen[dmode] = print_entry_ndx;
@@ -597,7 +598,7 @@ static int print_statfs(struct gfs2_inode *dis)
}
print_gfs2("statfs file contents:");
eol(0);
-   lgfs2_statfs_change_print();
+   statfs_change_print();
return 0;
 }
 
@@ -621,7 +622,7 @@ static int print_quota(struct gfs2_inode *diq)
}
print_gfs2("Entry #%d", i + 1);
eol(0);
-   lgfs2_quota_print();
+   quota_print();
}
return 0;
 }
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index 219a20ea..9c71ac60 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -11,11 +11,12 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "hexedit.h"
 #include "extended.h"
 #include "gfs2hex.h"
-#include "libgfs2.h"
+#include "struct_print.h"
 
 #define pv(struct, member, fmt, fmt2) do { \
print_it("  "#member, fmt, fmt2, struct->member);   \
@@ -364,7 +365,7 @@ static void do_eattr_extended(char *buf)
eol(0);
buf += x;
ea = (struct gfs2_ea_header *)buf;
-   lgfs2_ea_header_print(ea);
+   ea_header_print(ea);
rec_len = be32_to_cpu(ea->ea_rec_len);
}
 }
@@ -377,20 +378,20 @@ static void gfs_sb_print(void *sbp)
 {
struct gfs_sb *sb = sbp;
 
-   lgfs2_meta_header_print(>sb_header);
+   meta_header_print(>sb_header);
printbe32(sb, sb_fs_format);
printbe32(sb, sb_multihost_format);
printbe32(sb, sb_flags);
printbe32(sb, sb_bsize);
printbe32(sb, sb_bsize_shift);
printbe32(sb, sb_seg_size);
-   lgfs2_inum_print(>sb_jindex_di);
-   lgfs2_inum_print(>sb

[Cluster-devel] [PATCH 16/18] libgfs2: Remove config.[ch]

2022-01-12 Thread Andrew Price
The cfg_debug bits are no longer used.

Signed-off-by: Andrew Price 
---
 gfs2/libgfs2/Makefile.am   | 2 --
 gfs2/libgfs2/checks.am | 1 -
 gfs2/libgfs2/config.c  | 9 -
 gfs2/libgfs2/config.h  | 6 --
 gfs2/libgfs2/device_geometry.c | 1 -
 gfs2/libgfs2/libgfs2.h | 3 ---
 gfs2/libgfs2/structures.c  | 1 -
 gfs2/mkfs/main_jadd.c  | 1 -
 gfs2/mkfs/main_mkfs.c  | 1 -
 9 files changed, 25 deletions(-)
 delete mode 100644 gfs2/libgfs2/config.c
 delete mode 100644 gfs2/libgfs2/config.h

diff --git a/gfs2/libgfs2/Makefile.am b/gfs2/libgfs2/Makefile.am
index c3f2425d..123b85b7 100644
--- a/gfs2/libgfs2/Makefile.am
+++ b/gfs2/libgfs2/Makefile.am
@@ -23,7 +23,6 @@ noinst_HEADERS = \
libgfs2.h \
crc32c.h \
lang.h \
-   config.h \
rgrp.h
 
 noinst_LTLIBRARIES = libgfs2.la
@@ -40,7 +39,6 @@ libgfs2_la_SOURCES = \
buf.c \
gfs2_disk_hash.c \
ondisk.c \
-   config.c \
device_geometry.c \
fs_ops.c \
recovery.c \
diff --git a/gfs2/libgfs2/checks.am b/gfs2/libgfs2/checks.am
index 18d719ab..d1aa7189 100644
--- a/gfs2/libgfs2/checks.am
+++ b/gfs2/libgfs2/checks.am
@@ -12,7 +12,6 @@ check_libgfs2_SOURCES = \
device_geometry.c \
fs_ops.c \
structures.c \
-   config.c \
fs_bits.c \
gfs1.c \
misc.c \
diff --git a/gfs2/libgfs2/config.c b/gfs2/libgfs2/config.c
deleted file mode 100644
index d2431e43..
--- a/gfs2/libgfs2/config.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "libgfs2.h"
-#include "config.h"
-
-int cfg_debug = 0;
-
-void lgfs2_set_debug(int enable)
-{
-   cfg_debug = enable;
-}
diff --git a/gfs2/libgfs2/config.h b/gfs2/libgfs2/config.h
deleted file mode 100644
index 7c1eb3c3..
--- a/gfs2/libgfs2/config.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __LGFS2_CONFIG_H__
-#define __LGFS2_CONFIG_H__
-
-extern int cfg_debug;
-
-#endif /* __LGFS2_CONFIG_H__ */
diff --git a/gfs2/libgfs2/device_geometry.c b/gfs2/libgfs2/device_geometry.c
index b149d2c0..cb1ed6d5 100644
--- a/gfs2/libgfs2/device_geometry.c
+++ b/gfs2/libgfs2/device_geometry.c
@@ -14,7 +14,6 @@
 #include 
 
 #include "libgfs2.h"
-#include "config.h"
 
 #ifndef BLKSSZGET
 #define BLKSSZGET _IO(0x12,104)   /* logical_block_size */
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index fa710a6c..20d8d57e 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -471,9 +471,6 @@ extern uint32_t lgfs2_get_block_type(const char *buf);
 #define bread(bl, num) __bread(bl, num, __LINE__, __FUNCTION__)
 #define breadm(bl, bhs, n, block) __breadm(bl, bhs, n, block, __LINE__, 
__FUNCTION__)
 
-/* config.c */
-extern void lgfs2_set_debug(int enable);
-
 /* device_geometry.c */
 extern int lgfs2_get_dev_info(int fd, struct lgfs2_dev_info *i);
 extern void fix_device_geometry(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 9b78ed51..d7b7f4e1 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -14,7 +14,6 @@
 #include 
 
 #include "libgfs2.h"
-#include "config.h"
 #include "crc32c.h"
 
 int build_master(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index 2648b980..0a7f1f33 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -158,7 +158,6 @@ static int decode_arguments(int argc, char *argv[], struct 
gfs2_sbd *sdp, struct
break;
case 'D':
opts->debug = 1;
-   lgfs2_set_debug(1);
break;
case 'h':
print_usage(argv[0]);
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index ae192bd4..8f8d8f04 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -366,7 +366,6 @@ static int opts_get(int argc, char *argv[], struct 
mkfs_opts *opts)
break;
case 'D':
opts->debug = 1;
-   lgfs2_set_debug(1);
break;
case 'h':
print_usage(argv[0]);
-- 
2.34.1



[Cluster-devel] [PATCH 14/18] libgfs2: Move debugging output out of do_init_inum()

2022-01-12 Thread Andrew Price
Signed-off-by: Andrew Price 
---
 gfs2/libgfs2/structures.c | 3 ---
 gfs2/mkfs/main_mkfs.c | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index d4a08c43..9b78ed51 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -465,9 +465,6 @@ int do_init_inum(struct gfs2_sbd *sdp)
if (count != sizeof(uint64_t))
return -1;
 
-   if (cfg_debug)
-   printf("\nNext Inum: %"PRIu64"\n",
-  sdp->md.next_inum);
return 0;
 }
 
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 36341d99..ae192bd4 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1356,6 +1356,9 @@ int main(int argc, char *argv[])
sbd.sd_locktable[GFS2_LOCKNAME_LEN - 1] = '\0';
 
do_init_inum();
+   if (opts.debug)
+   printf("\nNext Inum: %"PRIu64"\n", sbd.md.next_inum);
+
do_init_statfs(, );
if (opts.debug) {
printf("\nStatfs:\n");
-- 
2.34.1



[Cluster-devel] [PATCH 15/18] libgfs2: Remove debugging printfs from fix_device_geometry()

2022-01-12 Thread Andrew Price
This block never gets executed as the only utils that enable cfg_debug
don't call the function.

Signed-off-by: Andrew Price 
---
 gfs2/libgfs2/device_geometry.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/gfs2/libgfs2/device_geometry.c b/gfs2/libgfs2/device_geometry.c
index 4a0aeab2..b149d2c0 100644
--- a/gfs2/libgfs2/device_geometry.c
+++ b/gfs2/libgfs2/device_geometry.c
@@ -98,10 +98,4 @@ void fix_device_geometry(struct gfs2_sbd *sdp)
struct device *device = >device;
 
device->length = sdp->dinfo.size / sdp->sd_bsize;
-
-   if (cfg_debug) {
-   printf("\nDevice Geometry:  (in FS blocks)\n");
-   printf("  length = %"PRIu64"\n", device->length);
-   printf("\nDevice Size: %"PRIu64"\n", sdp->dinfo.size);
-   }
 }
-- 
2.34.1



[Cluster-devel] [PATCH 13/18] libgfs2: Remove debugging printf from do_init_statfs()

2022-01-12 Thread Andrew Price
Allow the caller to provide a pointer to a statfs change structure so
that it can do its own debug message printing. This is only used by
mkfs.gfs2.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c | 2 +-
 gfs2/fsck/initialize.c  | 2 +-
 gfs2/fsck/main.c| 2 +-
 gfs2/libgfs2/libgfs2.h  | 2 +-
 gfs2/libgfs2/structures.c   | 8 +++-
 gfs2/mkfs/main_mkfs.c   | 8 ++--
 6 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 8667d8fb..5bfc616b 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2357,7 +2357,7 @@ int main(int argc, char **argv)
 strerror(error));
exit(-1);
}
-   do_init_statfs();
+   do_init_statfs(, NULL);
 
/* Create the resource group index file */
ip = build_rindex();
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index a2bc44c0..fab9a1e7 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -867,7 +867,7 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
   "a valid statfs file; aborting.\n"));
goto fail;
}
-   do_init_statfs(sdp);
+   do_init_statfs(sdp, NULL);
}
if (sdp->md.statfs->i_size) {
buf = malloc(sdp->md.statfs->i_size);
diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c
index 35b13950..cb667815 100644
--- a/gfs2/fsck/main.c
+++ b/gfs2/fsck/main.c
@@ -228,7 +228,7 @@ static int check_statfs(struct gfs2_sbd *sdp)
return 0;
}
 
-   do_init_statfs(sdp);
+   do_init_statfs(sdp, NULL);
log_err( _("The statfs file was fixed.\n"));
errors_corrected++;
return 0;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 3396ddb0..fa710a6c 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -783,7 +783,7 @@ extern struct gfs2_inode *build_rindex(struct gfs2_sbd 
*sdp);
 extern struct gfs2_inode *build_quota(struct gfs2_sbd *sdp);
 extern int build_root(struct gfs2_sbd *sdp);
 extern int do_init_inum(struct gfs2_sbd *sdp);
-extern int do_init_statfs(struct gfs2_sbd *sdp);
+extern int do_init_statfs(struct gfs2_sbd *sdp, struct gfs2_statfs_change 
*res);
 extern int gfs2_check_meta(const char *buf, int type);
 extern unsigned lgfs2_bm_scan(struct rgrp_tree *rgd, unsigned idx,
  uint64_t *buf, uint8_t state);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 7ac38f92..d4a08c43 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -471,7 +471,7 @@ int do_init_inum(struct gfs2_sbd *sdp)
return 0;
 }
 
-int do_init_statfs(struct gfs2_sbd *sdp)
+int do_init_statfs(struct gfs2_sbd *sdp, struct gfs2_statfs_change *res)
 {
struct gfs2_inode *ip = sdp->md.statfs;
struct gfs2_statfs_change sc;
@@ -485,10 +485,8 @@ int do_init_statfs(struct gfs2_sbd *sdp)
if (count != sizeof(sc))
return -1;
 
-   if (cfg_debug) {
-   printf("\nStatfs:\n");
-   lgfs2_statfs_change_print();
-   }
+   if (res)
+   *res = sc;
return 0;
 }
 
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 9a73ff7b..36341d99 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1196,6 +1196,7 @@ static int open_dev(struct mkfs_dev *dev, int withprobe)
 #ifndef UNITTESTS
 int main(int argc, char *argv[])
 {
+   struct gfs2_statfs_change sc;
struct gfs2_sbd sbd;
struct mkfs_opts opts;
struct gfs2_inode *ip;
@@ -1355,8 +1356,11 @@ int main(int argc, char *argv[])
sbd.sd_locktable[GFS2_LOCKNAME_LEN - 1] = '\0';
 
do_init_inum();
-   do_init_statfs();
-
+   do_init_statfs(, );
+   if (opts.debug) {
+   printf("\nStatfs:\n");
+   lgfs2_statfs_change_print();
+   }
inode_put();
inode_put(_dir);
inode_put();
-- 
2.34.1



[Cluster-devel] [PATCH 12/18] libgfs2: Move debugging printf out of build_root()

2022-01-12 Thread Andrew Price
mkfs.gfs2 is the only place it could ever get printed so move it there
instead.

Signed-off-by: Andrew Price 
---
 gfs2/libgfs2/structures.c | 4 
 gfs2/mkfs/main_mkfs.c | 4 
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 6cc0a8dd..7ac38f92 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -450,10 +450,6 @@ int build_root(struct gfs2_sbd *sdp)
if (sdp->md.rooti == NULL)
return -1;
 
-   if (cfg_debug) {
-   printf("\nRoot directory:\n");
-   lgfs2_dinode_print(bh->b_data);
-   }
sdp->md.rooti->bh_owned = 1;
return 0;
 }
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 56a3b7d2..9a73ff7b 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1343,6 +1343,10 @@ int main(int argc, char *argv[])
printf("%s", _("Done\n"));
 
build_root();
+   if (opts.debug) {
+   printf("\nRoot directory:\n");
+   lgfs2_dinode_print(sbd.md.rooti->i_bh->b_data);
+   }
sbd.sd_root_dir = sbd.md.rooti->i_num;
 
strncpy(sbd.sd_lockproto, opts.lockproto, GFS2_LOCKNAME_LEN - 1);
-- 
2.34.1



[Cluster-devel] [PATCH 11/18] libgfs2: Return the inode from build_quota()

2022-01-12 Thread Andrew Price
This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c |  5 +++--
 gfs2/fsck/initialize.c  | 17 +
 gfs2/fsck/pass1.c   | 11 ++-
 gfs2/libgfs2/libgfs2.h  |  2 +-
 gfs2/libgfs2/structures.c   | 20 +++-
 gfs2/mkfs/main_mkfs.c   |  9 +++--
 6 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 5a542e29..8667d8fb 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2368,12 +2368,13 @@ int main(int argc, char **argv)
}
inode_put();
/* Create the quota file */
-   error = build_quota();
-   if (error) {
+   ip = build_quota();
+   if (ip == NULL) {
log_crit(_("Error building quota inode: %s\n"),
 strerror(error));
exit(-1);
}
+   inode_put();
 
/* Copy out the master dinode */
if (sb2.master_dir->i_bh->b_modified)
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index e1c71fc8..a2bc44c0 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -562,11 +562,12 @@ static int rebuild_master(struct gfs2_sbd *sdp)
exit(FSCK_ERROR);
}
} else {
-   err = build_quota(sdp);
-   if (err) {
-   log_crit(_("Error %d building quota inode\n"), err);
+   struct gfs2_inode *qip = build_quota(sdp);
+   if (qip == NULL) {
+   log_crit(_("Error building quota inode: %s\n"), 
strerror(errno));
exit(FSCK_ERROR);
}
+   inode_put();
}
 
log_err(_("Master directory rebuilt.\n"));
@@ -911,13 +912,13 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
   "rebuilt.  Aborting.\n"));
goto fail;
}
-   err = build_quota(sdp);
-   if (err) {
-   log_crit(_("Error %d rebuilding quota inode\n"), err);
+   sdp->md.qinode = build_quota(sdp);
+   if (sdp->md.qinode == NULL) {
+   log_crit(_("Error rebuilding quota inode: %s\n"), 
strerror(errno));
exit(FSCK_ERROR);
}
-   gfs2_lookupi(sdp->master_dir, "quota", 5, >md.qinode);
-   if (!sdp->md.qinode) {
+   lgfs2_dinode_out(sdp->md.qinode, sdp->md.qinode->i_bh->b_data);
+   if (bwrite(sdp->md.qinode->i_bh) != 0) {
log_crit(_("Unable to rebuild system quota file "
   "inode.  Aborting.\n"));
goto fail;
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 389cfbe5..ad16971e 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1646,6 +1646,15 @@ static int fsck_build_rindex(struct gfs2_sbd *sdp)
return 0;
 }
 
+static int fsck_build_quota(struct gfs2_sbd *sdp)
+{
+   struct gfs2_inode *ip = build_quota(sdp);
+   if (ip == NULL)
+   return -1;
+   inode_put();
+   return 0;
+}
+
 static int check_system_inodes(struct gfs2_sbd *sdp)
 {
int journal_count;
@@ -1696,7 +1705,7 @@ static int check_system_inodes(struct gfs2_sbd *sdp)
stack;
return -1;
}
-   if (check_system_inode(sdp, >md.qinode, "quota", build_quota,
+   if (check_system_inode(sdp, >md.qinode, "quota", fsck_build_quota,
   0, sdp->master_dir, !sdp->gfs1)) {
stack;
return -1;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 3c1ec9b2..3396ddb0 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -780,7 +780,7 @@ extern struct gfs2_inode *lgfs2_build_jindex(struct 
gfs2_inode *metafs, struct l
 extern struct gfs2_inode *build_inum(struct gfs2_sbd *sdp);
 extern struct gfs2_inode *build_statfs(struct gfs2_sbd *sdp);
 extern struct gfs2_inode *build_rindex(struct gfs2_sbd *sdp);
-extern int build_quota(struct gfs2_sbd *sdp);
+extern struct gfs2_inode *build_quota(struct gfs2_sbd *sdp);
 extern int build_root(struct gfs2_sbd *sdp);
 extern int do_init_inum(struct gfs2_sbd *sdp);
 extern int do_init_statfs(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libg

[Cluster-devel] [PATCH 10/18] libgfs2: Return the inode from build_rindex()

2022-01-12 Thread Andrew Price
This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c |  8 +---
 gfs2/fsck/initialize.c  | 15 +--
 gfs2/fsck/pass1.c   | 11 ++-
 gfs2/libgfs2/libgfs2.h  |  2 +-
 gfs2/libgfs2/structures.c   | 20 +++-
 gfs2/mkfs/main_mkfs.c   | 10 --
 6 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 93c9755b..5a542e29 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2308,6 +2308,7 @@ int main(int argc, char **argv)
/* Create our system files and directories.   */
/* -- */
if (!error) {
+   struct gfs2_inode *ip;
int jreduce = 0;
 
/* Now we've got to treat it as a gfs2 file system */
@@ -2359,12 +2360,13 @@ int main(int argc, char **argv)
do_init_statfs();
 
/* Create the resource group index file */
-   error = build_rindex();
-   if (error) {
+   ip = build_rindex();
+   if (ip == NULL) {
log_crit(_("Error building rindex inode: %s\n"),
-strerror(error));
+strerror(errno));
exit(-1);
}
+   inode_put();
/* Create the quota file */
error = build_quota();
if (error) {
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index bb2bcfb7..e1c71fc8 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -544,11 +544,12 @@ static int rebuild_master(struct gfs2_sbd *sdp)
exit(FSCK_ERROR);
}
} else {
-   err = build_rindex(sdp);
-   if (err) {
-   log_crit(_("Error %d building rindex inode\n"), err);
+   struct gfs2_inode *rip = build_rindex(sdp);
+   if (rip == NULL) {
+   log_crit(_("Error building rindex inode: %s\n"), 
strerror(errno));
exit(FSCK_ERROR);
}
+   inode_put();
}
 
if (fix_md.qinode) {
@@ -1514,7 +1515,7 @@ static int reconstruct_journals(struct gfs2_sbd *sdp)
  */
 static int init_rindex(struct gfs2_sbd *sdp)
 {
-   int err;
+   struct gfs2_inode *ip;
 
if (sdp->gfs1)
sdp->md.riinode = lgfs2_inode_read(sdp, 
sdp->sd_rindex_di.in_addr);
@@ -1529,10 +1530,12 @@ static int init_rindex(struct gfs2_sbd *sdp)
log_crit(_("Error: Cannot proceed without a valid rindex.\n"));
return -1;
}
-   if ((err = build_rindex(sdp))) {
-   log_crit(_("Error %d rebuilding rindex\n"), err);
+   ip = build_rindex(sdp);
+   if (ip == NULL) {
+   log_crit(_("Error rebuilding rindex: %s\n"), strerror(errno));
return -1;
}
+   inode_put();
return 0;
 }
 
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index b19292eb..389cfbe5 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1637,6 +1637,15 @@ static int fsck_build_statfs(struct gfs2_sbd *sdp)
return 0;
 }
 
+static int fsck_build_rindex(struct gfs2_sbd *sdp)
+{
+   struct gfs2_inode *ip = build_rindex(sdp);
+   if (ip == NULL)
+   return -1;
+   inode_put();
+   return 0;
+}
+
 static int check_system_inodes(struct gfs2_sbd *sdp)
 {
int journal_count;
@@ -1682,7 +1691,7 @@ static int check_system_inodes(struct gfs2_sbd *sdp)
stack;
return -1;
}
-   if (check_system_inode(sdp, >md.riinode, "rindex", build_rindex,
+   if (check_system_inode(sdp, >md.riinode, "rindex", 
fsck_build_rindex,
   0, sdp->master_dir, !sdp->gfs1)) {
stack;
return -1;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 83fc90ce..3c1ec9b2 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -779,7 +779,7 @@ extern int build_journal(struct gfs2_sbd *sdp, int j,
 extern struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *metafs, struct 
lgfs2_inum *jnls, size_t nmemb);
 extern struct gfs2_inode *build_inum(struct gfs2_sbd *sdp);
 extern struct gfs2_inode *build_statfs(struct gfs2_sbd *sdp);
-extern int build_rindex(struct gfs2_sbd *sdp);
+extern struct gfs2_inode *build_rindex(struct gfs2_sbd *sdp);
 extern int build_quota(struct gfs2_s

[Cluster-devel] [PATCH 09/18] libgfs2: Return the inode from build_statfs()

2022-01-12 Thread Andrew Price
This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c |  5 ++---
 gfs2/fsck/initialize.c  | 16 +---
 gfs2/fsck/pass1.c   | 11 ++-
 gfs2/libgfs2/libgfs2.h  |  2 +-
 gfs2/libgfs2/structures.c   | 14 ++
 gfs2/mkfs/main_mkfs.c   |  9 ++---
 6 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 210528c9..93c9755b 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2350,13 +2350,12 @@ int main(int argc, char **argv)
exit(-1);
}
/* Create the statfs file */
-   error = build_statfs(); /* Does not do inode_put */
-   if (error) {
+   sb2.md.statfs = build_statfs(); /* Does not do inode_put */
+   if (sb2.md.statfs == NULL) {
log_crit(_("Error building statfs inode: %s\n"),
 strerror(error));
exit(-1);
}
-   gfs2_lookupi(sb2.master_dir, "statfs", 6, );
do_init_statfs();
 
/* Create the resource group index file */
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index a46d3ecb..bb2bcfb7 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -524,12 +524,14 @@ static int rebuild_master(struct gfs2_sbd *sdp)
exit(FSCK_ERROR);
}
} else {
-   err = build_statfs(sdp);
-   if (err) {
+   sdp->md.statfs = build_statfs(sdp);
+   if (sdp->md.statfs == NULL) {
log_crit(_("Error %d building statfs inode\n"), err);
exit(FSCK_ERROR);
}
-   gfs2_lookupi(sdp->master_dir, "statfs", 6, >md.statfs);
+   /* Write the inode but don't free it, to avoid doing an extra 
lookup */
+   lgfs2_dinode_out(sdp->md.statfs, sdp->md.statfs->i_bh->b_data);
+   bwrite(sdp->md.statfs->i_bh);
}
 
if (fix_md.riinode) {
@@ -851,13 +853,13 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
   "statfs file; aborting.\n"));
goto fail;
}
-   err = build_statfs(sdp);
-   if (err) {
+   sdp->md.statfs = build_statfs(sdp);
+   if (sdp->md.statfs == NULL) {
log_crit(_("Error %d rebuilding statfs inode\n"), err);
exit(FSCK_ERROR);
}
-   gfs2_lookupi(sdp->master_dir, "statfs", 6, >md.statfs);
-   if (!sdp->md.statfs) {
+   lgfs2_dinode_out(sdp->md.statfs, sdp->md.statfs->i_bh->b_data);
+   if (bwrite(sdp->md.statfs->i_bh) != 0) {
log_err( _("Rebuild of statfs system file failed."));
log_err( _("fsck.gfs2 cannot continue without "
   "a valid statfs file; aborting.\n"));
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index acd9929f..b19292eb 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1628,6 +1628,15 @@ static int fsck_build_inum(struct gfs2_sbd *sdp)
return 0;
 }
 
+static int fsck_build_statfs(struct gfs2_sbd *sdp)
+{
+   struct gfs2_inode *ip = build_statfs(sdp);
+   if (ip == NULL)
+   return -1;
+   inode_put();
+   return 0;
+}
+
 static int check_system_inodes(struct gfs2_sbd *sdp)
 {
int journal_count;
@@ -1662,7 +1671,7 @@ static int check_system_inodes(struct gfs2_sbd *sdp)
stack;
return -1;
}
-   if (check_system_inode(sdp, >md.statfs, "statfs", build_statfs, 0,
+   if (check_system_inode(sdp, >md.statfs, "statfs", 
fsck_build_statfs, 0,
   sdp->master_dir, !sdp->gfs1)) {
stack;
return -1;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index aea2b676..83fc90ce 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -778,7 +778,7 @@ extern int build_journal(struct gfs2_sbd *sdp, int j,
 struct gfs2_inode *jindex);
 extern struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *metafs, struct 
lgfs2_inum *jnls, size_t nmemb);
 extern struct gfs2_inode *build_inum(struct gfs2_sbd *sdp);
-extern int build_statfs(struct g

[Cluster-devel] [PATCH 07/18] libgfs2: Return the inode from build_quota_change()

2022-01-12 Thread Andrew Price
This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c |  8 
 gfs2/fsck/pass1.c   |  8 
 gfs2/fsck/pass2.c   | 12 +++-
 gfs2/libgfs2/libgfs2.h  |  2 +-
 gfs2/libgfs2/structures.c   | 18 +-
 gfs2/mkfs/main_mkfs.c   | 12 
 6 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 1cb2d6fa..0953d2a7 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2103,7 +2103,6 @@ static int build_per_node(struct gfs2_sbd *sdp)
 {
struct gfs2_inode *per_node;
unsigned int j;
-   int err;
 
per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
   GFS2_DIF_SYSTEM);
@@ -2130,12 +2129,13 @@ static int build_per_node(struct gfs2_sbd *sdp)
}
inode_put();
 
-   err = build_quota_change(per_node, j);
-   if (err) {
+   ip = build_quota_change(per_node, j);
+   if (ip == NULL) {
log_crit(_("Error building '%s': %s\n"), "quota_change",
 strerror(errno));
-   return err;
+   return 1;
}
+   inode_put();
}
inode_put(_node);
return 0;
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 3df64de7..a016f2a4 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1581,7 +1581,6 @@ int build_per_node(struct gfs2_sbd *sdp)
 {
struct gfs2_inode *per_node;
unsigned int j;
-   int err;
 
per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
   GFS2_DIF_SYSTEM);
@@ -1608,12 +1607,13 @@ int build_per_node(struct gfs2_sbd *sdp)
}
inode_put();
 
-   err = build_quota_change(per_node, j);
-   if (err) {
+   ip = build_quota_change(per_node, j);
+   if (ip == NULL) {
log_err(_("Error building '%s': %s\n"), "quota_change",
strerror(errno));
-   return err;
+   return 1;
}
+   inode_put();
}
inode_put(_node);
return 0;
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 2e0c1bb7..d82380a1 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1895,6 +1895,16 @@ static int fsck_build_statfs_change(struct gfs2_inode 
*per_node, unsigned int n)
return 0;
 }
 
+static int fsck_build_quota_change(struct gfs2_inode *per_node, unsigned int n)
+{
+   struct gfs2_inode *ip = build_quota_change(per_node, n);
+
+   if (ip == NULL)
+   return 1;
+   inode_put();
+   return 0;
+}
+
 /* Check system directory inode   */
 /* Should work for all system directories: root, master, jindex, per_node */
 static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
@@ -1986,7 +1996,7 @@ static int check_system_dir(struct gfs2_inode *sysinode, 
const char *dirname,
sprintf(fn, "quota_change%d", j);
error += check_pernode_for(j, sysinode, fn, 1048576, 1,
   _change_fxns,
-  build_quota_change);
+  fsck_build_quota_change);
}
}
return error;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 0c702df0..a928e1ab 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -789,7 +789,7 @@ extern unsigned lgfs2_bm_scan(struct rgrp_tree *rgd, 
unsigned idx,
  uint64_t *buf, uint8_t state);
 extern struct gfs2_inode *build_inum_range(struct gfs2_inode *per_node, 
unsigned int n);
 extern struct gfs2_inode *build_statfs_change(struct gfs2_inode *per_node, 
unsigned int j);
-extern int build_quota_change(struct gfs2_inode *per_node, unsigned int j);
+extern struct gfs2_inode *build_quota_change(struct gfs2_inode *per_node, 
unsigned int j);
 
 /* super.c */
 extern int check_sb(void *sbp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index bd226e6d..1d4635ab 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -313,7 +313,7 @@ struct gfs2_inode *build_statfs_change(struct gfs2_inode 
*per_node, unsigned int
return ip;
 }
 
-int build_quota_change(struct gfs2_in

[Cluster-devel] [PATCH 04/18] libgfs2: Push down build_per_node() into the utils

2022-01-12 Thread Andrew Price
The trouble with having this function in libgfs2 is that it creates
per_node and everything inside it, which means that it's difficult to
know where an error occurred and we don't have any control over how
debug/error messages are printed. It's also not necessarily the order
that we want to create the inodes in all utilities. Move
build_per_node() down into the utils and add error reporting to match.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c | 36 +++
 gfs2/fsck/fsck.h|  1 +
 gfs2/fsck/pass1.c   | 36 +++
 gfs2/libgfs2/libgfs2.h  |  1 -
 gfs2/libgfs2/structures.c   | 36 ---
 gfs2/mkfs/main_mkfs.c   | 49 +
 6 files changed, 117 insertions(+), 42 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 237160af..9a326e7f 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2099,6 +2099,42 @@ static int check_fit(struct gfs2_sbd *sdp)
return blks_avail > blks_need;
 }
 
+static int build_per_node(struct gfs2_sbd *sdp)
+{
+   struct gfs2_inode *per_node;
+   unsigned int j;
+   int err;
+
+   per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
+  GFS2_DIF_SYSTEM);
+   if (per_node == NULL) {
+   log_crit(_("Error building '%s': %s\n"), "per_node", 
strerror(errno));
+   return -1;
+   }
+   for (j = 0; j < sdp->md.journals; j++) {
+   err = build_inum_range(per_node, j);
+   if (err) {
+   log_crit(_("Error building '%s': %s\n"), "inum_range",
+strerror(errno));
+   return err;
+   }
+   err = build_statfs_change(per_node, j);
+   if (err) {
+   log_crit(_("Error building '%s': %s\n"), 
"statfs_change",
+strerror(errno));
+   return err;
+   }
+   err = build_quota_change(per_node, j);
+   if (err) {
+   log_crit(_("Error building '%s': %s\n"), "quota_change",
+strerror(errno));
+   return err;
+   }
+   }
+   inode_put(_node);
+   return 0;
+}
+
 /* We fetch the old quota inode block and copy the contents of the block
  * (minus the struct gfs2_dinode) into the new quota block. We update the 
  * inode height/size of the new quota file to that of the old one and set the 
diff --git a/gfs2/fsck/fsck.h b/gfs2/fsck/fsck.h
index f6c7d1dd..7b991614 100644
--- a/gfs2/fsck/fsck.h
+++ b/gfs2/fsck/fsck.h
@@ -200,5 +200,6 @@ extern struct special_blocks *blockfind(struct 
special_blocks *blist, uint64_t n
 extern void gfs2_special_set(struct special_blocks *blocklist, uint64_t block);
 extern void gfs2_special_free(struct special_blocks *blist);
 extern int sb_fixed;
+extern int build_per_node(struct gfs2_sbd *sdp);
 
 #endif /* _FSCK_H */
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index e976149c..38da46a6 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1577,6 +1577,42 @@ static int build_a_journal(struct gfs2_sbd *sdp)
return 0;
 }
 
+int build_per_node(struct gfs2_sbd *sdp)
+{
+   struct gfs2_inode *per_node;
+   unsigned int j;
+   int err;
+
+   per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
+  GFS2_DIF_SYSTEM);
+   if (per_node == NULL) {
+   log_err(_("Error building '%s': %s\n"), "per_node", 
strerror(errno));
+   return -1;
+   }
+   for (j = 0; j < sdp->md.journals; j++) {
+   err = build_inum_range(per_node, j);
+   if (err) {
+   log_err(_("Error building '%s': %s\n"), "inum_range",
+   strerror(errno));
+   return err;
+   }
+   err = build_statfs_change(per_node, j);
+   if (err) {
+   log_err(_("Error building '%s': %s\n"), "statfs_change",
+   strerror(errno));
+   return err;
+   }
+   err = build_quota_change(per_node, j);
+   if (err) {
+   log_err(_("Error building '%s': %s\n"), "quota_change",
+   strerror(errno));
+   return err;
+   }
+   }
+   inode_put(_node);
+   return 0;
+}
+
 static int check_system_inodes(struct gfs2_sbd *sdp)
 {
int journal_count;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index

[Cluster-devel] [PATCH 06/18] libgfs2: Return the inode from build_statfs_change()

2022-01-12 Thread Andrew Price
This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c |  8 +---
 gfs2/fsck/pass1.c   |  8 +---
 gfs2/fsck/pass2.c   | 12 +++-
 gfs2/libgfs2/libgfs2.h  |  2 +-
 gfs2/libgfs2/structures.c   | 16 +---
 gfs2/mkfs/main_mkfs.c   | 12 +---
 6 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index dd809e48..1cb2d6fa 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2122,12 +2122,14 @@ static int build_per_node(struct gfs2_sbd *sdp)
}
inode_put();
 
-   err = build_statfs_change(per_node, j);
-   if (err) {
+   ip = build_statfs_change(per_node, j);
+   if (ip == NULL) {
log_crit(_("Error building '%s': %s\n"), 
"statfs_change",
 strerror(errno));
-   return err;
+   return 1;
}
+   inode_put();
+
err = build_quota_change(per_node, j);
if (err) {
log_crit(_("Error building '%s': %s\n"), "quota_change",
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 8f576fe2..3df64de7 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1600,12 +1600,14 @@ int build_per_node(struct gfs2_sbd *sdp)
}
inode_put();
 
-   err = build_statfs_change(per_node, j);
-   if (err) {
+   ip = build_statfs_change(per_node, j);
+   if (ip == NULL) {
log_err(_("Error building '%s': %s\n"), "statfs_change",
strerror(errno));
-   return err;
+   return 1;
}
+   inode_put();
+
err = build_quota_change(per_node, j);
if (err) {
log_err(_("Error building '%s': %s\n"), "quota_change",
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 229667fb..2e0c1bb7 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1885,6 +1885,16 @@ static int fsck_build_inum_range(struct gfs2_inode 
*per_node, unsigned int n)
return 0;
 }
 
+static int fsck_build_statfs_change(struct gfs2_inode *per_node, unsigned int 
n)
+{
+   struct gfs2_inode *ip = build_statfs_change(per_node, n);
+
+   if (ip == NULL)
+   return 1;
+   inode_put();
+   return 0;
+}
+
 /* Check system directory inode   */
 /* Should work for all system directories: root, master, jindex, per_node */
 static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
@@ -1972,7 +1982,7 @@ static int check_system_dir(struct gfs2_inode *sysinode, 
const char *dirname,
   NULL, fsck_build_inum_range);
sprintf(fn, "statfs_change%d", j);
error += check_pernode_for(j, sysinode, fn, 24, 0,
-  NULL, build_statfs_change);
+  NULL, 
fsck_build_statfs_change);
sprintf(fn, "quota_change%d", j);
error += check_pernode_for(j, sysinode, fn, 1048576, 1,
   _change_fxns,
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index e9c51054..0c702df0 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -788,7 +788,7 @@ extern int gfs2_check_meta(const char *buf, int type);
 extern unsigned lgfs2_bm_scan(struct rgrp_tree *rgd, unsigned idx,
  uint64_t *buf, uint8_t state);
 extern struct gfs2_inode *build_inum_range(struct gfs2_inode *per_node, 
unsigned int n);
-extern int build_statfs_change(struct gfs2_inode *per_node, unsigned int j);
+extern struct gfs2_inode *build_statfs_change(struct gfs2_inode *per_node, 
unsigned int j);
 extern int build_quota_change(struct gfs2_inode *per_node, unsigned int j);
 
 /* super.c */
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 96a62475..bd226e6d 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -296,7 +296,7 @@ struct gfs2_inode *build_inum_range(struct gfs2_inode 
*per_node, unsigned int j)
return ip;
 }
 
-int build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
+struct gfs2_inode *build_statfs_change(struct gfs2_inode *per_node, 

[Cluster-devel] [PATCH 05/18] libgfs2: Return the inode from build_inum_range()

2022-01-12 Thread Andrew Price
This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c | 10 +++---
 gfs2/fsck/pass1.c   | 10 +++---
 gfs2/fsck/pass2.c   | 12 +++-
 gfs2/libgfs2/libgfs2.h  |  2 +-
 gfs2/libgfs2/structures.c   | 16 +---
 gfs2/mkfs/main_mkfs.c   | 14 +++---
 6 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 9a326e7f..dd809e48 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2112,12 +2112,16 @@ static int build_per_node(struct gfs2_sbd *sdp)
return -1;
}
for (j = 0; j < sdp->md.journals; j++) {
-   err = build_inum_range(per_node, j);
-   if (err) {
+   struct gfs2_inode *ip;
+
+   ip = build_inum_range(per_node, j);
+   if (ip == NULL) {
log_crit(_("Error building '%s': %s\n"), "inum_range",
 strerror(errno));
-   return err;
+   return 1;
}
+   inode_put();
+
err = build_statfs_change(per_node, j);
if (err) {
log_crit(_("Error building '%s': %s\n"), 
"statfs_change",
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 38da46a6..8f576fe2 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1590,12 +1590,16 @@ int build_per_node(struct gfs2_sbd *sdp)
return -1;
}
for (j = 0; j < sdp->md.journals; j++) {
-   err = build_inum_range(per_node, j);
-   if (err) {
+   struct gfs2_inode *ip;
+
+   ip = build_inum_range(per_node, j);
+   if (ip == NULL) {
log_err(_("Error building '%s': %s\n"), "inum_range",
strerror(errno));
-   return err;
+   return 1;
}
+   inode_put();
+
err = build_statfs_change(per_node, j);
if (err) {
log_err(_("Error building '%s': %s\n"), "statfs_change",
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 0ab35b55..229667fb 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1875,6 +1875,16 @@ build_it:
goto out_good;
 }
 
+static int fsck_build_inum_range(struct gfs2_inode *per_node, unsigned int n)
+{
+   struct gfs2_inode *ip = build_inum_range(per_node, n);
+
+   if (ip == NULL)
+   return 1;
+   inode_put();
+   return 0;
+}
+
 /* Check system directory inode   */
 /* Should work for all system directories: root, master, jindex, per_node */
 static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
@@ -1959,7 +1969,7 @@ static int check_system_dir(struct gfs2_inode *sysinode, 
const char *dirname,
for (j = 0; j < sysinode->i_sbd->md.journals; j++) {
sprintf(fn, "inum_range%d", j);
error += check_pernode_for(j, sysinode, fn, 16, 0,
-  NULL, build_inum_range);
+  NULL, fsck_build_inum_range);
sprintf(fn, "statfs_change%d", j);
error += check_pernode_for(j, sysinode, fn, 24, 0,
   NULL, build_statfs_change);
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 863b84e6..e9c51054 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -787,7 +787,7 @@ extern int do_init_statfs(struct gfs2_sbd *sdp);
 extern int gfs2_check_meta(const char *buf, int type);
 extern unsigned lgfs2_bm_scan(struct rgrp_tree *rgd, unsigned idx,
  uint64_t *buf, uint8_t state);
-extern int build_inum_range(struct gfs2_inode *per_node, unsigned int j);
+extern struct gfs2_inode *build_inum_range(struct gfs2_inode *per_node, 
unsigned int n);
 extern int build_statfs_change(struct gfs2_inode *per_node, unsigned int j);
 extern int build_quota_change(struct gfs2_inode *per_node, unsigned int j);
 
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index c9c31dd2..96a62475 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -279,7 +279,7 @@ struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode 
*master, struct lgfs2_in
return jindex;
 }
 
-int build_inum_range(struc

[Cluster-devel] [PATCH 03/18] libgfs2: Move build_jindex() into fsck.gfs2

2022-01-12 Thread Andrew Price
fsck.gfs2 is the only remaining util that builds journals this way so
move it out of libgfs2. The debug printfs can be removed because
fsck.gfs2 doesn't enable libgfs2's cfg_debug.

Signed-off-by: Andrew Price 
---
 gfs2/fsck/fs_recovery.c   | 21 +
 gfs2/fsck/fs_recovery.h   |  1 +
 gfs2/fsck/pass2.c |  1 +
 gfs2/libgfs2/libgfs2.h|  1 -
 gfs2/libgfs2/structures.c | 29 -
 5 files changed, 23 insertions(+), 30 deletions(-)

diff --git a/gfs2/fsck/fs_recovery.c b/gfs2/fsck/fs_recovery.c
index 48d98626..e5cde051 100644
--- a/gfs2/fsck/fs_recovery.c
+++ b/gfs2/fsck/fs_recovery.c
@@ -848,6 +848,27 @@ static struct metawalk_fxns jindex_check_fxns = {
.check_dentry = check_jindex_dent,
 };
 
+int build_jindex(struct gfs2_sbd *sdp)
+{
+   struct gfs2_inode *jindex;
+
+   jindex = createi(sdp->master_dir, "jindex", S_IFDIR | 0700,
+GFS2_DIF_SYSTEM);
+   if (jindex == NULL) {
+   return errno;
+   }
+   sdp->md.journal = malloc(sdp->md.journals * sizeof(struct gfs2_inode 
*));
+   for (unsigned j = 0; j < sdp->md.journals; j++) {
+   int ret = build_journal(sdp, j, jindex);
+   if (ret)
+   return ret;
+   inode_put(>md.journal[j]);
+   }
+   free(sdp->md.journal);
+   inode_put();
+   return 0;
+}
+
 /**
  * init_jindex - read in the rindex file
  */
diff --git a/gfs2/fsck/fs_recovery.h b/gfs2/fsck/fs_recovery.h
index d6876274..884d3c43 100644
--- a/gfs2/fsck/fs_recovery.h
+++ b/gfs2/fsck/fs_recovery.h
@@ -8,6 +8,7 @@ extern int replay_journals(struct gfs2_sbd *sdp, int preen, int 
force_check,
 extern int preen_is_safe(struct gfs2_sbd *sdp, int preen, int force_check);
 
 extern int ji_update(struct gfs2_sbd *sdp);
+extern int build_jindex(struct gfs2_sbd *sdp);
 extern int init_jindex(struct gfs2_sbd *sdp, int allow_ji_rebuild);
 #endif /* __FS_RECOVERY_H__ */
 
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 998b0c96..0ab35b55 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -18,6 +18,7 @@
 #include "lost_n_found.h"
 #include "inode_hash.h"
 #include "afterpass1_common.h"
+#include "fs_recovery.h"
 
 #define MAX_FILENAME 256
 
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 990a9d9e..9a66b5b3 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -776,7 +776,6 @@ extern int build_master(struct gfs2_sbd *sdp);
 extern int lgfs2_sb_write(const struct gfs2_sbd *sdp, int fd);
 extern int build_journal(struct gfs2_sbd *sdp, int j,
 struct gfs2_inode *jindex);
-extern int build_jindex(struct gfs2_sbd *sdp);
 extern struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *metafs, struct 
lgfs2_inum *jnls, size_t nmemb);
 extern int build_per_node(struct gfs2_sbd *sdp);
 extern int build_inum(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index de36c4e3..09d7041e 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -279,35 +279,6 @@ struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode 
*master, struct lgfs2_in
return jindex;
 }
 
-int build_jindex(struct gfs2_sbd *sdp)
-{
-   struct gfs2_inode *jindex;
-   unsigned int j;
-   int ret;
-
-   jindex = createi(sdp->master_dir, "jindex", S_IFDIR | 0700,
-GFS2_DIF_SYSTEM);
-   if (jindex == NULL) {
-   return errno;
-   }
-   sdp->md.journal = malloc(sdp->md.journals *
-sizeof(struct gfs2_inode *));
-   for (j = 0; j < sdp->md.journals; j++) {
-   ret = build_journal(sdp, j, jindex);
-   if (ret)
-   return ret;
-   inode_put(>md.journal[j]);
-   }
-   if (cfg_debug) {
-   printf("\nJindex:\n");
-   lgfs2_dinode_print(jindex->i_bh->b_data);
-   }
-
-   free(sdp->md.journal);
-   inode_put();
-   return 0;
-}
-
 int build_inum_range(struct gfs2_inode *per_node, unsigned int j)
 {
char name[256];
-- 
2.34.1



[Cluster-devel] [PATCH 08/18] libgfs2: Return the inode from build_inum()

2022-01-12 Thread Andrew Price
This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c |  5 ++---
 gfs2/fsck/initialize.c  | 25 -
 gfs2/fsck/pass1.c   | 11 ++-
 gfs2/libgfs2/libgfs2.h  |  2 +-
 gfs2/libgfs2/structures.c   | 14 ++
 gfs2/mkfs/main_mkfs.c   |  9 ++---
 6 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 0953d2a7..210528c9 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2343,13 +2343,12 @@ int main(int argc, char **argv)
exit(-1);
}
/* Create the empty inode number file */
-   error = build_inum(); /* Does not do inode_put */
-   if (error) {
+   sb2.md.inum = build_inum(); /* Does not do inode_put */
+   if (sb2.md.inum == NULL) {
log_crit(_("Error building inum inode: %s\n"),
 strerror(error));
exit(-1);
}
-   gfs2_lookupi(sb2.master_dir, "inum", 4, );
/* Create the statfs file */
error = build_statfs(); /* Does not do inode_put */
if (error) {
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index b9db79b0..a46d3ecb 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -504,12 +504,14 @@ static int rebuild_master(struct gfs2_sbd *sdp)
exit(FSCK_ERROR);
}
} else {
-   err = build_inum(sdp);
-   if (err) {
-   log_crit(_("Error %d building inum inode\n"), err);
+   sdp->md.inum = build_inum(sdp);
+   if (sdp->md.inum == NULL) {
+   log_crit(_("Error building inum inode: %s\n"), 
strerror(errno));
exit(FSCK_ERROR);
}
-   gfs2_lookupi(sdp->master_dir, "inum", 4, >md.inum);
+   /* Write the inode but don't free it, to avoid doing an extra 
lookup */
+   lgfs2_dinode_out(sdp->md.inum, sdp->md.inum->i_bh->b_data);
+   bwrite(sdp->md.inum->i_bh);
}
 
if (fix_md.statfs) {
@@ -798,17 +800,14 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
   "a valid inum file; aborting.\n"));
goto fail;
}
-   err = build_inum(sdp);
-   if (err) {
-   log_crit(_("Error %d rebuilding inum inode\n"),
-err);
+   sdp->md.inum = build_inum(sdp);
+   if (sdp->md.inum == NULL) {
+   log_crit(_("Error rebuilding inum inode: 
%s\n"), strerror(errno));
exit(FSCK_ERROR);
}
-   gfs2_lookupi(sdp->master_dir, "inum", 4,
->md.inum);
-   if (!sdp->md.inum) {
-   log_crit(_("System inum inode was not rebuilt."
-  " Aborting.\n"));
+   lgfs2_dinode_out(sdp->md.inum, 
sdp->md.inum->i_bh->b_data);
+   if (bwrite(sdp->md.inum->i_bh) != 0) {
+   log_crit(_("System inum inode was not rebuilt. 
Aborting.\n"));
goto fail;
}
}
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index a016f2a4..acd9929f 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1619,6 +1619,15 @@ int build_per_node(struct gfs2_sbd *sdp)
return 0;
 }
 
+static int fsck_build_inum(struct gfs2_sbd *sdp)
+{
+   struct gfs2_inode *ip = build_inum(sdp);
+   if (ip == NULL)
+   return -1;
+   inode_put();
+   return 0;
+}
+
 static int check_system_inodes(struct gfs2_sbd *sdp)
 {
int journal_count;
@@ -1648,7 +1657,7 @@ static int check_system_inodes(struct gfs2_sbd *sdp)
return -1;
}
if (!sdp->gfs1 &&
-   check_system_inode(sdp, >md.inum, "inum", build_inum, 0,
+   check_system_inode(sdp, >md.inum, "inum", fsck_build_inum, 0,
   sdp->master_dir, 1)) {
stack;
 

[Cluster-devel] [PATCH 02/18] libgfs2: Rework lgfs2_build_jindex()

2022-01-12 Thread Andrew Price
Return the inode instead of freeing it and move the debug printfs out of
libgfs2.

Signed-off-by: Andrew Price 
---
 gfs2/libgfs2/libgfs2.h|  2 +-
 gfs2/libgfs2/structures.c | 23 ---
 gfs2/mkfs/main_mkfs.c | 27 ++-
 3 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 04e6ec0f..990a9d9e 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -777,7 +777,7 @@ extern int lgfs2_sb_write(const struct gfs2_sbd *sdp, int 
fd);
 extern int build_journal(struct gfs2_sbd *sdp, int j,
 struct gfs2_inode *jindex);
 extern int build_jindex(struct gfs2_sbd *sdp);
-extern int lgfs2_build_jindex(struct gfs2_inode *master, struct lgfs2_inum 
*jnls, size_t nmemb);
+extern struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *metafs, struct 
lgfs2_inum *jnls, size_t nmemb);
 extern int build_per_node(struct gfs2_sbd *sdp);
 extern int build_inum(struct gfs2_sbd *sdp);
 extern int build_statfs(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 95ad3ac9..de36c4e3 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -251,39 +251,32 @@ int build_journal(struct gfs2_sbd *sdp, int j, struct 
gfs2_inode *jindex)
  * nmemb: The number of entries in the list (number of journals).
  * Returns 0 on success or non-zero on error with errno set.
  */
-int lgfs2_build_jindex(struct gfs2_inode *master, struct lgfs2_inum *jnls, 
size_t nmemb)
+struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *master, struct 
lgfs2_inum *jnls, size_t nmemb)
 {
char fname[GFS2_FNAMESIZE + 1];
struct gfs2_inode *jindex;
-   unsigned j;
-   int ret;
 
if (nmemb == 0 || jnls == NULL) {
errno = EINVAL;
-   return 1;
+   return NULL;
}
jindex = createi(master, "jindex", S_IFDIR | 0700, GFS2_DIF_SYSTEM);
if (jindex == NULL)
-   return 1;
+   return NULL;
 
fname[GFS2_FNAMESIZE] = '\0';
 
-   for (j = 0; j < nmemb; j++) {
+   for (unsigned j = 0; j < nmemb; j++) {
+   int ret;
+
snprintf(fname, GFS2_FNAMESIZE, "journal%u", j);
ret = dir_add(jindex, fname, strlen(fname), [j], 
IF2DT(S_IFREG | 0600));
if (ret) {
inode_put();
-   return 1;
+   return NULL;
}
}
-
-   if (cfg_debug) {
-   printf("\nJindex:\n");
-   lgfs2_dinode_print(jindex->i_bh->b_data);
-   }
-
-   inode_put();
-   return 0;
+   return jindex;
 }
 
 int build_jindex(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index dbee5cab..17284976 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -941,6 +941,24 @@ static int place_rgrps(struct gfs2_sbd *sdp, lgfs2_rgrps_t 
rgs, uint64_t *rgaddr
return 0;
 }
 
+static int create_jindex(struct gfs2_sbd *sdp, struct mkfs_opts *opts, struct 
lgfs2_inum *jnls)
+{
+   struct gfs2_inode *jindex;
+
+   jindex = lgfs2_build_jindex(sdp->master_dir, jnls, opts->journals);
+   if (jindex == NULL) {
+   fprintf(stderr, _("Error building '%s': %s\n"), "jindex", 
strerror(errno));
+   return 1;
+   }
+   if (opts->debug) {
+   printf("Jindex:\n");
+   lgfs2_dinode_print(jindex->i_bh->b_data);
+   }
+   inode_put();
+   return 0;
+}
+
+
 /*
  * Find a reasonable journal file size (in blocks) given the number of blocks
  * in the filesystem.  For very small filesystems, it is not reasonable to
@@ -1211,12 +1229,11 @@ int main(int argc, char *argv[])
}
sbd.sd_meta_dir = sbd.master_dir->i_num;
 
-   error = lgfs2_build_jindex(sbd.master_dir, mkfs_journals, 
opts.journals);
-   if (error) {
-   fprintf(stderr, _("Error building '%s': %s\n"), "jindex", 
strerror(errno));
-   exit(EXIT_FAILURE);
-   }
+   error = create_jindex(, , mkfs_journals);
free(mkfs_journals);
+   if (error != 0)
+   exit(1);
+
error = build_per_node();
if (error) {
fprintf(stderr, _("Error building '%s': %s\n"), "per_node", 
strerror(errno));
-- 
2.34.1



[Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2

2022-01-12 Thread Andrew Price
This patch set fixes a long-standing issue in libgfs2 where it requires apps 
linking to it to provide a print_it function, which it uses in 
lgfs2_(struct)_print() functions defined in libgfs2/ondisk.c. This was the main 
blocker to it becoming a library in a more meaningful sense.

The approach taken is to remove the responsibility of printing gfs2 structures 
from libgfs2 altogether. So the first challenge is to remove debugging output 
from libgfs2 and push it down into the utils, which in turn required returning 
more context from some libgfs2 functions, mainly the build_* functions in 
structures.c.

The overall result is more flexibility and control over the way the utils print 
on-disk structures and improved error/debug messages. Test code is also tidied 
up as we no longer have to define a print_it() in each of the tests.


Andrew Price (18):
  libgfs2: Move debugging printf out of build_master()
  libgfs2: Rework lgfs2_build_jindex()
  libgfs2: Move build_jindex() into fsck.gfs2
  libgfs2: Push down build_per_node() into the utils
  libgfs2: Return the inode from build_inum_range()
  libgfs2: Return the inode from build_statfs_change()
  libgfs2: Return the inode from build_quota_change()
  libgfs2: Return the inode from build_inum()
  libgfs2: Return the inode from build_statfs()
  libgfs2: Return the inode from build_rindex()
  libgfs2: Return the inode from build_quota()
  libgfs2: Move debugging printf out of build_root()
  libgfs2: Remove debugging printf from do_init_statfs()
  libgfs2: Move debugging output out of do_init_inum()
  libgfs2: Remove debugging printfs from fix_device_geometry()
  libgfs2: Remove config.[ch]
  libgfs2: Move struct printing functions out of libgfs2
  libgfs2: Remove print_it extern requirement

 gfs2/convert/gfs2_convert.c|  80 +---
 gfs2/edit/Makefile.am  |   2 +
 gfs2/edit/extended.c   |  18 +-
 gfs2/edit/gfs2hex.c| 156 +-
 gfs2/edit/hexedit.c|  36 +---
 gfs2/edit/hexedit.h|   4 +-
 gfs2/edit/struct_print.c   | 364 +
 gfs2/edit/struct_print.h   |  23 +++
 gfs2/fsck/fs_recovery.c|  21 ++
 gfs2/fsck/fs_recovery.h|   1 +
 gfs2/fsck/fsck.h   |   1 +
 gfs2/fsck/initialize.c |  75 +++
 gfs2/fsck/main.c   |  13 +-
 gfs2/fsck/pass1.c  |  86 +++-
 gfs2/fsck/pass2.c  |  37 +++-
 gfs2/glocktop/glocktop.c   |   3 +-
 gfs2/libgfs2/Makefile.am   |   2 -
 gfs2/libgfs2/check_libgfs2.c   |   3 -
 gfs2/libgfs2/checks.am |   1 -
 gfs2/libgfs2/config.c  |   9 -
 gfs2/libgfs2/config.h  |   6 -
 gfs2/libgfs2/device_geometry.c |   7 -
 gfs2/libgfs2/gfs2l.c   |   3 -
 gfs2/libgfs2/libgfs2.h |  40 +---
 gfs2/libgfs2/ondisk.c  | 199 --
 gfs2/libgfs2/structures.c  | 226 
 gfs2/mkfs/Makefile.am  |   2 +
 gfs2/mkfs/gfs2_mkfs.h  |  11 -
 gfs2/mkfs/main_jadd.c  |   1 -
 gfs2/mkfs/main_mkfs.c  | 152 +++---
 gfs2/mkfs/struct_print.c   | 218 
 gfs2/mkfs/struct_print.h   |  19 ++
 tests/nukerg.c |   3 -
 33 files changed, 1067 insertions(+), 755 deletions(-)
 create mode 100644 gfs2/edit/struct_print.c
 create mode 100644 gfs2/edit/struct_print.h
 delete mode 100644 gfs2/libgfs2/config.c
 delete mode 100644 gfs2/libgfs2/config.h
 create mode 100644 gfs2/mkfs/struct_print.c
 create mode 100644 gfs2/mkfs/struct_print.h

-- 
2.34.1



[Cluster-devel] [PATCH 01/18] libgfs2: Move debugging printf out of build_master()

2022-01-12 Thread Andrew Price
mkfs.gfs2 is the only place it could ever get printed so move it there
instead.

Signed-off-by: Andrew Price 
---
 gfs2/libgfs2/structures.c | 4 
 gfs2/mkfs/main_mkfs.c | 4 
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index a562dc50..95ad3ac9 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -38,10 +38,6 @@ int build_master(struct gfs2_sbd *sdp)
if (sdp->master_dir == NULL)
return -1;
 
-   if (cfg_debug) {
-   printf("\nMaster dir:\n");
-   lgfs2_dinode_print(bh->b_data);
-   }
sdp->master_dir->bh_owned = 1;
return 0;
 }
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 6f30b2d3..dbee5cab 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1205,6 +1205,10 @@ int main(int argc, char *argv[])
fprintf(stderr, _("Error building '%s': %s\n"), "master", 
strerror(errno));
exit(EXIT_FAILURE);
}
+   if (opts.debug) {
+   printf("Metafs inode:\n");
+   lgfs2_dinode_print(sbd.master_dir->i_bh->b_data);
+   }
sbd.sd_meta_dir = sbd.master_dir->i_num;
 
error = lgfs2_build_jindex(sbd.master_dir, mkfs_journals, 
opts.journals);
-- 
2.34.1



Re: [Cluster-devel] Upcoming change to the gfs2-utils.git repository

2022-01-05 Thread Andrew Price

On 04/01/2022 15:35, Andrew Price wrote:

Happy new year, all!

Just a heads-up that the main branch in gfs2-utils.git will be renamed 
from master to main tomorrow (January 5). I will follow the procedure here:


   https://wiki.clusterlabs.org/wiki/How_to_rename_git_default_branch

The wiki page also has a section on how to update your local clone to 
use the new upstream branch name. Thanks to Ken for writing that up!


This change affects https://pagure.io/gfs2-utils.git

I will post a follow-up once the change has been completed.


This change is now complete. To update your gfs2-utils git branch 
references locally, use:


  $ git branch --set-upstream-to origin/main 

for es that currently have origin/master as the remote ref.

To rename your local master branch to main:

  $ git branch -m master main

Cheers,
Andy



[Cluster-devel] Upcoming change to the gfs2-utils.git repository

2022-01-04 Thread Andrew Price

Happy new year, all!

Just a heads-up that the main branch in gfs2-utils.git will be renamed 
from master to main tomorrow (January 5). I will follow the procedure here:


  https://wiki.clusterlabs.org/wiki/How_to_rename_git_default_branch

The wiki page also has a section on how to update your local clone to 
use the new upstream branch name. Thanks to Ken for writing that up!


This change affects https://pagure.io/gfs2-utils.git

I will post a follow-up once the change has been completed.

Cheers,
Andy



Re: [Cluster-devel] message in syslog: shrink_slab: gfs2_glock_shrink_scan+0x0/0x240 [gfs2] negative objects to delete nr=xxxxxxxxxxxx

2021-12-08 Thread Andrew Price

Hi Bernd,

On 08/12/2021 16:50, Lentes, Bernd wrote:

Hi,

i hope this is the right place for asking about GFS2.
Yesterday one of my two nodes HA-cluster got slower and slower, until it was 
fenced.
In /var/log/messages i found this message repeated often before the system got 
slower:
shrink_slab: gfs2_glock_shrink_scan+0x0/0x240 [gfs2] negative objects to delete 
nr=
What does it mean ? Is it a problem ?


This could be the same issue as 
https://bugzilla.redhat.com/show_bug.cgi?id=1599324


The last comment in that bug mentions a kernel patch that is probably 
missing from your distro kernel version.


Cheers,
Andy



My Setup:
SuSE SLES 12 SP5
Kernel 4.12.14-122.46-default
Pacemaker 1.1.23
corosync 2.3.6-9.13.1
gfs2-utils-3.1.6-1.101.x86_64

Thanks.

Bernd





[Cluster-devel] [PATCH] gfs2_grow.8: Man page improvements

2021-12-08 Thread Andrew Price
- Restructure sentences to make gfs2_grow the subject instead of "you"
- Use more consistent formatting
- Remove some unnecessary technical details
- Move a sentence relating to the -T option to the options section
- List the lack of shrink support as a note instead of a bug

Signed-off-by: Andrew Price 
---
 gfs2/man/gfs2_grow.8 | 53 +---
 1 file changed, 20 insertions(+), 33 deletions(-)

diff --git a/gfs2/man/gfs2_grow.8 b/gfs2/man/gfs2_grow.8
index 8bef1a47..f1ba5e4e 100644
--- a/gfs2/man/gfs2_grow.8
+++ b/gfs2/man/gfs2_grow.8
@@ -8,39 +8,25 @@ gfs2_grow - Expand a GFS2 filesystem
 [\fIOPTION\fR]... <\fIDEVICE\fR|\fIMOUNTPOINT\fR>...
 
 .SH DESCRIPTION
-gfs2_grow is used to expand a GFS2 filesystem after the device
-upon which the filesystem resides has also been expanded.  By
-running gfs2_grow on a GFS2 filesystem, you are requesting that
-any spare space between the current end of the filesystem and
-the end of the device is filled with a newly initialized GFS2
-filesystem extension.  When this operation is complete, the resource
-group index for the filesystem is updated so that all nodes in the
+\fBgfs2_grow\fP expands a GFS2 filesystem after the device upon which the
+filesystem resides has also been expanded. \fBgfs2_grow\fP expands the GFS2
+filesystem to utilize any unused space between the current end of the
+filesystem and the end of the block device.  When this operation is complete,
+the resource group index for the filesystem is updated so that all nodes in the
 cluster can use the extra storage space that has been added.
 
 See \fBlvmlockd(8)\fP for the procedure to extend and refresh the logical
-volume prior to running gfs2_grow.
+volume prior to running \fBgfs2_grow\fP.
 
-You may only run gfs2_grow on a mounted filesystem; expansion of 
-unmounted filesystems is not supported.  You only need to
-run gfs2_grow on one node in the cluster.  All the other nodes will
-see the expansion has occurred and automatically start to use the
-newly available space.
+The \fIDEVICE\fR or \fIMOUNTPOINT\fR arguments must be paths to mounted
+filesystems; expansion of unmounted filesystems is not supported.
+\fBgfs2_grow\fP need only be run on one node in the cluster.  The other nodes
+will see the expansion has occurred and automatically start to use the newly
+available space.
 
-You must be superuser to execute \fBgfs2_grow\fP.  The gfs2_grow
-tool tries to prevent you from corrupting your filesystem by checking as
-many of the likely problems as it can.  When expanding a filesystem,
-only the last step of updating the resource index affects the currently
-mounted filesystem and so failure part way through the expansion process
-should leave your filesystem in its original unexpanded state.
-
-You can run gfs2_grow with the \fB-T\fP flag to get a display
-of the current state of a mounted GFS2 filesystem.
-
-The gfs2_grow tool uses the resource group (RG) size that was originally
-calculated when mkfs.gfs2 was done.  This allows tools like fsck.gfs2
-to better ensure the integrity of the file system.  Since the new free
-space often does not lie on even boundaries based on that RG size,
-there may be some unused space on the device after gfs2_grow is run.
+\fBgfs2_grow\fP must be run as the superuser. When the filesystem cannot be
+resized due to detected errors, \fBgfs2_grow\fP will leave the filesystem in a
+consistent state.
 .SH OPTIONS
 .TP
 \fB-D\fP
@@ -53,16 +39,17 @@ Prints out a short usage message and exits.
 Be quiet.  Don't print anything.
 .TP
 \fB-T\fP
-Test. Do all calculations, but do not write any data to the disk and do
-not expand the filesystem. This is used to discover what the tool would
-have done were it run without this flag.
+Test. Do all calculations, but do not write any data to the disk and do not
+expand the filesystem. This is used to discover what the tool would have done
+were it run without this flag. This option can be used to display the current
+state of a mounted GFS2 filesystem.
 .TP
 \fB-V\fP
 Version. Print out version information, then exit.
 
-.SH BUGS
+.SH NOTES
 
-There is no way to shrink a GFS2 filesystem.
+Shrinking GFS2 filesystems is currently unsupported.
 
 .SH SEE ALSO
 .BR mkfs.gfs2(8)
-- 
2.33.1



[Cluster-devel] [PATCH gfs2-utils] tests: Increase the size of the sparse file used by tests

2021-11-09 Thread Andrew Price
Bump the size of the 'testvol' sparse file that the tests use to 20G.
The actual disk space used is more like 200M which should be fine for
build environments. The increased size allows more resource groups to be
created in tests that use a larger resource group size.

Signed-off-by: Andrew Price 
---
 tests/atlocal.in | 2 +-
 tests/edit.at| 4 ++--
 tests/tune.at| 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tests/atlocal.in b/tests/atlocal.in
index b021b132..b0f22f10 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -1,5 +1,5 @@
 GFS_TGT="$abs_builddir/testvol"
-GFS_TGT_SZ=10
+GFS_TGT_SZ=20
 GFS_MKFS="mkfs.gfs2 -O -D"
 
 gfs_max_blocks()
diff --git a/tests/edit.at b/tests/edit.at
index d70d012e..d6795218 100644
--- a/tests/edit.at
+++ b/tests/edit.at
@@ -6,8 +6,8 @@ AT_KEYWORDS(gfs2_edit edit)
 GFS_TGT_REGEN
 AT_CHECK([$GFS_MKFS -p lock_nolock $GFS_TGT $(($(gfs_max_blocks 4096)/2))], 0, 
[ignore], [ignore])
 AT_CHECK([gfs2_edit savemeta $GFS_TGT test.meta > savemeta.log], 0, [ignore], 
[ignore])
-AT_CHECK([head -2 savemeta.log], 0, [There are 1310716 blocks of 4096 bytes in 
the filesystem.
-Filesystem size: 5.00GB
+AT_CHECK([head -2 savemeta.log], 0, [There are 2621439 blocks of 4096 bytes in 
the filesystem.
+Filesystem size: 10.00GB
 ], [ignore])
 GFS_TGT_REGEN
 AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore])
diff --git a/tests/tune.at b/tests/tune.at
index 43ce34ce..4f0ecd79 100644
--- a/tests/tune.at
+++ b/tests/tune.at
@@ -32,8 +32,8 @@ File system magic number: 0x1161970
 File system format version: 1802
 Block size: 4096
 Block shift: 12
-Root inode: 16709
-Master inode: 16437
+Root inode: 33127
+Master inode: 32854
 Lock protocol: lock_nolock
 Lock table: cluster:fsname
 " > expout], 0, [ignore], [ignore])
-- 
2.31.1



[Cluster-devel] gfs2-utils pull requests enabled

2021-11-08 Thread Andrew Price

Hi,

I've enabled the pull requests feature for gfs2-utils.git on 
https://pagure.io/gfs2-utils after a contributor enquired about it. I 
don't expect to receive many of them but the option is now there for 
those who prefer it to emailing patches.


Cheers,
Andy



[Cluster-devel] [PATCH] tunegfs2: Use O_EXCL when opening the device rw

2021-11-04 Thread Andrew Price
Use O_RDONLY when listing and O_RDWR|O_EXCL when modifying.

Also don't print the tunegfs2 version with -l output, improve open()
error reporting and add some more basic tunegfs2 tests.

Signed-off-by: Andrew Price 
---
 gfs2/tune/main.c | 12 ++--
 tests/tune.at| 30 ++
 2 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/gfs2/tune/main.c b/gfs2/tune/main.c
index fe137803..f72bdc3c 100644
--- a/gfs2/tune/main.c
+++ b/gfs2/tune/main.c
@@ -65,6 +65,7 @@ static void version(void)
 int main(int argc, char **argv)
 {
int c, status;
+   int flags = O_RDWR | O_EXCL;
 
memset(tfs, 0, sizeof(struct tunegfs2));
while((c = getopt(argc, argv, "hL:U:lo:Vr:")) != -1) {
@@ -82,6 +83,7 @@ int main(int argc, char **argv)
break;
case 'l':
tfs->opt_list = 1;
+   flags = O_RDONLY;
break;
case 'o':
parse_mount_options(optarg);
@@ -113,11 +115,11 @@ int main(int argc, char **argv)
}
 
tfs->devicename = argv[optind];
-   tfs->fd = open(tfs->devicename, O_RDWR); 
+   tfs->fd = open(tfs->devicename, flags);
 
if (tfs->fd < 0) {
-   fprintf(stderr, _("Unable to open device %s\n"),
-   tfs->devicename);
+   fprintf(stderr, _("Unable to open device %s: %s\n"),
+   tfs->devicename, strerror(errno));
return EX_IOERR;
}
 
@@ -160,10 +162,8 @@ int main(int argc, char **argv)
goto out;
}
 
-   if (tfs->opt_list) {
-   version();
+   if (tfs->opt_list)
print_super(tfs);
-   }
 
close(tfs->fd);
 out:
diff --git a/tests/tune.at b/tests/tune.at
index b0158034..43ce34ce 100644
--- a/tests/tune.at
+++ b/tests/tune.at
@@ -15,3 +15,33 @@ AT_CHECK([$GFS_MKFS -p lock_nolock -o format=1801 $GFS_TGT], 
0, [ignore], [ignor
 AT_CHECK([tunegfs2 -r 1802 $GFS_TGT], 0, [ignore], [ignore])
 AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
 AT_CLEANUP
+
+AT_SETUP([Handle bad fs])
+AT_KEYWORDS(tunegfs2 tune)
+AT_CHECK([tunegfs2 -l /dev/null], 74, [ignore], [Device does not contain a GFS 
or GFS2 file system
+])
+AT_CHECK([tunegfs2 -l /dev/zero], 74, [ignore], [Device does not contain a GFS 
or GFS2 file system
+])
+AT_CLEANUP
+
+AT_SETUP([Expected output])
+AT_KEYWORDS(tunegfs2 tune)
+AT_CHECK([echo -n "File system volume name: cluster:fsname
+File system UUID: e90815fc-087b-460c-b8a5-8edc8a2ed691
+File system magic number: 0x1161970
+File system format version: 1802
+Block size: 4096
+Block shift: 12
+Root inode: 16709
+Master inode: 16437
+Lock protocol: lock_nolock
+Lock table: cluster:fsname
+" > expout], 0, [ignore], [ignore])
+# Create the fs without alignment so that we can predict the root inode address
+AT_CHECK([$GFS_MKFS -p lock_nolock -t cluster:fsname -o align=0 $GFS_TGT], 0, 
[ignore], [ignore])
+# Set a known UUID to ease comparison
+AT_CHECK([tunegfs2 -U e90815fc-087b-460c-b8a5-8edc8a2ed691 $GFS_TGT], 0, 
[ignore], [ignore])
+# Check tunegfs2 set the UUID correctly with gfs2_edit
+AT_CHECK([gfs2_edit -p sb field sb_uuid $GFS_TGT | tr -d '\n'], 0, 
[e90815fc-087b-460c-b8a5-8edc8a2ed691], [ignore])
+AT_CHECK([tunegfs2 -l $GFS_TGT], 0, [expout], [stderr])
+AT_CLEANUP
-- 
2.31.1



Re: [Cluster-devel] [GFS2 PATCH 13/15] gfs2: ignore usr|grp|prjquota mount options

2021-08-02 Thread Andrew Price

On 28/07/2021 21:32, Bob Peterson wrote:

On 7/28/21 1:28 PM, Andreas Gruenbacher wrote:

On Tue, Jul 27, 2021 at 7:37 PM Bob Peterson  wrote:

Before this patch, gfs2 rejected mounts attempted with the usrquota,
grpquota, or prjquota mount options. That caused numerous xfstests tests
to fail. This patch allows gfs2 to accept but ignore those mount options
so the tests may be run.


We can't just fake this up. Instead, the fstests need to be fixed to
skip tests that don't run on particular filesystems.

Hi Andreas,

I see your point, and sure, the maintainers of xfstests can improve the 
tests to make them check whether the options are supported for gfs2 as

they do with other some other options.

Still, if you look at the man page for "mount(8)" under "Mount options 
for affs" you see:


"grpquota|noquota|quota|usrquota
These options are accepted but ignored.  (However, quota utilities may 
react to such strings in /etc/fstab.)"


If you look at "Mount options for jfs" you similarly see:

"noquota|quota|usrquota|grpquota
These options are accepted but ignored."

So if affs and jfs can ignore these mount options, why can't gfs2?
Are we planning to support them ever?
FWIW I agree with Andreas, this is definitely a bug in the test suite. 
If we fix fstests then we can use fstests for bisecting older gfs2 
issues, but if we no-op incompatible mount options that make their way 
into the generic tests then we're only fixing the tests for future gfs2 
versions and not older ones.


Andy



[Cluster-devel] [PATCH] gfs2-utils: Include asm/types.h in our linux/types.h

2021-06-29 Thread Andrew Price
Include asm/types.h to provide __u* and __s*, and __vector128 which
fixes build failures on ppc64le and s390x:

  In file included from /usr/include/asm/sigcontext.h:14,
   from /usr/include/bits/sigcontext.h:30,
   from /usr/include/signal.h:291,
   from hexedit.c:16:
  /usr/include/asm/elf.h:160:9: error: unknown type name ‘__vector128’
   typedef __vector128 elf_vrreg_t;

asm/types.h is included in the original linux/types.h so this reduces
the difference (at the expense of portability).

Signed-off-by: Andrew Price 
---
 gfs2/include/linux/types.h | 24 
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/gfs2/include/linux/types.h b/gfs2/include/linux/types.h
index a092afc0..46ef54ba 100644
--- a/gfs2/include/linux/types.h
+++ b/gfs2/include/linux/types.h
@@ -1,6 +1,8 @@
 #ifndef LINUX_TYPES_H
 #define LINUX_TYPES_H
 
+#include 
+
 /* Satisfy gfs2_ondisk.h with userspace definitions of kernel types */
 
 #include 
@@ -15,21 +17,11 @@
 #define __bitwise __bitwise__
 #define __force __force__
 
-typedef uint8_t __u8;
-typedef uint16_t __u16;
-typedef uint32_t __u32;
-typedef uint64_t __u64;
-
-typedef int8_t __s8;
-typedef int16_t __s16;
-typedef int32_t __s32;
-typedef int64_t __s64;
-
-typedef __u16 __bitwise __le16;
-typedef __u16 __bitwise __be16;
-typedef __u32 __bitwise __le32;
-typedef __u32 __bitwise __be32;
-typedef __u64 __bitwise __le64;
-typedef __u64 __bitwise __be64;
+typedef uint16_t __bitwise __le16;
+typedef uint16_t __bitwise __be16;
+typedef uint32_t __bitwise __le32;
+typedef uint32_t __bitwise __be32;
+typedef uint64_t __bitwise __le64;
+typedef uint64_t __bitwise __be64;
 
 #endif /* LINUX_TYPES_H */
-- 
2.31.1



[Cluster-devel] [PATCH] libgfs2: Add __force tags to endianness conversion macros

2021-04-23 Thread Andrew Price
The __be* on-disk field types are annotated with __bitwise, which causes
sparse to recognise them as conflicting with non-__bitwise types, but
the endianness conversion macros don't have the required annotations to
tell sparse when to resolve the conflicts instead of flagging a warning.
Add __force annotations to the conversion macros.

This clears up a handful of sparse warnings but the anti-pattern of
storing cpu-endian values in the on-disk structs is still common (see
libgfs2/ondisk.c), so there are still some to be resolved.

Signed-off-by: Andrew Price 
---
 gfs2/convert/gfs2_convert.c |  2 +-
 gfs2/include/linux/types.h  |  3 +++
 gfs2/libgfs2/libgfs2.h  | 49 ++---
 3 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 5656b39d..ded2589e 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -1201,7 +1201,7 @@ static int process_dirent_info(struct gfs2_inode *dip, 
struct gfs2_sbd *sbp,
/* Only do this if the dent was a true gfs1 dent, and not a   */
/* gfs2 dent converted from a previously aborted run. */
if (dent_was_gfs1) {
-   switch be16_to_cpu(dent->de_type) {
+   switch (be16_to_cpu(dent->de_type)) {
case GFS_FILE_NON:
dent->de_type = cpu_to_be16(DT_UNKNOWN);
break;
diff --git a/gfs2/include/linux/types.h b/gfs2/include/linux/types.h
index 7f4d4b98..a092afc0 100644
--- a/gfs2/include/linux/types.h
+++ b/gfs2/include/linux/types.h
@@ -7,10 +7,13 @@
 
 #ifdef __CHECKER__
 #define __bitwise__ __attribute__((bitwise))
+#define __force__ __attribute__((force))
 #else
 #define __bitwise__
+#define __force__
 #endif
 #define __bitwise __bitwise__
+#define __force __force__
 
 typedef uint8_t __u8;
 typedef uint16_t __u16;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index d8afc100..3f36ffb2 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -21,42 +21,41 @@ __BEGIN_DECLS
 
 #if __BYTE_ORDER == __BIG_ENDIAN
 
-#define be16_to_cpu(x) (x)
-#define be32_to_cpu(x) (x)
-#define be64_to_cpu(x) (x)
+#define be16_to_cpu(x) ((__force uint16_t)(__be16)(x))
+#define be32_to_cpu(x) ((__force uint32_t)(__be32)(x))
+#define be64_to_cpu(x) ((__force uint64_t)(__be64)(x))
 
-#define cpu_to_be16(x) (x)
-#define cpu_to_be32(x) (x)
-#define cpu_to_be64(x) (x)
+#define cpu_to_be16(x) ((__force __be16)(uint16_t)(x))
+#define cpu_to_be32(x) ((__force __be32)(uint32_t)(x))
+#define cpu_to_be64(x) ((__force __be64)(uint64_t)(x))
 
-#define le16_to_cpu(x) (bswap_16((x)))
-#define le32_to_cpu(x) (bswap_32((x)))
-#define le64_to_cpu(x) (bswap_64((x)))
+#define le16_to_cpu(x) bswap_16((__force uint16_t)(__le16)(x))
+#define le32_to_cpu(x) bswap_32((__force uint32_t)(__le32)(x))
+#define le64_to_cpu(x) bswap_64((__force uint64_t)(__le64)(x))
 
-#define cpu_to_le16(x) (bswap_16((x)))
-#define cpu_to_le32(x) (bswap_32((x)))
-#define cpu_to_le64(x) (bswap_64((x)))
+#define cpu_to_le16(x) ((__force __le16)bswap_16((x)))
+#define cpu_to_le32(x) ((__force __le32)bswap_32((x)))
+#define cpu_to_le64(x) ((__force __le64)bswap_64((x)))
 
 #endif  /*  __BYTE_ORDER == __BIG_ENDIAN  */
 
-
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 
-#define be16_to_cpu(x) (bswap_16((x)))
-#define be32_to_cpu(x) (bswap_32((x)))
-#define be64_to_cpu(x) (bswap_64((x)))
+#define be16_to_cpu(x) bswap_16((__force uint16_t)(__be16)(x))
+#define be32_to_cpu(x) bswap_32((__force uint32_t)(__be32)(x))
+#define be64_to_cpu(x) bswap_64((__force uint64_t)(__be64)(x))
 
-#define cpu_to_be16(x) (bswap_16((x)))
-#define cpu_to_be32(x) (bswap_32((x)))
-#define cpu_to_be64(x) (bswap_64((x))) 
+#define cpu_to_be16(x) ((__force __be16)bswap_16((x)))
+#define cpu_to_be32(x) ((__force __be32)bswap_32((x)))
+#define cpu_to_be64(x) ((__force __be64)bswap_64((x)))
 
-#define le16_to_cpu(x) (x)
-#define le32_to_cpu(x) (x)
-#define le64_to_cpu(x) (x)
+#define le16_to_cpu(x) ((__force uint16_t)(__le16)(x))
+#define le32_to_cpu(x) ((__force uint32_t)(__le32)(x))
+#define le64_to_cpu(x) ((__force uint64_t)(__le64)(x))
 
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
-#define cpu_to_le64(x) (x)
+#define cpu_to_le16(x) ((__force __le16)(uint16_t)(x))
+#define cpu_to_le32(x) ((__force __le32)(uint32_t)(x))
+#define cpu_to_le64(x) ((__force __le64)(uint64_t)(x))
 
 #endif  /*  __BYTE_ORDER == __LITTLE_ENDIAN  */
 
-- 
2.30.2



Re: [Cluster-devel] [PATCH 1/8] Import linux/gfs2_ondisk.h

2021-04-20 Thread Andrew Price

On 20/04/2021 10:07, Andreas Gruenbacher wrote:

On Tue, Apr 20, 2021 at 10:34 AM Andrew Price  wrote:

On 20/04/2021 07:00, Andreas Gruenbacher wrote:

On Mon, Apr 19, 2021 at 10:47 PM Andrew Price  wrote:

On 19/04/2021 20:35, Andreas Gruenbacher wrote:

Andy,

On Mon, Apr 19, 2021 at 9:11 PM Andrew Price  wrote:

diff --git a/gfs2/include/gfs2_ondisk.h b/gfs2/include/gfs2_ondisk.h
new file mode 100644
index ..fc948f89
--- /dev/null
+++ b/gfs2/include/gfs2_ondisk.h


any reason why this file shouldn't be at gfs2/include/linux/gfs2_ondisk.h?


I didn't feel it was needed, but it does have the benefit of making sure
we're not picking up the system linux/gfs2_ondisk.h when we #include
 and it shows clearly that we're not trying to.


Well, we have "-I$(top_srcdir)/gfs2/include" in CPPFLAGS so
gfs2/include/linux/types.h is picked up by . We already
rely on that working. So gfs2/include/linux/gfs2_ondisk.h would be
picked up by  already anyway.


So, what would be the advantage of having gfs2_ondisk.h in
gfs2/include/linux/? I put types.h in that directory because I didn't
want to change the #include statement, but I didn't see a reason to put
gfs2_ondisk.h in there.


It's more consistent if the definitions are always included as
 by the kernel and by all user-space programs.


Hmm, I guess. I've moved it into gfs2/include/linux/ in my local branch 
and I'll push it with that change later, barring objections.


Andy



Re: [Cluster-devel] [PATCH 1/8] Import linux/gfs2_ondisk.h

2021-04-20 Thread Andrew Price

On 20/04/2021 07:00, Andreas Gruenbacher wrote:

On Mon, Apr 19, 2021 at 10:47 PM Andrew Price  wrote:

On 19/04/2021 20:35, Andreas Gruenbacher wrote:

Andy,

On Mon, Apr 19, 2021 at 9:11 PM Andrew Price  wrote:

diff --git a/gfs2/include/gfs2_ondisk.h b/gfs2/include/gfs2_ondisk.h
new file mode 100644
index ..fc948f89
--- /dev/null
+++ b/gfs2/include/gfs2_ondisk.h


any reason why this file shouldn't be at gfs2/include/linux/gfs2_ondisk.h?


I didn't feel it was needed, but it does have the benefit of making sure
we're not picking up the system linux/gfs2_ondisk.h when we #include
 and it shows clearly that we're not trying to.


Well, we have "-I$(top_srcdir)/gfs2/include" in CPPFLAGS so
gfs2/include/linux/types.h is picked up by . We already
rely on that working. So gfs2/include/linux/gfs2_ondisk.h would be
picked up by  already anyway.


So, what would be the advantage of having gfs2_ondisk.h in
gfs2/include/linux/? I put types.h in that directory because I didn't 
want to change the #include statement, but I didn't see a reason to put 
gfs2_ondisk.h in there.


Andy



Re: [Cluster-devel] [PATCH 1/8] Import linux/gfs2_ondisk.h

2021-04-19 Thread Andrew Price

On 19/04/2021 20:35, Andreas Gruenbacher wrote:

Andy,

On Mon, Apr 19, 2021 at 9:11 PM Andrew Price  wrote:

diff --git a/gfs2/include/gfs2_ondisk.h b/gfs2/include/gfs2_ondisk.h
new file mode 100644
index ..fc948f89
--- /dev/null
+++ b/gfs2/include/gfs2_ondisk.h


any reason why this file shouldn't be at gfs2/include/linux/gfs2_ondisk.h?


I didn't feel it was needed, but it does have the benefit of making sure 
we're not picking up the system linux/gfs2_ondisk.h when we #include 
 and it shows clearly that we're not trying to.


Andy



[Cluster-devel] [PATCH 8/8] Use PRI* when printing gfs2 structures

2021-04-19 Thread Andrew Price
Now that we have gfs2 structs defined in terms of standard userspace
types instead of kernel types we can use these defines from inttypes.h
to print their fields in a consistent way across architectures.

Fixes a number of -Wformat warnings on x86_64.

Signed-off-by: Andrew Price 
---
 gfs2/edit/extended.c |  37 -
 gfs2/edit/gfs2hex.c  |  28 +++
 gfs2/edit/journal.c  |  13 ++-
 gfs2/fsck/fs_recovery.c  |  10 +--
 gfs2/fsck/initialize.c   |  47 ++-
 gfs2/fsck/lost_n_found.c |  10 +--
 gfs2/fsck/pass1.c|   5 +-
 gfs2/fsck/pass2.c|   2 +-
 gfs2/fsck/rgrepair.c |  37 -
 gfs2/libgfs2/ondisk.c| 168 +++
 10 files changed, 170 insertions(+), 187 deletions(-)

diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index 91609bd2..30e227d1 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -308,9 +308,9 @@ static int display_leaf(struct iinfo *ind)
if (gfs2_struct_type == GFS2_METATYPE_SB)
print_gfs2("The superblock has 2 directories");
else
-   print_gfs2("Directory block: lf_depth:%d, lf_entries:%d, "
+   print_gfs2("Directory block: lf_depth:%"PRIu16", 
lf_entries:%"PRIu16", "
   LEAF_HINT_FMTS
-  "fmt:%d next=0x%llx (%d dirents).",
+  "fmt:%"PRIu32" next=0x%"PRIx64" (%d dirents).",
   leaf->lf_depth, leaf->lf_entries,
   LEAF_HINT_FIELDS(leaf)
   leaf->lf_dirent_format,
@@ -330,12 +330,11 @@ static int display_leaf(struct iinfo *ind)
line - start_line - 1 ==
edit_row[dmode] - start_row[dmode]) {
COLORS_HIGHLIGHT;
-   sprintf(estring, "%llx",
-   (unsigned long 
long)ind->ii[0].dirent[d].block);
+   sprintf(estring, "%"PRIx64, 
ind->ii[0].dirent[d].block);
strcpy(edit_fmt, "%llx");
}
}
-   print_gfs2("%d/%d [%08x] %lld/%"PRId64" 
(0x%llx/0x%"PRIx64") +%"PRIu16": ",
+   print_gfs2("%d/%d [%08"PRIX32"] %"PRIu64"/%"PRIu64" 
(0x%"PRIx64"/0x%"PRIx64") +%"PRIu16": ",
   total_dirents, d + 1,
   ind->ii[0].dirent[d].dirent.de_hash,
   
ind->ii[0].dirent[d].dirent.de_inum.no_formal_ino,
@@ -388,11 +387,9 @@ static void print_block_details(struct iinfo *ind, int 
level, int cur_height,
while (thisblk) {
/* read in the desired block */
if (pread(sbd.device_fd, tmpbuf, sbd.bsize, thisblk * 
sbd.bsize) != sbd.bsize) {
-   fprintf(stderr, "bad read: %s from %s:%d: block %lld "
-   "(0x%llx)\n", strerror(errno), __FUNCTION__,
-   __LINE__,
-   (unsigned long long)ind->ii[pndx].block,
-   (unsigned long long)ind->ii[pndx].block);
+   fprintf(stderr, "bad read: %s from %s:%d: block %"PRIu64
+   " (0x%"PRIx64")\n", strerror(errno), 
__FUNCTION__,
+   __LINE__, ind->ii[pndx].block, 
ind->ii[pndx].block);
exit(-1);
}
thisblk = 0;
@@ -428,9 +425,9 @@ static void print_block_details(struct iinfo *ind, int 
level, int cur_height,
 
 static void gfs_jindex_print(struct gfs_jindex *ji)
 {
-pv((unsigned long long)ji, ji_addr, "%llu", "0x%llx");
-pv(ji, ji_nsegment, "%u", "0x%x");
-pv(ji, ji_pad, "%u", "0x%x");
+pv(ji, ji_addr, "%"PRIu64, "0x%"PRIx64);
+pv(ji, ji_nsegment, "%"PRIu32, "0x%"PRIx32);
+pv(ji, ji_pad, "%"PRIu32, "0x%"PRIx32);
 }
 
 static int print_gfs_jindex(struct gfs2_inode *dij)
@@ -440,7 +437,7 @@ static int print_gfs_jindex(struct gfs2_inode *dij)
char jbuf[sizeof(struct gfs_jindex)];
 
start_line = line;
-   print_gfs2("Journal index entries found: %lld.",
+   print_gfs2("Journal index entries found: %"PRIu64".",
   dij->i_di.di_size / sizeof(struct gfs_jindex));
eol(0);
lines_per_row[dmode] = 4;
@@ -4

[Cluster-devel] [PATCH 4/8] Remove GFS2_HAS_DE_RAHEAD/COOKIE conditionals

2021-04-19 Thread Andrew Price
Our own gfs2_ondisk.h has de_rahead and de_cookie so there's no need for
these conditionals.

Signed-off-by: Andrew Price 
---
 configure.ac  |  4 
 gfs2/edit/extended.c  |  8 ++--
 gfs2/libgfs2/meta.c   |  8 
 gfs2/libgfs2/ondisk.c | 16 
 4 files changed, 2 insertions(+), 34 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5cb0770f..a512f9dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -126,10 +126,6 @@ AC_SUBST([udevdir], [$with_udevdir])
 AC_CHECK_HEADERS([fcntl.h libintl.h limits.h locale.h mntent.h stddef.h 
sys/file.h sys/ioctl.h sys/mount.h sys/time.h sys/vfs.h syslog.h termios.h])
 AC_CHECK_HEADER([linux/fs.h], [], [AC_MSG_ERROR([Unable to find linux/fs.h])])
 AC_CHECK_HEADER([linux/limits.h], [], [AC_MSG_ERROR([Unable to find 
linux/limits.h])])
-AC_CHECK_MEMBER([struct 
gfs2_dirent.de_rahead],[AC_DEFINE([GFS2_HAS_DE_RAHEAD],[],[Dirent readahead 
field])],
-[], [[#include ]])
-AC_CHECK_MEMBER([struct 
gfs2_dirent.de_cookie],[AC_DEFINE([GFS2_HAS_DE_COOKIE],[],[Dirent cookie 
field])],
-[], [[#include ]])
 AC_CHECK_MEMBER([struct 
gfs2_rgrp.rg_skip],[AC_DEFINE([GFS2_HAS_RG_SKIP],[],[Next resource group 
pointer])],
 [], [[#include ]])
 AC_CHECK_MEMBER([struct 
gfs2_rgrp.rg_data0],[AC_DEFINE([GFS2_HAS_RG_RI_FIELDS],[],[Resource group 
fields duplicated from the rindex])],
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index b8c61ee1..91609bd2 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -335,18 +335,14 @@ static int display_leaf(struct iinfo *ind)
strcpy(edit_fmt, "%llx");
}
}
-   print_gfs2("%d/%d [%08x] %lld/%"PRId64" 
(0x%llx/0x%"PRIx64") +%u: ",
+   print_gfs2("%d/%d [%08x] %lld/%"PRId64" 
(0x%llx/0x%"PRIx64") +%"PRIu16": ",
   total_dirents, d + 1,
   ind->ii[0].dirent[d].dirent.de_hash,
   
ind->ii[0].dirent[d].dirent.de_inum.no_formal_ino,
   ind->ii[0].dirent[d].block,
   
ind->ii[0].dirent[d].dirent.de_inum.no_formal_ino,
   ind->ii[0].dirent[d].block,
-#ifdef GFS2_HAS_DE_RAHEAD
-  (unsigned 
int)ind->ii[0].dirent[d].dirent.de_rahead
-#else
-  0
-#endif
+  ind->ii[0].dirent[d].dirent.de_rahead
);
}
print_inode_type(ind->ii[0].dirent[d].dirent.de_type);
diff --git a/gfs2/libgfs2/meta.c b/gfs2/libgfs2/meta.c
index 2be87045..d642424a 100644
--- a/gfs2/libgfs2/meta.c
+++ b/gfs2/libgfs2/meta.c
@@ -481,17 +481,9 @@ F(de_hash, .flags = LGFS2_MFF_CHECK)
 F(de_rec_len, .flags = LGFS2_MFF_BYTES)
 F(de_name_len, .flags = LGFS2_MFF_BYTES)
 F(de_type)
-#ifdef GFS2_HAS_DE_RAHEAD
 F(de_rahead)
-#ifdef GFS2_HAS_DE_COOKIE
 F(de_cookie)
 RF(pad3)
-#else
-RF(pad2)
-#endif /* GFS2_HAS_DE_COOKIE */
-#else
-RF(__pad)
-#endif /* GFS2_HAS_DE_RAHEAD */
 };
 
 #undef STRUCT
diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c
index dffd2221..6e969143 100644
--- a/gfs2/libgfs2/ondisk.c
+++ b/gfs2/libgfs2/ondisk.c
@@ -404,17 +404,9 @@ void gfs2_dirent_in(struct gfs2_dirent *de, char *buf)
CPIN_16(de, str, de_rec_len);
CPIN_16(de, str, de_name_len);
CPIN_16(de, str, de_type);
-#ifdef GFS2_HAS_DE_RAHEAD
CPIN_16(de, str, de_rahead);
-#ifdef GFS2_HAS_DE_COOKIE
CPIN_32(de, str, de_cookie);
CPIN_08(de, str, pad3, 8);
-#else
-   CPIN_08(de, str, pad2, 12);
-#endif /* GFS2_HAS_DE_COOKIE */
-#else
-   CPIN_08(de, str, __pad, 14);
-#endif /* GFS2_HAS_DE_RAHEAD */
 }
 
 void gfs2_dirent_out(struct gfs2_dirent *de, char *buf)
@@ -426,17 +418,9 @@ void gfs2_dirent_out(struct gfs2_dirent *de, char *buf)
CPOUT_16(de, str, de_rec_len);
CPOUT_16(de, str, de_name_len);
CPOUT_16(de, str, de_type);
-#ifdef GFS2_HAS_DE_RAHEAD
CPOUT_16(de, str, de_rahead);
-#ifdef GFS2_HAS_DE_COOKIE
CPOUT_32(de, str, de_cookie);
CPOUT_08(de, str, pad3, 8);
-#else
-   CPOUT_08(de, str, pad2, 12);
-#endif /* GFS2_HAS_DE_COOKIE */
-#else
-   CPOUT_08(de, str, __pad, 14);
-#endif /* GFS2_HAS_DE_RAHEAD */
 }
 
 void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf)
-- 
2.30.2



[Cluster-devel] [PATCH 7/8] Remove GFS2_HAS_LH_V2 conditionals

2021-04-19 Thread Andrew Price
Our own gfs2_ondisk.h has v2 log headers so there's no need for these
conditionals. There aren't any users of gfs2_log_header_v1_*() functions
so fold those into gfs2_log_header*().

Signed-off-by: Andrew Price 
---
 configure.ac  |  2 --
 gfs2/libgfs2/libgfs2.h|  3 ---
 gfs2/libgfs2/meta.c   |  4 
 gfs2/libgfs2/ondisk.c | 35 +++
 gfs2/libgfs2/recovery.c   |  2 --
 gfs2/libgfs2/structures.c | 16 ++--
 gfs2/mkfs/main_jadd.c |  9 +
 7 files changed, 6 insertions(+), 65 deletions(-)

diff --git a/configure.ac b/configure.ac
index e356199c..bb85d65c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -126,8 +126,6 @@ AC_SUBST([udevdir], [$with_udevdir])
 AC_CHECK_HEADERS([fcntl.h libintl.h limits.h locale.h mntent.h stddef.h 
sys/file.h sys/ioctl.h sys/mount.h sys/time.h sys/vfs.h syslog.h termios.h])
 AC_CHECK_HEADER([linux/fs.h], [], [AC_MSG_ERROR([Unable to find linux/fs.h])])
 AC_CHECK_HEADER([linux/limits.h], [], [AC_MSG_ERROR([Unable to find 
linux/limits.h])])
-AC_CHECK_MEMBER([struct 
gfs2_log_header.lh_crc],[AC_DEFINE([GFS2_HAS_LH_V2],[],[v2 log header format])],
-[], [[#include ]])
 
 # *FLAGS handling
 ENV_CFLAGS="$CFLAGS"
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 6346b74a..b59b72b7 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -715,9 +715,7 @@ extern void gfs2_dirent_out(struct gfs2_dirent *de, char 
*buf);
 extern void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf);
 extern void gfs2_leaf_out(struct gfs2_leaf *lf, char *buf);
 extern void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf);
-extern void gfs2_log_header_v1_in(struct gfs2_log_header *lh, char *buf);
 extern void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf);
-extern void gfs2_log_header_v1_out(struct gfs2_log_header *lh, char *buf);
 extern void gfs2_log_header_out(struct gfs2_log_header *lh, char *buf);
 extern void gfs2_log_descriptor_in(struct gfs2_log_descriptor *ld, char *buf);
 extern void gfs2_log_descriptor_out(struct gfs2_log_descriptor *ld, char *buf);
@@ -737,7 +735,6 @@ extern void gfs2_quota_print(const struct gfs2_quota *qu);
 extern void gfs2_dinode_print(const struct gfs2_dinode *di);
 extern void gfs2_leaf_print(const struct gfs2_leaf *lf);
 extern void gfs2_ea_header_print(const struct gfs2_ea_header *ea, char *name);
-extern void gfs2_log_header_v1_print(const struct gfs2_log_header *lh);
 extern void gfs2_log_header_print(const struct gfs2_log_header *lh);
 extern void gfs2_log_descriptor_print(const struct gfs2_log_descriptor *ld);
 extern void gfs2_statfs_change_print(const struct gfs2_statfs_change *sc);
diff --git a/gfs2/libgfs2/meta.c b/gfs2/libgfs2/meta.c
index 771b1f13..db5f37b1 100644
--- a/gfs2/libgfs2/meta.c
+++ b/gfs2/libgfs2/meta.c
@@ -69,7 +69,6 @@ const unsigned lgfs2_di_flag_size = 
ARRAY_SIZE(lgfs2_di_flags);
 
 const struct lgfs2_symbolic lgfs2_lh_flags[] = {
 PREFIX_SYM(GFS2_LOG_HEAD_, UNMOUNT)
-#ifdef GFS2_HAS_LH_V2
 PREFIX_SYM(GFS2_LOG_HEAD_FLUSH_, NORMAL)
 PREFIX_SYM(GFS2_LOG_HEAD_FLUSH_, SYNC)
 PREFIX_SYM(GFS2_LOG_HEAD_FLUSH_, SHUTDOWN)
@@ -97,7 +96,6 @@ PREFIX_SYM(GFS2_LFC_, EVICT_INODE)
 PREFIX_SYM(GFS2_LFC_, TRANS_END)
 PREFIX_SYM(GFS2_LFC_, LOGD_JFLUSH_REQD)
 PREFIX_SYM(GFS2_LFC_, LOGD_AIL_FLUSH_REQD)
-#endif
 };
 
 const unsigned int lgfs2_lh_flag_size = ARRAY_SIZE(lgfs2_lh_flags);
@@ -381,7 +379,6 @@ F(lh_flags, .flags = LGFS2_MFF_MASK, .symtab = 
lgfs2_lh_flags, .nsyms = ARRAY_SI
 F(lh_tail)
 F(lh_blkno)
 F(lh_hash, .flags = LGFS2_MFF_CHECK)
-#ifdef GFS2_HAS_LH_V2
 F(lh_crc, .flags = LGFS2_MFF_CHECK)
 F(lh_nsec, .flags = LGFS2_MFF_NSECS)
 F(lh_sec, .flags = LGFS2_MFF_SECS)
@@ -392,7 +389,6 @@ FP(lh_quota_addr, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
 F(lh_local_total, .flags = LGFS2_MFF_FSBLOCKS)
 F(lh_local_free, .flags = LGFS2_MFF_FSBLOCKS)
 F(lh_local_dinodes, .flags = LGFS2_MFF_FSBLOCKS)
-#endif
 };
 
 #undef STRUCT
diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c
index 157f3358..0d68de8f 100644
--- a/gfs2/libgfs2/ondisk.c
+++ b/gfs2/libgfs2/ondisk.c
@@ -476,7 +476,7 @@ void gfs2_ea_header_print(const struct gfs2_ea_header *ea, 
char *name)
print_it("  name", "%s", NULL, buf);
 }
 
-void gfs2_log_header_v1_in(struct gfs2_log_header *lh, char *buf)
+void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf)
 {
struct gfs2_log_header *str = (struct gfs2_log_header *)buf;
 
@@ -486,15 +486,6 @@ void gfs2_log_header_v1_in(struct gfs2_log_header *lh, 
char *buf)
CPIN_32(lh, str, lh_tail);
CPIN_32(lh, str, lh_blkno);
CPIN_32(lh, str, lh_hash);
-}
-
-void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf)
-{
-   gfs2_log_header_v1_in(lh, buf);
-#ifdef GFS2_HAS_LH_V2
-   {
-   struct gfs2_log_header *str = (struct gfs2_log_header *)buf;
-
CPIN_32(lh, str, lh_crc);
CPIN_32(lh, str, lh_nsec);
CPIN_64

[Cluster-devel] [PATCH 6/8] Remove GFS2_HAS_RG_RI_FIELDS conditionals

2021-04-19 Thread Andrew Price
Our own gfs2_ondisk.h has the new rgrp fields so there's no need for
these conditionals.

Signed-off-by: Andrew Price 
---
 configure.ac  | 2 --
 gfs2/libgfs2/meta.c   | 2 --
 gfs2/libgfs2/ondisk.c | 8 
 gfs2/libgfs2/rgrp.c   | 6 --
 4 files changed, 18 deletions(-)

diff --git a/configure.ac b/configure.ac
index 31cb3e49..e356199c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -126,8 +126,6 @@ AC_SUBST([udevdir], [$with_udevdir])
 AC_CHECK_HEADERS([fcntl.h libintl.h limits.h locale.h mntent.h stddef.h 
sys/file.h sys/ioctl.h sys/mount.h sys/time.h sys/vfs.h syslog.h termios.h])
 AC_CHECK_HEADER([linux/fs.h], [], [AC_MSG_ERROR([Unable to find linux/fs.h])])
 AC_CHECK_HEADER([linux/limits.h], [], [AC_MSG_ERROR([Unable to find 
linux/limits.h])])
-AC_CHECK_MEMBER([struct 
gfs2_rgrp.rg_data0],[AC_DEFINE([GFS2_HAS_RG_RI_FIELDS],[],[Resource group 
fields duplicated from the rindex])],
-[], [[#include ]])
 AC_CHECK_MEMBER([struct 
gfs2_log_header.lh_crc],[AC_DEFINE([GFS2_HAS_LH_V2],[],[v2 log header format])],
 [], [[#include ]])
 
diff --git a/gfs2/libgfs2/meta.c b/gfs2/libgfs2/meta.c
index c209c70a..771b1f13 100644
--- a/gfs2/libgfs2/meta.c
+++ b/gfs2/libgfs2/meta.c
@@ -227,12 +227,10 @@ F(rg_free, .flags = LGFS2_MFF_FSBLOCKS)
 F(rg_dinodes, .flags = LGFS2_MFF_FSBLOCKS)
 FP(rg_skip, .points_to = (1 << LGFS2_MT_GFS2_RGRP))
 F(rg_igeneration)
-#ifdef GFS2_HAS_RG_RI_FIELDS
 FP(rg_data0, .points_to = ANY_GFS2_BLOCK|(1 << LGFS2_MT_FREE))
 F(rg_data, .flags = LGFS2_MFF_FSBLOCKS)
 F(rg_bitbytes, .flags = LGFS2_MFF_BYTES)
 F(rg_crc, .flags = LGFS2_MFF_CHECK)
-#endif
 RF(rg_reserved)
 };
 
diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c
index cf81005e..157f3358 100644
--- a/gfs2/libgfs2/ondisk.c
+++ b/gfs2/libgfs2/ondisk.c
@@ -210,12 +210,10 @@ void gfs2_rgrp_in(struct gfs2_rgrp *rg, char *buf)
CPIN_32(rg, str, rg_dinodes);
CPIN_32(rg, str, rg_skip);
CPIN_64(rg, str, rg_igeneration);
-#ifdef GFS2_HAS_RG_RI_FIELDS
CPIN_64(rg, str, rg_data0);
CPIN_32(rg, str, rg_data);
CPIN_32(rg, str, rg_bitbytes);
CPIN_32(rg, str, rg_crc);
-#endif
CPIN_08(rg, str, rg_reserved, sizeof(rg->rg_reserved));
 }
 
@@ -229,15 +227,11 @@ void gfs2_rgrp_out(const struct gfs2_rgrp *rg, char *buf)
CPOUT_32(rg, str, rg_dinodes);
CPOUT_32(rg, str, rg_skip);
CPOUT_64(rg, str, rg_igeneration);
-#ifdef GFS2_HAS_RG_RI_FIELDS
CPOUT_64(rg, str, rg_data0);
CPOUT_32(rg, str, rg_data);
CPOUT_32(rg, str, rg_bitbytes);
CPOUT_08(rg, str, rg_reserved, sizeof(rg->rg_reserved));
lgfs2_rgrp_crc_set(buf);
-#else
-   CPOUT_08(rg, str, rg_reserved, sizeof(rg->rg_reserved));
-#endif
 }
 
 void gfs2_rgrp_print(const struct gfs2_rgrp *rg)
@@ -248,12 +242,10 @@ void gfs2_rgrp_print(const struct gfs2_rgrp *rg)
pv(rg, rg_dinodes, "%u", "0x%x");
pv(rg, rg_skip, "%u", "0x%x");
pv(rg, rg_igeneration, "%llu", "0x%llx");
-#ifdef GFS2_HAS_RG_RI_FIELDS
pv(rg, rg_data0, "%llu", "0x%llx");
pv(rg, rg_data, "%u", "0x%x");
pv(rg, rg_bitbytes, "%u", "0x%x");
pv(rg, rg_crc, "%u", "0x%x");
-#endif
 }
 
 void gfs2_quota_in(struct gfs2_quota *qu, char *buf)
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index f5eb88c9..aa5eadf2 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -156,7 +156,6 @@ void lgfs2_rgrp_bitbuf_free(lgfs2_rgrp_t rg)
 int lgfs2_rgrp_crc_check(char *buf)
 {
int ret = 0;
-#ifdef GFS2_HAS_RG_RI_FIELDS
struct gfs2_rgrp *rg = (struct gfs2_rgrp *)buf;
uint32_t crc = rg->rg_crc;
 
@@ -167,7 +166,6 @@ int lgfs2_rgrp_crc_check(char *buf)
if (be32_to_cpu(crc) != gfs2_disk_hash(buf, sizeof(struct gfs2_rgrp)))
ret = 1;
rg->rg_crc = crc;
-#endif
return ret;
 }
 
@@ -176,14 +174,12 @@ int lgfs2_rgrp_crc_check(char *buf)
  */
 void lgfs2_rgrp_crc_set(char *buf)
 {
-#ifdef GFS2_HAS_RG_RI_FIELDS
struct gfs2_rgrp *rg = (struct gfs2_rgrp *)buf;
uint32_t crc;
 
rg->rg_crc = 0;
crc = gfs2_disk_hash(buf, sizeof(struct gfs2_rgrp));
rg->rg_crc = cpu_to_be32(crc);
-#endif
 }
 
 /**
@@ -674,12 +670,10 @@ lgfs2_rgrp_t lgfs2_rgrps_append(lgfs2_rgrps_t rgs, struct 
gfs2_rindex *entry, ui
rg->rg.rg_header.mh_format = GFS2_FORMAT_RG;
rg->rg.rg_free = rg->ri.ri_data;
rg->rg.rg_skip = rg_skip;
-#ifdef GFS2_HAS_RG_RI_FIELDS
rg->rg.rg_data0 = rg->ri.ri_data0;
rg->rg.rg_data = rg->ri.ri_data;
rg->rg.rg_bitbytes = rg->ri.ri_bitbytes;
rg->rg.rg_crc = 0;
-#endif
compute_bitmaps(rg, rgs->sdp->bsize);
rg->rgrps = rgs;
return rg;
-- 
2.30.2



[Cluster-devel] [PATCH 1/8] Import linux/gfs2_ondisk.h

2021-04-19 Thread Andrew Price
Give gfs2-utils its own copy of gfs2_ondisk.h. This allows us to always
support the latest ondisk structures and obsoletes a lot of #ifdef
GFS2_HAS_ blocks and configure.ac checks.

Provide the kernel int typedefs that gfs2_ondisk.h uses with our own
linux/types.h, which uses standard userspace types but keeps the bitwise
attribute tags that sparse uses.

Remove a bunch of unnecessary #include statements in the utils so that
linux/gfs2_ondisk.h is never included and (our) linux/types.h is only
ever included in libgfs2.h.

Signed-off-by: Andrew Price 
---
 configure.ac   |   2 -
 gfs2/convert/gfs2_convert.c|   2 -
 gfs2/edit/extended.c   |   2 -
 gfs2/edit/gfs2hex.c|   5 -
 gfs2/edit/hexedit.c|   2 -
 gfs2/edit/hexedit.h|   1 -
 gfs2/edit/journal.c|   2 -
 gfs2/edit/savemeta.c   |   2 -
 gfs2/include/Makefile.am   |   2 +
 gfs2/include/gfs2_ondisk.h | 542 +
 gfs2/include/linux/types.h |  32 ++
 gfs2/libgfs2/buf.c |   1 -
 gfs2/libgfs2/device_geometry.c |   1 -
 gfs2/libgfs2/fs_ops.c  |   1 -
 gfs2/libgfs2/gfs1.c|   2 -
 gfs2/libgfs2/libgfs2.h |   3 +-
 gfs2/libgfs2/ondisk.c  |   1 -
 gfs2/libgfs2/structures.c  |   1 -
 gfs2/mkfs/gfs2_mkfs.h  |   1 -
 gfs2/mkfs/main_grow.c  |   1 -
 gfs2/mkfs/main_jadd.c  |   1 -
 gfs2/mkfs/main_mkfs.c  |   1 -
 gfs2/tune/super.c  |   1 -
 23 files changed, 577 insertions(+), 32 deletions(-)
 create mode 100644 gfs2/include/gfs2_ondisk.h
 create mode 100644 gfs2/include/linux/types.h

diff --git a/configure.ac b/configure.ac
index 690049f2..9a7e50ab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -127,9 +127,7 @@ AC_SUBST([udevdir], [$with_udevdir])
 # Checks for header files.
 AC_CHECK_HEADERS([fcntl.h libintl.h limits.h locale.h mntent.h stddef.h 
sys/file.h sys/ioctl.h sys/mount.h sys/time.h sys/vfs.h syslog.h termios.h])
 AC_CHECK_HEADER([linux/fs.h], [], [AC_MSG_ERROR([Unable to find linux/fs.h])])
-AC_CHECK_HEADER([linux/types.h], [], [AC_MSG_ERROR([Unable to find 
linux/types.h])])
 AC_CHECK_HEADER([linux/limits.h], [], [AC_MSG_ERROR([Unable to find 
linux/limits.h])])
-AC_CHECK_HEADER([linux/gfs2_ondisk.h], [], [AC_MSG_ERROR([Unable to find 
linux/gfs2_ondisk.h])])
 AC_CHECK_MEMBER([struct gfs2_sb.sb_uuid], [sb_has_uuid=yes], [sb_has_uuid=no],
 [[#include ]])
 AC_CHECK_MEMBER([struct 
gfs2_leaf.lf_inode],[AC_DEFINE([GFS2_HAS_LEAF_HINTS],[],[Leaf block hints])],
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 142c7d4e..5656b39d 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -28,8 +28,6 @@
 #include 
 #define _(String) gettext(String)
 
-#include 
-#include 
 #include 
 #include "osi_list.h"
 #include "copyright.cf"
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index 0e5ecda4..64e4d31f 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -6,7 +6,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -19,7 +18,6 @@
 #include 
 #include 
 
-#include 
 #include "copyright.cf"
 
 #include "hexedit.h"
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index 3204577a..133a508e 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -5,7 +5,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -13,10 +12,6 @@
 #include 
 
 #include "hexedit.h"
-
-#define WANT_GFS_CONVERSION_FUNCTIONS
-#include 
-
 #include "extended.h"
 #include "gfs2hex.h"
 #include "libgfs2.h"
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index d07437bb..e38d0b7b 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -6,7 +6,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -19,7 +18,6 @@
 #include 
 #include 
 
-#include 
 #include "copyright.cf"
 
 #include "hexedit.h"
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index 1c94c901..35573415 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -4,7 +4,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include "libgfs2.h"
diff --git a/gfs2/edit/journal.c b/gfs2/edit/journal.c
index 1adbc4b1..313f18f2 100644
--- a/gfs2/edit/journal.c
+++ b/gfs2/edit/journal.c
@@ -6,7 +6,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -19,7 +18,6 @@
 #include 
 #include 
 
-#include 
 #include "copyright.cf"
 
 #include "hexedit.h"
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index a13e6a5f..e256fa26 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -7,7 +7,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -17,7 +16,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #inclu

[Cluster-devel] [PATCH 3/8] Remove GFS2_HAS_LEAF_HINTS conditionals

2021-04-19 Thread Andrew Price
Our own gfs2_ondisk.h has leaf hints so there's no need for these
conditionals.

Signed-off-by: Andrew Price 
---
 configure.ac  |  2 --
 gfs2/edit/extended.c  |  9 ++---
 gfs2/libgfs2/fs_ops.c |  6 --
 gfs2/libgfs2/ondisk.c | 10 --
 4 files changed, 2 insertions(+), 25 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8c60741d..5cb0770f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -126,8 +126,6 @@ AC_SUBST([udevdir], [$with_udevdir])
 AC_CHECK_HEADERS([fcntl.h libintl.h limits.h locale.h mntent.h stddef.h 
sys/file.h sys/ioctl.h sys/mount.h sys/time.h sys/vfs.h syslog.h termios.h])
 AC_CHECK_HEADER([linux/fs.h], [], [AC_MSG_ERROR([Unable to find linux/fs.h])])
 AC_CHECK_HEADER([linux/limits.h], [], [AC_MSG_ERROR([Unable to find 
linux/limits.h])])
-AC_CHECK_MEMBER([struct 
gfs2_leaf.lf_inode],[AC_DEFINE([GFS2_HAS_LEAF_HINTS],[],[Leaf block hints])],
-[], [[#include ]])
 AC_CHECK_MEMBER([struct 
gfs2_dirent.de_rahead],[AC_DEFINE([GFS2_HAS_DE_RAHEAD],[],[Dirent readahead 
field])],
 [], [[#include ]])
 AC_CHECK_MEMBER([struct 
gfs2_dirent.de_cookie],[AC_DEFINE([GFS2_HAS_DE_COOKIE],[],[Dirent cookie 
field])],
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index 64e4d31f..b8c61ee1 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -294,14 +294,9 @@ static void print_inode_type(__be16 de_type)
}
 }
 
-#ifdef GFS2_HAS_LEAF_HINTS
-#define LEAF_HINT_FMTS "lf_inode: 0x%llx, lf_dist: %u, " \
-   "lf_nsec: %u, lf_sec: %llu, "
+#define LEAF_HINT_FMTS "lf_inode: 0x%"PRIx64", lf_dist: %"PRIu32", " \
+   "lf_nsec: %"PRIu32", lf_sec: %"PRIu64", "
 #define LEAF_HINT_FIELDS(lp) lp->lf_inode, lp->lf_dist, lp->lf_nsec, 
lp->lf_sec,
-#else
-#define LEAF_HINT_FMTS
-#define LEAF_HINT_FIELDS(lp)
-#endif
 
 static int display_leaf(struct iinfo *ind)
 {
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 1c580081..27fb43cb 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -1001,9 +1001,7 @@ void dir_split_leaf(struct gfs2_inode *dip, uint32_t 
start, uint64_t leaf_no,
oleaf->lf_depth = cpu_to_be16(oleaf->lf_depth);
nleaf->lf_depth = oleaf->lf_depth;
 
-#ifdef GFS2_HAS_LEAF_HINTS
nleaf->lf_inode = cpu_to_be64(dip->i_di.di_num.no_addr);
-#endif
dip->i_di.di_blocks++;
bmodified(dip->i_bh);
 
@@ -1203,9 +1201,7 @@ restart:
nleaf = (struct gfs2_leaf *)nbh->b_data;
nleaf->lf_depth = leaf->lf_depth;
nleaf->lf_dirent_format = 
cpu_to_be32(GFS2_FORMAT_DE);
-#ifdef GFS2_HAS_LEAF_HINTS
nleaf->lf_inode = 
cpu_to_be64(dip->i_di.di_num.no_addr);
-#endif
err = dirent_alloc(dip, nbh, len, );
if (err)
return err;
@@ -1257,9 +1253,7 @@ static void dir_make_exhash(struct gfs2_inode *dip)
leaf = (struct gfs2_leaf *)bh->b_data;
leaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE);
leaf->lf_entries = cpu_to_be16(dip->i_di.di_entries);
-#ifdef GFS2_HAS_LEAF_HINTS
leaf->lf_inode = cpu_to_be64(dip->i_di.di_num.no_addr);
-#endif
buffer_copy_tail(sdp, bh, sizeof(struct gfs2_leaf),
 dip->i_bh, sizeof(struct gfs2_dinode));
 
diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c
index 2185fd38..dffd2221 100644
--- a/gfs2/libgfs2/ondisk.c
+++ b/gfs2/libgfs2/ondisk.c
@@ -448,15 +448,11 @@ void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf)
CPIN_16(lf, str, lf_entries);
CPIN_32(lf, str, lf_dirent_format);
CPIN_64(lf, str, lf_next);
-#ifdef GFS2_HAS_LEAF_HINTS
CPIN_64(lf, str, lf_inode);
CPIN_32(lf, str, lf_dist);
CPIN_32(lf, str, lf_nsec);
CPIN_64(lf, str, lf_sec);
CPIN_08(lf, str, lf_reserved2, 40);
-#else
-   CPIN_08(lf, str, lf_reserved, 32);
-#endif
 }
 
 void gfs2_leaf_out(struct gfs2_leaf *lf, char *buf)
@@ -468,15 +464,11 @@ void gfs2_leaf_out(struct gfs2_leaf *lf, char *buf)
CPOUT_16(lf, str, lf_entries);
CPOUT_32(lf, str, lf_dirent_format);
CPOUT_64(lf, str, lf_next);
-#ifdef GFS2_HAS_LEAF_HINTS
CPOUT_64(lf, str, lf_inode);
CPOUT_32(lf, str, lf_dist);
CPOUT_32(lf, str, lf_nsec);
CPOUT_64(lf, str, lf_sec);
CPOUT_08(lf, str, lf_reserved2, 40);
-#else
-   CPOUT_08(lf, str, lf_reserved, 64);
-#endif
 }
 
 void gfs2_leaf_print(const struct gfs2_leaf *lf)
@@ -486,12 +478,10 @@ void gfs2_leaf_print(const struct gfs2_leaf *lf)
pv(lf, lf_entries, "%u", "0x%x");
pv(lf, lf_dirent_format, "%u", "0x%x");
pv(lf, lf_n

  1   2   3   4   5   6   7   8   >