Skip to contentSkip to conversation

btrfs: qgroup: Remove qgroup item along with subvolume deletion

PATCH Superseded Misono Tomohiro 4 participants 11 messages Aug 3, 2018 – Aug 6, 2018 1 message not in the archive Btrfs file system

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 btrfs: qgroup: Remove qgroup item along with subvolume deletion

In reply to a message not in the archive

When qgroup is on, subvolume deletion does not remove qgroup items of the subvolume (qgroup info, limits, relation) from quota tree and they need to get removed manually by "btrfs qgroup destroy".

Since level 0 qgroup cannot be used/inherited by any other subvolume, let's remove them automatically when subvolume is deleted.

---

I don't see any reason to keep these items after subvolume deletion, but is there something I'm missing?

 fs/btrfs/inode.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/btrfs/inode.c +4 -0
index 3f51ddc18f98..4ec60a1b53a3 100644
@@ -4372,6 +4372,10 @@ int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry)
 		}
 	}
 
+	ret = btrfs_remove_qgroup(trans, dest->root_key.objectid);
+	if (ret == -EINVAL || ret == -ENOENT)
+		ret = 0;
+
 out_end_trans:
 	trans->block_rsv = NULL;
 	trans->bytes_reserved = 0;
Signature · 1 line
2.14.4
#2 lore raw
Quoted 21 lines · Misono Tomohiro

When qgroup is on, subvolume deletion does not remove qgroup items of the subvolume (qgroup info, limits, relation) from quota tree and they need to get removed manually by "btrfs qgroup destroy".

Since level 0 qgroup cannot be used/inherited by any other subvolume, let's remove them automatically when subvolume is deleted.

---

I don't see any reason to keep these items after subvolume deletion, but is there something I'm missing?

 fs/btrfs/inode.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/btrfs/inode.c +0 -0
index 3f51ddc18f98..4ec60a1b53a3 100644

fs/btrfs/inode.c int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry) · line 4375

Quoted 4 lines
fs/btrfs/inode.c +1 -0
@@ -4372,6 +4372,10 @@ int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry)
 		}
 	}
 
+	ret = btrfs_remove_qgroup(trans, dest->root_key.objectid);

According to the caller, it only unlinks the subvolume without really delete the whole subvolume.

I'm wondering if we should call btrfs_remove_qgroup() only after we have deleted the whole subvolume, e.g inside btrfs_drop_snapshot().

Thanks,
Qu

Quoted 7 lines
fs/btrfs/inode.c +3 -0
+	if (ret == -EINVAL || ret == -ENOENT)
+		ret = 0;
+
 out_end_trans:
 	trans->block_rsv = NULL;
 	trans->bytes_reserved = 0;
#3 lore raw
Quoted 27 lines · Qu Wenruo
Quoted 24 lines · Misono Tomohiro

When qgroup is on, subvolume deletion does not remove qgroup items of the subvolume (qgroup info, limits, relation) from quota tree and they need to get removed manually by "btrfs qgroup destroy".

Since level 0 qgroup cannot be used/inherited by any other subvolume, let's remove them automatically when subvolume is deleted.

---

I don't see any reason to keep these items after subvolume deletion, but is there something I'm missing?

 fs/btrfs/inode.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/btrfs/inode.c +0 -0
index 3f51ddc18f98..4ec60a1b53a3 100644
@@ -4372,6 +4372,10 @@ int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry)
 		}
 	}
 
Quoted 7 lines

fs/btrfs/inode.c int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry) · line 4375

Quoted 1 line
fs/btrfs/inode.c +1 -0
+	ret = btrfs_remove_qgroup(trans, dest->root_key.objectid);

According to the caller, it only unlinks the subvolume without really delete the whole subvolume.

I'm wondering if we should call btrfs_remove_qgroup() only after we have deleted the whole subvolume, e.g inside btrfs_drop_snapshot().

I agree with Qu's point, because the ongoing online undelete subvolume will be able to recover the subvolume which is intact ondisk, including the qgroup.

Signature · 2 lines
Thanks,
Lu
Quoted 12 lines

Thanks,
Qu

Quoted 7 lines
fs/btrfs/inode.c +3 -0
+	if (ret == -EINVAL || ret == -ENOENT)
+		ret = 0;
+
 out_end_trans:
 	trans->block_rsv = NULL;
 	trans->bytes_reserved = 0;
