2019-05-31 16:09:24 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* include/linux/sunrpc/cache.h
|
|
|
|
*
|
|
|
|
* Generic code for various authentication-related caches
|
|
|
|
* used by sunrpc clients and servers.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Neil Brown <neilb@cse.unsw.edu.au>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_SUNRPC_CACHE_H_
|
|
|
|
#define _LINUX_SUNRPC_CACHE_H_
|
|
|
|
|
2011-01-10 14:18:25 +08:00
|
|
|
#include <linux/kref.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/slab.h>
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2021-07-01 09:56:10 +08:00
|
|
|
#include <linux/kstrtox.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each cache requires:
|
|
|
|
* - A 'struct cache_detail' which contains information specific to the cache
|
|
|
|
* for common code to use.
|
|
|
|
* - An item structure that must contain a "struct cache_head"
|
|
|
|
* - A lookup function defined using DefineCacheLookup
|
|
|
|
* - A 'put' function that can release a cache item. It will only
|
|
|
|
* be called after cache_put has succeed, so there are guarantee
|
|
|
|
* to be no references.
|
|
|
|
* - A function to calculate a hash of an item's key.
|
|
|
|
*
|
|
|
|
* as well as assorted code fragments (e.g. compare keys) and numbers
|
|
|
|
* (e.g. hash size, goal_age, etc).
|
|
|
|
*
|
|
|
|
* Each cache must be registered so that it can be cleaned regularly.
|
|
|
|
* When the cache is unregistered, it is flushed completely.
|
|
|
|
*
|
2011-03-31 09:57:33 +08:00
|
|
|
* Entries have a ref count and a 'hashed' flag which counts the existence
|
2005-04-17 06:20:36 +08:00
|
|
|
* in the hash table.
|
|
|
|
* We only expire entries when refcount is zero.
|
2011-03-31 09:57:33 +08:00
|
|
|
* Existence in the cache is counted the refcount.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Every cache item has a common header that is used
|
|
|
|
* for expiring and refreshing entries.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct cache_head {
|
2015-07-27 11:10:15 +08:00
|
|
|
struct hlist_node cache_list;
|
2020-07-16 09:31:30 +08:00
|
|
|
time64_t expiry_time; /* After time expiry_time, don't use
|
|
|
|
* the data */
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
time64_t last_refresh; /* If CACHE_PENDING, this is when upcall was
|
2015-10-16 05:59:08 +08:00
|
|
|
* sent, else this is when update was
|
|
|
|
* received, though it is alway set to
|
|
|
|
* be *after* ->flush_time.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2006-03-27 17:15:09 +08:00
|
|
|
struct kref ref;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
};
|
|
|
|
#define CACHE_VALID 0 /* Entry contains valid data */
|
|
|
|
#define CACHE_NEGATIVE 1 /* Negative entry - there is no match for the key */
|
|
|
|
#define CACHE_PENDING 2 /* An upcall has been sent but no reply received yet*/
|
2013-06-13 10:53:42 +08:00
|
|
|
#define CACHE_CLEANED 3 /* Entry has been cleaned from cache */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define CACHE_NEW_EXPIRY 120 /* keep new things pending confirmation for 120 seconds */
|
|
|
|
|
|
|
|
struct cache_detail {
|
2005-09-07 06:17:08 +08:00
|
|
|
struct module * owner;
|
2005-04-17 06:20:36 +08:00
|
|
|
int hash_size;
|
2015-07-27 11:10:15 +08:00
|
|
|
struct hlist_head * hash_table;
|
2018-10-01 22:41:52 +08:00
|
|
|
spinlock_t hash_lock;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
char *name;
|
2006-03-27 17:15:09 +08:00
|
|
|
void (*cache_put)(struct kref *);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-08-10 03:14:29 +08:00
|
|
|
int (*cache_upcall)(struct cache_detail *,
|
|
|
|
struct cache_head *);
|
|
|
|
|
2013-02-04 19:02:45 +08:00
|
|
|
void (*cache_request)(struct cache_detail *cd,
|
|
|
|
struct cache_head *ch,
|
|
|
|
char **bpp, int *blen);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int (*cache_parse)(struct cache_detail *,
|
|
|
|
char *buf, int len);
|
|
|
|
|
|
|
|
int (*cache_show)(struct seq_file *m,
|
|
|
|
struct cache_detail *cd,
|
|
|
|
struct cache_head *h);
|
2009-08-10 03:14:26 +08:00
|
|
|
void (*warn_no_listener)(struct cache_detail *cd,
|
|
|
|
int has_died);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-27 17:15:02 +08:00
|
|
|
struct cache_head * (*alloc)(void);
|
2019-08-19 02:18:44 +08:00
|
|
|
void (*flush)(void);
|
2006-03-27 17:15:02 +08:00
|
|
|
int (*match)(struct cache_head *orig, struct cache_head *new);
|
|
|
|
void (*init)(struct cache_head *orig, struct cache_head *new);
|
|
|
|
void (*update)(struct cache_head *orig, struct cache_head *new);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* fields below this comment are for internal use
|
|
|
|
* and should not be touched by cache owners
|
|
|
|
*/
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
time64_t flush_time; /* flush all cache items with
|
2015-10-16 05:59:08 +08:00
|
|
|
* last_refresh at or earlier
|
|
|
|
* than this. last_refresh
|
|
|
|
* is never set at or earlier
|
|
|
|
* than this.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
struct list_head others;
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
time64_t nextcheck;
|
2005-04-17 06:20:36 +08:00
|
|
|
int entries;
|
|
|
|
|
|
|
|
/* fields for communication over channel */
|
|
|
|
struct list_head queue;
|
|
|
|
|
2019-07-27 06:33:01 +08:00
|
|
|
atomic_t writers; /* how many time is /channel open */
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
time64_t last_close; /* if no writers, when did last close */
|
|
|
|
time64_t last_warn; /* when we last warned about no writers */
|
2009-08-10 03:14:29 +08:00
|
|
|
|
|
|
|
union {
|
2017-02-07 21:47:16 +08:00
|
|
|
struct proc_dir_entry *procfs;
|
|
|
|
struct dentry *pipefs;
|
|
|
|
};
|
2012-01-20 01:42:21 +08:00
|
|
|
struct net *net;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* this must be embedded in any request structure that
|
|
|
|
* identifies an object that will want a callback on
|
|
|
|
* a cache fill
|
|
|
|
*/
|
|
|
|
struct cache_req {
|
|
|
|
struct cache_deferred_req *(*defer)(struct cache_req *req);
|
2022-04-02 01:10:31 +08:00
|
|
|
unsigned long thread_wait; /* How long (jiffies) we can block the
|
|
|
|
* current thread to wait for updates.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
2022-04-02 01:10:31 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* this must be embedded in a deferred_request that is being
|
|
|
|
* delayed awaiting cache-fill
|
|
|
|
*/
|
|
|
|
struct cache_deferred_req {
|
2010-08-12 15:04:08 +08:00
|
|
|
struct hlist_node hash; /* on hash chain */
|
2005-04-17 06:20:36 +08:00
|
|
|
struct list_head recent; /* on fifo */
|
|
|
|
struct cache_head *item; /* cache item we wait on */
|
|
|
|
void *owner; /* we might need to discard all defered requests
|
|
|
|
* owned by someone */
|
|
|
|
void (*revisit)(struct cache_deferred_req *req,
|
|
|
|
int too_many);
|
|
|
|
};
|
|
|
|
|
2013-06-13 10:53:42 +08:00
|
|
|
/*
|
|
|
|
* timestamps kept in the cache are expressed in seconds
|
|
|
|
* since boot. This is the best for measuring differences in
|
|
|
|
* real time.
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
* This reimplemnts ktime_get_boottime_seconds() in a slightly
|
|
|
|
* faster but less accurate way. When we end up converting
|
|
|
|
* back to wallclock (CLOCK_REALTIME), that error often
|
|
|
|
* cancels out during the reverse operation.
|
2013-06-13 10:53:42 +08:00
|
|
|
*/
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
static inline time64_t seconds_since_boot(void)
|
2013-06-13 10:53:42 +08:00
|
|
|
{
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
struct timespec64 boot;
|
|
|
|
getboottime64(&boot);
|
|
|
|
return ktime_get_real_seconds() - boot.tv_sec;
|
2013-06-13 10:53:42 +08:00
|
|
|
}
|
|
|
|
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
static inline time64_t convert_to_wallclock(time64_t sinceboot)
|
2013-06-13 10:53:42 +08:00
|
|
|
{
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
struct timespec64 boot;
|
|
|
|
getboottime64(&boot);
|
2013-06-13 10:53:42 +08:00
|
|
|
return boot.tv_sec + sinceboot;
|
|
|
|
}
|
2006-03-27 17:15:01 +08:00
|
|
|
|
2009-08-10 03:14:30 +08:00
|
|
|
extern const struct file_operations cache_file_operations_pipefs;
|
|
|
|
extern const struct file_operations content_file_operations_pipefs;
|
|
|
|
extern const struct file_operations cache_flush_operations_pipefs;
|
|
|
|
|
2018-10-04 00:01:22 +08:00
|
|
|
extern struct cache_head *
|
|
|
|
sunrpc_cache_lookup_rcu(struct cache_detail *detail,
|
|
|
|
struct cache_head *key, int hash);
|
2006-03-27 17:15:02 +08:00
|
|
|
extern struct cache_head *
|
|
|
|
sunrpc_cache_update(struct cache_detail *detail,
|
|
|
|
struct cache_head *new, struct cache_head *old, int hash);
|
|
|
|
|
2009-08-10 03:14:29 +08:00
|
|
|
extern int
|
2013-02-04 19:02:55 +08:00
|
|
|
sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h);
|
2020-03-02 07:21:42 +08:00
|
|
|
extern int
|
|
|
|
sunrpc_cache_pipe_upcall_timeout(struct cache_detail *detail,
|
|
|
|
struct cache_head *h);
|
2009-08-10 03:14:29 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
extern void cache_clean_deferred(void *owner);
|
|
|
|
|
|
|
|
static inline struct cache_head *cache_get(struct cache_head *h)
|
|
|
|
{
|
2006-03-27 17:15:09 +08:00
|
|
|
kref_get(&h->ref);
|
2005-04-17 06:20:36 +08:00
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2018-10-04 00:01:22 +08:00
|
|
|
static inline struct cache_head *cache_get_rcu(struct cache_head *h)
|
|
|
|
{
|
|
|
|
if (kref_get_unless_zero(&h->ref))
|
|
|
|
return h;
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-27 17:15:09 +08:00
|
|
|
static inline void cache_put(struct cache_head *h, struct cache_detail *cd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2016-11-15 00:29:48 +08:00
|
|
|
if (kref_read(&h->ref) <= 2 &&
|
2005-04-17 06:20:36 +08:00
|
|
|
h->expiry_time < cd->nextcheck)
|
|
|
|
cd->nextcheck = h->expiry_time;
|
2006-03-27 17:15:09 +08:00
|
|
|
kref_put(&h->ref, cd->cache_put);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
SUNRPC/Cache: Always treat the invalid cache as unexpired
When the first time pynfs runs after rpc/nfsd startup, always get the warning,
"Got error: Connection closed"
I found the problem is caused by,
1. A new startup of nfsd, rpc.mountd, etc,
2. A rpc request from client (pynfs test, or normal mounting),
3. An ip_map cache is created but invalid, so upcall to rpc.mountd,
4. rpc.mountd process the ip_map upcall, before write the valid data to nfsd,
do auth_reload(), and check_useipaddr(),
5. For the first time, old_use_ipaddr = -1, it causes rpc.mountd do write_flush that doing cache_clean,
6. The ip_map cache will be treat as expired and clean,
7. When rpc.mountd write the valid data to nfsd, a new ip_map is created
and updated, the cache_check of old ip_map(doing the upcall) will
return -ETIMEDOUT.
8. RPC layer return SVC_CLOSE and close the xprt after commit 4d712ef1db05
"svcauth_gss: Close connection when dropping an incoming message"
NeilBrown suggest in another email,
"If CACHE_VALID is not set, then there is no data in the cache item,
so there is nothing to expire. So it would be nice if cache items that
don't have CACHE_VALID are never treated as expired."
v3, change the order of the two patches
v2, change the checking of CACHE_PENDING to CACHE_VALID
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
2017-02-08 09:54:42 +08:00
|
|
|
static inline bool cache_is_expired(struct cache_detail *detail, struct cache_head *h)
|
2006-10-04 17:15:50 +08:00
|
|
|
{
|
2020-03-27 23:53:09 +08:00
|
|
|
if (h->expiry_time < seconds_since_boot())
|
|
|
|
return true;
|
|
|
|
if (!test_bit(CACHE_VALID, &h->flags))
|
|
|
|
return false;
|
|
|
|
return detail->flush_time >= h->last_refresh;
|
2006-10-04 17:15:50 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
extern int cache_check(struct cache_detail *detail,
|
|
|
|
struct cache_head *h, struct cache_req *rqstp);
|
|
|
|
extern void cache_flush(void);
|
|
|
|
extern void cache_purge(struct cache_detail *detail);
|
|
|
|
#define NEVER (0x7FFFFFFF)
|
sunrpc: make the cache cleaner workqueue deferrable
This patch makes the cache_cleaner workqueue deferrable, to prevent
unnecessary system wake-ups, which is very important for embedded
battery-powered devices.
do_cache_clean() is called every 30 seconds at the moment, and often
makes the system wake up from its power-save sleep state. With this
change, when the workqueue uses a deferrable timer, the
do_cache_clean() invocation will be delayed and combined with the
closest "real" wake-up. This improves the power consumption situation.
Note, I tried to create a DECLARE_DELAYED_WORK_DEFERRABLE() helper
macro, similar to DECLARE_DELAYED_WORK(), but failed because of the
way the timer wheel core stores the deferrable flag (it is the
LSBit in the time->base pointer). My attempt to define a static
variable with this bit set ended up with the "initializer element is
not constant" error.
Thus, I have to use run-time initialization, so I created a new
cache_initialize() function which is called once when sunrpc is
being initialized.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
2010-07-01 23:05:56 +08:00
|
|
|
extern void __init cache_initialize(void);
|
2010-09-27 18:00:15 +08:00
|
|
|
extern int cache_register_net(struct cache_detail *cd, struct net *net);
|
|
|
|
extern void cache_unregister_net(struct cache_detail *cd, struct net *net);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-10-18 00:14:23 +08:00
|
|
|
extern struct cache_detail *cache_create_net(const struct cache_detail *tmpl, struct net *net);
|
2012-01-20 01:42:21 +08:00
|
|
|
extern void cache_destroy_net(struct cache_detail *cd, struct net *net);
|
|
|
|
|
2011-11-25 22:12:40 +08:00
|
|
|
extern void sunrpc_init_cache_detail(struct cache_detail *cd);
|
|
|
|
extern void sunrpc_destroy_cache_detail(struct cache_detail *cd);
|
2009-08-10 03:14:30 +08:00
|
|
|
extern int sunrpc_cache_register_pipefs(struct dentry *parent, const char *,
|
2011-07-25 12:35:13 +08:00
|
|
|
umode_t, struct cache_detail *);
|
2009-08-10 03:14:30 +08:00
|
|
|
extern void sunrpc_cache_unregister_pipefs(struct cache_detail *);
|
2016-12-23 01:38:06 +08:00
|
|
|
extern void sunrpc_cache_unhash(struct cache_detail *, struct cache_head *);
|
2009-08-10 03:14:30 +08:00
|
|
|
|
2015-07-27 11:09:42 +08:00
|
|
|
/* Must store cache_detail in seq_file->private if using next three functions */
|
2018-10-04 00:01:22 +08:00
|
|
|
extern void *cache_seq_start_rcu(struct seq_file *file, loff_t *pos);
|
|
|
|
extern void *cache_seq_next_rcu(struct seq_file *file, void *p, loff_t *pos);
|
|
|
|
extern void cache_seq_stop_rcu(struct seq_file *file, void *p);
|
2015-07-27 11:09:42 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
extern void qword_add(char **bpp, int *lp, char *str);
|
|
|
|
extern void qword_addhex(char **bpp, int *lp, char *buf, int blen);
|
|
|
|
extern int qword_get(char **bpp, char *dest, int bufsize);
|
|
|
|
|
|
|
|
static inline int get_int(char **bpp, int *anint)
|
|
|
|
{
|
|
|
|
char buf[50];
|
2012-11-14 23:48:05 +08:00
|
|
|
char *ep;
|
|
|
|
int rv;
|
2012-07-07 03:31:56 +08:00
|
|
|
int len = qword_get(bpp, buf, sizeof(buf));
|
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
if (len == 0)
|
|
|
|
return -ENOENT;
|
|
|
|
|
2012-11-14 23:48:05 +08:00
|
|
|
rv = simple_strtol(buf, &ep, 0);
|
|
|
|
if (*ep)
|
2012-07-07 03:31:56 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2012-11-14 23:48:05 +08:00
|
|
|
*anint = rv;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-13 04:54:16 +08:00
|
|
|
static inline int get_uint(char **bpp, unsigned int *anint)
|
|
|
|
{
|
|
|
|
char buf[50];
|
|
|
|
int len = qword_get(bpp, buf, sizeof(buf));
|
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
if (len == 0)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
if (kstrtouint(buf, 0, anint))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
static inline int get_time(char **bpp, time64_t *time)
|
2013-08-16 01:46:40 +08:00
|
|
|
{
|
|
|
|
char buf[50];
|
|
|
|
long long ll;
|
|
|
|
int len = qword_get(bpp, buf, sizeof(buf));
|
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
if (len == 0)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
if (kstrtoll(buf, 0, &ll))
|
|
|
|
return -EINVAL;
|
|
|
|
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
*time = ll;
|
2013-08-16 01:46:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
static inline time64_t get_expiry(char **bpp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
time64_t rv;
|
|
|
|
struct timespec64 boot;
|
2010-08-12 14:55:22 +08:00
|
|
|
|
2013-08-16 01:46:40 +08:00
|
|
|
if (get_time(bpp, &rv))
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
if (rv < 0)
|
|
|
|
return 0;
|
nfs: use time64_t internally
The timestamps for the cache are all in boottime seconds, so they
don't overflow 32-bit values, but the use of time_t is deprecated
because it generally does overflow when used with wall-clock time.
There are multiple possible ways of avoiding it:
- leave time_t, which is safe here, but forces others to
look into this code to determine that it is over and over.
- use a more generic type, like 'int' or 'long', which is known
to be sufficient here but loses the documentation of referring
to timestamps
- use ktime_t everywhere, and convert into seconds in the few
places where we want realtime-seconds. The conversion is
sometimes expensive, but not more so than the conversion we
do today.
- use time64_t to clarify that this code is safe. Nothing would
change for 64-bit architectures, but it is slightly less
efficient on 32-bit architectures.
Without a clear winner of the three approaches above, this picks
the last one, favouring readability over a small performance
loss on 32-bit architectures.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2017-10-20 22:34:42 +08:00
|
|
|
getboottime64(&boot);
|
2010-08-12 14:55:22 +08:00
|
|
|
return rv - boot.tv_sec;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _LINUX_SUNRPC_CACHE_H_ */
|