From patchwork Wed Apr 13 09:12:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Philipp X-Patchwork-Id: 703371 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 p3D9CW9J031847 for ; Wed, 13 Apr 2011 09:12:32 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757895Ab1DMJM3 (ORCPT ); Wed, 13 Apr 2011 05:12:29 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:44409 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757966Ab1DMJM1 (ORCPT ); Wed, 13 Apr 2011 05:12:27 -0400 Received: by wwa36 with SMTP id 36so479183wwa.1 for ; Wed, 13 Apr 2011 02:12:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=1zML3bDq5nJHQMm3ynV5hSAO+QOrEFdd6f6ZglEgCzk=; b=phonRGrPLRv4qElswF2VGtmKTYtgmhqXD2h7zxnRSkLGe2dW9J83HSCViFjgSVvxKr TRTKP3C3kwvSv/a58vkETf4T/q3Mq15GwjsBWQCUK4Tx5qByqaNWNqrGqUmYD1eUi7Q0 LTkYqO5oRjhQU9K+g+uKpzdpBWoPHM3c1SFLM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=hcLQdWPHhabrkE6rh/G7vmmS/nE4u6FiMVLPhw9eC4a2UGgC0YtNMHRW8jmwflA6Yi g/AdWW51ikn/NXinYXfAT+s2UYNC3q16xRqE+3mDOFNy9pmmTholjSjA436YIUCTeKsG U0IejyRXm/zIzsKAyZgqtKpywSkTLfCzRqK5Q= Received: by 10.216.140.219 with SMTP id e69mr5529052wej.45.1302685946745; Wed, 13 Apr 2011 02:12:26 -0700 (PDT) Received: from localhost.localdomain (84-119-52-190.dynamic.xdsl-line.inode.at [84.119.52.190]) by mx.google.com with ESMTPS id d54sm148184wej.10.2011.04.13.02.12.25 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 13 Apr 2011 02:12:25 -0700 (PDT) From: Andreas Philipp To: linux-btrfs@vger.kernel.org Cc: Andreas Philipp , lizf@cn.fujitsu.com Subject: [PATCH 1/5] Add support for read-only subvolumes. Date: Wed, 13 Apr 2011 11:12:10 +0200 Message-Id: <1302685934-15737-2-git-send-email-philipp.andreas@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1302685934-15737-1-git-send-email-philipp.andreas@gmail.com> References: <1302685934-15737-1-git-send-email-philipp.andreas@gmail.com> 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.6 (demeter1.kernel.org [140.211.167.41]); Wed, 13 Apr 2011 09:12:32 +0000 (UTC) Use BTRFS_IOC_CREATE_SNAP_V2 instead of BTRFS_IOC_CREATE_SNAP and add an option for the creation of a readonly snapshot. Signed-off-by: Andreas Philipp --- btrfs_cmds.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 files changed, 36 insertions(+), 8 deletions(-) diff --git a/btrfs_cmds.c b/btrfs_cmds.c index 8031c58..baec675 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -43,7 +43,7 @@ #ifdef __CHECKER__ #define BLKGETSIZE64 0 -#define BTRFS_IOC_SNAP_CREATE 0 +#define BTRFS_IOC_SNAP_CREATE_V2 0 #define BTRFS_VOL_NAME_MAX 255 struct btrfs_ioctl_vol_args { char name[BTRFS_VOL_NAME_MAX]; }; static inline int ioctl(int fd, int define, void *arg) { return 0; } @@ -310,13 +310,34 @@ int do_subvol_list(int argc, char **argv) int do_clone(int argc, char **argv) { char *subvol, *dst; - int res, fd, fddst, len; + int res, fd, fddst, len, optind = 0, readonly = 0; char *newname; char *dstdir; - subvol = argv[1]; - dst = argv[2]; - struct btrfs_ioctl_vol_args args; + while(1) { + int c = getopt(argc, argv, "r"); + if (c < 0) + break; + switch(c) { + case 'r': + optind++; + readonly = 1; + break; + default: + fprintf(stderr, "Invalid arguments for subvolume snapshot\n"); + free(argv); + return 1; + } + } + if (argc - optind < 2) { + fprintf(stderr, "Invalid arguments for defragment\n"); + free(argv); + return 1; + } + + subvol = argv[optind+1]; + dst = argv[optind+2]; + struct btrfs_ioctl_vol_args_v2 args; res = test_issubvolume(subvol); if(res<0){ @@ -371,12 +392,19 @@ int do_clone(int argc, char **argv) fprintf(stderr, "ERROR: can't access to '%s'\n", dstdir); return 12; } + + if (readonly) { + args.flags |= BTRFS_SUBVOL_RDONLY; + printf("Create a readonly snapshot of '%s' in '%s/%s'\n", + subvol, dstdir, newname); + } + else + printf("Create a snapshot of '%s' in '%s/%s'\n", + subvol, dstdir, newname); - 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); + res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE_V2, &args); close(fd); close(fddst);