xfs: refactor the geometry structure filling function
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 8 Jan 2018 18:51:27 +0000 (10:51 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Mon, 8 Jan 2018 18:54:48 +0000 (10:54 -0800)
Refactor the geometry structure filling function to use the superblock
to fill the fields.  While we're at it, make the function less indenty
and use some whitespace to make the function easier to read.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
fs/xfs/libxfs/xfs_da_format.h
fs/xfs/libxfs/xfs_dir2.c
fs/xfs/libxfs/xfs_sb.c
fs/xfs/libxfs/xfs_sb.h
fs/xfs/xfs_ioctl.c
fs/xfs/xfs_ioctl32.c

index 3771edcb301d5ab748f15c8b62b5cd772128ce41..7e77299b778950127cbbcbe9b1dea5feb2ca6e10 100644 (file)
@@ -875,4 +875,10 @@ struct xfs_attr3_rmt_hdr {
        ((bufsize) - (xfs_sb_version_hascrc(&(mp)->m_sb) ? \
                        sizeof(struct xfs_attr3_rmt_hdr) : 0))
 
+/* Number of bytes in a directory block. */
+static inline unsigned int xfs_dir2_dirblock_bytes(struct xfs_sb *sbp)
+{
+       return 1 << (sbp->sb_blocklog + sbp->sb_dirblklog);
+}
+
 #endif /* __XFS_DA_FORMAT_H__ */
index e10778c102ea71e0f4b4727f6acfe28a30aaa4a1..92f94e190f04474953105c049b62a8367fbc7d1e 100644 (file)
@@ -119,8 +119,7 @@ xfs_da_mount(
 
 
        ASSERT(mp->m_sb.sb_versionnum & XFS_SB_VERSION_DIRV2BIT);
-       ASSERT((1 << (mp->m_sb.sb_blocklog + mp->m_sb.sb_dirblklog)) <=
-              XFS_MAX_BLOCKSIZE);
+       ASSERT(xfs_dir2_dirblock_bytes(&mp->m_sb) <= XFS_MAX_BLOCKSIZE);
 
        mp->m_dir_inode_ops = xfs_dir_get_ops(mp, NULL);
        mp->m_nondir_inode_ops = xfs_nondir_get_ops(mp, NULL);
@@ -140,7 +139,7 @@ xfs_da_mount(
        dageo = mp->m_dir_geo;
        dageo->blklog = mp->m_sb.sb_blocklog + mp->m_sb.sb_dirblklog;
        dageo->fsblog = mp->m_sb.sb_blocklog;
-       dageo->blksize = 1 << dageo->blklog;
+       dageo->blksize = xfs_dir2_dirblock_bytes(&mp->m_sb);
        dageo->fsbcount = 1 << mp->m_sb.sb_dirblklog;
 
        /*
index 139517ae7aa896498c5e097a5b74be5f396ea89f..35b005d66977f630fb63f57646e38de09470958f 100644 (file)
@@ -879,77 +879,85 @@ xfs_sync_sb(
 
 int
 xfs_fs_geometry(
-       xfs_mount_t             *mp,
-       xfs_fsop_geom_t         *geo,
-       int                     new_version)
+       struct xfs_sb           *sbp,
+       struct xfs_fsop_geom    *geo,
+       int                     struct_version)
 {
+       memset(geo, 0, sizeof(struct xfs_fsop_geom));
+
+       geo->blocksize = sbp->sb_blocksize;
+       geo->rtextsize = sbp->sb_rextsize;
+       geo->agblocks = sbp->sb_agblocks;
+       geo->agcount = sbp->sb_agcount;
+       geo->logblocks = sbp->sb_logblocks;
+       geo->sectsize = sbp->sb_sectsize;
+       geo->inodesize = sbp->sb_inodesize;
+       geo->imaxpct = sbp->sb_imax_pct;
+       geo->datablocks = sbp->sb_dblocks;
+       geo->rtblocks = sbp->sb_rblocks;
+       geo->rtextents = sbp->sb_rextents;
+       geo->logstart = sbp->sb_logstart;
+       BUILD_BUG_ON(sizeof(geo->uuid) != sizeof(sbp->sb_uuid));
+       memcpy(geo->uuid, &sbp->sb_uuid, sizeof(sbp->sb_uuid));
+
+       if (struct_version < 2)
+               return 0;
+
+       geo->sunit = sbp->sb_unit;
+       geo->swidth = sbp->sb_width;
+
+       if (struct_version < 3)
+               return 0;
+
+       geo->version = XFS_FSOP_GEOM_VERSION;
+       geo->flags = XFS_FSOP_GEOM_FLAGS_NLINK |
+                    XFS_FSOP_GEOM_FLAGS_DIRV2;
+       if (xfs_sb_version_hasattr(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_ATTR;
+       if (xfs_sb_version_hasquota(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_QUOTA;
+       if (xfs_sb_version_hasalign(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_IALIGN;
+       if (xfs_sb_version_hasdalign(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_DALIGN;
+       if (xfs_sb_version_hasextflgbit(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_EXTFLG;
+       if (xfs_sb_version_hassector(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_SECTOR;
+       if (xfs_sb_version_hasasciici(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_DIRV2CI;
+       if (xfs_sb_version_haslazysbcount(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_LAZYSB;
+       if (xfs_sb_version_hasattr2(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_ATTR2;
+       if (xfs_sb_version_hasprojid32bit(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_PROJID32;
+       if (xfs_sb_version_hascrc(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_V5SB;
+       if (xfs_sb_version_hasftype(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_FTYPE;
+       if (xfs_sb_version_hasfinobt(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_FINOBT;
+       if (xfs_sb_version_hassparseinodes(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_SPINODES;
+       if (xfs_sb_version_hasrmapbt(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_RMAPBT;
+       if (xfs_sb_version_hasreflink(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_REFLINK;
+       if (xfs_sb_version_hassector(sbp))
+               geo->logsectsize = sbp->sb_logsectsize;
+       else
+               geo->logsectsize = BBSIZE;
+       geo->rtsectsize = sbp->sb_blocksize;
+       geo->dirblocksize = xfs_dir2_dirblock_bytes(sbp);
+
+       if (struct_version < 3)
+               return 0;
+
+       if (xfs_sb_version_haslogv2(sbp))
+               geo->flags |= XFS_FSOP_GEOM_FLAGS_LOGV2;
+
+       geo->logsunit = sbp->sb_logsunit;
 
-       memset(geo, 0, sizeof(*geo));
-
-       geo->blocksize = mp->m_sb.sb_blocksize;
-       geo->rtextsize = mp->m_sb.sb_rextsize;
-       geo->agblocks = mp->m_sb.sb_agblocks;
-       geo->agcount = mp->m_sb.sb_agcount;
-       geo->logblocks = mp->m_sb.sb_logblocks;
-       geo->sectsize = mp->m_sb.sb_sectsize;
-       geo->inodesize = mp->m_sb.sb_inodesize;
-       geo->imaxpct = mp->m_sb.sb_imax_pct;
-       geo->datablocks = mp->m_sb.sb_dblocks;
-       geo->rtblocks = mp->m_sb.sb_rblocks;
-       geo->rtextents = mp->m_sb.sb_rextents;
-       geo->logstart = mp->m_sb.sb_logstart;
-       ASSERT(sizeof(geo->uuid) == sizeof(mp->m_sb.sb_uuid));
-       memcpy(geo->uuid, &mp->m_sb.sb_uuid, sizeof(mp->m_sb.sb_uuid));
-       if (new_version >= 2) {
-               geo->sunit = mp->m_sb.sb_unit;
-               geo->swidth = mp->m_sb.sb_width;
-       }
-       if (new_version >= 3) {
-               geo->version = XFS_FSOP_GEOM_VERSION;
-               geo->flags = XFS_FSOP_GEOM_FLAGS_NLINK |
-                            XFS_FSOP_GEOM_FLAGS_DIRV2 |
-                       (xfs_sb_version_hasattr(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_ATTR : 0) |
-                       (xfs_sb_version_hasquota(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_QUOTA : 0) |
-                       (xfs_sb_version_hasalign(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_IALIGN : 0) |
-                       (xfs_sb_version_hasdalign(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_DALIGN : 0) |
-                       (xfs_sb_version_hasextflgbit(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_EXTFLG : 0) |
-                       (xfs_sb_version_hassector(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_SECTOR : 0) |
-                       (xfs_sb_version_hasasciici(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_DIRV2CI : 0) |
-                       (xfs_sb_version_haslazysbcount(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_LAZYSB : 0) |
-                       (xfs_sb_version_hasattr2(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_ATTR2 : 0) |
-                       (xfs_sb_version_hasprojid32bit(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_PROJID32 : 0) |
-                       (xfs_sb_version_hascrc(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_V5SB : 0) |
-                       (xfs_sb_version_hasftype(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_FTYPE : 0) |
-                       (xfs_sb_version_hasfinobt(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_FINOBT : 0) |
-                       (xfs_sb_version_hassparseinodes(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_SPINODES : 0) |
-                       (xfs_sb_version_hasrmapbt(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_RMAPBT : 0) |
-                       (xfs_sb_version_hasreflink(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_REFLINK : 0);
-               geo->logsectsize = xfs_sb_version_hassector(&mp->m_sb) ?
-                               mp->m_sb.sb_logsectsize : BBSIZE;
-               geo->rtsectsize = mp->m_sb.sb_blocksize;
-               geo->dirblocksize = mp->m_dir_geo->blksize;
-       }
-       if (new_version >= 4) {
-               geo->flags |=
-                       (xfs_sb_version_haslogv2(&mp->m_sb) ?
-                               XFS_FSOP_GEOM_FLAGS_LOGV2 : 0);
-               geo->logsunit = mp->m_sb.sb_logsunit;
-       }
        return 0;
 }
index a16632c2a332393dd5c90d486f44d7183194b40a..63dcd2a1a65717353b539617e0480eb0fb8f2709 100644 (file)
@@ -34,7 +34,8 @@ extern void   xfs_sb_from_disk(struct xfs_sb *to, struct xfs_dsb *from);
 extern void    xfs_sb_to_disk(struct xfs_dsb *to, struct xfs_sb *from);
 extern void    xfs_sb_quota_from_disk(struct xfs_sb *sbp);
 
-extern int     xfs_fs_geometry(struct xfs_mount *mp, struct xfs_fsop_geom *geo,
-                               int nversion);
+#define XFS_FS_GEOM_MAX_STRUCT_VER     (4)
+extern int     xfs_fs_geometry(struct xfs_sb *sbp, struct xfs_fsop_geom *geo,
+                               int struct_version);
 
 #endif /* __XFS_SB_H__ */
index 3015e178d028e016610b695b32b31cf2a2d770ec..89fb1eb80aae88b3a47e4fd63cb64857639fbb76 100644 (file)
@@ -810,7 +810,7 @@ xfs_ioc_fsgeometry_v1(
        xfs_fsop_geom_t         fsgeo;
        int                     error;
 
-       error = xfs_fs_geometry(mp, &fsgeo, 3);
+       error = xfs_fs_geometry(&mp->m_sb, &fsgeo, 3);
        if (error)
                return error;
 
@@ -832,7 +832,7 @@ xfs_ioc_fsgeometry(
        xfs_fsop_geom_t         fsgeo;
        int                     error;
 
-       error = xfs_fs_geometry(mp, &fsgeo, 4);
+       error = xfs_fs_geometry(&mp->m_sb, &fsgeo, 4);
        if (error)
                return error;
 
index 66cc3cd7026852a33779386483af8072b9a2dabd..10fbde359649dc6a52a8afdb9b26353b4152bbc5 100644 (file)
@@ -67,7 +67,7 @@ xfs_compat_ioc_fsgeometry_v1(
        xfs_fsop_geom_t           fsgeo;
        int                       error;
 
-       error = xfs_fs_geometry(mp, &fsgeo, 3);
+       error = xfs_fs_geometry(&mp->m_sb, &fsgeo, 3);
        if (error)
                return error;
        /* The 32-bit variant simply has some padding at the end */