From 06b3a860dcf596bdc2bb1cca3252d3907b581938 Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Wed, 27 Feb 2013 11:16:57 +0000 Subject: Btrfs: fix missing deleted items in btrfs_clean_quota_tree Steps to reproduce: i=0 ncases=100 mkfs.btrfs mount btrfs quota enable btrfs qgroup create 2/1 while [ $i -le $ncases ] do btrfs qgroup create 1/$i btrfs qgroup assign 1/$i 2/1 i=$(($i+1)) done btrfs quota disable umount btrfsck You can also use the commands: btrfs-debug-tree | 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: Wang Shilong Signed-off-by: Miao Xie Signed-off-by: Josef Bacik --- fs/btrfs/qgroup.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 88ab785bbd73..f011d9b8ffb1 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -732,7 +732,9 @@ static int btrfs_clean_quota_tree(struct btrfs_trans_handle *trans, { struct btrfs_path *path; struct btrfs_key key; + struct extent_buffer *leaf = NULL; int ret; + int nr = 0; if (!root) return -EINVAL; @@ -741,24 +743,30 @@ static int btrfs_clean_quota_tree(struct btrfs_trans_handle *trans, if (!path) return -ENOMEM; - while (1) { - key.objectid = 0; - key.offset = 0; - key.type = 0; + path->leave_spinning = 1; - path->leave_spinning = 1; + key.objectid = 0; + key.offset = 0; + key.type = 0; + + while (1) { ret = btrfs_search_slot(trans, root, &key, path, -1, 1); - if (ret > 0) { - if (path->slots[0] == 0) - break; - path->slots[0]--; - } else if (ret < 0) { + if (ret < 0) + goto out; + leaf = path->nodes[0]; + nr = btrfs_header_nritems(leaf); + if (!nr) break; - } - - ret = btrfs_del_item(trans, root, path); + /* + * delete the leaf one by one + * since the whole tree is going + * to be deleted. + */ + path->slots[0] = 0; + ret = btrfs_del_items(trans, root, path, 0, nr); if (ret) goto out; + btrfs_release_path(path); } ret = 0; -- cgit v1.2.1