#4 lore raw
Quoted 33 lines · Lu Fengqi
Quoted 32 lines · Qu Wenruo
Quoted 21 lines · Misono Tomohiro

When qgroup is on, subvolume deletion does not remove qgroup items of the subvolume (qgroup info, limits, relation) from quota tree and they need to get removed manually by "btrfs qgroup destroy".

Since level 0 qgroup cannot be used/inherited by any other subvolume, let's remove them automatically when subvolume is deleted.

---

I don't see any reason to keep these items after subvolume deletion, but is there something I'm missing?

 fs/btrfs/inode.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/btrfs/inode.c +0 -0
index 3f51ddc18f98..4ec60a1b53a3 100644

fs/btrfs/inode.c int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry) · line 4375

Quoted 4 lines
fs/btrfs/inode.c +1 -0
@@ -4372,6 +4372,10 @@ int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry)
 		}
 	}
 
+	ret = btrfs_remove_qgroup(trans, dest->root_key.objectid);

According to the caller, it only unlinks the subvolume without really delete the whole subvolume.

Quoted 6 lines
Quoted 2 lines

I'm wondering if we should call btrfs_remove_qgroup() only after we have deleted the whole subvolume, e.g inside btrfs_drop_snapshot().

I agree with Qu's point, because the ongoing online undelete subvolume will be able to recover the subvolume which is intact ondisk, including the qgroup.

Thanks to both of you, I'll update the patch.
Misono

#5 lore raw

PATCH v2 1/1 btrfs: qgroup: Remove qgroup item along with subvolume deletion

In reply to Misono Tomohiro

When qgroup is on, subvolume deletion does not remove qgroup item of the subvolume (qgroup info, limits, relation) from quota tree and they needs to get removed manually by "btrfs qgroup destroy".

Since level 0 qgroup cannot be used/inherited by any other subvolume, let's remove them automatically when subvolume is deleted (to be precise, when the subvolume root is dropped).

---
Note that btrfs/057 fails, but it is the problem of testcase. I will update it too.

v1 -> v2:
Move call of btrfs_remove_qgroup() from btrfs_delete_subvolume() to btrfs_snapshot_destroy() so that it will be called after the subvolume root is really dropped

 fs/btrfs/extent-tree.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
fs/btrfs/extent-tree.c +12 -4
index 9e7b237b9547..b56dea8c8b9f 100644
@@ -8871,12 +8871,13 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 	struct btrfs_root_item *root_item = &root->root_item;
 	struct walk_control *wc;
 	struct btrfs_key key;
+	u64 objectid = root->objectid;
 	int err = 0;
 	int ret;
 	int level;
 	bool root_dropped = false;
 
-	btrfs_debug(fs_info, "Drop subvolume %llu", root->objectid);
+	btrfs_debug(fs_info, "Drop subvolume %llu", objectid);
 
 	path = btrfs_alloc_path();
 	if (!path) {
@@ -9030,7 +9031,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		goto out_end_trans;
 	}
 
-	if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
+	if (objectid != BTRFS_TREE_RELOC_OBJECTID) {
 		ret = btrfs_find_root(tree_root, &root->root_key, path,
 				      NULL, NULL);
 		if (ret < 0) {
@@ -9043,8 +9044,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 			 *
 			 * The most common failure here is just -ENOENT.
 			 */
-			btrfs_del_orphan_item(trans, tree_root,
-					      root->root_key.objectid);
+			btrfs_del_orphan_item(trans, tree_root, objectid);
 		}
 	}
 
@@ -9056,6 +9056,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		btrfs_put_fs_root(root);
 	}
 	root_dropped = true;
+
+	 /* Remove level-0 qgroup items since no other subvolume can use them */
+	ret = btrfs_remove_qgroup(trans, objectid);
+	if (ret && ret != -EINVAL && ret != -ENOENT) {
+		btrfs_abort_transaction(trans, ret);
+		err = ret;
+	}
+
 out_end_trans:
 	btrfs_end_transaction_throttle(trans);
 out_free:
Signature · 1 line
2.14.4
Reviewed-by on v2 1/1
#6 lore raw
Quoted 9 lines · Misono Tomohiro

