Thread (50 messages) 50 messages, 8 authors, 2021-09-25

Re: [PATCH v2] BTRFS/NFSD: provide more unique inode number for btrfs export

From: J. Bruce Fields <hidden>
Date: 2021-08-27 18:32:18

On Fri, Aug 27, 2021 at 08:10:38AM +1000, NeilBrown wrote:
On Fri, 27 Aug 2021, J.  Bruce Fields wrote:
quoted
On Thu, Aug 26, 2021 at 04:03:04PM +1000, NeilBrown wrote:
quoted
+	}
+	if (resp->dir_ino_uniquifier != ino)
+		ino ^= resp->dir_ino_uniquifier;
I guess this check (here and in nfsd_uniquify_ino) is just to prevent
returning inode number zero?
Yep.  The set of valid inode numbers is 1..MAX and that set isn't closed
under xor.
I was curious....

The NFS specs don't require FILEID to be nonzero as far as I can tell.

Our client doesn't treat fileid 0 specially.  In the case it has to
return a 32-bit inode it xors the high and low parts and makes no effort
I can see to check for the 0 case.

I modified a server to return 0 for FILEID and MOUNTED_ON_FILEID on one
particular file, and an strace shows that's happily passed on to
userspace:

	getdents64(3, [..., {d_ino=0, d_off=2048, d_reclen=32,
	d_type=DT_REG, d_name="LOCKTESTFILE"}]

But ls silently skips that file in the output.  Huh.

--b.
quoted hunk ↗ jump to hunk
It is closed (and bijective) under "xor if not equals".

I've added:
diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
index 5e2d5c352ecd..fed56edf229f 100644
--- a/fs/nfsd/nfs3xdr.c
+++ b/fs/nfsd/nfs3xdr.c
@@ -1162,6 +1162,7 @@ svcxdr_encode_entry3_common(struct nfsd3_readdirres *resp, const char *name,
 			resp->dir_ino_uniquifier = 0;
 		resp->dir_have_uniquifier = true;
 	}
+	/* See comment in nfsd_uniquify_ino() */
 	if (resp->dir_ino_uniquifier != ino)
 		ino ^= resp->dir_ino_uniquifier;
 	if (xdr_stream_encode_u64(xdr, ino) < 0)
diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h
index bbc7ddd34143..6dd8c7325902 100644
--- a/fs/nfsd/nfsfh.h
+++ b/fs/nfsd/nfsfh.h
@@ -155,6 +155,9 @@ static inline u64 nfsd_uniquify_ino(const struct svc_fh *fhp,
 				    const struct kstat *stat)
 {
 	u64 u = nfsd_ino_uniquifier(fhp, stat);
+	/* Neither stat->ino or return value can be zero, so
+	 * if ->ino is u, return u.
+	 */
 	if (u != stat->ino)
 		return stat->ino ^ u;
 	return stat->ino;
Thanks,
NeilBrown
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help