linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] Btrfs: add default support for subvol getflags
@ 2012-06-29  9:59 Liu Bo
  2012-06-29  9:59 ` [PATCH 2/3] Btrfs: update subvol_getflags/setflags to know new args from user Liu Bo
  2012-06-29  9:59 ` [PATCH 3/3] Btrfs: use helper function to simplify code Liu Bo
  0 siblings, 2 replies; 8+ messages in thread
From: Liu Bo @ 2012-06-29  9:59 UTC (permalink / raw)
  To: linux-btrfs

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


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

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

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-29  9:59 [PATCH 1/3] Btrfs: add default support for subvol getflags Liu Bo
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

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