xfs: split xfs_iformat_fork
authorChristoph Hellwig <hch@lst.de>
Thu, 14 May 2020 21:01:17 +0000 (14:01 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Tue, 19 May 2020 16:40:57 +0000 (09:40 -0700)
xfs_iformat_fork is a weird catchall.  Split it into one helper for
the data fork and one for the attr fork, and then call both helper
as well as the COW fork initialization from xfs_inode_from_disk.  Order
the COW fork initialization after the attr fork initialization given
that it can't fail to simplify the error handling.

Note that the newly split helpers are moved down the file in
xfs_inode_fork.c to avoid the need for forward declarations.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
fs/xfs/libxfs/xfs_inode_buf.c
fs/xfs/libxfs/xfs_inode_fork.c
fs/xfs/libxfs/xfs_inode_fork.h

index dc00ce6fc4a2f42662742863e6791d2864140b0d..abdecc80579e3a7c7f19d0352c350bd65f918d72 100644 (file)
@@ -187,6 +187,10 @@ xfs_inode_from_disk(
 {
        struct xfs_icdinode     *to = &ip->i_d;
        struct inode            *inode = VFS_I(ip);
+       int                     error;
+
+       ASSERT(ip->i_cowfp == NULL);
+       ASSERT(ip->i_afp == NULL);
 
        /*
         * Convert v1 inodes immediately to v2 inode format as this is the
@@ -242,7 +246,21 @@ xfs_inode_from_disk(
                to->di_cowextsize = be32_to_cpu(from->di_cowextsize);
        }
 
-       return xfs_iformat_fork(ip, from);
+       error = xfs_iformat_data_fork(ip, from);
+       if (error)
+               return error;
+       if (XFS_DFORK_Q(from)) {
+               error = xfs_iformat_attr_fork(ip, from);
+               if (error)
+                       goto out_destroy_data_fork;
+       }
+       if (xfs_is_reflink_inode(ip))
+               xfs_ifork_init_cow(ip);
+       return 0;
+
+out_destroy_data_fork:
+       xfs_idestroy_fork(ip, XFS_DATA_FORK);
+       return error;
 }
 
 void
index 3e9a42f1e23b9de331c460c9e70a61c5a0cf7b5b..5fadfa9a17eb927b15221eabd7efe669c92450f9 100644 (file)
 
 kmem_zone_t *xfs_ifork_zone;
 
-STATIC int xfs_iformat_local(xfs_inode_t *, xfs_dinode_t *, int, int);
-STATIC int xfs_iformat_extents(xfs_inode_t *, xfs_dinode_t *, int);
-STATIC int xfs_iformat_btree(xfs_inode_t *, xfs_dinode_t *, int);
-
-/*
- * Copy inode type and data and attr format specific information from the
- * on-disk inode to the in-core inode and fork structures.  For fifos, devices,
- * and sockets this means set i_rdev to the proper value.  For files,
- * directories, and symlinks this means to bring in the in-line data or extent
- * pointers as well as the attribute fork.  For a fork in B-tree format, only
- * the root is immediately brought in-core.  The rest will be read in later when
- * first referenced (see xfs_iread_extents()).
- */
-int
-xfs_iformat_fork(
-       struct xfs_inode        *ip,
-       struct xfs_dinode       *dip)
-{
-       struct inode            *inode = VFS_I(ip);
-       struct xfs_attr_shortform *atp;
-       int                     size;
-       int                     error = 0;
-       xfs_fsize_t             di_size;
-
-       switch (inode->i_mode & S_IFMT) {
-       case S_IFIFO:
-       case S_IFCHR:
-       case S_IFBLK:
-       case S_IFSOCK:
-               ip->i_d.di_size = 0;
-               inode->i_rdev = xfs_to_linux_dev_t(xfs_dinode_get_rdev(dip));
-               break;
-
-       case S_IFREG:
-       case S_IFLNK:
-       case S_IFDIR:
-               switch (dip->di_format) {
-               case XFS_DINODE_FMT_LOCAL:
-                       di_size = be64_to_cpu(dip->di_size);
-                       size = (int)di_size;
-                       error = xfs_iformat_local(ip, dip, XFS_DATA_FORK, size);
-                       break;
-               case XFS_DINODE_FMT_EXTENTS:
-                       error = xfs_iformat_extents(ip, dip, XFS_DATA_FORK);
-                       break;
-               case XFS_DINODE_FMT_BTREE:
-                       error = xfs_iformat_btree(ip, dip, XFS_DATA_FORK);
-                       break;
-               default:
-                       xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__,
-                                       dip, sizeof(*dip), __this_address);
-                       return -EFSCORRUPTED;
-               }
-               break;
-
-       default:
-               xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__, dip,
-                               sizeof(*dip), __this_address);
-               return -EFSCORRUPTED;
-       }
-       if (error)
-               return error;
-
-       if (xfs_is_reflink_inode(ip)) {
-               ASSERT(ip->i_cowfp == NULL);
-               xfs_ifork_init_cow(ip);
-       }
-
-       if (!XFS_DFORK_Q(dip))
-               return 0;
-
-       ASSERT(ip->i_afp == NULL);
-       ip->i_afp = kmem_zone_zalloc(xfs_ifork_zone, KM_NOFS);
-
-       switch (dip->di_aformat) {
-       case XFS_DINODE_FMT_LOCAL:
-               atp = (xfs_attr_shortform_t *)XFS_DFORK_APTR(dip);
-               size = be16_to_cpu(atp->hdr.totsize);
-
-               error = xfs_iformat_local(ip, dip, XFS_ATTR_FORK, size);
-               break;
-       case XFS_DINODE_FMT_EXTENTS:
-               error = xfs_iformat_extents(ip, dip, XFS_ATTR_FORK);
-               break;
-       case XFS_DINODE_FMT_BTREE:
-               error = xfs_iformat_btree(ip, dip, XFS_ATTR_FORK);
-               break;
-       default:
-               xfs_inode_verifier_error(ip, error, __func__, dip,
-                               sizeof(*dip), __this_address);
-               error = -EFSCORRUPTED;
-               break;
-       }
-       if (error) {
-               kmem_cache_free(xfs_ifork_zone, ip->i_afp);
-               ip->i_afp = NULL;
-               if (ip->i_cowfp)
-                       kmem_cache_free(xfs_ifork_zone, ip->i_cowfp);
-               ip->i_cowfp = NULL;
-               xfs_idestroy_fork(ip, XFS_DATA_FORK);
-       }
-       return error;
-}
-
 void
 xfs_init_local_fork(
        struct xfs_inode        *ip,
@@ -325,6 +221,88 @@ xfs_iformat_btree(
        return 0;
 }
 
+int
+xfs_iformat_data_fork(
+       struct xfs_inode        *ip,
+       struct xfs_dinode       *dip)
+{
+       struct inode            *inode = VFS_I(ip);
+
+       switch (inode->i_mode & S_IFMT) {
+       case S_IFIFO:
+       case S_IFCHR:
+       case S_IFBLK:
+       case S_IFSOCK:
+               ip->i_d.di_size = 0;
+               inode->i_rdev = xfs_to_linux_dev_t(xfs_dinode_get_rdev(dip));
+               return 0;
+       case S_IFREG:
+       case S_IFLNK:
+       case S_IFDIR:
+               switch (dip->di_format) {
+               case XFS_DINODE_FMT_LOCAL:
+                       return xfs_iformat_local(ip, dip, XFS_DATA_FORK,
+                                       be64_to_cpu(dip->di_size));
+               case XFS_DINODE_FMT_EXTENTS:
+                       return xfs_iformat_extents(ip, dip, XFS_DATA_FORK);
+               case XFS_DINODE_FMT_BTREE:
+                       return xfs_iformat_btree(ip, dip, XFS_DATA_FORK);
+               default:
+                       xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__,
+                                       dip, sizeof(*dip), __this_address);
+                       return -EFSCORRUPTED;
+               }
+               break;
+       default:
+               xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__, dip,
+                               sizeof(*dip), __this_address);
+               return -EFSCORRUPTED;
+       }
+}
+
+static uint16_t
+xfs_dfork_attr_shortform_size(
+       struct xfs_dinode               *dip)
+{
+       struct xfs_attr_shortform       *atp =
+               (struct xfs_attr_shortform *)XFS_DFORK_APTR(dip);
+
+       return be16_to_cpu(atp->hdr.totsize);
+}
+
+int
+xfs_iformat_attr_fork(
+       struct xfs_inode        *ip,
+       struct xfs_dinode       *dip)
+{
+       int                     error = 0;
+
+       ip->i_afp = kmem_zone_zalloc(xfs_ifork_zone, KM_NOFS);
+       switch (dip->di_aformat) {
+       case XFS_DINODE_FMT_LOCAL:
+               error = xfs_iformat_local(ip, dip, XFS_ATTR_FORK,
+                               xfs_dfork_attr_shortform_size(dip));
+               break;
+       case XFS_DINODE_FMT_EXTENTS:
+               error = xfs_iformat_extents(ip, dip, XFS_ATTR_FORK);
+               break;
+       case XFS_DINODE_FMT_BTREE:
+               error = xfs_iformat_btree(ip, dip, XFS_ATTR_FORK);
+               break;
+       default:
+               xfs_inode_verifier_error(ip, error, __func__, dip,
+                               sizeof(*dip), __this_address);
+               error = -EFSCORRUPTED;
+               break;
+       }
+
+       if (error) {
+               kmem_cache_free(xfs_ifork_zone, ip->i_afp);
+               ip->i_afp = NULL;
+       }
+       return error;
+}
+
 /*
  * Reallocate the space for if_broot based on the number of records
  * being added or deleted as indicated in rec_diff.  Move the records
index 668ee942be224f87c0d76093fbb3dd5d0435b190..8487b0c88a75e04b276c1a7f771bed8b0e87d6a0 100644 (file)
@@ -88,7 +88,8 @@ struct xfs_ifork {
 
 struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state);
 
-int            xfs_iformat_fork(struct xfs_inode *, struct xfs_dinode *);
+int            xfs_iformat_data_fork(struct xfs_inode *, struct xfs_dinode *);
+int            xfs_iformat_attr_fork(struct xfs_inode *, struct xfs_dinode *);
 void           xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,
                                struct xfs_inode_log_item *, int);
 void           xfs_idestroy_fork(struct xfs_inode *, int);