Skip to content

Commit a86f867

Browse files
author
Darrick J. Wong
committed
xfs: use unsigned ints for non-negative quantities in xfs_attr_remote.c
In the next few patches we're going to refactor the attr remote code so that we can support headerless remote xattr values for storing merkle tree blocks. For now, let's change the code to use unsigned int to describe quantities of bytes and blocks that cannot be negative. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Andrey Albershteyn <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 21255af commit a86f867

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

fs/xfs/libxfs/xfs_attr_remote.c

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
* Each contiguous block has a header, so it is not just a simple attribute
4848
* length to FSB conversion.
4949
*/
50-
int
50+
unsigned int
5151
xfs_attr3_rmt_blocks(
52-
struct xfs_mount *mp,
53-
int attrlen)
52+
struct xfs_mount *mp,
53+
unsigned int attrlen)
5454
{
5555
if (xfs_has_crc(mp)) {
56-
int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize);
56+
unsigned int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize);
5757
return (attrlen + buflen - 1) / buflen;
5858
}
5959
return XFS_B_TO_FSB(mp, attrlen);
@@ -92,7 +92,6 @@ xfs_attr3_rmt_verify(
9292
struct xfs_mount *mp,
9393
struct xfs_buf *bp,
9494
void *ptr,
95-
int fsbsize,
9695
xfs_daddr_t bno)
9796
{
9897
struct xfs_attr3_rmt_hdr *rmt = ptr;
@@ -103,7 +102,7 @@ xfs_attr3_rmt_verify(
103102
return __this_address;
104103
if (be64_to_cpu(rmt->rm_blkno) != bno)
105104
return __this_address;
106-
if (be32_to_cpu(rmt->rm_bytes) > fsbsize - sizeof(*rmt))
105+
if (be32_to_cpu(rmt->rm_bytes) > mp->m_attr_geo->blksize - sizeof(*rmt))
107106
return __this_address;
108107
if (be32_to_cpu(rmt->rm_offset) +
109108
be32_to_cpu(rmt->rm_bytes) > XFS_XATTR_SIZE_MAX)
@@ -122,9 +121,9 @@ __xfs_attr3_rmt_read_verify(
122121
{
123122
struct xfs_mount *mp = bp->b_mount;
124123
char *ptr;
125-
int len;
124+
unsigned int len;
126125
xfs_daddr_t bno;
127-
int blksize = mp->m_attr_geo->blksize;
126+
unsigned int blksize = mp->m_attr_geo->blksize;
128127

129128
/* no verification of non-crc buffers */
130129
if (!xfs_has_crc(mp))
@@ -141,7 +140,7 @@ __xfs_attr3_rmt_read_verify(
141140
*failaddr = __this_address;
142141
return -EFSBADCRC;
143142
}
144-
*failaddr = xfs_attr3_rmt_verify(mp, bp, ptr, blksize, bno);
143+
*failaddr = xfs_attr3_rmt_verify(mp, bp, ptr, bno);
145144
if (*failaddr)
146145
return -EFSCORRUPTED;
147146
len -= blksize;
@@ -186,7 +185,7 @@ xfs_attr3_rmt_write_verify(
186185
{
187186
struct xfs_mount *mp = bp->b_mount;
188187
xfs_failaddr_t fa;
189-
int blksize = mp->m_attr_geo->blksize;
188+
unsigned int blksize = mp->m_attr_geo->blksize;
190189
char *ptr;
191190
int len;
192191
xfs_daddr_t bno;
@@ -203,7 +202,7 @@ xfs_attr3_rmt_write_verify(
203202
while (len > 0) {
204203
struct xfs_attr3_rmt_hdr *rmt = (struct xfs_attr3_rmt_hdr *)ptr;
205204

206-
fa = xfs_attr3_rmt_verify(mp, bp, ptr, blksize, bno);
205+
fa = xfs_attr3_rmt_verify(mp, bp, ptr, bno);
207206
if (fa) {
208207
xfs_verifier_error(bp, -EFSCORRUPTED, fa);
209208
return;
@@ -281,20 +280,20 @@ xfs_attr_rmtval_copyout(
281280
struct xfs_buf *bp,
282281
struct xfs_inode *dp,
283282
xfs_ino_t owner,
284-
int *offset,
285-
int *valuelen,
283+
unsigned int *offset,
284+
unsigned int *valuelen,
286285
uint8_t **dst)
287286
{
288287
char *src = bp->b_addr;
289288
xfs_daddr_t bno = xfs_buf_daddr(bp);
290-
int len = BBTOB(bp->b_length);
291-
int blksize = mp->m_attr_geo->blksize;
289+
unsigned int len = BBTOB(bp->b_length);
290+
unsigned int blksize = mp->m_attr_geo->blksize;
292291

293292
ASSERT(len >= blksize);
294293

295294
while (len > 0 && *valuelen > 0) {
296-
int hdr_size = 0;
297-
int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize);
295+
unsigned int hdr_size = 0;
296+
unsigned int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize);
298297

299298
byte_cnt = min(*valuelen, byte_cnt);
300299

@@ -330,20 +329,20 @@ xfs_attr_rmtval_copyin(
330329
struct xfs_mount *mp,
331330
struct xfs_buf *bp,
332331
xfs_ino_t ino,
333-
int *offset,
334-
int *valuelen,
332+
unsigned int *offset,
333+
unsigned int *valuelen,
335334
uint8_t **src)
336335
{
337336
char *dst = bp->b_addr;
338337
xfs_daddr_t bno = xfs_buf_daddr(bp);
339-
int len = BBTOB(bp->b_length);
340-
int blksize = mp->m_attr_geo->blksize;
338+
unsigned int len = BBTOB(bp->b_length);
339+
unsigned int blksize = mp->m_attr_geo->blksize;
341340

342341
ASSERT(len >= blksize);
343342

344343
while (len > 0 && *valuelen > 0) {
345-
int hdr_size;
346-
int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize);
344+
unsigned int hdr_size;
345+
unsigned int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize);
347346

348347
byte_cnt = min(*valuelen, byte_cnt);
349348
hdr_size = xfs_attr3_rmt_hdr_set(mp, dst, ino, *offset,
@@ -389,12 +388,12 @@ xfs_attr_rmtval_get(
389388
struct xfs_buf *bp;
390389
xfs_dablk_t lblkno = args->rmtblkno;
391390
uint8_t *dst = args->value;
392-
int valuelen;
391+
unsigned int valuelen;
393392
int nmap;
394393
int error;
395-
int blkcnt = args->rmtblkcnt;
394+
unsigned int blkcnt = args->rmtblkcnt;
396395
int i;
397-
int offset = 0;
396+
unsigned int offset = 0;
398397

399398
trace_xfs_attr_rmtval_get(args);
400399

@@ -452,7 +451,7 @@ xfs_attr_rmt_find_hole(
452451
struct xfs_inode *dp = args->dp;
453452
struct xfs_mount *mp = dp->i_mount;
454453
int error;
455-
int blkcnt;
454+
unsigned int blkcnt;
456455
xfs_fileoff_t lfileoff = 0;
457456

458457
/*
@@ -481,11 +480,11 @@ xfs_attr_rmtval_set_value(
481480
struct xfs_bmbt_irec map;
482481
xfs_dablk_t lblkno;
483482
uint8_t *src = args->value;
484-
int blkcnt;
485-
int valuelen;
483+
unsigned int blkcnt;
484+
unsigned int valuelen;
486485
int nmap;
487486
int error;
488-
int offset = 0;
487+
unsigned int offset = 0;
489488

490489
/*
491490
* Roll through the "value", copying the attribute value to the
@@ -644,7 +643,7 @@ xfs_attr_rmtval_invalidate(
644643
struct xfs_da_args *args)
645644
{
646645
xfs_dablk_t lblkno;
647-
int blkcnt;
646+
unsigned int blkcnt;
648647
int error;
649648

650649
/*

fs/xfs/libxfs/xfs_attr_remote.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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);
1010

1111
int xfs_attr_rmtval_get(struct xfs_da_args *args);
1212
int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,

0 commit comments

Comments
 (0)