]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: pass an initialized xfs_da_args structure to xfs_attr_set
authorChristoph Hellwig <hch@lst.de>
Fri, 1 May 2020 21:01:30 +0000 (17:01 -0400)
committerEric Sandeen <sandeen@redhat.com>
Fri, 1 May 2020 21:01:30 +0000 (17:01 -0400)
Source kernel commit: a25446224353a773c7f4ba9ee5ae137515204efe

Instead of converting from one style of arguments to another in
xfs_attr_set, pass the structure from higher up in the call chain.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com>
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>
db/attrset.c
libxfs/xfs_attr.c
libxfs/xfs_attr.h

index 5bf82fd613564e96aed0c2431bb057c14631c47e..2d5e16485fc2aff0d7661b3a6743d13550813510 100644 (file)
@@ -63,12 +63,13 @@ attrset_init(void)
 
 static int
 attr_set_f(
-       int             argc,
-       char            **argv)
+       int                     argc,
+       char                    **argv)
 {
-       xfs_inode_t     *ip = NULL;
-       char            *name, *value, *sp;
-       int             c, valuelen = 0, flags = 0;
+       struct xfs_inode        *ip = NULL;
+       struct xfs_da_args      args = { NULL };
+       char                    *name, *value, *sp;
+       int                     c, valuelen = 0, flags = 0;
 
        if (cur_typ == NULL) {
                dbprintf(_("no current type\n"));
@@ -146,8 +147,14 @@ attr_set_f(
                goto out;
        }
 
-       if (libxfs_attr_set(ip, (unsigned char *)name, strlen(name),
-                               (unsigned char *)value, valuelen, flags)) {
+       args.dp = ip;
+       args.name = (unsigned char *)name;
+       args.namelen = strlen(name);
+       args.value = value;
+       args.valuelen = valuelen;
+       args.flags = flags;
+
+       if (libxfs_attr_set(&args)) {
                dbprintf(_("failed to set attr %s on inode %llu\n"),
                        name, (unsigned long long)iocur_top->ino);
                goto out;
@@ -167,12 +174,13 @@ out:
 
 static int
 attr_remove_f(
-       int             argc,
-       char            **argv)
+       int                     argc,
+       char                    **argv)
 {
-       xfs_inode_t     *ip = NULL;
-       char            *name;
-       int             c, flags = 0;
+       struct xfs_inode        *ip = NULL;
+       struct xfs_da_args      args = { NULL };
+       char                    *name;
+       int                     c, flags = 0;
 
        if (cur_typ == NULL) {
                dbprintf(_("no current type\n"));
@@ -222,8 +230,13 @@ attr_remove_f(
                goto out;
        }
 
-       if (libxfs_attr_set(ip, (unsigned char *)name, strlen(name),
-                               NULL, 0, flags)) {
+       args.dp = ip;
+       args.name = (unsigned char *)name;
+       args.namelen = strlen(name);
+       args.value = NULL;
+       args.flags = flags;
+
+       if (libxfs_attr_set(&args)) {
                dbprintf(_("failed to remove attr %s from inode %llu\n"),
                        name, (unsigned long long)iocur_top->ino);
                goto out;
index ded952da7aebb8c7d2616a99150da4f7805a9b55..e42a80339a37cf972736b0953eb2539e8a09ed81 100644 (file)
@@ -330,22 +330,17 @@ xfs_attr_remove_args(
 }
 
 /*
- * Note: If value is NULL the attribute will be removed, just like the
+ * Note: If args->value is NULL the attribute will be removed, just like the
  * Linux ->setattr API.
  */
 int
 xfs_attr_set(
-       struct xfs_inode        *dp,
-       const unsigned char     *name,
-       size_t                  namelen,
-       unsigned char           *value,
-       int                     valuelen,
-       int                     flags)
+       struct xfs_da_args      *args)
 {
+       struct xfs_inode        *dp = args->dp;
        struct xfs_mount        *mp = dp->i_mount;
-       struct xfs_da_args      args;
        struct xfs_trans_res    tres;
-       int                     rsvd = (flags & ATTR_ROOT) != 0;
+       int                     rsvd = (args->flags & ATTR_ROOT) != 0;
        int                     error, local;
        unsigned int            total;
 
@@ -356,25 +351,22 @@ xfs_attr_set(
        if (error)
                return error;
 
-       error = xfs_attr_args_init(&args, dp, name, namelen, flags);
-       if (error)
-               return error;
-
-       args.value = value;
-       args.valuelen = valuelen;
+       args->geo = mp->m_attr_geo;
+       args->whichfork = XFS_ATTR_FORK;
+       args->hashval = xfs_da_hashname(args->name, args->namelen);
 
        /*
         * We have no control over the attribute names that userspace passes us
         * to remove, so we have to allow the name lookup prior to attribute
         * removal to fail as well.
         */
-       args.op_flags = XFS_DA_OP_OKNOENT;
+       args->op_flags = XFS_DA_OP_OKNOENT;
 
-       if (value) {
+       if (args->value) {
                XFS_STATS_INC(mp, xs_attr_set);
 
-               args.op_flags |= XFS_DA_OP_ADDNAME;
-               args.total = xfs_attr_calc_size(&args, &local);
+               args->op_flags |= XFS_DA_OP_ADDNAME;
+               args->total = xfs_attr_calc_size(args, &local);
 
                /*
                 * If the inode doesn't have an attribute fork, add one.
@@ -382,8 +374,8 @@ xfs_attr_set(
                 */
                if (XFS_IFORK_Q(dp) == 0) {
                        int sf_size = sizeof(struct xfs_attr_sf_hdr) +
-                               XFS_ATTR_SF_ENTSIZE_BYNAME(args.namelen,
-                                               valuelen);
+                               XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen,
+                                               args->valuelen);
 
                        error = xfs_bmap_add_attrfork(dp, sf_size, rsvd);
                        if (error)
@@ -391,10 +383,11 @@ xfs_attr_set(
                }
 
                tres.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres +
-                                M_RES(mp)->tr_attrsetrt.tr_logres * args.total;
+                                M_RES(mp)->tr_attrsetrt.tr_logres *
+                                       args->total;
                tres.tr_logcount = XFS_ATTRSET_LOG_COUNT;
                tres.tr_logflags = XFS_TRANS_PERM_LOG_RES;
-               total = args.total;
+               total = args->total;
        } else {
                XFS_STATS_INC(mp, xs_attr_remove);
 
@@ -407,29 +400,29 @@ xfs_attr_set(
         * operation if necessary
         */
        error = xfs_trans_alloc(mp, &tres, total, 0,
-                       rsvd ? XFS_TRANS_RESERVE : 0, &args.trans);
+                       rsvd ? XFS_TRANS_RESERVE : 0, &args->trans);
        if (error)
                return error;
 
        xfs_ilock(dp, XFS_ILOCK_EXCL);
-       xfs_trans_ijoin(args.trans, dp, 0);
-       if (value) {
+       xfs_trans_ijoin(args->trans, dp, 0);
+       if (args->value) {
                unsigned int    quota_flags = XFS_QMOPT_RES_REGBLKS;
 
                if (rsvd)
                        quota_flags |= XFS_QMOPT_FORCE_RES;
-               error = xfs_trans_reserve_quota_nblks(args.trans, dp,
-                               args.total, 0, quota_flags);
+               error = xfs_trans_reserve_quota_nblks(args->trans, dp,
+                               args->total, 0, quota_flags);
                if (error)
                        goto out_trans_cancel;
-               error = xfs_attr_set_args(&args);
+               error = xfs_attr_set_args(args);
                if (error)
                        goto out_trans_cancel;
                /* shortform attribute has already been committed */
-               if (!args.trans)
+               if (!args->trans)
                        goto out_unlock;
        } else {
-               error = xfs_attr_remove_args(&args);
+               error = xfs_attr_remove_args(args);
                if (error)
                        goto out_trans_cancel;
        }
@@ -439,23 +432,23 @@ xfs_attr_set(
         * transaction goes to disk before returning to the user.
         */
        if (mp->m_flags & XFS_MOUNT_WSYNC)
-               xfs_trans_set_sync(args.trans);
+               xfs_trans_set_sync(args->trans);
 
-       if ((flags & ATTR_KERNOTIME) == 0)
-               xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
+       if ((args->flags & ATTR_KERNOTIME) == 0)
+               xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG);
 
        /*
         * Commit the last in the sequence of transactions.
         */
-       xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
-       error = xfs_trans_commit(args.trans);
+       xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE);
+       error = xfs_trans_commit(args->trans);
 out_unlock:
        xfs_iunlock(dp, XFS_ILOCK_EXCL);
        return error;
 
 out_trans_cancel:
-       if (args.trans)
-               xfs_trans_cancel(args.trans);
+       if (args->trans)
+               xfs_trans_cancel(args->trans);
        goto out_unlock;
 }
 
index db58a6c7dea5a766e7c25bffdb9affcbb9da20bc..07ca543db831f14fc8c82ea4c21209cffffcf34a 100644 (file)
@@ -149,8 +149,7 @@ int xfs_attr_get_ilocked(struct xfs_inode *ip, struct xfs_da_args *args);
 int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name,
                 size_t namelen, unsigned char **value, int *valuelenp,
                 int flags);
-int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
-                size_t namelen, unsigned char *value, int valuelen, int flags);
+int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_args(struct xfs_da_args *args);
 int xfs_attr_remove_args(struct xfs_da_args *args);
 int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,