aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2018-04-04 08:41:25 -0400
committerDavid Howells <dhowells@redhat.com>2018-04-04 08:41:25 -0400
commit27a3ee3a0471abaacf0c2ab1397b188c7b693fcd (patch)
treeee791b6c562b287637539c8c2968b3dbbdd5ce55
parentc1515999bdf9a91a4b7c82623a068ffe770a17b9 (diff)
afs: Use the vnode ID uniquifier in the cache key not the aux data
AFS vnodes (files) are referenced by a triplet of { volume ID, vnode ID, uniquifier }. Currently, kafs is only using the vnode ID as the file key in the volume fscache index and checking the uniquifier on cookie acquisition against the contents of the auxiliary data stored in the cache. Unfortunately, this is subject to a race in which an FS.RemoveFile or FS.RemoveDir op is issued against the server but the local afs inode isn't torn down and disposed off before another thread issues something like FS.CreateFile. The latter then gets given the vnode ID that just got removed, but with a new uniquifier and a cookie collision occurs in the cache because the cookie is only keyed on the vnode ID whereas the inode is keyed on the vnode ID plus the uniquifier. Fix this by keying the cookie on the uniquifier in addition to the vnode ID and dropping the uniquifier from the auxiliary data supplied. Signed-off-by: David Howells <dhowells@redhat.com>
-rw-r--r--fs/afs/cache.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/fs/afs/cache.c b/fs/afs/cache.c
index f62ff71d28c9..cd857db9b112 100644
--- a/fs/afs/cache.c
+++ b/fs/afs/cache.c
@@ -29,7 +29,7 @@ static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
29 29
30struct fscache_netfs afs_cache_netfs = { 30struct fscache_netfs afs_cache_netfs = {
31 .name = "afs", 31 .name = "afs",
32 .version = 1, 32 .version = 2,
33}; 33};
34 34
35struct fscache_cookie_def afs_cell_cache_index_def = { 35struct fscache_cookie_def afs_cell_cache_index_def = {
@@ -103,7 +103,9 @@ static uint16_t afs_vnode_cache_get_key(const void *cookie_netfs_data,
103{ 103{
104 const struct afs_vnode *vnode = cookie_netfs_data; 104 const struct afs_vnode *vnode = cookie_netfs_data;
105 struct { 105 struct {
106 u32 vnode_id[3]; 106 u32 vnode_id;
107 u32 unique;
108 u32 vnode_id_ext[2]; /* Allow for a 96-bit key */
107 } __packed key; 109 } __packed key;
108 110
109 _enter("{%x,%x,%llx},%p,%u", 111 _enter("{%x,%x,%llx},%p,%u",
@@ -112,9 +114,10 @@ static uint16_t afs_vnode_cache_get_key(const void *cookie_netfs_data,
112 114
113 /* Allow for a 96-bit key */ 115 /* Allow for a 96-bit key */
114 memset(&key, 0, sizeof(key)); 116 memset(&key, 0, sizeof(key));
115 key.vnode_id[0] = vnode->fid.vnode; 117 key.vnode_id = vnode->fid.vnode;
116 key.vnode_id[1] = 0; 118 key.unique = vnode->fid.unique;
117 key.vnode_id[2] = 0; 119 key.vnode_id_ext[0] = 0;
120 key.vnode_id_ext[1] = 0;
118 121
119 if (sizeof(key) > bufmax) 122 if (sizeof(key) > bufmax)
120 return 0; 123 return 0;
@@ -140,7 +143,6 @@ static void afs_vnode_cache_get_attr(const void *cookie_netfs_data,
140 143
141struct afs_vnode_cache_aux { 144struct afs_vnode_cache_aux {
142 u64 data_version; 145 u64 data_version;
143 u32 fid_unique;
144} __packed; 146} __packed;
145 147
146/* 148/*
@@ -156,9 +158,7 @@ static uint16_t afs_vnode_cache_get_aux(const void *cookie_netfs_data,
156 vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version, 158 vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
157 buffer, bufmax); 159 buffer, bufmax);
158 160
159 memset(&aux, 0, sizeof(aux));
160 aux.data_version = vnode->status.data_version; 161 aux.data_version = vnode->status.data_version;
161 aux.fid_unique = vnode->fid.unique;
162 162
163 if (bufmax < sizeof(aux)) 163 if (bufmax < sizeof(aux))
164 return 0; 164 return 0;
@@ -189,12 +189,6 @@ static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
189 return FSCACHE_CHECKAUX_OBSOLETE; 189 return FSCACHE_CHECKAUX_OBSOLETE;
190 } 190 }
191 191
192 if (vnode->fid.unique != aux.fid_unique) {
193 _leave(" = OBSOLETE [uniq %x != %x]",
194 aux.fid_unique, vnode->fid.unique);
195 return FSCACHE_CHECKAUX_OBSOLETE;
196 }
197
198 if (vnode->status.data_version != aux.data_version) { 192 if (vnode->status.data_version != aux.data_version) {
199 _leave(" = OBSOLETE [vers %llx != %llx]", 193 _leave(" = OBSOLETE [vers %llx != %llx]",
200 aux.data_version, vnode->status.data_version); 194 aux.data_version, vnode->status.data_version);