cifs: Fix duplicate fscache cookie warnings 6.9-rc1-smb3-client-fixes
authorDavid Howells <dhowells@redhat.com>
Wed, 27 Mar 2024 14:13:24 +0000 (14:13 +0000)
committerSteve French <stfrench@microsoft.com>
Wed, 27 Mar 2024 17:04:06 +0000 (12:04 -0500)
fscache emits a lot of duplicate cookie warnings with cifs because the
index key for the fscache cookies does not include everything that the
cifs_find_inode() function does.  The latter is used with iget5_locked() to
distinguish between inodes in the local inode cache.

Fix this by adding the creation time and file type to the fscache cookie
key.

Additionally, add a couple of comments to note that if one is changed the
other must be also.

Signed-off-by: David Howells <dhowells@redhat.com>
Fixes: 70431bfd825d ("cifs: Support fscache indexing rewrite")
cc: Shyam Prasad N <nspmangalore@gmail.com>
cc: Rohith Surabattula <rohiths.msft@gmail.com>
cc: Jeff Layton <jlayton@kernel.org>
cc: linux-cifs@vger.kernel.org
cc: netfs@lists.linux.dev
cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/fscache.c
fs/smb/client/inode.c

index c4a3cb736881ae73fe2e002fcb2f5cadbe6cd731..340efce8f052951a308329b70b5846d9e57477f5 100644 (file)
 #include "cifs_fs_sb.h"
 #include "cifsproto.h"
 
+/*
+ * Key for fscache inode.  [!] Contents must match comparisons in cifs_find_inode().
+ */
+struct cifs_fscache_inode_key {
+
+       __le64  uniqueid;       /* server inode number */
+       __le64  createtime;     /* creation time on server */
+       u8      type;           /* S_IFMT file type */
+} __packed;
+
 static void cifs_fscache_fill_volume_coherency(
        struct cifs_tcon *tcon,
        struct cifs_fscache_volume_coherency_data *cd)
@@ -97,15 +107,19 @@ void cifs_fscache_release_super_cookie(struct cifs_tcon *tcon)
 void cifs_fscache_get_inode_cookie(struct inode *inode)
 {
        struct cifs_fscache_inode_coherency_data cd;
+       struct cifs_fscache_inode_key key;
        struct cifsInodeInfo *cifsi = CIFS_I(inode);
        struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
        struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
 
+       key.uniqueid    = cpu_to_le64(cifsi->uniqueid);
+       key.createtime  = cpu_to_le64(cifsi->createtime);
+       key.type        = (inode->i_mode & S_IFMT) >> 12;
        cifs_fscache_fill_coherency(&cifsi->netfs.inode, &cd);
 
        cifsi->netfs.cache =
                fscache_acquire_cookie(tcon->fscache, 0,
-                                      &cifsi->uniqueid, sizeof(cifsi->uniqueid),
+                                      &key, sizeof(key),
                                       &cd, sizeof(cd),
                                       i_size_read(&cifsi->netfs.inode));
        if (cifsi->netfs.cache)
index d28ab0af60493623f3d209c4f36b5ccea14973bb..91b07ef9e25ca1c195bef21d06c92f5193633022 100644 (file)
@@ -1351,6 +1351,8 @@ cifs_find_inode(struct inode *inode, void *opaque)
 {
        struct cifs_fattr *fattr = opaque;
 
+       /* [!] The compared values must be the same in struct cifs_fscache_inode_key. */
+
        /* don't match inode with different uniqueid */
        if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid)
                return 0;