linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] btrfs: qgroup: return EINVAL if level of parent is not higher than child's.
@ 2015-01-22  5:46 Dongsheng Yang
  2015-01-22  5:46 ` [PATCH 2/3] btrfs: qgroup: allow user to remove qgroup which has parent but no child Dongsheng Yang
  2015-01-22  5:46 ` [PATCH 3/3] btrfs: qgroup: destroy related qgroup when removing subvolume if needed Dongsheng Yang
  0 siblings, 2 replies; 5+ messages in thread
From: Dongsheng Yang @ 2015-01-22  5:46 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Dongsheng Yang

When we create a qgroup inheriting a qgroup, we need to check the level
of them. Otherwise, there is a chance where a qgroup can inherit another qgroup
at the same level.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
---
 fs/btrfs/qgroup.c | 6 ++++++
 fs/btrfs/qgroup.h | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 953befd..c2983a4 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -2221,6 +2221,12 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
 				ret = -EINVAL;
 				goto out;
 			}
+
+			if ((srcgroup->qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT) <=
+			    (objectid >> BTRFS_QGROUP_LEVEL_SHIFT)) {
+				ret = -EINVAL;
+				goto out;
+			}
 			++i_qgroups;
 		}
 	}
diff --git a/fs/btrfs/qgroup.h b/fs/btrfs/qgroup.h
index 18cc68c..67291ff 100644
--- a/fs/btrfs/qgroup.h
+++ b/fs/btrfs/qgroup.h
@@ -20,6 +20,15 @@
 #define __BTRFS_QGROUP__
 
 /*
+ * The ID of a qgroup consists of a level and a id, looks like: 1/3.
+ * The 1 is the level means this qgroup is in the level 1 and the 3
+ * is the id of this qgroup in level 1. We use a u64 number store a
+ * qgroup ID, the first 16bits stands for the level and the last 48bits
+ * stands for the id.
+ */
+#define BTRFS_QGROUP_LEVEL_SHIFT	48
+
+/*
  * A description of the operations, all of these operations only happen when we
  * are adding the 1st reference for that subvolume in the case of adding space
  * or on the last reference delete in the case of subtraction.  The only
-- 
1.8.4.2


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

end of thread, other threads:[~2015-01-22  9:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-22  5:46 [PATCH 1/3] btrfs: qgroup: return EINVAL if level of parent is not higher than child's Dongsheng Yang
2015-01-22  5:46 ` [PATCH 2/3] btrfs: qgroup: allow user to remove qgroup which has parent but no child Dongsheng Yang
2015-01-22  5:46 ` [PATCH 3/3] btrfs: qgroup: destroy related qgroup when removing subvolume if needed Dongsheng Yang
2015-01-22  6:16   ` Wang Shilong
2015-01-22  9:46     ` Dongsheng Yang

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