mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-04 01:49:36 +00:00
![David Howells](/assets/img/avatar_default.png)
Change the 9p filesystem to take account of the changes to fscache's indexing rewrite and reenable caching in 9p. The following changes have been made: (1) The fscache_netfs struct is no more, and there's no need to register the filesystem as a whole. (2) The session cookie is now an fscache_volume cookie, allocated with fscache_acquire_volume(). That takes three parameters: a string representing the "volume" in the index, a string naming the cache to use (or NULL) and a u64 that conveys coherency metadata for the volume. For 9p, I've made it render the volume name string as: "9p,<devname>,<cachetag>" where the cachetag is replaced by the aname if it wasn't supplied. This probably needs rethinking a bit as the aname can have slashes in it. It might be better to hash the cachetag and use the hash or I could substitute commas for the slashes or something. (3) The fscache_cookie_def is no more and needed information is passed directly to fscache_acquire_cookie(). The cache no longer calls back into the filesystem, but rather metadata changes are indicated at other times. fscache_acquire_cookie() is passed the same keying and coherency information as before. (4) The functions to set/reset/flush cookies are removed and fscache_use_cookie() and fscache_unuse_cookie() are used instead. fscache_use_cookie() is passed a flag to indicate if the cookie is opened for writing. fscache_unuse_cookie() is passed updates for the metadata if we changed it (ie. if the file was opened for writing). These are called when the file is opened or closed. (5) wait_on_page_bit[_killable]() is replaced with the specific wait functions for the bits waited upon. (6) I've got rid of some of the 9p-specific cache helper functions and called things like fscache_relinquish_cookie() directly as they'll optimise away if v9fs_inode_cookie() returns an unconditional NULL (which will be the case if CONFIG_9P_FSCACHE=n). (7) v9fs_vfs_setattr() is made to call fscache_resize() to change the size of the cache object. Notes: (A) We should call fscache_invalidate() if we detect that the server's copy of a file got changed by a third party, but I don't know where to do that. We don't need to do that when allocating the cookie as we get a check-and-invalidate when we initially bind to the cache object. (B) The copy-to-cache-on-writeback side of things will be handled in separate patch. Changes ======= ver #3: - Canonicalise the cookie key and coherency data to make them endianness-independent. ver #2: - Use gfpflags_allow_blocking() rather than using flag directly. - fscache_acquire_volume() now returns errors. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: Jeff Layton <jlayton@kernel.org> Tested-by: Dominique Martinet <asmadeus@codewreck.org> cc: Eric Van Hensbergen <ericvh@gmail.com> cc: Latchesar Ionkov <lucho@ionkov.net> cc: v9fs-developer@lists.sourceforge.net cc: linux-cachefs@redhat.com Link: https://lore.kernel.org/r/163819664645.215744.1555314582005286846.stgit@warthog.procyon.org.uk/ # v1 Link: https://lore.kernel.org/r/163906975017.143852.3459573173204394039.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/163967178512.1823006.17377493641569138183.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/164021573143.640689.3977487095697717967.stgit@warthog.procyon.org.uk/ # v4
76 lines
1.7 KiB
C
76 lines
1.7 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* V9FS cache definitions.
|
|
*
|
|
* Copyright (C) 2009 by Abhishek Kulkarni <adkulkar@umail.iu.edu>
|
|
*/
|
|
|
|
#include <linux/jiffies.h>
|
|
#include <linux/file.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/stat.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/fs.h>
|
|
#include <net/9p/9p.h>
|
|
|
|
#include "v9fs.h"
|
|
#include "cache.h"
|
|
|
|
int v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses,
|
|
const char *dev_name)
|
|
{
|
|
struct fscache_volume *vcookie;
|
|
char *name, *p;
|
|
|
|
name = kasprintf(GFP_KERNEL, "9p,%s,%s",
|
|
dev_name, v9ses->cachetag ?: v9ses->aname);
|
|
if (!name)
|
|
return -ENOMEM;
|
|
|
|
for (p = name; *p; p++)
|
|
if (*p == '/')
|
|
*p = ';';
|
|
|
|
vcookie = fscache_acquire_volume(name, NULL, NULL, 0);
|
|
p9_debug(P9_DEBUG_FSC, "session %p get volume %p (%s)\n",
|
|
v9ses, vcookie, name);
|
|
if (IS_ERR(vcookie)) {
|
|
if (vcookie != ERR_PTR(-EBUSY)) {
|
|
kfree(name);
|
|
return PTR_ERR(vcookie);
|
|
}
|
|
pr_err("Cache volume key already in use (%s)\n", name);
|
|
vcookie = NULL;
|
|
}
|
|
v9ses->fscache = vcookie;
|
|
kfree(name);
|
|
return 0;
|
|
}
|
|
|
|
void v9fs_cache_inode_get_cookie(struct inode *inode)
|
|
{
|
|
struct v9fs_inode *v9inode;
|
|
struct v9fs_session_info *v9ses;
|
|
__le32 version;
|
|
__le64 path;
|
|
|
|
if (!S_ISREG(inode->i_mode))
|
|
return;
|
|
|
|
v9inode = V9FS_I(inode);
|
|
if (WARN_ON(v9inode->fscache))
|
|
return;
|
|
|
|
version = cpu_to_le32(v9inode->qid.version);
|
|
path = cpu_to_le64(v9inode->qid.path);
|
|
v9ses = v9fs_inode2v9ses(inode);
|
|
v9inode->fscache =
|
|
fscache_acquire_cookie(v9fs_session_cache(v9ses),
|
|
0,
|
|
&path, sizeof(path),
|
|
&version, sizeof(version),
|
|
i_size_read(&v9inode->vfs_inode));
|
|
|
|
p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n",
|
|
inode, v9inode->fscache);
|
|
}
|