Btrfs-progs: restriper interface
PATCH 1/1 Btrfs-progs: restriper interface
Hello,
This is an update of userspace restriper interface. The main change is that restriper commands have been moved under balance prefix. So now we have:
btrfs fi balance start
btrfs fi balance pause
btrfs fi balance cancel
btrfs fi balance resume
btrfs fi balance status
This breaks btrfs-progs backwards compatibility: to get the old balancing behaviour you have to call 'btrfs fi balance start' instead of 'btrfs fi balance'. This is caused by stupidity of the core sub-command matcher. There are also some other problems with that parser and I'll fix them all in one commit shortly. After that the "start" will be optional:
btrfs fi balance [options]
btrfs fi balance start [options]
Apart from some minor error handling fixes went in.
Here are some specs:
./btrfs fi balance start [-d[filters]] [-m[filters]] [-s[filters]]
[-vf] <path>
where 'filters' is comma-separated list of filters (comma == AND):
o profiles={profiles mask} - profiles filter
profiles mask is '|'-separated list ('|' == OR) of profileso usage={percentage} - usage filter
o devid={devid} - devid filter
o drange={start..end} - devid subset filter, it's tied to devid filter:
we say balance out range [start..end) on a particular devid. These are also acceptable:
drange=start.. - [start..end of device)
drange=..end - [start of device..end)
o vrange={start..end} - virtual address space subset filter. Same forms as above are acceptable.
Convert (profile changing) is specified as follows:
o convert={profile},[soft]
soft parameter makes sense only for convert option. It turns on
"soft" mode for profile changing, see the kernel patch.
Each chunk type can be either balanced or converted to some new profile. By specifying some filters w/o convert option we balance chunks that passed all filters (remember, comma == AND). If only convert parameter is specified we convert all chunks of that type. If both convert and filters are specified restriper filters out chunks according to the given filters and then converts everything that passed through all the filters.
By default system chunks are relocated along with meta chunks with the same exact options. To operate explicitly on system chunks -f (--force) flag has to be specified.
Examples (somewhat contrived, but they demonstrate the flexibility of the interface):
o ./btrfs fi balance start <path>
will balance everything (what ./btrfs fi balance <path> did)
o ./btrfs fi balance start -d
will balance only data chunks
o ./btrfs fi balance start -d -m
will balance everything (because -m by default applies to system chunks too, see above)
o ./btrfs fi balance start -d -s -f
will balance all data and system chunks, won't touch meta chunks (note that the force is used to operate explicitly on system chunks)
o ./btrfs fi balance start -dprofiles=raid1\|raid0
will balance only data chunks that have raid1 or raid0 profile (\ - shell escape)
o ./btrfs fi balance start -mprofiles=raid1\|raid0,devid=2
will balance meta and sys chunks that have raid1 or raid0 profile and at least one stripe located on device with devid 2
o ./btrfs fi balance start -s -musage=80,profiles=dup -f
will balance all system chunks and dup'ed metadata chunks which are less than 80% full
o ./btrfs fi balance start -s -mprofiles=dup,convert=raid1 -f
will *balance* all system chunks and *convert* dup meta chunks to raid1
o ./btrfs fi balance start -dvrange=100..803337011,convert=raid0,soft
will soft-convert data chunks in that virtual address space range to raid0
Note that you can't put a space between e.g. -m and a list of filters because of the way getopt(3) works. There are also long options, if you prefer (--data, --metadata, --system), e.g:
./btrfs fi balance start --data=profiles=raid1\|raid0
All permutations are possible, restriper doesn't care about the order in which options are given, all settings are per-chunk-type, and what you do with one chunk type is completely independent of what you do with the other.
The force flag also has to be given if you want to "downgrade" the profile. By downgrading I mean reducing the number of copies, so raid10->raid1 can be done w/o this flag, while raid1->raid0 cannot.
And the management commands:
./btrfs fi balance cancel <path>
./btrfs fi balance pause <path>
./btrfs fi balance resume <path>
./btrfs fi balance status [-v] <path>
Patch is on top of master branch of btrfs-progs repo, available at:
git://github.com/idryomov/btrfs-progs.git restriper
Thanks,
Ilya
Ilya Dryomov (1):
Btrfs-progs: add restriper commands
btrfs.c | 27 +++- btrfs_cmds.c | 577 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- btrfs_cmds.h | 8 +- ctree.h | 23 ++- ioctl.h | 53 ++++++ print-tree.c | 6 + volumes.h | 30 +++ 7 files changed, 687 insertions(+), 37 deletions(-)
Signature · 1 line
1.7.6.3
PATCH 1/1 Btrfs-progs: add restriper commands
Import restriper commands under btrfs fi balance:
btrfs fi balance start
btrfs fi balance cancel
btrfs fi balance pause
btrfs fi balance resume
btrfs fi balance status
NOTE: Backwards compatibility is broken for now, to get the old "balance everything" behaviour one has to call 'btrfs fi balance start' with no options instead of 'btrfs fi balance'. This is because btrfs utility sub-command parser is not flexible enough.
--- btrfs.c | 27 +++- btrfs_cmds.c | 577 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- btrfs_cmds.h | 8 +- ctree.h | 23 ++- ioctl.h | 53 ++++++ print-tree.c | 6 + volumes.h | 30 +++ 7 files changed, 687 insertions(+), 37 deletions(-)
btrfs.c +24 -3
@@ -119,9 +119,30 @@ static struct Command commands[] = {"Show space usage information for a mount point." ,NULL }, - { do_balance, 1, -"filesystem balance" ,"<path>\n" -"Balance the chunks across the device." , + { do_balance, -1, +"filesystem balance start" ,"[-d [filters]] [-m [filters]] " +"[-s [filters]] [-vf] <path>\n" +"Balance chunks across the devices." , +NULL + }, + { do_balance_pause, 1, +"filesystem balance pause" ,"<path>\n" +"Pause running balance." , +NULL + }, + { do_balance_cancel, 1, +"filesystem balance cancel" ,"<path>\n" +"Cancel running or paused balance." , +NULL + }, + { do_balance_resume, 1, +"filesystem balance resume" ,"<path>\n" +"Resume interrupted balance." , +NULL + }, + { do_balance_progress, -1, +"filesystem balance status" ,"[-v] <path>\n" +"Show status of running or paused balance." ,NULL }, { do_change_label, -1,
btrfs_cmds.c +552 -25
595 lines not on this page · raw message
btrfs_cmds.h +6 -2
@@ -22,12 +22,16 @@ int do_fssync(int nargs, char **argv);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_remove_volume (int nargs,char **args); +int do_balance (int argc,char **argv); +int do_balance_pause (int argc,char **argv); +int do_balance_cancel (int argc,char **argv); +int do_balance_resume (int argc,char **argv); +int do_balance_progress (int argc,char **argv);int do_scrub_start (int nargs,char **argv);int do_scrub_status (int argc,char **argv);int do_scrub_resume (int argc,char **argv);int do_scrub_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);int do_subvol_list (int nargs,char **argv);
ctree.h +16 -7
@@ -61,6 +61,9 @@ struct btrfs_trans_handle;#define BTRFS_CSUM_TREE_OBJECTID 7ULL +/* for storing balance parameters in the root tree */ +#define BTRFS_BALANCE_OBJECTID -4ULL +/* oprhan objectid for tracking unlinked/truncated files */ #define BTRFS_ORPHAN_OBJECTID -5ULL
@@ -697,13 +700,17 @@ struct btrfs_csum_item { } __attribute__ ((__packed__));/* tag for the radix tree of block groups in ram */ -#define BTRFS_BLOCK_GROUP_DATA (1 << 0) -#define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1) -#define BTRFS_BLOCK_GROUP_METADATA (1 << 2) -#define BTRFS_BLOCK_GROUP_RAID0 (1 << 3) -#define BTRFS_BLOCK_GROUP_RAID1 (1 << 4) -#define BTRFS_BLOCK_GROUP_DUP (1 << 5) -#define BTRFS_BLOCK_GROUP_RAID10 (1 << 6) +#define BTRFS_BLOCK_GROUP_DATA (1ULL << 0) +#define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1) +#define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2) +#define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3) +#define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4) +#define BTRFS_BLOCK_GROUP_DUP (1ULL << 5) +#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6) +#define BTRFS_BLOCK_GROUP_RESERVED BTRFS_AVAIL_ALLOC_BIT_SINGLE + +/* used in struct btrfs_balance_args fields */ +#define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)struct btrfs_block_group_item {__le64 used;
@@ -911,6 +918,8 @@ struct btrfs_root {#define BTRFS_DEV_ITEM_KEY 216#define BTRFS_CHUNK_ITEM_KEY 228 +#define BTRFS_BALANCE_ITEM_KEY 248 +/* * string items are for debugging. They just store a short string of * data in the FS
ioctl.h +53 -0
65 lines not on this page · raw message
print-tree.c +6 -0
@@ -351,6 +351,9 @@ static void print_key_type(u8 type)case BTRFS_DEV_EXTENT_KEY :printf ("DEV_EXTENT" );break ; +case BTRFS_BALANCE_ITEM_KEY : +printf ("BALANCE_ITEM" ); +break ;case BTRFS_STRING_ITEM_KEY :printf ("STRING_ITEM" );break ;
@@ -391,6 +394,9 @@ static void print_objectid(unsigned long long objectid, u8 type)case BTRFS_CSUM_TREE_OBJECTID :printf ("CSUM_TREE" );break ; +case BTRFS_BALANCE_OBJECTID : +printf ("BALANCE" ); +break ;case BTRFS_ORPHAN_OBJECTID :printf ("ORPHAN" );break ;
volumes.h +30 -0
@@ -91,6 +91,36 @@ struct btrfs_multi_bio {#define btrfs_multi_bio_size (n) (sizeof(struct btrfs_multi_bio) + \ (sizeof(struct btrfs_bio_stripe) * (n))) +/* +* Restriper's general type filter +*/ +#define BTRFS_BALANCE_DATA (1ULL << 0) +#define BTRFS_BALANCE_SYSTEM (1ULL << 1) +#define BTRFS_BALANCE_METADATA (1ULL << 2) + +#define BTRFS_BALANCE_TYPE_MASK (BTRFS_BALANCE_DATA | \ + BTRFS_BALANCE_SYSTEM | \ + BTRFS_BALANCE_METADATA) + +#define BTRFS_BALANCE_FORCE (1ULL << 3) + +/* +* Balance filters +*/ +#define BTRFS_BALANCE_ARGS_PROFILES (1ULL << 0) +#define BTRFS_BALANCE_ARGS_USAGE (1ULL << 1) +#define BTRFS_BALANCE_ARGS_DEVID (1ULL << 2) +#define BTRFS_BALANCE_ARGS_DRANGE (1ULL << 3) +#define BTRFS_BALANCE_ARGS_VRANGE (1ULL << 4) + +/* +* Profile changing flags. When SOFT is set we won't relocate chunk if +* it already has the target profile (even though it may be +* half-filled). +*/ +#define BTRFS_BALANCE_ARGS_CONVERT (1ULL << 8) +#define BTRFS_BALANCE_ARGS_SOFT (1ULL << 9) + int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans, struct btrfs_device *device, u64 chunk_tree, u64 chunk_objectid,
Signature · 1 line
1.7.6.3
Quoted 12 lines · On Friday, 06 January, 2012 15:37:59 Ilya Dryomov wrote:
Hello,
This is an update of userspace restriper interface. The main change is that restriper commands have been moved under balance prefix. So now we have:
btrfs fi balance start
btrfs fi balance pause
btrfs fi balance cancel
btrfs fi balance resume
btrfs fi balance status
Quoted 4 lines
This breaks btrfs-progs backwards compatibility: to get the old balancing behaviour you have to call 'btrfs fi balance start' instead of 'btrfs fi balance'. This is caused by stupidity of the core sub-command matcher.
Hi Ilya,
what you called "stupidity of the core sub-command matcher" was a design decision.
If you make "btrfs balance" a both command and a prefix you (my opinion) confuses a possible user and complex the interface:
for example what means:
# btrfs filesystem balance pause
when 'pause' (and all the valid abbreviation like "pa" or "p" ) is a valid mount point ?
My opinion, in order to not break the backward compatibility is to add another subcommand family, like 'restriper' or whatsoever, then deprecating the 'balance' sub command.
Finally, please could you update the man page too ?
BR
G.Baroncelli
Disclaimer, I was the author of the sub-command matcher.
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
Quoted 26 lines · Goffredo Baroncelli
Quoted 12 lines · On Friday, 06 January, 2012 15:37:59 Ilya Dryomov wrote:
Hello,
This is an update of userspace restriper interface. The main change is that restriper commands have been moved under balance prefix. So now we have:
btrfs fi balance start
btrfs fi balance pause
btrfs fi balance cancel
btrfs fi balance resume
btrfs fi balance statusQuoted 4 lines
This breaks btrfs-progs backwards compatibility: to get the old balancing behaviour you have to call 'btrfs fi balance start' instead of 'btrfs fi balance'. This is caused by stupidity of the core sub-command matcher.
Hi Ilya,
what you called "stupidity of the core sub-command matcher" was a design decision.
If you make "btrfs balance" a both command and a prefix you (my opinion) confuses a possible user and complex the interface:
Quoted 6 lines
for example what means:
# btrfs filesystem balance pausewhen 'pause' (and all the valid abbreviation like "pa" or "p" ) is a valid mount point ?
pause needs an argument so technically we have a way out here, but at the expense of an awful interface (because then we have to be able to deal with sub-commands with no arguments, etc)
You are right, I was too quick to call it stupid. I guess my problem is that I never bought this "the shortest abbreviation possible" thing. IMHO it would be much better if we had our long names and a handful of predefined abbreviations (like ip command for example).
Quoted 4 lines
My opinion, in order to not break the backward compatibility is to add another subcommand family, like 'restriper' or whatsoever, then deprecating the 'balance' sub command.
It was that way initially, but half of what restriper does is selective balancing. The other half is profile changing, but that also boils down to a balance. So I decided not to introduce another obscure term.
As for compatibility, I guess we will have to eat it and have everybody switch from "btrfs fi balance" to "btrfs fi balance start" if we want that shortest match behaviour. However if people feel strong about it I surely can put it under "restripe" and keep "btrfs fi balance" intact.
Chris ?
Quoted 2 lines
Finally, please could you update the man page too ?
I will, this version was not intended for pulling anyway because of this problem.
Thanks,
Ilya
Quoted 2 lines · On Sat, 7 Jan 2012 16:25:29 +0200 Ilya Dryomov <[email protected]> wrote:
IMHO it would be much better if we had our long names and a handful of predefined abbreviations (like ip command for example).
Does the ip command use just a handful of predefined abbrebiations?
ip addr show
ip add sho
ip ad sh
ip a s
all work.
which suggests to me they use exactly the same scheme as btrfs currently.
Signature · 8 lines
With respect, Roman ~~~~~~~~~~~~~~~~~~~~~~~~~~~ "Stallman had a printer, with code he could not see. So he began to tinker, and set the software free."
Quoted 8 lines · Roman Mamedov
Quoted 2 lines · On Sat, 7 Jan 2012 16:25:29 +0200 Ilya Dryomov <[email protected]> wrote:
IMHO it would be much better if we had our long names and a handful of predefined abbreviations (like ip command for example).
Does the ip command use just a handful of predefined abbrebiations?
Quoted 7 lines
ip addr show
ip add sho
ip ad sh
ip a sall work.
which suggests to me they use exactly the same scheme as btrfs currently.
Look at ntbl for ntable, tunl for tunnel, tap for tuntap, lst for list, etc. On top af that they are using a "first match" policy, which leads to a very simple and clean code and is not at all what btrfs uses:
ip route
ip rout
ip rou
ip ro
ip r
all work and expand to "ip route"
and if you want the "rule" sub-command, you have to use
ip ru
at the very least.
btrfs instead tries to be clever, and if ip was doing the same thing btrfs does you would get "ambiguous command 'r'" error in response to "ip r".
Thanks,
Ilya
Quoted 31 lines · On Saturday, 07 January, 2012 16:14:43 you wrote:
Quoted 8 lines · Roman Mamedov
On Sat, 7 Jan 2012 16:25:29 +0200
Quoted 2 lines · Ilya Dryomov
IMHO it would be much better if we had our long names and a handful of predefined abbreviations (like ip command for example).
Does the ip command use just a handful of predefined abbrebiations?
Quoted 7 lines
ip addr show
ip add sho
ip ad sh
ip a sall work.
which suggests to me they use exactly the same scheme as btrfs currently.Look at ntbl for ntable, tunl for tunnel, tap for tuntap, lst for list, etc. On top af that they are using a "first match" policy, which leads to a very simple and clean code and is not at all what btrfs uses:
ip route
ip rout
ip rou
ip ro
ip rall work and expand to "ip route"
and if you want the "rule" sub-command, you have to use
Quoted 7 lines
ip ru
at the very least.
btrfs instead tries to be clever, and if ip was doing the same thing btrfs does you would get "ambiguous command 'r'" error in response to "ip r".
You are right, but this is a bug.
1) btrfs s sn -> means btrfs subvolume snapshot
2) btrfs s se -> means btrfs subvolume set-default
3) btrfs s s -> is ambiguous command because it could means both 1) and 2)
However if we try 1) we get an error. But this is not the intended behavior. I have to investigate why.
BR
G.Baroncelli
Quoted 4 lines
Thanks,
Ilya
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
Quoted 1 line · On Saturday, 07 January, 2012 17:49:01 Goffredo Baroncelli wrote:
On Saturday, 07 January, 2012 16:14:43 you wrote:
[..]
Quoted 4 lines
Quoted 3 lines
btrfs instead tries to be clever, and if ip was doing the same thing btrfs does you would get "ambiguous command 'r'" error in response to "ip r".
Quoted 8 lines
You are right, but this is a bug.
1) btrfs s sn -> means btrfs subvolume snapshot
2) btrfs s se -> means btrfs subvolume set-default
3) btrfs s s -> is ambiguous command because it could means both 1) and 2)However if we try 1) we get an error. But this is not the intended behavior. I have to investigate why.
The change should be quite simple
btrfs.c +0 -0
@@ -268,8 +268,8 @@ static int check_ambiguity(struct Command *cmd, char
**argv)
if( cp->ncmds < i )
continue;- for( skip = 0, j = 0 ; j < i ; j++ )
- if( strcmp(cmd->cmds[j], cp->cmds[j])){
+ for( skip = 0, j = 0 ; j <= i ; j++ )
+ if( !strcmp(cmd->cmds[j], cp->cmds[j])){
skip=1;
break;
}But before issue a new patch I want to be sure about its correctness. I have to make a more formal test.
Quoted 7 lines
BR
G.BaroncelliQuoted 3 lines
Thanks,
Ilya
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