]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ceph: fix st_nlink stat for directories
authorLuis Henriques <lhenriques@suse.com>
Mon, 21 May 2018 09:27:29 +0000 (10:27 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 4 Jun 2018 18:45:56 +0000 (20:45 +0200)
Currently, calling stat on a cephfs directory returns 1 for st_nlink.
This behaviour has recently changed in the fuse client, as some
applications seem to expect this value to be either 0 (if it's
unlinked) or 2 + number of subdirectories.  This behaviour was changed
in the fuse client with commit 67c7e4619188 ("client: use common
interp of st_nlink for dirs").

This patch modifies the kernel client to have a similar behaviour.

Link: https://tracker.ceph.com/issues/23873
Signed-off-by: Luis Henriques <lhenriques@suse.com>
Reviewed-by: "Yan, Zheng" <zyan@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/inode.c

index 4712c943cdf7a02de8fbc3c0943ab4efdb34c287..4aeccb13437bdbc4fad2dee6a6548eaece0e8188 100644 (file)
@@ -2271,6 +2271,14 @@ int ceph_getattr(const struct path *path, struct kstat *stat,
                                stat->size = ci->i_files + ci->i_subdirs;
                        stat->blocks = 0;
                        stat->blksize = 65536;
+                       /*
+                        * Some applications rely on the number of st_nlink
+                        * value on directories to be either 0 (if unlinked)
+                        * or 2 + number of subdirectories.
+                        */
+                       if (stat->nlink == 1)
+                               /* '.' + '..' + subdirs */
+                               stat->nlink = 1 + 1 + ci->i_subdirs;
                }
        }
        return err;