[lkml]   [2010]   [Aug]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[065/111] Btrfs: fix regression in orphan cleanup
2.6.32-stable review patch.  If anyone has any objections, please let us know.


From: Josef Bacik <>

commit 6c090a11e1c403b727a6a8eff0b97d5fb9e95cb5 upstream.

Currently orphan cleanup only ever gets triggered if we cross subvolumes during
a lookup, which means that if we just mount a plain jane fs that has orphans in
it, they will never get cleaned up. This results in panic's like these

where adding an orphan entry results in -EEXIST being returned and we panic. In
order to fix this, we check to see on lookup if our root has had the orphan
cleanup done, and if not go ahead and do it. This is easily reproduceable by
running this testcase

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv)
char data[4096];
char newdata[4096];
int fd1, fd2;

memset(data, 'a', 4096);
memset(newdata, 'b', 4096);

while (1) {
int i;

fd1 = creat("file1", 0666);
if (fd1 < 0)

for (i = 0; i < 512; i++)
write(fd1, data, 4096);


fd2 = creat("file2", 0666);
if (fd2 < 0)

ftruncate(fd2, 4096 * 512);

for (i = 0; i < 512; i++)
write(fd2, newdata, 4096);

i = rename("file2", "file1");

return 0;

and then pulling the power on the box, and then trying to run that test again
when the box comes back up. I've tested this locally and it fixes the problem.
Thanks to Tomas Carnecky for helping me track this down initially.

Signed-off-by: Josef Bacik <>
Signed-off-by: Chris Mason <>
Acked-by: Jeff Mahoney <>
Signed-off-by: Greg Kroah-Hartman <>

fs/btrfs/inode.c | 6 ++++++
1 file changed, 6 insertions(+)

--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3796,6 +3796,12 @@ struct inode *btrfs_lookup_dentry(struct

if (location.type == BTRFS_INODE_ITEM_KEY) {
inode = btrfs_iget(dir->i_sb, &location, root);
+ if (unlikely(root->clean_orphans) &&
+ !(inode->i_sb->s_flags & MS_RDONLY)) {
+ down_read(&root->fs_info->cleanup_work_sem);
+ btrfs_orphan_cleanup(root);
+ up_read(&root->fs_info->cleanup_work_sem);
+ }
return inode;

 \ /
  Last update: 2010-08-12 02:05    [W:0.429 / U:0.376 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site