btrfs: a new tool to manage a btrfs filesystem
Hi all,
on the basis of the suggestion received, I update my btrfs tool.
The main changes are:
- removed the short form of the command (like '-C')
- deployed the "multi level" command (i.e.: btrfs snapshot create)
- split the source in three files. This because the new parses are quite big (about 295 lines; for example btrfsctl.c are only 239 lines).
The "multi level" command parser is quite flexible. They accept the full- length command (btrfs subvolume create) and a contract form (btrfs subvol cr). The commands may be arbitrary shortly (even 1 chars) but they have to be un- ambiguous. For example
- btrfs s s -> OK (matches 'btrfs subvolume snapshot' only)
- btrfs dev s -> FAIL (matches both 'btrfs dev show' and
'btrfs dev scan')
The parser highlights which part of the command are ambiguous.
This is a RFC because there is no agreement about the name of the command. I am proposing the following structure:
btrfs <object> <action>
where <object> are:
- subvolume (valid action: create, delete, snapshot, list [not implemented])
- filesystem (valid action: defrag, sync, resize [not implemented])
- device (valid action: add, delete, scan, show, balance)
You can find the source at
http://cassiopea.homelinux.net/git/btrfs-command.git
(commit 3deec45d18879d60b4032dc1f8895d7b7e1211ec, remember to switch to the "remotes/origin/multi-level-command" branch (I hate git!!!)
BR
G.Baroncelli
----
$ git diff remotes/origin/orig | diffstat Makefile | 6 btrfs.c | 73 ++++++ btrfs_cmds.c | 587 +++++++++++++++++++++++++++++++++++++++++++[...] btrfs_cmds.h | 30 ++ btrfs_cmds_parse.c | 296 +++++++++++++++++++++++++ man/Makefile | 5 man/btrfs.8.in | 148 ++++++++++++ 13 files changed, 1291 insertions(+), 2 deletions(-)
----
$ ./btrfs
Usage:
btrfs subvolume snapshot [<dest>/]<name>
Create a writeble snapshot of the subvolume <source> with
the name <name> in the <dest> directory.
btrfs subvolume delete <subvolume>
Delete the subvolume <subvolume>.
btrfs subvolume create [<dest>/]<name>
Create a subvolume in <dest> (or the current directory if
not passed).
btrfs filesystem defrag <file>|<dir> [<file>|<dir>...]
Defragment a file or a directory.
btrfs device scan [<device> [<device>..]
Scan all device for or the passed device for a btrfs
filesystem.
btrfs filesystem sync <path>
Force a fs sync on the filesystem <path>
btrfs filesystem resize [+/-]<newsize>[gkm]|max <filesystem>
Resize the file system. If 'max' is passed, the filesystem
will occupe all available space on the device.
btrfs device show [<dev>|<label>...]
Show the btrfs devices
btrfs device balance <path>
Balance the chunk across the device
btrfs device add <dev> [<dev>..] <path>
Add a device to a filesystem
btrfs device delete <dev> [<dev>..] <path>
Remove a device from a filesystem btrfs help|--help|-h
Show the help.
Btrfs v0.19-22-g07a97f0-dirty
----
$ man man/btrfs.8.in | cat BTRFS(8) btrfs BTRFS(8)
NAME
btrfs - control a btrfs filesystem
SYNOPSIS
btrfs subvolume snapshot <source> [<dest>/]<name>
btrfs subvolume delete <subvolume>
btrfs subvolume create [<dest>/]<name>
btrfs filesystem defrag <file>|<dir> [<file>|<dir>...]
btrfs filesystem fssync <path>
btrfs filesystem resize [+/-]<size>[gkm]|max <filesystem>
btrfs device scan [<device> [<device>..]]
btrfs device show <dev>|<label> [<dev>|<label>...]
btrfs device balance <path>
btrfs device add <dev> [<dev>..] <path>
btrfs device delete <dev> [<dev>..] <path> ]
btrfs help|--help|-h
DESCRIPTION
btrfs is used to control the filesystem and the files and directo‐ ries stored. It is the tool to create or destroy a new snapshot or a new subvolume for the filesystem, to defrag a file or a directory, to flush the dato to the disk, to resize the filesystem, to scan the device.
It is possible to abbreviate the commands unless the commands are ambiguous. For example: it is possible to run btrfs sub snaps
instead of btrfs subvolume snapshot. But btrfs dev s is not
allowed, because dev s may be interpreted both as device show and as device scan. In this case btrfs returns an error.
If a command is terminated by --help , the relevant help is showed. If the passed command matches more commands, the help of all the matched commands are showed. For example btrfs dev --help shows the help of all device* command.
COMMANDS
subvolume snapshot <source> [<dest>/]<name>
Create a writeble snapshot of the subvolume <source> with the name <name> in the <dest> directory. If <source> is not a subvolume, btrfs returns an error.
subvolume delete <subvolume>
Delete the subvolume <subvolume>. If <subvolume> is not a subvolume, btrfs returns an error.
subvolume create [<dest>/]<name>
Create a subvolume in <dest> (or in the current directory if <dest> is not passed).
filesystem defrag <file>|<dir> [<file>|<dir>...]
Defragment files and/or directories.
device scan [<device> [<device>..]]
Scan devices for a btrfs filesystem. If no devices are passed, btrfs scans all the block devices.
filesystem fssync <path>
Force a sync for the filesystem identified by <path>.
filesystem resize [+/-]<size>[gkm]|max <filesystem>
Resize a file system identified by <path>. The <size> param‐ eter specifies the new size of the filesystem. If the prefix
+ or - is present the size is increased or decreased by the quantity <size>. If no units are specified, the unit of the <size> parameter is the byte. Optionally, the size parameter may be suffixed by one of the following the units designa‐
tors: 'K', 'M', or 'G', kilobytes, megabytes, or gigabytes, respectively.
If 'max' is passed, the filesystem will occupy all available space on the volume(s).
The resize command does not manipulate the size of underlying partitions. If you wish to enlarge/reduce a filesystem, you must make sure you can expand/reduce the size of the parti‐ tion also.
device show [<dev>|<label>...]
Show the btrfs devices with some additional info. If no devices or labels are passed, btrfs scans all the block devices.
device balance|-b <path>
Balance the chunk of the filesystem identified by <path> across the devices.
device add <dev> [<dev>..] <path>
Add device(s) to the filesystem identified by <path>.
device delete <dev> [<dev>..] <path>
Remove device(s) from a filesystem identified by <path>.
EXIT STATUS
btrfs returns a zero exist status if it succeeds. Non zero is returned in case of failure.
AVAILABILITY
btrfs is part of btrfs-progs. Btrfs filesystem is currently under heavy development, and not suitable for any uses other than bench‐
marking and review. Please refer to the btrfs wiki
http://btrfs.wiki.kernel.org for further details.
SEE ALSO
mkfs.btrfs(8)
btrfs BTRFS(8)
Signature · 2 lines
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijackATinwind.it> Key fingerprint = 4769 7E51 5293 D36C 814E C054 BF04 F161 3DC5 0512
Quoted 8 lines · Goffredo Baroncelli
Hi all,
on the basis of the suggestion received, I update my btrfs tool.
The main changes are:
- removed the short form of the command (like '-C')
- deployed the "multi level" command (i.e.: btrfs snapshot create)
- split the source in three files. This because the new parses are qu=
ite big
Quoted 3 lines
(about =C2=A0295 lines; for example
btrfsctl.care only 239 lines).The "multi level" command parser is quite flexible. They accept the f=
ull-
Quoted 1 line
length command (btrfs subvolume create) and a contract form (btrfs su=
bvol cr).
Quoted 1 line
The commands may be arbitrary shortly (even 1 chars) but they have to=
be un-
Quoted 2 lines
ambiguous. For example
- btrfs s s =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -> OK (matches =
'btrfs subvolume snapshot' only)
Quoted 1 line
- btrfs dev s =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -> FAIL (matches bot=
h 'btrfs dev show' and
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'btrfs dev scan')
Quoted 4 lines
The parser highlights which part of the command are ambiguous.
This is a RFC because there is no agreement about the name of the com=
mand.
Quoted 6 lines
I am proposing the following structure:
=C2=A0 btrfs <object> <action>
where <object> are:
- subvolume (valid action: create, delete, snapshot, list [not implem=
ented])
Quoted 6 lines
- filesystem (valid action: defrag, sync, resize [not implemented])
- device (valid action: add, delete, scan, show, balance)You can find the source at
=C2=A0 =C2=A0 =C2=A0 =C2=A0http://cassiopea.homelinux.net/git/btrfs-c=
ommand.git
Quoted 2 lines
(commit
3deec45d18879d60b4032dc1f8895d7b7e1211ec, remember to switch =
to the
Quoted 9 lines
"remotes/origin/multi-level-command" branch (I hate git!!!)
BR
G.Baroncelli
----$ git diff remotes/origin/orig | diffstat =C2=A0Makefile =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=
=A06
Quoted 1 line
=C2=A0btrfs.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0=
73 ++++++
Quoted 1 line
=C2=A0btrfs_cmds.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0587 ++++++++++=
+++++++++++++++++++++++++++++++++[...]
Quoted 11 lines
=C2=A0btrfs_cmds.h =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 30 ++ =C2=A0btrfs_cmds_parse.c =C2=A0 | =C2=A0296 +++++++++++++++++++++++++ =C2=A0man/Makefile =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A05 =C2=A0man/btrfs.8.in =C2=A0 =C2=A0 =C2=A0 | =C2=A0148 ++++++++++++ =C2=A013 files changed, 1291 insertions(+), 2 deletions(-)
----
$ ./btrfs Usage: =C2=A0 =C2=A0 =C2=A0 =C2=A0btrfs subvolume snapshot [<dest>/]<name> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Create a write=
ble snapshot of the subvolume <source> with
Quoted 4 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0the name <name= in the <dest> directory.
=C2=A0 =C2=A0 =C2=A0 =C2=A0btrfs subvolume delete <subvolume> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Delete the sub=
volume <subvolume>.
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0btrfs subvolume create [<dest>/]<name> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Create a subvo=
lume in <dest> (or the current directory if
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0not passed). =C2=A0 =C2=A0 =C2=A0 =C2=A0btrfs filesystem defrag <file>|<dir> [<fil=
e>|<dir>...]
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Defragment a f=
ile or a directory.
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0btrfs device scan [<device> [<device>..] =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Scan all devic=
e for or the passed device for a btrfs
Quoted 3 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0filesystem. =C2=A0 =C2=A0 =C2=A0 =C2=A0btrfs filesystem sync <path> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Force a fs syn=
c on the filesystem <path>
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0btrfs filesystem resize [+/-]<newsize>[gkm=
]|max <filesystem>
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Resize the fil=
e system. If 'max' is passed, the filesystem
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0will occupe al=
l available space on the device.
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0btrfs device show [<dev>|<label>...] =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Show the btrfs=
devices
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0btrfs device balance <path> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Balance the ch=
unk across the device
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0btrfs device add <dev> [<dev>..] <path> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Add a device t=
o a filesystem
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0btrfs device delete <dev> [<dev>..] <path> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Remove a devic=
e from a filesystem
Quoted 10 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0btrfs help|--help|-h
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Show the help.Btrfs v0.19-22-g07a97f0-dirty
----
$ man man/btrfs.8.in | cat BTRFS(8) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 btrfs =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 BTRFS(8)
Quoted 10 lines
NAME
=C2=A0 =C2=A0 =C2=A0 btrfs - control a btrfs filesystemSYNOPSIS
=C2=A0 =C2=A0 =C2=A0 btrfs subvolume snapshot <source> [<dest>/]<name=
Quoted 5 lines
=C2=A0 =C2=A0 =C2=A0 btrfs subvolume delete <subvolume>
=C2=A0 =C2=A0 =C2=A0 btrfs subvolume create [<dest>/]<name>
=C2=A0 =C2=A0 =C2=A0 btrfs filesystem defrag <file>|<dir> [<file>|<di=
r>...]
Quoted 4 lines
=C2=A0 =C2=A0 =C2=A0 btrfs filesystem fssync <path>
=C2=A0 =C2=A0 =C2=A0 btrfs filesystem resize [+/-]<size>[gkm]|max <fi=
lesystem>
Quoted 4 lines
=C2=A0 =C2=A0 =C2=A0 btrfs device scan [<device> [<device>..]]
=C2=A0 =C2=A0 =C2=A0 btrfs device show <dev>|<label> [<dev>|<label>..=
=2E]
Quoted 5 lines
=C2=A0 =C2=A0 =C2=A0 btrfs device balance <path>
=C2=A0 =C2=A0 =C2=A0 btrfs device add <dev> [<dev>..] <path>
Quoted 7 lines
=C2=A0 =C2=A0 =C2=A0 btrfs device delete <dev> [<dev>..] <path> ]
=C2=A0 =C2=A0 =C2=A0 btrfs help|--help|-h
DESCRIPTION
=C2=A0 =C2=A0 =C2=A0 btrfs =C2=A0is =C2=A0used to control the filesys=
tem and the files and directo=E2=80=90
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 ries stored. It is the tool to create or destroy=
a new snapshot or a
-create or destroy a new snapshot
+create or destroy a snapshot
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 new =C2=A0subvolume =C2=A0for the filesystem, to=
defrag a file or a directory,
-new subvolume for the filesystem, to defrag a file or a directory +subvolume for the filesystem, defrag a file or a directory
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 to flush the dato to the disk, to resize the fil=
esystem, to scan the
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 device.
-to flush the dato to the disk, to resize the filesystem, to scan the +flush the data to the disk, resize the filesystem, scan the
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 It =C2=A0is =C2=A0possible to abbreviate the com=
mands unless the commands =C2=A0are
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 ambiguous. =C2=A0For example: it is =C2=A0possib=
le =C2=A0to =C2=A0run =C2=A0btrfs =C2=A0sub =C2=A0snaps
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 instead =C2=A0of =C2=A0btrfs =C2=A0subvolume =C2=
=A0snapshot. =C2=A0 But =C2=A0btrfs =C2=A0dev =C2=A0s is not
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 allowed, because dev s may be interpreted both a=
s device show and as
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 device scan. =C2=A0In this case btrfs returns an=
error.
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 If =C2=A0a command is terminated by --help , the=
relevant help is showed.
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 If the passed command matches more commands, the=
=C2=A0help =C2=A0of =C2=A0all =C2=A0the
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 matched =C2=A0commands are showed. For example b=
trfs dev --help shows the
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 help of all device* command.
Several parts above have more than one space between words, and less than two spaces between sentences.
Quoted 4 lines
COMMANDS
=C2=A0 =C2=A0 =C2=A0 subvolume snapshot <source> [<dest>/]<name> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Create a writeble sna=
pshot of the subvolume <source> with the
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name =C2=A0<name> =C2=
=A0in =C2=A0the =C2=A0<dest> directory. If <source> is not a
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0subvolume, btrfs retu=
rns an error.
Quoted 1 line
-Create a writeble snapshot of the subvolume <source> with the +Create a writeable snapshot of the subvolume <source> with the
Quoted 3 lines
=C2=A0 =C2=A0 =C2=A0 subvolume delete <subvolume>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Delete the subvolume =
<subvolume>. If =C2=A0<subvolume> =C2=A0is =C2=A0not =C2=A0a
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0subvolume, btrfs retu=
rns an error.
Quoted 4 lines
=C2=A0 =C2=A0 =C2=A0 subvolume create [<dest>/]<name> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Create =C2=A0a subvol=
ume in <dest> (or in the current directory if
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<dest> is not passed)=
=2E
Quoted 4 lines
=C2=A0 =C2=A0 =C2=A0 filesystem defrag <file>|<dir> [<file>|<dir>...] =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Defragment files and/=
or directories.
Quoted 1 line
-filesystem defrag <file>|<dir> [<file>|<dir>...] +filesystem defragment <file>|<dir> [<file>|<dir>...]
Since the commands can be arbitrarily shortened, might as well spell the full command out.
Quoted 3 lines
=C2=A0 =C2=A0 =C2=A0 device scan [<device> [<device>..]] =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Scan devices for =C2=A0=
a =C2=A0btrfs =C2=A0filesystem. =C2=A0If =C2=A0no =C2=A0devices =C2=A0a= re
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0passed, btrfs scans a=
ll the block devices.
Quoted 4 lines
=C2=A0 =C2=A0 =C2=A0 filesystem fssync <path>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Force a sync for the =
filesystem identified by <path>.
Quoted 1 line
-filesystem fssync <path>
+filesystem sync <path>
You have done away with specifying what it is working on. I think that's best, it just needs good error messages to handle the unimplemented cases at the moment.
I would also rename "fssync" to "sync".
Quoted 3 lines
=C2=A0 =C2=A0 =C2=A0 filesystem resize [+/-]<size>[gkm]|max <filesyst=
em>
-filesystem resize [+/-]<size>[gkm]|max <filesystem> +filesystem resize [+/-]<size>[gkm]|max <dev>
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Resize a file system =
identified by <path>. =C2=A0The <size> param=E2=80=90
-Resize a file system identified
+Resize a filesystem identified
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0eter specifies the ne=
w size of the filesystem. =C2=A0If the prefix
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0+ =C2=A0or =C2=A0- is=
present the size is increased or decreased by the
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0quantity <size>. =C2=A0=
If no units are specified, the unit of =C2=A0the
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<size> parameter is t=
he byte. =C2=A0Optionally, the size parameter
-<size> parameter is the byte.
+<size> parameter defaults to bytes.
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0may be suffixed by on=
e of the following =C2=A0the =C2=A0units =C2=A0designa=E2=80=90
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tors: =C2=A0'K', =C2=A0=
'M', or 'G', kilobytes, megabytes, or gigabytes,
Quoted 3 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0respectively.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0If 'max' is passed, t=
he filesystem will occupy all =C2=A0available
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0space on the volume(s=
).
-space on the volume(s).
+space on the block device specified.
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0The resize command do=
es not manipulate the size of underlying
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0partitions. =C2=A0If =
you wish to enlarge/reduce a filesystem, =C2=A0you
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0must =C2=A0make =C2=A0=
sure you can expand/reduce the size of the parti=E2=80=90
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tion also.
There are multiple ways to resize a btrfs filesystem. You can add add or remove devices or shrink or enlarge the devices the filesystem is already on. This operation only works on one block device at a time so I think it should be under device instead of filesystem.
Quoted 3 lines
=C2=A0 =C2=A0 =C2=A0 device show [<dev>|<label>...]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Show the btrfs device=
s =C2=A0with =C2=A0some =C2=A0additional =C2=A0info. =C2=A0If =C2=A0no
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0devices =C2=A0or =C2=A0=
labels =C2=A0are =C2=A0passed, =C2=A0btrfs =C2=A0scans all the block
Quoted 5 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0devices.
=C2=A0 =C2=A0 =C2=A0 device balance|-b <path>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Balance the chunk of =
=C2=A0the =C2=A0filesystem =C2=A0identified =C2=A0by =C2=A0<path>
Quoted 2 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0across the devices.
I think this is a bit ambiguous. While true, it is "balancing the filesystem across devices" and "btrfs device balance" is quite descriptive, it is working against a path and not a block device for its argument. I think that just tips the scales enough to put it under filesystem instead of device.
Quoted 3 lines
=C2=A0 =C2=A0 =C2=A0 device add <dev> [<dev>..] <path> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Add device(s) to the =
filesystem identified by <path>.
Quoted 4 lines
=C2=A0 =C2=A0 =C2=A0 device delete <dev> [<dev>..] <path> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Remove device(s) from=
a filesystem identified by <path>.
Quoted 3 lines
EXIT STATUS
=C2=A0 =C2=A0 =C2=A0 btrfs =C2=A0returns =C2=A0a =C2=A0zero =C2=A0exi=
st =C2=A0status =C2=A0if =C2=A0it succeeds. Non zero is
Quoted 5 lines
=C2=A0 =C2=A0 =C2=A0 returned in case of failure.
AVAILABILITY
=C2=A0 =C2=A0 =C2=A0 btrfs is part of btrfs-progs. Btrfs filesystem =C2=
=A0is =C2=A0currently =C2=A0under
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 heavy =C2=A0development, =C2=A0and not suitable =
for any uses other than bench=E2=80=90
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 marking =C2=A0 and =C2=A0 review. =C2=A0 =C2=A0P=
lease =C2=A0 refer =C2=A0 to =C2=A0 the =C2=A0 btrfs =C2=A0 =C2=A0wiki
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 http://btrfs.wiki.kernel.org for further details=
=2E
Quoted 7 lines
SEE ALSO
=C2=A0 =C2=A0 =C2=A0mkfs.btrfs(8)btrfs =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0BTRFS(8)
Quoted 4 lines
--
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijackATi=
nwind.it>
Quoted 1 line
Key fingerprint =3D 4769 7E51 5293 D36C 814E =C2=A0C054 BF04 F161 3DC=
5 0512
Quoted 1 line
--
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
Hi Mike,
Thanks, I implemented all your suggestion except the one related to the=
resize=20
command.
These patches doesn't address problems related to btrfs itself, and now=
the=20
interface of the btrfs function is based on the filesystem and not on t= he=20
device.
But I agree with you that today if a btrfs filesystem relies on more th= an one=20
device, is not clear how "shrink" the occupation of one specific device= =20
(remove the device, resize the partition and add the device again ?)=20
I hope to post the new patches (with the implementation of the resize i= octl=20
call) in this week end.
BR
Goffredo
Quoted 10 lines · Mike Fedyk
Quoted 8 lines · Goffredo Baroncelli
Hi all,
on the basis of the suggestion received, I update my btrfs tool.
The main changes are:
- removed the short form of the command (like '-C')
- deployed the "multi level" command (i.e.: btrfs snapshot create)
- split the source in three files. This because the new parses are =
quite=20
big
Quoted 3 lines
Quoted 3 lines
(about 295 lines; for example
btrfsctl.care only 239 lines).The "multi level" command parser is quite flexible. They accept the=
full-
Quoted 1 line
Quoted 1 line
length command (btrfs subvolume create) and a contract form (btrfs =
subvol=20
cr).
Quoted 1 line
Quoted 1 line
The commands may be arbitrary shortly (even 1 chars) but they have =
to be=20
un-
Quoted 2 lines
Quoted 2 lines
ambiguous. For example
- btrfs s s -> OK (matches 'btrfs subvolume snapshot' o=
nly)
Quoted 6 lines
Quoted 6 lines
- btrfs dev s -> FAIL (matches both 'btrfs dev show' and
'btrfs dev scan')The parser highlights which part of the command are ambiguous.
This is a RFC because there is no agreement about the name of the c=
ommand.
Quoted 6 lines
Quoted 6 lines
I am proposing the following structure:
btrfs <object> <action>
where <object> are:
- subvolume (valid action: create, delete, snapshot, list [not=20
implemented])
Quoted 8 lines
Quoted 8 lines
- filesystem (valid action: defrag, sync, resize [not implemented])
- device (valid action: add, delete, scan, show, balance)You can find the source at
http://cassiopea.homelinux.net/git/btrfs-command.git
(commit
3deec45d18879d60b4032dc1f8895d7b7e1211ec, remember to switc=
h to=20
the
Quoted 11 lines
Quoted 11 lines
"remotes/origin/multi-level-command" branch (I hate git!!!)
BR
G.Baroncelli
----$ git diff remotes/origin/orig | diffstat Makefile | 6 btrfs.c | 73 ++++++ btrfs_cmds.c | 587=20
+++++++++++++++++++++++++++++++++++++++++++[...]
Quoted 11 lines
Quoted 11 lines
btrfs_cmds.h | 30 ++ btrfs_cmds_parse.c | 296 +++++++++++++++++++++++++ man/Makefile | 5 man/btrfs.8.in | 148 ++++++++++++ 13 files changed, 1291 insertions(+), 2 deletions(-)----
$ ./btrfs Usage: btrfs subvolume snapshot [<dest>/]<name> Create a writeble snapshot of the subvolume <source>=
with
Quoted 5 lines
Quoted 5 lines
the name <name> in the <dest> directory.
btrfs subvolume delete <subvolume>
Delete the subvolume <subvolume>.
btrfs subvolume create [<dest>/]<name>
Create a subvolume in <dest> (or the current directo=
ry if
Quoted 10 lines
Quoted 10 lines
not passed).
btrfs filesystem defrag <file>|<dir> [<file>|<dir>...]
Defragment a file or a directory.
btrfs device scan [<device> [<device>..]
Scan all device for or the passed device for a btrfs filesystem.
btrfs filesystem sync <path>
Force a fs sync on the filesystem <path>
btrfs filesystem resize [+/-]<newsize>[gkm]|max <filesystem>
Resize the file system. If 'max' is passed, the file=
system
Quoted 13 lines
Quoted 13 lines
will occupe all available space on the device.
btrfs device show [<dev>|<label>...]
Show the btrfs devices
btrfs device balance <path>
Balance the chunk across the device
btrfs device add <dev> [<dev>..] <path>
Add a device to a filesystem
btrfs device delete <dev> [<dev>..] <path>
Remove a device from a filesystembtrfs help|--help|-h
Show the help.
Quoted 6 lines
Quoted 6 lines
Btrfs v0.19-22-g07a97f0-dirty
----
$ man man/btrfs.8.in | cat BTRFS(8) btrfs =20
BTRFS(8)
Quoted 27 lines
Quoted 27 lines
NAME
btrfs - control a btrfs filesystemSYNOPSIS
btrfs subvolume snapshot <source> [<dest>/]<name>btrfs subvolume delete <subvolume>
btrfs subvolume create [<dest>/]<name>
btrfs filesystem defrag <file>|<dir> [<file>|<dir>...]
btrfs filesystem fssync <path>
btrfs filesystem resize [+/-]<size>[gkm]|max <filesystem>
btrfs device scan [<device> [<device>..]]
btrfs device show <dev>|<label> [<dev>|<label>...]
btrfs device balance <path>
btrfs device add <dev> [<dev>..] <path>
Quoted 7 lines
Quoted 7 lines
btrfs device delete <dev> [<dev>..] <path> ]
btrfs help|--help|-h
DESCRIPTION
btrfs is used to control the filesystem and the files and d=
irecto=E2=80=90
Quoted 1 line
Quoted 1 line
ries stored. It is the tool to create or destroy a new snapsh=
ot or a
Quoted 5 lines
=20
(quoted diff) +1
-1-create or destroy a new snapshot +create or destroy a snapshot=20
Quoted 1 line
new subvolume for the filesystem, to defrag a file or a dir=
ectory,
Quoted 5 lines
=20
(quoted diff) +1
-1-new subvolume for the filesystem, to defrag a file or a directory +subvolume for the filesystem, defrag a file or a directory=20
Quoted 1 line
to flush the dato to the disk, to resize the filesystem, to s=
can the
Quoted 7 lines
Quoted 1 line
device.
=20
(quoted diff) +1
-1-to flush the dato to the disk, to resize the filesystem, to scan the +flush the data to the disk, resize the filesystem, scan the=20
Quoted 2 lines
It is possible to abbreviate the commands unless the comman=
ds are
Quoted 1 line
Quoted 1 line
ambiguous. For example: it is possible to run btrfs sub=
snaps
Quoted 1 line
Quoted 1 line
instead of btrfs subvolume snapshot. But btrfs dev s=
is not
Quoted 1 line
Quoted 1 line
allowed, because dev s may be interpreted both as device show=
and as
Quoted 3 lines
Quoted 3 lines
device scan. In this case btrfs returns an error.
If a command is terminated by --help , the relevant help is =
showed.
Quoted 1 line
Quoted 1 line
If the passed command matches more commands, the help of a=
ll the
Quoted 1 line
Quoted 1 line
matched commands are showed. For example btrfs dev --help sh=
ows the
Quoted 10 lines
Quoted 2 lines
help of all device* command.
=20
Several parts above have more than one space between words, and less than two spaces between sentences.
=20Quoted 4 lines
COMMANDS
subvolume snapshot <source> [<dest>/]<name>
Create a writeble snapshot of the subvolume <source> w=
ith the
Quoted 1 line
Quoted 1 line
name <name> in the <dest> directory. If <source> i=
s not a
Quoted 9 lines
Quoted 2 lines
subvolume, btrfs returns an error.
=20
(quoted diff) +1
-1-Create a writeble snapshot of the subvolume <source> with the +Create a writeable snapshot of the subvolume <source> with the=20
Quoted 3 lines
subvolume delete <subvolume>
Delete the subvolume <subvolume>. If <subvolume> is =
not a
Quoted 5 lines
Quoted 5 lines
subvolume, btrfs returns an error.
subvolume create [<dest>/]<name>
Create a subvolume in <dest> (or in the current direc=
tory if
Quoted 9 lines
Quoted 6 lines
<dest> is not passed).
filesystem defrag <file>|<dir> [<file>|<dir>...]
Defragment files and/or directories.=20
(quoted diff) +1
-1-filesystem defrag <file>|<dir> [<file>|<dir>...] +filesystem defragment <file>|<dir> [<file>|<dir>...]
Quoted 7 lines
=20
Since the commands can be arbitrarily shortened, might as well spell the full command out.
=20Quoted 3 lines
device scan [<device> [<device>..]]
Scan devices for a btrfs filesystem. If no devic=
es are
Quoted 21 lines
Quoted 6 lines
passed, btrfs scans all the block devices.
filesystem fssync <path>
Force a sync for the filesystem identified by <path>.=20
(quoted diff) +1
-1-filesystem fssync <path> +filesystem sync <path>=20
You have done away with specifying what it is working on. I think that's best, it just needs good error messages to handle the unimplemented cases at the moment.
I would also rename "fssync" to "sync".
=20Quoted 3 lines
filesystem resize [+/-]<size>[gkm]|max <filesystem>
=20
(quoted diff) +1
-1-filesystem resize [+/-]<size>[gkm]|max <filesystem> +filesystem resize [+/-]<size>[gkm]|max <dev>
Quoted 2 lines
=20
Quoted 1 line
Resize a file system identified by <path>. The <size>=
param=E2=80=90
Quoted 5 lines
=20
(quoted diff) +1
-1-Resize a file system identified +Resize a filesystem identified=20
Quoted 1 line
eter specifies the new size of the filesystem. If the=
prefix
Quoted 1 line
Quoted 1 line
+ or - is present the size is increased or decreased=
by the
Quoted 1 line
Quoted 1 line
quantity <size>. If no units are specified, the unit =
of the
Quoted 1 line
Quoted 1 line
<size> parameter is the byte. Optionally, the size pa=
rameter
Quoted 5 lines
=20
-<size> parameter is the byte.
+<size> parameter defaults to bytes.
=20Quoted 1 line
may be suffixed by one of the following the units d=
esigna=E2=80=90
Quoted 1 line
Quoted 1 line
tors: 'K', 'M', or 'G', kilobytes, megabytes, or gig=
abytes,
Quoted 3 lines
Quoted 3 lines
respectively.
If 'max' is passed, the filesystem will occupy all av=
ailable
Quoted 7 lines
Quoted 1 line
space on the volume(s).
=20
(quoted diff) +1
-1-space on the volume(s). +space on the block device specified.=20
Quoted 2 lines
The resize command does not manipulate the size of und=
erlying
Quoted 1 line
Quoted 1 line
partitions. If you wish to enlarge/reduce a filesyste=
m, you
Quoted 1 line
Quoted 1 line
must make sure you can expand/reduce the size of the=
parti=E2=80=90
Quoted 4 lines
Quoted 2 lines
tion also.
=20
There are multiple ways to resize a btrfs filesystem. You can add ad=
d
Quoted 7 lines
or remove devices or shrink or enlarge the devices the filesystem is already on. This operation only works on one block device at a time so I think it should be under device instead of filesystem. =20
Quoted 3 lines
device show [<dev>|<label>...]
Show the btrfs devices with some additional info. =
If no
Quoted 1 line
Quoted 1 line
devices or labels are passed, btrfs scans all th=
e block
Quoted 5 lines
Quoted 5 lines
devices.
device balance|-b <path>
Balance the chunk of the filesystem identified by =
<path>
Quoted 10 lines
Quoted 2 lines
across the devices.
=20
I think this is a bit ambiguous. While true, it is "balancing the filesystem across devices" and "btrfs device balance" is quite descriptive, it is working against a path and not a block device for its argument. I think that just tips the scales enough to put it under filesystem instead of device.
=20Quoted 1 line
Quoted 10 lines
Quoted 6 lines
device add <dev> [<dev>..] <path>
Add device(s) to the filesystem identified by <path>.device delete <dev> [<dev>..] <path>
Remove device(s) from a filesystem identified by <path=.
Quoted 3 lines
EXIT STATUS
btrfs returns a zero exist status if it succeeds. Non =
zero is
Quoted 5 lines
Quoted 5 lines
returned in case of failure.
AVAILABILITY
btrfs is part of btrfs-progs. Btrfs filesystem is currently=
under
Quoted 1 line
Quoted 1 line
heavy development, and not suitable for any uses other than=
bench=E2=80=90
Quoted 1 line
Quoted 1 line
marking and review. Please refer to the btrfs =
wiki
Quoted 8 lines
Quoted 8 lines
http://btrfs.wiki.kernel.org for further details.
SEE ALSO
mkfs.btrfs(8)btrfs =20
BTRFS(8)
Quoted 4 lines
Quoted 4 lines
--
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo)=20
<kreijackATinwind.it>
Quoted 1 line
Quoted 1 line
Key fingerprint =3D 4769 7E51 5293 D36C 814E C054 BF04 F161 3DC5 0=
512
Quoted 3 lines
Quoted 1 line
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs=
" in
Quoted 3 lines
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
=20
--=20
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwi= nd.it>
Key fingerprint =3D 4769 7E51 5293 D36C 814E C054 BF04 F161 3DC5 0512 --
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