Skip to contentSkip to conversation

ceph: fix st_nlink stat for directories

PATCH Applied Luis Henriques 2 participants 2 messages May 21, 2018 Ceph client

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: fix st_nlink stat for directories

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.

---
 fs/ceph/inode.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/ceph/inode.c +8 -0
index aa7c5a4ff137..6ad66ef8fd66 100644
@@ -2288,6 +2288,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;
Applied
#1 lore raw
Quoted 28 lines · Luis Henriques

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.

---
fs/ceph/inode.c | 8 ++++++++

1 file changed, 8 insertions(+)
fs/ceph/inode.c +1 -0
index aa7c5a4ff137..6ad66ef8fd66 100644
@@ -2288,6 +2288,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;
+			/*

fs/ceph/inode.c int ceph_getattr(const struct path *path, struct kstat *stat, · line 2301

Quoted 10 lines
fs/ceph/inode.c +7 -0
+			 * 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;

Applied, thanks.

Yan, Zheng