Control filesystem balances (userspace)
cover Control filesystem balances (userspace)
These two 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 patch allows a running balance to be cancelled.
I'm a bit uncertain about the best name for these commands. Several
options:
1)
# btrfs filesystem progress <path> # btrfs filesystem cancel <path>
Way too vague (cancel *what*?)
2)
# btrfs filesystem balance-progress <path> # btrfs filesystem balance-cancel <path>
Clashes horribly with "filesystem balance" -- no abbreviations
possible.
3)
btrfs filesystem balance -p <path>
btrfs filesystem balance -c <path>
Changes behaviour significantly on a switch, in contrast to the
behaviour of the rest of the btrfs tool.
4)
btrfs balance progress <path>
btrfs balance cancel <path>
My current favourite, although we introduce a new namespace
("balance") for commands. We could add "btrfs balance start <path>" as a synonym for "btrfs filesystem balance <path>", for some degree of consistency.
At some point, I'll add a "monitor" function, which will poll at 1s
intervals for progress updates, and print out progress when it changes.
Hugo.
Signature · 3 lines
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk === PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk --- "No! My collection of rare, incurable diseases! Violated!" ---
PATCH 1/2 Balance progress monitoring.
Add support to the btrfs tool for monitoring a balance operation on a filesystem.
--- btrfs.c | 4 ++++ btrfs_cmds.c | 40 ++++++++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ioctl.h | 7 +++++++ 4 files changed, 52 insertions(+)
btrfs.c +4 -0
@@ -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"
btrfs_cmds.c +40 -0
@@ -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) {
btrfs_cmds.h +1 -0
@@ -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);
ioctl.h +7 -0
@@ -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
PATCH 2/2 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(+)
btrfs.c +4 -0
@@ -99,6 +99,10 @@"balance progress" ,"<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_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_space_args)#define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 21, \ struct btrfs_ioctl_balance_progress) +#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 22)#endif
You could always use btrfs filesystem balance progress which would not introduce a new root level option and still be short to type. That would mean balance should have a "start" option or default to start when no sub options are used.
Sent from my mobile device.
Quoted 54 lines · Hugo Mills
These two 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 patch allows a running balance to be cancelled.I'm a bit uncertain about the best name for these commands. Several
options:1)
# btrfs filesystem progress <path> # btrfs filesystem cancel <path>Way too vague (cancel *what*?)
2)
# btrfs filesystem balance-progress <path> # btrfs filesystem balance-cancel <path>Clashes horribly with "filesystem balance" -- no abbreviations
possible.3)
btrfs filesystem balance -p <path>
btrfs filesystem balance -c <path>Changes behaviour significantly on a switch, in contrast to the
behaviour of the rest of the btrfs tool.4)
btrfs balance progress <path>
btrfs balance cancel <path>My current favourite, although we introduce a new namespace
("balance") for commands. We could add "btrfs balance start <path>" as a synonym for "btrfs filesystem balance <path>", for some degree of consistency.At some point, I'll add a "monitor" function, which will poll at 1s
intervals for progress updates, and print out progress when it changes.Hugo.
--
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
--- "No! My collection of rare, incurable diseases! Violated!" -----
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Hugo Mills
These two 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 patch allows a running balance to be cancelled.I'm a bit uncertain about the best name for these commands. Several
options:
[...]
Quoted 9 lines
4)
btrfs balance progress <path>
btrfs balance cancel <path>My current favourite, although we introduce a new namespace
("balance") for commands. We could add "btrfs balance start <path>" as a synonym for "btrfs filesystem balance <path>", for some degree of consistency.
I like this.
Regards
G.Baroncelli
Quoted 16 lines
At some point, I'll add a "monitor" function, which will poll at 1s
intervals for progress updates, and print out progress when it changes.Hugo.
Signature · 8 lines
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk === PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk --- "No! My collection of rare, incurable diseases! Violated!" --- -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <[email protected]> Key fingerprint = 4769 7E51 5293 D36C 814E C054 BF04 F161 3DC5 0512