Skip to content

Commit 2b666a1

Browse files
author
Trond Myklebust
committed
Merge tag 'fscache-fixes-20200508-2' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs
(1) The reorganisation of bmap() use accidentally caused the return value of cachefiles_read_or_alloc_pages() to get corrupted. (2) The NFS superblock index key accidentally got changed to include a number of kernel pointers - meaning that the key isn't matchable after a reboot. (3) A redundant check in nfs_fscache_get_super_cookie(). (4) The NFS change_attr sometimes set in the auxiliary data for the caching of an file and sometimes not, which causes the cache to get discarded when it shouldn't. (5) There's a race between cachefiles_read_waiter() and cachefiles_read_copier() that causes an occasional assertion failure.
2 parents ce99aa6 + 7bb0c53 commit 2b666a1

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

fs/cachefiles/rdwr.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ static int cachefiles_read_waiter(wait_queue_entry_t *wait, unsigned mode,
6060
object = container_of(op->op.object, struct cachefiles_object, fscache);
6161
spin_lock(&object->work_lock);
6262
list_add_tail(&monitor->op_link, &op->to_do);
63+
fscache_enqueue_retrieval(op);
6364
spin_unlock(&object->work_lock);
6465

65-
fscache_enqueue_retrieval(op);
6666
fscache_put_retrieval(op);
6767
return 0;
6868
}
@@ -398,7 +398,7 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op,
398398
struct inode *inode;
399399
sector_t block;
400400
unsigned shift;
401-
int ret;
401+
int ret, ret2;
402402

403403
object = container_of(op->op.object,
404404
struct cachefiles_object, fscache);
@@ -430,8 +430,8 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op,
430430
block = page->index;
431431
block <<= shift;
432432

433-
ret = bmap(inode, &block);
434-
ASSERT(ret < 0);
433+
ret2 = bmap(inode, &block);
434+
ASSERT(ret2 == 0);
435435

