2013-08-22 01:29:54 +04:00
|
|
|
/*
|
|
|
|
* Ceph cache definitions.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 by Adfin Solutions, Inc. All Rights Reserved.
|
|
|
|
* Written by Milosz Tanski (milosz@adfin.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to:
|
|
|
|
* Free Software Foundation
|
|
|
|
* 51 Franklin Street, Fifth Floor
|
|
|
|
* Boston, MA 02111-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "super.h"
|
|
|
|
#include "cache.h"
|
|
|
|
|
|
|
|
struct ceph_aux_inode {
|
2016-05-20 11:57:29 +03:00
|
|
|
u64 version;
|
2013-08-22 01:29:54 +04:00
|
|
|
struct timespec mtime;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fscache_netfs ceph_cache_netfs = {
|
|
|
|
.name = "ceph",
|
|
|
|
.version = 0,
|
|
|
|
};
|
|
|
|
|
2017-06-27 06:57:56 +03:00
|
|
|
static DEFINE_MUTEX(ceph_fscache_lock);
|
|
|
|
static LIST_HEAD(ceph_fscache_list);
|
|
|
|
|
|
|
|
struct ceph_fscache_entry {
|
|
|
|
struct list_head list;
|
|
|
|
struct fscache_cookie *fscache;
|
|
|
|
size_t uniq_len;
|
2018-04-04 15:41:28 +03:00
|
|
|
/* The following members must be last */
|
|
|
|
struct ceph_fsid fsid;
|
2017-06-27 06:57:56 +03:00
|
|
|
char uniquifier[0];
|
|
|
|
};
|
|
|
|
|
2013-08-22 01:29:54 +04:00
|
|
|
static const struct fscache_cookie_def ceph_fscache_fsid_object_def = {
|
|
|
|
.name = "CEPH.fsid",
|
|
|
|
.type = FSCACHE_COOKIE_TYPE_INDEX,
|
|
|
|
};
|
|
|
|
|
2018-03-10 15:32:05 +03:00
|
|
|
int __init ceph_fscache_register(void)
|
2013-08-22 01:29:54 +04:00
|
|
|
{
|
|
|
|
return fscache_register_netfs(&ceph_cache_netfs);
|
|
|
|
}
|
|
|
|
|
2013-09-06 19:13:18 +04:00
|
|
|
void ceph_fscache_unregister(void)
|
2013-08-22 01:29:54 +04:00
|
|
|
{
|
|
|
|
fscache_unregister_netfs(&ceph_cache_netfs);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ceph_fscache_register_fs(struct ceph_fs_client* fsc)
|
|
|
|
{
|
2017-06-27 06:57:56 +03:00
|
|
|
const struct ceph_fsid *fsid = &fsc->client->fsid;
|
|
|
|
const char *fscache_uniq = fsc->mount_options->fscache_uniq;
|
|
|
|
size_t uniq_len = fscache_uniq ? strlen(fscache_uniq) : 0;
|
|
|
|
struct ceph_fscache_entry *ent;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
mutex_lock(&ceph_fscache_lock);
|
|
|
|
list_for_each_entry(ent, &ceph_fscache_list, list) {
|
|
|
|
if (memcmp(&ent->fsid, fsid, sizeof(*fsid)))
|
|
|
|
continue;
|
|
|
|
if (ent->uniq_len != uniq_len)
|
|
|
|
continue;
|
|
|
|
if (uniq_len && memcmp(ent->uniquifier, fscache_uniq, uniq_len))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pr_err("fscache cookie already registered for fsid %pU\n", fsid);
|
|
|
|
pr_err(" use fsc=%%s mount option to specify a uniquifier\n");
|
|
|
|
err = -EBUSY;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
ent = kzalloc(sizeof(*ent) + uniq_len, GFP_KERNEL);
|
|
|
|
if (!ent) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
2018-04-04 15:41:28 +03:00
|
|
|
memcpy(&ent->fsid, fsid, sizeof(*fsid));
|
|
|
|
if (uniq_len > 0) {
|
|
|
|
memcpy(&ent->uniquifier, fscache_uniq, uniq_len);
|
|
|
|
ent->uniq_len = uniq_len;
|
|
|
|
}
|
|
|
|
|
2013-08-22 01:29:54 +04:00
|
|
|
fsc->fscache = fscache_acquire_cookie(ceph_cache_netfs.primary_index,
|
|
|
|
&ceph_fscache_fsid_object_def,
|
2018-04-04 15:41:28 +03:00
|
|
|
&ent->fsid, sizeof(ent->fsid) + uniq_len,
|
|
|
|
NULL, 0,
|
2018-04-04 15:41:28 +03:00
|
|
|
fsc, 0, true);
|
2013-08-22 01:29:54 +04:00
|
|
|
|
2017-06-27 06:57:56 +03:00
|
|
|
if (fsc->fscache) {
|
|
|
|
ent->fscache = fsc->fscache;
|
|
|
|
list_add_tail(&ent->list, &ceph_fscache_list);
|
|
|
|
} else {
|
|
|
|
kfree(ent);
|
|
|
|
pr_err("unable to register fscache cookie for fsid %pU\n",
|
|
|
|
fsid);
|
|
|
|
/* all other fs ignore this error */
|
|
|
|
}
|
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&ceph_fscache_lock);
|
|
|
|
return err;
|
2013-08-22 01:29:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static enum fscache_checkaux ceph_fscache_inode_check_aux(
|
2018-04-04 15:41:28 +03:00
|
|
|
void *cookie_netfs_data, const void *data, uint16_t dlen,
|
|
|
|
loff_t object_size)
|
2013-08-22 01:29:54 +04:00
|
|
|
{
|
|
|
|
struct ceph_aux_inode aux;
|
|
|
|
struct ceph_inode_info* ci = cookie_netfs_data;
|
|
|
|
struct inode* inode = &ci->vfs_inode;
|
|
|
|
|
2018-04-04 15:41:28 +03:00
|
|
|
if (dlen != sizeof(aux) ||
|
|
|
|
i_size_read(inode) != object_size)
|
2013-08-22 01:29:54 +04:00
|
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
|
|
|
|
|
|
|
memset(&aux, 0, sizeof(aux));
|
2016-05-20 11:57:29 +03:00
|
|
|
aux.version = ci->i_version;
|
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 05:36:02 +03:00
|
|
|
aux.mtime = timespec64_to_timespec(inode->i_mtime);
|
2013-08-22 01:29:54 +04:00
|
|
|
|
|
|
|
if (memcmp(data, &aux, sizeof(aux)) != 0)
|
|
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
|
|
|
|
2018-01-30 11:29:17 +03:00
|
|
|
dout("ceph inode 0x%p cached okay\n", ci);
|
2013-08-22 01:29:54 +04:00
|
|
|
return FSCACHE_CHECKAUX_OKAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct fscache_cookie_def ceph_fscache_inode_object_def = {
|
|
|
|
.name = "CEPH.inode",
|
|
|
|
.type = FSCACHE_COOKIE_TYPE_DATAFILE,
|
|
|
|
.check_aux = ceph_fscache_inode_check_aux,
|
|
|
|
};
|
|
|
|
|
2016-05-18 10:25:03 +03:00
|
|
|
void ceph_fscache_register_inode_cookie(struct inode *inode)
|
2013-08-22 01:29:54 +04:00
|
|
|
{
|
2016-05-18 10:25:03 +03:00
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
|
2018-04-04 15:41:28 +03:00
|
|
|
struct ceph_aux_inode aux;
|
2013-08-22 01:29:54 +04:00
|
|
|
|
|
|
|
/* No caching for filesystem */
|
2017-08-20 21:22:02 +03:00
|
|
|
if (!fsc->fscache)
|
2013-08-22 01:29:54 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Only cache for regular files that are read only */
|
2016-05-18 10:25:03 +03:00
|
|
|
if (!S_ISREG(inode->i_mode))
|
2013-08-22 01:29:54 +04:00
|
|
|
return;
|
|
|
|
|
2016-05-18 10:25:03 +03:00
|
|
|
inode_lock_nested(inode, I_MUTEX_CHILD);
|
|
|
|
if (!ci->fscache) {
|
2018-04-04 15:41:28 +03:00
|
|
|
memset(&aux, 0, sizeof(aux));
|
|
|
|
aux.version = ci->i_version;
|
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 05:36:02 +03:00
|
|
|
aux.mtime = timespec64_to_timespec(inode->i_mtime);
|
2016-05-18 10:25:03 +03:00
|
|
|
ci->fscache = fscache_acquire_cookie(fsc->fscache,
|
2018-04-04 15:41:28 +03:00
|
|
|
&ceph_fscache_inode_object_def,
|
|
|
|
&ci->i_vino, sizeof(ci->i_vino),
|
|
|
|
&aux, sizeof(aux),
|
2018-04-04 15:41:28 +03:00
|
|
|
ci, i_size_read(inode), false);
|
2016-05-18 10:25:03 +03:00
|
|
|
}
|
2016-01-22 23:40:57 +03:00
|
|
|
inode_unlock(inode);
|
2013-08-22 01:29:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci)
|
|
|
|
{
|
|
|
|
struct fscache_cookie* cookie;
|
|
|
|
|
|
|
|
if ((cookie = ci->fscache) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ci->fscache = NULL;
|
|
|
|
|
|
|
|
fscache_uncache_all_inode_pages(cookie, &ci->vfs_inode);
|
2018-04-04 15:41:28 +03:00
|
|
|
fscache_relinquish_cookie(cookie, &ci->i_vino, false);
|
2013-08-22 01:29:54 +04:00
|
|
|
}
|
|
|
|
|
2016-05-18 10:25:03 +03:00
|
|
|
static bool ceph_fscache_can_enable(void *data)
|
|
|
|
{
|
|
|
|
struct inode *inode = data;
|
|
|
|
return !inode_is_open_for_write(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ceph_fscache_file_set_cookie(struct inode *inode, struct file *filp)
|
|
|
|
{
|
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
|
|
|
|
if (!fscache_cookie_valid(ci->fscache))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (inode_is_open_for_write(inode)) {
|
|
|
|
dout("fscache_file_set_cookie %p %p disabling cache\n",
|
|
|
|
inode, filp);
|
2018-04-04 15:41:28 +03:00
|
|
|
fscache_disable_cookie(ci->fscache, &ci->i_vino, false);
|
2016-05-18 10:25:03 +03:00
|
|
|
fscache_uncache_all_inode_pages(ci->fscache, inode);
|
|
|
|
} else {
|
2018-04-04 15:41:28 +03:00
|
|
|
fscache_enable_cookie(ci->fscache, &ci->i_vino, i_size_read(inode),
|
2018-04-04 15:41:28 +03:00
|
|
|
ceph_fscache_can_enable, inode);
|
2016-05-18 10:25:03 +03:00
|
|
|
if (fscache_cookie_enabled(ci->fscache)) {
|
2016-12-29 23:19:32 +03:00
|
|
|
dout("fscache_file_set_cookie %p %p enabling cache\n",
|
2016-05-18 10:25:03 +03:00
|
|
|
inode, filp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 06:22:31 +03:00
|
|
|
static void ceph_readpage_from_fscache_complete(struct page *page, void *data, int error)
|
2013-08-22 01:29:54 +04:00
|
|
|
{
|
|
|
|
if (!error)
|
|
|
|
SetPageUptodate(page);
|
|
|
|
|
|
|
|
unlock_page(page);
|
|
|
|
}
|
|
|
|
|
2016-03-25 12:18:39 +03:00
|
|
|
static inline bool cache_valid(struct ceph_inode_info *ci)
|
2013-08-22 01:29:54 +04:00
|
|
|
{
|
2016-05-18 15:31:55 +03:00
|
|
|
return ci->i_fscache_gen == ci->i_rdcache_gen;
|
2013-08-22 01:29:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Atempt to read from the fscache,
|
|
|
|
*
|
|
|
|
* This function is called from the readpage_nounlock context. DO NOT attempt to
|
|
|
|
* unlock the page here (or in the callback).
|
|
|
|
*/
|
|
|
|
int ceph_readpage_from_fscache(struct inode *inode, struct page *page)
|
|
|
|
{
|
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!cache_valid(ci))
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
|
|
|
ret = fscache_read_or_alloc_page(ci->fscache, page,
|
2017-08-04 06:22:31 +03:00
|
|
|
ceph_readpage_from_fscache_complete, NULL,
|
2013-08-22 01:29:54 +04:00
|
|
|
GFP_KERNEL);
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case 0: /* Page found */
|
|
|
|
dout("page read submitted\n");
|
|
|
|
return 0;
|
|
|
|
case -ENOBUFS: /* Pages were not found, and can't be */
|
|
|
|
case -ENODATA: /* Pages were not found */
|
|
|
|
dout("page/inode not in cache\n");
|
|
|
|
return ret;
|
|
|
|
default:
|
|
|
|
dout("%s: unknown error ret = %i\n", __func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ceph_readpages_from_fscache(struct inode *inode,
|
|
|
|
struct address_space *mapping,
|
|
|
|
struct list_head *pages,
|
|
|
|
unsigned *nr_pages)
|
|
|
|
{
|
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!cache_valid(ci))
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
|
|
|
ret = fscache_read_or_alloc_pages(ci->fscache, mapping, pages, nr_pages,
|
2017-08-04 06:22:31 +03:00
|
|
|
ceph_readpage_from_fscache_complete,
|
2013-08-22 01:29:54 +04:00
|
|
|
NULL, mapping_gfp_mask(mapping));
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case 0: /* All pages found */
|
|
|
|
dout("all-page read submitted\n");
|
|
|
|
return 0;
|
|
|
|
case -ENOBUFS: /* Some pages were not found, and can't be */
|
|
|
|
case -ENODATA: /* some pages were not found */
|
|
|
|
dout("page/inode not in cache\n");
|
|
|
|
return ret;
|
|
|
|
default:
|
|
|
|
dout("%s: unknown error ret = %i\n", __func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ceph_readpage_to_fscache(struct inode *inode, struct page *page)
|
|
|
|
{
|
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
int ret;
|
|
|
|
|
2013-09-04 03:11:01 +04:00
|
|
|
if (!PageFsCache(page))
|
|
|
|
return;
|
|
|
|
|
2013-08-22 01:29:54 +04:00
|
|
|
if (!cache_valid(ci))
|
|
|
|
return;
|
|
|
|
|
2018-04-04 15:41:28 +03:00
|
|
|
ret = fscache_write_page(ci->fscache, page, i_size_read(inode),
|
|
|
|
GFP_KERNEL);
|
2013-08-22 01:29:54 +04:00
|
|
|
if (ret)
|
|
|
|
fscache_uncache_page(ci->fscache, page);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ceph_invalidate_fscache_page(struct inode* inode, struct page *page)
|
|
|
|
{
|
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
|
2013-09-25 19:18:14 +04:00
|
|
|
if (!PageFsCache(page))
|
|
|
|
return;
|
|
|
|
|
2013-08-22 01:29:54 +04:00
|
|
|
fscache_wait_on_page_write(ci->fscache, page);
|
|
|
|
fscache_uncache_page(ci->fscache, page);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
|
|
|
|
{
|
2017-06-27 06:57:56 +03:00
|
|
|
if (fscache_cookie_valid(fsc->fscache)) {
|
|
|
|
struct ceph_fscache_entry *ent;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
mutex_lock(&ceph_fscache_lock);
|
|
|
|
list_for_each_entry(ent, &ceph_fscache_list, list) {
|
|
|
|
if (ent->fscache == fsc->fscache) {
|
|
|
|
list_del(&ent->list);
|
|
|
|
kfree(ent);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WARN_ON_ONCE(!found);
|
|
|
|
mutex_unlock(&ceph_fscache_lock);
|
|
|
|
|
2018-04-04 15:41:28 +03:00
|
|
|
__fscache_relinquish_cookie(fsc->fscache, NULL, false);
|
2017-06-27 06:57:56 +03:00
|
|
|
}
|
2013-08-22 01:29:54 +04:00
|
|
|
fsc->fscache = NULL;
|
|
|
|
}
|
|
|
|
|
2016-05-18 15:31:55 +03:00
|
|
|
/*
|
|
|
|
* caller should hold CEPH_CAP_FILE_{RD,CACHE}
|
|
|
|
*/
|
|
|
|
void ceph_fscache_revalidate_cookie(struct ceph_inode_info *ci)
|
2013-08-22 01:29:54 +04:00
|
|
|
{
|
2016-05-18 15:31:55 +03:00
|
|
|
if (cache_valid(ci))
|
2013-09-05 22:29:03 +04:00
|
|
|
return;
|
|
|
|
|
2016-05-18 15:31:55 +03:00
|
|
|
/* resue i_truncate_mutex. There should be no pending
|
|
|
|
* truncate while the caller holds CEPH_CAP_FILE_RD */
|
|
|
|
mutex_lock(&ci->i_truncate_mutex);
|
|
|
|
if (!cache_valid(ci)) {
|
2018-04-04 15:41:28 +03:00
|
|
|
if (fscache_check_consistency(ci->fscache, &ci->i_vino))
|
2016-05-18 15:31:55 +03:00
|
|
|
fscache_invalidate(ci->fscache);
|
|
|
|
spin_lock(&ci->i_ceph_lock);
|
|
|
|
ci->i_fscache_gen = ci->i_rdcache_gen;
|
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2013-08-22 01:29:54 +04:00
|
|
|
}
|
2016-05-18 15:31:55 +03:00
|
|
|
mutex_unlock(&ci->i_truncate_mutex);
|
2013-08-22 01:29:54 +04:00
|
|
|
}
|