btrfsprogs/0109-Add-support-for-read-only-subvolumes.patch

96 lines
2.5 KiB
Diff
Raw Normal View History

From fd296ee4952a542d18ed1bfe4adbf247474f7d21 Mon Sep 17 00:00:00 2001
From: Andreas Philipp <philipp.andreas@gmail.com>
Date: Tue, 26 Apr 2011 10:02:41 +0200
Subject: [PATCH 09/28] Add support for read-only subvolumes.
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>
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
---
btrfs_cmds.c | 48 ++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/btrfs_cmds.c b/btrfs_cmds.c
index 32f6b25..505322d 100644
--- a/btrfs_cmds.c
+++ b/btrfs_cmds.c
@@ -44,7 +44,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; }
@@ -330,13 +330,38 @@ int do_subvol_list(int argc, char **argv)
int do_clone(int argc, char **argv)
{
char *subvol, *dst;
- int res, fd, fddst, len, e;
+ int res, fd, fddst, len, e, 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){
@@ -392,11 +417,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;
strncpy(args.name, newname, BTRFS_PATH_NAME_MAX);
- res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args);
+ res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE_V2, &args);
e = errno;
close(fd);
--
1.7.5.2.353.g5df3e