Skip to content

Commit 0370f9b

Browse files
author
Chandan Babu R
committed
Merge tag 'xfs-cleanups-6.10_2024-05-02' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.10-mergeF
xfs: last round of cleanups for 6.10 Here are the reviewed cleanups at the head of the fsverity series. Apparently there's other work that could use some of these things, so let's try to get it in for 6.10. Signed-off-by: Darrick J. Wong <[email protected]> Signed-off-by: Chandan Babu R <[email protected]> * tag 'xfs-cleanups-6.10_2024-05-02' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux: xfs: widen flags argument to the xfs_iflags_* helpers xfs: minor cleanups of xfs_attr3_rmt_blocks xfs: create a helper to compute the blockcount of a max sized remote value xfs: turn XFS_ATTR3_RMT_BUF_SPACE into a function xfs: use unsigned ints for non-negative quantities in xfs_attr_remote.c
2 parents 21255af + 1a3f1af commit 0370f9b

File tree

7 files changed

+69
-55
lines changed

7 files changed

+69
-55
lines changed

fs/xfs/libxfs/xfs_attr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ xfs_attr_set(
10361036
break;
10371037
case XFS_ATTRUPDATE_REMOVE:
10381038
XFS_STATS_INC(mp, xs_attr_remove);
1039-
rmt_blks = xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX);
1039+
rmt_blks = xfs_attr3_max_rmt_blocks(mp);
10401040
break;
10411041
}
10421042

fs/xfs/libxfs/xfs_attr_remote.c

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,32 @@
4343
* the logging system and therefore never have a log item.
4444
*/
4545

46-
/*
47-
* Each contiguous block has a header, so it is not just a simple attribute
48-
* length to FSB conversion.
49-
*/
50-
int
46+
/* How many bytes can be stored in a remote value buffer? */
47+
inline unsigned int
48+
xfs_attr3_rmt_buf_space(
49+
struct xfs_mount *mp)
50+
{
51+
unsigned int blocksize = mp->m_attr_geo->blksize;
52+
53+
if (xfs_has_crc(mp))
54+
return blocksize - sizeof(struct xfs_attr3_rmt_hdr);
55+
56+
return blocksize;
57+
}
58+
59+
/* Compute number of fsblocks needed to store a remote attr value */
60+
unsigned int
5161
xfs_attr3_rmt_blocks(
52-
struct xfs_mount *mp,
53-
int attrlen)
62+
struct xfs_mount *mp,
63+
unsigned int attrlen)
5464
{
55-
if (xfs_has_crc(mp)) {
56-
int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize);
57-
return (attrlen + buflen - 1) / buflen;
58-
}
65+
/*
66+
* Each contiguous block has a header, so it is not just a simple
67+
* attribute length to FSB conversion.
68+
*/
69+
if (xfs_has_crc(mp))
70+
return howmany(attrlen, xfs_attr3_rmt_buf_space(mp));
71+
5972
return XFS_B_TO_FSB(mp, attrlen);
6073
}
6174

