* [PATCH 1/5] Add support for read-only subvolumes.
2011-04-13 9:12 [PATCH 0/5] Add user-space support for read-only snapshot creation Andreas Philipp
@ 2011-04-13 9:12 ` Andreas Philipp
2011-04-13 9:12 ` [PATCH 2/5] Support the new parameters in do_clone(int argc, char** argv) Andreas Philipp
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Andreas Philipp @ 2011-04-13 9:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Andreas Philipp, lizf
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 | 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);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/5] Support the new parameters in do_clone(int argc, char** argv).
2011-04-13 9:12 [PATCH 0/5] Add user-space support for read-only snapshot creation Andreas Philipp
2011-04-13 9:12 ` [PATCH 1/5] Add support for read-only subvolumes Andreas Philipp
@ 2011-04-13 9:12 ` Andreas Philipp
2011-04-13 9:12 ` [PATCH 3/5] Added support for an additional ioctl Andreas Philipp
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Andreas Philipp @ 2011-04-13 9:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Andreas Philipp, lizf
Now 'btrfs subvolume snapshot' takes not two but only at least two
parameters. Additionally, the help message is updated accordingly.
Signed-off-by: Andreas Philipp <philipp.andreas@gmail.com>
---
btrfs.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/btrfs.c b/btrfs.c
index 46314cf..f70d64b 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -44,9 +44,9 @@ static struct Command commands[] = {
/*
avoid short commands different for the case only
*/
- { do_clone, 2,
- "subvolume snapshot", "<source> [<dest>/]<name>\n"
- "Create a writable snapshot of the subvolume <source> with\n"
+ { do_clone, -2,
+ "subvolume snapshot", "[-r] <source> [<dest>/]<name>\n"
+ "Create a writable/readonly snapshot of the subvolume <source> with\n"
"the name <name> in the <dest> directory."
},
{ do_delete_subvolume, 1,
--
1.7.4.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/5] Added support for an additional ioctl.
2011-04-13 9:12 [PATCH 0/5] Add user-space support for read-only snapshot creation Andreas Philipp
2011-04-13 9:12 ` [PATCH 1/5] Add support for read-only subvolumes Andreas Philipp
2011-04-13 9:12 ` [PATCH 2/5] Support the new parameters in do_clone(int argc, char** argv) Andreas Philipp
@ 2011-04-13 9:12 ` Andreas Philipp
2011-04-13 9:12 ` [PATCH 4/5] Test the " Andreas Philipp
2011-04-13 9:12 ` [PATCH 5/5] Updated documentation for btrfs subvolume snapshot Andreas Philipp
4 siblings, 0 replies; 8+ messages in thread
From: Andreas Philipp @ 2011-04-13 9:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Andreas Philipp, lizf
Added BTRFS_IOC_SNAP_CREATE_V2 and struct btrfs_ioctl_vol_args_v2 as
defined in fs/btrfs/ioctl.h in the kernel sources.
Signed-off-by: Andreas Philipp <philipp.andreas@gmail.com>
---
ioctl.h | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/ioctl.h b/ioctl.h
index 776d7a9..358f814 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -30,6 +30,17 @@ struct btrfs_ioctl_vol_args {
char name[BTRFS_PATH_NAME_MAX + 1];
};
+#define BTRFS_SUBVOL_RDONLY (1ULL << 1)
+#define BTRFS_SUBVOL_NAME_MAX 4039
+
+struct btrfs_ioctl_vol_args_v2 {
+ __s64 fd;
+ __u64 transid;
+ __u64 flags;
+ __u64 unused[4];
+ char name[BTRFS_SUBVOL_NAME_MAX + 1];
+};
+
struct btrfs_ioctl_search_key {
/* which root are we searching. 0 is the tree of tree roots */
__u64 tree_id;
@@ -132,6 +143,7 @@ struct btrfs_ioctl_space_args {
struct btrfs_ioctl_space_info spaces[0];
};
+/* BTRFS_IOC_SNAP_CREATE is no longer used by the btrfs command */
#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
struct btrfs_ioctl_vol_args)
#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
@@ -169,4 +181,6 @@ 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_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
+ struct btrfs_ioctl_vol_args_v2)
#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/5] Test the additional ioctl.
2011-04-13 9:12 [PATCH 0/5] Add user-space support for read-only snapshot creation Andreas Philipp
` (2 preceding siblings ...)
2011-04-13 9:12 ` [PATCH 3/5] Added support for an additional ioctl Andreas Philipp
@ 2011-04-13 9:12 ` Andreas Philipp
2011-04-13 9:12 ` [PATCH 5/5] Updated documentation for btrfs subvolume snapshot Andreas Philipp
4 siblings, 0 replies; 8+ messages in thread
From: Andreas Philipp @ 2011-04-13 9:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Andreas Philipp, lizf
Signed-off-by: Andreas Philipp <philipp.andreas@gmail.com>
---
ioctl-test.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/ioctl-test.c b/ioctl-test.c
index 7cf3bc2..1c27d61 100644
--- a/ioctl-test.c
+++ b/ioctl-test.c
@@ -22,6 +22,7 @@ unsigned long ioctls[] = {
BTRFS_IOC_INO_LOOKUP,
BTRFS_IOC_DEFAULT_SUBVOL,
BTRFS_IOC_SPACE_INFO,
+ BTRFS_IOC_SNAP_CREATE_V2,
0 };
int main(int ac, char **av)
--
1.7.4.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/5] Updated documentation for btrfs subvolume snapshot.
2011-04-13 9:12 [PATCH 0/5] Add user-space support for read-only snapshot creation Andreas Philipp
` (3 preceding siblings ...)
2011-04-13 9:12 ` [PATCH 4/5] Test the " Andreas Philipp
@ 2011-04-13 9:12 ` Andreas Philipp
4 siblings, 0 replies; 8+ messages in thread
From: Andreas Philipp @ 2011-04-13 9:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Andreas Philipp, lizf
Signed-off-by: Andreas Philipp <philipp.andreas@gmail.com>
---
man/btrfs.8.in | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 26ef982..b59bc6f 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -5,7 +5,7 @@
.SH NAME
btrfs \- control a btrfs filesystem
.SH SYNOPSIS
-\fBbtrfs\fP \fBsubvolume snapshot\fP\fI <source> [<dest>/]<name>\fP
+\fBbtrfs\fP \fBsubvolume snapshot\fP\fI [-r] <source> [<dest>/]<name>\fP
.PP
\fBbtrfs\fP \fBsubvolume delete\fP\fI <subvolume>\fP
.PP
@@ -70,10 +70,11 @@ command.
.SH COMMANDS
.TP
-\fBsubvolume snapshot\fR\fI <source> [<dest>/]<name>\fR
-Create a writable snapshot of the subvolume \fI<source>\fR with the name
-\fI<name>\fR in the \fI<dest>\fR directory. If \fI<source>\fR is not a
-subvolume, \fBbtrfs\fR returns an error.
+\fBsubvolume snapshot\fR\fI [-r] <source> [<dest>/]<name>\fR
+Create a writable/readonly snapshot of the subvolume \fI<source>\fR with the
+name \fI<name>\fR in the \fI<dest>\fR directory. If \fI<source>\fR is not a
+subvolume, \fBbtrfs\fR returns an error. If \fI-r\fR is given, the snapshot
+will be readonly.
.TP
\fBsubvolume delete\fR\fI <subvolume>\fR
--
1.7.4.1
^ permalink raw reply related [flat|nested] 8+ messages in thread