Re: [patch] tmpfs: incr. link-count on directory rename

From: Jan Harkes (jaharkes@cs.cmu.edu)
Date: Thu Feb 14 2002 - 01:19:33 EST


On Thu, Feb 14, 2002 at 02:07:18AM +0100, Uli Martens wrote:
> When I move a directory into another on a tmpfs filesystem, the
> link-count of the new parent directory isn't getting incremented.
> (which leads to find getting hickup, which eg. lets dpkg produce a
> "bzip2" binary package without binaries, generally not a nice thing)

Yeah, that optimization actually breaks on so many filesystems
(AFS/Coda/iso9660/msdos/any filesystem which contains more than 65538
subdirectories in a directory/you name it) that they even provided a
flag to disable it (-noleaf), which in my opinion should always be the
default setting.

Another trick on the 'filesystem side' of things is to set the directory
linkcount to 1. Basically find always subtracts 2 and then as long as
the count is not zero, it will stat the entry to see if it's a
directory. So a directory linkcount of 1 will 'underflow' and find will
work correctly for the first 65535 sub-directories.

It's been on my todo list to use this fix in Coda as we have some link
count issues when we're flipping entries between 'faked' symlinks for
mountpoints/conflicts and real directories.

Jan

> @@ -1085,6 +1085,9 @@
> {
> int error = -ENOTEMPTY;
>
> + if (S_ISDIR(old_dentry->d_inode->i_mode)) {
> + new_dir->i_nlink++;
> + }
> if (shmem_empty(new_dentry)) {
> struct inode *inode = new_dentry->d_inode;
> if (inode) {

ps. shouldn't the linkcount of the old_dir get decremented too? Also you
should only change the linkcounts when the operation completed
successfully. i.e. something more like,

--- /tmp/shmem.c.orig Thu Feb 14 01:17:23 2002
+++ /tmp/shmem.c Thu Feb 14 01:18:25 2002
@@ -1100,6 +1100,10 @@
                 error = 0;
                 old_dentry->d_inode->i_ctime = old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
         }
+ if (!error && S_ISDIR(old_dentry->d_inode->i_mode)) {
+ old_dir->i_nlink--;
+ new_dir->i_nlink++;
+ }
         return error;
 }
 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Feb 15 2002 - 21:01:00 EST