Skip to content

Commit 36523e9

Browse files
kdavemasoncl
authored andcommitted
btrfs: export global block reserve size as space_info
Introduce a block group type bit for a global reserve and fill the space info for SPACE_INFO ioctl. This should replace the newly added ioctl (01e219e) to get just the 'size' part of the global reserve, while the actual usage can be now visible in the 'btrfs fi df' output during ENOSPC stress. The unpatched userspace tools will show the blockgroup as 'unknown'. CC: Jeff Mahoney <[email protected]> CC: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent 800ee22 commit 36523e9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

fs/btrfs/ctree.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,8 @@ struct btrfs_dev_replace_item {
987987
#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
988988
#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
989989
#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
990-
#define BTRFS_BLOCK_GROUP_RESERVED BTRFS_AVAIL_ALLOC_BIT_SINGLE
990+
#define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
991+
BTRFS_SPACE_INFO_GLOBAL_RSV)
991992

992993
enum btrfs_raid_types {
993994
BTRFS_RAID_RAID10,
@@ -1019,6 +1020,12 @@ enum btrfs_raid_types {
10191020
*/
10201021
#define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
10211022

1023+
/*
1024+
* A fake block group type that is used to communicate global block reserve
1025+
* size to userspace via the SPACE_INFO ioctl.
1026+
*/
1027+
#define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
1028+
10221029
#define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
10231030
BTRFS_AVAIL_ALLOC_BIT_SINGLE)
10241031

fs/btrfs/ioctl.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3562,6 +3562,11 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
35623562
up_read(&info->groups_sem);
35633563
}
35643564

3565+
/*
3566+
* Global block reserve, exported as a space_info
3567+
*/
3568+
slot_count++;
3569+
35653570
/* space_slots == 0 means they are asking for a count */
35663571
if (space_args.space_slots == 0) {
35673572
space_args.total_spaces = slot_count;
@@ -3620,6 +3625,21 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
36203625
up_read(&info->groups_sem);
36213626
}
36223627

3628+
/*
3629+
* Add global block reserve
3630+
*/
3631+
if (slot_count) {
3632+
struct btrfs_block_rsv *block_rsv = &root->fs_info->global_block_rsv;
3633+
3634+
spin_lock(&block_rsv->lock);
3635+
space.total_bytes = block_rsv->size;
3636+
space.used_bytes = block_rsv->size - block_rsv->reserved;
3637+
spin_unlock(&block_rsv->lock);
3638+
space.flags = BTRFS_SPACE_INFO_GLOBAL_RSV;
3639+
memcpy(dest, &space, sizeof(space));
3640+
space_args.total_spaces++;
3641+
}
3642+
36233643
user_dest = (struct btrfs_ioctl_space_info __user *)
36243644
(arg + sizeof(struct btrfs_ioctl_space_args));
36253645

0 commit comments

Comments
 (0)