]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libfrog: create online fs geometry converters
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 9 Sep 2019 19:37:05 +0000 (15:37 -0400)
committerEric Sandeen <sandeen@redhat.com>
Mon, 9 Sep 2019 19:37:05 +0000 (15:37 -0400)
Create helper functions to perform unit conversions against a runtime
filesystem, then remove the open-coded versions in scrub.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Collins <allison.henderson@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
include/fsgeom.h
libfrog/fsgeom.c
scrub/fscounters.c
scrub/inodes.c
scrub/phase3.c
scrub/phase5.c
scrub/phase6.c
scrub/phase7.c

index 7837c700b331d7d96e2734233e2a4b7c7b6bea49..771732f2f5b887e448cd42262fb0ab0fcd9e5f83 100644 (file)
@@ -32,6 +32,9 @@ struct xfs_fd {
 
        /* log2 of sb_inopblock */
        unsigned int            inopblog;
+
+       /* bits for agino in inum */
+       unsigned int            aginolog;
 };
 
 /* Static initializers */
@@ -41,4 +44,58 @@ struct xfs_fd {
 int xfd_prepare_geometry(struct xfs_fd *xfd);
 int xfd_close(struct xfs_fd *xfd);
 
+/* Convert AG number and AG inode number into fs inode number. */
+static inline uint64_t
+cvt_agino_to_ino(
+       const struct xfs_fd     *xfd,
+       uint32_t                agno,
+       uint32_t                agino)
+{
+       return ((uint64_t)agno << xfd->aginolog) + agino;
+}
+
+/* Convert fs inode number into AG number. */
+static inline uint32_t
+cvt_ino_to_agno(
+       const struct xfs_fd     *xfd,
+       uint64_t                ino)
+{
+       return ino >> xfd->aginolog;
+}
+
+/* Convert fs inode number into AG inode number. */
+static inline uint32_t
+cvt_ino_to_agino(
+       const struct xfs_fd     *xfd,
+       uint64_t                ino)
+{
+       return ino & ((1ULL << xfd->aginolog) - 1);
+}
+
+/*
+ * Convert a linear fs block offset number into bytes.  This is the runtime
+ * equivalent of XFS_FSB_TO_B, which means that it is /not/ for segmented fsbno
+ * format (= agno | agbno) that we use internally for the data device.
+ */
+static inline uint64_t
+cvt_off_fsb_to_b(
+       const struct xfs_fd     *xfd,
+       uint64_t                fsb)
+{
+       return fsb << xfd->blocklog;
+}
+
+/*
+ * Convert bytes into a (rounded down) linear fs block offset number.  This is
+ * the runtime equivalent of XFS_B_TO_FSBT.  It does not produce segmented
+ * fsbno numbers (= agno | agbno).
+ */
+static inline uint64_t
+cvt_b_to_off_fsbt(
+       const struct xfs_fd     *xfd,
+       uint64_t                bytes)
+{
+       return bytes >> xfd->blocklog;
+}
+
 #endif /* _LIBFROG_FSGEOM_H_ */
index b7e2b2f8ab777ba10081a14bb8f0cbb2ea747098..39604556a7dc19e532b0c19ee016d99c83f1e91a 100644 (file)
@@ -112,6 +112,7 @@ xfd_prepare_geometry(
        xfd->blocklog = highbit32(xfd->fsgeom.blocksize);
        xfd->inodelog = highbit32(xfd->fsgeom.inodesize);
        xfd->inopblog = xfd->blocklog - xfd->inodelog;
+       xfd->aginolog = xfd->agblklog + xfd->inopblog;
        return 0;
 }
 
index ac898764b7181da59bc92ad7a9a2a6c771d70080..ea6af156f72f2a9eabcfa25ba43bb66e6f79ae17 100644 (file)
@@ -91,8 +91,8 @@ xfs_count_ag_inodes(
                                minor(ctx->fsinfo.fs_datadev),
                                agno);
 
-       ag_ino = (__u64)agno << (ctx->mnt.inopblog + ctx->mnt.agblklog);
-       next_ag_ino = (__u64)(agno + 1) << (ctx->mnt.inopblog + ctx->mnt.agblklog);
+       ag_ino = cvt_agino_to_ino(&ctx->mnt, agno, 0);
+       next_ag_ino = cvt_agino_to_ino(&ctx->mnt, agno + 1, 0);
 
        moveon = xfs_count_inodes_range(ctx, descr, ag_ino, next_ag_ino - 1,
                        &ci->counters[agno]);
index 873ad4258028f512c44f3c8251c4ea9c917447bb..700e52009e5bd8648a649dcfc88827bca8bd7d92 100644 (file)
@@ -228,8 +228,8 @@ xfs_scan_ag_inodes(
                                minor(ctx->fsinfo.fs_datadev),
                                agno);
 
-       ag_ino = (__u64)agno << (ctx->mnt.inopblog + ctx->mnt.agblklog);
-       next_ag_ino = (__u64)(agno + 1) << (ctx->mnt.inopblog + ctx->mnt.agblklog);
+       ag_ino = cvt_agino_to_ino(&ctx->mnt, agno, 0);
+       next_ag_ino = cvt_agino_to_ino(&ctx->mnt, agno + 1, 0);
 
        moveon = xfs_iterate_inodes_range(ctx, descr, ctx->fshandle, ag_ino,
                        next_ag_ino - 1, si->fn, si->arg);
index 579e08c385ffada4b85f88005bbe93ca774a64ce..8c02f1cb19e05c47b33f09ae3a8f3a6e149982b6 100644 (file)
@@ -52,8 +52,8 @@ xfs_scrub_inode_vfs_error(
        xfs_agino_t             agino;
        int                     old_errno = errno;
 
-       agno = bstat->bs_ino / (1ULL << (ctx->mnt.inopblog + ctx->mnt.agblklog));
-       agino = bstat->bs_ino % (1ULL << (ctx->mnt.inopblog + ctx->mnt.agblklog));
+       agno = cvt_ino_to_agno(&ctx->mnt, bstat->bs_ino);
+       agino = cvt_ino_to_agino(&ctx->mnt, bstat->bs_ino);
        snprintf(descr, DESCR_BUFSZ, _("inode %"PRIu64" (%u/%u)"),
                        (uint64_t)bstat->bs_ino, agno, agino);
        errno = old_errno;
@@ -77,7 +77,7 @@ xfs_scrub_inode(
        int                     error;
 
        xfs_action_list_init(&alist);
-       agno = bstat->bs_ino / (1ULL << (ctx->mnt.inopblog + ctx->mnt.agblklog));
+       agno = cvt_ino_to_agno(&ctx->mnt, bstat->bs_ino);
        background_sleep();
 
        /* Try to open the inode to pin it. */
index 36ec27b38704304d3211a93f37f8d6cecfa22cd2..f3ee22e6a3dfe42d305de50c1fca1e9bd99e4750 100644 (file)
@@ -239,8 +239,8 @@ xfs_scrub_connections(
        int                     fd = -1;
        int                     error;
 
-       agno = bstat->bs_ino / (1ULL << (ctx->mnt.inopblog + ctx->mnt.agblklog));
-       agino = bstat->bs_ino % (1ULL << (ctx->mnt.inopblog + ctx->mnt.agblklog));
+       agno = cvt_ino_to_agno(&ctx->mnt, bstat->bs_ino);
+       agino = cvt_ino_to_agino(&ctx->mnt, bstat->bs_ino);
        snprintf(descr, DESCR_BUFSZ, _("inode %"PRIu64" (%u/%u)"),
                        (uint64_t)bstat->bs_ino, agno, agino);
        background_sleep();
index 489712702c4b3d2989d7f69a805a614274e56f4f..5628b926830e833f61b93696456be40c618d67a1 100644 (file)
@@ -547,7 +547,8 @@ xfs_estimate_verify_work(
        if (!moveon)
                return moveon;
 
-       *items = ((d_blocks - d_bfree) + (r_blocks - r_bfree)) << ctx->mnt.blocklog;
+       *items = cvt_off_fsb_to_b(&ctx->mnt,
+                       (d_blocks - d_bfree) + (r_blocks - r_bfree));
        *nr_threads = disk_heads(ctx->datadev);
        *rshift = 20;
        return moveon;
index 41a7735649a2cf1c7e164af0dbfc28ad04e6d957..8a028e191b1c635de87bdf919f32a91ee0f02b94 100644 (file)
@@ -148,11 +148,11 @@ xfs_scan_summary(
         * filesystem treats them as "free", but since we scanned
         * them, we'll consider them used.
         */
-       d_bfree -= totalcount.agbytes >> ctx->mnt.blocklog;
+       d_bfree -= cvt_b_to_off_fsbt(&ctx->mnt, totalcount.agbytes);
 
        /* Report on what we found. */
-       used_data = (d_blocks - d_bfree) << ctx->mnt.blocklog;
-       used_rt = (r_blocks - r_bfree) << ctx->mnt.blocklog;
+       used_data = cvt_off_fsb_to_b(&ctx->mnt, d_blocks - d_bfree);
+       used_rt = cvt_off_fsb_to_b(&ctx->mnt, r_blocks - r_bfree);
        used_files = f_files - f_free;
        stat_data = totalcount.dbytes;
        stat_rt = totalcount.rbytes;