License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 17:07:57 +03:00
// SPDX-License-Identifier: GPL-2.0
2005-04-17 02:20:36 +04:00
/*
* Request reply cache . This is currently a global cache , but this may
* change in the future and be a per - client cache .
*
* This code is heavily inspired by the 44 BSD implementation , although
* it does things a bit differently .
*
* Copyright ( C ) 1995 , 1996 Olaf Kirch < okir @ monad . swb . de >
*/
2019-05-17 16:03:38 +03:00
# include <linux/sunrpc/svc_xprt.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
# include <linux/slab.h>
2016-10-26 14:26:40 +03:00
# include <linux/vmalloc.h>
2013-02-04 21:50:00 +04:00
# include <linux/sunrpc/addr.h>
2013-02-04 17:18:02 +04:00
# include <linux/highmem.h>
2013-03-27 18:15:39 +04:00
# include <linux/log2.h>
# include <linux/hash.h>
2013-02-04 20:57:27 +04:00
# include <net/checksum.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
2009-12-03 21:30:56 +03:00
# include "nfsd.h"
# include "cache.h"
2020-05-02 18:34:40 +03:00
# include "trace.h"
2013-02-04 17:18:02 +04:00
2013-03-27 18:15:39 +04:00
/*
* We use this value to determine the number of hash buckets from the max
* cache size , the idea being that when the cache is at its maximum number
* of entries , then this should be the average number of entries per bucket .
*/
# define TARGET_BUCKET_SIZE 64
2005-04-17 02:20:36 +04:00
2014-08-06 21:44:20 +04:00
struct nfsd_drc_bucket {
2018-10-01 17:41:57 +03:00
struct rb_root rb_head ;
2014-08-06 21:44:21 +04:00
struct list_head lru_head ;
2014-08-06 21:44:24 +04:00
spinlock_t cache_lock ;
2014-08-06 21:44:20 +04:00
} ;
2020-06-02 00:44:45 +03:00
static struct kmem_cache * drc_slab ;
2005-04-17 02:20:36 +04:00
static int nfsd_cache_append ( struct svc_rqst * rqstp , struct kvec * vec ) ;
2013-08-28 04:18:09 +04:00
static unsigned long nfsd_reply_cache_count ( struct shrinker * shrink ,
struct shrink_control * sc ) ;
static unsigned long nfsd_reply_cache_scan ( struct shrinker * shrink ,
struct shrink_control * sc ) ;
2013-02-04 17:18:06 +04:00
2013-02-04 17:18:02 +04:00
/*
* Put a cap on the size of the DRC based on the amount of available
* low memory in the machine .
*
* 64 MB : 8192
* 128 MB : 11585
* 256 MB : 16384
* 512 MB : 23170
* 1 GB : 32768
* 2 GB : 46340
* 4 GB : 65536
* 8 GB : 92681
* 16 GB : 131072
*
* . . . with a hard cap of 256 k entries . In the worst case , each entry will be
* ~ 1 k , so the above numbers should give a rough max of the amount of memory
* used in k .
2019-05-17 16:03:38 +03:00
*
* XXX : these limits are per - container , so memory used will increase
* linearly with number of containers . Maybe that ' s OK .
2013-02-04 17:18:02 +04:00
*/
static unsigned int
nfsd_cache_size_limit ( void )
{
unsigned int limit ;
2018-12-28 11:34:29 +03:00
unsigned long low_pages = totalram_pages ( ) - totalhigh_pages ( ) ;
2013-02-04 17:18:02 +04:00
limit = ( 16 * int_sqrt ( low_pages ) ) < < ( PAGE_SHIFT - 10 ) ;
return min_t ( unsigned int , limit , 256 * 1024 ) ;
}
2013-03-27 18:15:39 +04:00
/*
* Compute the number of hash buckets we need . Divide the max cachesize by
* the " target " max bucket size , and round up to next power of two .
*/
static unsigned int
nfsd_hashsize ( unsigned int limit )
{
return roundup_pow_of_two ( limit / TARGET_BUCKET_SIZE ) ;
}
2023-07-09 18:45:48 +03:00
static struct nfsd_cacherep *
2023-07-09 18:45:22 +03:00
nfsd_cacherep_alloc ( struct svc_rqst * rqstp , __wsum csum ,
struct nfsd_net * nn )
2005-04-17 02:20:36 +04:00
{
2023-07-09 18:45:48 +03:00
struct nfsd_cacherep * rp ;
2005-04-17 02:20:36 +04:00
2020-06-02 00:44:45 +03:00
rp = kmem_cache_alloc ( drc_slab , GFP_KERNEL ) ;
2013-01-28 23:41:11 +04:00
if ( rp ) {
2005-04-17 02:20:36 +04:00
rp - > c_state = RC_UNUSED ;
rp - > c_type = RC_NOCACHE ;
2018-10-01 17:41:57 +03:00
RB_CLEAR_NODE ( & rp - > c_node ) ;
2013-01-28 23:41:11 +04:00
INIT_LIST_HEAD ( & rp - > c_lru ) ;
2018-10-01 17:41:55 +03:00
2018-10-03 20:11:51 +03:00
memset ( & rp - > c_key , 0 , sizeof ( rp - > c_key ) ) ;
rp - > c_key . k_xid = rqstp - > rq_xid ;
rp - > c_key . k_proc = rqstp - > rq_proc ;
rpc_copy_addr ( ( struct sockaddr * ) & rp - > c_key . k_addr , svc_addr ( rqstp ) ) ;
rpc_set_port ( ( struct sockaddr * ) & rp - > c_key . k_addr , rpc_get_port ( svc_addr ( rqstp ) ) ) ;
rp - > c_key . k_prot = rqstp - > rq_prot ;
rp - > c_key . k_vers = rqstp - > rq_vers ;
rp - > c_key . k_len = rqstp - > rq_arg . len ;
rp - > c_key . k_csum = csum ;
2005-04-17 02:20:36 +04:00
}
2013-01-28 23:41:11 +04:00
return rp ;
}
2005-04-17 02:20:36 +04:00
2023-07-09 18:45:48 +03:00
static void nfsd_cacherep_free ( struct nfsd_cacherep * rp )
2023-07-09 18:45:16 +03:00
{
if ( rp - > c_type = = RC_REPLBUFF )
kfree ( rp - > c_replvec . iov_base ) ;
kmem_cache_free ( drc_slab , rp ) ;
}
2023-07-09 18:45:29 +03:00
static unsigned long
nfsd_cacherep_dispose ( struct list_head * dispose )
{
2023-07-09 18:45:48 +03:00
struct nfsd_cacherep * rp ;
2023-07-09 18:45:29 +03:00
unsigned long freed = 0 ;
while ( ! list_empty ( dispose ) ) {
2023-07-09 18:45:48 +03:00
rp = list_first_entry ( dispose , struct nfsd_cacherep , c_lru ) ;
2023-07-09 18:45:29 +03:00
list_del ( & rp - > c_lru ) ;
nfsd_cacherep_free ( rp ) ;
freed + + ;
}
return freed ;
}
2013-01-28 23:41:11 +04:00
static void
2023-07-09 18:45:16 +03:00
nfsd_cacherep_unlink_locked ( struct nfsd_net * nn , struct nfsd_drc_bucket * b ,
2023-07-09 18:45:48 +03:00
struct nfsd_cacherep * rp )
2013-01-28 23:41:11 +04:00
{
2023-07-09 18:45:16 +03:00
if ( rp - > c_type = = RC_REPLBUFF & & rp - > c_replvec . iov_base )
2021-01-06 10:52:35 +03:00
nfsd_stats_drc_mem_usage_sub ( nn , rp - > c_replvec . iov_len ) ;
2018-10-01 17:41:55 +03:00
if ( rp - > c_state ! = RC_UNUSED ) {
2018-10-01 17:41:57 +03:00
rb_erase ( & rp - > c_node , & b - > rb_head ) ;
2018-10-01 17:41:55 +03:00
list_del ( & rp - > c_lru ) ;
2019-05-17 16:03:38 +03:00
atomic_dec ( & nn - > num_drc_entries ) ;
2021-01-06 10:52:35 +03:00
nfsd_stats_drc_mem_usage_sub ( nn , sizeof ( * rp ) ) ;
2018-10-01 17:41:55 +03:00
}
2023-07-09 18:45:16 +03:00
}
static void
2023-07-09 18:45:48 +03:00
nfsd_reply_cache_free_locked ( struct nfsd_drc_bucket * b , struct nfsd_cacherep * rp ,
2023-07-09 18:45:16 +03:00
struct nfsd_net * nn )
{
nfsd_cacherep_unlink_locked ( nn , b , rp ) ;
nfsd_cacherep_free ( rp ) ;
2013-01-28 23:41:11 +04:00
}
2013-02-04 17:18:04 +04:00
static void
2023-07-09 18:45:48 +03:00
nfsd_reply_cache_free ( struct nfsd_drc_bucket * b , struct nfsd_cacherep * rp ,
2019-05-17 16:03:38 +03:00
struct nfsd_net * nn )
2013-02-04 17:18:04 +04:00
{
2014-08-06 21:44:24 +04:00
spin_lock ( & b - > cache_lock ) ;
2023-07-09 18:45:16 +03:00
nfsd_cacherep_unlink_locked ( nn , b , rp ) ;
2014-08-06 21:44:24 +04:00
spin_unlock ( & b - > cache_lock ) ;
2023-07-09 18:45:16 +03:00
nfsd_cacherep_free ( rp ) ;
2013-02-04 17:18:04 +04:00
}
2020-06-02 00:44:45 +03:00
int nfsd_drc_slab_create ( void )
{
drc_slab = kmem_cache_create ( " nfsd_drc " ,
2023-07-09 18:45:48 +03:00
sizeof ( struct nfsd_cacherep ) , 0 , 0 , NULL ) ;
2020-06-02 00:44:45 +03:00
return drc_slab ? 0 : - ENOMEM ;
}
void nfsd_drc_slab_free ( void )
{
kmem_cache_destroy ( drc_slab ) ;
}
2023-06-17 00:51:34 +03:00
/**
* nfsd_net_reply_cache_init - per net namespace reply cache set - up
* @ nn : nfsd_net being initialized
*
* Returns zero on succes ; otherwise a negative errno is returned .
*/
int nfsd_net_reply_cache_init ( struct nfsd_net * nn )
2021-01-06 10:52:35 +03:00
{
return nfsd_percpu_counters_init ( nn - > counter , NFSD_NET_COUNTERS_NUM ) ;
}
2023-06-17 00:51:34 +03:00
/**
* nfsd_net_reply_cache_destroy - per net namespace reply cache tear - down
* @ nn : nfsd_net being freed
*
*/
void nfsd_net_reply_cache_destroy ( struct nfsd_net * nn )
2021-01-06 10:52:35 +03:00
{
nfsd_percpu_counters_destroy ( nn - > counter , NFSD_NET_COUNTERS_NUM ) ;
}
2019-05-17 16:03:38 +03:00
int nfsd_reply_cache_init ( struct nfsd_net * nn )
2013-01-28 23:41:11 +04:00
{
2013-03-27 18:15:39 +04:00
unsigned int hashsize ;
2014-08-06 21:44:21 +04:00
unsigned int i ;
2015-03-19 14:48:31 +03:00
int status = 0 ;
2013-03-27 18:15:39 +04:00
2019-05-17 16:03:38 +03:00
nn - > max_drc_entries = nfsd_cache_size_limit ( ) ;
atomic_set ( & nn - > num_drc_entries , 0 ) ;
hashsize = nfsd_hashsize ( nn - > max_drc_entries ) ;
nn - > maskbits = ilog2 ( hashsize ) ;
2013-03-15 17:16:29 +04:00
2019-05-17 16:03:38 +03:00
nn - > nfsd_reply_cache_shrinker . scan_objects = nfsd_reply_cache_scan ;
nn - > nfsd_reply_cache_shrinker . count_objects = nfsd_reply_cache_count ;
nn - > nfsd_reply_cache_shrinker . seeks = 1 ;
2022-06-01 06:22:24 +03:00
status = register_shrinker ( & nn - > nfsd_reply_cache_shrinker ,
" nfsd-reply:%s " , nn - > nfsd_name ) ;
2015-03-19 14:48:31 +03:00
if ( status )
2023-06-17 00:51:34 +03:00
return status ;
2015-03-19 14:48:31 +03:00
2020-09-14 20:07:19 +03:00
nn - > drc_hashtbl = kvzalloc ( array_size ( hashsize ,
sizeof ( * nn - > drc_hashtbl ) ) , GFP_KERNEL ) ;
if ( ! nn - > drc_hashtbl )
goto out_shrinker ;
2016-10-26 14:26:40 +03:00
2014-08-06 21:44:24 +04:00
for ( i = 0 ; i < hashsize ; i + + ) {
2019-05-17 16:03:38 +03:00
INIT_LIST_HEAD ( & nn - > drc_hashtbl [ i ] . lru_head ) ;
spin_lock_init ( & nn - > drc_hashtbl [ i ] . cache_lock ) ;
2014-08-06 21:44:24 +04:00
}
2019-05-17 16:03:38 +03:00
nn - > drc_hashsize = hashsize ;
2005-04-17 02:20:36 +04:00
2007-11-09 22:10:56 +03:00
return 0 ;
2019-06-06 01:03:52 +03:00
out_shrinker :
unregister_shrinker ( & nn - > nfsd_reply_cache_shrinker ) ;
2007-11-09 22:10:56 +03:00
printk ( KERN_ERR " nfsd: failed to allocate reply cache \n " ) ;
return - ENOMEM ;
2005-04-17 02:20:36 +04:00
}
2019-05-17 16:03:38 +03:00
void nfsd_reply_cache_shutdown ( struct nfsd_net * nn )
2005-04-17 02:20:36 +04:00
{
2023-07-09 18:45:48 +03:00
struct nfsd_cacherep * rp ;
2014-08-06 21:44:21 +04:00
unsigned int i ;
2005-04-17 02:20:36 +04:00
2019-05-17 16:03:38 +03:00
unregister_shrinker ( & nn - > nfsd_reply_cache_shrinker ) ;
2013-02-04 17:18:05 +04:00
2019-05-17 16:03:38 +03:00
for ( i = 0 ; i < nn - > drc_hashsize ; i + + ) {
struct list_head * head = & nn - > drc_hashtbl [ i ] . lru_head ;
2014-08-06 21:44:21 +04:00
while ( ! list_empty ( head ) ) {
2023-07-09 18:45:48 +03:00
rp = list_first_entry ( head , struct nfsd_cacherep , c_lru ) ;
2019-05-17 16:03:38 +03:00
nfsd_reply_cache_free_locked ( & nn - > drc_hashtbl [ i ] ,
rp , nn ) ;
2014-08-06 21:44:21 +04:00
}
2005-04-17 02:20:36 +04:00
}
2019-05-17 16:03:38 +03:00
kvfree ( nn - > drc_hashtbl ) ;
nn - > drc_hashtbl = NULL ;
nn - > drc_hashsize = 0 ;
2013-01-28 23:41:10 +04:00
2005-04-17 02:20:36 +04:00
}
/*
2013-02-04 17:18:05 +04:00
* Move cache entry to end of LRU list , and queue the cleaner to run if it ' s
* not already scheduled .
2005-04-17 02:20:36 +04:00
*/
static void
2023-07-09 18:45:48 +03:00
lru_put_end ( struct nfsd_drc_bucket * b , struct nfsd_cacherep * rp )
2005-04-17 02:20:36 +04:00
{
2013-02-04 17:18:00 +04:00
rp - > c_timestamp = jiffies ;
2014-08-06 21:44:21 +04:00
list_move_tail ( & rp - > c_lru , & b - > lru_head ) ;
2005-04-17 02:20:36 +04:00
}
2021-10-01 02:19:57 +03:00
static noinline struct nfsd_drc_bucket *
nfsd_cache_bucket_find ( __be32 xid , struct nfsd_net * nn )
{
unsigned int hash = hash_32 ( ( __force u32 ) xid , nn - > maskbits ) ;
return & nn - > drc_hashtbl [ hash ] ;
}
2023-07-09 18:45:29 +03:00
/*
* Remove and return no more than @ max expired entries in bucket @ b .
* If @ max is zero , do not limit the number of removed entries .
*/
static void
nfsd_prune_bucket_locked ( struct nfsd_net * nn , struct nfsd_drc_bucket * b ,
unsigned int max , struct list_head * dispose )
{
unsigned long expiry = jiffies - RC_EXPIRE ;
2023-07-09 18:45:48 +03:00
struct nfsd_cacherep * rp , * tmp ;
2023-07-09 18:45:29 +03:00
unsigned int freed = 0 ;
lockdep_assert_held ( & b - > cache_lock ) ;
/* The bucket LRU is ordered oldest-first. */
list_for_each_entry_safe ( rp , tmp , & b - > lru_head , c_lru ) {
/*
* Don ' t free entries attached to calls that are still
* in - progress , but do keep scanning the list .
*/
if ( rp - > c_state = = RC_INPROG )
continue ;
if ( atomic_read ( & nn - > num_drc_entries ) < = nn - > max_drc_entries & &
time_before ( expiry , rp - > c_timestamp ) )
break ;
nfsd_cacherep_unlink_locked ( nn , b , rp ) ;
list_add ( & rp - > c_lru , dispose ) ;
if ( max & & + + freed > max )
break ;
}
}
2023-07-09 18:45:35 +03:00
/**
* nfsd_reply_cache_count - count_objects method for the DRC shrinker
* @ shrink : our registered shrinker context
* @ sc : garbage collection parameters
*
* Returns the total number of entries in the duplicate reply cache . To
* keep things simple and quick , this is not the number of expired entries
* in the cache ( ie , the number that would be removed by a call to
* nfsd_reply_cache_scan ) .
*/
static unsigned long
nfsd_reply_cache_count ( struct shrinker * shrink , struct shrink_control * sc )
2013-02-04 17:18:05 +04:00
{
2023-07-09 18:45:35 +03:00
struct nfsd_net * nn = container_of ( shrink ,
struct nfsd_net , nfsd_reply_cache_shrinker ) ;
2013-02-04 17:18:05 +04:00
2023-07-09 18:45:35 +03:00
return atomic_read ( & nn - > num_drc_entries ) ;
2014-08-06 21:44:21 +04:00
}
2023-07-09 18:45:35 +03:00
/**
* nfsd_reply_cache_scan - scan_objects method for the DRC shrinker
* @ shrink : our registered shrinker context
* @ sc : garbage collection parameters
*
* Free expired entries on each bucket ' s LRU list until we ' ve released
* nr_to_scan freed objects . Nothing will be released if the cache
* has not exceeded it ' s max_drc_entries limit .
*
* Returns the number of entries released by this call .
2014-08-06 21:44:21 +04:00
*/
2023-07-09 18:45:35 +03:00
static unsigned long
nfsd_reply_cache_scan ( struct shrinker * shrink , struct shrink_control * sc )
2014-08-06 21:44:21 +04:00
{
2023-07-09 18:45:35 +03:00
struct nfsd_net * nn = container_of ( shrink ,
struct nfsd_net , nfsd_reply_cache_shrinker ) ;
unsigned long freed = 0 ;
LIST_HEAD ( dispose ) ;
2014-08-06 21:44:21 +04:00
unsigned int i ;
2019-05-17 16:03:38 +03:00
for ( i = 0 ; i < nn - > drc_hashsize ; i + + ) {
struct nfsd_drc_bucket * b = & nn - > drc_hashtbl [ i ] ;
2014-08-06 21:44:21 +04:00
2014-08-06 21:44:24 +04:00
if ( list_empty ( & b - > lru_head ) )
continue ;
2023-07-09 18:45:35 +03:00
2014-08-06 21:44:24 +04:00
spin_lock ( & b - > cache_lock ) ;
2023-07-09 18:45:35 +03:00
nfsd_prune_bucket_locked ( nn , b , 0 , & dispose ) ;
2014-08-06 21:44:24 +04:00
spin_unlock ( & b - > cache_lock ) ;
2013-02-04 17:18:05 +04:00
2023-07-09 18:45:35 +03:00
freed + = nfsd_cacherep_dispose ( & dispose ) ;
if ( freed > sc - > nr_to_scan )
break ;
}
2019-05-17 16:03:38 +03:00
2023-07-09 18:45:35 +03:00
trace_nfsd_drc_gc ( nn , freed ) ;
return freed ;
2013-02-04 17:18:06 +04:00
}
2013-02-04 20:57:27 +04:00
/*
* Walk an xdr_buf and get a CRC for at most the first RC_CSUMLEN bytes
*/
static __wsum
nfsd_cache_csum ( struct svc_rqst * rqstp )
{
int idx ;
unsigned int base ;
__wsum csum ;
struct xdr_buf * buf = & rqstp - > rq_arg ;
const unsigned char * p = buf - > head [ 0 ] . iov_base ;
size_t csum_len = min_t ( size_t , buf - > head [ 0 ] . iov_len + buf - > page_len ,
RC_CSUMLEN ) ;
size_t len = min ( buf - > head [ 0 ] . iov_len , csum_len ) ;
/* rq_arg.head first */
csum = csum_partial ( p , len , 0 ) ;
csum_len - = len ;
/* Continue into page array */
idx = buf - > page_base / PAGE_SIZE ;
base = buf - > page_base & ~ PAGE_MASK ;
while ( csum_len ) {
p = page_address ( buf - > pages [ idx ] ) + base ;
2013-02-15 22:36:34 +04:00
len = min_t ( size_t , PAGE_SIZE - base , csum_len ) ;
2013-02-04 20:57:27 +04:00
csum = csum_partial ( p , len , csum ) ;
csum_len - = len ;
base = 0 ;
+ + idx ;
}
return csum ;
}
2018-10-03 20:11:51 +03:00
static int
2023-07-09 18:45:48 +03:00
nfsd_cache_key_cmp ( const struct nfsd_cacherep * key ,
const struct nfsd_cacherep * rp , struct nfsd_net * nn )
2013-03-27 18:15:37 +04:00
{
2018-10-03 20:11:51 +03:00
if ( key - > c_key . k_xid = = rp - > c_key . k_xid & &
2020-05-02 18:34:40 +03:00
key - > c_key . k_csum ! = rp - > c_key . k_csum ) {
2021-01-06 10:52:35 +03:00
nfsd_stats_payload_misses_inc ( nn ) ;
2020-05-02 18:34:40 +03:00
trace_nfsd_drc_mismatch ( nn , key , rp ) ;
}
2014-08-06 21:44:25 +04:00
2018-10-03 20:11:51 +03:00
return memcmp ( & key - > c_key , & rp - > c_key , sizeof ( key - > c_key ) ) ;
2013-03-27 18:15:37 +04:00
}
2013-01-28 23:41:14 +04:00
/*
* Search the request hash for an entry that matches the given rqstp .
* Must be called with cache_lock held . Returns the found entry or
2018-10-01 17:41:55 +03:00
* inserts an empty key on failure .
2013-01-28 23:41:14 +04:00
*/
2023-07-09 18:45:48 +03:00
static struct nfsd_cacherep *
nfsd_cache_insert ( struct nfsd_drc_bucket * b , struct nfsd_cacherep * key ,
2019-05-17 16:03:38 +03:00
struct nfsd_net * nn )
2013-01-28 23:41:14 +04:00
{
2023-07-09 18:45:48 +03:00
struct nfsd_cacherep * rp , * ret = key ;
2018-10-01 17:41:57 +03:00
struct rb_node * * p = & b - > rb_head . rb_node ,
* parent = NULL ;
2013-03-27 18:15:39 +04:00
unsigned int entries = 0 ;
2018-10-01 17:41:57 +03:00
int cmp ;
2013-01-28 23:41:14 +04:00
2018-10-01 17:41:57 +03:00
while ( * p ! = NULL ) {
2013-03-27 18:15:39 +04:00
+ + entries ;
2018-10-01 17:41:57 +03:00
parent = * p ;
2023-07-09 18:45:48 +03:00
rp = rb_entry ( parent , struct nfsd_cacherep , c_node ) ;
2018-10-01 17:41:57 +03:00
2019-05-17 16:03:38 +03:00
cmp = nfsd_cache_key_cmp ( key , rp , nn ) ;
2018-10-01 17:41:57 +03:00
if ( cmp < 0 )
p = & parent - > rb_left ;
else if ( cmp > 0 )
p = & parent - > rb_right ;
else {
2013-03-27 18:15:39 +04:00
ret = rp ;
2018-10-01 17:41:57 +03:00
goto out ;
2013-03-27 18:15:39 +04:00
}
}
2018-10-01 17:41:57 +03:00
rb_link_node ( & key - > c_node , parent , p ) ;
rb_insert_color ( & key - > c_node , & b - > rb_head ) ;
out :
2013-03-27 18:15:39 +04:00
/* tally hash chain length stats */
2019-05-17 16:03:38 +03:00
if ( entries > nn - > longest_chain ) {
nn - > longest_chain = entries ;
nn - > longest_chain_cachesize = atomic_read ( & nn - > num_drc_entries ) ;
} else if ( entries = = nn - > longest_chain ) {
2013-03-27 18:15:39 +04:00
/* prefer to keep the smallest cachesize possible here */
2019-05-17 16:03:38 +03:00
nn - > longest_chain_cachesize = min_t ( unsigned int ,
nn - > longest_chain_cachesize ,
atomic_read ( & nn - > num_drc_entries ) ) ;
2013-01-28 23:41:14 +04:00
}
2013-03-27 18:15:39 +04:00
2018-10-01 17:41:55 +03:00
lru_put_end ( b , ret ) ;
2013-03-27 18:15:39 +04:00
return ret ;
2013-01-28 23:41:14 +04:00
}
2020-05-02 18:34:40 +03:00
/**
* nfsd_cache_lookup - Find an entry in the duplicate reply cache
* @ rqstp : Incoming Call to find
2023-07-09 18:45:41 +03:00
* @ cacherep : OUT : DRC entry for this request
2020-05-02 18:34:40 +03:00
*
2005-04-17 02:20:36 +04:00
* Try to find an entry matching the current call in the cache . When none
2013-02-15 01:45:13 +04:00
* is found , we try to grab the oldest expired entry off the LRU list . If
* a suitable one isn ' t there , then drop the cache_lock and allocate a
* new one , then search again in case one got inserted while this thread
* didn ' t hold the lock .
2020-05-02 18:34:40 +03:00
*
* Return values :
* % RC_DOIT : Process the request normally
* % RC_REPLY : Reply from cache
* % RC_DROPIT : Do not process the request further
2005-04-17 02:20:36 +04:00
*/
2023-07-09 18:45:48 +03:00
int nfsd_cache_lookup ( struct svc_rqst * rqstp , struct nfsd_cacherep * * cacherep )
2005-04-17 02:20:36 +04:00
{
2021-09-28 18:39:02 +03:00
struct nfsd_net * nn ;
2023-07-09 18:45:48 +03:00
struct nfsd_cacherep * rp , * found ;
2013-02-04 20:57:27 +04:00
__wsum csum ;
2021-09-28 18:39:02 +03:00
struct nfsd_drc_bucket * b ;
2011-01-24 20:11:02 +03:00
int type = rqstp - > rq_cachetype ;
2023-07-09 18:45:29 +03:00
unsigned long freed ;
LIST_HEAD ( dispose ) ;
2013-03-27 18:15:37 +04:00
int rtn = RC_DOIT ;
2005-04-17 02:20:36 +04:00
2013-02-04 17:18:03 +04:00
if ( type = = RC_NOCACHE ) {
2021-01-06 10:52:35 +03:00
nfsd_stats_rc_nocache_inc ( ) ;
2020-05-02 18:34:40 +03:00
goto out ;
2005-04-17 02:20:36 +04:00
}
2013-02-04 20:57:27 +04:00
csum = nfsd_cache_csum ( rqstp ) ;
2013-03-27 18:15:37 +04:00
/*
* Since the common case is a cache miss followed by an insert ,
2013-12-05 15:00:51 +04:00
* preallocate an entry .
2013-03-27 18:15:37 +04:00
*/
2021-09-28 18:39:02 +03:00
nn = net_generic ( SVC_NET ( rqstp ) , nfsd_net_id ) ;
2023-07-09 18:45:22 +03:00
rp = nfsd_cacherep_alloc ( rqstp , csum , nn ) ;
2020-05-02 18:34:40 +03:00
if ( ! rp )
goto out ;
2013-02-04 17:18:02 +04:00
2021-09-28 18:39:02 +03:00
b = nfsd_cache_bucket_find ( rqstp - > rq_xid , nn ) ;
2018-10-01 17:41:55 +03:00
spin_lock ( & b - > cache_lock ) ;
2019-05-17 16:03:38 +03:00
found = nfsd_cache_insert ( b , rp , nn ) ;
2021-09-28 18:40:59 +03:00
if ( found ! = rp )
2013-02-04 17:18:02 +04:00
goto found_entry ;
2023-07-09 18:45:41 +03:00
* cacherep = rp ;
2005-04-17 02:20:36 +04:00
rp - > c_state = RC_INPROG ;
2023-07-09 18:45:29 +03:00
nfsd_prune_bucket_locked ( nn , b , 3 , & dispose ) ;
spin_unlock ( & b - > cache_lock ) ;
2018-10-01 17:41:55 +03:00
2023-07-09 18:45:29 +03:00
freed = nfsd_cacherep_dispose ( & dispose ) ;
trace_nfsd_drc_gc ( nn , freed ) ;
nfsd_stats_rc_misses_inc ( ) ;
2019-05-17 16:03:38 +03:00
atomic_inc ( & nn - > num_drc_entries ) ;
2021-01-06 10:52:35 +03:00
nfsd_stats_drc_mem_usage_add ( nn , sizeof ( * rp ) ) ;
2023-07-09 18:45:29 +03:00
goto out ;
2005-04-17 02:20:36 +04:00
found_entry :
/* We found a matching entry which is either in progress or done. */
2021-09-28 18:40:59 +03:00
nfsd_reply_cache_free_locked ( NULL , rp , nn ) ;
2021-01-06 10:52:35 +03:00
nfsd_stats_rc_hits_inc ( ) ;
2005-04-17 02:20:36 +04:00
rtn = RC_DROPIT ;
2021-09-28 18:40:59 +03:00
rp = found ;
2018-10-01 17:41:55 +03:00
2018-03-28 19:18:01 +03:00
/* Request being processed */
if ( rp - > c_state = = RC_INPROG )
2020-05-02 18:34:40 +03:00
goto out_trace ;
2005-04-17 02:20:36 +04:00
/* From the hall of fame of impractical attacks:
* Is this a user who tries to snoop on the cache ? */
rtn = RC_DOIT ;
2014-11-19 15:51:14 +03:00
if ( ! test_bit ( RQ_SECURE , & rqstp - > rq_flags ) & & rp - > c_secure )
2020-05-02 18:34:40 +03:00
goto out_trace ;
2005-04-17 02:20:36 +04:00
/* Compose RPC reply header */
switch ( rp - > c_type ) {
case RC_NOCACHE :
break ;
case RC_REPLSTAT :
2023-01-08 19:29:44 +03:00
xdr_stream_encode_be32 ( & rqstp - > rq_res_stream , rp - > c_replstat ) ;
2005-04-17 02:20:36 +04:00
rtn = RC_REPLY ;
break ;
case RC_REPLBUFF :
if ( ! nfsd_cache_append ( rqstp , & rp - > c_replvec ) )
2020-05-02 18:34:40 +03:00
goto out_unlock ; /* should not happen */
2005-04-17 02:20:36 +04:00
rtn = RC_REPLY ;
break ;
default :
2020-06-03 18:12:32 +03:00
WARN_ONCE ( 1 , " nfsd: bad repcache type %d \n " , rp - > c_type ) ;
2005-04-17 02:20:36 +04:00
}
2020-05-02 18:34:40 +03:00
out_trace :
trace_nfsd_drc_found ( nn , rqstp , rtn ) ;
2023-07-09 18:45:29 +03:00
out_unlock :
spin_unlock ( & b - > cache_lock ) ;
out :
return rtn ;
2005-04-17 02:20:36 +04:00
}
2020-05-02 18:34:40 +03:00
/**
* nfsd_cache_update - Update an entry in the duplicate reply cache .
* @ rqstp : svc_rqst with a finished Reply
2023-07-09 18:45:41 +03:00
* @ rp : IN : DRC entry for this request
2020-05-02 18:34:40 +03:00
* @ cachetype : which cache to update
2023-01-08 19:30:59 +03:00
* @ statp : pointer to Reply ' s NFS status code , or NULL
2020-05-02 18:34:40 +03:00
*
* This is called from nfsd_dispatch when the procedure has been
* executed and the complete reply is in rqstp - > rq_res .
2005-04-17 02:20:36 +04:00
*
* We ' re copying around data here rather than swapping buffers because
* the toplevel loop requires max - sized buffers , which would be a waste
* of memory for a cache with a max reply size of 100 bytes ( diropokres ) .
*
* If we should start to use different types of cache entries tailored
* specifically for attrstat and fh ' s , we may save even more space .
*
* Also note that a cachetype of RC_NOCACHE can legally be passed when
* nfsd failed to encode a reply that otherwise would have been cached .
* In this case , nfsd_cache_update is called with statp = = NULL .
*/
2023-07-09 18:45:48 +03:00
void nfsd_cache_update ( struct svc_rqst * rqstp , struct nfsd_cacherep * rp ,
2023-07-09 18:45:41 +03:00
int cachetype , __be32 * statp )
2005-04-17 02:20:36 +04:00
{
2019-05-17 16:03:38 +03:00
struct nfsd_net * nn = net_generic ( SVC_NET ( rqstp ) , nfsd_net_id ) ;
2005-04-17 02:20:36 +04:00
struct kvec * resv = & rqstp - > rq_res . head [ 0 ] , * cachv ;
2014-08-06 21:44:21 +04:00
struct nfsd_drc_bucket * b ;
2005-04-17 02:20:36 +04:00
int len ;
2013-03-27 18:15:38 +04:00
size_t bufsize = 0 ;
2005-04-17 02:20:36 +04:00
2013-02-04 17:18:03 +04:00
if ( ! rp )
2005-04-17 02:20:36 +04:00
return ;
2021-10-01 02:19:57 +03:00
b = nfsd_cache_bucket_find ( rp - > c_key . k_xid , nn ) ;
2014-08-06 21:44:21 +04:00
2005-04-17 02:20:36 +04:00
len = resv - > iov_len - ( ( char * ) statp - ( char * ) resv - > iov_base ) ;
len > > = 2 ;
2009-04-01 00:28:13 +04:00
2005-04-17 02:20:36 +04:00
/* Don't cache excessive amounts of data and XDR failures */
if ( ! statp | | len > ( 256 > > 2 ) ) {
2019-05-17 16:03:38 +03:00
nfsd_reply_cache_free ( b , rp , nn ) ;
2005-04-17 02:20:36 +04:00
return ;
}
switch ( cachetype ) {
case RC_REPLSTAT :
if ( len ! = 1 )
printk ( " nfsd: RC_REPLSTAT/reply len %d! \n " , len ) ;
rp - > c_replstat = * statp ;
break ;
case RC_REPLBUFF :
cachv = & rp - > c_replvec ;
2013-03-27 18:15:38 +04:00
bufsize = len < < 2 ;
cachv - > iov_base = kmalloc ( bufsize , GFP_KERNEL ) ;
2005-04-17 02:20:36 +04:00
if ( ! cachv - > iov_base ) {
2019-05-17 16:03:38 +03:00
nfsd_reply_cache_free ( b , rp , nn ) ;
2005-04-17 02:20:36 +04:00
return ;
}
2013-03-27 18:15:38 +04:00
cachv - > iov_len = bufsize ;
memcpy ( cachv - > iov_base , statp , bufsize ) ;
2005-04-17 02:20:36 +04:00
break ;
2013-02-04 17:18:04 +04:00
case RC_NOCACHE :
2019-05-17 16:03:38 +03:00
nfsd_reply_cache_free ( b , rp , nn ) ;
2013-02-04 17:18:04 +04:00
return ;
2005-04-17 02:20:36 +04:00
}
2014-08-06 21:44:24 +04:00
spin_lock ( & b - > cache_lock ) ;
2021-01-06 10:52:35 +03:00
nfsd_stats_drc_mem_usage_add ( nn , bufsize ) ;
2014-08-06 21:44:21 +04:00
lru_put_end ( b , rp ) ;
2014-11-19 15:51:14 +03:00
rp - > c_secure = test_bit ( RQ_SECURE , & rqstp - > rq_flags ) ;
2005-04-17 02:20:36 +04:00
rp - > c_type = cachetype ;
rp - > c_state = RC_DONE ;
2014-08-06 21:44:24 +04:00
spin_unlock ( & b - > cache_lock ) ;
2005-04-17 02:20:36 +04:00
return ;
}
/*
* Copy cached reply to current reply buffer . Should always fit .
* FIXME as reply is in a page , we should just attach the page , and
* keep a refcount . . . .
*/
static int
nfsd_cache_append ( struct svc_rqst * rqstp , struct kvec * data )
{
struct kvec * vec = & rqstp - > rq_res . head [ 0 ] ;
if ( vec - > iov_len + data - > iov_len > PAGE_SIZE ) {
2017-02-28 01:30:02 +03:00
printk ( KERN_WARNING " nfsd: cached reply too large (%zd). \n " ,
2005-04-17 02:20:36 +04:00
data - > iov_len ) ;
return 0 ;
}
memcpy ( ( char * ) vec - > iov_base + vec - > iov_len , data - > iov_base , data - > iov_len ) ;
vec - > iov_len + = data - > iov_len ;
return 1 ;
}
2013-03-27 18:15:38 +04:00
/*
* Note that fields may be added , removed or reordered in the future . Programs
* scraping this file for info should test the labels to ensure they ' re
* getting the correct field .
*/
2022-09-22 19:31:55 +03:00
int nfsd_reply_cache_stats_show ( struct seq_file * m , void * v )
2013-03-27 18:15:38 +04:00
{
2022-09-22 19:31:55 +03:00
struct nfsd_net * nn = net_generic ( file_inode ( m - > file ) - > i_sb - > s_fs_info ,
nfsd_net_id ) ;
2019-05-17 16:03:38 +03:00
seq_printf ( m , " max entries: %u \n " , nn - > max_drc_entries ) ;
2014-08-06 21:44:23 +04:00
seq_printf ( m , " num entries: %u \n " ,
2021-01-06 10:52:35 +03:00
atomic_read ( & nn - > num_drc_entries ) ) ;
2019-05-17 16:03:38 +03:00
seq_printf ( m , " hash buckets: %u \n " , 1 < < nn - > maskbits ) ;
2021-01-06 10:52:35 +03:00
seq_printf ( m , " mem usage: %lld \n " ,
percpu_counter_sum_positive ( & nn - > counter [ NFSD_NET_DRC_MEM_USAGE ] ) ) ;
seq_printf ( m , " cache hits: %lld \n " ,
percpu_counter_sum_positive ( & nfsdstats . counter [ NFSD_STATS_RC_HITS ] ) ) ;
seq_printf ( m , " cache misses: %lld \n " ,
percpu_counter_sum_positive ( & nfsdstats . counter [ NFSD_STATS_RC_MISSES ] ) ) ;
seq_printf ( m , " not cached: %lld \n " ,
percpu_counter_sum_positive ( & nfsdstats . counter [ NFSD_STATS_RC_NOCACHE ] ) ) ;
seq_printf ( m , " payload misses: %lld \n " ,
percpu_counter_sum_positive ( & nn - > counter [ NFSD_NET_PAYLOAD_MISSES ] ) ) ;
2019-05-17 16:03:38 +03:00
seq_printf ( m , " longest chain len: %u \n " , nn - > longest_chain ) ;
seq_printf ( m , " cachesize at longest: %u \n " , nn - > longest_chain_cachesize ) ;
2013-03-27 18:15:38 +04:00
return 0 ;
}