@@ -92,7 +105,6 @@ xfs_attr3_rmt_verify(
92105
struct xfs_mount *mp,
93106
struct xfs_buf *bp,
94107
void *ptr,
95-
int fsbsize,
96108
xfs_daddr_t bno)
97109
{
98110
struct xfs_attr3_rmt_hdr *rmt = ptr;
@@ -103,7 +115,7 @@ xfs_attr3_rmt_verify(
103115
return __this_address;
104116
if (be64_to_cpu(rmt->rm_blkno) != bno)
105117
return __this_address;
106-
if (be32_to_cpu(rmt->rm_bytes) > fsbsize - sizeof(*rmt))
118+
if (be32_to_cpu(rmt->rm_bytes) > mp->m_attr_geo->blksize - sizeof(*rmt))
107119
return __this_address;
108120
if (be32_to_cpu(rmt->rm_offset) +
109121
be32_to_cpu(rmt->rm_bytes) > XFS_XATTR_SIZE_MAX)
@@ -122,9 +134,9 @@ __xfs_attr3_rmt_read_verify(
122134
{
123135
struct xfs_mount *mp = bp->b_mount;
124136
char *ptr;
125-
int len;
137+
unsigned int len;
126138
xfs_daddr_t bno;
127-
int blksize = mp->m_attr_geo->blksize;
139+
unsigned int blksize = mp->m_attr_geo->blksize;
128140

129141
/* no verification of non-crc buffers */
130142
if (!xfs_has_crc(mp))
@@ -141,7 +153,7 @@ __xfs_attr3_rmt_read_verify(
141153
*failaddr = __this_address;
142154
return -EFSBADCRC;
143155
}
144-
*failaddr = xfs_attr3_rmt_verify(mp, bp, ptr, blksize, bno);
156+
*failaddr = xfs_attr3_rmt_verify(mp, bp, ptr, bno);
145157
if (*failaddr)
146158
return -EFSCORRUPTED;
147159
len -= blksize;
@@ -186,7 +198,7 @@ xfs_attr3_rmt_write_verify(
186198
{
187199
struct xfs_mount *mp = bp->b_mount;
188200
xfs_failaddr_t fa;
189-
int blksize = mp->m_attr_geo->blksize;
201+
unsigned int blksize = mp->m_attr_geo->blksize;
190202
char *ptr;
191203
int len;
192204
xfs_daddr_t bno;
@@ -203,7 +215,7 @@ xfs_attr3_rmt_write_verify(
203215
while (len > 0) {
204216
struct xfs_attr3_rmt_hdr *rmt = (struct xfs_attr3_rmt_hdr *)ptr;
205217

206-
fa = xfs_attr3_rmt_verify(mp, bp, ptr, blksize, bno);
218+
fa = xfs_attr3_rmt_verify(mp, bp, ptr, bno);
207219
if (fa) {
208220
xfs_verifier_error(bp, -EFSCORRUPTED, fa);
209221
return;
@@ -281,20 +293,20 @@ xfs_attr_rmtval_copyout(
281293
struct xfs_buf *bp,
282294
struct xfs_inode *dp,
283295
xfs_ino_t owner,
284-
int *offset,
285-
int *valuelen,
296+
unsigned int *offset,
297+
unsigned int *valuelen,
286298
uint8_t **dst)
287299
{
288300
char *src = bp->b_addr;
289301
xfs_daddr_t bno = xfs_buf_daddr(bp);
290-
int len = BBTOB(bp->b_length);
291-
int blksize = mp->m_attr_geo->blksize;
302+
unsigned int len = BBTOB(bp->b_length);
303+
unsigned int blksize = mp->m_attr_geo->blksize;
292304

293305
ASSERT(len >= blksize);
294306

295307
while (len > 0 && *valuelen > 0) {
296-
int hdr_size = 0;
297-
int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize);
308+
unsigned int hdr_size = 0;
309+
unsigned int byte_cnt = xfs_attr3_rmt_buf_space(mp);
298310

299311
byte_cnt = min(*valuelen, byte_cnt);
300312

@@ -330,20 +342,20 @@ xfs_attr_rmtval_copyin(
330342
struct xfs_mount *mp,
331343
struct xfs_buf *bp,
332344
xfs_ino_t ino,
333-
int *offset,
334-
int *valuelen,
345+
unsigned int *offset,
346+
unsigned int *valuelen,
335347
uint8_t **src)
336348
{
337349
char *dst = bp->b_addr;
338350
xfs_daddr_t bno = xfs_buf_daddr(bp);
339-
int len = BBTOB(bp->b_length);
340-
int blksize = mp->m_attr_geo->blksize;
351+
unsigned int len = BBTOB(bp->b_length);
352+
unsigned int blksize = mp->m_attr_geo->blksize;
341353

342354
ASSERT(len >= blksize);
343355

344356
while (len > 0 && *valuelen > 0) {
345-
int hdr_size;
346-
int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize);
357+
unsigned int hdr_size;
358+
unsigned int byte_cnt = xfs_attr3_rmt_buf_space(mp);
347359

348360
byte_cnt = min(*valuelen, byte_cnt);
349361
hdr_size = xfs_attr3_rmt_hdr_set(mp, dst, ino, *offset,
@@ -389,12 +401,12 @@ xfs_attr_rmtval_get(
389401
struct xfs_buf *bp;
390402
xfs_dablk_t lblkno = args->rmtblkno;
391403
uint8_t *dst = args->value;
392-
int valuelen;
404+
unsigned int valuelen;
393405
int nmap;
394406
int error;
395-
int blkcnt = args->rmtblkcnt;
407+
unsigned int blkcnt = args->rmtblkcnt;
396408
int i;
397-
int offset = 0;
409+
unsigned int offset = 0;
398410

399411
trace_xfs_attr_rmtval_get(args);
400412

@@ -452,7 +464,7 @@ xfs_attr_rmt_find_hole(
452464
struct xfs_inode *dp = args->dp;
453465
struct xfs_mount *mp = dp->i_mount;
454466
int error;
455-
int blkcnt;
467+
unsigned int blkcnt;
456468
xfs_fileoff_t lfileoff = 0;
457469

458470
/*
@@ -481,11 +493,11 @@ xfs_attr_rmtval_set_value(
481493
struct xfs_bmbt_irec map;
482494
xfs_dablk_t lblkno;
483495
uint8_t *src = args->value;
484-
int blkcnt;
485-
int valuelen;
496+
unsigned int blkcnt;
497+
unsigned int valuelen;
486498
int nmap;
487499
int error;
488-
int offset = 0;
500+
unsigned int offset = 0;
489501

490502
/*
491503
* Roll through the "value", copying the attribute value to the
@@ -644,7 +656,7 @@ xfs_attr_rmtval_invalidate(
644656
struct xfs_da_args *args)
645657
{
646658
xfs_dablk_t lblkno;
647-
int blkcnt;
659+
unsigned int blkcnt;
648660
int error;
649661

650662
/*

fs/xfs/libxfs/xfs_attr_remote.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
#ifndef __XFS_ATTR_REMOTE_H__
77
#define __XFS_ATTR_REMOTE_H__
88

9-
int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);
9+
unsigned int xfs_attr3_rmt_blocks(struct xfs_mount *mp, unsigned int attrlen);
10+
11+
/* Number of rmt blocks needed to store the maximally sized attr value */
12+
static inline unsigned int xfs_attr3_max_rmt_blocks(struct xfs_mount *mp)
13+
{
14+
return xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX);
15+
}
1016

1117
int xfs_attr_rmtval_get(struct xfs_da_args *args);
1218
int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,

fs/xfs/libxfs/xfs_da_format.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,9 +880,7 @@ struct xfs_attr3_rmt_hdr {
880880

881881
#define XFS_ATTR3_RMT_CRC_OFF offsetof(struct xfs_attr3_rmt_hdr, rm_crc)
882882

883-
#define XFS_ATTR3_RMT_BUF_SPACE(mp, bufsize) \
884-
((bufsize) - (xfs_has_crc((mp)) ? \
885-
sizeof(struct xfs_attr3_rmt_hdr) : 0))
883+
unsigned int xfs_attr3_rmt_buf_space(struct xfs_mount *mp);
886884

887885
/* Number of bytes in a directory block. */
888886
static inline unsigned int xfs_dir2_dirblock_bytes(struct xfs_sb *sbp)

fs/xfs/scrub/reap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ xrep_bufscan_max_sectors(
223223
int max_fsbs;
224224

225225
/* Remote xattr values are the largest buffers that we support. */
226-
max_fsbs = xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX);
226+
max_fsbs = xfs_attr3_max_rmt_blocks(mp);
227227

228228
return XFS_FSB_TO_BB(mp, min_t(xfs_extlen_t, fsblocks, max_fsbs));
229229
}
@@ -806,7 +806,7 @@ xreap_bmapi_binval(
806806
* of the next hole.
807807
*/
808808
off = imap->br_startoff + imap->br_blockcount;
809-
max_off = off + xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX);
809+
max_off = off + xfs_attr3_max_rmt_blocks(mp);
810810
while (off < max_off) {
811811
struct xfs_bmbt_irec hmap;
812812
int nhmaps = 1;

fs/xfs/xfs_icache.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ xfs_iget_cache_miss(
613613
struct xfs_inode *ip;
614614
int error;
615615
xfs_agino_t agino = XFS_INO_TO_AGINO(mp, ino);
616-
int iflags;
617616

618617
ip = xfs_inode_alloc(mp, ino);
619618
if (!ip)
@@ -693,13 +692,12 @@ xfs_iget_cache_miss(
693692
* memory barrier that ensures this detection works correctly at lookup
694693
* time.
695694
*/
696-
iflags = XFS_INEW;
697695
if (flags & XFS_IGET_DONTCACHE)
698696
d_mark_dontcache(VFS_I(ip));
699697
ip->i_udquot = NULL;
700698
ip->i_gdquot = NULL;
701699
ip->i_pdquot = NULL;
702-
xfs_iflags_set(ip, iflags);
700+
xfs_iflags_set(ip, XFS_INEW);
703701

704702
/* insert the new inode */
705703
spin_lock(&pag->pag_ici_lock);

fs/xfs/xfs_inode.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,35 +207,35 @@ xfs_new_eof(struct xfs_inode *ip, xfs_fsize_t new_size)
207207
* i_flags helper functions
208208
*/
209209
static inline void
210-
__xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
210+
__xfs_iflags_set(xfs_inode_t *ip, unsigned long flags)
211211
{
212212
ip->i_flags |= flags;
213213
}
214214

215215
static inline void
216-
xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
216+
xfs_iflags_set(xfs_inode_t *ip, unsigned long flags)
217217
{
218218
spin_lock(&ip->i_flags_lock);
219219
__xfs_iflags_set(ip, flags);
220220
spin_unlock(&ip->i_flags_lock);
221221
}
222222

223223
static inline void
224-
xfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
224+
xfs_iflags_clear(xfs_inode_t *ip, unsigned long flags)
225225
{
226226
spin_lock(&ip->i_flags_lock);
227227
ip->i_flags &= ~flags;
228228
spin_unlock(&ip->i_flags_lock);
229229
}
230230

231231
static inline int
232-
__xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
232+
__xfs_iflags_test(xfs_inode_t *ip, unsigned long flags)
233233
{
234234
return (ip->i_flags & flags);
235235
}
236236

237237
static inline int
238-
xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
238+
xfs_iflags_test(xfs_inode_t *ip, unsigned long flags)
239239
{
240240
int ret;
241241
spin_lock(&ip->i_flags_lock);
@@ -245,7 +245,7 @@ xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
245245
}
246246

247247
static inline int
248-
xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
248+
xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned long flags)
249249
{
250250
int ret;
251251

@@ -258,7 +258,7 @@ xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
258258
}
259259

260260
static inline int
261-
xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned short flags)
261+
xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned long flags)
262262
{
263263
int ret;
264264

0 commit comments

Comments
 (0)