When qgroup is on, subvolume deletion does not remove qgroup item of the subvolume (qgroup info, limits, relation) from quota tree and they needs to get removed manually by "btrfs qgroup destroy".

Since level 0 qgroup cannot be used/inherited by any other subvolume, let's remove them automatically when subvolume is deleted (to be precise, when the subvolume root is dropped).

Looks good to me.

There is an off-topic question below.

Quoted 32 lines

---
Note that btrfs/057 fails, but it is the problem of testcase. I will update it too.

v1 -> v2:
Move call of btrfs_remove_qgroup() from btrfs_delete_subvolume() to btrfs_snapshot_destroy() so that it will be called after the subvolume root is really dropped

fs/btrfs/extent-tree.c | 16 ++++++++++++----

1 file changed, 12 insertions(+), 4 deletions(-)
fs/btrfs/extent-tree.c +2 -1
index 9e7b237b9547..b56dea8c8b9f 100644
@@ -8871,12 +8871,13 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 	struct btrfs_root_item *root_item = &root->root_item;
 	struct walk_control *wc;
 	struct btrfs_key key;
+	u64 objectid = root->objectid;
 	int err = 0;
 	int ret;
 	int level;
 	bool root_dropped = false;
 
-	btrfs_debug(fs_info, "Drop subvolume %llu", root->objectid);
+	btrfs_debug(fs_info, "Drop subvolume %llu", objectid);
 
 	path = btrfs_alloc_path();
 	if (!path) {

fs/btrfs/extent-tree.c int btrfs_drop_snapshot(struct btrfs_root *root, · line 9034

Quoted 5 lines
fs/btrfs/extent-tree.c +1 -1
@@ -9030,7 +9031,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		goto out_end_trans;
 	}
 
-	if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
+	if (objectid != BTRFS_TREE_RELOC_OBJECTID) {

Here use root->objectid instead of root->root_key.objectid. If I recall correctly, the root->objectid and root->root_key.objectid are set to the identical value. I just wonder if there is any difference between the two "objectid"s after the btrfs_root was created?

--
Thanks,
Lu

Quoted 38 lines
fs/btrfs/extent-tree.c +9 -2
 		ret = btrfs_find_root(tree_root, &root->root_key, path,
 				      NULL, NULL);
 		if (ret < 0) {
@@ -9043,8 +9044,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 			 *
 			 * The most common failure here is just -ENOENT.
 			 */
-			btrfs_del_orphan_item(trans, tree_root,
-					      root->root_key.objectid);
+			btrfs_del_orphan_item(trans, tree_root, objectid);
 		}
 	}
 
@@ -9056,6 +9056,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		btrfs_put_fs_root(root);
 	}
 	root_dropped = true;
+
+	 /* Remove level-0 qgroup items since no other subvolume can use them */
+	ret = btrfs_remove_qgroup(trans, objectid);
+	if (ret && ret != -EINVAL && ret != -ENOENT) {
+		btrfs_abort_transaction(trans, ret);
+		err = ret;
+	}
+

out_end_trans:

	btrfs_end_transaction_throttle(trans);

out_free:

Signature · 7 lines
2.14.4


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw
Quoted 9 lines · Lu Fengqi
Quoted 8 lines · Misono Tomohiro

When qgroup is on, subvolume deletion does not remove qgroup item of the subvolume (qgroup info, limits, relation) from quota tree and they needs to get removed manually by "btrfs qgroup destroy".

Since level 0 qgroup cannot be used/inherited by any other subvolume, let's remove them automatically when subvolume is deleted (to be precise, when the subvolume root is dropped).

Quoted 5 lines
Quoted 1 line

Looks good to me.

Thanks for the review.

Quoted 38 lines

There is an off-topic question below.

Quoted 35 lines

---
Note that btrfs/057 fails, but it is the problem of testcase. I will update it too.

v1 -> v2:
Move call of btrfs_remove_qgroup() from btrfs_delete_subvolume() to btrfs_snapshot_destroy() so that it will be called after the subvolume root is really dropped

fs/btrfs/extent-tree.c | 16 ++++++++++++----

