Skip to content

Commit 01e219e

Browse files
jeffmahoneymasoncl
authored andcommitted
btrfs: add ioctl to export size of global metadata reservation
btrfs filesystem df output will show the size of the metadata space and how much of it is used, and the user assumes that the difference is all usable space. Since that's not actually the case due to the global metadata reservation, we should provide the full picture to the user. This patch adds an ioctl that exports the size of the global metadata reservation so that btrfs filesystem df can report it. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <clm@fb.com>
1 parent 3b02a68 commit 01e219e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

fs/btrfs/ioctl.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3498,6 +3498,20 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
34983498
return ret;
34993499
}
35003500

3501+
static long btrfs_ioctl_global_rsv(struct btrfs_root *root, void __user *arg)
3502+
{
3503+
struct btrfs_block_rsv *block_rsv = &root->fs_info->global_block_rsv;
3504+
u64 reserved;
3505+
3506+
spin_lock(&block_rsv->lock);
3507+
reserved = block_rsv->reserved;
3508+
spin_unlock(&block_rsv->lock);
3509+
3510+
if (arg && copy_to_user(arg, &reserved, sizeof(reserved)))
3511+
return -EFAULT;
3512+
return 0;
3513+
}
3514+
35013515
/*
35023516
* there are many ways the trans_start and trans_end ioctls can lead
35033517
* to deadlocks. They should only be used by applications that
@@ -4706,6 +4720,8 @@ long btrfs_ioctl(struct file *file, unsigned int
47064720
return btrfs_ioctl_logical_to_ino(root, argp);
47074721
case BTRFS_IOC_SPACE_INFO:
47084722
return btrfs_ioctl_space_info(root, argp);
4723+
case BTRFS_IOC_GLOBAL_RSV:
4724+
return btrfs_ioctl_global_rsv(root, argp);
47094725
case BTRFS_IOC_SYNC: {
47104726
int ret;
47114727

include/uapi/linux/btrfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)
558558
#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64)
559559
#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
560560
struct btrfs_ioctl_space_args)
561+
#define BTRFS_IOC_GLOBAL_RSV _IOR(BTRFS_IOCTL_MAGIC, 20, __u64)
561562
#define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
562563
#define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
563564
#define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \

0 commit comments

Comments
 (0)