From: Liu Bo <liubo2009@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 1/3] Btrfs-progs: add support to set subvolume/snapshot readonly
Date: Fri, 29 Jun 2012 18:00:36 +0800 [thread overview]
Message-ID: <1340964038-32584-1-git-send-email-liubo2009@cn.fujitsu.com> (raw)
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
next reply other threads:[~2012-06-29 9:51 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-29 10:00 Liu Bo [this message]
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
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=1340964038-32584-1-git-send-email-liubo2009@cn.fujitsu.com \
--to=liubo2009@cn.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
/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).