Skip to content

Commit 134d451

Browse files
ukernelchrismason-xx
authored andcommitted
Fix ENOTEMPTY check in btrfs_rmdir
The ENOTEMPTY check in btrfs_rmdir isn't reliable. It's possible that the backward search finds . or .. at first, then some other directory entry. In that case, btrfs_rmdir delete . or .. improperly. The patch also fixes a fs_mutex unlock issue in btrfs_rmdir. -- Signed-off-by: Chris Mason <[email protected]>
1 parent 0d9f7f3 commit 134d451

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/btrfs/inode.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
448448
char *goodnames = "..";
449449
unsigned long nr;
450450

451+
if (inode->i_size > BTRFS_EMPTY_DIR_SIZE)
452+
return -ENOTEMPTY;
453+
451454
path = btrfs_alloc_path();
452455
BUG_ON(!path);
453456
mutex_lock(&root->fs_info->fs_mutex);
@@ -501,9 +504,9 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
501504
out:
502505
btrfs_release_path(root, path);
503506
btrfs_free_path(path);
504-
mutex_unlock(&root->fs_info->fs_mutex);
505507
nr = trans->blocks_used;
506508
ret = btrfs_end_transaction(trans, root);
509+
mutex_unlock(&root->fs_info->fs_mutex);
507510
btrfs_btree_balance_dirty(root, nr);
508511
if (ret && !err)
509512
err = ret;

0 commit comments

Comments
 (0)