From: Andreas Philipp <philipp.andreas@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Andreas Philipp <philipp.andreas@gmail.com>,
chris.mason@oracle.com, dcrmorgado@gmail.com, kreijack@libero.it,
lizf@cn.fujitsu.com
Subject: [PATCH 2/5] Add support for read-only subvolumes.
Date: Tue, 26 Apr 2011 10:02:41 +0200 [thread overview]
Message-ID: <1303804964-2840-3-git-send-email-philipp.andreas@gmail.com> (raw)
In-Reply-To: <1303804964-2840-1-git-send-email-philipp.andreas@gmail.com>
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 <philipp.andreas@gmail.com>
---
btrfs_cmds.c | 48 ++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/btrfs_cmds.c b/btrfs_cmds.c
index 8031c58..9367bac 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,38 @@ 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;
+ struct btrfs_ioctl_vol_args_v2 args;
- subvol = argv[1];
- dst = argv[2];
- struct btrfs_ioctl_vol_args args;
+ memset(&args, 0, sizeof(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 subvolume snapshot\n");
+ free(argv);
+ return 1;
+ }
+
+ subvol = argv[optind+1];
+ dst = argv[optind+2];
res = test_issubvolume(subvol);
if(res<0){
@@ -372,11 +397,18 @@ int do_clone(int argc, char **argv)
return 12;
}
- printf("Create a snapshot of '%s' in '%s/%s'\n",
- subvol, dstdir, newname);
+ 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);
+ }
+
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);
--
1.7.4.1
next prev parent reply other threads:[~2011-04-26 8:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <There is kernel side support for the creation of read-only snapshots>
2011-04-26 8:02 ` [PATCH v2 0/5] Add user-space support for read-only snapshot creation Andreas Philipp
2011-04-26 8:02 ` [PATCH 1/5] Added support for an additional ioctl Andreas Philipp
2011-04-26 8:02 ` Andreas Philipp [this message]
2011-04-26 8:02 ` [PATCH 3/5] Support the new parameters in do_clone(int argc, char** argv) Andreas Philipp
2011-04-26 8:02 ` [PATCH 4/5] Test the additional ioctl Andreas Philipp
2011-04-26 8:02 ` [PATCH 5/5] Updated manpage for btrfs subvolume snapshot Andreas Philipp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1303804964-2840-3-git-send-email-philipp.andreas@gmail.com \
--to=philipp.andreas@gmail.com \
--cc=chris.mason@oracle.com \
--cc=dcrmorgado@gmail.com \
--cc=kreijack@libero.it \
--cc=linux-btrfs@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).