Balance management, userspace side
v2 cover Balance management, userspace side
These three patches complement the previous two kernel-side
patches. The first implements a way of displaying the current progress of any running balance process. The second adds a "monitor" mode, which watches the progress and makes an estimate of the completion time. The third and final patch allows a running balance to be cancelled.
Hugo Mills (3):
Balance progress monitoring.
Add --monitor option to btrfs balance progress. User-space tool for cancelling balance operations.
btrfs.c | 12 ++++ btrfs_cmds.c | 187 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 2 + ioctl.h | 8 +++ man/btrfs.8.in | 7 ++ 5 files changed, 216 insertions(+), 0 deletions(-)
PATCH v2 1/3 Balance progress monitoring.
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.
We also add "btrfs balance start" as an alias for "btrfs filesystem balance", so that all balance-related functions are available under one prefix.
--- btrfs.c | 8 +++++++ btrfs_cmds.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ioctl.h | 7 ++++++ man/btrfs.8.in | 7 ++++++ 5 files changed, 83 insertions(+), 0 deletions(-)
btrfs.c +8 -0
@@ -95,6 +95,14 @@ static struct Command commands[] = {"filesystem balance" ,"<path>\n" "Balance the chunks across the device." }, + { do_balance, 1, +"balance start" ,"<path>\n" +"Synonym for \"btrfs filesystem balance\"." + }, + { do_balance_progress, -1, +"balance progress" ,"[-m|--monitor] <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"
btrfs_cmds.c +60 -0
72 lines not on this page · raw message
btrfs_cmds.h +1 -0
@@ -23,6 +23,7 @@ int do_defrag(int argc, char **argv);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);
ioctl.h +7 -0
@@ -132,6 +132,11 @@ struct btrfs_ioctl_space_args {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 @@ struct btrfs_ioctl_space_args {#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, 25, \ + struct btrfs_ioctl_balance_progress)#endif
man/btrfs.8.in +7 -0
@@ -21,6 +21,8 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBfilesystem resize\fP\fI [+/\-]<size>[gkm]|max <filesystem>\fP .PP +\fBbtrfs\fP \fBbalance progress\fP \fI<path>\fP +.PP \fBbtrfs\fP \fBdevice scan\fP\fI [<device> [<device>..]]\fP .PP \fBbtrfs\fP \fBdevice show\fP\fI <dev>|<label> [<dev>|<label>...]\fP
@@ -148,6 +150,11 @@ Balance the chunks of the filesystem identified by \fI<path>\fR across the devices. .TP +\fBbalance progress\fP \fI<path>\fP +Report progress on the currently-running balance operation on +\fI<path>\fP. +.TP + \fBdevice add\fR\fI <dev> [<dev>..] <path>\fR Add device(s) to the filesystem identified by \fI<path>\fR. .TP
Signature · 1 line
1.7.1
PATCH v2 2/3 Add --monitor option to btrfs balance progress.
In reply to Hugo MillsFor the impatient, this patch introduces the pot-watching --monitor option, which checks the balance progress at regular intervals, and updates a single status line with the current progress and an estimated completion time.
--- btrfs_cmds.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++---- man/btrfs.8.in | 4 +- 2 files changed, 96 insertions(+), 10 deletions(-)
btrfs_cmds.c +94 -8
@@ -797,22 +797,108 @@ int get_balance_progress(char *path, struct btrfs_ioctl_balance_progress *bal)return err; } +const struct option progress_options[] = { + {"monitor" ,0 ,NULL ,'m' }, + {NULL ,0 ,NULL ,0 } +}; +int do_balance_progress (int argc,char **argv) {char *path;int ret =0 ;int err =0 ;struct btrfs_ioctl_balance_progress bal; +__u64 last_completed =-1 ; +__u64 initial_completed =-1 ; +struct timeval now; +struct timeval started; +int monitor =0 ; + + optind =1 ; +while (1 ) { +int c =getopt_long (argc, argv,"m" , progress_options,NULL ); +if (c <0 ) +break ; +switch (c) { +case 'm' : + monitor =1 ; +break ; +default : +fprintf (stderr,"Invalid arguments for balance progress\n" ); +free (argv); +return 1 ; + } + } + +if (optind >= argc) { +fprintf (stderr,"No filesystem path given for progress\n" ); +return 1 ; + } - path = argv[1 ]; + path = argv[optind]; +do { +int prs =0 ; - ret =get_balance_progress (path, &bal); -if (!ret) -printf ("\r%llu/%llu block groups moved, " -"%0.2f%% complete.\n" , - bal.completed, - bal.expected, - (float )bal.completed/bal.expected*100.0 ); + ret =get_balance_progress (path, &bal); +if (ret) +break ; + +if (last_completed != bal.completed) { +printf ("\r%llu/%llu block groups moved, " +"%0.2f%% complete." , + bal.completed, + bal.expected, + (float )bal.completed/bal.expected*100.0 ); + } + +if (initial_completed !=-1 + && initial_completed != bal.completed) { + ret =gettimeofday (&now,NULL ); +if (ret) { +fprintf (stderr,"Can't read current time\n" ); +return 22 ; + } +/* Seconds per block */ +float rate = (float )(now.tv_sec - started.tv_sec) + / (bal.completed - initial_completed); +int secs_remaining = rate + * (bal.expected - bal.completed); +printf (" Time remaining" ); +if (secs_remaining >=60 *60 *24 ) { +printf (" %dd" , secs_remaining / (60 *60 *24 )); + secs_remaining %=60 *60 *24 ; + prs =1 ; + } +if (prs || secs_remaining >=60 *60 ) { +printf (" %dh" , secs_remaining / (60 *60 )); + secs_remaining %=60 *60 ; + prs =1 ; + } +if (prs || secs_remaining >60 ) { +printf (" %dm" , secs_remaining /60 ); + secs_remaining %=60 ; + } +printf (" %ds\x1b[K" , secs_remaining); + } + +if (last_completed !=-1 && last_completed != bal.completed) { + initial_completed = bal.completed; + ret =gettimeofday (&started,NULL ); +if (ret) { +fprintf (stderr,"Can't read current time\n" ); +return 22 ; + } + } + + last_completed = bal.completed; + +if (monitor) { +fflush (stdout); +sleep (1 ); + }else { +printf ("\n" ); + } + }while (monitor);switch (ret) {case 0 :
man/btrfs.8.in +2 -2
@@ -21,7 +21,7 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBfilesystem resize\fP\fI [+/\-]<size>[gkm]|max <filesystem>\fP .PP -\fBbtrfs\fP \fBbalance progress\fP \fI<path>\fP +\fBbtrfs\fP \fBbalance progress\fP [\fB-m\fP|\fB--monitor\fP] \fI<path>\fP .PP \fBbtrfs\fP \fBdevice scan\fP\fI [<device> [<device>..]]\fP .PP
@@ -150,7 +150,7 @@ Balance the chunks of the filesystem identified by \fI<path>\fR across the devices. .TP -\fBbalance progress\fP \fI<path>\fP +\fBbalance progress\fP [\fB-m\fP|\fB--monitor\fP] \fI<path>\fP Report progress on the currently-running balance operation on \fI<path>\fP. .TP
Signature · 1 line
1.7.1
PATCH v2 3/3 User-space tool for cancelling balance operations.
In reply to Hugo MillsAdd an option to the btrfs tool to use the ioctl for cancelling balance operations.
--- btrfs.c | 4 ++++ btrfs_cmds.c | 41 +++++++++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ioctl.h | 1 + 4 files changed, 47 insertions(+), 0 deletions(-)
btrfs.c +4 -0
@@ -103,6 +103,10 @@ static struct Command commands[] = {"balance progress" ,"[-m|--monitor] <path>\n" "Show progress of the balance operation running on <path>." }, + { do_balance_cancel, 1, +"balance cancel" ,"<path>\n" +"Cancel 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"
btrfs_cmds.c +41 -0
47 lines not on this page · raw message
btrfs_cmds.h +1 -0
@@ -24,6 +24,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_balance_cancel (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);
ioctl.h +1 -0
@@ -176,4 +176,5 @@ struct btrfs_ioctl_balance_progress { struct btrfs_ioctl_space_args)#define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 25, \ struct btrfs_ioctl_balance_progress) +#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 26)#endif
Signature · 1 line
1.7.1