Skip to content

Commit 1321890

Browse files
author
Chandan Babu R
committed
Merge tag 'shrink-dirattr-args-6.10_2024-04-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.10-mergeC
xfs: shrink struct xfs_da_args Let's clean out some unused flags and fields from struct xfs_da_args. Signed-off-by: Darrick J. Wong <[email protected]> Signed-off-by: Chandan Babu R <[email protected]> * tag 'shrink-dirattr-args-6.10_2024-04-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux: xfs: rearrange xfs_da_args a bit to use less space xfs: make attr removal an explicit operation xfs: remove xfs_da_args.attr_flags xfs: remove XFS_DA_OP_NOTIME xfs: remove XFS_DA_OP_REMOVE
2 parents 6a94b1a + cda6031 commit 1321890

File tree

11 files changed

+80
-65
lines changed

11 files changed

+80
-65
lines changed

fs/xfs/libxfs/xfs_attr.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ xfs_attr_try_sf_addname(
365365
* Commit the shortform mods, and we're done.
366366
* NOTE: this is also the error path (EEXIST, etc).
367367
*/
368-
if (!error && !(args->op_flags & XFS_DA_OP_NOTIME))
368+
if (!error)
369369
xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG);
370370

371371
if (xfs_has_wsync(dp->i_mount))
@@ -916,13 +916,10 @@ xfs_attr_defer_add(
916916
trace_xfs_attr_defer_add(new->xattri_dela_state, args->dp);
917917
}
918918

919-
/*
920-
* Note: If args->value is NULL the attribute will be removed, just like the
921-
* Linux ->setattr API.
922-
*/
923919
int
924920
xfs_attr_set(
925-
struct xfs_da_args *args)
921+
struct xfs_da_args *args,
922+
enum xfs_attr_update op)
926923
{
927924
struct xfs_inode *dp = args->dp;
928925
struct xfs_mount *mp = dp->i_mount;
@@ -954,7 +951,10 @@ xfs_attr_set(
954951
args->op_flags = XFS_DA_OP_OKNOENT |
955952
(args->op_flags & XFS_DA_OP_LOGGED);
956953

957-
if (args->value) {
954+
switch (op) {
955+
case XFS_ATTRUPDATE_UPSERT:
956+
case XFS_ATTRUPDATE_CREATE:
957+
case XFS_ATTRUPDATE_REPLACE:
958958
XFS_STATS_INC(mp, xs_attr_set);
959959
args->total = xfs_attr_calc_size(args, &local);
960960

@@ -974,9 +974,11 @@ xfs_attr_set(
974974

975975
if (!local)
976976
rmt_blks = xfs_attr3_rmt_blocks(mp, args->valuelen);
977-
} else {
977+
break;
978+
case XFS_ATTRUPDATE_REMOVE:
978979
XFS_STATS_INC(mp, xs_attr_remove);
979980
rmt_blks = xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX);
981+
break;
980982
}
981983

982984
/*
@@ -988,7 +990,7 @@ xfs_attr_set(
988990
if (error)
989991
return error;
990992

991-
if (args->value || xfs_inode_hasattr(dp)) {
993+
if (op != XFS_ATTRUPDATE_REMOVE || xfs_inode_hasattr(dp)) {
992994
error = xfs_iext_count_may_overflow(dp, XFS_ATTR_FORK,
993995
XFS_IEXT_ATTR_MANIP_CNT(rmt_blks));
994996
if (error == -EFBIG)
@@ -1001,24 +1003,24 @@ xfs_attr_set(
10011003
error = xfs_attr_lookup(args);
10021004
switch (error) {
10031005
case -EEXIST:
1004-
if (!args->value) {
1006+
if (op == XFS_ATTRUPDATE_REMOVE) {
10051007
/* if no value, we are performing a remove operation */
10061008
xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_REMOVE);
10071009
break;
10081010
}
10091011

10101012
/* Pure create fails if the attr already exists */
1011-
if (args->attr_flags & XATTR_CREATE)
1013+
if (op == XFS_ATTRUPDATE_CREATE)
10121014
goto out_trans_cancel;
10131015
xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_REPLACE);
10141016
break;
10151017
case -ENOATTR:
10161018
/* Can't remove what isn't there. */
1017-
if (!args->value)
1019+
if (op == XFS_ATTRUPDATE_REMOVE)
10181020
goto out_trans_cancel;
10191021

10201022
/* Pure replace fails if no existing attr to replace. */
1021-
if (args->attr_flags & XATTR_REPLACE)
1023+
if (op == XFS_ATTRUPDATE_REPLACE)
10221024
goto out_trans_cancel;
10231025
xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_SET);
10241026
break;
@@ -1033,8 +1035,7 @@ xfs_attr_set(
10331035
if (xfs_has_wsync(mp))
10341036
xfs_trans_set_sync(args->trans);
10351037

1036-
if (!(args->op_flags & XFS_DA_OP_NOTIME))
1037-
xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG);
1038+
xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG);
10381039

