From: Christoph Hellwig <hch@lst.de>
To: sandeen@sandeen.net
Cc: linux-xfs@vger.kernel.org, Dave Chinner <dchinner@redhat.com>,
Chandan Rajendra <chandanrlinux@gmail.com>,
"Darrick J . Wong" <darrick.wong@oracle.com>
Subject: [PATCH 12/58] xfs: pass an initialized xfs_da_args structure to xfs_attr_set
Date: Thu, 7 May 2020 14:18:05 +0200 [thread overview]
Message-ID: <20200507121851.304002-13-hch@lst.de> (raw)
In-Reply-To: <20200507121851.304002-1-hch@lst.de>
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: Christoph Hellwig <hch@lst.de>
---
db/attrset.c | 106 ++++++++++++++++++++++------------------------
libxfs/xfs_attr.c | 69 ++++++++++++++----------------
libxfs/xfs_attr.h | 3 +-
3 files changed, 83 insertions(+), 95 deletions(-)
diff --git a/db/attrset.c b/db/attrset.c
index c39782b3..21103d8e 100644
--- a/db/attrset.c
+++ b/db/attrset.c
@@ -63,13 +63,12 @@ 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;
- size_t namelen;
+ struct xfs_da_args args = { };
+ char *sp;
+ int c;
if (cur_typ == NULL) {
dbprintf(_("no current type\n"));
@@ -84,23 +83,23 @@ attr_set_f(
switch (c) {
/* namespaces */
case 'r':
- flags |= LIBXFS_ATTR_ROOT;
- flags &= ~LIBXFS_ATTR_SECURE;
+ args.flags |= LIBXFS_ATTR_ROOT;
+ args.flags &= ~LIBXFS_ATTR_SECURE;
break;
case 'u':
- flags &= ~(LIBXFS_ATTR_ROOT | LIBXFS_ATTR_SECURE);
+ args.flags &= ~(LIBXFS_ATTR_ROOT | LIBXFS_ATTR_SECURE);
break;
case 's':
- flags |= LIBXFS_ATTR_SECURE;
- flags &= ~LIBXFS_ATTR_ROOT;
+ args.flags |= LIBXFS_ATTR_SECURE;
+ args.flags &= ~LIBXFS_ATTR_ROOT;
break;
/* modifiers */
case 'C':
- flags |= LIBXFS_ATTR_CREATE;
+ args.flags |= LIBXFS_ATTR_CREATE;
break;
case 'R':
- flags |= LIBXFS_ATTR_REPLACE;
+ args.flags |= LIBXFS_ATTR_REPLACE;
break;
case 'n':
@@ -109,8 +108,9 @@ attr_set_f(
/* value length */
case 'v':
- valuelen = (int)strtol(optarg, &sp, 0);
- if (*sp != '\0' || valuelen < 0 || valuelen > 64*1024) {
+ args.valuelen = strtol(optarg, &sp, 0);
+ if (*sp != '\0' ||
+ args.valuelen < 0 || args.valuelen > 64 * 1024) {
dbprintf(_("bad attr_set valuelen %s\n"), optarg);
return 0;
}
@@ -127,40 +127,38 @@ attr_set_f(
return 0;
}
- name = argv[optind];
- if (!name) {
+ args.name = (const unsigned char *)argv[optind];
+ if (!args.name) {
dbprintf(_("invalid name\n"));
return 0;
}
- namelen = strlen(name);
- if (namelen >= MAXNAMELEN) {
+ args.namelen = strlen(argv[optind]);
+ if (args.namelen >= MAXNAMELEN) {
dbprintf(_("name too long\n"));
return 0;
}
- if (valuelen) {
- value = (char *)memalign(getpagesize(), valuelen);
- if (!value) {
- dbprintf(_("cannot allocate buffer (%d)\n"), valuelen);
+ if (args.valuelen) {
+ args.value = memalign(getpagesize(), args.valuelen);
+ if (!args.value) {
+ dbprintf(_("cannot allocate buffer (%d)\n"),
+ args.valuelen);
goto out;
}
- memset(value, 'v', valuelen);
- } else {
- value = NULL;
+ memset(args.value, 'v', args.valuelen);
}
- if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip,
+ if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &args.dp,
&xfs_default_ifork_ops)) {
dbprintf(_("failed to iget inode %llu\n"),
(unsigned long long)iocur_top->ino);
goto out;
}
- if (libxfs_attr_set(ip, (unsigned char *)name, namelen,
- (unsigned char *)value, valuelen, flags)) {
+ if (libxfs_attr_set(&args)) {
dbprintf(_("failed to set attr %s on inode %llu\n"),
- name, (unsigned long long)iocur_top->ino);
+ args.name, (unsigned long long)iocur_top->ino);
goto out;
}
@@ -169,22 +167,20 @@ attr_set_f(
out:
mp->m_flags &= ~LIBXFS_MOUNT_COMPAT_ATTR;
- if (ip)
- libxfs_irele(ip);
- if (value)
- free(value);
+ if (args.dp)
+ libxfs_irele(args.dp);
+ if (args.value)
+ free(args.value);
return 0;
}
static int
attr_remove_f(
- int argc,
- char **argv)
+ int argc,
+ char **argv)
{
- xfs_inode_t *ip = NULL;
- char *name;
- int c, flags = 0;
- size_t namelen;
+ struct xfs_da_args args = { };
+ int c;
if (cur_typ == NULL) {
dbprintf(_("no current type\n"));
@@ -199,15 +195,15 @@ attr_remove_f(
switch (c) {
/* namespaces */
case 'r':
- flags |= LIBXFS_ATTR_ROOT;
- flags &= ~LIBXFS_ATTR_SECURE;
+ args.flags |= LIBXFS_ATTR_ROOT;
+ args.flags &= ~LIBXFS_ATTR_SECURE;
break;
case 'u':
- flags &= ~(LIBXFS_ATTR_ROOT | LIBXFS_ATTR_SECURE);
+ args.flags &= ~(LIBXFS_ATTR_ROOT | LIBXFS_ATTR_SECURE);
break;
case 's':
- flags |= LIBXFS_ATTR_SECURE;
- flags &= ~LIBXFS_ATTR_ROOT;
+ args.flags |= LIBXFS_ATTR_SECURE;
+ args.flags &= ~LIBXFS_ATTR_ROOT;
break;
case 'n':
@@ -225,29 +221,29 @@ attr_remove_f(
return 0;
}
- name = argv[optind];
- if (!name) {
+ args.name = (const unsigned char *)argv[optind];
+ if (!args.name) {
dbprintf(_("invalid name\n"));
return 0;
}
- namelen = strlen(name);
- if (namelen >= MAXNAMELEN) {
+ args.namelen = strlen(argv[optind]);
+ if (args.namelen >= MAXNAMELEN) {
dbprintf(_("name too long\n"));
return 0;
}
- if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip,
+ if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &args.dp,
&xfs_default_ifork_ops)) {
dbprintf(_("failed to iget inode %llu\n"),
(unsigned long long)iocur_top->ino);
goto out;
}
- if (libxfs_attr_set(ip, (unsigned char *)name, namelen,
- NULL, 0, flags)) {
+ if (libxfs_attr_set(&args)) {
dbprintf(_("failed to remove attr %s from inode %llu\n"),
- name, (unsigned long long)iocur_top->ino);
+ (unsigned char *)args.name,
+ (unsigned long long)iocur_top->ino);
goto out;
}
@@ -256,7 +252,7 @@ attr_remove_f(
out:
mp->m_flags &= ~LIBXFS_MOUNT_COMPAT_ATTR;
- if (ip)
- libxfs_irele(ip);
+ if (args.dp)
+ libxfs_irele(args.dp);
return 0;
}
diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c
index ded952da..e42a8033 100644
--- a/libxfs/xfs_attr.c
+++ b/libxfs/xfs_attr.c
@@ -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;
}
diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h
index db58a6c7..07ca543d 100644
--- a/libxfs/xfs_attr.h
+++ b/libxfs/xfs_attr.h
@@ -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,
--
2.26.2
next prev parent reply other threads:[~2020-05-07 12:19 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-07 12:17 libxfs 5.7 resync Christoph Hellwig
2020-05-07 12:17 ` [PATCH 01/58] xfs: add agf freeblocks verify in xfs_agf_verify Christoph Hellwig
2020-05-07 12:17 ` [PATCH 02/58] xfs: ensure that the inode uid/gid match values match the icdinode ones Christoph Hellwig
2020-05-07 12:17 ` [PATCH 03/58] xfs: remove the icdinode di_uid/di_gid members Christoph Hellwig
2020-05-07 12:17 ` [PATCH 04/58] xfs: remove the kuid/kgid conversion wrappers Christoph Hellwig
2020-05-07 12:17 ` [PATCH 05/58] xfs: fix an undefined behaviour in _da3_path_shift Christoph Hellwig
2020-05-07 12:17 ` [PATCH 06/58] xfs: open code insert range extent split helper Christoph Hellwig
2020-05-07 12:18 ` [PATCH 07/58] xfs: remove the ATTR_INCOMPLETE flag Christoph Hellwig
2020-05-07 12:18 ` [PATCH 08/58] xfs: merge xfs_attr_remove into xfs_attr_set Christoph Hellwig
2020-05-07 12:18 ` [PATCH 09/58] xfs: remove the name == NULL check from xfs_attr_args_init Christoph Hellwig
2020-05-07 12:18 ` [PATCH 10/58] xfs: remove the MAXNAMELEN " Christoph Hellwig
2020-05-07 12:18 ` [PATCH 11/58] xfs: turn xfs_da_args.value into a void pointer Christoph Hellwig
2020-05-07 12:18 ` Christoph Hellwig [this message]
2020-05-07 12:18 ` [PATCH 13/58] xfs: pass an initialized xfs_da_args to xfs_attr_get Christoph Hellwig
2020-05-07 12:18 ` [PATCH 14/58] xfs: remove the xfs_inode argument to xfs_attr_get_ilocked Christoph Hellwig
2020-05-07 12:18 ` [PATCH 15/58] xfs: remove ATTR_KERNOVAL Christoph Hellwig
2020-05-07 12:18 ` [PATCH 16/58] xfs: remove ATTR_ALLOC and XFS_DA_OP_ALLOCVAL Christoph Hellwig
2020-05-07 12:18 ` [PATCH 17/58] xfs: replace ATTR_KERNOTIME with XFS_DA_OP_NOTIME Christoph Hellwig
2020-05-07 12:18 ` [PATCH 18/58] xfs: factor out a xfs_attr_match helper Christoph Hellwig
2020-05-07 12:18 ` [PATCH 19/58] xfs: cleanup struct xfs_attr_list_context Christoph Hellwig
2020-05-07 12:18 ` [PATCH 20/58] xfs: remove the unused ATTR_ENTRY macro Christoph Hellwig
2020-05-07 12:18 ` [PATCH 21/58] xfs: move the legacy xfs_attr_list to xfs_ioctl.c Christoph Hellwig
2020-05-07 12:18 ` [PATCH 22/58] xfs: rename xfs_attr_list_int to xfs_attr_list Christoph Hellwig
2020-05-07 12:18 ` [PATCH 23/58] xfs: clean up the ATTR_REPLACE checks Christoph Hellwig
2020-05-07 12:18 ` [PATCH 24/58] xfs: clean up the attr flag confusion Christoph Hellwig
2020-05-07 12:18 ` [PATCH 25/58] xfs: remove XFS_DA_OP_INCOMPLETE Christoph Hellwig
2020-05-07 12:18 ` [PATCH 26/58] xfs: embedded the attrlist cursor into struct xfs_attr_list_context Christoph Hellwig
2020-05-07 12:18 ` [PATCH 27/58] xfs: remove the agfl_bno member from struct xfs_agfl Christoph Hellwig
2020-05-07 12:18 ` [PATCH 28/58] xfs: remove the xfs_agfl_t typedef Christoph Hellwig
2020-05-07 12:18 ` [PATCH 29/58] xfs: remove XFS_BUF_TO_AGI Christoph Hellwig
2020-05-07 12:18 ` [PATCH 30/58] xfs: remove XFS_BUF_TO_AGF Christoph Hellwig
2020-05-07 12:18 ` [PATCH 31/58] xfs: remove XFS_BUF_TO_SBP Christoph Hellwig
2020-05-07 12:18 ` [PATCH 32/58] xfs: fix xfs_rmap_has_other_keys usage of ECANCELED Christoph Hellwig
2020-05-07 12:18 ` [PATCH 33/58] xfs: add a function to deal with corrupt buffers post-verifiers Christoph Hellwig
2020-05-07 12:18 ` [PATCH 34/58] xfs: fix buffer corruption reporting when xfs_dir3_free_header_check fails Christoph Hellwig
2020-05-07 12:18 ` [PATCH 35/58] xfs: don't ever return a stale pointer from __xfs_dir3_free_read Christoph Hellwig
2020-05-07 12:18 ` [PATCH 36/58] xfs: check owner of dir3 free blocks Christoph Hellwig
2020-05-07 12:18 ` [PATCH 37/58] xfs: check owner of dir3 data blocks Christoph Hellwig
2020-05-07 12:18 ` [PATCH 38/58] xfs: check owner of dir3 blocks Christoph Hellwig
2020-05-07 12:18 ` [PATCH 39/58] xfs: introduce new private btree cursor names Christoph Hellwig
2020-05-07 12:18 ` [PATCH 40/58] xfs: convert btree cursor ag-private member name Christoph Hellwig
2020-05-07 12:18 ` [PATCH 41/58] xfs: convert btree cursor inode-private member names Christoph Hellwig
2020-05-07 12:18 ` [PATCH 42/58] xfs: rename btree cursor private btree member flags Christoph Hellwig
2020-05-07 12:18 ` [PATCH 43/58] xfs: make btree cursor private union anonymous Christoph Hellwig
2020-05-07 12:18 ` [PATCH 44/58] xfs: make the btree cursor union members named structure Christoph Hellwig
2020-05-07 12:18 ` [PATCH 45/58] xfs: make the btree ag cursor private union anonymous Christoph Hellwig
2020-05-07 12:18 ` [PATCH 46/58] xfs: xfs_dabuf_map should return ENOMEM when map allocation fails Christoph Hellwig
2020-05-07 12:18 ` [PATCH 47/58] xfs: fix incorrect test in xfs_alloc_ag_vextent_lastblock Christoph Hellwig
2020-05-07 12:18 ` [PATCH 48/58] xfs: introduce fake roots for ag-rooted btrees Christoph Hellwig
2020-05-07 12:18 ` [PATCH 49/58] xfs: introduce fake roots for inode-rooted btrees Christoph Hellwig
2020-05-07 12:18 ` [PATCH 50/58] xfs: support bulk loading of staged btrees Christoph Hellwig
2020-05-07 12:18 ` [PATCH 51/58] xfs: add support for free space btree staging cursors Christoph Hellwig
2020-05-07 12:18 ` [PATCH 52/58] xfs: add support for inode " Christoph Hellwig
2020-05-07 12:18 ` [PATCH 53/58] xfs: add support for refcount " Christoph Hellwig
2020-05-07 12:18 ` [PATCH 54/58] xfs: add support for rmap " Christoph Hellwig
2020-05-07 12:18 ` [PATCH 55/58] xfs: add a new xfs_sb_version_has_v3inode helper Christoph Hellwig
2020-05-07 12:18 ` [PATCH 56/58] xfs: only check the superblock version for dinode size calculation Christoph Hellwig
2020-05-07 12:18 ` [PATCH 57/58] xfs: remove the di_version field from struct icdinode Christoph Hellwig
2020-05-07 12:18 ` [PATCH 58/58] xfs: validate the realtime geometry in xfs_validate_sb_common Christoph Hellwig
2020-05-07 12:47 ` libxfs 5.7 resync Eric Sandeen
2020-05-07 15:48 ` Darrick J. Wong
2020-05-07 15:54 ` Darrick J. Wong
2020-05-07 15:54 ` Christoph Hellwig
2020-05-07 16:07 ` Darrick J. Wong
2020-05-07 16:11 ` Christoph Hellwig
2020-05-07 16:12 ` Eric Sandeen
2020-05-07 16:14 ` Christoph Hellwig
2020-05-07 16:22 ` Eric Sandeen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200507121851.304002-13-hch@lst.de \
--to=hch@lst.de \
--cc=chandanrlinux@gmail.com \
--cc=darrick.wong@oracle.com \
--cc=dchinner@redhat.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox