]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: devirtualize ->sf_get_ftype and ->sf_put_ftype
authorChristoph Hellwig <hch@lst.de>
Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)
committerEric Sandeen <sandeen@redhat.com>
Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)
Source kernel commit: 4501ed2a3a863ae5d43629b98f6a4d7f6147c4df

Replace the ->sf_get_ftype and ->sf_put_ftype dir ops methods with
directly called xfs_dir2_sf_get_ftype and xfs_dir2_sf_put_ftype helpers
that takes care of the differences between the directory format with and
without the file type field.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/libxfs_api_defs.h
libxfs/xfs_da_format.c
libxfs/xfs_dir2.h
libxfs/xfs_dir2_block.c
libxfs/xfs_dir2_priv.h
libxfs/xfs_dir2_sf.c
repair/phase6.c

index 3ec24798500a4f32beb3e21669937d0ae7ea555c..09d618e22937779f996c9f1ef050eb5ec7e6d8ae 100644 (file)
@@ -89,6 +89,8 @@
 #define xfs_dir2_sf_put_parent_ino     libxfs_dir2_sf_put_parent_ino
 #define xfs_dir2_sf_entsize            libxfs_dir2_sf_entsize
 #define xfs_dir2_sf_nextentry          libxfs_dir2_sf_nextentry
+#define xfs_dir2_sf_get_ftype          libxfs_dir2_sf_get_ftype
+#define xfs_dir2_sf_put_ftype          libxfs_dir2_sf_put_ftype
 #define xfs_dir2_sf_get_ino            libxfs_dir2_sf_get_ino
 #define xfs_dir2_sf_put_ino            libxfs_dir2_sf_put_ino
 #define xfs_dir2_namecheck             libxfs_dir2_namecheck
index c58efe0cec22134d8ebfb15cd77a15674a2d0d5c..f940a6b53fd9a3585a378b492f005305fafe7d99 100644 (file)
 #include "xfs_dir2.h"
 #include "xfs_dir2_priv.h"
 
-/*
- * For filetype enabled shortform directories, the file type field is stored at
- * the end of the name.  Because it's only a single byte, endian conversion is
- * not necessary. For non-filetype enable directories, the type is always
- * unknown and we never store the value.
- */
-static uint8_t
-xfs_dir2_sfe_get_ftype(
-       struct xfs_dir2_sf_entry *sfep)
-{
-       return XFS_DIR3_FT_UNKNOWN;
-}
-
-static void
-xfs_dir2_sfe_put_ftype(
-       struct xfs_dir2_sf_entry *sfep,
-       uint8_t                 ftype)
-{
-       ASSERT(ftype < XFS_DIR3_FT_MAX);
-}
-
-static uint8_t
-xfs_dir3_sfe_get_ftype(
-       struct xfs_dir2_sf_entry *sfep)
-{
-       uint8_t         ftype;
-
-       ftype = sfep->name[sfep->namelen];
-       if (ftype >= XFS_DIR3_FT_MAX)
-               return XFS_DIR3_FT_UNKNOWN;
-       return ftype;
-}
-
-static void
-xfs_dir3_sfe_put_ftype(
-       struct xfs_dir2_sf_entry *sfep,
-       uint8_t                 ftype)
-{
-       ASSERT(ftype < XFS_DIR3_FT_MAX);
-
-       sfep->name[sfep->namelen] = ftype;
-}
-
 /*
  * Directory data block operations
  */
