2019-05-28 19:57:16 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-09-23 22:00:27 +04:00
|
|
|
/*
|
|
|
|
* V9FS cache definitions.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 by Abhishek Kulkarni <adkulkar@umail.iu.edu>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/file.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2009-09-23 22:00:27 +04:00
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <net/9p/9p.h>
|
|
|
|
|
|
|
|
#include "v9fs.h"
|
|
|
|
#include "cache.h"
|
|
|
|
|
|
|
|
#define CACHETAG_LEN 11
|
|
|
|
|
|
|
|
struct fscache_netfs v9fs_cache_netfs = {
|
2021-11-02 16:16:43 +03:00
|
|
|
.name = "9p",
|
|
|
|
.version = 0,
|
2009-09-23 22:00:27 +04:00
|
|
|
};
|
|
|
|
|
2021-10-05 00:07:22 +03:00
|
|
|
/*
|
2009-09-23 22:00:27 +04:00
|
|
|
* v9fs_random_cachetag - Generate a random tag to be associated
|
|
|
|
* with a new cache session.
|
|
|
|
*
|
|
|
|
* The value of jiffies is used for a fairly randomly cache tag.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static
|
|
|
|
int v9fs_random_cachetag(struct v9fs_session_info *v9ses)
|
|
|
|
{
|
|
|
|
v9ses->cachetag = kmalloc(CACHETAG_LEN, GFP_KERNEL);
|
|
|
|
if (!v9ses->cachetag)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return scnprintf(v9ses->cachetag, CACHETAG_LEN, "%lu", jiffies);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct fscache_cookie_def v9fs_cache_session_index_def = {
|
2011-02-28 14:34:02 +03:00
|
|
|
.name = "9P.session",
|
|
|
|
.type = FSCACHE_COOKIE_TYPE_INDEX,
|
2009-09-23 22:00:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses)
|
|
|
|
{
|
|
|
|
/* If no cache session tag was specified, we generate a random one. */
|
2018-04-04 15:41:28 +03:00
|
|
|
if (!v9ses->cachetag) {
|
|
|
|
if (v9fs_random_cachetag(v9ses) < 0) {
|
|
|
|
v9ses->fscache = NULL;
|
2019-05-22 22:45:19 +03:00
|
|
|
kfree(v9ses->cachetag);
|
|
|
|
v9ses->cachetag = NULL;
|
2018-04-04 15:41:28 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-09-23 22:00:27 +04:00
|
|
|
|
|
|
|
v9ses->fscache = fscache_acquire_cookie(v9fs_cache_netfs.primary_index,
|
|
|
|
&v9fs_cache_session_index_def,
|
2018-04-04 15:41:28 +03:00
|
|
|
v9ses->cachetag,
|
|
|
|
strlen(v9ses->cachetag),
|
|
|
|
NULL, 0,
|
2018-04-04 15:41:28 +03:00
|
|
|
v9ses, 0, true);
|
2011-11-28 22:40:46 +04:00
|
|
|
p9_debug(P9_DEBUG_FSC, "session %p get cookie %p\n",
|
|
|
|
v9ses, v9ses->fscache);
|
2009-09-23 22:00:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses)
|
|
|
|
{
|
2011-11-28 22:40:46 +04:00
|
|
|
p9_debug(P9_DEBUG_FSC, "session %p put cookie %p\n",
|
|
|
|
v9ses, v9ses->fscache);
|
2018-04-04 15:41:28 +03:00
|
|
|
fscache_relinquish_cookie(v9ses->fscache, NULL, false);
|
2009-09-23 22:00:27 +04:00
|
|
|
v9ses->fscache = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum
|
|
|
|
fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
|
|
|
|
const void *buffer,
|
2018-04-04 15:41:28 +03:00
|
|
|
uint16_t buflen,
|
|
|
|
loff_t object_size)
|
2009-09-23 22:00:27 +04:00
|
|
|
{
|
2011-02-28 14:34:02 +03:00
|
|
|
const struct v9fs_inode *v9inode = cookie_netfs_data;
|
2009-09-23 22:00:27 +04:00
|
|
|
|
2011-07-11 20:40:59 +04:00
|
|
|
if (buflen != sizeof(v9inode->qid.version))
|
2009-09-23 22:00:27 +04:00
|
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
|
|
|
|
2011-07-11 20:40:59 +04:00
|
|
|
if (memcmp(buffer, &v9inode->qid.version,
|
|
|
|
sizeof(v9inode->qid.version)))
|
2009-09-23 22:00:27 +04:00
|
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
|
|
|
|
|
|
|
return FSCACHE_CHECKAUX_OKAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct fscache_cookie_def v9fs_cache_inode_index_def = {
|
|
|
|
.name = "9p.inode",
|
|
|
|
.type = FSCACHE_COOKIE_TYPE_DATAFILE,
|
|
|
|
.check_aux = v9fs_cache_inode_check_aux,
|
|
|
|
};
|
|
|
|
|
|
|
|
void v9fs_cache_inode_get_cookie(struct inode *inode)
|
|
|
|
{
|
2011-02-28 14:34:02 +03:00
|
|
|
struct v9fs_inode *v9inode;
|
2009-09-23 22:00:27 +04:00
|
|
|
struct v9fs_session_info *v9ses;
|
|
|
|
|
|
|
|
if (!S_ISREG(inode->i_mode))
|
|
|
|
return;
|
|
|
|
|
2011-02-28 14:34:02 +03:00
|
|
|
v9inode = V9FS_I(inode);
|
|
|
|
if (v9inode->fscache)
|
2009-09-23 22:00:27 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
v9ses = v9fs_inode2v9ses(inode);
|
2011-02-28 14:34:02 +03:00
|
|
|
v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
|
2009-09-23 22:00:27 +04:00
|
|
|
&v9fs_cache_inode_index_def,
|
2018-04-04 15:41:28 +03:00
|
|
|
&v9inode->qid.path,
|
|
|
|
sizeof(v9inode->qid.path),
|
|
|
|
&v9inode->qid.version,
|
|
|
|
sizeof(v9inode->qid.version),
|
2018-04-04 15:41:28 +03:00
|
|
|
v9inode,
|
|
|
|
i_size_read(&v9inode->vfs_inode),
|
|
|
|
true);
|
2009-09-23 22:00:27 +04:00
|
|
|
|
2011-11-28 22:40:46 +04:00
|
|
|
p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n",
|
|
|
|
inode, v9inode->fscache);
|
2009-09-23 22:00:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void v9fs_cache_inode_put_cookie(struct inode *inode)
|
|
|
|
{
|
2011-02-28 14:34:02 +03:00
|
|
|
struct v9fs_inode *v9inode = V9FS_I(inode);
|
2009-09-23 22:00:27 +04:00
|
|
|
|
2011-02-28 14:34:02 +03:00
|
|
|
if (!v9inode->fscache)
|
2009-09-23 22:00:27 +04:00
|
|
|
return;
|
2011-11-28 22:40:46 +04:00
|
|
|
p9_debug(P9_DEBUG_FSC, "inode %p put cookie %p\n",
|
|
|
|
inode, v9inode->fscache);
|
2009-09-23 22:00:27 +04:00
|
|
|
|
2018-04-04 15:41:28 +03:00
|
|
|
fscache_relinquish_cookie(v9inode->fscache, &v9inode->qid.version,
|
|
|
|
false);
|
2011-02-28 14:34:02 +03:00
|
|
|
v9inode->fscache = NULL;
|
2009-09-23 22:00:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void v9fs_cache_inode_flush_cookie(struct inode *inode)
|
|
|
|
{
|
2011-02-28 14:34:02 +03:00
|
|
|
struct v9fs_inode *v9inode = V9FS_I(inode);
|
2009-09-23 22:00:27 +04:00
|
|
|
|
2011-02-28 14:34:02 +03:00
|
|
|
if (!v9inode->fscache)
|
2009-09-23 22:00:27 +04:00
|
|
|
return;
|
2011-11-28 22:40:46 +04:00
|
|
|
p9_debug(P9_DEBUG_FSC, "inode %p flush cookie %p\n",
|
|
|
|
inode, v9inode->fscache);
|
2009-09-23 22:00:27 +04:00
|
|
|
|
2018-04-04 15:41:28 +03:00
|
|
|
fscache_relinquish_cookie(v9inode->fscache, NULL, true);
|
2011-02-28 14:34:02 +03:00
|
|
|
v9inode->fscache = NULL;
|
2009-09-23 22:00:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp)
|
|
|
|
{
|
2011-02-28 14:34:02 +03:00
|
|
|
struct v9fs_inode *v9inode = V9FS_I(inode);
|
2009-09-23 22:00:27 +04:00
|
|
|
|
2011-02-28 14:34:02 +03:00
|
|
|
if (!v9inode->fscache)
|
2009-09-23 22:00:27 +04:00
|
|
|
return;
|
|
|
|
|
2016-01-08 01:49:51 +03:00
|
|
|
mutex_lock(&v9inode->fscache_lock);
|
2013-09-29 03:32:13 +04:00
|
|
|
|
2009-09-23 22:00:27 +04:00
|
|
|
if ((filp->f_flags & O_ACCMODE) != O_RDONLY)
|
|
|
|
v9fs_cache_inode_flush_cookie(inode);
|
|
|
|
else
|
|
|
|
v9fs_cache_inode_get_cookie(inode);
|
|
|
|
|
2016-01-08 01:49:51 +03:00
|
|
|
mutex_unlock(&v9inode->fscache_lock);
|
2009-09-23 22:00:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void v9fs_cache_inode_reset_cookie(struct inode *inode)
|
|
|
|
{
|
2011-02-28 14:34:02 +03:00
|
|
|
struct v9fs_inode *v9inode = V9FS_I(inode);
|
2009-09-23 22:00:27 +04:00
|
|
|
struct v9fs_session_info *v9ses;
|
|
|
|
struct fscache_cookie *old;
|
|
|
|
|
2011-02-28 14:34:02 +03:00
|
|
|
if (!v9inode->fscache)
|
2009-09-23 22:00:27 +04:00
|
|
|
return;
|
|
|
|
|
2011-02-28 14:34:02 +03:00
|
|
|
old = v9inode->fscache;
|
2009-09-23 22:00:27 +04:00
|
|
|
|
2016-01-08 01:49:51 +03:00
|
|
|
mutex_lock(&v9inode->fscache_lock);
|
2018-04-04 15:41:28 +03:00
|
|
|
fscache_relinquish_cookie(v9inode->fscache, NULL, true);
|
2009-09-23 22:00:27 +04:00
|
|
|
|
|
|
|
v9ses = v9fs_inode2v9ses(inode);
|
2011-02-28 14:34:02 +03:00
|
|
|
v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
|
2009-09-23 22:00:27 +04:00
|
|
|
&v9fs_cache_inode_index_def,
|
2018-04-04 15:41:28 +03:00
|
|
|
&v9inode->qid.path,
|
|
|
|
sizeof(v9inode->qid.path),
|
|
|
|
&v9inode->qid.version,
|
|
|
|
sizeof(v9inode->qid.version),
|
2018-04-04 15:41:28 +03:00
|
|
|
v9inode,
|
|
|
|
i_size_read(&v9inode->vfs_inode),
|
|
|
|
true);
|
2011-11-28 22:40:46 +04:00
|
|
|
p9_debug(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p\n",
|
|
|
|
inode, old, v9inode->fscache);
|
2009-09-23 22:00:27 +04:00
|
|
|
|
2016-01-08 01:49:51 +03:00
|
|
|
mutex_unlock(&v9inode->fscache_lock);
|
2009-09-23 22:00:27 +04:00
|
|
|
}
|