Skip to contentSkip to conversation

ceph: ensure we have Fs caps when fetching dir link count

PATCH Superseded Jeff Layton 1 participant 2 messages Nov 10, 2020 Ceph client

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: ensure we have Fs caps when fetching dir link count

The link count for a directory is defined as inode->i_subdirs + 2, (for "." and ".."). i_subdirs is only populated when Fs caps are held. Ensure we grab Fs caps when fetching the link count for a directory.

URL: https://tracker.ceph.com/issues/48125

---
 fs/ceph/inode.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
fs/ceph/inode.c +10 -3
index 7c22bc2ea076..9ba15ca6b010 100644
@@ -2343,15 +2343,22 @@ int ceph_permission(struct inode *inode, int mask)
 }
 
 /* Craft a mask of needed caps given a set of requested statx attrs. */
-static int statx_to_caps(u32 want)
+static int statx_to_caps(u32 want, umode_t mode)
 {
 	int mask = 0;
 
 	if (want & (STATX_MODE|STATX_UID|STATX_GID|STATX_CTIME|STATX_BTIME))
 		mask |= CEPH_CAP_AUTH_SHARED;
 
-	if (want & (STATX_NLINK|STATX_CTIME))
+	if (want & (STATX_NLINK|STATX_CTIME)) {
 		mask |= CEPH_CAP_LINK_SHARED;
+		/*
+		 * The link count for directories depends on inode->i_subdirs,
+		 * and that is only updated when Fs caps are held.
+		 */
+		if (S_ISDIR(mode))
+			mask |= CEPH_CAP_FILE_SHARED;
+	}
 
 	if (want & (STATX_ATIME|STATX_MTIME|STATX_CTIME|STATX_SIZE|
 		    STATX_BLOCKS))
@@ -2377,7 +2384,7 @@ int ceph_getattr(const struct path *path, struct kstat *stat,
 
 	/* Skip the getattr altogether if we're asked not to sync */
 	if (!(flags & AT_STATX_DONT_SYNC)) {
-		err = ceph_do_getattr(inode, statx_to_caps(request_mask),
+		err = ceph_do_getattr(inode, statx_to_caps(request_mask, inode->i_mode),
 				      flags & AT_STATX_FORCE_SYNC);
 		if (err)
 			return err;
Signature · 1 line
2.28.0
#1 lore raw
Quoted 38 lines · Jeff Layton

The link count for a directory is defined as inode->i_subdirs + 2, (for "." and ".."). i_subdirs is only populated when Fs caps are held. Ensure we grab Fs caps when fetching the link count for a directory.

URL: https://tracker.ceph.com/issues/48125

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

 1 file changed, 10 insertions(+), 3 deletions(-)
fs/ceph/inode.c +0 -0
index 7c22bc2ea076..9ba15ca6b010 100644
@@ -2343,15 +2343,22 @@ int ceph_permission(struct inode *inode, int mask)
  }

 /* Craft a mask of needed caps given a set of requested statx attrs. */

fs/ceph/inode.c +1 -1
-static int statx_to_caps(u32 want)
+static int statx_to_caps(u32 want, umode_t mode)

 {
  int mask = 0;

  if (want & (STATX_MODE|STATX_UID|STATX_GID|STATX_CTIME|STATX_BTIME)) mask |= CEPH_CAP_AUTH_SHARED;

fs/ceph/inode.c +1 -1
-	if (want & (STATX_NLINK|STATX_CTIME))
+	if (want & (STATX_NLINK|STATX_CTIME)) {

  mask |= CEPH_CAP_LINK_SHARED;

fs/ceph/inode.c int ceph_permission(struct inode *inode, int mask) · line 2361

Quoted 7 lines
fs/ceph/inode.c +7 -0
+		/*
+		 * The link count for directories depends on inode->i_subdirs,
+		 * and that is only updated when Fs caps are held.
+		 */
+		if (S_ISDIR(mode))
+			mask |= CEPH_CAP_FILE_SHARED;
+	}

I think I'm going to make a small change here and make this not set the Ls bit on directories. There really is no need for it since only care about i_subdirs, and that might prevent having to do a synchronous call to the MDS.

Quoted 18 lines

  if (want & (STATX_ATIME|STATX_MTIME|STATX_CTIME|STATX_SIZE| STATX_BLOCKS))

fs/ceph/inode.c +0 -0
@@ -2377,7 +2384,7 @@ int ceph_getattr(const struct path *path, struct kstat *stat,

  /* Skip the getattr altogether if we're asked not to sync */ if (!(flags & AT_STATX_DONT_SYNC)) {

fs/ceph/inode.c +1 -1
-		err = ceph_do_getattr(inode, statx_to_caps(request_mask),
+		err = ceph_do_getattr(inode, statx_to_caps(request_mask, inode->i_mode),

  flags & AT_STATX_FORCE_SYNC); if (err)
  return err;

Signature · 1 line
Jeff Layton <[email protected]>