From patchwork Sat Oct 30 17:56:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sage Weil X-Patchwork-Id: 292322 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9UIGK4e008543 for ; Sat, 30 Oct 2010 18:16:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755114Ab0J3SQP (ORCPT ); Sat, 30 Oct 2010 14:16:15 -0400 Received: from cobra.newdream.net ([66.33.216.30]:44716 "EHLO cobra.newdream.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755062Ab0J3SQN (ORCPT ); Sat, 30 Oct 2010 14:16:13 -0400 Received: from vapre.ww.newdream.net (dsl092-035-022.lax1.dsl.speakeasy.net [66.92.35.22]) by cobra.newdream.net (Postfix) with ESMTPA id 3EB5EBC75B; Sat, 30 Oct 2010 11:19:35 -0700 (PDT) From: Sage Weil To: linux-btrfs@vger.kernel.org Cc: Sage Weil Subject: [PATCH 2/3] btrfs: implement 'async-snapshot' command Date: Sat, 30 Oct 2010 10:56:05 -0700 Message-Id: <1288461366-26914-2-git-send-email-sage@newdream.net> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1288461366-26914-1-git-send-email-sage@newdream.net> References: <1288461366-26914-1-git-send-email-sage@newdream.net> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Sat, 30 Oct 2010 18:16:23 +0000 (UTC) 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", " [/]\n" "Create a writable snapshot of the subvolume with\n" "the name in the directory." }, + { do_create_snap_async, 2, + "subvolume async-snapshot", " [/]\n" + "Create a writable snapshot of the subvolume with\n" + "the name in the directory. Do not wait for\n" + "the snapshot creation to commit to disk before returning." + }, { do_delete_subvolume, 1, "subvolume delete", "\n" "Delete the 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);