1 file changed, 12 insertions(+), 4 deletions(-)
fs/btrfs/extent-tree.c +2 -1
index 9e7b237b9547..b56dea8c8b9f 100644
@@ -8871,12 +8871,13 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 	struct btrfs_root_item *root_item = &root->root_item;
 	struct walk_control *wc;
 	struct btrfs_key key;
+	u64 objectid = root->objectid;
 	int err = 0;
 	int ret;
 	int level;
 	bool root_dropped = false;
 
-	btrfs_debug(fs_info, "Drop subvolume %llu", root->objectid);
+	btrfs_debug(fs_info, "Drop subvolume %llu", objectid);
 
 	path = btrfs_alloc_path();
 	if (!path) {
@@ -9030,7 +9031,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		goto out_end_trans;
 	}
 
Quoted 7 lines

fs/btrfs/extent-tree.c int btrfs_drop_snapshot(struct btrfs_root *root, · line 9034

Quoted 2 lines
fs/btrfs/extent-tree.c +1 -1
-	if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
+	if (objectid != BTRFS_TREE_RELOC_OBJECTID) {

Here use root->objectid instead of root->root_key.objectid. If I recall correctly, the root->objectid and root->root_key.objectid are set to the identical value. I just wonder if there is any difference between the two "objectid"s after the btrfs_root was created?

in __setup_root(root, fs_info, objectid):
<snip>
root->objectid = objectid;
<snip>
root->root_key.objectid = objectid;
<snip>

and I don't see any update of objectid from "grep -r "root_key.objectid ="", I think it the same too (and fstests is ok), but any comment from those who more familiar with code is helpful.

thanks,
Misono

Quoted 50 lines

--
Thanks,
Lu

Quoted 26 lines
fs/btrfs/extent-tree.c +9 -2
 		ret = btrfs_find_root(tree_root, &root->root_key, path,
 				      NULL, NULL);
 		if (ret < 0) {
@@ -9043,8 +9044,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 			 *
 			 * The most common failure here is just -ENOENT.
 			 */
-			btrfs_del_orphan_item(trans, tree_root,
-					      root->root_key.objectid);
+			btrfs_del_orphan_item(trans, tree_root, objectid);
 		}
 	}
 
@@ -9056,6 +9056,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		btrfs_put_fs_root(root);
 	}
 	root_dropped = true;
+
+	 /* Remove level-0 qgroup items since no other subvolume can use them */
+	ret = btrfs_remove_qgroup(trans, objectid);
+	if (ret && ret != -EINVAL && ret != -ENOENT) {
+		btrfs_abort_transaction(trans, ret);
+		err = ret;
+	}
+

out_end_trans:

Quoted 12 lines
	btrfs_end_transaction_throttle(trans);

out_free:

Signature · 7 lines
2.14.4


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
Quoted 71 lines · Misono Tomohiro
Quoted 9 lines · Lu Fengqi
Quoted 8 lines · Misono Tomohiro

When qgroup is on, subvolume deletion does not remove qgroup item of the subvolume (qgroup info, limits, relation) from quota tree and they needs to get removed manually by "btrfs qgroup destroy".

Since level 0 qgroup cannot be used/inherited by any other subvolume, let's remove them automatically when subvolume is deleted (to be precise, when the subvolume root is dropped).

Quoted 5 lines
Quoted 1 line

Looks good to me.

Thanks for the review.

Quoted 38 lines

There is an off-topic question below.

Quoted 35 lines

---
Note that btrfs/057 fails, but it is the problem of testcase. I will update it too.

v1 -> v2:
Move call of btrfs_remove_qgroup() from btrfs_delete_subvolume() to btrfs_snapshot_destroy() so that it will be called after the subvolume root is really dropped

fs/btrfs/extent-tree.c | 16 ++++++++++++----

1 file changed, 12 insertions(+), 4 deletions(-)
fs/btrfs/extent-tree.c +2 -1
index 9e7b237b9547..b56dea8c8b9f 100644
@@ -8871,12 +8871,13 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 	struct btrfs_root_item *root_item = &root->root_item;
 	struct walk_control *wc;
 	struct btrfs_key key;
+	u64 objectid = root->objectid;
 	int err = 0;
 	int ret;
 	int level;
 	bool root_dropped = false;
 
