lk: drop parent's nlink during directory unlink

Alex Chiang achiang at hp.com
Fri May 2 16:43:40 PDT 2008


Hi Zach,

Can you give this patch a think?

I was running into a problem where I couldn't rmdir
subdirectories:

	$ mkdir foo && sync
	$ cd foo
	$ mkdir bar && sync
	$ rmdir bar && sync
	$ cd ..
	$ rmdir foo
	rmdir: failed to remove `foo': Directory not empty

Basically, we weren't dropping nlink in our parent directory
during the 'rmdir bar'.

This patch fixes the issue. My doubt comes from, should we be
doing a simple drop_nlink() on our parent directory, or should we
be expressing that as a change?

It seems that the simple drop_nlink() is sufficient because we've
already dirtied our parent directory's inode when we updated its
timestamps. But it would be nice to hear what you think...

I tested with the crfs test suite:

	all tests passed

We also get a *lot* further in the POSIX test suite. Now, we pass
all of the following tests:

	chflags
	chmod
	chown
	mkdir
	mkfifo
	open

Note that for each interface above, there are probably ~100 or so
individual tests.

We still have problems in the following:

	link	# probably due to the #if 0 around crfs_link ;)
	rename	# will look at this stuff after link

Thanks!

/ac

From: Alex Chiang <achiang at hp.com>

When unlinking a directory, need to drop the parent's nlink
count as well.

Signed-off-by: Alex Chiang <achiang at hp.com>
---
diff -r 77848719c4ba lk/namei.c
--- a/lk/namei.c	Tue Apr 22 14:03:17 2008 -0700
+++ b/lk/namei.c	Fri May 02 17:23:33 2008 -0600
@@ -645,6 +645,8 @@ static int crfs_unlink(struct inode *dir
 	dir->i_mtime = CURRENT_TIME;
 	dir->i_ctime = dir->i_mtime;
 	drop_nlink(inode);
+	if (S_ISDIR(inode->i_mode))
+		drop_nlink(dir);
 	/* XXX I'm not sure when we drop nlink for . and .. */
 
 	/* now call all the change functions to update the crfs items */



More information about the crfs-devel mailing list