From: Liu Bo <liubo2009@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 1/3] Btrfs: add default support for subvol getflags
Date: Fri, 29 Jun 2012 17:59:53 +0800 [thread overview]
Message-ID: <1340963995-32549-1-git-send-email-liubo2009@cn.fujitsu.com> (raw)
This is kernel side patch for 'btrfs subvolume get-default'.
Our 'btrfs subvolume get-default' did not work as wish, because we do not have
APIs to fetch the subvolume's default state.
This patch treats default state as a flag and returns it to user space.
Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
---
fs/btrfs/ioctl.c | 37 +++++++++++++++++++++++++++++++++++++
fs/btrfs/ioctl.h | 1 +
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 2cf6b1b..60fff96 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1487,6 +1487,39 @@ out:
return ret;
}
+/* Return 1 for default, otherwise return 0. */
+static int btrfs_root_default(struct btrfs_root *root)
+{
+ struct btrfs_path *path;
+ struct btrfs_disk_key disk_key;
+ struct btrfs_key key;
+ struct btrfs_dir_item *di;
+ int is_default = 0;
+ u64 dir_id;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return -ENOMEM;
+
+ dir_id = btrfs_super_root_dir(root->fs_info->super_copy);
+ di = btrfs_lookup_dir_item(NULL, root->fs_info->tree_root, path,
+ dir_id, "default", 7, 0);
+ if (IS_ERR_OR_NULL(di)) {
+ btrfs_free_path(path);
+ printk(KERN_ERR "Umm, no default dir item!\n");
+ return -ENOENT;
+ }
+ btrfs_dir_item_key(path->nodes[0], di, &disk_key);
+ btrfs_disk_key_to_cpu(&key, &disk_key);
+ if (btrfs_comp_cpu_keys(&key, &root->root_key))
+ is_default = 0;
+ else
+ is_default = 1;
+
+ btrfs_free_path(path);
+ return is_default;
+}
+
static noinline int btrfs_ioctl_subvol_getflags(struct file *file,
void __user *arg)
{
@@ -1501,6 +1534,10 @@ static noinline int btrfs_ioctl_subvol_getflags(struct file *file,
down_read(&root->fs_info->subvol_sem);
if (btrfs_root_readonly(root))
flags |= BTRFS_SUBVOL_RDONLY;
+
+ ret = btrfs_root_default(root);
+ if (ret > 0)
+ flags |= BTRFS_SUBVOL_DEFAULT;
up_read(&root->fs_info->subvol_sem);
if (copy_to_user(arg, &flags, sizeof(flags)))
diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
index 497c530..3186d2d 100644
--- a/fs/btrfs/ioctl.h
+++ b/fs/btrfs/ioctl.h
@@ -32,6 +32,7 @@ struct btrfs_ioctl_vol_args {
#define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
#define BTRFS_SUBVOL_RDONLY (1ULL << 1)
+#define BTRFS_SUBVOL_DEFAULT (1ULL << 2)
#define BTRFS_FSID_SIZE 16
#define BTRFS_UUID_SIZE 16
--
1.6.5.2
next reply other threads:[~2012-06-29 9:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-29 9:59 Liu Bo [this message]
2012-06-29 9:59 ` [PATCH 2/3] Btrfs: update subvol_getflags/setflags to know new args from user Liu Bo
2012-07-03 11:27 ` Alexander Block
2012-07-03 12:04 ` Liu Bo
2012-07-03 12:09 ` Alexander Block
2012-07-03 16:08 ` Josef Bacik
2012-07-04 0:57 ` Liu Bo
2012-06-29 9:59 ` [PATCH 3/3] Btrfs: use helper function to simplify code 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=1340963995-32549-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).