introduce btrfs filesystem property command
Subsystems (2)
cover introduce btrfs filesystem property command
This patchset introduces the btrfs filesystem property command. It is the result of a discussion we had on IRC. I tried to make the properties interface as generic and extensible as possible. Comments are welcome.
Currently the command looks like this:
btrfs fi prop /path/to/object [name[=value]]
Some people may prefer other forms. For example I got suggestions for these forms:
btrfs set/get /path/to/object [name [value]]
btrfs prop /pach/to/object [name[=value]] (and also without the =)
I'm open to more suggestions and a discussion on this. I'm definitely for removing the fi[lesystem] prefix but I'm neutral to the other suggestions made so far.
For now, I've implemented three properties:
1. read-only. Usable on subvolumes to toggle the read-only flags.
2. label. I looked through btrfs to find good examples of things that could be moved to the new properties interface and the filesystem label looked like a good one. There are for sure more, but that is something for later (and maybe for someone else). I would suggest to move everthing that makes sense over to the props interface and mark the old interfaces as deprecated. Comments on this are welcome.
Alex.
Alexander Block (5):
Btrfs-progs: add BTRFS_IOC_SUBVOL_GET/SETFLAGS to ioctl.h
Btrfs-progs: move skip_prefix and prefixcmp to utils.c
Btrfs-progs: let get_label return the label instead of of printing it
Btrfs-progs: make filesystem_cmd_group non const
Btrfs-progs: introduce btrfs filesystem property command
Makefile | 3 +- btrfs.c | 19 +-- btrfslabel.c | 13 +- btrfslabel.h | 4 +- cmds-filesystem.c | 115 +++++++++++++- commands.h | 9 +- help.c | 2 + ioctl.h | 2 + props.c | 460 +++++++++++++++++++++++++++++++++++++++++++++++++++++ props.h | 45 ++++++ utils.c | 15 ++ utils.h | 3 + 12 files changed, 659 insertions(+), 31 deletions(-) create mode 100644 props.c create mode 100644 props.h
Signature · 1 line
1.7.10
PATCH 1/5 Btrfs-progs: add BTRFS_IOC_SUBVOL_GET/SETFLAGS to ioctl.h
Btrfs send/receive needs this ioctl to make a subvolume r/o after it was received.
--- ioctl.h | 2 ++ 1 file changed, 2 insertions(+)
ioctl.h +2 -0
@@ -312,6 +312,8 @@ struct btrfs_ioctl_logical_ino_args { struct btrfs_ioctl_space_args)#define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \ struct btrfs_ioctl_vol_args_v2) +#define BTRFS_IOC_SUBVOL_GETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 25, __u64) +#define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)#define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \ struct btrfs_ioctl_scrub_args)#define BTRFS_IOC_SCRUB_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28)
Signature · 1 line
1.7.10
PATCH 2/5 Btrfs-progs: move skip_prefix and prefixcmp to utils.c
In reply to Alexander BlockNeeded by btrfs fi prop.
--- btrfs.c | 17 ++--------------- commands.h | 2 -- help.c | 2 ++ utils.c | 15 +++++++++++++++ utils.h | 3 +++ 5 files changed, 22 insertions(+), 17 deletions(-)
btrfs.c +2 -15
@@ -19,7 +19,9 @@#include <stdlib.h> #include <string.h> +#include "ctree.h" #include "commands.h" +#include "utils.h" #include "version.h" static const char *const btrfs_cmd_group_usage[] = {
@@ -32,21 +34,6 @@ static const char btrfs_cmd_group_info[] =char argv0_buf[ARGV0_BUF_SIZE ] ="btrfs" ; -static inline const char *skip_prefix (const char *str,const char *prefix) -{ -size_t len =strlen (prefix); -return strncmp (str, prefix, len) ?NULL : str + len; -} - -int prefixcmp (const char *str,const char *prefix) -{ -for (; ; str++, prefix++) -if (!*prefix) -return 0 ; -else if (*str != *prefix) -return (unsigned char )*prefix - (unsigned char )*str; -} -static int parse_one_token (const char *arg,const struct cmd_group *grp,const struct cmd_struct **cmd_ret) {
commands.h +0 -2
@@ -58,8 +58,6 @@ struct cmd_group { };/* btrfs.c */ -int prefixcmp (const char *str,const char *prefix); -int check_argc_exact (int nargs,int expected);int check_argc_min (int nargs,int expected);int check_argc_max (int nargs,int expected);
help.c +2 -0
@@ -18,7 +18,9 @@#include <stdlib.h> #include <string.h> +#include "ctree.h" #include "commands.h" +#include "utils.h" extern char argv0_buf[ARGV0_BUF_SIZE ];
utils.c +15 -0
@@ -1216,3 +1216,18 @@ scan_again:return 0 ; } +const char *skip_prefix (const char *str,const char *prefix) +{ +size_t len =strlen (prefix); +return strncmp (str, prefix, len) ?NULL : str + len; +} + +int prefixcmp (const char *str,const char *prefix) +{ +for (; ; str++, prefix++) +if (!*prefix) +return 0 ; +else if (*str != *prefix) +return (unsigned char )*prefix - (unsigned char )*str; +} +
utils.h +3 -0
@@ -46,4 +46,7 @@ int check_label(char *input);int get_mountpt (char *dev,char *mntpt,size_t size);int btrfs_scan_block_devices (int run_ioctl); + +const char *skip_prefix (const char *str,const char *prefix); +int prefixcmp (const char *str,const char *prefix);#endif
Signature · 1 line
1.7.10
PATCH 3/5 Btrfs-progs: let get_label return the label instead of of printing it
In reply to Alexander Blockget_label prints the label at the moment. Change this so that the label is returned and printing is done by the caller.
Also bail out when open_ctree failed to avoid a crash when btrfs fi label is called on a device with no btrfs on it.
--- btrfslabel.c | 13 ++++++++----- btrfslabel.h | 4 ++-- cmds-filesystem.c | 15 ++++++++++++--- 3 files changed, 22 insertions(+), 10 deletions(-)
btrfslabel.c +8 -5
@@ -67,7 +67,7 @@ static void change_label_unmounted(char *dev, char *nLabel)close_ctree (root); } -static void get_label_unmounted (char *dev) +static int get_label_unmounted (char *dev,char **label) {struct btrfs_root *root;
@@ -75,14 +75,18 @@ static void get_label_unmounted(char *dev)* and as read-only. */ root =open_ctree (dev,0 ,0 ); +if (!root) +return -1 ; -fprintf (stdout,"%s\n" , root->fs_info->super_copy.label); + *label =strdup (root->fs_info->super_copy.label);/* Now we close it since we are done. */ close_ctree (root); + +return 0 ; } -int get_label (char *btrfs_dev) +int get_label (char *btrfs_dev,char **label) {int ret;
@@ -98,8 +102,7 @@ int get_label(char *btrfs_dev)fprintf (stderr,"FATAL: the filesystem has to be unmounted\n" );return -2 ; } -get_label_unmounted (btrfs_dev); -return 0 ; +return get_label_unmounted (btrfs_dev, label); }
btrfslabel.h +2 -2
@@ -1,5 +1,5 @@/* btrflabel.h */ -int get_label (char *btrfs_dev); -int set_label (char *btrfs_dev,char *nLabel); +int get_label (char *btrfs_dev,char **label); +int set_label (char *btrfs_dev,char *nLabel);
cmds-filesystem.c +12 -3
@@ -518,13 +518,22 @@ static const char * const cmd_label_usage[] = {static int cmd_label (int argc,char **argv) { +int ret; +char *label;if (check_argc_min (argc,2 ) ||check_argc_max (argc,3 ))usage (cmd_label_usage); -if (argc >2 ) +if (argc >2 ) {return set_label (argv[1 ], argv[2 ]); -else -return get_label (argv[1 ]); + }else { + ret =get_label (argv[1 ], &label); +if (ret <0 ) +return ret; +fprintf (stdout,"%s\n" , label); +free (label); +return ret; + } +} }const struct cmd_group filesystem_cmd_group = {
Signature · 1 line
1.7.10
PATCH 4/5 Btrfs-progs: make filesystem_cmd_group non const
In reply to Alexander BlockMake filesystem_cmd_group non const so that btrfs fi prop can generate the usage string at runtime. The commands member of struct cmd_group is also non const now.
--- cmds-filesystem.c | 2 +- commands.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
cmds-filesystem.c +1 -1
@@ -536,7 +536,7 @@ static int cmd_label(int argc, char **argv) } } -const struct cmd_group filesystem_cmd_group = { +struct cmd_group filesystem_cmd_group = { filesystem_cmd_group_usage,NULL , { {"df" , cmd_df, cmd_df_usage,NULL ,0 }, {"show" , cmd_show, cmd_show_usage,NULL ,0 },
commands.h +2 -2
@@ -54,7 +54,7 @@ struct cmd_group {const char *const *usagestr;const char *infostr; -const struct cmd_struct commands[]; +struct cmd_struct commands[]; };/* btrfs.c */
@@ -81,7 +81,7 @@ void help_command_group(const struct cmd_group *grp, int argc, char **argv);int open_file_or_dir (const char *fname);extern const struct cmd_group subvolume_cmd_group; -extern const struct cmd_group filesystem_cmd_group; +extern struct cmd_group filesystem_cmd_group;extern const struct cmd_group balance_cmd_group;extern const struct cmd_group device_cmd_group;extern const struct cmd_group scrub_cmd_group;
Signature · 1 line
1.7.10
PATCH 5/5 Btrfs-progs: introduce btrfs filesystem property command
In reply to Alexander Block"btrfs filesystem property" is a generic interface to set/get properties on filesystem objects (inodes/subvolumes/roots/devs).
This patch adds the generic framework for properties and also implements two properties. The first is the read-only property for subvolumes and the second is the label property for devices.
--- Makefile | 3 +- btrfs.c | 2 + cmds-filesystem.c | 98 ++++++++++++ commands.h | 3 + props.c | 460 +++++++++++++++++++++++++++++++++++++++++++++++++++++ props.h | 45 ++++++ 6 files changed, 610 insertions(+), 1 deletion(-) create mode 100644 props.c create mode 100644 props.h
Makefile +2 -1
@@ -4,7 +4,8 @@ CFLAGS = -g -O0 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ root-tree.o dir-item.o file-item.o inode-item.o \ inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ - volumes.o utils.o btrfs-list.o btrfslabel.o repair.o + volumes.o utils.o btrfs-list.o btrfslabel.o repair.o \ + props.o cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \ cmds-inspect.o cmds-balance.o
btrfs.c +2 -0
@@ -243,6 +243,8 @@ int main(int argc, char **argv) {const struct cmd_struct *cmd; +init_cmd_prop_usage (); + argc--; argv++;handle_options (&argc, &argv);
cmds-filesystem.c +98 -0
116 lines not on this page · raw message
commands.h +3 -0
@@ -87,6 +87,9 @@ extern const struct cmd_group device_cmd_group;extern const struct cmd_group scrub_cmd_group;extern const struct cmd_group inspect_cmd_group; +/* cmds-filesystem.c */ +void init_cmd_prop_usage (); +int cmd_subvolume (int argc,char **argv);int cmd_filesystem (int argc,char **argv);int cmd_balance (int argc,char **argv);
props.c new file +460 -0
460 lines not on this page · raw message
props.h new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
1.7.10
Re: [PATCH 4/5] Btrfs-progs: make filesystem_cmd_group non const
In reply to Alexander BlockI've removed this patch in the mean time. It was needed to build the usage string
for btrfs fi props at runtime but I found a solution to do this at compile time now.
Quoted 48 lines · Alexander Block
Make
filesystem_cmd_groupnon const so that btrfs fi prop can generate the usage string at runtime. The commands member of structcmd_groupis also non const now.Signed-off-by Alexander Block <[email protected]>---
cmds-filesystem.c | 2 +-
commands.h | 4 ++--2 files changed, 3 insertions(+), 3 deletions(-)cmds-filesystem.c +1
-1@@ -536,7 +536,7 @@ static int cmd_label(int argc, char **argv) } } -const struct cmd_group filesystem_cmd_group = { +struct cmd_group filesystem_cmd_group = { filesystem_cmd_group_usage, NULL, { { "df", cmd_df, cmd_df_usage, NULL, 0 }, { "show", cmd_show, cmd_show_usage, NULL, 0 },commands.h +2
-3@@ -54,7 +54,7 @@ struct cmd_group { const char * const *usagestr; const char *infostr; - const struct cmd_struct commands[]; + struct cmd_struct commands[]; }; /* btrfs.c */@@ -81,7 +81,7 @@ void help_command_group(const struct cmd_group *grp, int argc, char **argv); int open_file_or_dir(const char *fname); extern const struct cmd_group subvolume_cmd_group; -extern const struct cmd_group filesystem_cmd_group; +extern struct cmd_group filesystem_cmd_group; extern const struct cmd_group balance_cmd_group; extern const struct cmd_group device_cmd_group; extern const struct cmd_group scrub_cmd_group; --1.7.10
Quoted 16 lines · Alexander Block
This patchset introduces the btrfs filesystem property command. It is the result of a discussion we had on IRC. I tried to make the properties interface as generic and extensible as possible. Comments are welcome.
Currently the command looks like this:
btrfs fi prop /path/to/object [name[=value]]Some people may prefer other forms. For example I got suggestions for these forms:
btrfs set/get /path/to/object [name [value]]
btrfs prop /pach/to/object [name[=value]] (and also without the =)I'm open to more suggestions and a discussion on this. I'm definitely for removing the fi[lesystem] prefix but I'm neutral to the other suggestions made so far.
Quoted 9 lines
For now, I've implemented three properties:
1. read-only. Usable on subvolumes to toggle the read-only flags.
2. label. I looked through btrfs to find good examples of things that could be moved to the new properties interface and the filesystem label looked like a good one. There are for sure more, but that is something for later (and maybe for someone else). I would suggest to move everthing that makes sense over to the props interface and mark the old interfaces as deprecated. Comments on this are welcome.
Hi Alex,
Thanks for doing these!
I'm doing something similar to yours, but I prefer keeping these prefixes and making some efforts to enhance original APIs:
For subvolume, right now we can have two attributes: readonly and default, and let 'btrfs sub list' work just like 'ls' so that we can get their attributes easier:
o btrfs subvolume list [-p] path
subvol (Default)
snap (Readonly)
o btrfs subvolume list [-p] path/subvol
subvol (Default)
o btrfs subvolume list [-p] path/snap
snap (Readonly)
how about this?
thanks,
liubo
Quoted 25 lines
Alex.
Alexander Block (5):
Btrfs-progs: add BTRFS_IOC_SUBVOL_GET/SETFLAGS toioctl.h
Btrfs-progs: moveskip_prefixand prefixcmp toutils.c
Btrfs-progs: letget_labelreturn the label instead of of printing it
Btrfs-progs: makefilesystem_cmd_groupnon const
Btrfs-progs: introduce btrfs filesystem property commandMakefile | 3 +- btrfs.c | 19 +-- btrfslabel.c | 13 +- btrfslabel.h | 4 +- cmds-filesystem.c | 115 +++++++++++++- commands.h | 9 +- help.c | 2 + ioctl.h | 2 + props.c | 460 +++++++++++++++++++++++++++++++++++++++++++++++++++++ props.h | 45 ++++++ utils.c | 15 ++ utils.h | 3 + 12 files changed, 659 insertions(+), 31 deletions(-) create mode 100644 props.c create mode 100644 props.h
Quoted 29 lines · Liu Bo
Quoted 16 lines · Alexander Block
This patchset introduces the btrfs filesystem property command. It is the result of a discussion we had on IRC. I tried to make the properties interface as generic and extensible as possible. Comments are welcome.
Currently the command looks like this:
btrfs fi prop /path/to/object [name[=value]]Some people may prefer other forms. For example I got suggestions for these forms:
btrfs set/get /path/to/object [name [value]]
btrfs prop /pach/to/object [name[=value]] (and also without the =)I'm open to more suggestions and a discussion on this. I'm definitely for removing the fi[lesystem] prefix but I'm neutral to the other suggestions made so far.
Quoted 9 lines
For now, I've implemented three properties:
1. read-only. Usable on subvolumes to toggle the read-only flags.
2. label. I looked through btrfs to find good examples of things that could be moved to the new properties interface and the filesystem label looked like a good one. There are for sure more, but that is something for later (and maybe for someone else). I would suggest to move everthing that makes sense over to the props interface and mark the old interfaces as deprecated. Comments on this are welcome.
Quoted 6 lines
Hi Alex,
Thanks for doing these!
I'm doing something similar to yours, but I prefer keeping these prefixes and making some efforts to enhance original APIs:
I had some discussions with David and Ilya and we agreen on dropping the filesystem prefix for a
filesystem prefix for a simple reason. The property command is not only for filesystems, so the
prefix does not make sense here. We can later set/get properties on inodes, subvolumes,
filesystems, devices and maybe more later.
At the moment, the command has this form (new patchset will follow):
btrfs property set [<type>:]<object> <name> <value>
btrfs property get [<type>:]<object> [<name>] (no name means dump all) btrfs property list [<type>:]<object> (lists all available properties for the given object/type with a description)
The type is a prefix to explicitly specify what type of object you mean. This is necessary in case
the object+property combination is ambiguous. For example '/path/to/fs/root' could mean the root subvolume,
the directory inode or the filesystem itself. Normally, btrfs-progs will try to detect the type automatically.
Quoted 8 lines
For subvolume, right now we can have two attributes: readonly and default, and let 'btrfs sub list' work just like 'ls' so that we can get their attributes easier:
o btrfs subvolume list [-p] path
subvol (Default)
snap (Readonly)
Quoted 8 lines
o btrfs subvolume list [-p] path/subvol
subvol (Default)o btrfs subvolume list [-p] path/snap
snap (Readonly)how about this?
This sounds like something that we should handle/discuss separately to the new property command group.
Quoted 31 lines
thanks,
liuboQuoted 25 lines
Alex.
Alexander Block (5):
Btrfs-progs: add BTRFS_IOC_SUBVOL_GET/SETFLAGS toioctl.h
Btrfs-progs: moveskip_prefixand prefixcmp toutils.c
Btrfs-progs: letget_labelreturn the label instead of of printing it
Btrfs-progs: makefilesystem_cmd_groupnon const
Btrfs-progs: introduce btrfs filesystem property commandMakefile | 3 +-
btrfs.c | 19 +--
btrfslabel.c | 13 +-
btrfslabel.h | 4 +-
cmds-filesystem.c | 115 +++++++++++++-
commands.h | 9 +-
help.c | 2 +ioctl.h | 2 + props.c | 460 +++++++++++++++++++++++++++++++++++++++++++++++++++++ props.h | 45 ++++++ utils.c | 15 ++ utils.h | 3 + 12 files changed, 659 insertions(+), 31 deletions(-)create mode 100644
props.c
create mode 100644props.h
Am Sonntag, 24. Juni 2012 schrieb Alexander Block:
Quoted 8 lines
This patchset introduces the btrfs filesystem property command. It is the result of a discussion we had on IRC. I tried to make the properties interface as generic and extensible as possible. Comments are welcome.
Currently the command looks like this:
btrfs fi prop /path/to/object [name[=value]]
Quoted 6 lines
Some people may prefer other forms. For example I got suggestions for these forms:
btrfs set/get /path/to/object [name [value]]
btrfs prop /pach/to/object [name[=value]] (and also without the =)I'm open to more suggestions and a discussion on this. I'm definitely
I wonder about a way to find out directly
1) size of node and leaf metadata blocks
2) whether inode cache is active
3) whether space cache is active
Would also be nice to be able to set this. I do not know whether this is possible re 1 during a balance for example. Re 2 and 3 it would be nice to be able to skip the mount options in /etc/fstab. AFAIK space cache is permanent anyway, but inode cache isn´t or vice versa.
Either way I find the current way BTRFS handles options via mount options a bit confusion.
I´d like some way to set attributes / flags permanently like in Ext4 via tune2fs or xfs_admin.
Thanks,
Signature · 2 lines
Martin 'Helios' Steigerwald - http://www.Lichtvoll.de GPG: 03B0 0D6C 0040 0710 4AFA B82F 991B EAAC A599 84C7