]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - scrub/inodes.c
libfrog: refactor open-coded bulkstat calls
[thirdparty/xfsprogs-dev.git] / scrub / inodes.c
index 700e52009e5bd8648a649dcfc88827bca8bd7d92..c2cbe2602019d63bcc00f428a6676240f1e767dc 100644 (file)
@@ -17,6 +17,8 @@
 #include "xfs_scrub.h"
 #include "common.h"
 #include "inodes.h"
+#include "fsgeom.h"
+#include "libfrog/bulkstat.h"
 
 /*
  * Iterate a range of inodes.
@@ -50,17 +52,10 @@ xfs_iterate_inodes_range_check(
        struct xfs_inogrp       *inogrp,
        struct xfs_bstat        *bstat)
 {
-       struct xfs_fsop_bulkreq onereq = {NULL};
        struct xfs_bstat        *bs;
-       __u64                   oneino;
-       __s32                   onelen = 0;
        int                     i;
        int                     error;
 
-       onereq.lastip  = &oneino;
-       onereq.icount  = 1;
-       onereq.ocount  = &onelen;
-
        for (i = 0, bs = bstat; i < XFS_INODES_PER_CHUNK; i++) {
                if (!(inogrp->xi_allocmask & (1ULL << i)))
                        continue;
@@ -70,10 +65,8 @@ xfs_iterate_inodes_range_check(
                }
 
                /* Load the one inode. */
-               oneino = inogrp->xi_startino + i;
-               onereq.ubuffer = bs;
-               error = ioctl(ctx->mnt.fd, XFS_IOC_FSBULKSTAT_SINGLE,
-                               &onereq);
+               error = xfrog_bulkstat_single(&ctx->mnt,
+                               inogrp->xi_startino + i, bs);
                if (error || bs->bs_ino != inogrp->xi_startino + i) {
                        memset(bs, 0, sizeof(struct xfs_bstat));
                        bs->bs_ino = inogrp->xi_startino + i;
@@ -99,16 +92,14 @@ xfs_iterate_inodes_range(
        void                    *arg)
 {
        struct xfs_fsop_bulkreq igrpreq = {NULL};
-       struct xfs_fsop_bulkreq bulkreq = {NULL};
        struct xfs_handle       handle;
        struct xfs_inogrp       inogrp;
        struct xfs_bstat        bstat[XFS_INODES_PER_CHUNK];
        char                    idescr[DESCR_BUFSZ];
-       char                    buf[DESCR_BUFSZ];
        struct xfs_bstat        *bs;
        __u64                   igrp_ino;
-       __u64                   ino;
-       __s32                   bulklen = 0;
+       uint64_t                ino;
+       uint32_t                bulklen = 0;
        __s32                   igrplen = 0;
        bool                    moveon = true;
        int                     i;
@@ -117,10 +108,6 @@ xfs_iterate_inodes_range(
 
 
        memset(bstat, 0, XFS_INODES_PER_CHUNK * sizeof(struct xfs_bstat));
-       bulkreq.lastip  = &ino;
-       bulkreq.icount  = XFS_INODES_PER_CHUNK;
-       bulkreq.ubuffer = &bstat;
-       bulkreq.ocount  = &bulklen;
 
        igrpreq.lastip  = &igrp_ino;
        igrpreq.icount  = 1;
@@ -138,17 +125,21 @@ xfs_iterate_inodes_range(
        while (!error && igrplen) {
                /* Load the inodes. */
                ino = inogrp.xi_startino - 1;
-               bulkreq.icount = inogrp.xi_alloccount;
+
                /*
                 * We can have totally empty inode chunks on filesystems where
                 * there are more than 64 inodes per block.  Skip these.
                 */
                if (inogrp.xi_alloccount == 0)
                        goto igrp_retry;
-               error = ioctl(ctx->mnt.fd, XFS_IOC_FSBULKSTAT, &bulkreq);
-               if (error)
-                       str_info(ctx, descr, "%s", strerror_r(errno,
-                                               buf, DESCR_BUFSZ));
+               error = xfrog_bulkstat(&ctx->mnt, &ino, inogrp.xi_alloccount,
+                               bstat, &bulklen);
+               if (error) {
+                       char    errbuf[DESCR_BUFSZ];
+
+                       str_info(ctx, descr, "%s", strerror_r(error,
+                                               errbuf, DESCR_BUFSZ));
+               }
 
                xfs_iterate_inodes_range_check(ctx, &inogrp, bstat);