-	btrfs_debug(fs_info, "Drop subvolume %llu", root->objectid);
+	btrfs_debug(fs_info, "Drop subvolume %llu", objectid);
 
 	path = btrfs_alloc_path();
 	if (!path) {
@@ -9030,7 +9031,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		goto out_end_trans;
 	}
 
Quoted 7 lines

fs/btrfs/extent-tree.c int btrfs_drop_snapshot(struct btrfs_root *root, · line 9034

Quoted 2 lines
fs/btrfs/extent-tree.c +1 -1
-	if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
+	if (objectid != BTRFS_TREE_RELOC_OBJECTID) {

Here use root->objectid instead of root->root_key.objectid. If I recall correctly, the root->objectid and root->root_key.objectid are set to the identical value. I just wonder if there is any difference between the two "objectid"s after the btrfs_root was created?

in __setup_root(root, fs_info, objectid):
<snip>
root->objectid = objectid;
<snip>
root->root_key.objectid = objectid;
<snip>

Quoted 3 lines

and I don't see any update of objectid from "grep -r "root_key.objectid ="", I think it the same too (and fstests is ok), but any comment from those who more familiar with code is helpful.

Perhaps root->objectid should be removed altogether, if it's a duplicate of root->root_key.objectid

Quoted 60 lines

thanks,
Misono

Quoted 37 lines

--
Thanks,
Lu

Quoted 32 lines
fs/btrfs/extent-tree.c +9 -2
 		ret = btrfs_find_root(tree_root, &root->root_key, path,
 				      NULL, NULL);
 		if (ret < 0) {
@@ -9043,8 +9044,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 			 *
 			 * The most common failure here is just -ENOENT.
 			 */
-			btrfs_del_orphan_item(trans, tree_root,
-					      root->root_key.objectid);
+			btrfs_del_orphan_item(trans, tree_root, objectid);
 		}
 	}
 
@@ -9056,6 +9056,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		btrfs_put_fs_root(root);
 	}
 	root_dropped = true;
+
+	 /* Remove level-0 qgroup items since no other subvolume can use them */
+	ret = btrfs_remove_qgroup(trans, objectid);
+	if (ret && ret != -EINVAL && ret != -ENOENT) {
+		btrfs_abort_transaction(trans, ret);
+		err = ret;
+	}
+

out_end_trans:

	btrfs_end_transaction_throttle(trans);

out_free:

Signature · 1 line
2.14.4
Quoted 13 lines
Quoted 6 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Reviewed-by
#9 lore raw
Quoted 13 lines · Nikolay Borisov
Quoted 10 lines · Misono Tomohiro
Quoted 9 lines · Lu Fengqi
Quoted 8 lines · Misono Tomohiro

When qgroup is on, subvolume deletion does not remove qgroup item of the subvolume (qgroup info, limits, relation) from quota tree and they needs to get removed manually by "btrfs qgroup destroy".

Since level 0 qgroup cannot be used/inherited by any other subvolume, let's remove them automatically when subvolume is deleted (to be precise, when the subvolume root is dropped).

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

Looks good to me.

[snip]

Quoted 15 lines
Quoted 15 lines
Quoted 7 lines

fs/btrfs/extent-tree.c int btrfs_drop_snapshot(struct btrfs_root *root, · line 9034

Quoted 2 lines
fs/btrfs/extent-tree.c +1 -1
-	if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
+	if (objectid != BTRFS_TREE_RELOC_OBJECTID) {

Here use root->objectid instead of root->root_key.objectid. If I recall correctly, the root->objectid and root->root_key.objectid are set to the identical value. I just wonder if there is any difference between the two "objectid"s after the btrfs_root was created?

in __setup_root(root, fs_info, objectid):
<snip>
root->objectid = objectid;
<snip>
root->root_key.objectid = objectid;
<snip>

Quoted 6 lines
Quoted 3 lines

and I don't see any update of objectid from "grep -r "root_key.objectid ="", I think it the same too (and fstests is ok), but any comment from those who more familiar with code is helpful.

Perhaps root->objectid should be removed altogether, if it's a duplicate of root->root_key.objectid

Yep, cleaning up root->objectid looks pretty good to me.

In fact, root->objectid is not enough to distinguish tree reloc trees. So using root->root_key should be a safer way to go.

Thanks,
Qu

Quoted 66 lines
Quoted 56 lines

thanks,
Misono

Quoted 37 lines

--
Thanks,
Lu

Quoted 32 lines
		ret = btrfs_find_root(tree_root, &root->root_key, path,
				      NULL, NULL);
		if (ret < 0) {
fs/btrfs/extent-tree.c +9 -2
@@ -9043,8 +9044,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 			 *
 			 * The most common failure here is just -ENOENT.
 			 */
-			btrfs_del_orphan_item(trans, tree_root,
-					      root->root_key.objectid);
+			btrfs_del_orphan_item(trans, tree_root, objectid);
 		}
 	}
 
@@ -9056,6 +9056,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		btrfs_put_fs_root(root);
 	}
 	root_dropped = true;
