Skip to content

Commit a5714b6

Browse files
author
Darrick J. Wong
committed
xfs: turn XFS_ATTR3_RMT_BUF_SPACE into a function
Turn this into a properly typechecked function, and actually use the correct blocksize for extended attributes. The function cannot be static inline because xfsprogs userspace uses it. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Andrey Albershteyn <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent a86f867 commit a5714b6

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

fs/xfs/libxfs/xfs_attr_remote.c

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

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+
4659
/*
4760
* Each contiguous block has a header, so it is not just a simple attribute
4861
* length to FSB conversion.
@@ -53,7 +66,7 @@ xfs_attr3_rmt_blocks(
5366
unsigned int attrlen)
5467
{
5568
if (xfs_has_crc(mp)) {
56-
unsigned int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize);
69+
unsigned int buflen = xfs_attr3_rmt_buf_space(mp);
5770
return (attrlen + buflen - 1) / buflen;
5871
}
5972
return XFS_B_TO_FSB(mp, attrlen);
@@ -293,7 +306,7 @@ xfs_attr_rmtval_copyout(
293306

294307
while (len > 0 && *valuelen > 0) {
295308
unsigned int hdr_size = 0;
296-
unsigned int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize);
309+
unsigned int byte_cnt = xfs_attr3_rmt_buf_space(mp);
297310

298311
byte_cnt = min(*valuelen, byte_cnt);
299312

@@ -342,7 +355,7 @@ xfs_attr_rmtval_copyin(
342355

343356
while (len > 0 && *valuelen > 0) {
344357
unsigned int hdr_size;
345-
unsigned int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize);
358+
unsigned int byte_cnt = xfs_attr3_rmt_buf_space(mp);
346359

347360
byte_cnt = min(*valuelen, byte_cnt);
348361
hdr_size = xfs_attr3_rmt_hdr_set(mp, dst, ino, *offset,

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)

0 commit comments

Comments
 (0)