smb3: extend fscache mount volume coherency check
authorSteve French <stfrench@microsoft.com>
Fri, 5 Jun 2020 22:19:46 +0000 (17:19 -0500)
committerSteve French <stfrench@microsoft.com>
Sat, 6 Jun 2020 16:16:25 +0000 (11:16 -0500)
It is better to check volume id and creation time, not just
the root inode number to verify if the volume has changed
when remounting.

Reviewed-by: David Howells <dhowells@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/cifs/cache.c
fs/cifs/fscache.c
fs/cifs/fscache.h

index b7420e605b28804be516a5cd9c2ab250bffc5ea0..0f2adecb94f22473c0e9af3952f5716fd5ef5624 100644 (file)
@@ -53,13 +53,6 @@ const struct fscache_cookie_def cifs_fscache_server_index_def = {
        .type = FSCACHE_COOKIE_TYPE_INDEX,
 };
 
-/*
- * Auxiliary data attached to CIFS superblock within the cache
- */
-struct cifs_fscache_super_auxdata {
-       u64     resource_id;            /* unique server resource id */
-};
-
 char *extract_sharename(const char *treename)
 {
        const char *src;
@@ -98,6 +91,8 @@ fscache_checkaux cifs_fscache_super_check_aux(void *cookie_netfs_data,
 
        memset(&auxdata, 0, sizeof(auxdata));
        auxdata.resource_id = tcon->resource_id;
+       auxdata.vol_create_time = tcon->vol_create_time;
+       auxdata.vol_serial_number = tcon->vol_serial_number;
 
        if (memcmp(data, &auxdata, datalen) != 0)
                return FSCACHE_CHECKAUX_OBSOLETE;
index ea6ace9c2417dd954047799e691a7759cd2c5471..da688185403c3ee2550590e37c7bc6ff82d50f99 100644 (file)
@@ -96,6 +96,7 @@ void cifs_fscache_get_super_cookie(struct cifs_tcon *tcon)
 {
        struct TCP_Server_Info *server = tcon->ses->server;
        char *sharename;
+       struct cifs_fscache_super_auxdata auxdata;
 
        sharename = extract_sharename(tcon->treeName);
        if (IS_ERR(sharename)) {
@@ -104,11 +105,16 @@ void cifs_fscache_get_super_cookie(struct cifs_tcon *tcon)
                return;
        }
 
+       memset(&auxdata, 0, sizeof(auxdata));
+       auxdata.resource_id = tcon->resource_id;
+       auxdata.vol_create_time = tcon->vol_create_time;
+       auxdata.vol_serial_number = tcon->vol_serial_number;
+
        tcon->fscache =
                fscache_acquire_cookie(server->fscache,
                                       &cifs_fscache_super_index_def,
                                       sharename, strlen(sharename),
-                                      &tcon->resource_id, sizeof(tcon->resource_id),
+                                      &auxdata, sizeof(auxdata),
                                       tcon, 0, true);
        kfree(sharename);
        cifs_dbg(FYI, "%s: (0x%p/0x%p)\n",
@@ -117,8 +123,15 @@ void cifs_fscache_get_super_cookie(struct cifs_tcon *tcon)
 
 void cifs_fscache_release_super_cookie(struct cifs_tcon *tcon)
 {
+       struct cifs_fscache_super_auxdata auxdata;
+
+       memset(&auxdata, 0, sizeof(auxdata));
+       auxdata.resource_id = tcon->resource_id;
+       auxdata.vol_create_time = tcon->vol_create_time;
+       auxdata.vol_serial_number = tcon->vol_serial_number;
+
        cifs_dbg(FYI, "%s: (0x%p)\n", __func__, tcon->fscache);
-       fscache_relinquish_cookie(tcon->fscache, &tcon->resource_id, false);
+       fscache_relinquish_cookie(tcon->fscache, &auxdata, false);
        tcon->fscache = NULL;
 }
 
index 8c0862e413064c32a6df043e8d27f0d8530b2849..1091633d2adbd2aed356c653d052e96d4b4268ef 100644 (file)
 
 #ifdef CONFIG_CIFS_FSCACHE
 
+/*
+ * Auxiliary data attached to CIFS superblock within the cache
+ */
+struct cifs_fscache_super_auxdata {
+       u64     resource_id;            /* unique server resource id */
+       __le64  vol_create_time;
+       u32     vol_serial_number;
+} __packed;
+
 /*
  * Auxiliary data attached to CIFS inode within the cache
  */