2019-05-21 01:08:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-04-03 23:42:42 +08:00
|
|
|
/* NFS filesystem cache interface
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
|
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/nfs_fs.h>
|
|
|
|
#include <linux/nfs_fs_sb.h>
|
|
|
|
#include <linux/in6.h>
|
|
|
|
#include <linux/seq_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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2018-04-04 20:41:28 +08:00
|
|
|
#include <linux/iversion.h>
|
2009-04-03 23:42:42 +08:00
|
|
|
|
|
|
|
#include "internal.h"
|
2009-04-03 23:42:44 +08:00
|
|
|
#include "iostat.h"
|
2009-04-03 23:42:42 +08:00
|
|
|
#include "fscache.h"
|
|
|
|
|
|
|
|
#define NFSDBG_FACILITY NFSDBG_FSCACHE
|
|
|
|
|
2009-04-03 23:42:42 +08:00
|
|
|
static struct rb_root nfs_fscache_keys = RB_ROOT;
|
|
|
|
static DEFINE_SPINLOCK(nfs_fscache_keys_lock);
|
|
|
|
|
2018-04-04 20:41:28 +08:00
|
|
|
/*
|
|
|
|
* Layout of the key for an NFS server cache object.
|
|
|
|
*/
|
|
|
|
struct nfs_server_key {
|
|
|
|
struct {
|
|
|
|
uint16_t nfsversion; /* NFS protocol version */
|
|
|
|
uint16_t family; /* address family */
|
|
|
|
__be16 port; /* IP port */
|
|
|
|
} hdr;
|
|
|
|
union {
|
|
|
|
struct in_addr ipv4_addr; /* IPv4 address */
|
|
|
|
struct in6_addr ipv6_addr; /* IPv6 address */
|
|
|
|
};
|
|
|
|
} __packed;
|
|
|
|
|
2009-04-03 23:42:42 +08:00
|
|
|
/*
|
|
|
|
* Get the per-client index cookie for an NFS client if the appropriate mount
|
|
|
|
* flag was set
|
|
|
|
* - We always try and get an index cookie for the client, but get filehandle
|
|
|
|
* cookies on a per-superblock basis, depending on the mount flags
|
|
|
|
*/
|
|
|
|
void nfs_fscache_get_client_cookie(struct nfs_client *clp)
|
|
|
|
{
|
2018-04-04 20:41:28 +08:00
|
|
|
const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &clp->cl_addr;
|
|
|
|
const struct sockaddr_in *sin = (struct sockaddr_in *) &clp->cl_addr;
|
|
|
|
struct nfs_server_key key;
|
|
|
|
uint16_t len = sizeof(key.hdr);
|
|
|
|
|
|
|
|
memset(&key, 0, sizeof(key));
|
|
|
|
key.hdr.nfsversion = clp->rpc_ops->version;
|
|
|
|
key.hdr.family = clp->cl_addr.ss_family;
|
|
|
|
|
|
|
|
switch (clp->cl_addr.ss_family) {
|
|
|
|
case AF_INET:
|
|
|
|
key.hdr.port = sin->sin_port;
|
|
|
|
key.ipv4_addr = sin->sin_addr;
|
|
|
|
len += sizeof(key.ipv4_addr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_INET6:
|
|
|
|
key.hdr.port = sin6->sin6_port;
|
|
|
|
key.ipv6_addr = sin6->sin6_addr;
|
|
|
|
len += sizeof(key.ipv6_addr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printk(KERN_WARNING "NFS: Unknown network family '%d'\n",
|
|
|
|
clp->cl_addr.ss_family);
|
|
|
|
clp->fscache = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-03 23:42:42 +08:00
|
|
|
/* create a cache index for looking up filehandles */
|
|
|
|
clp->fscache = fscache_acquire_cookie(nfs_fscache_netfs.primary_index,
|
|
|
|
&nfs_fscache_server_index_def,
|
2018-04-04 20:41:28 +08:00
|
|
|
&key, len,
|
|
|
|
NULL, 0,
|
2018-04-04 20:41:28 +08:00
|
|
|
clp, 0, true);
|
2009-04-03 23:42:42 +08:00
|
|
|
dfprintk(FSCACHE, "NFS: get client cookie (0x%p/0x%p)\n",
|
|
|
|
clp, clp->fscache);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dispose of a per-client cookie
|
|
|
|
*/
|
|
|
|
void nfs_fscache_release_client_cookie(struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
dfprintk(FSCACHE, "NFS: releasing client cookie (0x%p/0x%p)\n",
|
|
|
|
clp, clp->fscache);
|
|
|
|
|
2018-04-04 20:41:28 +08:00
|
|
|
fscache_relinquish_cookie(clp->fscache, NULL, false);
|
2009-04-03 23:42:42 +08:00
|
|
|
clp->fscache = NULL;
|
|
|
|
}
|
2009-04-03 23:42:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the cache cookie for an NFS superblock. We have to handle
|
|
|
|
* uniquification here because the cache doesn't do it for us.
|
2009-09-24 02:36:39 +08:00
|
|
|
*
|
|
|
|
* The default uniquifier is just an empty string, but it may be overridden
|
|
|
|
* either by the 'fsc=xxx' option to mount, or by inheriting it from the parent
|
|
|
|
* superblock across an automount point of some nature.
|
2009-04-03 23:42:42 +08:00
|
|
|
*/
|
2012-05-11 03:07:32 +08:00
|
|
|
void nfs_fscache_get_super_cookie(struct super_block *sb, const char *uniq, int ulen)
|
2009-04-03 23:42:42 +08:00
|
|
|
{
|
|
|
|
struct nfs_fscache_key *key, *xkey;
|
|
|
|
struct nfs_server *nfss = NFS_SB(sb);
|
|
|
|
struct rb_node **p, *parent;
|
2012-05-11 03:07:32 +08:00
|
|
|
int diff;
|
2009-09-24 02:36:39 +08:00
|
|
|
|
2019-08-04 01:39:24 +08:00
|
|
|
nfss->fscache_key = NULL;
|
|
|
|
nfss->fscache = NULL;
|
|
|
|
if (!(nfss->options & NFS_OPTION_FSCACHE))
|
|
|
|
return;
|
2009-09-24 02:36:39 +08:00
|
|
|
if (!uniq) {
|
|
|
|
uniq = "";
|
|
|
|
ulen = 1;
|
|
|
|
}
|
|
|
|
|
2009-04-03 23:42:42 +08:00
|
|
|
key = kzalloc(sizeof(*key) + ulen, GFP_KERNEL);
|
|
|
|
if (!key)
|
|
|
|
return;
|
|
|
|
|
|
|
|
key->nfs_client = nfss->nfs_client;
|
|
|
|
key->key.super.s_flags = sb->s_flags & NFS_MS_MASK;
|
|
|
|
key->key.nfs_server.flags = nfss->flags;
|
|
|
|
key->key.nfs_server.rsize = nfss->rsize;
|
|
|
|
key->key.nfs_server.wsize = nfss->wsize;
|
|
|
|
key->key.nfs_server.acregmin = nfss->acregmin;
|
|
|
|
key->key.nfs_server.acregmax = nfss->acregmax;
|
|
|
|
key->key.nfs_server.acdirmin = nfss->acdirmin;
|
|
|
|
key->key.nfs_server.acdirmax = nfss->acdirmax;
|
|
|
|
key->key.nfs_server.fsid = nfss->fsid;
|
|
|
|
key->key.rpc_auth.au_flavor = nfss->client->cl_auth->au_flavor;
|
|
|
|
|
|
|
|
key->key.uniq_len = ulen;
|
|
|
|
memcpy(key->key.uniquifier, uniq, ulen);
|
|
|
|
|
|
|
|
spin_lock(&nfs_fscache_keys_lock);
|
|
|
|
p = &nfs_fscache_keys.rb_node;
|
|
|
|
parent = NULL;
|
|
|
|
while (*p) {
|
|
|
|
parent = *p;
|
|
|
|
xkey = rb_entry(parent, struct nfs_fscache_key, node);
|
|
|
|
|
|
|
|
if (key->nfs_client < xkey->nfs_client)
|
|
|
|
goto go_left;
|
|
|
|
if (key->nfs_client > xkey->nfs_client)
|
|
|
|
goto go_right;
|
|
|
|
|
|
|
|
diff = memcmp(&key->key, &xkey->key, sizeof(key->key));
|
|
|
|
if (diff < 0)
|
|
|
|
goto go_left;
|
|
|
|
if (diff > 0)
|
|
|
|
goto go_right;
|
|
|
|
|
|
|
|
if (key->key.uniq_len == 0)
|
|
|
|
goto non_unique;
|
|
|
|
diff = memcmp(key->key.uniquifier,
|
|
|
|
xkey->key.uniquifier,
|
|
|
|
key->key.uniq_len);
|
|
|
|
if (diff < 0)
|
|
|
|
goto go_left;
|
|
|
|
if (diff > 0)
|
|
|
|
goto go_right;
|
|
|
|
goto non_unique;
|
|
|
|
|
|
|
|
go_left:
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
continue;
|
|
|
|
go_right:
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_link_node(&key->node, parent, p);
|
|
|
|
rb_insert_color(&key->node, &nfs_fscache_keys);
|
|
|
|
spin_unlock(&nfs_fscache_keys_lock);
|
|
|
|
nfss->fscache_key = key;
|
|
|
|
|
|
|
|
/* create a cache index for looking up filehandles */
|
|
|
|
nfss->fscache = fscache_acquire_cookie(nfss->nfs_client->fscache,
|
|
|
|
&nfs_fscache_super_index_def,
|
2018-04-04 20:41:28 +08:00
|
|
|
key, sizeof(*key) + ulen,
|
|
|
|
NULL, 0,
|
2018-04-04 20:41:28 +08:00
|
|
|
nfss, 0, true);
|
2009-04-03 23:42:42 +08:00
|
|
|
dfprintk(FSCACHE, "NFS: get superblock cookie (0x%p/0x%p)\n",
|
|
|
|
nfss, nfss->fscache);
|
|
|
|
return;
|
|
|
|
|
|
|
|
non_unique:
|
|
|
|
spin_unlock(&nfs_fscache_keys_lock);
|
|
|
|
kfree(key);
|
|
|
|
nfss->fscache_key = NULL;
|
|
|
|
nfss->fscache = NULL;
|
|
|
|
printk(KERN_WARNING "NFS:"
|
|
|
|
" Cache request denied due to non-unique superblock keys\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* release a per-superblock cookie
|
|
|
|
*/
|
|
|
|
void nfs_fscache_release_super_cookie(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct nfs_server *nfss = NFS_SB(sb);
|
|
|
|
|
|
|
|
dfprintk(FSCACHE, "NFS: releasing superblock cookie (0x%p/0x%p)\n",
|
|
|
|
nfss, nfss->fscache);
|
|
|
|
|
2018-04-04 20:41:28 +08:00
|
|
|
fscache_relinquish_cookie(nfss->fscache, NULL, false);
|
2009-04-03 23:42:42 +08:00
|
|
|
nfss->fscache = NULL;
|
|
|
|
|
|
|
|
if (nfss->fscache_key) {
|
|
|
|
spin_lock(&nfs_fscache_keys_lock);
|
|
|
|
rb_erase(&nfss->fscache_key->node, &nfs_fscache_keys);
|
|
|
|
spin_unlock(&nfs_fscache_keys_lock);
|
|
|
|
kfree(nfss->fscache_key);
|
|
|
|
nfss->fscache_key = NULL;
|
|
|
|
}
|
|
|
|
}
|
2009-04-03 23:42:43 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise the per-inode cache cookie pointer for an NFS inode.
|
|
|
|
*/
|
2013-09-27 18:20:03 +08:00
|
|
|
void nfs_fscache_init_inode(struct inode *inode)
|
2009-04-03 23:42:43 +08:00
|
|
|
{
|
2018-04-04 20:41:28 +08:00
|
|
|
struct nfs_fscache_inode_auxdata auxdata;
|
2019-08-04 01:39:24 +08:00
|
|
|
struct nfs_server *nfss = NFS_SERVER(inode);
|
2009-04-03 23:42:43 +08:00
|
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
|
|
|
2013-09-27 18:20:03 +08:00
|
|
|
nfsi->fscache = NULL;
|
2019-08-04 01:39:24 +08:00
|
|
|
if (!(nfss->fscache && S_ISREG(inode->i_mode)))
|
2009-04-03 23:42:43 +08:00
|
|
|
return;
|
2018-04-04 20:41:28 +08:00
|
|
|
|
|
|
|
memset(&auxdata, 0, sizeof(auxdata));
|
vfs: change inode times to use struct timespec64
struct timespec is not y2038 safe. Transition vfs to use
y2038 safe struct timespec64 instead.
The change was made with the help of the following cocinelle
script. This catches about 80% of the changes.
All the header file and logic changes are included in the
first 5 rules. The rest are trivial substitutions.
I avoid changing any of the function signatures or any other
filesystem specific data structures to keep the patch simple
for review.
The script can be a little shorter by combining different cases.
But, this version was sufficient for my usecase.
virtual patch
@ depends on patch @
identifier now;
@@
- struct timespec
+ struct timespec64
current_time ( ... )
{
- struct timespec now = current_kernel_time();
+ struct timespec64 now = current_kernel_time64();
...
- return timespec_trunc(
+ return timespec64_trunc(
... );
}
@ depends on patch @
identifier xtime;
@@
struct \( iattr \| inode \| kstat \) {
...
- struct timespec xtime;
+ struct timespec64 xtime;
...
}
@ depends on patch @
identifier t;
@@
struct inode_operations {
...
int (*update_time) (...,
- struct timespec t,
+ struct timespec64 t,
...);
...
}
@ depends on patch @
identifier t;
identifier fn_update_time =~ "update_time$";
@@
fn_update_time (...,
- struct timespec *t,
+ struct timespec64 *t,
...) { ... }
@ depends on patch @
identifier t;
@@
lease_get_mtime( ... ,
- struct timespec *t
+ struct timespec64 *t
) { ... }
@te depends on patch forall@
identifier ts;
local idexpression struct inode *inode_node;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn_update_time =~ "update_time$";
identifier fn;
expression e, E3;
local idexpression struct inode *node1;
local idexpression struct inode *node2;
local idexpression struct iattr *attr1;
local idexpression struct iattr *attr2;
local idexpression struct iattr attr;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
@@
(
(
- struct timespec ts;
+ struct timespec64 ts;
|
- struct timespec ts = current_time(inode_node);
+ struct timespec64 ts = current_time(inode_node);
)
<+... when != ts
(
- timespec_equal(&inode_node->i_xtime, &ts)
+ timespec64_equal(&inode_node->i_xtime, &ts)
|
- timespec_equal(&ts, &inode_node->i_xtime)
+ timespec64_equal(&ts, &inode_node->i_xtime)
|
- timespec_compare(&inode_node->i_xtime, &ts)
+ timespec64_compare(&inode_node->i_xtime, &ts)
|
- timespec_compare(&ts, &inode_node->i_xtime)
+ timespec64_compare(&ts, &inode_node->i_xtime)
|
ts = current_time(e)
|
fn_update_time(..., &ts,...)
|
inode_node->i_xtime = ts
|
node1->i_xtime = ts
|
ts = inode_node->i_xtime
|
<+... attr1->ia_xtime ...+> = ts
|
ts = attr1->ia_xtime
|
ts.tv_sec
|
ts.tv_nsec
|
btrfs_set_stack_timespec_sec(..., ts.tv_sec)
|
btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
|
- ts = timespec64_to_timespec(
+ ts =
...
-)
|
- ts = ktime_to_timespec(
+ ts = ktime_to_timespec64(
...)
|
- ts = E3
+ ts = timespec_to_timespec64(E3)
|
- ktime_get_real_ts(&ts)
+ ktime_get_real_ts64(&ts)
|
fn(...,
- ts
+ timespec64_to_timespec(ts)
,...)
)
...+>
(
<... when != ts
- return ts;
+ return timespec64_to_timespec(ts);
...>
)
|
- timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
|
- timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
+ timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
|
- timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
|
node1->i_xtime1 =
- timespec_trunc(attr1->ia_xtime1,
+ timespec64_trunc(attr1->ia_xtime1,
...)
|
- attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
+ attr1->ia_xtime1 = timespec64_trunc(attr2->ia_xtime2,
...)
|
- ktime_get_real_ts(&attr1->ia_xtime1)
+ ktime_get_real_ts64(&attr1->ia_xtime1)
|
- ktime_get_real_ts(&attr.ia_xtime1)
+ ktime_get_real_ts64(&attr.ia_xtime1)
)
@ depends on patch @
struct inode *node;
struct iattr *attr;
identifier fn;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
expression e;
@@
(
- fn(node->i_xtime);
+ fn(timespec64_to_timespec(node->i_xtime));
|
fn(...,
- node->i_xtime);
+ timespec64_to_timespec(node->i_xtime));
|
- e = fn(attr->ia_xtime);
+ e = fn(timespec64_to_timespec(attr->ia_xtime));
)
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
fn (...,
- &attr->ia_xtime,
+ &ts,
...);
)
...+>
}
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
struct kstat *stat;
identifier ia_xtime =~ "^ia_[acm]time$";
identifier i_xtime =~ "^i_[acm]time$";
identifier xtime =~ "^[acm]time$";
identifier fn, ret;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(stat->xtime);
ret = fn (...,
- &stat->xtime);
+ &ts);
)
...+>
}
@ depends on patch @
struct inode *node;
struct inode *node2;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier i_xtime3 =~ "^i_[acm]time$";
struct iattr *attrp;
struct iattr *attrp2;
struct iattr attr ;
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
struct kstat *stat;
struct kstat stat1;
struct timespec64 ts;
identifier xtime =~ "^[acmb]time$";
expression e;
@@
(
( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1 ;
|
node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
stat->xtime = node2->i_xtime1;
|
stat1.xtime = node2->i_xtime1;
|
( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1 ;
|
( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
|
- e = node->i_xtime1;
+ e = timespec64_to_timespec( node->i_xtime1 );
|
- e = attrp->ia_xtime1;
+ e = timespec64_to_timespec( attrp->ia_xtime1 );
|
node->i_xtime1 = current_time(...);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
- node->i_xtime1 = e;
+ node->i_xtime1 = timespec_to_timespec64(e);
)
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: <anton@tuxera.com>
Cc: <balbi@kernel.org>
Cc: <bfields@fieldses.org>
Cc: <darrick.wong@oracle.com>
Cc: <dhowells@redhat.com>
Cc: <dsterba@suse.com>
Cc: <dwmw2@infradead.org>
Cc: <hch@lst.de>
Cc: <hirofumi@mail.parknet.co.jp>
Cc: <hubcap@omnibond.com>
Cc: <jack@suse.com>
Cc: <jaegeuk@kernel.org>
Cc: <jaharkes@cs.cmu.edu>
Cc: <jslaby@suse.com>
Cc: <keescook@chromium.org>
Cc: <mark@fasheh.com>
Cc: <miklos@szeredi.hu>
Cc: <nico@linaro.org>
Cc: <reiserfs-devel@vger.kernel.org>
Cc: <richard@nod.at>
Cc: <sage@redhat.com>
Cc: <sfrench@samba.org>
Cc: <swhiteho@redhat.com>
Cc: <tj@kernel.org>
Cc: <trond.myklebust@primarydata.com>
Cc: <tytso@mit.edu>
Cc: <viro@zeniv.linux.org.uk>
2018-05-09 10:36:02 +08:00
|
|
|
auxdata.mtime = timespec64_to_timespec(nfsi->vfs_inode.i_mtime);
|
|
|
|
auxdata.ctime = timespec64_to_timespec(nfsi->vfs_inode.i_ctime);
|
2018-04-04 20:41:28 +08:00
|
|
|
|
|
|
|
if (NFS_SERVER(&nfsi->vfs_inode)->nfs_client->rpc_ops->version == 4)
|
|
|
|
auxdata.change_attr = inode_peek_iversion_raw(&nfsi->vfs_inode);
|
|
|
|
|
2013-09-27 18:20:03 +08:00
|
|
|
nfsi->fscache = fscache_acquire_cookie(NFS_SB(inode->i_sb)->fscache,
|
|
|
|
&nfs_fscache_inode_object_def,
|
2018-04-04 20:41:28 +08:00
|
|
|
nfsi->fh.data, nfsi->fh.size,
|
|
|
|
&auxdata, sizeof(auxdata),
|
2018-04-04 20:41:28 +08:00
|
|
|
nfsi, nfsi->vfs_inode.i_size, false);
|
2009-04-03 23:42:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release a per-inode cookie.
|
|
|
|
*/
|
2013-09-27 18:20:03 +08:00
|
|
|
void nfs_fscache_clear_inode(struct inode *inode)
|
2009-04-03 23:42:43 +08:00
|
|
|
{
|
2018-04-04 20:41:28 +08:00
|
|
|
struct nfs_fscache_inode_auxdata auxdata;
|
2009-04-03 23:42:43 +08:00
|
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
2013-09-27 18:20:03 +08:00
|
|
|
struct fscache_cookie *cookie = nfs_i_fscache(inode);
|
2009-04-03 23:42:43 +08:00
|
|
|
|
2013-09-27 18:20:03 +08:00
|
|
|
dfprintk(FSCACHE, "NFS: clear cookie (0x%p/0x%p)\n", nfsi, cookie);
|
2009-04-03 23:42:43 +08:00
|
|
|
|
2018-04-04 20:41:28 +08:00
|
|
|
memset(&auxdata, 0, sizeof(auxdata));
|
vfs: change inode times to use struct timespec64
struct timespec is not y2038 safe. Transition vfs to use
y2038 safe struct timespec64 instead.
The change was made with the help of the following cocinelle
script. This catches about 80% of the changes.
All the header file and logic changes are included in the
first 5 rules. The rest are trivial substitutions.
I avoid changing any of the function signatures or any other
filesystem specific data structures to keep the patch simple
for review.
The script can be a little shorter by combining different cases.
But, this version was sufficient for my usecase.
virtual patch
@ depends on patch @
identifier now;
@@
- struct timespec
+ struct timespec64
current_time ( ... )
{
- struct timespec now = current_kernel_time();
+ struct timespec64 now = current_kernel_time64();
...
- return timespec_trunc(
+ return timespec64_trunc(
... );
}
@ depends on patch @
identifier xtime;
@@
struct \( iattr \| inode \| kstat \) {
...
- struct timespec xtime;
+ struct timespec64 xtime;
...
}
@ depends on patch @
identifier t;
@@
struct inode_operations {
...
int (*update_time) (...,
- struct timespec t,
+ struct timespec64 t,
...);
...
}
@ depends on patch @
identifier t;
identifier fn_update_time =~ "update_time$";
@@
fn_update_time (...,
- struct timespec *t,
+ struct timespec64 *t,
...) { ... }
@ depends on patch @
identifier t;
@@
lease_get_mtime( ... ,
- struct timespec *t
+ struct timespec64 *t
) { ... }
@te depends on patch forall@
identifier ts;
local idexpression struct inode *inode_node;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn_update_time =~ "update_time$";
identifier fn;
expression e, E3;
local idexpression struct inode *node1;
local idexpression struct inode *node2;
local idexpression struct iattr *attr1;
local idexpression struct iattr *attr2;
local idexpression struct iattr attr;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
@@
(
(
- struct timespec ts;
+ struct timespec64 ts;
|
- struct timespec ts = current_time(inode_node);
+ struct timespec64 ts = current_time(inode_node);
)
<+... when != ts
(
- timespec_equal(&inode_node->i_xtime, &ts)
+ timespec64_equal(&inode_node->i_xtime, &ts)
|
- timespec_equal(&ts, &inode_node->i_xtime)
+ timespec64_equal(&ts, &inode_node->i_xtime)
|
- timespec_compare(&inode_node->i_xtime, &ts)
+ timespec64_compare(&inode_node->i_xtime, &ts)
|
- timespec_compare(&ts, &inode_node->i_xtime)
+ timespec64_compare(&ts, &inode_node->i_xtime)
|
ts = current_time(e)
|
fn_update_time(..., &ts,...)
|
inode_node->i_xtime = ts
|
node1->i_xtime = ts
|
ts = inode_node->i_xtime
|
<+... attr1->ia_xtime ...+> = ts
|
ts = attr1->ia_xtime
|
ts.tv_sec
|
ts.tv_nsec
|
btrfs_set_stack_timespec_sec(..., ts.tv_sec)
|
btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
|
- ts = timespec64_to_timespec(
+ ts =
...
-)
|
- ts = ktime_to_timespec(
+ ts = ktime_to_timespec64(
...)
|
- ts = E3
+ ts = timespec_to_timespec64(E3)
|
- ktime_get_real_ts(&ts)
+ ktime_get_real_ts64(&ts)
|
fn(...,
- ts
+ timespec64_to_timespec(ts)
,...)
)
...+>
(
<... when != ts
- return ts;
+ return timespec64_to_timespec(ts);
...>
)
|
- timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
|
- timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
+ timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
|
- timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
|
node1->i_xtime1 =
- timespec_trunc(attr1->ia_xtime1,
+ timespec64_trunc(attr1->ia_xtime1,
...)
|
- attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
+ attr1->ia_xtime1 = timespec64_trunc(attr2->ia_xtime2,
...)
|
- ktime_get_real_ts(&attr1->ia_xtime1)
+ ktime_get_real_ts64(&attr1->ia_xtime1)
|
- ktime_get_real_ts(&attr.ia_xtime1)
+ ktime_get_real_ts64(&attr.ia_xtime1)
)
@ depends on patch @
struct inode *node;
struct iattr *attr;
identifier fn;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
expression e;
@@
(
- fn(node->i_xtime);
+ fn(timespec64_to_timespec(node->i_xtime));
|
fn(...,
- node->i_xtime);
+ timespec64_to_timespec(node->i_xtime));
|
- e = fn(attr->ia_xtime);
+ e = fn(timespec64_to_timespec(attr->ia_xtime));
)
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
fn (...,
- &attr->ia_xtime,
+ &ts,
...);
)
...+>
}
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
struct kstat *stat;
identifier ia_xtime =~ "^ia_[acm]time$";
identifier i_xtime =~ "^i_[acm]time$";
identifier xtime =~ "^[acm]time$";
identifier fn, ret;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(stat->xtime);
ret = fn (...,
- &stat->xtime);
+ &ts);
)
...+>
}
@ depends on patch @
struct inode *node;
struct inode *node2;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier i_xtime3 =~ "^i_[acm]time$";
struct iattr *attrp;
struct iattr *attrp2;
struct iattr attr ;
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
struct kstat *stat;
struct kstat stat1;
struct timespec64 ts;
identifier xtime =~ "^[acmb]time$";
expression e;
@@
(
( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1 ;
|
node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
stat->xtime = node2->i_xtime1;
|
stat1.xtime = node2->i_xtime1;
|
( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1 ;
|
( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
|
- e = node->i_xtime1;
+ e = timespec64_to_timespec( node->i_xtime1 );
|
- e = attrp->ia_xtime1;
+ e = timespec64_to_timespec( attrp->ia_xtime1 );
|
node->i_xtime1 = current_time(...);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
- node->i_xtime1 = e;
+ node->i_xtime1 = timespec_to_timespec64(e);
)
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: <anton@tuxera.com>
Cc: <balbi@kernel.org>
Cc: <bfields@fieldses.org>
Cc: <darrick.wong@oracle.com>
Cc: <dhowells@redhat.com>
Cc: <dsterba@suse.com>
Cc: <dwmw2@infradead.org>
Cc: <hch@lst.de>
Cc: <hirofumi@mail.parknet.co.jp>
Cc: <hubcap@omnibond.com>
Cc: <jack@suse.com>
Cc: <jaegeuk@kernel.org>
Cc: <jaharkes@cs.cmu.edu>
Cc: <jslaby@suse.com>
Cc: <keescook@chromium.org>
Cc: <mark@fasheh.com>
Cc: <miklos@szeredi.hu>
Cc: <nico@linaro.org>
Cc: <reiserfs-devel@vger.kernel.org>
Cc: <richard@nod.at>
Cc: <sage@redhat.com>
Cc: <sfrench@samba.org>
Cc: <swhiteho@redhat.com>
Cc: <tj@kernel.org>
Cc: <trond.myklebust@primarydata.com>
Cc: <tytso@mit.edu>
Cc: <viro@zeniv.linux.org.uk>
2018-05-09 10:36:02 +08:00
|
|
|
auxdata.mtime = timespec64_to_timespec(nfsi->vfs_inode.i_mtime);
|
|
|
|
auxdata.ctime = timespec64_to_timespec(nfsi->vfs_inode.i_ctime);
|
2018-04-04 20:41:28 +08:00
|
|
|
fscache_relinquish_cookie(cookie, &auxdata, false);
|
2009-04-03 23:42:43 +08:00
|
|
|
nfsi->fscache = NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-27 18:20:03 +08:00
|
|
|
static bool nfs_fscache_can_enable(void *data)
|
2009-04-03 23:42:43 +08:00
|
|
|
{
|
2013-09-27 18:20:03 +08:00
|
|
|
struct inode *inode = data;
|
2009-04-03 23:42:43 +08:00
|
|
|
|
2013-09-27 18:20:03 +08:00
|
|
|
return !inode_is_open_for_write(inode);
|
2009-04-03 23:42:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-09-27 18:20:03 +08:00
|
|
|
* Enable or disable caching for a file that is being opened as appropriate.
|
|
|
|
* The cookie is allocated when the inode is initialised, but is not enabled at
|
|
|
|
* that time. Enablement is deferred to file-open time to avoid stat() and
|
|
|
|
* access() thrashing the cache.
|
|
|
|
*
|
|
|
|
* For now, with NFS, only regular files that are open read-only will be able
|
|
|
|
* to use the cache.
|
|
|
|
*
|
|
|
|
* We enable the cache for an inode if we open it read-only and it isn't
|
|
|
|
* currently open for writing. We disable the cache if the inode is open
|
|
|
|
* write-only.
|
|
|
|
*
|
|
|
|
* The caller uses the file struct to pin i_writecount on the inode before
|
|
|
|
* calling us when a file is opened for writing, so we can make use of that.
|
|
|
|
*
|
|
|
|
* Note that this may be invoked multiple times in parallel by parallel
|
|
|
|
* nfs_open() functions.
|
2009-04-03 23:42:43 +08:00
|
|
|
*/
|
2013-09-27 18:20:03 +08:00
|
|
|
void nfs_fscache_open_file(struct inode *inode, struct file *filp)
|
2009-04-03 23:42:43 +08:00
|
|
|
{
|
2018-04-04 20:41:28 +08:00
|
|
|
struct nfs_fscache_inode_auxdata auxdata;
|
2009-04-03 23:42:43 +08:00
|
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
2013-09-27 18:20:03 +08:00
|
|
|
struct fscache_cookie *cookie = nfs_i_fscache(inode);
|
2009-04-03 23:42:43 +08:00
|
|
|
|
2013-09-27 18:20:03 +08:00
|
|
|
if (!fscache_cookie_valid(cookie))
|
|
|
|
return;
|
2009-04-03 23:42:43 +08:00
|
|
|
|
2018-04-04 20:41:28 +08:00
|
|
|
memset(&auxdata, 0, sizeof(auxdata));
|
vfs: change inode times to use struct timespec64
struct timespec is not y2038 safe. Transition vfs to use
y2038 safe struct timespec64 instead.
The change was made with the help of the following cocinelle
script. This catches about 80% of the changes.
All the header file and logic changes are included in the
first 5 rules. The rest are trivial substitutions.
I avoid changing any of the function signatures or any other
filesystem specific data structures to keep the patch simple
for review.
The script can be a little shorter by combining different cases.
But, this version was sufficient for my usecase.
virtual patch
@ depends on patch @
identifier now;
@@
- struct timespec
+ struct timespec64
current_time ( ... )
{
- struct timespec now = current_kernel_time();
+ struct timespec64 now = current_kernel_time64();
...
- return timespec_trunc(
+ return timespec64_trunc(
... );
}
@ depends on patch @
identifier xtime;
@@
struct \( iattr \| inode \| kstat \) {
...
- struct timespec xtime;
+ struct timespec64 xtime;
...
}
@ depends on patch @
identifier t;
@@
struct inode_operations {
...
int (*update_time) (...,
- struct timespec t,
+ struct timespec64 t,
...);
...
}
@ depends on patch @
identifier t;
identifier fn_update_time =~ "update_time$";
@@
fn_update_time (...,
- struct timespec *t,
+ struct timespec64 *t,
...) { ... }
@ depends on patch @
identifier t;
@@
lease_get_mtime( ... ,
- struct timespec *t
+ struct timespec64 *t
) { ... }
@te depends on patch forall@
identifier ts;
local idexpression struct inode *inode_node;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn_update_time =~ "update_time$";
identifier fn;
expression e, E3;
local idexpression struct inode *node1;
local idexpression struct inode *node2;
local idexpression struct iattr *attr1;
local idexpression struct iattr *attr2;
local idexpression struct iattr attr;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
@@
(
(
- struct timespec ts;
+ struct timespec64 ts;
|
- struct timespec ts = current_time(inode_node);
+ struct timespec64 ts = current_time(inode_node);
)
<+... when != ts
(
- timespec_equal(&inode_node->i_xtime, &ts)
+ timespec64_equal(&inode_node->i_xtime, &ts)
|
- timespec_equal(&ts, &inode_node->i_xtime)
+ timespec64_equal(&ts, &inode_node->i_xtime)
|
- timespec_compare(&inode_node->i_xtime, &ts)
+ timespec64_compare(&inode_node->i_xtime, &ts)
|
- timespec_compare(&ts, &inode_node->i_xtime)
+ timespec64_compare(&ts, &inode_node->i_xtime)
|
ts = current_time(e)
|
fn_update_time(..., &ts,...)
|
inode_node->i_xtime = ts
|
node1->i_xtime = ts
|
ts = inode_node->i_xtime
|
<+... attr1->ia_xtime ...+> = ts
|
ts = attr1->ia_xtime
|
ts.tv_sec
|
ts.tv_nsec
|
btrfs_set_stack_timespec_sec(..., ts.tv_sec)
|
btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
|
- ts = timespec64_to_timespec(
+ ts =
...
-)
|
- ts = ktime_to_timespec(
+ ts = ktime_to_timespec64(
...)
|
- ts = E3
+ ts = timespec_to_timespec64(E3)
|
- ktime_get_real_ts(&ts)
+ ktime_get_real_ts64(&ts)
|
fn(...,
- ts
+ timespec64_to_timespec(ts)
,...)
)
...+>
(
<... when != ts
- return ts;
+ return timespec64_to_timespec(ts);
...>
)
|
- timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
|
- timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
+ timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
|
- timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
|
node1->i_xtime1 =
- timespec_trunc(attr1->ia_xtime1,
+ timespec64_trunc(attr1->ia_xtime1,
...)
|
- attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
+ attr1->ia_xtime1 = timespec64_trunc(attr2->ia_xtime2,
...)
|
- ktime_get_real_ts(&attr1->ia_xtime1)
+ ktime_get_real_ts64(&attr1->ia_xtime1)
|
- ktime_get_real_ts(&attr.ia_xtime1)
+ ktime_get_real_ts64(&attr.ia_xtime1)
)
@ depends on patch @
struct inode *node;
struct iattr *attr;
identifier fn;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
expression e;
@@
(
- fn(node->i_xtime);
+ fn(timespec64_to_timespec(node->i_xtime));
|
fn(...,
- node->i_xtime);
+ timespec64_to_timespec(node->i_xtime));
|
- e = fn(attr->ia_xtime);
+ e = fn(timespec64_to_timespec(attr->ia_xtime));
)
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
fn (...,
- &attr->ia_xtime,
+ &ts,
...);
)
...+>
}
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
struct kstat *stat;
identifier ia_xtime =~ "^ia_[acm]time$";
identifier i_xtime =~ "^i_[acm]time$";
identifier xtime =~ "^[acm]time$";
identifier fn, ret;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(stat->xtime);
ret = fn (...,
- &stat->xtime);
+ &ts);
)
...+>
}
@ depends on patch @
struct inode *node;
struct inode *node2;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier i_xtime3 =~ "^i_[acm]time$";
struct iattr *attrp;
struct iattr *attrp2;
struct iattr attr ;
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
struct kstat *stat;
struct kstat stat1;
struct timespec64 ts;
identifier xtime =~ "^[acmb]time$";
expression e;
@@
(
( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1 ;
|
node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
stat->xtime = node2->i_xtime1;
|
stat1.xtime = node2->i_xtime1;
|
( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1 ;
|
( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
|
- e = node->i_xtime1;
+ e = timespec64_to_timespec( node->i_xtime1 );
|
- e = attrp->ia_xtime1;
+ e = timespec64_to_timespec( attrp->ia_xtime1 );
|
node->i_xtime1 = current_time(...);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
- node->i_xtime1 = e;
+ node->i_xtime1 = timespec_to_timespec64(e);
)
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: <anton@tuxera.com>
Cc: <balbi@kernel.org>
Cc: <bfields@fieldses.org>
Cc: <darrick.wong@oracle.com>
Cc: <dhowells@redhat.com>
Cc: <dsterba@suse.com>
Cc: <dwmw2@infradead.org>
Cc: <hch@lst.de>
Cc: <hirofumi@mail.parknet.co.jp>
Cc: <hubcap@omnibond.com>
Cc: <jack@suse.com>
Cc: <jaegeuk@kernel.org>
Cc: <jaharkes@cs.cmu.edu>
Cc: <jslaby@suse.com>
Cc: <keescook@chromium.org>
Cc: <mark@fasheh.com>
Cc: <miklos@szeredi.hu>
Cc: <nico@linaro.org>
Cc: <reiserfs-devel@vger.kernel.org>
Cc: <richard@nod.at>
Cc: <sage@redhat.com>
Cc: <sfrench@samba.org>
Cc: <swhiteho@redhat.com>
Cc: <tj@kernel.org>
Cc: <trond.myklebust@primarydata.com>
Cc: <tytso@mit.edu>
Cc: <viro@zeniv.linux.org.uk>
2018-05-09 10:36:02 +08:00
|
|
|
auxdata.mtime = timespec64_to_timespec(nfsi->vfs_inode.i_mtime);
|
|
|
|
auxdata.ctime = timespec64_to_timespec(nfsi->vfs_inode.i_ctime);
|
2018-04-04 20:41:28 +08:00
|
|
|
|
2013-09-27 18:20:03 +08:00
|
|
|
if (inode_is_open_for_write(inode)) {
|
|
|
|
dfprintk(FSCACHE, "NFS: nfsi 0x%p disabling cache\n", nfsi);
|
|
|
|
clear_bit(NFS_INO_FSCACHE, &nfsi->flags);
|
2018-04-04 20:41:28 +08:00
|
|
|
fscache_disable_cookie(cookie, &auxdata, true);
|
2013-09-27 18:20:03 +08:00
|
|
|
fscache_uncache_all_inode_pages(cookie, inode);
|
|
|
|
} else {
|
|
|
|
dfprintk(FSCACHE, "NFS: nfsi 0x%p enabling cache\n", nfsi);
|
2018-04-04 20:41:28 +08:00
|
|
|
fscache_enable_cookie(cookie, &auxdata, nfsi->vfs_inode.i_size,
|
2018-04-04 20:41:28 +08:00
|
|
|
nfs_fscache_can_enable, inode);
|
2013-09-27 18:20:03 +08:00
|
|
|
if (fscache_cookie_enabled(cookie))
|
|
|
|
set_bit(NFS_INO_FSCACHE, &NFS_I(inode)->flags);
|
2009-04-03 23:42:43 +08:00
|
|
|
}
|
|
|
|
}
|
2013-09-27 18:20:03 +08:00
|
|
|
EXPORT_SYMBOL_GPL(nfs_fscache_open_file);
|
2009-04-03 23:42:44 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the caching state associated with a page, if the page isn't busy
|
|
|
|
* interacting with the cache.
|
|
|
|
* - Returns true (can release page) or false (page busy).
|
|
|
|
*/
|
|
|
|
int nfs_fscache_release_page(struct page *page, gfp_t gfp)
|
|
|
|
{
|
|
|
|
if (PageFsCache(page)) {
|
2013-09-27 18:20:03 +08:00
|
|
|
struct fscache_cookie *cookie = nfs_i_fscache(page->mapping->host);
|
2010-02-08 22:32:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!cookie);
|
2009-04-03 23:42:44 +08:00
|
|
|
dfprintk(FSCACHE, "NFS: fscache releasepage (0x%p/0x%p/0x%p)\n",
|
2013-09-27 18:20:03 +08:00
|
|
|
cookie, page, NFS_I(page->mapping->host));
|
2009-04-03 23:42:44 +08:00
|
|
|
|
FS-Cache: Handle pages pending storage that get evicted under OOM conditions
Handle netfs pages that the vmscan algorithm wants to evict from the pagecache
under OOM conditions, but that are waiting for write to the cache. Under these
conditions, vmscan calls the releasepage() function of the netfs, asking if a
page can be discarded.
The problem is typified by the following trace of a stuck process:
kslowd005 D 0000000000000000 0 4253 2 0x00000080
ffff88001b14f370 0000000000000046 ffff880020d0d000 0000000000000007
0000000000000006 0000000000000001 ffff88001b14ffd8 ffff880020d0d2a8
000000000000ddf0 00000000000118c0 00000000000118c0 ffff880020d0d2a8
Call Trace:
[<ffffffffa00782d8>] __fscache_wait_on_page_write+0x8b/0xa7 [fscache]
[<ffffffff8104c0f1>] ? autoremove_wake_function+0x0/0x34
[<ffffffffa0078240>] ? __fscache_check_page_write+0x63/0x70 [fscache]
[<ffffffffa00b671d>] nfs_fscache_release_page+0x4e/0xc4 [nfs]
[<ffffffffa00927f0>] nfs_release_page+0x3c/0x41 [nfs]
[<ffffffff810885d3>] try_to_release_page+0x32/0x3b
[<ffffffff81093203>] shrink_page_list+0x316/0x4ac
[<ffffffff8109372b>] shrink_inactive_list+0x392/0x67c
[<ffffffff813532fa>] ? __mutex_unlock_slowpath+0x100/0x10b
[<ffffffff81058df0>] ? trace_hardirqs_on_caller+0x10c/0x130
[<ffffffff8135330e>] ? mutex_unlock+0x9/0xb
[<ffffffff81093aa2>] shrink_list+0x8d/0x8f
[<ffffffff81093d1c>] shrink_zone+0x278/0x33c
[<ffffffff81052d6c>] ? ktime_get_ts+0xad/0xba
[<ffffffff81094b13>] try_to_free_pages+0x22e/0x392
[<ffffffff81091e24>] ? isolate_pages_global+0x0/0x212
[<ffffffff8108e743>] __alloc_pages_nodemask+0x3dc/0x5cf
[<ffffffff81089529>] grab_cache_page_write_begin+0x65/0xaa
[<ffffffff8110f8c0>] ext3_write_begin+0x78/0x1eb
[<ffffffff81089ec5>] generic_file_buffered_write+0x109/0x28c
[<ffffffff8103cb69>] ? current_fs_time+0x22/0x29
[<ffffffff8108a509>] __generic_file_aio_write+0x350/0x385
[<ffffffff8108a588>] ? generic_file_aio_write+0x4a/0xae
[<ffffffff8108a59e>] generic_file_aio_write+0x60/0xae
[<ffffffff810b2e82>] do_sync_write+0xe3/0x120
[<ffffffff8104c0f1>] ? autoremove_wake_function+0x0/0x34
[<ffffffff810b18e1>] ? __dentry_open+0x1a5/0x2b8
[<ffffffff810b1a76>] ? dentry_open+0x82/0x89
[<ffffffffa00e693c>] cachefiles_write_page+0x298/0x335 [cachefiles]
[<ffffffffa0077147>] fscache_write_op+0x178/0x2c2 [fscache]
[<ffffffffa0075656>] fscache_op_execute+0x7a/0xd1 [fscache]
[<ffffffff81082093>] slow_work_execute+0x18f/0x2d1
[<ffffffff8108239a>] slow_work_thread+0x1c5/0x308
[<ffffffff8104c0f1>] ? autoremove_wake_function+0x0/0x34
[<ffffffff810821d5>] ? slow_work_thread+0x0/0x308
[<ffffffff8104be91>] kthread+0x7a/0x82
[<ffffffff8100beda>] child_rip+0xa/0x20
[<ffffffff8100b87c>] ? restore_args+0x0/0x30
[<ffffffff8102ef83>] ? tg_shares_up+0x171/0x227
[<ffffffff8104be17>] ? kthread+0x0/0x82
[<ffffffff8100bed0>] ? child_rip+0x0/0x20
In the above backtrace, the following is happening:
(1) A page storage operation is being executed by a slow-work thread
(fscache_write_op()).
(2) FS-Cache farms the operation out to the cache to perform
(cachefiles_write_page()).
(3) CacheFiles is then calling Ext3 to perform the actual write, using Ext3's
standard write (do_sync_write()) under KERNEL_DS directly from the netfs
page.
(4) However, for Ext3 to perform the write, it must allocate some memory, in
particular, it must allocate at least one page cache page into which it
can copy the data from the netfs page.
(5) Under OOM conditions, the memory allocator can't immediately come up with
a page, so it uses vmscan to find something to discard
(try_to_free_pages()).
(6) vmscan finds a clean netfs page it might be able to discard (possibly the
one it's trying to write out).
(7) The netfs is called to throw the page away (nfs_release_page()) - but it's
called with __GFP_WAIT, so the netfs decides to wait for the store to
complete (__fscache_wait_on_page_write()).
(8) This blocks a slow-work processing thread - possibly against itself.
The system ends up stuck because it can't write out any netfs pages to the
cache without allocating more memory.
To avoid this, we make FS-Cache cancel some writes that aren't in the middle of
actually being performed. This means that some data won't make it into the
cache this time. To support this, a new FS-Cache function is added
fscache_maybe_release_page() that replaces what the netfs releasepage()
functions used to do with respect to the cache.
The decisions fscache_maybe_release_page() makes are counted and displayed
through /proc/fs/fscache/stats on a line labelled "VmScan". There are four
counters provided: "nos=N" - pages that weren't pending storage; "gon=N" -
pages that were pending storage when we first looked, but weren't by the time
we got the object lock; "bsy=N" - pages that we ignored as they were actively
being written when we looked; and "can=N" - pages that we cancelled the storage
of.
What I'd really like to do is alter the behaviour of the cancellation
heuristics, depending on how necessary it is to expel pages. If there are
plenty of other pages that aren't waiting to be written to the cache that
could be ejected first, then it would be nice to hold up on immediate
cancellation of cache writes - but I don't see a way of doing that.
Signed-off-by: David Howells <dhowells@redhat.com>
2009-11-20 02:11:35 +08:00
|
|
|
if (!fscache_maybe_release_page(cookie, page, gfp))
|
|
|
|
return 0;
|
|
|
|
|
2014-11-23 12:47:41 +08:00
|
|
|
nfs_inc_fscache_stats(page->mapping->host,
|
|
|
|
NFSIOS_FSCACHE_PAGES_UNCACHED);
|
2009-04-03 23:42:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the caching state associated with a page if undergoing complete page
|
|
|
|
* invalidation.
|
|
|
|
*/
|
|
|
|
void __nfs_fscache_invalidate_page(struct page *page, struct inode *inode)
|
|
|
|
{
|
2013-09-27 18:20:03 +08:00
|
|
|
struct fscache_cookie *cookie = nfs_i_fscache(inode);
|
2009-04-03 23:42:44 +08:00
|
|
|
|
|
|
|
BUG_ON(!cookie);
|
|
|
|
|
|
|
|
dfprintk(FSCACHE, "NFS: fscache invalidatepage (0x%p/0x%p/0x%p)\n",
|
2013-09-27 18:20:03 +08:00
|
|
|
cookie, page, NFS_I(inode));
|
2009-04-03 23:42:44 +08:00
|
|
|
|
|
|
|
fscache_wait_on_page_write(cookie, page);
|
|
|
|
|
|
|
|
BUG_ON(!PageLocked(page));
|
|
|
|
fscache_uncache_page(cookie, page);
|
2014-11-23 12:47:41 +08:00
|
|
|
nfs_inc_fscache_stats(page->mapping->host,
|
|
|
|
NFSIOS_FSCACHE_PAGES_UNCACHED);
|
2009-04-03 23:42:44 +08:00
|
|
|
}
|
2009-04-03 23:42:44 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle completion of a page being read from the cache.
|
|
|
|
* - Called in process (keventd) context.
|
|
|
|
*/
|
|
|
|
static void nfs_readpage_from_fscache_complete(struct page *page,
|
|
|
|
void *context,
|
|
|
|
int error)
|
|
|
|
{
|
|
|
|
dfprintk(FSCACHE,
|
|
|
|
"NFS: readpage_from_fscache_complete (0x%p/0x%p/%d)\n",
|
|
|
|
page, context, error);
|
|
|
|
|
|
|
|
/* if the read completes with an error, we just unlock the page and let
|
|
|
|
* the VM reissue the readpage */
|
|
|
|
if (!error) {
|
|
|
|
SetPageUptodate(page);
|
|
|
|
unlock_page(page);
|
|
|
|
} else {
|
|
|
|
error = nfs_readpage_async(context, page->mapping->host, page);
|
|
|
|
if (error)
|
|
|
|
unlock_page(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieve a page from fscache
|
|
|
|
*/
|
|
|
|
int __nfs_readpage_from_fscache(struct nfs_open_context *ctx,
|
|
|
|
struct inode *inode, struct page *page)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dfprintk(FSCACHE,
|
|
|
|
"NFS: readpage_from_fscache(fsc:%p/p:%p(i:%lx f:%lx)/0x%p)\n",
|
2013-09-27 18:20:03 +08:00
|
|
|
nfs_i_fscache(inode), page, page->index, page->flags, inode);
|
2009-04-03 23:42:44 +08:00
|
|
|
|
2013-09-27 18:20:03 +08:00
|
|
|
ret = fscache_read_or_alloc_page(nfs_i_fscache(inode),
|
2009-04-03 23:42:44 +08:00
|
|
|
page,
|
|
|
|
nfs_readpage_from_fscache_complete,
|
|
|
|
ctx,
|
|
|
|
GFP_KERNEL);
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case 0: /* read BIO submitted (page in fscache) */
|
|
|
|
dfprintk(FSCACHE,
|
|
|
|
"NFS: readpage_from_fscache: BIO submitted\n");
|
2014-11-23 12:47:41 +08:00
|
|
|
nfs_inc_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_OK);
|
2009-04-03 23:42:44 +08:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
case -ENOBUFS: /* inode not in cache */
|
|
|
|
case -ENODATA: /* page not in cache */
|
2014-11-23 12:47:41 +08:00
|
|
|
nfs_inc_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_FAIL);
|
2009-04-03 23:42:44 +08:00
|
|
|
dfprintk(FSCACHE,
|
|
|
|
"NFS: readpage_from_fscache %d\n", ret);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dfprintk(FSCACHE, "NFS: readpage_from_fscache %d\n", ret);
|
2014-11-23 12:47:41 +08:00
|
|
|
nfs_inc_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_FAIL);
|
2009-04-03 23:42:44 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieve a set of pages from fscache
|
|
|
|
*/
|
|
|
|
int __nfs_readpages_from_fscache(struct nfs_open_context *ctx,
|
|
|
|
struct inode *inode,
|
|
|
|
struct address_space *mapping,
|
|
|
|
struct list_head *pages,
|
|
|
|
unsigned *nr_pages)
|
|
|
|
{
|
2010-05-08 01:33:48 +08:00
|
|
|
unsigned npages = *nr_pages;
|
|
|
|
int ret;
|
2009-04-03 23:42:44 +08:00
|
|
|
|
|
|
|
dfprintk(FSCACHE, "NFS: nfs_getpages_from_fscache (0x%p/%u/0x%p)\n",
|
2013-09-27 18:20:03 +08:00
|
|
|
nfs_i_fscache(inode), npages, inode);
|
2009-04-03 23:42:44 +08:00
|
|
|
|
2013-09-27 18:20:03 +08:00
|
|
|
ret = fscache_read_or_alloc_pages(nfs_i_fscache(inode),
|
2009-04-03 23:42:44 +08:00
|
|
|
mapping, pages, nr_pages,
|
|
|
|
nfs_readpage_from_fscache_complete,
|
|
|
|
ctx,
|
|
|
|
mapping_gfp_mask(mapping));
|
|
|
|
if (*nr_pages < npages)
|
|
|
|
nfs_add_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_OK,
|
|
|
|
npages);
|
|
|
|
if (*nr_pages > 0)
|
|
|
|
nfs_add_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_FAIL,
|
|
|
|
*nr_pages);
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case 0: /* read submitted to the cache for all pages */
|
|
|
|
BUG_ON(!list_empty(pages));
|
|
|
|
BUG_ON(*nr_pages != 0);
|
|
|
|
dfprintk(FSCACHE,
|
|
|
|
"NFS: nfs_getpages_from_fscache: submitted\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
case -ENOBUFS: /* some pages aren't cached and can't be */
|
|
|
|
case -ENODATA: /* some pages aren't cached */
|
|
|
|
dfprintk(FSCACHE,
|
|
|
|
"NFS: nfs_getpages_from_fscache: no page: %d\n", ret);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dfprintk(FSCACHE,
|
|
|
|
"NFS: nfs_getpages_from_fscache: ret %d\n", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2009-04-03 23:42:45 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Store a newly fetched page in fscache
|
|
|
|
* - PG_fscache must be set on the page
|
|
|
|
*/
|
|
|
|
void __nfs_readpage_to_fscache(struct inode *inode, struct page *page, int sync)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dfprintk(FSCACHE,
|
|
|
|
"NFS: readpage_to_fscache(fsc:%p/p:%p(i:%lx f:%lx)/%d)\n",
|
2013-09-27 18:20:03 +08:00
|
|
|
nfs_i_fscache(inode), page, page->index, page->flags, sync);
|
2009-04-03 23:42:45 +08:00
|
|
|
|
2018-04-04 20:41:28 +08:00
|
|
|
ret = fscache_write_page(nfs_i_fscache(inode), page,
|
|
|
|
inode->i_size, GFP_KERNEL);
|
2009-04-03 23:42:45 +08:00
|
|
|
dfprintk(FSCACHE,
|
|
|
|
"NFS: readpage_to_fscache: p:%p(i:%lu f:%lx) ret %d\n",
|
|
|
|
page, page->index, page->flags, ret);
|
|
|
|
|
|
|
|
if (ret != 0) {
|
2013-09-27 18:20:03 +08:00
|
|
|
fscache_uncache_page(nfs_i_fscache(inode), page);
|
2014-11-23 12:47:41 +08:00
|
|
|
nfs_inc_fscache_stats(inode,
|
|
|
|
NFSIOS_FSCACHE_PAGES_WRITTEN_FAIL);
|
|
|
|
nfs_inc_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_UNCACHED);
|
2009-04-03 23:42:45 +08:00
|
|
|
} else {
|
2014-11-23 12:47:41 +08:00
|
|
|
nfs_inc_fscache_stats(inode,
|
|
|
|
NFSIOS_FSCACHE_PAGES_WRITTEN_OK);
|
2009-04-03 23:42:45 +08:00
|
|
|
}
|
|
|
|
}
|