mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-17 09:14:19 +08:00
95582b0083
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>
145 lines
3.7 KiB
C
145 lines
3.7 KiB
C
/*
|
|
* fs/cifs/cache.c - CIFS filesystem cache index structure definitions
|
|
*
|
|
* Copyright (c) 2010 Novell, Inc.
|
|
* Authors(s): Suresh Jayaraman (sjayaraman@suse.de>
|
|
*
|
|
* This library is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published
|
|
* by the Free Software Foundation; either version 2.1 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This library 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 Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
#include "fscache.h"
|
|
#include "cifs_debug.h"
|
|
|
|
/*
|
|
* CIFS filesystem definition for FS-Cache
|
|
*/
|
|
struct fscache_netfs cifs_fscache_netfs = {
|
|
.name = "cifs",
|
|
.version = 0,
|
|
};
|
|
|
|
/*
|
|
* Register CIFS for caching with FS-Cache
|
|
*/
|
|
int cifs_fscache_register(void)
|
|
{
|
|
return fscache_register_netfs(&cifs_fscache_netfs);
|
|
}
|
|
|
|
/*
|
|
* Unregister CIFS for caching
|
|
*/
|
|
void cifs_fscache_unregister(void)
|
|
{
|
|
fscache_unregister_netfs(&cifs_fscache_netfs);
|
|
}
|
|
|
|
/*
|
|
* Server object for FS-Cache
|
|
*/
|
|
const struct fscache_cookie_def cifs_fscache_server_index_def = {
|
|
.name = "CIFS.server",
|
|
.type = FSCACHE_COOKIE_TYPE_INDEX,
|
|
};
|
|
|
|
/*
|
|
* Auxiliary data attached to CIFS superblock within the cache
|
|
*/
|
|
struct cifs_fscache_super_auxdata {
|
|
u64 resource_id; /* unique server resource id */
|
|
};
|
|
|
|
char *extract_sharename(const char *treename)
|
|
{
|
|
const char *src;
|
|
char *delim, *dst;
|
|
int len;
|
|
|
|
/* skip double chars at the beginning */
|
|
src = treename + 2;
|
|
|
|
/* share name is always preceded by '\\' now */
|
|
delim = strchr(src, '\\');
|
|
if (!delim)
|
|
return ERR_PTR(-EINVAL);
|
|
delim++;
|
|
len = strlen(delim);
|
|
|
|
/* caller has to free the memory */
|
|
dst = kstrndup(delim, len, GFP_KERNEL);
|
|
if (!dst)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
return dst;
|
|
}
|
|
|
|
static enum
|
|
fscache_checkaux cifs_fscache_super_check_aux(void *cookie_netfs_data,
|
|
const void *data,
|
|
uint16_t datalen,
|
|
loff_t object_size)
|
|
{
|
|
struct cifs_fscache_super_auxdata auxdata;
|
|
const struct cifs_tcon *tcon = cookie_netfs_data;
|
|
|
|
if (datalen != sizeof(auxdata))
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
|
|
|
memset(&auxdata, 0, sizeof(auxdata));
|
|
auxdata.resource_id = tcon->resource_id;
|
|
|
|
if (memcmp(data, &auxdata, datalen) != 0)
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
|
|
|
return FSCACHE_CHECKAUX_OKAY;
|
|
}
|
|
|
|
/*
|
|
* Superblock object for FS-Cache
|
|
*/
|
|
const struct fscache_cookie_def cifs_fscache_super_index_def = {
|
|
.name = "CIFS.super",
|
|
.type = FSCACHE_COOKIE_TYPE_INDEX,
|
|
.check_aux = cifs_fscache_super_check_aux,
|
|
};
|
|
|
|
static enum
|
|
fscache_checkaux cifs_fscache_inode_check_aux(void *cookie_netfs_data,
|
|
const void *data,
|
|
uint16_t datalen,
|
|
loff_t object_size)
|
|
{
|
|
struct cifs_fscache_inode_auxdata auxdata;
|
|
struct cifsInodeInfo *cifsi = cookie_netfs_data;
|
|
|
|
if (datalen != sizeof(auxdata))
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
|
|
|
memset(&auxdata, 0, sizeof(auxdata));
|
|
auxdata.eof = cifsi->server_eof;
|
|
auxdata.last_write_time = timespec64_to_timespec(cifsi->vfs_inode.i_mtime);
|
|
auxdata.last_change_time = timespec64_to_timespec(cifsi->vfs_inode.i_ctime);
|
|
|
|
if (memcmp(data, &auxdata, datalen) != 0)
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
|
|
|
return FSCACHE_CHECKAUX_OKAY;
|
|
}
|
|
|
|
const struct fscache_cookie_def cifs_fscache_inode_object_def = {
|
|
.name = "CIFS.uniqueid",
|
|
.type = FSCACHE_COOKIE_TYPE_DATAFILE,
|
|
.check_aux = cifs_fscache_inode_check_aux,
|
|
};
|