Signed-off-by: Sage Weil <sage@newdream.net> --- ioctl.h | 39 ++++++++++++++++++++++++++++++--------- 1 files changed, 30 insertions(+), 9 deletions(-) diff --git a/ioctl.h b/ioctl.h index 776d7a9..5a03317 100644 --- a/ioctl.h +++ b/ioctl.h @@ -23,13 +23,28 @@ #define BTRFS_IOCTL_MAGIC 0x94 #define BTRFS_VOL_NAME_MAX 255 -#define BTRFS_PATH_NAME_MAX 4087 +/* this should be 4k */ +#define BTRFS_PATH_NAME_MAX 4087 struct btrfs_ioctl_vol_args { __s64 fd; char name[BTRFS_PATH_NAME_MAX + 1]; }; +#define BTRFS_SNAPSHOT_NAME_MAX 4079 +struct btrfs_ioctl_async_vol_args { + __s64 fd; + __u64 transid; + char name[BTRFS_SNAPSHOT_NAME_MAX + 1]; +}; + +#define BTRFS_INO_LOOKUP_PATH_MAX 4080 +struct btrfs_ioctl_ino_lookup_args { + __u64 treeid; + __u64 objectid; + char name[BTRFS_INO_LOOKUP_PATH_MAX]; +}; + struct btrfs_ioctl_search_key { /* which root are we searching. 0 is the tree of tree roots */ __u64 tree_id; @@ -72,7 +87,7 @@ struct btrfs_ioctl_search_header { __u64 offset; __u32 type; __u32 len; -} __attribute__((may_alias)); +}; #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key)) /* @@ -85,11 +100,10 @@ struct btrfs_ioctl_search_args { char buf[BTRFS_SEARCH_ARGS_BUFSIZE]; }; -#define BTRFS_INO_LOOKUP_PATH_MAX 4080 -struct btrfs_ioctl_ino_lookup_args { - __u64 treeid; - __u64 objectid; - char name[BTRFS_INO_LOOKUP_PATH_MAX]; +struct btrfs_ioctl_clone_range_args { + __s64 src_fd; + __u64 src_offset, src_length; + __u64 dest_offset; }; /* flags for the defrag range ioctl */ @@ -155,11 +169,14 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_vol_args) #define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \ struct btrfs_ioctl_vol_args) -/* 13 is for CLONE_RANGE */ + +#define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \ + struct btrfs_ioctl_clone_range_args) + #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \ struct btrfs_ioctl_vol_args) #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \ - struct btrfs_ioctl_vol_args) + struct btrfs_ioctl_vol_args) #define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \ struct btrfs_ioctl_defrag_range_args) #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \ @@ -169,4 +186,8 @@ 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_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64) +#define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64) +#define BTRFS_IOC_SNAP_CREATE_ASYNC _IOW(BTRFS_IOCTL_MAGIC, 23, \ + struct btrfs_ioctl_async_vol_args) #endif -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
This is identical to ''snapshot'', but uses the new async snapshot creation ioctl, and prints out the transid the new snapshot will be committed with. Signed-off-by: Sage Weil <sage@newdream.net> --- btrfs.c | 8 +++++++- btrfs_cmds.c | 32 +++++++++++++++++++++++++++----- btrfs_cmds.h | 3 ++- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/btrfs.c b/btrfs.c index 46314cf..c4b9a31 100644 --- a/btrfs.c +++ b/btrfs.c @@ -44,11 +44,17 @@ static struct Command commands[] = { /* avoid short commands different for the case only */ - { do_clone, 2, + { do_create_snap, 2, "subvolume snapshot", "<source> [<dest>/]<name>\n" "Create a writable snapshot of the subvolume <source> with\n" "the name <name> in the <dest> directory." }, + { do_create_snap_async, 2, + "subvolume async-snapshot", "<source> [<dest>/]<name>\n" + "Create a writable snapshot of the subvolume <source> with\n" + "the name <name> in the <dest> directory. Do not wait for\n" + "the snapshot creation to commit to disk before returning." + }, { do_delete_subvolume, 1, "subvolume delete", "<subvolume>\n" "Delete the subvolume <subvolume>." diff --git a/btrfs_cmds.c b/btrfs_cmds.c index 8031c58..6da5862 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -307,7 +307,7 @@ int do_subvol_list(int argc, char **argv) return 0; } -int do_clone(int argc, char **argv) +static int create_snap(int argc, char **argv, int async) { char *subvol, *dst; int res, fd, fddst, len; @@ -316,7 +316,6 @@ int do_clone(int argc, char **argv) subvol = argv[1]; dst = argv[2]; - struct btrfs_ioctl_vol_args args; res = test_issubvolume(subvol); if(res<0){ @@ -374,9 +373,22 @@ int do_clone(int argc, char **argv) printf("Create a snapshot of ''%s'' in ''%s/%s''\n", subvol, dstdir, newname); - args.fd = fd; - strcpy(args.name, newname); - res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args); + if (async) { + struct btrfs_ioctl_async_vol_args async_args; + async_args.fd = fd; + async_args.transid = 0; + strcpy(async_args.name, newname); + res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE_ASYNC, &async_args); + if (res == 0) + printf("transid %llu\n", + (unsigned long long)async_args.transid); + } else { + struct btrfs_ioctl_vol_args args; + + args.fd = fd; + strcpy(args.name, newname); + res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args); + } close(fd); close(fddst); @@ -390,6 +402,16 @@ int do_clone(int argc, char **argv) } +int do_create_snap_async(int argc, char **argv) +{ + return create_snap(argc, argv, 1); +} + +int do_create_snap(int argc, char **argv) +{ + return create_snap(argc, argv, 0); +} + int do_delete_subvolume(int argc, char **argv) { int res, fd, len; diff --git a/btrfs_cmds.h b/btrfs_cmds.h index 7bde191..c44dc79 100644 --- a/btrfs_cmds.h +++ b/btrfs_cmds.h @@ -15,7 +15,8 @@ */ /* btrfs_cmds.c*/ -int do_clone(int nargs, char **argv); +int do_create_snap(int nargs, char **argv); +int do_create_snap_async(int nargs, char **argv); int do_delete_subvolume(int nargs, char **argv); int do_create_subvol(int nargs, char **argv); int do_fssync(int nargs, char **argv); -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Sage Weil
2010-Oct-30 17:56 UTC
[PATCH 3/3] btrfs: implement ''start-sync'' and ''wait-sync'' commands
The ''start-sync'' command initiates a sync, but does not wait for it to complete. A transaction is printed that can be fed to ''wait-sync'', which will wait for it to commit. ''wait-sync'' can also be used in combination with ''async-snapshot'' to wait for an async snapshot creation to commit. Signed-off-by: Sage Weil <sage@newdream.net> --- btrfs.c | 9 +++++++++ btrfs_cmds.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 2 ++ 3 files changed, 60 insertions(+), 0 deletions(-) diff --git a/btrfs.c b/btrfs.c index c4b9a31..d45ac1f 100644 --- a/btrfs.c +++ b/btrfs.c @@ -83,6 +83,15 @@ static struct Command commands[] = { "filesystem sync", "<path>\n" "Force a sync on the filesystem <path>." }, + { do_start_sync, 1, + "filesystem start-sync", "<path>\n" + "Start a sync on the filesystem <path>, and print the resulting\n" + "transaction id." + }, + { do_wait_sync, 2, + "filesystem wait-sync", "<path> <transid>\n" + "Wait for the transaction <transid> on the filesystem at <path> to commit." + }, { do_resize, 2, "filesystem resize", "[+/-]<newsize>[gkm]|max <filesystem>\n" "Resize the file system. If ''max'' is passed, the filesystem\n" diff --git a/btrfs_cmds.c b/btrfs_cmds.c index 6da5862..5b5bb15 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -548,6 +548,55 @@ int do_fssync(int argc, char **argv) return 0; } +int do_start_sync(int argc, char **argv) +{ + int fd, res; + char *path = argv[1]; + __u64 transid; + + fd = open_file_or_dir(path); + if (fd < 0) { + fprintf(stderr, "ERROR: can''t access to ''%s''\n", path); + return 12; + } + + printf("StartSync ''%s''\n", path); + res = ioctl(fd, BTRFS_IOC_START_SYNC, &transid); + close(fd); + if( res < 0 ){ + fprintf(stderr, "ERROR: unable to fs-syncing ''%s''\n", path); + return 16; + } else { + printf("transid %llu\n", (unsigned long long)transid); + } + + return 0; +} + +int do_wait_sync(int argc, char **argv) +{ + int fd, res; + char *path = argv[1]; + __u64 transid = atoll(argv[2]); + + fd = open_file_or_dir(path); + if (fd < 0) { + fprintf(stderr, "ERROR: can''t access to ''%s''\n", path); + return 12; + } + + printf("WaitSync ''%s'' transid %llu\n", path, (unsigned long long)transid); + res = ioctl(fd, BTRFS_IOC_WAIT_SYNC, &transid); + close(fd); + if( res < 0 ){ + fprintf(stderr, "ERROR: unable to wait-sync on ''%s'' transid %llu: %s\n", path, + (unsigned long long)transid, strerror(errno)); + return 16; + } + + return 0; +} + int do_scan(int argc, char **argv) { int i, fd; diff --git a/btrfs_cmds.h b/btrfs_cmds.h index c44dc79..e0e5ceb 100644 --- a/btrfs_cmds.h +++ b/btrfs_cmds.h @@ -20,6 +20,8 @@ int do_create_snap_async(int nargs, char **argv); int do_delete_subvolume(int nargs, char **argv); int do_create_subvol(int nargs, char **argv); int do_fssync(int nargs, char **argv); +int do_start_sync(int nargs, char **argv); +int do_wait_sync(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); -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Goffredo Baroncelli
2010-Oct-30 18:27 UTC
Re: [PATCH 2/3] btrfs: implement ''async-snapshot'' command
On Saturday, 30 October, 2010, Sage Weil wrote:> This is identical to ''snapshot'', but uses the new async snapshot creation > ioctl, and prints out the transid the new snapshot will be committed > with. > > Signed-off-by: Sage Weil <sage@newdream.net> > --- > btrfs.c | 8 +++++++- > btrfs_cmds.c | 32 +++++++++++++++++++++++++++----- > btrfs_cmds.h | 3 ++- > 3 files changed, 36 insertions(+), 7 deletions(-) > > diff --git a/btrfs.c b/btrfs.c > index 46314cf..c4b9a31 100644 > --- a/btrfs.c > +++ b/btrfs.c > @@ -44,11 +44,17 @@ static struct Command commands[] = { > /* > avoid short commands different for the case only > */ > - { do_clone, 2, > + { do_create_snap, 2, > "subvolume snapshot", "<source> [<dest>/]<name>\n" > "Create a writable snapshot of the subvolume <source> with\n" > "the name <name> in the <dest> directory." > }, > + { do_create_snap_async, 2, > + "subvolume async-snapshot", "<source> [<dest>/]<name>\n" > + "Create a writable snapshot of the subvolume <source> with\n" > + "the name <name> in the <dest> directory. Do not wait for\n" > + "the snapshot creation to commit to disk before returning." > + },Why create another command ? I think that it is better add a switch like btrfs subvolume snapshot [--async] <source> [<dest>/]<name> Create a writable snapshot of the subvolume <source> with the name <name> in the <dest> directory. If --async is passed, do not wait for the snapshot creation to commit to disk before returning. In any case, please update the man page too.> { do_delete_subvolume, 1, > "subvolume delete", "<subvolume>\n" > "Delete the subvolume <subvolume>." > diff --git a/btrfs_cmds.c b/btrfs_cmds.c > index 8031c58..6da5862 100644 > --- a/btrfs_cmds.c > +++ b/btrfs_cmds.c > @@ -307,7 +307,7 @@ int do_subvol_list(int argc, char **argv) > return 0; > } > > -int do_clone(int argc, char **argv) > +static int create_snap(int argc, char **argv, int async) > { > char *subvol, *dst; > int res, fd, fddst, len; > @@ -316,7 +316,6 @@ int do_clone(int argc, char **argv) > > subvol = argv[1]; > dst = argv[2]; > - struct btrfs_ioctl_vol_args args; > > res = test_issubvolume(subvol); > if(res<0){ > @@ -374,9 +373,22 @@ int do_clone(int argc, char **argv) > > printf("Create a snapshot of ''%s'' in ''%s/%s''\n", > subvol, dstdir, newname); > - args.fd = fd; > - strcpy(args.name, newname); > - res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args); > + if (async) { > + struct btrfs_ioctl_async_vol_args async_args; > + async_args.fd = fd; > + async_args.transid = 0; > + strcpy(async_args.name, newname); > + res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE_ASYNC, &async_args); > + if (res == 0) > + printf("transid %llu\n", > + (unsigned long long)async_args.transid); > + } else { > + struct btrfs_ioctl_vol_args args; > + > + args.fd = fd; > + strcpy(args.name, newname); > + res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args); > + } > > close(fd); > close(fddst); > @@ -390,6 +402,16 @@ int do_clone(int argc, char **argv) > > } > > +int do_create_snap_async(int argc, char **argv) > +{ > + return create_snap(argc, argv, 1); > +} > + > +int do_create_snap(int argc, char **argv) > +{ > + return create_snap(argc, argv, 0); > +} > + > int do_delete_subvolume(int argc, char **argv) > { > int res, fd, len; > diff --git a/btrfs_cmds.h b/btrfs_cmds.h > index 7bde191..c44dc79 100644 > --- a/btrfs_cmds.h > +++ b/btrfs_cmds.h > @@ -15,7 +15,8 @@ > */ > > /* btrfs_cmds.c*/ > -int do_clone(int nargs, char **argv); > +int do_create_snap(int nargs, char **argv); > +int do_create_snap_async(int nargs, char **argv); > int do_delete_subvolume(int nargs, char **argv); > int do_create_subvol(int nargs, char **argv); > int do_fssync(int nargs, char **argv); > -- > 1.7.1 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >-- gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it> Key fingerprint = 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 majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Goffredo Baroncelli
2010-Oct-30 18:29 UTC
Re: [PATCH 3/3] btrfs: implement ''start-sync'' and ''wait-sync'' commands
On Saturday, 30 October, 2010, Sage Weil wrote:> The ''start-sync'' command initiates a sync, but does not wait for it to > complete. A transaction is printed that can be fed to ''wait-sync'', which > will wait for it to commit. > > ''wait-sync'' can also be used in combination with ''async-snapshot'' to wait > for an async snapshot creation to commit.As previous, if you add or update a command, please update the man page too.> > Signed-off-by: Sage Weil <sage@newdream.net> > --- > btrfs.c | 9 +++++++++ > btrfs_cmds.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ > btrfs_cmds.h | 2 ++ > 3 files changed, 60 insertions(+), 0 deletions(-) > > diff --git a/btrfs.c b/btrfs.c > index c4b9a31..d45ac1f 100644 > --- a/btrfs.c > +++ b/btrfs.c > @@ -83,6 +83,15 @@ static struct Command commands[] = { > "filesystem sync", "<path>\n" > "Force a sync on the filesystem <path>." > }, > + { do_start_sync, 1, > + "filesystem start-sync", "<path>\n" > + "Start a sync on the filesystem <path>, and print theresulting\n"> + "transaction id." > + }, > + { do_wait_sync, 2, > + "filesystem wait-sync", "<path> <transid>\n" > + "Wait for the transaction <transid> on the filesystem at<path> to commit."> + }, > { do_resize, 2, > "filesystem resize", "[+/-]<newsize>[gkm]|max <filesystem>\n" > "Resize the file system. If ''max'' is passed, the filesystem\n" > diff --git a/btrfs_cmds.c b/btrfs_cmds.c > index 6da5862..5b5bb15 100644 > --- a/btrfs_cmds.c > +++ b/btrfs_cmds.c > @@ -548,6 +548,55 @@ int do_fssync(int argc, char **argv) > return 0; > } > > +int do_start_sync(int argc, char **argv) > +{ > + int fd, res; > + char *path = argv[1]; > + __u64 transid; > + > + fd = open_file_or_dir(path); > + if (fd < 0) { > + fprintf(stderr, "ERROR: can''t access to ''%s''\n", path); > + return 12; > + } > + > + printf("StartSync ''%s''\n", path); > + res = ioctl(fd, BTRFS_IOC_START_SYNC, &transid); > + close(fd); > + if( res < 0 ){ > + fprintf(stderr, "ERROR: unable to fs-syncing ''%s''\n", path); > + return 16; > + } else { > + printf("transid %llu\n", (unsigned long long)transid); > + } > + > + return 0; > +} > + > +int do_wait_sync(int argc, char **argv) > +{ > + int fd, res; > + char *path = argv[1]; > + __u64 transid = atoll(argv[2]); > + > + fd = open_file_or_dir(path); > + if (fd < 0) { > + fprintf(stderr, "ERROR: can''t access to ''%s''\n", path); > + return 12; > + } > + > + printf("WaitSync ''%s'' transid %llu\n", path, (unsigned longlong)transid);> + res = ioctl(fd, BTRFS_IOC_WAIT_SYNC, &transid); > + close(fd); > + if( res < 0 ){ > + fprintf(stderr, "ERROR: unable to wait-sync on ''%s'' transid%llu: %s\n", path,> + (unsigned long long)transid, strerror(errno)); > + return 16; > + } > + > + return 0; > +} > + > int do_scan(int argc, char **argv) > { > int i, fd; > diff --git a/btrfs_cmds.h b/btrfs_cmds.h > index c44dc79..e0e5ceb 100644 > --- a/btrfs_cmds.h > +++ b/btrfs_cmds.h > @@ -20,6 +20,8 @@ int do_create_snap_async(int nargs, char **argv); > int do_delete_subvolume(int nargs, char **argv); > int do_create_subvol(int nargs, char **argv); > int do_fssync(int nargs, char **argv); > +int do_start_sync(int nargs, char **argv); > +int do_wait_sync(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); > -- > 1.7.1 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >-- gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it> Key fingerprint = 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 majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Goffredo Baroncelli
2010-Oct-30 18:35 UTC
Re: [PATCH 2/3] btrfs: implement ''async-snapshot'' command
On Saturday, 30 October, 2010, Sage Weil wrote:> This is identical to ''snapshot'', but uses the new async snapshot creation > ioctl, and prints out the transid the new snapshot will be committed > with.Only for curiosity, how long may take snapshot a tree ? It should be only a copy and update of few pages on the disk (the head of the trees), so the time should be O(1)... Goffredo [...] -- gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it> Key fingerprint = 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 majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Sage Weil
2010-Nov-01 16:29 UTC
Re: [PATCH 2/3] btrfs: implement ''async-snapshot'' command
On Sat, 30 Oct 2010, Goffredo Baroncelli wrote:> On Saturday, 30 October, 2010, Sage Weil wrote: > > This is identical to ''snapshot'', but uses the new async snapshot creation > > ioctl, and prints out the transid the new snapshot will be committed > > with. > > Only for curiosity, how long may take snapshot a tree ? It should be only a > copy and update of few pages on the disk (the head of the trees), so the time > should be O(1)...In theory, yes, but there is still a fair bit of disk io that goes on while preparing the commit in the current code. Also, I found that even when the transaction does unblock, most operations end up waiting for the btree inode pages anyway, so there is definitely room for improvement. Still, this avoids waiting for the new superblocks to commit, and gets the interface in place to take advantage of future improvements in this area. sage -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Sage Weil
2010-Nov-01 16:31 UTC
Re: [PATCH 2/3] btrfs: implement ''async-snapshot'' command
On Sat, 30 Oct 2010, Goffredo Baroncelli wrote:> On Saturday, 30 October, 2010, Sage Weil wrote: > > This is identical to ''snapshot'', but uses the new async snapshot creation > > ioctl, and prints out the transid the new snapshot will be committed > > with. > > > > Signed-off-by: Sage Weil <sage@newdream.net> > > --- > > btrfs.c | 8 +++++++- > > btrfs_cmds.c | 32 +++++++++++++++++++++++++++----- > > btrfs_cmds.h | 3 ++- > > 3 files changed, 36 insertions(+), 7 deletions(-) > > > > diff --git a/btrfs.c b/btrfs.c > > index 46314cf..c4b9a31 100644 > > --- a/btrfs.c > > +++ b/btrfs.c > > @@ -44,11 +44,17 @@ static struct Command commands[] = { > > /* > > avoid short commands different for the case only > > */ > > - { do_clone, 2, > > + { do_create_snap, 2, > > "subvolume snapshot", "<source> [<dest>/]<name>\n" > > "Create a writable snapshot of the subvolume <source> with\n" > > "the name <name> in the <dest> directory." > > }, > > + { do_create_snap_async, 2, > > + "subvolume async-snapshot", "<source> [<dest>/]<name>\n" > > + "Create a writable snapshot of the subvolume <source> with\n" > > + "the name <name> in the <dest> directory. Do not wait for\n" > > + "the snapshot creation to commit to disk before returning." > > + }, > > Why create another command ? I think that it is better add a switch like > > btrfs subvolume snapshot [--async] <source> [<dest>/]<name>How about btrfs subvolume snapshot <source> [<dest>/]<name> [async] That avoids ambiguity when <source> is named ''--async'' and simplifies parsing. Updated patches follow (including man page updates). sage> > Create a writable snapshot of the subvolume <source> with > the name <name> in the <dest> directory. If --async is > passed, do not wait for the snapshot creation to commit to > disk before returning. > > In any case, please update the man page too. > > > > > { do_delete_subvolume, 1, > > "subvolume delete", "<subvolume>\n" > > "Delete the subvolume <subvolume>." > > diff --git a/btrfs_cmds.c b/btrfs_cmds.c > > index 8031c58..6da5862 100644 > > --- a/btrfs_cmds.c > > +++ b/btrfs_cmds.c > > @@ -307,7 +307,7 @@ int do_subvol_list(int argc, char **argv) > > return 0; > > } > > > > -int do_clone(int argc, char **argv) > > +static int create_snap(int argc, char **argv, int async) > > { > > char *subvol, *dst; > > int res, fd, fddst, len; > > @@ -316,7 +316,6 @@ int do_clone(int argc, char **argv) > > > > subvol = argv[1]; > > dst = argv[2]; > > - struct btrfs_ioctl_vol_args args; > > > > res = test_issubvolume(subvol); > > if(res<0){ > > @@ -374,9 +373,22 @@ int do_clone(int argc, char **argv) > > > > printf("Create a snapshot of ''%s'' in ''%s/%s''\n", > > subvol, dstdir, newname); > > - args.fd = fd; > > - strcpy(args.name, newname); > > - res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args); > > + if (async) { > > + struct btrfs_ioctl_async_vol_args async_args; > > + async_args.fd = fd; > > + async_args.transid = 0; > > + strcpy(async_args.name, newname); > > + res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE_ASYNC, &async_args); > > + if (res == 0) > > + printf("transid %llu\n", > > + (unsigned long long)async_args.transid); > > + } else { > > + struct btrfs_ioctl_vol_args args; > > + > > + args.fd = fd; > > + strcpy(args.name, newname); > > + res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args); > > + } > > > > close(fd); > > close(fddst); > > @@ -390,6 +402,16 @@ int do_clone(int argc, char **argv) > > > > } > > > > +int do_create_snap_async(int argc, char **argv) > > +{ > > + return create_snap(argc, argv, 1); > > +} > > + > > +int do_create_snap(int argc, char **argv) > > +{ > > + return create_snap(argc, argv, 0); > > +} > > + > > int do_delete_subvolume(int argc, char **argv) > > { > > int res, fd, len; > > diff --git a/btrfs_cmds.h b/btrfs_cmds.h > > index 7bde191..c44dc79 100644 > > --- a/btrfs_cmds.h > > +++ b/btrfs_cmds.h > > @@ -15,7 +15,8 @@ > > */ > > > > /* btrfs_cmds.c*/ > > -int do_clone(int nargs, char **argv); > > +int do_create_snap(int nargs, char **argv); > > +int do_create_snap_async(int nargs, char **argv); > > int do_delete_subvolume(int nargs, char **argv); > > int do_create_subvol(int nargs, char **argv); > > int do_fssync(int nargs, char **argv); > > -- > > 1.7.1 > > > > -- > > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > > the body of a message to majordomo@vger.kernel.org > > More majordomo info at http://vger.kernel.org/majordomo-info.html > > > > > -- > gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it> > Key fingerprint = 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 majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Goffredo Baroncelli
2010-Nov-02 18:42 UTC
Re: [PATCH 2/3] btrfs: implement ''async-snapshot'' command
On Monday, 01 November, 2010, Sage Weil wrote:> On Sat, 30 Oct 2010, Goffredo Baroncelli wrote: > > On Saturday, 30 October, 2010, Sage Weil wrote: > > > This is identical to ''snapshot'', but uses the new async snapshotcreation> > > ioctl, and prints out the transid the new snapshot will be committed > > > with. > > > > > > Signed-off-by: Sage Weil <sage@newdream.net> > > > --- > > > btrfs.c | 8 +++++++- > > > btrfs_cmds.c | 32 +++++++++++++++++++++++++++----- > > > btrfs_cmds.h | 3 ++- > > > 3 files changed, 36 insertions(+), 7 deletions(-) > > > > > > diff --git a/btrfs.c b/btrfs.c > > > index 46314cf..c4b9a31 100644 > > > --- a/btrfs.c > > > +++ b/btrfs.c > > > @@ -44,11 +44,17 @@ static struct Command commands[] = { > > > /* > > > avoid short commands different for the case only > > > */ > > > - { do_clone, 2, > > > + { do_create_snap, 2, > > > "subvolume snapshot", "<source> [<dest>/]<name>\n" > > > "Create a writable snapshot of the subvolume <source> with\n" > > > "the name <name> in the <dest> directory." > > > }, > > > + { do_create_snap_async, 2, > > > + "subvolume async-snapshot", "<source> [<dest>/]<name>\n" > > > + "Create a writable snapshot of the subvolume <source> with\n" > > > + "the name <name> in the <dest> directory. Do not wait for\n" > > > + "the snapshot creation to commit to disk before returning." > > > + }, > > > > Why create another command ? I think that it is better add a switch like > > > > btrfs subvolume snapshot [--async] <source> [<dest>/]<name> > > How about > > btrfs subvolume snapshot <source> [<dest>/]<name> [async] > > That avoids ambiguity when <source> is named ''--async'' and simplifies > parsing. Updated patches follow (including man page updates). > > sage >No please ! Sorry but this is too strange as syntax. When the <source> is named "--async" it is possible to execute the command passing "./--async". This workaround is used in any unix command (have you ever thought what happens if you execute "rm *" when exists a file named "-rf" ?). I think that "--async" is a modification of the standard behaviour of "btrfs s s" command, so it is natural to use the switch syntax (30+ years of unix say so :-) ) Goffredo -- gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it> Key fingerprint = 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 majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Sage Weil
2010-Nov-02 18:45 UTC
Re: [PATCH 2/3] btrfs: implement ''async-snapshot'' command
On Tue, 2 Nov 2010, Goffredo Baroncelli wrote:> On Monday, 01 November, 2010, Sage Weil wrote: > > On Sat, 30 Oct 2010, Goffredo Baroncelli wrote: > > > On Saturday, 30 October, 2010, Sage Weil wrote: > > > > This is identical to ''snapshot'', but uses the new async snapshot > creation > > > > ioctl, and prints out the transid the new snapshot will be committed > > > > with. > > > > > > > > Signed-off-by: Sage Weil <sage@newdream.net> > > > > --- > > > > btrfs.c | 8 +++++++- > > > > btrfs_cmds.c | 32 +++++++++++++++++++++++++++----- > > > > btrfs_cmds.h | 3 ++- > > > > 3 files changed, 36 insertions(+), 7 deletions(-) > > > > > > > > diff --git a/btrfs.c b/btrfs.c > > > > index 46314cf..c4b9a31 100644 > > > > --- a/btrfs.c > > > > +++ b/btrfs.c > > > > @@ -44,11 +44,17 @@ static struct Command commands[] = { > > > > /* > > > > avoid short commands different for the case only > > > > */ > > > > - { do_clone, 2, > > > > + { do_create_snap, 2, > > > > "subvolume snapshot", "<source> [<dest>/]<name>\n" > > > > "Create a writable snapshot of the subvolume <source> with\n" > > > > "the name <name> in the <dest> directory." > > > > }, > > > > + { do_create_snap_async, 2, > > > > + "subvolume async-snapshot", "<source> [<dest>/]<name>\n" > > > > + "Create a writable snapshot of the subvolume <source> with\n" > > > > + "the name <name> in the <dest> directory. Do not wait for\n" > > > > + "the snapshot creation to commit to disk before returning." > > > > + }, > > > > > > Why create another command ? I think that it is better add a switch like > > > > > > btrfs subvolume snapshot [--async] <source> [<dest>/]<name> > > > > How about > > > > btrfs subvolume snapshot <source> [<dest>/]<name> [async] > > > > That avoids ambiguity when <source> is named ''--async'' and simplifies > > parsing. Updated patches follow (including man page updates). > > > > sage > > > > No please ! Sorry but this is too strange as syntax. > > When the <source> is named "--async" it is possible to execute the command > passing "./--async". This workaround is used in any unix command (have you > ever thought what happens if you execute "rm *" when exists a file named "-rf" > ?).Oh right, that''s better. I''m used to using -- (as in ''grep -- -foo''; rm supports the same syntax). Will resend. sage> I think that "--async" is a modification of the standard behaviour of "btrfs s > s" command, so it is natural to use the switch syntax (30+ years of unix say > so :-) ) > > Goffredo > > -- > gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it> > Key fingerprint = 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 majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html