Skip to content

Commit c3c4ecb

Browse files
author
Chandan Babu R
committed
xfs: Enable bulkstat ioctl to support 64-bit per-inode extent counters
The following changes are made to enable userspace to obtain 64-bit extent counters, 1. Carve out a new 64-bit field xfs_bulkstat->bs_extents64 from xfs_bulkstat->bs_pad[] to hold 64-bit extent counter. 2. Define the new flag XFS_BULK_IREQ_BULKSTAT for userspace to indicate that it is capable of receiving 64-bit extent counters. Reviewed-by: Dave Chinner <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Suggested-by: Darrick J. Wong <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 5b35d92 commit c3c4ecb

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

fs/xfs/libxfs/xfs_fs.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ struct xfs_bulkstat {
378378
uint32_t bs_extsize_blks; /* extent size hint, blocks */
379379

380380
uint32_t bs_nlink; /* number of links */
381-
uint32_t bs_extents; /* number of extents */
381+
uint32_t bs_extents; /* 32-bit data fork extent counter */
382382
uint32_t bs_aextents; /* attribute number of extents */
383383
uint16_t bs_version; /* structure version */
384384
uint16_t bs_forkoff; /* inode fork offset in bytes */
@@ -387,8 +387,9 @@ struct xfs_bulkstat {
387387
uint16_t bs_checked; /* checked inode metadata */
388388
uint16_t bs_mode; /* type and mode */
389389
uint16_t bs_pad2; /* zeroed */
390+
uint64_t bs_extents64; /* 64-bit data fork extent counter */
390391

391-
uint64_t bs_pad[7]; /* zeroed */
392+
uint64_t bs_pad[6]; /* zeroed */
392393
};
393394

394395
#define XFS_BULKSTAT_VERSION_V1 (1)
@@ -460,17 +461,28 @@ struct xfs_bulk_ireq {
460461
* Only return results from the specified @agno. If @ino is zero, start
461462
* with the first inode of @agno.
462463
*/
463-
#define XFS_BULK_IREQ_AGNO (1 << 0)
464+
#define XFS_BULK_IREQ_AGNO (1U << 0)
464465

465466
/*
466467
* Return bulkstat information for a single inode, where @ino value is a
467468
* special value, not a literal inode number. See the XFS_BULK_IREQ_SPECIAL_*
468469
* values below. Not compatible with XFS_BULK_IREQ_AGNO.
469470
*/
470-
#define XFS_BULK_IREQ_SPECIAL (1 << 1)
471+
#define XFS_BULK_IREQ_SPECIAL (1U << 1)
471472

472-
#define XFS_BULK_IREQ_FLAGS_ALL (XFS_BULK_IREQ_AGNO | \
473-
XFS_BULK_IREQ_SPECIAL)
473+
/*
474+
* Return data fork extent count via xfs_bulkstat->bs_extents64 field and assign
475+
* 0 to xfs_bulkstat->bs_extents when the flag is set. Otherwise, use
476+
* xfs_bulkstat->bs_extents for returning data fork extent count and set
477+
* xfs_bulkstat->bs_extents64 to 0. In the second case, return -EOVERFLOW and
478+
* assign 0 to xfs_bulkstat->bs_extents if data fork extent count is larger than
479+
* XFS_MAX_EXTCNT_DATA_FORK_OLD.
480+
*/
481+
#define XFS_BULK_IREQ_NREXT64 (1U << 2)
482+
483+
#define XFS_BULK_IREQ_FLAGS_ALL (XFS_BULK_IREQ_AGNO | \
484+
XFS_BULK_IREQ_SPECIAL | \
485+
XFS_BULK_IREQ_NREXT64)
474486

475487
/* Operate on the root directory inode. */
476488
#define XFS_BULK_IREQ_SPECIAL_ROOT (1)

fs/xfs/xfs_ioctl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,9 @@ xfs_bulk_ireq_setup(
813813
if (XFS_INO_TO_AGNO(mp, breq->startino) >= mp->m_sb.sb_agcount)
814814
return -ECANCELED;
815815

816+
if (hdr->flags & XFS_BULK_IREQ_NREXT64)
817+
breq->flags |= XFS_IBULK_NREXT64;
818+
816819
return 0;
817820
}
818821

fs/xfs/xfs_itable.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ xfs_bulkstat_one_int(
6464
struct xfs_inode *ip; /* incore inode pointer */
6565
struct inode *inode;
6666
struct xfs_bulkstat *buf = bc->buf;
67+
xfs_extnum_t nextents;
6768
int error = -EINVAL;
6869

6970
if (xfs_internal_inum(mp, ino))
@@ -102,7 +103,13 @@ xfs_bulkstat_one_int(
102103

103104
buf->bs_xflags = xfs_ip2xflags(ip);
104105
buf->bs_extsize_blks = ip->i_extsize;
105-
buf->bs_extents = xfs_ifork_nextents(&ip->i_df);
106+
107+
nextents = xfs_ifork_nextents(&ip->i_df);
108+
if (!(bc->breq->flags & XFS_IBULK_NREXT64))
109+
buf->bs_extents = min(nextents, XFS_MAX_EXTCNT_DATA_FORK_SMALL);
110+
else
111+
buf->bs_extents64 = nextents;
112+
106113
xfs_bulkstat_health(ip, buf);
107114
buf->bs_aextents = xfs_ifork_nextents(ip->i_afp);
108115
buf->bs_forkoff = XFS_IFORK_BOFF(ip);

fs/xfs/xfs_itable.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ struct xfs_ibulk {
1919
/* Only iterate within the same AG as startino */
2020
#define XFS_IBULK_SAME_AG (1U << 0)
2121

22+
/* Fill out the bs_extents64 field if set. */
23+
#define XFS_IBULK_NREXT64 (1U << 1)
24+
2225
/*
2326
* Advance the user buffer pointer by one record of the given size. If the
2427
* buffer is now full, return the appropriate error code.

0 commit comments

Comments
 (0)