+
+	 /* Remove level-0 qgroup items since no other subvolume can use them */
+	ret = btrfs_remove_qgroup(trans, objectid);
+	if (ret && ret != -EINVAL && ret != -ENOENT) {
+		btrfs_abort_transaction(trans, ret);
+		err = ret;
+	}
+

out_end_trans:

	btrfs_end_transaction_throttle(trans);

out_free:

Signature · 1 line
2.14.4
Quoted 13 lines
Quoted 6 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw
In reply to Nikolay Borisov
Quoted 74 lines · Nikolay Borisov
Quoted 71 lines · Misono Tomohiro
Quoted 9 lines · Lu Fengqi
Quoted 8 lines · Misono Tomohiro

When qgroup is on, subvolume deletion does not remove qgroup item of the subvolume (qgroup info, limits, relation) from quota tree and they needs to get removed manually by "btrfs qgroup destroy".

Since level 0 qgroup cannot be used/inherited by any other subvolume, let's remove them automatically when subvolume is deleted (to be precise, when the subvolume root is dropped).

Quoted 5 lines
Quoted 1 line

Looks good to me.

Thanks for the review.

Quoted 38 lines

There is an off-topic question below.

Quoted 35 lines

---
Note that btrfs/057 fails, but it is the problem of testcase. I will update it too.

v1 -> v2:
Move call of btrfs_remove_qgroup() from btrfs_delete_subvolume() to btrfs_snapshot_destroy() so that it will be called after the subvolume root is really dropped

fs/btrfs/extent-tree.c | 16 ++++++++++++----

1 file changed, 12 insertions(+), 4 deletions(-)
fs/btrfs/extent-tree.c +2 -1
index 9e7b237b9547..b56dea8c8b9f 100644
@@ -8871,12 +8871,13 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 	struct btrfs_root_item *root_item = &root->root_item;
 	struct walk_control *wc;
 	struct btrfs_key key;
+	u64 objectid = root->objectid;
 	int err = 0;
 	int ret;
 	int level;
 	bool root_dropped = false;
 
-	btrfs_debug(fs_info, "Drop subvolume %llu", root->objectid);
+	btrfs_debug(fs_info, "Drop subvolume %llu", objectid);
 
 	path = btrfs_alloc_path();
 	if (!path) {
@@ -9030,7 +9031,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		goto out_end_trans;
 	}
 
Quoted 7 lines

fs/btrfs/extent-tree.c int btrfs_drop_snapshot(struct btrfs_root *root, · line 9034

Quoted 2 lines
fs/btrfs/extent-tree.c +1 -1
-	if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
+	if (objectid != BTRFS_TREE_RELOC_OBJECTID) {

Here use root->objectid instead of root->root_key.objectid. If I recall correctly, the root->objectid and root->root_key.objectid are set to the identical value. I just wonder if there is any difference between the two "objectid"s after the btrfs_root was created?

in __setup_root(root, fs_info, objectid):
<snip>
root->objectid = objectid;
<snip>
root->root_key.objectid = objectid;
<snip>

Quoted 6 lines
Quoted 3 lines

and I don't see any update of objectid from "grep -r "root_key.objectid ="", I think it the same too (and fstests is ok), but any comment from those who more familiar with code is helpful.

Perhaps root->objectid should be removed altogether, if it's a duplicate of root->root_key.objectid

That's great! I hate these useless redundancies because they always make me confused. So Misono could you update this patch to use root->root_key.objectid?

Signature · 2 lines
Thanks,
Lu
Quoted 66 lines
Quoted 56 lines

thanks,
Misono

Quoted 37 lines

--
Thanks,
Lu

Quoted 32 lines
fs/btrfs/extent-tree.c +9 -2
 		ret = btrfs_find_root(tree_root, &root->root_key, path,
 				      NULL, NULL);
 		if (ret < 0) {
@@ -9043,8 +9044,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 			 *
 			 * The most common failure here is just -ENOENT.
 			 */
-			btrfs_del_orphan_item(trans, tree_root,
-					      root->root_key.objectid);
+			btrfs_del_orphan_item(trans, tree_root, objectid);
 		}
 	}
 
@@ -9056,6 +9056,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		btrfs_put_fs_root(root);
 	}
 	root_dropped = true;
