linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] Btrfs-progs: add support to set subvolume/snapshot readonly
@ 2012-06-29 10:00 Liu Bo
  2012-06-29 10:00 ` [PATCH 2/3] Btrfs-progs: make get default report correctly Liu Bo
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Liu Bo @ 2012-06-29 10:00 UTC (permalink / raw)
  To: linux-btrfs

Setting subvolume/snapshot readonly has been missing for a long time.

With this patch, we can set a subvolume/snapshot readonly via:

o    btrfs subvolume set-ro <path>

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
---
 cmds-subvolume.c |   40 ++++++++++++++++++++++++++++++++++++++++
 ioctl.h          |    7 +++++++
 2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index 950fa8f..5ee31cb 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -512,6 +512,44 @@ static int cmd_find_new(int argc, char **argv)
 	return 0;
 }
 
+static const char * const cmd_subvol_set_ro_usage[] = {
+	"btrfs subvolume set-ro <path>",
+	"Set the subvolume ro",
+	NULL
+};
+
+static int cmd_subvol_set_ro(int argc, char **argv)
+{
+	int	ret=0, fd, e;
+	char	*path;
+	struct	btrfs_ioctl_get_set_flags_args args;
+
+	if (check_argc_exact(argc, 2))
+		usage(cmd_subvol_set_ro_usage);
+
+	path = argv[1];
+
+	memset(&args, 0, sizeof(args));
+
+	fd = open_file_or_dir(path);
+	if (fd < 0) {
+		fprintf(stderr, "ERROR: can't access to '%s'\n", path);
+		return 12;
+	}
+
+	args.flags |= BTRFS_SUBVOL_RDONLY;
+	args.objectid = 0;
+	ret = ioctl(fd, BTRFS_IOC_SUBVOL_SETFLAGS, &args);
+	e = errno;
+	close(fd);
+	if( ret < 0 ){
+		fprintf(stderr, "ERROR: unable to set a subvolume RO- %s\n",
+			strerror(e));
+		return 30;
+	}
+	return 0;
+}
+
 const struct cmd_group subvolume_cmd_group = {
 	subvolume_cmd_group_usage, NULL, {
 		{ "create", cmd_subvol_create, cmd_subvol_create_usage, NULL, 0 },
@@ -522,6 +560,8 @@ const struct cmd_group subvolume_cmd_group = {
 			cmd_subvol_get_default_usage, NULL, 0 },
 		{ "set-default", cmd_subvol_set_default,
 			cmd_subvol_set_default_usage, NULL, 0 },
+		{ "set-ro", cmd_subvol_set_ro,
+			cmd_subvol_set_ro_usage, NULL, 0 },
 		{ "find-new", cmd_find_new, cmd_find_new_usage, NULL, 0 },
 		{ 0, 0, 0, 0, 0 }
 	}
diff --git a/ioctl.h b/ioctl.h
index f2e5d8d..9c066eb 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -42,6 +42,11 @@ struct btrfs_ioctl_vol_args_v2 {
 	char name[BTRFS_SUBVOL_NAME_MAX + 1];
 };
 
+struct btrfs_ioctl_get_set_flags_args {
+	__u64 objectid;
+	__u64 flags;
+};
+
 #define BTRFS_FSID_SIZE 16
 #define BTRFS_UUID_SIZE 16
 
@@ -312,6 +317,8 @@ struct btrfs_ioctl_logical_ino_args {
 				    struct btrfs_ioctl_space_args)
 #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
 				   struct btrfs_ioctl_vol_args_v2)
+#define BTRFS_IOC_SUBVOL_GETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 25, __u64)
+#define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
 #define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \
 				struct btrfs_ioctl_scrub_args)
 #define BTRFS_IOC_SCRUB_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28)
-- 
1.6.5.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-07-05 13:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-29 10:00 [PATCH 1/3] Btrfs-progs: add support to set subvolume/snapshot readonly Liu Bo
2012-06-29 10:00 ` [PATCH 2/3] Btrfs-progs: make get default report correctly Liu Bo
2012-06-29 10:36   ` Ilya Dryomov
2012-07-02  1:39     ` Liu Bo
2012-07-02  9:45       ` Ilya Dryomov
2012-07-03  1:27         ` Liu Bo
2012-06-29 10:00 ` [PATCH 3/3] Btrfs-progs: add 's' option for 'btrfs subvolume list' Liu Bo
2012-07-04 15:41   ` David Sterba
2012-07-05 12:42     ` Liu Bo
2012-06-29 10:21 ` [PATCH 1/3] Btrfs-progs: add support to set subvolume/snapshot readonly Ilya Dryomov
2012-07-02  2:07   ` Liu Bo
2012-07-02 10:00     ` Ilya Dryomov
2012-07-03  1:46       ` Liu Bo

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).