@@ -271,9 +228,6 @@ xfs_dir3_data_unused_p(struct xfs_dir2_data_hdr *hdr)
 }
 
 static const struct xfs_dir_ops xfs_dir2_ops = {
-       .sf_get_ftype = xfs_dir2_sfe_get_ftype,
-       .sf_put_ftype = xfs_dir2_sfe_put_ftype,
-
        .data_entsize = xfs_dir2_data_entsize,
        .data_get_ftype = xfs_dir2_data_get_ftype,
        .data_put_ftype = xfs_dir2_data_put_ftype,
@@ -296,9 +250,6 @@ static const struct xfs_dir_ops xfs_dir2_ops = {
 };
 
 static const struct xfs_dir_ops xfs_dir2_ftype_ops = {
-       .sf_get_ftype = xfs_dir3_sfe_get_ftype,
-       .sf_put_ftype = xfs_dir3_sfe_put_ftype,
-
        .data_entsize = xfs_dir3_data_entsize,
        .data_get_ftype = xfs_dir3_data_get_ftype,
        .data_put_ftype = xfs_dir3_data_put_ftype,
@@ -321,9 +272,6 @@ static const struct xfs_dir_ops xfs_dir2_ftype_ops = {
 };
 
 static const struct xfs_dir_ops xfs_dir3_ops = {
-       .sf_get_ftype = xfs_dir3_sfe_get_ftype,
-       .sf_put_ftype = xfs_dir3_sfe_put_ftype,
-
        .data_entsize = xfs_dir3_data_entsize,
        .data_get_ftype = xfs_dir3_data_get_ftype,
        .data_put_ftype = xfs_dir3_data_put_ftype,
index 049d844d6a181c79121805e06973a934083ca21f..61cc9ae837d5c5554df6d3da16e8b37fe239940c 100644 (file)
@@ -32,10 +32,6 @@ extern unsigned char xfs_mode_to_ftype(int mode);
  * directory operations vector for encode/decode routines
  */
 struct xfs_dir_ops {
-       uint8_t (*sf_get_ftype)(struct xfs_dir2_sf_entry *sfep);
-       void    (*sf_put_ftype)(struct xfs_dir2_sf_entry *sfep,
-                               uint8_t ftype);
-
        int     (*data_entsize)(int len);
        uint8_t (*data_get_ftype)(struct xfs_dir2_data_entry *dep);
        void    (*data_put_ftype)(struct xfs_dir2_data_entry *dep,
index 63e07cc9e5e7da49f698a1d26c27b45d8f173ec5..25662ca28c611971494b3c7dde55cbf652d3631a 100644 (file)
@@ -1207,7 +1207,7 @@ xfs_dir2_sf_to_block(
                dep = (xfs_dir2_data_entry_t *)((char *)hdr + newoffset);
                dep->inumber = cpu_to_be64(xfs_dir2_sf_get_ino(mp, sfp, sfep));
                dep->namelen = sfep->namelen;
-               dp->d_ops->data_put_ftype(dep, dp->d_ops->sf_get_ftype(sfep));
+               dp->d_ops->data_put_ftype(dep, xfs_dir2_sf_get_ftype(mp, sfep));
                memcpy(dep->name, sfep->name, dep->namelen);
                tagp = dp->d_ops->data_entry_tag_p(dep);
                *tagp = cpu_to_be16((char *)dep - (char *)hdr);
index 0271a6b206257830b2ba81cb6d50922963e7b5fa..d6b58aa7ee84e2976bab7bd771244119325af345 100644 (file)
@@ -151,6 +151,10 @@ void xfs_dir2_sf_put_ino(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr,
                struct xfs_dir2_sf_entry *sfep, xfs_ino_t ino);
 xfs_ino_t xfs_dir2_sf_get_parent_ino(struct xfs_dir2_sf_hdr *hdr);
 void xfs_dir2_sf_put_parent_ino(struct xfs_dir2_sf_hdr *hdr, xfs_ino_t ino);
+uint8_t xfs_dir2_sf_get_ftype(struct xfs_mount *mp,
+               struct xfs_dir2_sf_entry *sfep);
+void xfs_dir2_sf_put_ftype(struct xfs_mount *mp, struct xfs_dir2_sf_entry *sfep,
+               uint8_t ftype);
 struct xfs_dir2_sf_entry *xfs_dir2_sf_nextentry(struct xfs_mount *mp,
                struct xfs_dir2_sf_hdr *hdr, struct xfs_dir2_sf_entry *sfep);
 int xfs_dir2_sf_entsize(struct xfs_mount *mp,
index 0d8f692b600e88bd2b341c169a19b74be67b75b8..ddef8b448e1f8cfe4482ac9cb78907f688ef4ee2 100644 (file)
@@ -126,6 +126,37 @@ xfs_dir2_sf_put_parent_ino(
                put_unaligned_be32(ino, hdr->parent);
 }
 
+/*
+ * The file type field is stored at the end of the name for filetype enabled
+ * shortform directories, or not at all otherwise.
+ */
+uint8_t
+xfs_dir2_sf_get_ftype(
+       struct xfs_mount                *mp,
+       struct xfs_dir2_sf_entry        *sfep)
+{
+       if (xfs_sb_version_hasftype(&mp->m_sb)) {
+               uint8_t                 ftype = sfep->name[sfep->namelen];
+
+               if (ftype < XFS_DIR3_FT_MAX)
+                       return ftype;
+       }
+
+       return XFS_DIR3_FT_UNKNOWN;
+}
+
+void
+xfs_dir2_sf_put_ftype(
+       struct xfs_mount        *mp,
+       struct xfs_dir2_sf_entry *sfep,
+       uint8_t                 ftype)
+{
+       ASSERT(ftype < XFS_DIR3_FT_MAX);
+
+       if (xfs_sb_version_hasftype(&mp->m_sb))
+               sfep->name[sfep->namelen] = ftype;
+}
+
 /*
  * Given a block directory (dp/block), calculate its size as a shortform (sf)
  * directory and a header for the sf directory, if it will fit it the
@@ -305,7 +336,7 @@ xfs_dir2_block_to_sf(
                        memcpy(sfep->name, dep->name, dep->namelen);
                        xfs_dir2_sf_put_ino(mp, sfp, sfep,
                                              be64_to_cpu(dep->inumber));
-                       dp->d_ops->sf_put_ftype(sfep,
+                       xfs_dir2_sf_put_ftype(mp, sfep,
                                        dp->d_ops->data_get_ftype(dep));
 
                        sfep = xfs_dir2_sf_nextentry(mp, sfp, sfep);
@@ -471,7 +502,7 @@ xfs_dir2_sf_addname_easy(
        xfs_dir2_sf_put_offset(sfep, offset);
        memcpy(sfep->name, args->name, sfep->namelen);
        xfs_dir2_sf_put_ino(mp, sfp, sfep, args->inumber);
-       dp->d_ops->sf_put_ftype(sfep, args->filetype);
+       xfs_dir2_sf_put_ftype(mp, sfep, args->filetype);
 
        /*
         * Update the header and inode.
@@ -561,7 +592,7 @@ xfs_dir2_sf_addname_hard(
        xfs_dir2_sf_put_offset(sfep, offset);
        memcpy(sfep->name, args->name, sfep->namelen);
        xfs_dir2_sf_put_ino(mp, sfp, sfep, args->inumber);
-       dp->d_ops->sf_put_ftype(sfep, args->filetype);
+       xfs_dir2_sf_put_ftype(mp, sfep, args->filetype);
        sfp->count++;
        if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && !objchange)
                sfp->i8count++;
@@ -658,7 +689,8 @@ static void
 xfs_dir2_sf_check(
        xfs_da_args_t           *args)          /* operation arguments */
 {
-       xfs_inode_t             *dp;            /* incore directory inode */
+       struct xfs_inode        *dp = args->dp;
+       struct xfs_mount        *mp = dp->i_mount;
        int                     i;              /* entry number */
        int                     i8count;        /* number of big inode#s */
        xfs_ino_t               ino;            /* entry inode number */
@@ -666,8 +698,6 @@ xfs_dir2_sf_check(
        xfs_dir2_sf_entry_t     *sfep;          /* shortform dir entry */
        xfs_dir2_sf_hdr_t       *sfp;           /* shortform structure */
 
-       dp = args->dp;
-
        sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
        offset = dp->d_ops->data_first_offset;
        ino = xfs_dir2_sf_get_parent_ino(sfp);
@@ -675,14 +705,14 @@ xfs_dir2_sf_check(
 
        for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp);
             i < sfp->count;
-            i++, sfep = xfs_dir2_sf_nextentry(dp->i_mount, sfp, sfep)) {
+            i++, sfep = xfs_dir2_sf_nextentry(mp, sfp, sfep)) {
                ASSERT(xfs_dir2_sf_get_offset(sfep) >= offset);
-               ino = xfs_dir2_sf_get_ino(dp->i_mount, sfp, sfep);
+               ino = xfs_dir2_sf_get_ino(mp, sfp, sfep);
                i8count += ino > XFS_DIR2_MAX_SHORT_INUM;
                offset =
                        xfs_dir2_sf_get_offset(sfep) +
                        dp->d_ops->data_entsize(sfep->namelen);
-               ASSERT(dp->d_ops->sf_get_ftype(sfep) < XFS_DIR3_FT_MAX);
+               ASSERT(xfs_dir2_sf_get_ftype(mp, sfep) < XFS_DIR3_FT_MAX);
        }
        ASSERT(i8count == sfp->i8count);
        ASSERT((char *)sfep - (char *)sfp == dp->i_d.di_size);
@@ -776,7 +806,7 @@ xfs_dir2_sf_verify(
                        return __this_address;
 
                /* Check the file type. */
-               filetype = dops->sf_get_ftype(sfep);
+               filetype = xfs_dir2_sf_get_ftype(mp, sfep);
                if (filetype >= XFS_DIR3_FT_MAX)
                        return __this_address;
 
@@ -913,7 +943,7 @@ xfs_dir2_sf_lookup(
                if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) {
                        args->cmpresult = cmp;
                        args->inumber = xfs_dir2_sf_get_ino(mp, sfp, sfep);
-                       args->filetype = dp->d_ops->sf_get_ftype(sfep);
+                       args->filetype = xfs_dir2_sf_get_ftype(mp, sfep);
                        if (cmp == XFS_CMP_EXACT)
                                return -EEXIST;
                        ci_sfep = sfep;
@@ -1084,7 +1114,7 @@ xfs_dir2_sf_replace(
                                ASSERT(args->inumber != ino);
                                xfs_dir2_sf_put_ino(mp, sfp, sfep,
                                                args->inumber);
-                               dp->d_ops->sf_put_ftype(sfep, args->filetype);
+                               xfs_dir2_sf_put_ftype(mp, sfep, args->filetype);
                                break;
                        }
                }
@@ -1190,7 +1220,8 @@ xfs_dir2_sf_toino4(
                memcpy(sfep->name, oldsfep->name, sfep->namelen);
                xfs_dir2_sf_put_ino(mp, sfp, sfep,
                                xfs_dir2_sf_get_ino(mp, oldsfp, oldsfep));
-               dp->d_ops->sf_put_ftype(sfep, dp->d_ops->sf_get_ftype(oldsfep));
+               xfs_dir2_sf_put_ftype(mp, sfep,
+                               xfs_dir2_sf_get_ftype(mp, oldsfep));
        }
        /*
         * Clean up the inode.
@@ -1262,7 +1293,8 @@ xfs_dir2_sf_toino8(
                memcpy(sfep->name, oldsfep->name, sfep->namelen);
                xfs_dir2_sf_put_ino(mp, sfp, sfep,
                                xfs_dir2_sf_get_ino(mp, oldsfp, oldsfep));
-               dp->d_ops->sf_put_ftype(sfep, dp->d_ops->sf_get_ftype(oldsfep));
+               xfs_dir2_sf_put_ftype(mp, sfep,
+                               xfs_dir2_sf_get_ftype(mp, oldsfep));
        }
        /*
         * Clean up the inode.
index 7350e976192e33405fa5ea08177c5dfd76bfa230..d4d26254ab279ef3e408f99e0b3efb5761fdd3dd 100644 (file)
@@ -2708,7 +2708,7 @@ shortform_dir2_entry_check(xfs_mount_t    *mp,
                if (!dir_hash_add(mp, hashtab, (xfs_dir2_dataptr_t)
                                (sfep - xfs_dir2_sf_firstentry(sfp)),
                                lino, sfep->namelen, sfep->name,
-                               M_DIROPS(mp)->sf_get_ftype(sfep))) {
+                               libxfs_dir2_sf_get_ftype(mp, sfep))) {
                        do_warn(
 _("entry \"%s\" (ino %" PRIu64 ") in dir %" PRIu64 " is a duplicate name"),
                                fname, lino, ino);
@@ -2773,7 +2773,7 @@ _("entry \"%s\" (ino %" PRIu64 ") in dir %" PRIu64 " is a duplicate name"),
                        uint8_t dir_ftype;
                        uint8_t ino_ftype;
 
-                       dir_ftype = M_DIROPS(mp)->sf_get_ftype(sfep);
+                       dir_ftype = libxfs_dir2_sf_get_ftype(mp, sfep);
                        ino_ftype = get_inode_ftype(irec, ino_offset);
 
                        if (dir_ftype != ino_ftype) {
@@ -2787,7 +2787,7 @@ _("entry \"%s\" (ino %" PRIu64 ") in dir %" PRIu64 " is a duplicate name"),
        _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64 "/%" PRIu64 "\n"),
                                                dir_ftype, ino_ftype,
                                                ino, lino);
-                                       M_DIROPS(mp)->sf_put_ftype(sfep,
+                                       libxfs_dir2_sf_put_ftype(mp, sfep,
                                                                ino_ftype);
                                        dir_hash_update_ftype(hashtab,
                        (xfs_dir2_dataptr_t)(sfep - xfs_dir2_sf_firstentry(sfp)),