xfs: Refactor xfs_attr_rmtval_remove
authorAllison Collins <allison.henderson@oracle.com>
Tue, 21 Jul 2020 04:47:26 +0000 (21:47 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Wed, 29 Jul 2020 03:28:11 +0000 (20:28 -0700)
Refactor xfs_attr_rmtval_remove to add helper function
__xfs_attr_rmtval_remove. We will use this later when we introduce
delayed attributes.  This function will eventually replace
xfs_attr_rmtval_remove

Signed-off-by: Allison Collins <allison.henderson@oracle.com>
Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com>
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>
Acked-by: Dave Chinner <dchinner@redhat.com>
fs/xfs/libxfs/xfs_attr_remote.c
fs/xfs/libxfs/xfs_attr_remote.h

index 4d519691daafcb7c0d1595fc08fb3caeadaa380b..3e7f6e07586043692d0d6d2eb6f68932ce4e4e0c 100644 (file)
@@ -678,10 +678,8 @@ int
 xfs_attr_rmtval_remove(
        struct xfs_da_args      *args)
 {
-       xfs_dablk_t             lblkno;
-       int                     blkcnt;
-       int                     error = 0;
-       int                     done = 0;
+       int                     error;
+       int                     retval;
 
        trace_xfs_attr_rmtval_remove(args);
 
@@ -691,16 +689,10 @@ xfs_attr_rmtval_remove(
        /*
         * Keep de-allocating extents until the remote-value region is gone.
         */
-       lblkno = args->rmtblkno;
-       blkcnt = args->rmtblkcnt;
-       while (!done) {
-               error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
-                                   XFS_BMAPI_ATTRFORK, 1, &done);
-               if (error)
-                       return error;
-               error = xfs_defer_finish(&args->trans);
-               if (error)
-                       return error;
+       do {
+               retval = __xfs_attr_rmtval_remove(args);
+               if (retval && retval != -EAGAIN)
+                       return retval;
 
                /*
                 * Close out trans and start the next one in the chain.
@@ -708,6 +700,36 @@ xfs_attr_rmtval_remove(
                error = xfs_trans_roll_inode(&args->trans, args->dp);
                if (error)
                        return error;
-       }
+       } while (retval == -EAGAIN);
+
        return 0;
 }
+
+/*
+ * Remove the value associated with an attribute by deleting the out-of-line
+ * buffer that it is stored on. Returns EAGAIN for the caller to refresh the
+ * transaction and re-call the function
+ */
+int
+__xfs_attr_rmtval_remove(
+       struct xfs_da_args      *args)
+{
+       int                     error, done;
+
+       /*
+        * Unmap value blocks for this attr.
+        */
+       error = xfs_bunmapi(args->trans, args->dp, args->rmtblkno,
+                           args->rmtblkcnt, XFS_BMAPI_ATTRFORK, 1, &done);
+       if (error)
+               return error;
+
+       error = xfs_defer_finish(&args->trans);
+       if (error)
+               return error;
+
+       if (!done)
+               return -EAGAIN;
+
+       return error;
+}
index 3616e888f7948df060372a8b00518bfb8dea6182..9eee615da15672340b8aafa6348336815493d2cc 100644 (file)
@@ -14,4 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
 int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
                xfs_buf_flags_t incore_flags);
 int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
 #endif /* __XFS_ATTR_REMOTE_H__ */