On 10/30/2010 09:39 PM, Hugo Mills wrote:
This patch introduces a basic form of progress monitoring for balance
operations, by counting the number of block groups remaining. The
information is exposed to userspace by an ioctl.
IMO, tracking the information of blocks which are balancing also makes sense.
For example, the block information's blocknr.
It can help us monitor better.
Signed-off-by: Hugo Mills h...@carfax.org.uk
---
This patch replaces the one previously posted, correcting a minor error.
fs/btrfs/ctree.h |9
fs/btrfs/disk-io.c |2 +
fs/btrfs/ioctl.c | 34
fs/btrfs/ioctl.h |7 ++
fs/btrfs/volumes.c | 55
+++--
5 files changed, 105 insertions(+), 2 deletions(-)
Index: linux-mainline/fs/btrfs/ctree.h
===
--- linux-mainline.orig/fs/btrfs/ctree.h 2010-10-26 18:03:38.0
+0100
+++ linux-mainline/fs/btrfs/ctree.h 2010-10-30 14:35:25.306450922 +0100
@@ -803,6 +803,11 @@
struct list_head cluster_list;
};
+struct btrfs_balance_info {
+ u64 expected;
+ u64 completed;
+};
+
struct reloc_control;
struct btrfs_device;
struct btrfs_fs_devices;
@@ -1010,6 +1015,10 @@
unsigned metadata_ratio;
void *bdev_holder;
+
+ /* Keep track of any rebalance operations on this FS */
+ spinlock_t balance_info_lock;
+ struct btrfs_balance_info *balance_info;
};
/*
Index: linux-mainline/fs/btrfs/ioctl.c
===
--- linux-mainline.orig/fs/btrfs/ioctl.c 2010-10-26 18:03:38.0
+0100
+++ linux-mainline/fs/btrfs/ioctl.c 2010-10-30 14:35:25.396447198 +0100
@@ -1984,6 +1984,38 @@
return 0;
}
+/*
+ * Return the current status of any balance operation
+ */
+long btrfs_ioctl_balance_progress(
+ struct btrfs_fs_info *fs_info,
+ struct btrfs_ioctl_balance_progress __user *user_dest)
+{
+ int ret = 0;
+ struct btrfs_ioctl_balance_progress dest;
+
+ spin_lock(fs_info-balance_info_lock);
+ if (!fs_info-balance_info) {
+ ret = -EINVAL;
+ goto error;
+ }
+
+ dest.expected = fs_info-balance_info-expected;
+ dest.completed = fs_info-balance_info-completed;
+
+ spin_unlock(fs_info-balance_info_lock);
+
+ if (copy_to_user(user_dest, dest,
+ sizeof(struct btrfs_ioctl_balance_progress)))
+ return -EFAULT;
+
+ return 0;
+
+error:
+ spin_unlock(fs_info-balance_info_lock);
+ return ret;
+}
+
long btrfs_ioctl(struct file *file, unsigned int
cmd, unsigned long arg)
{
@@ -2017,6 +2049,8 @@
return btrfs_ioctl_rm_dev(root, argp);
case BTRFS_IOC_BALANCE:
return btrfs_balance(root-fs_info-dev_root);
+ case BTRFS_IOC_BALANCE_PROGRESS:
+ return btrfs_ioctl_balance_progress(root-fs_info, argp);
case BTRFS_IOC_CLONE:
return btrfs_ioctl_clone(file, arg, 0, 0, 0);
case BTRFS_IOC_CLONE_RANGE:
Index: linux-mainline/fs/btrfs/ioctl.h
===
--- linux-mainline.orig/fs/btrfs/ioctl.h 2010-10-26 18:03:38.0
+0100
+++ linux-mainline/fs/btrfs/ioctl.h 2010-10-30 14:35:25.316450509 +0100
@@ -138,6 +138,11 @@
struct btrfs_ioctl_space_info spaces[0];
};
+struct btrfs_ioctl_balance_progress {
+ __u64 expected;
+ __u64 completed;
+};
+
#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
struct btrfs_ioctl_vol_args)
#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
@@ -178,4 +183,6 @@
#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)
#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
struct btrfs_ioctl_space_args)
+#define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 21, \
+ struct btrfs_ioctl_balance_progress)
#endif
Index: linux-mainline/fs/btrfs/volumes.c
===
--- linux-mainline.orig/fs/btrfs/volumes.c2010-10-26 18:03:38.0
+0100
+++ linux-mainline/fs/btrfs/volumes.c 2010-10-30 14:35:25.326450096 +0100
@@ -1902,6 +1902,7 @@
struct btrfs_root *chunk_root = dev_root-fs_info-chunk_root;
struct btrfs_trans_handle *trans;
struct btrfs_key found_key;
+ struct btrfs_balance_info *bal_info;
if (dev_root-fs_info-sb-s_flags MS_RDONLY)
return -EROFS;
@@ -1909,6 +1910,18 @@
mutex_lock(dev_root-fs_info-volume_mutex);
dev_root = dev_root-fs_info-dev_root;
+ dev_root-fs_info-balance_info = kmalloc(
+ sizeof(struct btrfs_balance_info),
+