+
+	 /* Remove level-0 qgroup items since no other subvolume can use them */
+	ret = btrfs_remove_qgroup(trans, objectid);
+	if (ret && ret != -EINVAL && ret != -ENOENT) {
+		btrfs_abort_transaction(trans, ret);
+		err = ret;
+	}
+

out_end_trans:

	btrfs_end_transaction_throttle(trans);

out_free:

Signature · 1 line
2.14.4
Quoted 13 lines
Quoted 6 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw
Quoted 79 lines · Lu Fengqi
Quoted 78 lines · Nikolay Borisov
Quoted 74 lines · Misono Tomohiro
Quoted 9 lines · Lu Fengqi
Quoted 8 lines · Misono Tomohiro

When qgroup is on, subvolume deletion does not remove qgroup item of the subvolume (qgroup info, limits, relation) from quota tree and they needs to get removed manually by "btrfs qgroup destroy".

Since level 0 qgroup cannot be used/inherited by any other subvolume, let's remove them automatically when subvolume is deleted (to be precise, when the subvolume root is dropped).

Quoted 5 lines
Quoted 1 line

Looks good to me.

Thanks for the review.

Quoted 38 lines

There is an off-topic question below.

Quoted 35 lines

---
Note that btrfs/057 fails, but it is the problem of testcase. I will update it too.

v1 -> v2:
Move call of btrfs_remove_qgroup() from btrfs_delete_subvolume() to btrfs_snapshot_destroy() so that it will be called after the subvolume root is really dropped

fs/btrfs/extent-tree.c | 16 ++++++++++++----

1 file changed, 12 insertions(+), 4 deletions(-)
fs/btrfs/extent-tree.c +2 -1
index 9e7b237b9547..b56dea8c8b9f 100644
@@ -8871,12 +8871,13 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 	struct btrfs_root_item *root_item = &root->root_item;
 	struct walk_control *wc;
 	struct btrfs_key key;
+	u64 objectid = root->objectid;
 	int err = 0;
 	int ret;
 	int level;
 	bool root_dropped = false;
 
-	btrfs_debug(fs_info, "Drop subvolume %llu", root->objectid);
+	btrfs_debug(fs_info, "Drop subvolume %llu", objectid);
 
 	path = btrfs_alloc_path();
 	if (!path) {
@@ -9030,7 +9031,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		goto out_end_trans;
 	}
 
Quoted 7 lines

fs/btrfs/extent-tree.c int btrfs_drop_snapshot(struct btrfs_root *root, · line 9034

Quoted 2 lines
fs/btrfs/extent-tree.c +1 -1
-	if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
+	if (objectid != BTRFS_TREE_RELOC_OBJECTID) {

Here use root->objectid instead of root->root_key.objectid. If I recall correctly, the root->objectid and root->root_key.objectid are set to the identical value. I just wonder if there is any difference between the two "objectid"s after the btrfs_root was created?

in __setup_root(root, fs_info, objectid):
<snip>
root->objectid = objectid;
<snip>
root->root_key.objectid = objectid;
<snip>

and I don't see any update of objectid from "grep -r "root_key.objectid ="", I think it the same too (and fstests is ok), but any comment from those who more familiar with code is helpful.

Quoted 6 lines
Quoted 2 lines

Perhaps root->objectid should be removed altogether, if it's a duplicate of root->root_key.objectid

That's great! I hate these useless redundancies because they always make me confused. So Misono could you update this patch to use root->root_key.objectid?

Ok. Also I'll try to see if it is possible to remove root->objectid. Misono