10391040
/*
10401041
* Commit the last in the sequence of transactions.

fs/xfs/libxfs/xfs_attr.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,15 @@ int xfs_inode_hasattr(struct xfs_inode *ip);
544544
bool xfs_attr_is_leaf(struct xfs_inode *ip);
545545
int xfs_attr_get_ilocked(struct xfs_da_args *args);
546546
int xfs_attr_get(struct xfs_da_args *args);
547-
int xfs_attr_set(struct xfs_da_args *args);
547+
548+
enum xfs_attr_update {
549+
XFS_ATTRUPDATE_REMOVE, /* remove attr */
550+
XFS_ATTRUPDATE_UPSERT, /* set value, replace any existing attr */
551+
XFS_ATTRUPDATE_CREATE, /* set value, fail if attr already exists */
552+
XFS_ATTRUPDATE_REPLACE, /* set value, fail if attr does not exist */
553+
};
554+
555+
int xfs_attr_set(struct xfs_da_args *args, enum xfs_attr_update op);
548556
int xfs_attr_set_iter(struct xfs_attr_intent *attr);
549557
int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
550558
bool xfs_attr_namecheck(const void *name, size_t length);
@@ -590,7 +598,6 @@ xfs_attr_init_add_state(struct xfs_da_args *args)
590598
static inline enum xfs_delattr_state
591599
xfs_attr_init_remove_state(struct xfs_da_args *args)
592600
{
593-
args->op_flags |= XFS_DA_OP_REMOVE;
594601
if (xfs_attr_is_shortform(args->dp))
595602
return XFS_DAS_SF_REMOVE;
596603
if (xfs_attr_is_leaf(args->dp))

fs/xfs/libxfs/xfs_da_btree.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,20 @@ enum xfs_dacmp {
5454
*/
5555
typedef struct xfs_da_args {
5656
struct xfs_da_geometry *geo; /* da block geometry */
57-
const uint8_t *name; /* string (maybe not NULL terminated) */
58-
int namelen; /* length of string (maybe no NULL) */
59-
uint8_t filetype; /* filetype of inode for directories */
57+
const uint8_t *name; /* string (maybe not NULL terminated) */
6058
void *value; /* set of bytes (maybe contain NULLs) */
61-
int valuelen; /* length of value */
62-
unsigned int attr_filter; /* XFS_ATTR_{ROOT,SECURE,INCOMPLETE} */
63-
unsigned int attr_flags; /* XATTR_{CREATE,REPLACE} */
64-
xfs_dahash_t hashval; /* hash value of name */
65-
xfs_ino_t inumber; /* input/output inode number */
6659
struct xfs_inode *dp; /* directory inode to manipulate */
6760
struct xfs_trans *trans; /* current trans (changes over time) */
61+
62+
xfs_ino_t inumber; /* input/output inode number */
63+
xfs_ino_t owner; /* inode that owns the dir/attr data */
64+
65+
int valuelen; /* length of value */
66+
uint8_t filetype; /* filetype of inode for directories */
67+
uint8_t op_flags; /* operation flags */
68+
uint8_t attr_filter; /* XFS_ATTR_{ROOT,SECURE,INCOMPLETE} */
69+
short namelen; /* length of string (maybe no NULL) */
70+
xfs_dahash_t hashval; /* hash value of name */
6871
xfs_extlen_t total; /* total blocks needed, for 1st bmap */
6972
int whichfork; /* data or attribute fork */
7073
xfs_dablk_t blkno; /* blkno of attr leaf of interest */
@@ -77,9 +80,7 @@ typedef struct xfs_da_args {
7780
xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */
7881
int rmtblkcnt2; /* remote attr value block count */
7982
int rmtvaluelen2; /* remote attr value length in bytes */
80-
uint32_t op_flags; /* operation flags */
8183
enum xfs_dacmp cmpresult; /* name compare result for lookups */
82-
xfs_ino_t owner; /* inode that owns the dir/attr data */
8384
} xfs_da_args_t;
8485

8586
/*
@@ -90,19 +91,15 @@ typedef struct xfs_da_args {
9091
#define XFS_DA_OP_ADDNAME (1u << 2) /* this is an add operation */
9192
#define XFS_DA_OP_OKNOENT (1u << 3) /* lookup op, ENOENT ok, else die */
9293
#define XFS_DA_OP_CILOOKUP (1u << 4) /* lookup returns CI name if found */
93-
#define XFS_DA_OP_NOTIME (1u << 5) /* don't update inode timestamps */
94-
#define XFS_DA_OP_REMOVE (1u << 6) /* this is a remove operation */
95-
#define XFS_DA_OP_RECOVERY (1u << 7) /* Log recovery operation */
96-
#define XFS_DA_OP_LOGGED (1u << 8) /* Use intent items to track op */
94+
#define XFS_DA_OP_RECOVERY (1u << 5) /* Log recovery operation */
95+
#define XFS_DA_OP_LOGGED (1u << 6) /* Use intent items to track op */
9796

9897
#define XFS_DA_OP_FLAGS \
9998
{ XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \
10099
{ XFS_DA_OP_REPLACE, "REPLACE" }, \
101100
{ XFS_DA_OP_ADDNAME, "ADDNAME" }, \
102101
{ XFS_DA_OP_OKNOENT, "OKNOENT" }, \
103102
{ XFS_DA_OP_CILOOKUP, "CILOOKUP" }, \
104-
{ XFS_DA_OP_NOTIME, "NOTIME" }, \
105-
{ XFS_DA_OP_REMOVE, "REMOVE" }, \
106103
{ XFS_DA_OP_RECOVERY, "RECOVERY" }, \
107104
{ XFS_DA_OP_LOGGED, "LOGGED" }
108105

fs/xfs/scrub/attr.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ xchk_xattr_actor(
173173
void *priv)
174174
{
175175
struct xfs_da_args args = {
176-
.op_flags = XFS_DA_OP_NOTIME,
177176
.attr_filter = attr_flags & XFS_ATTR_NSP_ONDISK_MASK,
178177
.geo = sc->mp->m_attr_geo,
179178
.whichfork = XFS_ATTR_FORK,

fs/xfs/scrub/attr_repair.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ xrep_xattr_insert_rec(
557557
struct xfs_da_args args = {
558558
.dp = rx->sc->tempip,
559559
.attr_filter = key->flags,
560-
.attr_flags = XATTR_CREATE,
561560
.namelen = key->namelen,
562561
.valuelen = key->valuelen,
563562
.owner = rx->sc->ip->i_ino,
@@ -605,7 +604,7 @@ xrep_xattr_insert_rec(
605604
* xfs_attr_set creates and commits its own transaction. If the attr
606605
* already exists, we'll just drop it during the rebuild.
607606
*/
608-
error = xfs_attr_set(&args);
607+
error = xfs_attr_set(&args, XFS_ATTRUPDATE_CREATE);
609608
if (error == -EEXIST)
610609
error = 0;
611610

fs/xfs/xfs_acl.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,17 @@ __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
201201
if (!args.value)
202202
return -ENOMEM;
203203
xfs_acl_to_disk(args.value, acl);
204+
error = xfs_attr_change(&args, XFS_ATTRUPDATE_UPSERT);
205+
kvfree(args.value);
206+
} else {
207+
error = xfs_attr_change(&args, XFS_ATTRUPDATE_REMOVE);
208+
/*
209+
* If the attribute didn't exist to start with that's fine.
210+
*/
211+
if (error == -ENOATTR)
212+
error = 0;
204213
}
205214

206-
error = xfs_attr_change(&args);
207-
kvfree(args.value);
208-
209-
/*
210-
* If the attribute didn't exist to start with that's fine.
211-
*/
212-
if (!acl && error == -ENOATTR)
213-
error = 0;
214215
if (!error)
215216
set_cached_acl(inode, type, acl);
216217
return error;

fs/xfs/xfs_ioctl.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,18 @@ xfs_attr_filter(
361361
return 0;
362362
}
363363

364-
static unsigned int
365-
xfs_attr_flags(
366-
u32 ioc_flags)
364+
static inline enum xfs_attr_update
365+
xfs_xattr_flags(
366+
u32 ioc_flags,
367+
void *value)
367368
{
369+
if (!value)
370+
return XFS_ATTRUPDATE_REMOVE;
368371
if (ioc_flags & XFS_IOC_ATTR_CREATE)
369-
return XATTR_CREATE;
372+
return XFS_ATTRUPDATE_CREATE;
370373
if (ioc_flags & XFS_IOC_ATTR_REPLACE)
371-
return XATTR_REPLACE;
372-
return 0;
374+
return XFS_ATTRUPDATE_REPLACE;
375+
return XFS_ATTRUPDATE_UPSERT;
373376
}
374377

375378
int
@@ -476,7 +479,6 @@ xfs_attrmulti_attr_get(
476479
struct xfs_da_args args = {
477480
.dp = XFS_I(inode),
478481
.attr_filter = xfs_attr_filter(flags),
479-
.attr_flags = xfs_attr_flags(flags),
480482
.name = name,
481483
.namelen = strlen(name),
482484
.valuelen = *len,
@@ -510,7 +512,6 @@ xfs_attrmulti_attr_set(
510512
struct xfs_da_args args = {
511513
.dp = XFS_I(inode),
512514
.attr_filter = xfs_attr_filter(flags),
513-
.attr_flags = xfs_attr_flags(flags),
514515
.name = name,
515516
.namelen = strlen(name),
516517
};
@@ -528,7 +529,7 @@ xfs_attrmulti_attr_set(
528529
args.valuelen = len;
529530
}
530531

531-
error = xfs_attr_change(&args);
532+
error = xfs_attr_change(&args, xfs_xattr_flags(flags, args.value));
532533
if (!error && (flags & XFS_IOC_ATTR_ROOT))
533534
xfs_forget_acl(inode, name);
534535
kfree(args.value);

fs/xfs/xfs_iops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ xfs_initxattrs(
6363
.value = xattr->value,
6464
.valuelen = xattr->value_len,
6565
};
66-
error = xfs_attr_change(&args);
66+
error = xfs_attr_change(&args, XFS_ATTRUPDATE_UPSERT);
6767
if (error < 0)
6868
break;
6969
}

fs/xfs/xfs_trace.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,6 @@ DECLARE_EVENT_CLASS(xfs_attr_class,
19991999
__field(int, valuelen)
20002000
__field(xfs_dahash_t, hashval)
20012001
__field(unsigned int, attr_filter)
2002-
__field(unsigned int, attr_flags)
20032002
__field(uint32_t, op_flags)
20042003
),
20052004
TP_fast_assign(
@@ -2011,11 +2010,10 @@ DECLARE_EVENT_CLASS(xfs_attr_class,
20112010
__entry->valuelen = args->valuelen;
20122011
__entry->hashval = args->hashval;
20132012
__entry->attr_filter = args->attr_filter;
2014-
__entry->attr_flags = args->attr_flags;
20152013
__entry->op_flags = args->op_flags;
20162014
),
20172015
TP_printk("dev %d:%d ino 0x%llx name %.*s namelen %d valuelen %d "
2018-
"hashval 0x%x filter %s flags %s op_flags %s",
2016+
"hashval 0x%x filter %s op_flags %s",
20192017
MAJOR(__entry->dev), MINOR(__entry->dev),
20202018
__entry->ino,
20212019
__entry->namelen,
@@ -2025,9 +2023,6 @@ DECLARE_EVENT_CLASS(xfs_attr_class,
20252023
__entry->hashval,
20262024
__print_flags(__entry->attr_filter, "|",
20272025
XFS_ATTR_FILTER_FLAGS),
2028-
__print_flags(__entry->attr_flags, "|",
2029-
{ XATTR_CREATE, "CREATE" },
2030-
{ XATTR_REPLACE, "REPLACE" }),
20312026
__print_flags(__entry->op_flags, "|", XFS_DA_OP_FLAGS))
20322027
)
20332028

fs/xfs/xfs_xattr.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ xfs_attr_want_log_assist(
7373
*/
7474
int
7575
xfs_attr_change(
76-
struct xfs_da_args *args)
76+
struct xfs_da_args *args,
77+
enum xfs_attr_update op)
7778
{
7879
struct xfs_mount *mp = args->dp->i_mount;
7980
int error;
@@ -88,7 +89,7 @@ xfs_attr_change(
8889
args->op_flags |= XFS_DA_OP_LOGGED;
8990
}
9091

91-
return xfs_attr_set(args);
92+
return xfs_attr_set(args, op);
9293
}
9394

9495

@@ -115,6 +116,20 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,
115116
return args.valuelen;
116117
}
117118

119+
static inline enum xfs_attr_update
120+
xfs_xattr_flags_to_op(
121+
int flags,
122+
const void *value)
123+
{
124+
if (!value)
125+
return XFS_ATTRUPDATE_REMOVE;
126+
if (flags & XATTR_CREATE)
127+
return XFS_ATTRUPDATE_CREATE;
128+
if (flags & XATTR_REPLACE)
129+
return XFS_ATTRUPDATE_REPLACE;
130+
return XFS_ATTRUPDATE_UPSERT;
131+
}
132+
118133
static int
119134
xfs_xattr_set(const struct xattr_handler *handler,
120135
struct mnt_idmap *idmap, struct dentry *unused,
@@ -124,15 +139,14 @@ xfs_xattr_set(const struct xattr_handler *handler,
124139
struct xfs_da_args args = {
125140
.dp = XFS_I(inode),
126141
.attr_filter = handler->flags,
127-
.attr_flags = flags,
128142
.name = name,
129143
.namelen = strlen(name),
130144
.value = (void *)value,
131145
.valuelen = size,
132146
};
133147
int error;
134148

135-
error = xfs_attr_change(&args);
149+
error = xfs_attr_change(&args, xfs_xattr_flags_to_op(flags, value));
136150
if (!error && (handler->flags & XFS_ATTR_ROOT))
137151
xfs_forget_acl(inode, name);
138152
return error;

0 commit comments

Comments
 (0)