@@ -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>."
@@ -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;
@@ -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);