===================================================================
@@ -95,6 +95,10 @@
"filesystem balance", "<path>\n"
"Balance the chunks across the device."
},
+ { do_balance_progress, 1,
+ "balance progress", "<path>\n"
+ "Show progress of the balance operation running on <path>."
+ },
{ do_scan,
999, "device scan", "[<device> [<device>..]\n"
"Scan all device for or the passed device for a btrfs\n"
===================================================================
@@ -808,6 +808,46 @@
}
return 0;
}
+
+int do_balance_progress(int argc, char **argv)
+{
+ char *path = argv[1];
+ int fdmnt;
+ int ret = 0;
+ int err = 0;
+ struct btrfs_ioctl_balance_progress bal;
+
+ fdmnt = open_file_or_dir(path);
+ if(fdmnt < 0) {
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return 12;
+ }
+
+ ret = ioctl(fdmnt, BTRFS_IOC_BALANCE_PROGRESS, &bal);
+ if(!ret)
+ err = errno;
+ close(fdmnt);
+
+ switch(err) {
+ case 0:
+ break;
+ case -EINVAL:
+ fprintf(stderr, "No balance operation running on '%s'.\n",
+ path);
+ return 20;
+ default:
+ fprintf(stderr, "ERROR: ioctl returned error %d.", err);
+ return 21;
+ }
+
+ printf("%llu/%llu block groups moved, %0.2f%% complete.\n",
+ bal.completed,
+ bal.expected,
+ (float)bal.completed/bal.expected*100.0);
+
+ return 0;
+}
+
int do_remove_volume(int nargs, char **args)
{
===================================================================
@@ -23,6 +23,7 @@
int do_show_filesystem(int nargs, char **argv);
int do_add_volume(int nargs, char **args);
int do_balance(int nargs, char **argv);
+int do_balance_progress(int nargs, char **argv);
int do_remove_volume(int nargs, char **args);
int do_scan(int nargs, char **argv);
int do_resize(int nargs, char **argv);
===================================================================
@@ -132,6 +132,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, \
@@ -169,4 +174,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