Balance management, userspace
v5 cover Balance management, userspace
Hi, Chris,
These patches form the userspace side of the balance management
work. This includes two patches to add one-off and polled monitoring, a fork-to-background patch, and a sequence implementing the user interface to handle the various types of balance filtering implemented in the kernel-side patches.
Hugo.
---
Hugo Mills (8):
Balance progress monitoring.
Add --monitor option to btrfs balance progress.
User-space tool for cancelling balance operations.
Run userspace tool in background for balances.
Initial implementation of userspace interface for filtered balancing. Balance filter by device ID
Balance filter for virtual address range
Interface for device range balance filter
btrfs.c | 18 ++- btrfs_cmds.c | 463 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- btrfs_cmds.h | 2 + ioctl.h | 46 ++++++ man/btrfs.8.in | 79 +++++++++- 5 files changed, 596 insertions(+), 12 deletions(-)
Signature · 1 line
1.7.2.5
PATCH v5 1/8 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 | 11 ++++++++++ 5 files changed, 87 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 { +__u32 expected; +__u32 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 +11 -0
@@ -23,6 +23,8 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBdevice scan\fP\fI [<device> [<device>..]]\fP .PP +\fBbtrfs\fP \fBbalance progress\fP\fI <path>\fP +.PP \fBbtrfs\fP \fBdevice show\fP\fI <dev>|<label> [<dev>|<label>...]\fP .PP \fBbtrfs\fP \fBdevice balance\fP\fI <path> \fP
@@ -152,10 +154,19 @@ across the devices. Add device(s) to the filesystem identified by \fI<path>\fR. .TP +.SS +\fBdevice balance \fI<path>\fP +Balance the chunks of the filesystem identified by \fI<path>\fP +across the devices. + \fBdevice delete\fR\fI <dev> [<dev>..] <path>\fR Remove device(s) from a filesystem identified by \fI<path>\fR. .PP +\fBbalance progress\fP \fI<path>\fP +Report progress on the currently-running balance operation on the +filesystem mounted at \fI<path>\fP. + .SH EXIT STATUS \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in case of failure.
Signature · 1 line
1.7.2.5
PATCH v5 2/8 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 +++++++++++++++++++++++++++++++++++++++++++++++++++---- ioctl.h | 2 +- man/btrfs.8.in | 7 ++-- 3 files changed, 99 insertions(+), 12 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 :
ioctl.h +1 -1
@@ -174,6 +174,6 @@ struct btrfs_ioctl_balance_progress {#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, \ +#define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 27, \ struct btrfs_ioctl_balance_progress)#endif
man/btrfs.8.in +4 -3
@@ -23,7 +23,7 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBdevice scan\fP\fI [<device> [<device>..]]\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 show\fP\fI <dev>|<label> [<dev>|<label>...]\fP .PP
@@ -163,9 +163,10 @@ across the devices. Remove device(s) from a filesystem identified by \fI<path>\fR. .PP -\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 the -filesystem mounted at \fI<path>\fP. +filesystem mounted at \fI<path>\fP. Use --monitor to report progress +continually, including an estimate of completion time. .SH EXIT STATUS \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in
Signature · 1 line
1.7.2.5
PATCH v5 3/8 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 + man/btrfs.8.in | 6 ++++++ 5 files changed, 53 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, 27, \ struct btrfs_ioctl_balance_progress) +#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28)#endif
man/btrfs.8.in +6 -0
@@ -25,6 +25,8 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBbalance progress\fP [\fB-m\fP|\fB--monitor\fP] \fI<path>\fP .PP +\fBbtrfs\fP \fBbalance cancel\fP \fI<path>\fP +.PP \fBbtrfs\fP \fBdevice show\fP\fI <dev>|<label> [<dev>|<label>...]\fP .PP \fBbtrfs\fP \fBdevice balance\fP\fI <path> \fP
@@ -168,6 +170,10 @@ Report progress on the currently-running balance operation on the filesystem mounted at \fI<path>\fP. Use --monitor to report progress continually, including an estimate of completion time. +\fbalance cancel\fP \fI<path>\fP +Cancel the balance currently running on the filesystem mounted at +\fI<path>\fP. + .SH EXIT STATUS \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in case of failure.
Signature · 1 line
1.7.2.5
PATCH v5 4/8 Run userspace tool in background for balances.
In reply to Hugo MillsThis patch makes a balance operation fork and detach from the current terminal, to run the userspace side of the balance in the background.
Introduce a --wait switch so that a synchronous balance can be done if the user requires.
--- btrfs.c | 8 ++++---- btrfs_cmds.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- man/btrfs.8.in | 19 ++++++++++--------- 3 files changed, 64 insertions(+), 15 deletions(-)
btrfs.c +4 -4
@@ -91,12 +91,12 @@ static struct Command commands[] = {"filesystem df" ,"<path>\n" "Show space usage information for a mount point\n." }, - { do_balance, 1, -"filesystem balance" ,"<path>\n" + { do_balance, -1, +"filesystem balance" ,"[-w|--wait] <path>\n" "Balance the chunks across the device." }, - { do_balance, 1, -"balance start" ,"<path>\n" + { do_balance, -1, +"balance start" ,"[-w|--wait] <path>\n" "Synonym for \"btrfs filesystem balance\"." }, { do_balance_progress, -1,
btrfs_cmds.c +50 -2
68 lines not on this page · raw message
man/btrfs.8.in +10 -9
@@ -23,13 +23,15 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBdevice scan\fP\fI [<device> [<device>..]]\fP .PP +\fBbtrfs\fP \fBbalance start\fP [\fB-w\fP|\fB--wait\fP] \fI<path>\fP +.PP \fBbtrfs\fP \fBbalance progress\fP [\fB-m\fP|\fB--monitor\fP] \fI<path>\fP .PP \fBbtrfs\fP \fBbalance cancel\fP \fI<path>\fP .PP \fBbtrfs\fP \fBdevice show\fP\fI <dev>|<label> [<dev>|<label>...]\fP .PP -\fBbtrfs\fP \fBdevice balance\fP\fI <path> \fP +\fBbtrfs\fP \fBfilesystem balance\fP [\fB-w\fP|\fB--wait\fP] \fI<path>\fP .PP \fBbtrfs\fP \fBdevice add\fP\fI <dev> [<dev>..] <path> \fP .PP
@@ -147,20 +149,19 @@ Show the btrfs filesystem with some additional info. If no UUID or label is passed, \fBbtrfs\fR show info of all the btrfs filesystem. .TP -\fBdevice balance\fR \fI<path>\fR -Balance the chunks of the filesystem identified by \fI<path>\fR -across the devices. +\fBdevice balance\fR [\fB-w\fP|\fB--wait\fP] \fI<path>\fR + +\fBbalance start\fR [\fB-w\fP|\fB--wait\fP] \fI<path>\fR + +Balance the chunks of the filesystem identified by \fI<path>\fR across +the devices. The process runs in the background. Use \fB--wait\fP to +wait in the foreground for completion of the balance. .TP \fBdevice add\fR\fI <dev> [<dev>..] <path>\fR Add device(s) to the filesystem identified by \fI<path>\fR. .TP -.SS -\fBdevice balance \fI<path>\fP -Balance the chunks of the filesystem identified by \fI<path>\fP -across the devices. - \fBdevice delete\fR\fI <dev> [<dev>..] <path>\fR Remove device(s) from a filesystem identified by \fI<path>\fR. .PP
Signature · 1 line
1.7.2.5
PATCH v5 5/8 Initial implementation of userspace interface for filtered balancing.
In reply to Hugo MillsIt is useful to be able to balance a subset of the full filesystem. This patch implements the infrastructure for filtering block groups on different criteria when balancing the filesystem.
--- btrfs.c | 4 +- btrfs_cmds.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- ioctl.h | 24 ++++++++ man/btrfs.8.in | 40 +++++++++++-- 4 files changed, 225 insertions(+), 12 deletions(-)
btrfs.c +2 -2
@@ -92,8 +92,8 @@ static struct Command commands[] = {"Show space usage information for a mount point\n." }, { do_balance, -1, -"filesystem balance" ,"[-w|--wait] <path>\n" -"Balance the chunks across the device." +"filesystem balance" ,"[-w|--wait] [-f|--filter=<filter>:...] <path>\n" +"Balance chunks across the devices. --filter=help for help on filters.\n" }, { do_balance, -1,"balance start" ,"[-w|--wait] <path>\n"
btrfs_cmds.c +165 -4
217 lines not on this page · raw message
ioctl.h +24 -0
@@ -137,6 +137,28 @@ struct btrfs_ioctl_balance_progress {__u32 completed; }; +/* Types of balance filter */ +#define BTRFS_BALANCE_FILTER_COUNT_ONLY 0x1 + +#define BTRFS_BALANCE_FILTER_CHUNK_TYPE 0x2 +#define BTRFS_BALANCE_FILTER_MASK 0x3 + +/* All the possible options for a filter */ +struct btrfs_ioctl_balance_start { +__u64 flags;/* Bit field indicating which fields of this struct are filled */ + +/* Output values: chunk counts */ +__u64 examined; +__u64 balanced; + +/* For FILTER_CHUNK_TYPE */ +__u64 chunk_type;/* Flag bits required */ +__u64 chunk_type_mask;/* Mask of bits to examine */ + +__u64 spare[506 ];/* Make up the size of the structure to 4088 +* bytes for future expansion */ +}; +#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ struct btrfs_ioctl_vol_args)#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
@@ -177,4 +199,6 @@ struct btrfs_ioctl_balance_progress {#define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 27, \ struct btrfs_ioctl_balance_progress)#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28) +#define BTRFS_IOC_BALANCE_FILTERED _IOWR(BTRFS_IOCTL_MAGIC, 29, \ + struct btrfs_ioctl_balance_start)#endif
man/btrfs.8.in +34 -6
@@ -31,7 +31,7 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBdevice show\fP\fI <dev>|<label> [<dev>|<label>...]\fP .PP -\fBbtrfs\fP \fBfilesystem balance\fP [\fB-w\fP|\fB--wait\fP] \fI<path>\fP +\fBbtrfs\fP \fBfilesystem balance\fP [\fB-wcv\fP] [\fB--wait\fP] [\fB--count\fP] [\fB--verbose\fP] [\fB-f\fP|\fBfilter=\fP\fI<filter>\fP] \fI<path>\fP .PP \fBbtrfs\fP \fBdevice add\fP\fI <dev> [<dev>..] <path> \fP .PP
@@ -149,13 +149,18 @@ Show the btrfs filesystem with some additional info. If no UUID or label is passed, \fBbtrfs\fR show info of all the btrfs filesystem. .TP -\fBdevice balance\fR [\fB-w\fP|\fB--wait\fP] \fI<path>\fR +\fBdevice balance\fP [\fB-wcv\fP] [\fB--wait\fP] [\fB--count\fP] [\fB--verbose\fP] [\fB-f\fP|\fBfilter=\fP\fI<filter>\fP] \fI<path>\fP -\fBbalance start\fR [\fB-w\fP|\fB--wait\fP] \fI<path>\fR +\fBbalance start\fR [\fB-wcv\fP] [\fB--wait\fP] [\fB--count\fP] [\fB--verbose\fP] [\fB-f\fP|\fBfilter=\fP\fI<filter>\fP] \fI<path>\fP Balance the chunks of the filesystem identified by \fI<path>\fR across -the devices. The process runs in the background. Use \fB--wait\fP to -wait in the foreground for completion of the balance. +the devices. The command returns immediately, and the balance +operation runs in the background. Use \fB--wait\fP to run +synchronously instead. Use \fB--count\fP to scan the filesystem and +report the number of chunks that would be processed. Use +\fB--verbose\fP in synchronous mode to report the number of chunks +examined and balanced. See \fBBALANCE FILTERS\fR, below, for details +of the different filter types and syntax. .TP \fBdevice add\fR\fI <dev> [<dev>..] <path>\fR
@@ -171,10 +176,33 @@ Report progress on the currently-running balance operation on the filesystem mounted at \fI<path>\fP. Use --monitor to report progress continually, including an estimate of completion time. -\fbalance cancel\fP \fI<path>\fP +\fBbalance cancel\fP \fI<path>\fP Cancel the balance currently running on the filesystem mounted at \fI<path>\fP. +.SH BALANCE FILTERS +With balance filters, it is possible to perform a balance operation on +only a subset of the available chunks. Filters are specified with the +\fB--filter\fR option of \fBbtrfs device balance\fR or \fBbtrfs +balance start\fR. Multiple filters may be given, either with multiple +\fB--filter\fR options, or in a colon-separated list. When multiple +filters are given, only the chunks meeting all of the selection +critera are balanced. Help on the avaialble filters can be obtained +with \fB--filter=help\fR. + +.TP +\fBtype\fR=[\fB~\fR]\fI<flagname>\fR[\fB,\fR...] + +Select only the chunks with the given type flag(s). Requiring a flag +to be off can be specified with a \fB~\fR preceding the flag +name. Flag names are: + +\fBmeta\fR, \fBdata\fR, \fBsys\fR for metadata, file data and system +chunk types. + +\fBraid0\fR, \fBraid1\fR, \fBraid10\fR, \fBdup\fR for chunks of the +given replication levels. + .SH EXIT STATUS \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in case of failure.
Signature · 1 line
1.7.2.5
PATCH v5 6/8 Balance filter by device ID
In reply to Hugo MillsAdd the userspace implementation for filtering balances by device ID.
--- btrfs_cmds.c | 13 +++++++++++++ ioctl.h | 8 ++++++-- man/btrfs.8.in | 7 +++++++ 3 files changed, 26 insertions(+), 2 deletions(-)
btrfs_cmds.c +13 -0
@@ -775,6 +775,10 @@ const struct filter_class_desc filter_class[] = {"\t\tmeta, sys, data, raid0, raid1, raid10, dup\n" "\tPrefix a <flagname> with ~ to negate the match.\n" , BTRFS_BALANCE_FILTER_CHUNK_TYPE }, + { "devid", +"devid=<n>\n" +"\tBalance only chunks which have a stripe on device <n>.\n" , + BTRFS_BALANCE_FILTER_DEVID }, { NULL, NULL, 0 } };
@@ -872,6 +876,15 @@ int parse_filter(struct btrfs_ioctl_balance_start *args, char *filters_string) part =strtok_r (NULL ,"=," , &subsave); }break ; + +case BTRFS_BALANCE_FILTER_DEVID : + errno =0 ; + args->devid =strtoull (part,NULL ,10 ); +if (errno !=0 ) { +fprintf (stderr,"ERROR: '%s' is not a valid device ID\n" , part); +return 15 ; + } +break ; } this_filter_string =strtok_r (NULL ,":" , &saveptr);
ioctl.h +6 -2
@@ -141,7 +141,8 @@ struct btrfs_ioctl_balance_progress {#define BTRFS_BALANCE_FILTER_COUNT_ONLY 0x1#define BTRFS_BALANCE_FILTER_CHUNK_TYPE 0x2 -#define BTRFS_BALANCE_FILTER_MASK 0x3 +#define BTRFS_BALANCE_FILTER_DEVID 0x4 +#define BTRFS_BALANCE_FILTER_MASK 0x7/* All the possible options for a filter */ struct btrfs_ioctl_balance_start {
@@ -155,7 +156,10 @@ struct btrfs_ioctl_balance_start {__u64 chunk_type;/* Flag bits required */ __u64 chunk_type_mask;/* Mask of bits to examine */ -__u64 spare[506 ];/* Make up the size of the structure to 4088 +/* For FILTER_DEVID */ +__u64 devid; + +__u64 spare[505 ];/* Make up the size of the structure to 4088 * bytes for future expansion */ };
man/btrfs.8.in +7 -0
@@ -203,6 +203,13 @@ chunk types. \fBraid0\fR, \fBraid1\fR, \fBraid10\fR, \fBdup\fR for chunks of the given replication levels. +.TP +\fBdevid\fR=\fI<n>\fR + +Select chunks which have data on device ID \fI<n>\fR. This can be +used, for example, to reduplicate data in a mirrored configuration +where one drive has been lost due to hardware failure. + .SH EXIT STATUS \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in case of failure.
Signature · 1 line
1.7.2.5
PATCH v5 7/8 Balance filter for virtual address range
In reply to Hugo MillsImplement the userspace side of the virtual address range filter.
--- btrfs_cmds.c | 22 ++++++++++++++++++++++ ioctl.h | 9 +++++++-- man/btrfs.8.in | 9 +++++++++ 3 files changed, 38 insertions(+), 2 deletions(-)
btrfs_cmds.c +22 -0
@@ -779,6 +779,12 @@ const struct filter_class_desc filter_class[] = {"devid=<n>\n" "\tBalance only chunks which have a stripe on device <n>.\n" , BTRFS_BALANCE_FILTER_DEVID }, + { "vrange", +"vrange=<start>,<end>\n" +"\tBalances only chunks which have any bytes within the given\n" +"\trange of the filesystem's virtual address space.\n" +"\t<start> is inclusive, <end> is exclusive.\n" , + BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE }, { NULL, NULL, 0 } };
@@ -885,6 +891,22 @@ int parse_filter(struct btrfs_ioctl_balance_start *args, char *filters_string)return 15 ; }break ; + +case BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE : + errno =0 ; + args->vrange_start =strtoull (part,NULL ,10 ); +if (errno !=0 ) { +fprintf (stderr,"ERROR: '%s' is not a valid start address\n" , part); +return 15 ; + } + part =strtok_r (NULL ,"=," , &subsave); + errno =0 ; + args->vrange_end =strtoull (part,NULL ,10 ); +if (errno !=0 ) { +fprintf (stderr,"ERROR: '%s' is not a valid end address\n" , part); +return 15 ; + } +break ; } this_filter_string =strtok_r (NULL ,":" , &saveptr);
ioctl.h +7 -2
@@ -142,7 +142,8 @@ struct btrfs_ioctl_balance_progress {#define BTRFS_BALANCE_FILTER_CHUNK_TYPE 0x2#define BTRFS_BALANCE_FILTER_DEVID 0x4 -#define BTRFS_BALANCE_FILTER_MASK 0x7 +#define BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE 0x8 +#define BTRFS_BALANCE_FILTER_MASK 0xf/* All the possible options for a filter */ struct btrfs_ioctl_balance_start {
@@ -159,7 +160,11 @@ struct btrfs_ioctl_balance_start {/* For FILTER_DEVID */ __u64 devid; -__u64 spare[505 ];/* Make up the size of the structure to 4088 +/* For FILTER_VIRTUAL_ADDRESS_RANGE */ +__u64 vrange_start; +__u64 vrange_end; + +__u64 spare[503 ];/* Make up the size of the structure to 4088 * bytes for future expansion */ };
man/btrfs.8.in +9 -0
@@ -210,6 +210,15 @@ Select chunks which have data on device ID \fI<n>\fR. This can be used, for example, to reduplicate data in a mirrored configuration where one drive has been lost due to hardware failure. +.TP +\fBvrange\fR=\fI<start>\fB,\fI<end>\fR + +Select chunks which have btrfs-internal virtual addresses within the +range \fI<start>\fR (inclusive) to \fI<end>\fR (exclusive). Given the +address of the last chunk moved, this filter can be used to restart a +cancelled or interrupted balance operation, by supplying a range of +\fB0,\fI<chunkaddr+1>\fR. + .SH EXIT STATUS \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in case of failure.
Signature · 1 line
1.7.2.5
PATCH v5 8/8 Interface for device range balance filter
In reply to Hugo MillsImplement the userspace side of the balance filter for a range of bytes on any device. Note that this will match the same range on any device, so the use of the devid filter is recommended where this filter is used.
--- btrfs_cmds.c | 22 ++++++++++++++++++++++ ioctl.h | 9 +++++++-- man/btrfs.8.in | 8 ++++++++ 3 files changed, 37 insertions(+), 2 deletions(-)
btrfs_cmds.c +22 -0
@@ -785,6 +785,12 @@ const struct filter_class_desc filter_class[] = {"\trange of the filesystem's virtual address space.\n" "\t<start> is inclusive, <end> is exclusive.\n" , BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE }, + { "drange", +"drange=<start>,<end>\n" +"\tBalances chunks which have any bytes within the given\n" +"\tbyte range on any of the filesystem's underlying devices.\n" +"\t<start> is inclusive, <end> is exclusive.\n" , + BTRFS_BALANCE_FILTER_DEVICE_ADDRESS_RANGE }, { NULL, NULL, 0 } };
@@ -907,6 +913,22 @@ int parse_filter(struct btrfs_ioctl_balance_start *args, char *filters_string)return 15 ; }break ; + +case BTRFS_BALANCE_FILTER_DEVICE_ADDRESS_RANGE : + errno =0 ; + args->drange_start =strtoull (part,NULL ,10 ); +if (errno !=0 ) { +fprintf (stderr,"ERROR: '%s' is not a valid start address\n" , part); +return 15 ; + } + part =strtok_r (NULL ,"=," , &subsave); + errno =0 ; + args->drange_end =strtoull (part,NULL ,10 ); +if (errno !=0 ) { +fprintf (stderr,"ERROR: '%s' is not a valid end address\n" , part); +return 15 ; + } +break ; } this_filter_string =strtok_r (NULL ,":" , &saveptr);
ioctl.h +7 -2
@@ -143,7 +143,8 @@ struct btrfs_ioctl_balance_progress {#define BTRFS_BALANCE_FILTER_CHUNK_TYPE 0x2#define BTRFS_BALANCE_FILTER_DEVID 0x4#define BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE 0x8 -#define BTRFS_BALANCE_FILTER_MASK 0xf +#define BTRFS_BALANCE_FILTER_DEVICE_ADDRESS_RANGE 0x10 +#define BTRFS_BALANCE_FILTER_MASK 0x1f/* All the possible options for a filter */ struct btrfs_ioctl_balance_start {
@@ -164,7 +165,11 @@ struct btrfs_ioctl_balance_start {__u64 vrange_start;__u64 vrange_end; -__u64 spare[503 ];/* Make up the size of the structure to 4088 +/* For FILTER_DEVICE_ADDRESS_RANGE */ +__u64 drange_start; +__u64 drange_end; + +__u64 spare[501 ];/* Make up the size of the structure to 4088 * bytes for future expansion */ };
man/btrfs.8.in +8 -0
@@ -219,6 +219,14 @@ address of the last chunk moved, this filter can be used to restart a cancelled or interrupted balance operation, by supplying a range of \fB0,\fI<chunkaddr+1>\fR. +.TP +\fBdrange\fR=\fI<start>\fB,\fI<end>\fR + +Select chunks which contain data in the address range \fI<start>\fR +(inclusive) to \fI<end>\fR (exclusive) on \fIany\fR block device in +the filesystem. Can be mixed with the \fBdevid\fR filter to select +chunks in a given address range on a specific device. + .SH EXIT STATUS \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in case of failure.
Signature · 1 line
1.7.2.5
Re: [PATCH v5 4/8] Run userspace tool in background for balances.
In reply to Hugo MillsHallo, Hugo,
Du meintest am 10.04.11:
Quoted 2 lines
This patch makes a balance operation fork and detach from the current terminal, to run the userspace side of the balance in the background.
Fine!
Viele Gruesse!
Helmut