2019-05-31 11:09:24 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2005-04-17 02:20:36 +04: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 09:18:25 +03:00
|
|
|
#include <linux/kref.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/slab.h>
|
2011-07-27 03:09:06 +04:00
|
|
|
#include <linux/atomic.h>
|
2005-04-17 02:20:36 +04: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 05:57:33 +04:00
|
|
|
* Entries have a ref count and a 'hashed' flag which counts the existence
|
2005-04-17 02:20:36 +04:00
|
|
|
* in the hash table.
|
|
|
|
* We only expire entries when refcount is zero.
|
2011-03-31 05:57:33 +04:00
|
|
|
* Existence in the cache is counted the refcount.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Every cache item has a common header that is used
|
|
|
|
* for expiring and refreshing entries.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct cache_head {
|
2015-07-27 06:10:15 +03:00
|
|
|
struct hlist_node cache_list;
|
2020-07-16 04:31:30 +03: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 17:34:42 +03:00
|
|
|
time64_t last_refresh; /* If CACHE_PENDING, this is when upcall was
|
2015-10-16 00:59:08 +03:00
|
|
|
* sent, else this is when update was
|
|
|
|
* received, though it is alway set to
|
|
|
|
* be *after* ->flush_time.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2006-03-27 13:15:09 +04:00
|
|
|
struct kref ref;
|
2005-04-17 02:20:36 +04: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 06:53:42 +04:00
|
|
|
#define CACHE_CLEANED 3 /* Entry has been cleaned from cache */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#define CACHE_NEW_EXPIRY 120 /* keep new things pending confirmation for 120 seconds */
|
|
|
|
|
|
|
|
struct cache_detail {
|
2005-09-07 02:17:08 +04:00
|
|
|
struct module * owner;
|
2005-04-17 02:20:36 +04:00
|
|
|
int hash_size;
|
2015-07-27 06:10:15 +03:00
|
|
|
struct hlist_head * hash_table;
|
2018-10-01 17:41:52 +03:00
|
|
|
spinlock_t hash_lock;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
char *name;
|
2006-03-27 13:15:09 +04:00
|
|
|
void (*cache_put)(struct kref *);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-08-09 23:14:29 +04:00
|
|
|
int (*cache_upcall)(struct cache_detail *,
|
|
|
|
struct cache_head *);
|
|
|
|
|
2013-02-04 15:02:45 +04:00
|
|
|
void (*cache_request)(struct cache_detail *cd,
|
|
|
|
struct cache_head *ch,
|
|
|
|
char **bpp, int *blen);
|
|
|
|
|
2005-04-17 02:20:36 +04: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-09 23:14:26 +04:00
|
|
|
void (*warn_no_listener)(struct cache_detail *cd,
|
|
|
|
int has_died);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-03-27 13:15:02 +04:00
|
|
|
struct cache_head * (*alloc)(void);
|
2019-08-18 21:18:44 +03:00
|
|
|
void (*flush)(void);
|
2006-03-27 13:15:02 +04: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 02:20:36 +04: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 17:34:42 +03:00
|
|
|
time64_t flush_time; /* flush all cache items with
|
2015-10-16 00:59:08 +03:00
|
|
|
* last_refresh at or earlier
|
|
|
|
* than this. last_refresh
|
|
|
|
* is never set at or earlier
|
|
|
|
* than this.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04: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 17:34:42 +03:00
|
|
|
time64_t nextcheck;
|
2005-04-17 02:20:36 +04:00
|
|
|
int entries;
|
|
|
|
|
|
|
|
/* fields for communication over channel */
|
|
|
|
struct list_head queue;
|
|
|
|
|
2019-07-27 01:33:01 +03: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 17:34:42 +03: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-09 23:14:29 +04:00
|
|
|
|
|
|
|
union {
|
2017-02-07 16:47:16 +03:00
|
|
|
struct proc_dir_entry *procfs;
|
|
|
|
struct dentry *pipefs;
|
|
|
|
};
|
2012-01-19 21:42:21 +04:00
|
|
|
struct net *net;
|
2005-04-17 02:20:36 +04: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);
|
sunrpc/cache: allow threads to block while waiting for cache update.
The current practice of waiting for cache updates by queueing the
whole request to be retried has (at least) two problems.
1/ With NFSv4, requests can be quite complex and re-trying a whole
request when a later part fails should only be a last-resort, not a
normal practice.
2/ Large requests, and in particular any 'write' request, will not be
queued by the current code and doing so would be undesirable.
In many cases only a very sort wait is needed before the cache gets
valid data.
So, providing the underlying transport permits it by setting
->thread_wait,
arrange to wait briefly for an upcall to be completed (as reflected in
the clearing of CACHE_PENDING).
If the short wait was not long enough and CACHE_PENDING is still set,
fall back on the old approach.
The 'thread_wait' value is set to 5 seconds when there are spare
threads, and 1 second when there are no spare threads.
These values are probably much higher than needed, but will ensure
some forward progress.
Note that as we only request an update for a non-valid item, and as
non-valid items are updated in place it is extremely unlikely that
cache_check will return -ETIMEDOUT. Normally cache_defer_req will
sleep for a short while and then find that the item is_valid.
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
2010-08-12 11:04:06 +04:00
|
|
|
int thread_wait; /* How long (jiffies) we can block the
|
|
|
|
* current thread to wait for updates.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
/* this must be embedded in a deferred_request that is being
|
|
|
|
* delayed awaiting cache-fill
|
|
|
|
*/
|
|
|
|
struct cache_deferred_req {
|
2010-08-12 11:04:08 +04:00
|
|
|
struct hlist_node hash; /* on hash chain */
|
2005-04-17 02:20:36 +04: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 06:53:42 +04: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 17:34:42 +03: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 06:53:42 +04: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 17:34:42 +03:00
|
|
|
static inline time64_t seconds_since_boot(void)
|
2013-06-13 06:53:42 +04: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 17:34:42 +03:00
|
|
|
struct timespec64 boot;
|
|
|
|
getboottime64(&boot);
|
|
|
|
return ktime_get_real_seconds() - boot.tv_sec;
|
2013-06-13 06:53:42 +04: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 17:34:42 +03:00
|
|
|
static inline time64_t convert_to_wallclock(time64_t sinceboot)
|
2013-06-13 06:53:42 +04: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 17:34:42 +03:00
|
|
|
struct timespec64 boot;
|
|
|
|
getboottime64(&boot);
|
2013-06-13 06:53:42 +04:00
|
|
|
return boot.tv_sec + sinceboot;
|
|
|
|
}
|
2006-03-27 13:15:01 +04:00
|
|
|
|
2009-08-09 23:14:30 +04: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-03 19:01:22 +03:00
|
|
|
extern struct cache_head *
|
|
|
|
sunrpc_cache_lookup_rcu(struct cache_detail *detail,
|
|
|
|
struct cache_head *key, int hash);
|
2006-03-27 13:15:02 +04:00
|
|
|
extern struct cache_head *
|
|
|
|
sunrpc_cache_update(struct cache_detail *detail,
|
|
|
|
struct cache_head *new, struct cache_head *old, int hash);
|
|
|
|
|
2009-08-09 23:14:29 +04:00
|
|
|
extern int
|
2013-02-04 15:02:55 +04:00
|
|
|
sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h);
|
2020-03-02 02:21:42 +03:00
|
|
|
extern int
|
|
|
|
sunrpc_cache_pipe_upcall_timeout(struct cache_detail *detail,
|
|
|
|
struct cache_head *h);
|
2009-08-09 23:14:29 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
extern void cache_clean_deferred(void *owner);
|
|
|
|
|
|
|
|
static inline struct cache_head *cache_get(struct cache_head *h)
|
|
|
|
{
|
2006-03-27 13:15:09 +04:00
|
|
|
kref_get(&h->ref);
|
2005-04-17 02:20:36 +04:00
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2018-10-03 19:01:22 +03: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 02:20:36 +04:00
|
|
|
|
2006-03-27 13:15:09 +04:00
|
|
|
static inline void cache_put(struct cache_head *h, struct cache_detail *cd)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2016-11-14 19:29:48 +03:00
|
|
|
if (kref_read(&h->ref) <= 2 &&
|
2005-04-17 02:20:36 +04:00
|
|
|
h->expiry_time < cd->nextcheck)
|
|
|
|
cd->nextcheck = h->expiry_time;
|
2006-03-27 13:15:09 +04:00
|
|
|
kref_put(&h->ref, cd->cache_put);
|
2005-04-17 02:20:36 +04: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 04:54:42 +03:00
|
|
|
static inline bool cache_is_expired(struct cache_detail *detail, struct cache_head *h)
|
2006-10-04 13:15:50 +04:00
|
|
|
{
|
2020-03-27 18:53:09 +03: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 13:15:50 +04:00
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04: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 19:05:56 +04:00
|
|
|
extern void __init cache_initialize(void);
|
2010-09-27 14:00:15 +04: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 02:20:36 +04:00
|
|
|
|
2017-10-17 19:14:23 +03:00
|
|
|
extern struct cache_detail *cache_create_net(const struct cache_detail *tmpl, struct net *net);
|
2012-01-19 21:42:21 +04:00
|
|
|
extern void cache_destroy_net(struct cache_detail *cd, struct net *net);
|
|
|
|
|
2011-11-25 18:12:40 +04:00
|
|
|
extern void sunrpc_init_cache_detail(struct cache_detail *cd);
|
|
|
|
extern void sunrpc_destroy_cache_detail(struct cache_detail *cd);
|
2009-08-09 23:14:30 +04:00
|
|
|
extern int sunrpc_cache_register_pipefs(struct dentry *parent, const char *,
|
2011-07-25 08:35:13 +04:00
|
|
|
umode_t, struct cache_detail *);
|
2009-08-09 23:14:30 +04:00
|
|
|
extern void sunrpc_cache_unregister_pipefs(struct cache_detail *);
|
2016-12-22 20:38:06 +03:00
|
|
|
extern void sunrpc_cache_unhash(struct cache_detail *, struct cache_head *);
|
2009-08-09 23:14:30 +04:00
|
|
|
|
2015-07-27 06:09:42 +03:00
|
|
|
/* Must store cache_detail in seq_file->private if using next three functions */
|
2018-10-03 19:01:22 +03: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 06:09:42 +03:00
|
|
|
|
2005-04-17 02:20:36 +04: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 19:48:05 +04:00
|
|
|
char *ep;
|
|
|
|
int rv;
|
2012-07-06 23:31:56 +04:00
|
|
|
int len = qword_get(bpp, buf, sizeof(buf));
|
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
if (len == 0)
|
|
|
|
return -ENOENT;
|
|
|
|
|
2012-11-14 19:48:05 +04:00
|
|
|
rv = simple_strtol(buf, &ep, 0);
|
|
|
|
if (*ep)
|
2012-07-06 23:31:56 +04:00
|
|
|
return -EINVAL;
|
|
|
|
|
2012-11-14 19:48:05 +04:00
|
|
|
*anint = rv;
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-13 00:54:16 +04: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 17:34:42 +03:00
|
|
|
static inline int get_time(char **bpp, time64_t *time)
|
2013-08-15 21:46:40 +04: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 17:34:42 +03:00
|
|
|
*time = ll;
|
2013-08-15 21:46:40 +04: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 17:34:42 +03:00
|
|
|
static inline time64_t get_expiry(char **bpp)
|
2005-04-17 02:20:36 +04: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 17:34:42 +03:00
|
|
|
time64_t rv;
|
|
|
|
struct timespec64 boot;
|
2010-08-12 10:55:22 +04:00
|
|
|
|
2013-08-15 21:46:40 +04:00
|
|
|
if (get_time(bpp, &rv))
|
2005-04-17 02:20:36 +04: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 17:34:42 +03:00
|
|
|
getboottime64(&boot);
|
2010-08-12 10:55:22 +04:00
|
|
|
return rv - boot.tv_sec;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _LINUX_SUNRPC_CACHE_H_ */
|