Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06b3a860 authored by Wang Shilong's avatar Wang Shilong Committed by Josef Bacik
Browse files

Btrfs: fix missing deleted items in btrfs_clean_quota_tree



Steps to reproduce:

	i=0
	ncases=100

	mkfs.btrfs <disk>
	mount <disk> <mnt>
	btrfs quota enable <mnt>
	btrfs qgroup create 2/1 <mnt>
	while [ $i -le $ncases ]
	do
		btrfs qgroup create 1/$i <mnt>
		btrfs qgroup assign 1/$i 2/1 <mnt>
		i=$(($i+1))
	done

	btrfs quota disable <mnt>
	umount <mnt>
	btrfsck <mnt>

You can also use the commands:
	btrfs-debug-tree <disk> | grep QGROUP

You will find there are still items existed.The reasons why this happens
is because the original code just checks slots[0]==0 and returns.
We try to fix it by deleting the leaf one by one.

Signed-off-by: default avatarWang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
parent b8dae313
Loading
Loading
Loading
Loading
+21 −13
Original line number Original line Diff line number Diff line
@@ -732,7 +732,9 @@ static int btrfs_clean_quota_tree(struct btrfs_trans_handle *trans,
{
{
	struct btrfs_path *path;
	struct btrfs_path *path;
	struct btrfs_key key;
	struct btrfs_key key;
	struct extent_buffer *leaf = NULL;
	int ret;
	int ret;
	int nr = 0;


	if (!root)
	if (!root)
		return -EINVAL;
		return -EINVAL;
@@ -741,24 +743,30 @@ static int btrfs_clean_quota_tree(struct btrfs_trans_handle *trans,
	if (!path)
	if (!path)
		return -ENOMEM;
		return -ENOMEM;


	while (1) {
	path->leave_spinning = 1;

	key.objectid = 0;
	key.objectid = 0;
	key.offset = 0;
	key.offset = 0;
	key.type = 0;
	key.type = 0;


		path->leave_spinning = 1;
	while (1) {
		ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
		ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
		if (ret > 0) {
		if (ret < 0)
			if (path->slots[0] == 0)
			goto out;
				break;
		leaf = path->nodes[0];
			path->slots[0]--;
		nr = btrfs_header_nritems(leaf);
		} else if (ret < 0) {
		if (!nr)
			break;
			break;
		}
		/*

		 * delete the leaf one by one
		ret = btrfs_del_item(trans, root, path);
		 * since the whole tree is going
		 * to be deleted.
		 */
		path->slots[0] = 0;
		ret = btrfs_del_items(trans, root, path, 0, nr);
		if (ret)
		if (ret)
			goto out;
			goto out;

		btrfs_release_path(path);
		btrfs_release_path(path);
	}
	}
	ret = 0;
	ret = 0;