]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: factor out new get_last_inode() helper
authorEric Sandeen <sandeen@sandeen.net>
Sun, 2 Oct 2016 23:46:03 +0000 (10:46 +1100)
committerDave Chinner <david@fromorbit.com>
Sun, 2 Oct 2016 23:46:03 +0000 (10:46 +1100)
The inode command by default finds the last allocated inode in the
filesystem via bulkstat, and this specific function is open-coded
after other cases are handled, leading to a fairly long inode_f
function and confusing code flow.

Clean it up by factoring it into a new function, more refactoring
will follow.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
io/open.c

index 5efa739d8f8141df4a649bf2528e779f805877d1..c8c82b773e102523d553d50c7430f7ca08fb7722 100644 (file)
--- a/io/open.c
+++ b/io/open.c
@@ -767,14 +767,51 @@ inode_help(void)
 "\n"));
 }
 
+static __u64
+get_last_inode(void)
+{
+       __u64                   lastip = 0;
+       __u64                   lastgrp = 0;
+       __s32                   ocount = 0;
+       __u64                   last_ino;
+       struct xfs_inogrp       igroup[1024];
+       struct xfs_fsop_bulkreq bulkreq;
+
+       bulkreq.lastip = &lastip;
+       bulkreq.ubuffer = &igroup;
+       bulkreq.icount = sizeof(igroup) / sizeof(struct xfs_inogrp);
+       bulkreq.ocount = &ocount;
+
+       for (;;) {
+               if (xfsctl(file->name, file->fd, XFS_IOC_FSINUMBERS,
+                               &bulkreq)) {
+                       perror("XFS_IOC_FSINUMBERS");
+                       return 0;
+               }
+
+               /* Did we reach the last inode? */
+               if (ocount == 0)
+                       break;
+
+               /* last inode in igroup table */
+               lastgrp = ocount;
+       }
+
+       lastgrp--;
+
+       /* The last inode number in use */
+       last_ino = igroup[lastgrp].xi_startino +
+                 libxfs_highbit64(igroup[lastgrp].xi_allocmask);
+
+       return last_ino;
+}
+
 static int
 inode_f(
          int                   argc,
          char                  **argv)
 {
        __s32                   count = 0;
-       __s32                   lastgrp = 0;
-       __u64                   last = 0;
        __u64                   lastino = 0;
        __u64                   userino = 0;
        char                    *p;
@@ -782,7 +819,6 @@ inode_f(
        int                     verbose = 0;
        int                     ret_next = 0;
        int                     cmd = 0;
-       struct xfs_inogrp       igroup[1024];
        struct xfs_fsop_bulkreq bulkreq;
        struct xfs_bstat        bstat;
 
@@ -854,29 +890,13 @@ inode_f(
                return command_usage(&inode_cmd);
        }
 
-       bulkreq.lastip = &last;
-       bulkreq.icount = 1024; /* User-defined maybe!? */
-       bulkreq.ubuffer = &igroup;
-       bulkreq.ocount = &count;
-
-       for (;;) {
-               if (xfsctl(file->name, file->fd, XFS_IOC_FSINUMBERS,
-                               &bulkreq)) {
-                       perror("XFS_IOC_FSINUMBERS");
-                       exitcode = 1;
-                       return 0;
-               }
-
-               if (count == 0)
-                       break;
-
-               lastgrp = count;
+       /* We are finding last inode in use */
+       lastino = get_last_inode();
+       if (!lastino) {
+               exitcode = 1;
+               return 0;
        }
 
-       lastgrp--;
-       lastino = igroup[lastgrp].xi_startino +
-                 libxfs_highbit64(igroup[lastgrp].xi_allocmask);
-
        if (verbose)
                printf("%llu:%d\n", lastino,
                        lastino > XFS_MAXINUMBER_32 ? 64 : 32);