436436
_debug("%llx -> %llx",
437437
(unsigned long long) (page->index << shift),
@@ -739,8 +739,8 @@ int cachefiles_read_or_alloc_pages(struct fscache_retrieval *op,
739739
block = page->index;
740740
block <<= shift;
741741

742-
ret = bmap(inode, &block);
743-
ASSERT(!ret);
742+
ret2 = bmap(inode, &block);
743+
ASSERT(ret2 == 0);
744744

745745
_debug("%llx -> %llx",
746746
(unsigned long long) (page->index << shift),

fs/nfs/fscache.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ void nfs_fscache_get_super_cookie(struct super_block *sb, const char *uniq, int
118118

119119
nfss->fscache_key = NULL;
120120
nfss->fscache = NULL;
121-
if (!(nfss->options & NFS_OPTION_FSCACHE))
122-
return;
123121
if (!uniq) {
124122
uniq = "";
125123
ulen = 1;
@@ -188,7 +186,8 @@ void nfs_fscache_get_super_cookie(struct super_block *sb, const char *uniq, int
188186
/* create a cache index for looking up filehandles */
189187
nfss->fscache = fscache_acquire_cookie(nfss->nfs_client->fscache,
190188
&nfs_fscache_super_index_def,
191-
key, sizeof(*key) + ulen,
189+
&key->key,
190+
sizeof(key->key) + ulen,
192191
NULL, 0,
193192
nfss, 0, true);
194193
dfprintk(FSCACHE, "NFS: get superblock cookie (0x%p/0x%p)\n",
@@ -226,6 +225,19 @@ void nfs_fscache_release_super_cookie(struct super_block *sb)
226225
}
227226
}
228227

228+
static void nfs_fscache_update_auxdata(struct nfs_fscache_inode_auxdata *auxdata,
229+
struct nfs_inode *nfsi)
230+
{
231+
memset(auxdata, 0, sizeof(*auxdata));
232+
auxdata->mtime_sec = nfsi->vfs_inode.i_mtime.tv_sec;
233+
auxdata->mtime_nsec = nfsi->vfs_inode.i_mtime.tv_nsec;
234+
auxdata->ctime_sec = nfsi->vfs_inode.i_ctime.tv_sec;
235+
auxdata->ctime_nsec = nfsi->vfs_inode.i_ctime.tv_nsec;
236+
237+
if (NFS_SERVER(&nfsi->vfs_inode)->nfs_client->rpc_ops->version == 4)
238+
auxdata->change_attr = inode_peek_iversion_raw(&nfsi->vfs_inode);
239+
}
240+
229241
/*
230242
* Initialise the per-inode cache cookie pointer for an NFS inode.
231243
*/
@@ -239,14 +251,7 @@ void nfs_fscache_init_inode(struct inode *inode)
239251
if (!(nfss->fscache && S_ISREG(inode->i_mode)))
240252
return;
241253

242-
memset(&auxdata, 0, sizeof(auxdata));
243-
auxdata.mtime_sec = nfsi->vfs_inode.i_mtime.tv_sec;
244-
auxdata.mtime_nsec = nfsi->vfs_inode.i_mtime.tv_nsec;
245-
auxdata.ctime_sec = nfsi->vfs_inode.i_ctime.tv_sec;
246-
auxdata.ctime_nsec = nfsi->vfs_inode.i_ctime.tv_nsec;
247-
248-
if (NFS_SERVER(&nfsi->vfs_inode)->nfs_client->rpc_ops->version == 4)
249-
auxdata.change_attr = inode_peek_iversion_raw(&nfsi->vfs_inode);
254+
nfs_fscache_update_auxdata(&auxdata, nfsi);
250255

251256
nfsi->fscache = fscache_acquire_cookie(NFS_SB(inode->i_sb)->fscache,
252257
&nfs_fscache_inode_object_def,
@@ -266,11 +271,7 @@ void nfs_fscache_clear_inode(struct inode *inode)
266271

267272
dfprintk(FSCACHE, "NFS: clear cookie (0x%p/0x%p)\n", nfsi, cookie);
268273

269-
memset(&auxdata, 0, sizeof(auxdata));
270-
auxdata.mtime_sec = nfsi->vfs_inode.i_mtime.tv_sec;
271-
auxdata.mtime_nsec = nfsi->vfs_inode.i_mtime.tv_nsec;
272-
auxdata.ctime_sec = nfsi->vfs_inode.i_ctime.tv_sec;
273-
auxdata.ctime_nsec = nfsi->vfs_inode.i_ctime.tv_nsec;
274+
nfs_fscache_update_auxdata(&auxdata, nfsi);
274275
fscache_relinquish_cookie(cookie, &auxdata, false);
275276
nfsi->fscache = NULL;
276277
}
@@ -310,11 +311,7 @@ void nfs_fscache_open_file(struct inode *inode, struct file *filp)
310311
if (!fscache_cookie_valid(cookie))
311312
return;
312313

313-
memset(&auxdata, 0, sizeof(auxdata));
314-
auxdata.mtime_sec = nfsi->vfs_inode.i_mtime.tv_sec;
315-
auxdata.mtime_nsec = nfsi->vfs_inode.i_mtime.tv_nsec;
316-
auxdata.ctime_sec = nfsi->vfs_inode.i_ctime.tv_sec;
317-
auxdata.ctime_nsec = nfsi->vfs_inode.i_ctime.tv_nsec;
314+
nfs_fscache_update_auxdata(&auxdata, nfsi);
318315

319316
if (inode_is_open_for_write(inode)) {
320317
dfprintk(FSCACHE, "NFS: nfsi 0x%p disabling cache\n", nfsi);

fs/nfs/super.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,6 @@ static void nfs_get_cache_cookie(struct super_block *sb,
11891189
uniq = ctx->fscache_uniq;
11901190
ulen = strlen(ctx->fscache_uniq);
11911191
}
1192-
return;
11931192
}
11941193

11951194
nfs_fscache_get_super_cookie(sb, uniq, ulen);

0 commit comments

Comments
 (0)