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 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* NFS exporting and validation.
|
|
|
|
*
|
|
|
|
* We maintain a list of clients, each of which has a list of
|
|
|
|
* exports. To export an fs to a given client, you first have
|
|
|
|
* to create the client entry with NFSCTL_ADDCLIENT, which
|
|
|
|
* creates a client control block and adds it to the hash
|
|
|
|
* table. Then, you call NFSCTL_EXPORT for each fs.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995, 1996 Olaf Kirch, <okir@monad.swb.de>
|
|
|
|
*/
|
|
|
|
|
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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/namei.h>
|
2005-09-06 22:17:08 +00:00
|
|
|
#include <linux/module.h>
|
2007-07-17 11:04:28 +00:00
|
|
|
#include <linux/exportfs.h>
|
2012-04-11 11:13:21 +00:00
|
|
|
#include <linux/sunrpc/svc_xprt.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-12-03 18:30:56 +00:00
|
|
|
#include "nfsd.h"
|
2009-12-05 00:36:06 +00:00
|
|
|
#include "nfsfh.h"
|
2012-04-11 11:13:21 +00:00
|
|
|
#include "netns.h"
|
nfsd: implement pNFS operations
Add support for the GETDEVICEINFO, LAYOUTGET, LAYOUTCOMMIT and
LAYOUTRETURN NFSv4.1 operations, as well as backing code to manage
outstanding layouts and devices.
Layout management is very straight forward, with a nfs4_layout_stateid
structure that extends nfs4_stid to manage layout stateids as the
top-level structure. It is linked into the nfs4_file and nfs4_client
structures like the other stateids, and contains a linked list of
layouts that hang of the stateid. The actual layout operations are
implemented in layout drivers that are not part of this commit, but
will be added later.
The worst part of this commit is the management of the pNFS device IDs,
which suffers from a specification that is not sanely implementable due
to the fact that the device-IDs are global and not bound to an export,
and have a small enough size so that we can't store the fsid portion of
a file handle, and must never be reused. As we still do need perform all
export authentication and validation checks on a device ID passed to
GETDEVICEINFO we are caught between a rock and a hard place. To work
around this issue we add a new hash that maps from a 64-bit integer to a
fsid so that we can look up the export to authenticate against it,
a 32-bit integer as a generation that we can bump when changing the device,
and a currently unused 32-bit integer that could be used in the future
to handle more than a single device per export. Entries in this hash
table are never deleted as we can't reuse the ids anyway, and would have
a severe lifetime problem anyway as Linux export structures are temporary
structures that can go away under load.
Parts of the XDR data, structures and marshaling/unmarshaling code, as
well as many concepts are derived from the old pNFS server implementation
from Andy Adamson, Benny Halevy, Dean Hildebrand, Marc Eshel, Fred Isaman,
Mike Sager, Ricardo Labiaga and many others.
Signed-off-by: Christoph Hellwig <hch@lst.de>
2014-05-05 11:11:59 +00:00
|
|
|
#include "pnfs.h"
|
2019-08-18 18:18:48 +00:00
|
|
|
#include "filecache.h"
|
2020-03-01 23:21:40 +00:00
|
|
|
#include "trace.h"
|
2009-12-03 18:30:56 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#define NFSDDBG_FACILITY NFSDDBG_EXPORT
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have two caches.
|
|
|
|
* One maps client+vfsmnt+dentry to export options - the export map
|
|
|
|
* The other maps client+filehandle-fragment to export options. - the expkey map
|
|
|
|
*
|
|
|
|
* The export options are actually stored in the first map, and the
|
|
|
|
* second map contains a reference to the entry in the first map.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define EXPKEY_HASHBITS 8
|
|
|
|
#define EXPKEY_HASHMAX (1 << EXPKEY_HASHBITS)
|
|
|
|
#define EXPKEY_HASHMASK (EXPKEY_HASHMAX -1)
|
|
|
|
|
2006-03-27 09:15:10 +00:00
|
|
|
static void expkey_put(struct kref *ref)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-03-27 09:15:09 +00:00
|
|
|
struct svc_expkey *key = container_of(ref, struct svc_expkey, h.ref);
|
|
|
|
|
|
|
|
if (test_bit(CACHE_VALID, &key->h.flags) &&
|
2008-02-15 03:38:41 +00:00
|
|
|
!test_bit(CACHE_NEGATIVE, &key->h.flags))
|
|
|
|
path_put(&key->ek_path);
|
2006-03-27 09:15:09 +00:00
|
|
|
auth_domain_put(key->ek_client);
|
2018-10-01 14:41:47 +00:00
|
|
|
kfree_rcu(key, ek_rcu);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2020-03-01 23:21:42 +00:00
|
|
|
static int expkey_upcall(struct cache_detail *cd, struct cache_head *h)
|
|
|
|
{
|
|
|
|
return sunrpc_cache_pipe_upcall(cd, h);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static void expkey_request(struct cache_detail *cd,
|
|
|
|
struct cache_head *h,
|
|
|
|
char **bpp, int *blen)
|
|
|
|
{
|
|
|
|
/* client fsidtype \xfsid */
|
|
|
|
struct svc_expkey *ek = container_of(h, struct svc_expkey, h);
|
|
|
|
char type[5];
|
|
|
|
|
|
|
|
qword_add(bpp, blen, ek->ek_client->name);
|
|
|
|
snprintf(type, 5, "%d", ek->ek_fsidtype);
|
|
|
|
qword_add(bpp, blen, type);
|
|
|
|
qword_addhex(bpp, blen, (char*)ek->ek_fsid, key_len(ek->ek_fsidtype));
|
|
|
|
(*bpp)[-1] = '\n';
|
|
|
|
}
|
|
|
|
|
2012-03-28 15:09:50 +00:00
|
|
|
static struct svc_expkey *svc_expkey_update(struct cache_detail *cd, struct svc_expkey *new,
|
|
|
|
struct svc_expkey *old);
|
|
|
|
static struct svc_expkey *svc_expkey_lookup(struct cache_detail *cd, struct svc_expkey *);
|
2006-03-27 09:15:10 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
|
|
|
|
{
|
2014-05-23 12:56:16 +00:00
|
|
|
/* client fsidtype fsid expiry [path] */
|
2005-04-16 22:20:36 +00:00
|
|
|
char *buf;
|
|
|
|
int len;
|
|
|
|
struct auth_domain *dom = NULL;
|
|
|
|
int err;
|
|
|
|
int fsidtype;
|
|
|
|
char *ep;
|
|
|
|
struct svc_expkey key;
|
2008-10-20 20:34:21 +00:00
|
|
|
struct svc_expkey *ek = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-01-20 07:48:18 +00:00
|
|
|
if (mesg[mlen - 1] != '\n')
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
mesg[mlen-1] = 0;
|
|
|
|
|
|
|
|
buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
|
|
|
err = -ENOMEM;
|
2008-10-20 20:34:21 +00:00
|
|
|
if (!buf)
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err = -EINVAL;
|
2023-06-21 14:52:05 +00:00
|
|
|
if (qword_get(&mesg, buf, PAGE_SIZE) <= 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = -ENOENT;
|
|
|
|
dom = auth_domain_find(buf);
|
|
|
|
if (!dom)
|
|
|
|
goto out;
|
|
|
|
dprintk("found domain %s\n", buf);
|
|
|
|
|
|
|
|
err = -EINVAL;
|
2023-06-21 14:52:05 +00:00
|
|
|
if (qword_get(&mesg, buf, PAGE_SIZE) <= 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
fsidtype = simple_strtoul(buf, &ep, 10);
|
|
|
|
if (*ep)
|
|
|
|
goto out;
|
|
|
|
dprintk("found fsidtype %d\n", fsidtype);
|
2006-06-30 08:56:11 +00:00
|
|
|
if (key_len(fsidtype)==0) /* invalid type */
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
if ((len=qword_get(&mesg, buf, PAGE_SIZE)) <= 0)
|
|
|
|
goto out;
|
|
|
|
dprintk("found fsid length %d\n", len);
|
|
|
|
if (len != key_len(fsidtype))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* OK, we seem to have a valid key */
|
|
|
|
key.h.flags = 0;
|
2023-03-08 06:51:00 +00:00
|
|
|
err = get_expiry(&mesg, &key.h.expiry_time);
|
|
|
|
if (err)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
|
2023-03-08 06:51:00 +00:00
|
|
|
key.ek_client = dom;
|
2005-04-16 22:20:36 +00:00
|
|
|
key.ek_fsidtype = fsidtype;
|
|
|
|
memcpy(key.ek_fsid, buf, len);
|
|
|
|
|
2012-03-28 15:09:50 +00:00
|
|
|
ek = svc_expkey_lookup(cd, &key);
|
2006-03-27 09:15:04 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
if (!ek)
|
|
|
|
goto out;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* now we want a pathname, or empty meaning NEGATIVE */
|
2006-03-27 09:15:04 +00:00
|
|
|
err = -EINVAL;
|
2008-10-20 20:34:21 +00:00
|
|
|
len = qword_get(&mesg, buf, PAGE_SIZE);
|
|
|
|
if (len < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
dprintk("Path seems to be <%s>\n", buf);
|
|
|
|
err = 0;
|
|
|
|
if (len == 0) {
|
|
|
|
set_bit(CACHE_NEGATIVE, &key.h.flags);
|
2012-03-28 15:09:50 +00:00
|
|
|
ek = svc_expkey_update(cd, &key, ek);
|
2020-03-01 23:21:41 +00:00
|
|
|
if (ek)
|
|
|
|
trace_nfsd_expkey_update(ek, NULL);
|
|
|
|
else
|
2008-10-20 20:34:21 +00:00
|
|
|
err = -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2008-08-02 05:03:36 +00:00
|
|
|
err = kern_path(buf, 0, &key.ek_path);
|
2008-10-20 20:34:21 +00:00
|
|
|
if (err)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
dprintk("Found the path %s\n", buf);
|
2008-02-15 03:38:41 +00:00
|
|
|
|
2012-03-28 15:09:50 +00:00
|
|
|
ek = svc_expkey_update(cd, &key, ek);
|
2020-03-01 23:21:41 +00:00
|
|
|
if (ek)
|
|
|
|
trace_nfsd_expkey_update(ek, buf);
|
|
|
|
else
|
2006-03-27 09:15:04 +00:00
|
|
|
err = -ENOMEM;
|
2008-08-02 05:03:36 +00:00
|
|
|
path_put(&key.ek_path);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
cache_flush();
|
|
|
|
out:
|
2008-10-20 20:34:21 +00:00
|
|
|
if (ek)
|
2012-03-28 15:09:01 +00:00
|
|
|
cache_put(&ek->h, cd);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (dom)
|
|
|
|
auth_domain_put(dom);
|
2005-11-07 09:01:34 +00:00
|
|
|
kfree(buf);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int expkey_show(struct seq_file *m,
|
|
|
|
struct cache_detail *cd,
|
|
|
|
struct cache_head *h)
|
|
|
|
{
|
|
|
|
struct svc_expkey *ek ;
|
2007-02-14 08:33:12 +00:00
|
|
|
int i;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (h ==NULL) {
|
|
|
|
seq_puts(m, "#domain fsidtype fsid [path]\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ek = container_of(h, struct svc_expkey, h);
|
2007-02-14 08:33:12 +00:00
|
|
|
seq_printf(m, "%s %d 0x", ek->ek_client->name,
|
|
|
|
ek->ek_fsidtype);
|
|
|
|
for (i=0; i < key_len(ek->ek_fsidtype)/4; i++)
|
|
|
|
seq_printf(m, "%08x", ek->ek_fsid[i]);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (test_bit(CACHE_VALID, &h->flags) &&
|
|
|
|
!test_bit(CACHE_NEGATIVE, &h->flags)) {
|
|
|
|
seq_printf(m, " ");
|
2008-02-15 03:38:43 +00:00
|
|
|
seq_path(m, &ek->ek_path, "\\ \t\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
seq_printf(m, "\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-27 09:15:04 +00:00
|
|
|
static inline int expkey_match (struct cache_head *a, struct cache_head *b)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-03-27 09:15:04 +00:00
|
|
|
struct svc_expkey *orig = container_of(a, struct svc_expkey, h);
|
|
|
|
struct svc_expkey *new = container_of(b, struct svc_expkey, h);
|
|
|
|
|
|
|
|
if (orig->ek_fsidtype != new->ek_fsidtype ||
|
|
|
|
orig->ek_client != new->ek_client ||
|
|
|
|
memcmp(orig->ek_fsid, new->ek_fsid, key_len(orig->ek_fsidtype)) != 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-03-27 09:15:04 +00:00
|
|
|
static inline void expkey_init(struct cache_head *cnew,
|
|
|
|
struct cache_head *citem)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-03-27 09:15:04 +00:00
|
|
|
struct svc_expkey *new = container_of(cnew, struct svc_expkey, h);
|
|
|
|
struct svc_expkey *item = container_of(citem, struct svc_expkey, h);
|
|
|
|
|
2006-03-27 09:14:59 +00:00
|
|
|
kref_get(&item->ek_client->ref);
|
2005-04-16 22:20:36 +00:00
|
|
|
new->ek_client = item->ek_client;
|
|
|
|
new->ek_fsidtype = item->ek_fsidtype;
|
2007-02-14 08:33:12 +00:00
|
|
|
|
|
|
|
memcpy(new->ek_fsid, item->ek_fsid, sizeof(new->ek_fsid));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-27 09:15:04 +00:00
|
|
|
static inline void expkey_update(struct cache_head *cnew,
|
|
|
|
struct cache_head *citem)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-03-27 09:15:04 +00:00
|
|
|
struct svc_expkey *new = container_of(cnew, struct svc_expkey, h);
|
|
|
|
struct svc_expkey *item = container_of(citem, struct svc_expkey, h);
|
|
|
|
|
2008-02-15 03:38:41 +00:00
|
|
|
new->ek_path = item->ek_path;
|
|
|
|
path_get(&item->ek_path);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-27 09:15:04 +00:00
|
|
|
static struct cache_head *expkey_alloc(void)
|
|
|
|
{
|
|
|
|
struct svc_expkey *i = kmalloc(sizeof(*i), GFP_KERNEL);
|
|
|
|
if (i)
|
|
|
|
return &i->h;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-08-18 18:18:48 +00:00
|
|
|
static void expkey_flush(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Take the nfsd_mutex here to ensure that the file cache is not
|
|
|
|
* destroyed while we're in the middle of flushing.
|
|
|
|
*/
|
|
|
|
mutex_lock(&nfsd_mutex);
|
2019-09-02 17:02:55 +00:00
|
|
|
nfsd_file_cache_purge(current->nsproxy->net_ns);
|
2019-08-18 18:18:48 +00:00
|
|
|
mutex_unlock(&nfsd_mutex);
|
|
|
|
}
|
|
|
|
|
2017-10-17 16:14:25 +00:00
|
|
|
static const struct cache_detail svc_expkey_cache_template = {
|
2006-03-27 09:15:04 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.hash_size = EXPKEY_HASHMAX,
|
|
|
|
.name = "nfsd.fh",
|
|
|
|
.cache_put = expkey_put,
|
2020-03-01 23:21:42 +00:00
|
|
|
.cache_upcall = expkey_upcall,
|
2013-02-04 11:02:45 +00:00
|
|
|
.cache_request = expkey_request,
|
2006-03-27 09:15:04 +00:00
|
|
|
.cache_parse = expkey_parse,
|
|
|
|
.cache_show = expkey_show,
|
|
|
|
.match = expkey_match,
|
|
|
|
.init = expkey_init,
|
|
|
|
.update = expkey_update,
|
|
|
|
.alloc = expkey_alloc,
|
2019-08-18 18:18:48 +00:00
|
|
|
.flush = expkey_flush,
|
2006-03-27 09:15:04 +00:00
|
|
|
};
|
|
|
|
|
2010-02-03 06:31:31 +00:00
|
|
|
static int
|
|
|
|
svc_expkey_hash(struct svc_expkey *item)
|
2006-03-27 09:15:04 +00:00
|
|
|
{
|
|
|
|
int hash = item->ek_fsidtype;
|
|
|
|
char * cp = (char*)item->ek_fsid;
|
|
|
|
int len = key_len(item->ek_fsidtype);
|
|
|
|
|
|
|
|
hash ^= hash_mem(cp, len, EXPKEY_HASHBITS);
|
|
|
|
hash ^= hash_ptr(item->ek_client, EXPKEY_HASHBITS);
|
|
|
|
hash &= EXPKEY_HASHMASK;
|
2010-02-03 06:31:31 +00:00
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct svc_expkey *
|
2012-03-28 15:09:50 +00:00
|
|
|
svc_expkey_lookup(struct cache_detail *cd, struct svc_expkey *item)
|
2010-02-03 06:31:31 +00:00
|
|
|
{
|
|
|
|
struct cache_head *ch;
|
|
|
|
int hash = svc_expkey_hash(item);
|
2006-03-27 09:15:04 +00:00
|
|
|
|
2018-10-01 14:41:47 +00:00
|
|
|
ch = sunrpc_cache_lookup_rcu(cd, &item->h, hash);
|
2006-03-27 09:15:04 +00:00
|
|
|
if (ch)
|
|
|
|
return container_of(ch, struct svc_expkey, h);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct svc_expkey *
|
2012-03-28 15:09:50 +00:00
|
|
|
svc_expkey_update(struct cache_detail *cd, struct svc_expkey *new,
|
|
|
|
struct svc_expkey *old)
|
2006-03-27 09:15:04 +00:00
|
|
|
{
|
|
|
|
struct cache_head *ch;
|
2010-02-03 06:31:31 +00:00
|
|
|
int hash = svc_expkey_hash(new);
|
2006-03-27 09:15:04 +00:00
|
|
|
|
2012-03-28 15:09:50 +00:00
|
|
|
ch = sunrpc_cache_update(cd, &new->h, &old->h, hash);
|
2006-03-27 09:15:04 +00:00
|
|
|
if (ch)
|
|
|
|
return container_of(ch, struct svc_expkey, h);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define EXPORT_HASHBITS 8
|
|
|
|
#define EXPORT_HASHMAX (1<< EXPORT_HASHBITS)
|
|
|
|
|
2006-10-04 09:16:18 +00:00
|
|
|
static void nfsd4_fslocs_free(struct nfsd4_fs_locations *fsloc)
|
|
|
|
{
|
2014-05-23 11:57:49 +00:00
|
|
|
struct nfsd4_fs_location *locations = fsloc->locations;
|
2006-10-04 09:16:18 +00:00
|
|
|
int i;
|
|
|
|
|
2014-05-23 11:57:49 +00:00
|
|
|
if (!locations)
|
|
|
|
return;
|
|
|
|
|
2006-10-04 09:16:18 +00:00
|
|
|
for (i = 0; i < fsloc->locations_count; i++) {
|
2014-05-23 11:57:49 +00:00
|
|
|
kfree(locations[i].path);
|
|
|
|
kfree(locations[i].hosts);
|
2006-10-04 09:16:18 +00:00
|
|
|
}
|
2014-05-23 11:57:49 +00:00
|
|
|
|
|
|
|
kfree(locations);
|
|
|
|
fsloc->locations = NULL;
|
2006-10-04 09:16:18 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 07:52:36 +00:00
|
|
|
static int export_stats_init(struct export_stats *stats)
|
|
|
|
{
|
|
|
|
stats->start_time = ktime_get_seconds();
|
2024-03-25 13:21:39 +00:00
|
|
|
return percpu_counter_init_many(stats->counter, 0, GFP_KERNEL,
|
|
|
|
EXP_STATS_COUNTERS_NUM);
|
2021-01-06 07:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void export_stats_reset(struct export_stats *stats)
|
|
|
|
{
|
2024-03-25 13:21:39 +00:00
|
|
|
if (stats) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < EXP_STATS_COUNTERS_NUM; i++)
|
|
|
|
percpu_counter_set(&stats->counter[i], 0);
|
|
|
|
}
|
2021-01-06 07:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void export_stats_destroy(struct export_stats *stats)
|
|
|
|
{
|
2023-10-01 17:25:16 +00:00
|
|
|
if (stats)
|
2024-03-25 13:21:39 +00:00
|
|
|
percpu_counter_destroy_many(stats->counter,
|
|
|
|
EXP_STATS_COUNTERS_NUM);
|
2021-01-06 07:52:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-27 09:15:09 +00:00
|
|
|
static void svc_export_put(struct kref *ref)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-03-27 09:15:09 +00:00
|
|
|
struct svc_export *exp = container_of(ref, struct svc_export, h.ref);
|
2008-02-15 03:38:39 +00:00
|
|
|
path_put(&exp->ex_path);
|
2006-03-27 09:15:09 +00:00
|
|
|
auth_domain_put(exp->ex_client);
|
2006-10-04 09:16:18 +00:00
|
|
|
nfsd4_fslocs_free(&exp->ex_fslocs);
|
2023-10-01 17:25:16 +00:00
|
|
|
export_stats_destroy(exp->ex_stats);
|
|
|
|
kfree(exp->ex_stats);
|
2013-01-29 05:16:01 +00:00
|
|
|
kfree(exp->ex_uuid);
|
2018-10-01 14:41:47 +00:00
|
|
|
kfree_rcu(exp, ex_rcu);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2020-03-01 23:21:42 +00:00
|
|
|
static int svc_export_upcall(struct cache_detail *cd, struct cache_head *h)
|
|
|
|
{
|
|
|
|
return sunrpc_cache_pipe_upcall(cd, h);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static void svc_export_request(struct cache_detail *cd,
|
|
|
|
struct cache_head *h,
|
|
|
|
char **bpp, int *blen)
|
|
|
|
{
|
|
|
|
/* client path */
|
|
|
|
struct svc_export *exp = container_of(h, struct svc_export, h);
|
|
|
|
char *pth;
|
|
|
|
|
|
|
|
qword_add(bpp, blen, exp->ex_client->name);
|
2008-02-15 03:38:44 +00:00
|
|
|
pth = d_path(&exp->ex_path, *bpp, *blen);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (IS_ERR(pth)) {
|
|
|
|
/* is this correct? */
|
|
|
|
(*bpp)[0] = '\n';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qword_add(bpp, blen, pth);
|
|
|
|
(*bpp)[-1] = '\n';
|
|
|
|
}
|
|
|
|
|
2006-03-27 09:15:10 +00:00
|
|
|
static struct svc_export *svc_export_update(struct svc_export *new,
|
|
|
|
struct svc_export *old);
|
2006-03-27 09:15:03 +00:00
|
|
|
static struct svc_export *svc_export_lookup(struct svc_export *);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-01-23 11:00:02 +00:00
|
|
|
static int check_export(struct path *path, int *flags, unsigned char *uuid)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2021-01-23 11:00:02 +00:00
|
|
|
struct inode *inode = d_inode(path->dentry);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-11-12 22:26:19 +00:00
|
|
|
/*
|
|
|
|
* We currently export only dirs, regular files, and (for v4
|
|
|
|
* pseudoroot) symlinks.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
if (!S_ISDIR(inode->i_mode) &&
|
2009-11-12 22:26:19 +00:00
|
|
|
!S_ISLNK(inode->i_mode) &&
|
2005-04-16 22:20:36 +00:00
|
|
|
!S_ISREG(inode->i_mode))
|
|
|
|
return -ENOTDIR;
|
|
|
|
|
2009-12-14 01:21:48 +00:00
|
|
|
/*
|
|
|
|
* Mountd should never pass down a writeable V4ROOT export, but,
|
|
|
|
* just to make sure:
|
|
|
|
*/
|
|
|
|
if (*flags & NFSEXP_V4ROOT)
|
|
|
|
*flags |= NFSEXP_READONLY;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* There are two requirements on a filesystem to be exportable.
|
|
|
|
* 1: We must be able to identify the filesystem from a number.
|
|
|
|
* either a device number (so FS_REQUIRES_DEV needed)
|
2007-02-14 08:33:12 +00:00
|
|
|
* or an FSID number (so NFSEXP_FSID or ->uuid is needed).
|
2005-04-16 22:20:36 +00:00
|
|
|
* 2: We must be able to find an inode from a filehandle.
|
|
|
|
* This means that s_export_op must be set.
|
2021-01-23 11:00:02 +00:00
|
|
|
* 3: We must not currently be on an idmapped mount.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
if (!(inode->i_sb->s_type->fs_flags & FS_REQUIRES_DEV) &&
|
2009-12-14 01:21:48 +00:00
|
|
|
!(*flags & NFSEXP_FSID) &&
|
2007-02-14 08:33:12 +00:00
|
|
|
uuid == NULL) {
|
2006-10-02 09:17:41 +00:00
|
|
|
dprintk("exp_export: export of non-dev fs without fsid\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2007-10-21 23:42:16 +00:00
|
|
|
|
2023-10-23 18:07:58 +00:00
|
|
|
if (!exportfs_can_decode_fh(inode->i_sb->s_export_op)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
dprintk("exp_export: export of invalid fs type.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-12-03 11:16:58 +00:00
|
|
|
if (is_idmapped_mnt(path->mnt)) {
|
2021-01-23 11:00:02 +00:00
|
|
|
dprintk("exp_export: export of idmapped mounts not yet supported.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-11-30 22:03:15 +00:00
|
|
|
if (inode->i_sb->s_export_op->flags & EXPORT_OP_NOSUBTREECHK &&
|
|
|
|
!(*flags & NFSEXP_NOSUBTREECHECK)) {
|
|
|
|
dprintk("%s: %s does not support subtree checking!\n",
|
|
|
|
__func__, inode->i_sb->s_type->name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-04 09:16:18 +00:00
|
|
|
#ifdef CONFIG_NFSD_V4
|
|
|
|
|
|
|
|
static int
|
|
|
|
fsloc_parse(char **mesg, char *buf, struct nfsd4_fs_locations *fsloc)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int migrated, i, err;
|
|
|
|
|
2014-05-24 03:19:57 +00:00
|
|
|
/* more than one fsloc */
|
|
|
|
if (fsloc->locations)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2006-10-04 09:16:18 +00:00
|
|
|
/* listsize */
|
2012-06-12 20:54:16 +00:00
|
|
|
err = get_uint(mesg, &fsloc->locations_count);
|
2006-10-04 09:16:18 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (fsloc->locations_count > MAX_FS_LOCATIONS)
|
|
|
|
return -EINVAL;
|
|
|
|
if (fsloc->locations_count == 0)
|
|
|
|
return 0;
|
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 21:03:40 +00:00
|
|
|
fsloc->locations = kcalloc(fsloc->locations_count,
|
|
|
|
sizeof(struct nfsd4_fs_location),
|
|
|
|
GFP_KERNEL);
|
2006-10-04 09:16:18 +00:00
|
|
|
if (!fsloc->locations)
|
|
|
|
return -ENOMEM;
|
|
|
|
for (i=0; i < fsloc->locations_count; i++) {
|
|
|
|
/* colon separated host list */
|
|
|
|
err = -EINVAL;
|
|
|
|
len = qword_get(mesg, buf, PAGE_SIZE);
|
|
|
|
if (len <= 0)
|
|
|
|
goto out_free_all;
|
|
|
|
err = -ENOMEM;
|
|
|
|
fsloc->locations[i].hosts = kstrdup(buf, GFP_KERNEL);
|
|
|
|
if (!fsloc->locations[i].hosts)
|
|
|
|
goto out_free_all;
|
|
|
|
err = -EINVAL;
|
|
|
|
/* slash separated path component list */
|
|
|
|
len = qword_get(mesg, buf, PAGE_SIZE);
|
|
|
|
if (len <= 0)
|
|
|
|
goto out_free_all;
|
|
|
|
err = -ENOMEM;
|
|
|
|
fsloc->locations[i].path = kstrdup(buf, GFP_KERNEL);
|
|
|
|
if (!fsloc->locations[i].path)
|
|
|
|
goto out_free_all;
|
|
|
|
}
|
|
|
|
/* migrated */
|
|
|
|
err = get_int(mesg, &migrated);
|
|
|
|
if (err)
|
|
|
|
goto out_free_all;
|
|
|
|
err = -EINVAL;
|
|
|
|
if (migrated < 0 || migrated > 1)
|
|
|
|
goto out_free_all;
|
|
|
|
fsloc->migrated = migrated;
|
|
|
|
return 0;
|
|
|
|
out_free_all:
|
|
|
|
nfsd4_fslocs_free(fsloc);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-07-17 11:04:42 +00:00
|
|
|
static int secinfo_parse(char **mesg, char *buf, struct svc_export *exp)
|
|
|
|
{
|
|
|
|
struct exp_flavor_info *f;
|
2014-05-24 03:26:49 +00:00
|
|
|
u32 listsize;
|
|
|
|
int err;
|
2007-07-17 11:04:42 +00:00
|
|
|
|
2014-05-24 03:19:57 +00:00
|
|
|
/* more than one secinfo */
|
|
|
|
if (exp->ex_nflavors)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-05-24 03:26:49 +00:00
|
|
|
err = get_uint(mesg, &listsize);
|
2007-07-17 11:04:42 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2014-05-24 03:26:49 +00:00
|
|
|
if (listsize > MAX_SECINFO_LIST)
|
2007-07-17 11:04:42 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (f = exp->ex_flavors; f < exp->ex_flavors + listsize; f++) {
|
2012-06-12 20:54:16 +00:00
|
|
|
err = get_uint(mesg, &f->pseudoflavor);
|
2007-07-17 11:04:42 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
/*
|
2009-04-21 14:08:39 +00:00
|
|
|
* XXX: It would be nice to also check whether this
|
|
|
|
* pseudoflavor is supported, so we can discover the
|
|
|
|
* problem at export time instead of when a client fails
|
|
|
|
* to authenticate.
|
2007-07-17 11:04:42 +00:00
|
|
|
*/
|
2012-06-12 20:54:16 +00:00
|
|
|
err = get_uint(mesg, &f->flags);
|
2007-07-17 11:04:42 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
/* Only some flags are allowed to differ between flavors: */
|
|
|
|
if (~NFSEXP_SECINFO_FLAGS & (f->flags ^ exp->ex_flags))
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
exp->ex_nflavors = listsize;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-04 09:16:18 +00:00
|
|
|
#else /* CONFIG_NFSD_V4 */
|
2007-07-17 11:04:42 +00:00
|
|
|
static inline int
|
|
|
|
fsloc_parse(char **mesg, char *buf, struct nfsd4_fs_locations *fsloc){return 0;}
|
|
|
|
static inline int
|
|
|
|
secinfo_parse(char **mesg, char *buf, struct svc_export *exp) { return 0; }
|
2006-10-04 09:16:18 +00:00
|
|
|
#endif
|
|
|
|
|
2023-04-20 17:56:31 +00:00
|
|
|
static int xprtsec_parse(char **mesg, char *buf, struct svc_export *exp)
|
|
|
|
{
|
|
|
|
unsigned int i, mode, listsize;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = get_uint(mesg, &listsize);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (listsize > NFSEXP_XPRTSEC_NUM)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
exp->ex_xprtsec_modes = 0;
|
|
|
|
for (i = 0; i < listsize; i++) {
|
|
|
|
err = get_uint(mesg, &mode);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (mode > NFSEXP_XPRTSEC_MTLS)
|
|
|
|
return -EINVAL;
|
|
|
|
exp->ex_xprtsec_modes |= mode;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-23 11:59:06 +00:00
|
|
|
static inline int
|
2017-05-31 14:40:52 +00:00
|
|
|
nfsd_uuid_parse(char **mesg, char *buf, unsigned char **puuid)
|
2014-05-23 11:59:06 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
2014-05-24 03:19:57 +00:00
|
|
|
/* more than one uuid */
|
|
|
|
if (*puuid)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-05-23 11:59:06 +00:00
|
|
|
/* expect a 16 byte uuid encoded as \xXXXX... */
|
|
|
|
len = qword_get(mesg, buf, PAGE_SIZE);
|
2014-05-23 12:00:19 +00:00
|
|
|
if (len != EX_UUID_LEN)
|
2014-05-23 11:59:06 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2014-05-23 12:00:19 +00:00
|
|
|
*puuid = kmemdup(buf, EX_UUID_LEN, GFP_KERNEL);
|
2014-05-23 11:59:06 +00:00
|
|
|
if (*puuid == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
|
|
|
|
{
|
|
|
|
/* client path expiry [flags anonuid anongid fsid] */
|
|
|
|
char *buf;
|
|
|
|
int err;
|
|
|
|
struct auth_domain *dom = NULL;
|
2008-08-02 05:01:02 +00:00
|
|
|
struct svc_export exp = {}, *expp;
|
2005-04-16 22:20:36 +00:00
|
|
|
int an_int;
|
|
|
|
|
|
|
|
if (mesg[mlen-1] != '\n')
|
|
|
|
return -EINVAL;
|
|
|
|
mesg[mlen-1] = 0;
|
|
|
|
|
|
|
|
buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
2008-08-02 05:01:02 +00:00
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* client */
|
|
|
|
err = -EINVAL;
|
2023-06-21 14:52:05 +00:00
|
|
|
if (qword_get(&mesg, buf, PAGE_SIZE) <= 0)
|
2008-08-02 05:01:02 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err = -ENOENT;
|
|
|
|
dom = auth_domain_find(buf);
|
|
|
|
if (!dom)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* path */
|
|
|
|
err = -EINVAL;
|
2023-06-21 14:52:05 +00:00
|
|
|
if (qword_get(&mesg, buf, PAGE_SIZE) <= 0)
|
2008-08-02 05:01:02 +00:00
|
|
|
goto out1;
|
|
|
|
|
|
|
|
err = kern_path(buf, 0, &exp.ex_path);
|
|
|
|
if (err)
|
|
|
|
goto out1;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
exp.ex_client = dom;
|
2012-03-28 15:09:08 +00:00
|
|
|
exp.cd = cd;
|
nfsd: implement pNFS operations
Add support for the GETDEVICEINFO, LAYOUTGET, LAYOUTCOMMIT and
LAYOUTRETURN NFSv4.1 operations, as well as backing code to manage
outstanding layouts and devices.
Layout management is very straight forward, with a nfs4_layout_stateid
structure that extends nfs4_stid to manage layout stateids as the
top-level structure. It is linked into the nfs4_file and nfs4_client
structures like the other stateids, and contains a linked list of
layouts that hang of the stateid. The actual layout operations are
implemented in layout drivers that are not part of this commit, but
will be added later.
The worst part of this commit is the management of the pNFS device IDs,
which suffers from a specification that is not sanely implementable due
to the fact that the device-IDs are global and not bound to an export,
and have a small enough size so that we can't store the fsid portion of
a file handle, and must never be reused. As we still do need perform all
export authentication and validation checks on a device ID passed to
GETDEVICEINFO we are caught between a rock and a hard place. To work
around this issue we add a new hash that maps from a 64-bit integer to a
fsid so that we can look up the export to authenticate against it,
a 32-bit integer as a generation that we can bump when changing the device,
and a currently unused 32-bit integer that could be used in the future
to handle more than a single device per export. Entries in this hash
table are never deleted as we can't reuse the ids anyway, and would have
a severe lifetime problem anyway as Linux export structures are temporary
structures that can go away under load.
Parts of the XDR data, structures and marshaling/unmarshaling code, as
well as many concepts are derived from the old pNFS server implementation
from Andy Adamson, Benny Halevy, Dean Hildebrand, Marc Eshel, Fred Isaman,
Mike Sager, Ricardo Labiaga and many others.
Signed-off-by: Christoph Hellwig <hch@lst.de>
2014-05-05 11:11:59 +00:00
|
|
|
exp.ex_devid_map = NULL;
|
2023-04-20 17:56:31 +00:00
|
|
|
exp.ex_xprtsec_modes = NFSEXP_XPRTSEC_ALL;
|
2008-08-02 05:01:02 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* expiry */
|
2023-03-08 06:51:00 +00:00
|
|
|
err = get_expiry(&mesg, &exp.h.expiry_time);
|
|
|
|
if (err)
|
2008-08-02 05:01:02 +00:00
|
|
|
goto out3;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* flags */
|
|
|
|
err = get_int(&mesg, &an_int);
|
2007-07-31 07:37:53 +00:00
|
|
|
if (err == -ENOENT) {
|
|
|
|
err = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
set_bit(CACHE_NEGATIVE, &exp.h.flags);
|
2007-07-31 07:37:53 +00:00
|
|
|
} else {
|
2008-08-02 05:01:02 +00:00
|
|
|
if (err || an_int < 0)
|
|
|
|
goto out3;
|
2005-04-16 22:20:36 +00:00
|
|
|
exp.ex_flags= an_int;
|
2023-03-08 06:51:00 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* anon uid */
|
|
|
|
err = get_int(&mesg, &an_int);
|
2008-08-02 05:01:02 +00:00
|
|
|
if (err)
|
|
|
|
goto out3;
|
2019-04-09 16:13:42 +00:00
|
|
|
exp.ex_anon_uid= make_kuid(current_user_ns(), an_int);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* anon gid */
|
|
|
|
err = get_int(&mesg, &an_int);
|
2008-08-02 05:01:02 +00:00
|
|
|
if (err)
|
|
|
|
goto out3;
|
2019-04-09 16:13:42 +00:00
|
|
|
exp.ex_anon_gid= make_kgid(current_user_ns(), an_int);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* fsid */
|
|
|
|
err = get_int(&mesg, &an_int);
|
2008-08-02 05:01:02 +00:00
|
|
|
if (err)
|
|
|
|
goto out3;
|
2005-04-16 22:20:36 +00:00
|
|
|
exp.ex_fsid = an_int;
|
|
|
|
|
2023-06-21 14:52:05 +00:00
|
|
|
while (qword_get(&mesg, buf, PAGE_SIZE) > 0) {
|
2007-02-14 08:33:12 +00:00
|
|
|
if (strcmp(buf, "fsloc") == 0)
|
|
|
|
err = fsloc_parse(&mesg, buf, &exp.ex_fslocs);
|
2014-05-23 11:59:06 +00:00
|
|
|
else if (strcmp(buf, "uuid") == 0)
|
2017-05-31 14:40:52 +00:00
|
|
|
err = nfsd_uuid_parse(&mesg, buf, &exp.ex_uuid);
|
2014-05-23 11:59:06 +00:00
|
|
|
else if (strcmp(buf, "secinfo") == 0)
|
2007-07-17 11:04:42 +00:00
|
|
|
err = secinfo_parse(&mesg, buf, &exp);
|
2023-04-20 17:56:31 +00:00
|
|
|
else if (strcmp(buf, "xprtsec") == 0)
|
|
|
|
err = xprtsec_parse(&mesg, buf, &exp);
|
2007-07-17 11:04:42 +00:00
|
|
|
else
|
2007-02-14 08:33:12 +00:00
|
|
|
/* quietly ignore unknown words and anything
|
|
|
|
* following. Newer user-space can try to set
|
|
|
|
* new values, then see what the result was.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
if (err)
|
2008-08-02 05:01:02 +00:00
|
|
|
goto out4;
|
2007-02-14 08:33:12 +00:00
|
|
|
}
|
2006-10-04 09:16:18 +00:00
|
|
|
|
2021-01-23 11:00:02 +00:00
|
|
|
err = check_export(&exp.ex_path, &exp.ex_flags, exp.ex_uuid);
|
2008-08-02 05:01:02 +00:00
|
|
|
if (err)
|
|
|
|
goto out4;
|
2023-04-20 17:56:31 +00:00
|
|
|
|
2013-09-13 21:50:42 +00:00
|
|
|
/*
|
|
|
|
* No point caching this if it would immediately expire.
|
|
|
|
* Also, this protects exportfs's dummy export from the
|
|
|
|
* anon_uid/anon_gid checks:
|
|
|
|
*/
|
|
|
|
if (exp.h.expiry_time < seconds_since_boot())
|
|
|
|
goto out4;
|
2013-09-13 15:08:45 +00:00
|
|
|
/*
|
|
|
|
* For some reason exportfs has been passing down an
|
|
|
|
* invalid (-1) uid & gid on the "dummy" export which it
|
|
|
|
* uses to test export support. To make sure exportfs
|
|
|
|
* sees errors from check_export we therefore need to
|
|
|
|
* delay these checks till after check_export:
|
|
|
|
*/
|
2013-09-13 21:50:42 +00:00
|
|
|
err = -EINVAL;
|
2013-09-13 15:08:45 +00:00
|
|
|
if (!uid_valid(exp.ex_anon_uid))
|
|
|
|
goto out4;
|
|
|
|
if (!gid_valid(exp.ex_anon_gid))
|
|
|
|
goto out4;
|
2013-09-13 21:50:42 +00:00
|
|
|
err = 0;
|
nfsd: implement pNFS operations
Add support for the GETDEVICEINFO, LAYOUTGET, LAYOUTCOMMIT and
LAYOUTRETURN NFSv4.1 operations, as well as backing code to manage
outstanding layouts and devices.
Layout management is very straight forward, with a nfs4_layout_stateid
structure that extends nfs4_stid to manage layout stateids as the
top-level structure. It is linked into the nfs4_file and nfs4_client
structures like the other stateids, and contains a linked list of
layouts that hang of the stateid. The actual layout operations are
implemented in layout drivers that are not part of this commit, but
will be added later.
The worst part of this commit is the management of the pNFS device IDs,
which suffers from a specification that is not sanely implementable due
to the fact that the device-IDs are global and not bound to an export,
and have a small enough size so that we can't store the fsid portion of
a file handle, and must never be reused. As we still do need perform all
export authentication and validation checks on a device ID passed to
GETDEVICEINFO we are caught between a rock and a hard place. To work
around this issue we add a new hash that maps from a 64-bit integer to a
fsid so that we can look up the export to authenticate against it,
a 32-bit integer as a generation that we can bump when changing the device,
and a currently unused 32-bit integer that could be used in the future
to handle more than a single device per export. Entries in this hash
table are never deleted as we can't reuse the ids anyway, and would have
a severe lifetime problem anyway as Linux export structures are temporary
structures that can go away under load.
Parts of the XDR data, structures and marshaling/unmarshaling code, as
well as many concepts are derived from the old pNFS server implementation
from Andy Adamson, Benny Halevy, Dean Hildebrand, Marc Eshel, Fred Isaman,
Mike Sager, Ricardo Labiaga and many others.
Signed-off-by: Christoph Hellwig <hch@lst.de>
2014-05-05 11:11:59 +00:00
|
|
|
|
|
|
|
nfsd4_setup_layout_type(&exp);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-27 09:15:03 +00:00
|
|
|
expp = svc_export_lookup(&exp);
|
2020-03-01 23:21:41 +00:00
|
|
|
if (!expp) {
|
2006-03-27 09:15:03 +00:00
|
|
|
err = -ENOMEM;
|
2020-03-01 23:21:41 +00:00
|
|
|
goto out4;
|
|
|
|
}
|
|
|
|
expp = svc_export_update(&exp, expp);
|
|
|
|
if (expp) {
|
|
|
|
trace_nfsd_export_update(expp);
|
|
|
|
cache_flush();
|
2006-03-27 09:15:03 +00:00
|
|
|
exp_put(expp);
|
2020-03-01 23:21:41 +00:00
|
|
|
} else
|
|
|
|
err = -ENOMEM;
|
2008-08-02 05:01:02 +00:00
|
|
|
out4:
|
2007-02-14 08:33:12 +00:00
|
|
|
nfsd4_fslocs_free(&exp.ex_fslocs);
|
|
|
|
kfree(exp.ex_uuid);
|
2008-08-02 05:01:02 +00:00
|
|
|
out3:
|
|
|
|
path_put(&exp.ex_path);
|
|
|
|
out1:
|
|
|
|
auth_domain_put(dom);
|
|
|
|
out:
|
2005-11-07 09:01:34 +00:00
|
|
|
kfree(buf);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-10-04 09:16:18 +00:00
|
|
|
static void exp_flags(struct seq_file *m, int flag, int fsid,
|
2013-02-02 14:42:53 +00:00
|
|
|
kuid_t anonu, kgid_t anong, struct nfsd4_fs_locations *fslocs);
|
2007-07-17 11:04:49 +00:00
|
|
|
static void show_secinfo(struct seq_file *m, struct svc_export *exp);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-01-06 07:52:36 +00:00
|
|
|
static int is_export_stats_file(struct seq_file *m)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The export_stats file uses the same ops as the exports file.
|
|
|
|
* We use the file's name to determine the reported info per export.
|
|
|
|
* There is no rename in nsfdfs, so d_name.name is stable.
|
|
|
|
*/
|
|
|
|
return !strcmp(m->file->f_path.dentry->d_name.name, "export_stats");
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static int svc_export_show(struct seq_file *m,
|
|
|
|
struct cache_detail *cd,
|
|
|
|
struct cache_head *h)
|
|
|
|
{
|
2021-01-06 07:52:36 +00:00
|
|
|
struct svc_export *exp;
|
|
|
|
bool export_stats = is_export_stats_file(m);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-01-06 07:52:36 +00:00
|
|
|
if (h == NULL) {
|
|
|
|
if (export_stats)
|
|
|
|
seq_puts(m, "#path domain start-time\n#\tstats\n");
|
|
|
|
else
|
|
|
|
seq_puts(m, "#path domain(flags)\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
exp = container_of(h, struct svc_export, h);
|
2008-02-15 03:38:43 +00:00
|
|
|
seq_path(m, &exp->ex_path, " \t\n\\");
|
2005-04-16 22:20:36 +00:00
|
|
|
seq_putc(m, '\t');
|
|
|
|
seq_escape(m, exp->ex_client->name, " \t\n\\");
|
2021-01-06 07:52:36 +00:00
|
|
|
if (export_stats) {
|
2023-10-01 17:25:16 +00:00
|
|
|
struct percpu_counter *counter = exp->ex_stats->counter;
|
|
|
|
|
|
|
|
seq_printf(m, "\t%lld\n", exp->ex_stats->start_time);
|
2021-01-06 07:52:36 +00:00
|
|
|
seq_printf(m, "\tfh_stale: %lld\n",
|
2023-10-01 17:25:16 +00:00
|
|
|
percpu_counter_sum_positive(&counter[EXP_STATS_FH_STALE]));
|
2021-01-06 07:52:36 +00:00
|
|
|
seq_printf(m, "\tio_read: %lld\n",
|
2023-10-01 17:25:16 +00:00
|
|
|
percpu_counter_sum_positive(&counter[EXP_STATS_IO_READ]));
|
2021-01-06 07:52:36 +00:00
|
|
|
seq_printf(m, "\tio_write: %lld\n",
|
2023-10-01 17:25:16 +00:00
|
|
|
percpu_counter_sum_positive(&counter[EXP_STATS_IO_WRITE]));
|
2021-01-06 07:52:36 +00:00
|
|
|
seq_putc(m, '\n');
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
seq_putc(m, '(');
|
2021-01-06 07:52:36 +00:00
|
|
|
if (test_bit(CACHE_VALID, &h->flags) &&
|
2007-02-14 08:33:12 +00:00
|
|
|
!test_bit(CACHE_NEGATIVE, &h->flags)) {
|
2006-10-04 09:16:18 +00:00
|
|
|
exp_flags(m, exp->ex_flags, exp->ex_fsid,
|
|
|
|
exp->ex_anon_uid, exp->ex_anon_gid, &exp->ex_fslocs);
|
2007-02-14 08:33:12 +00:00
|
|
|
if (exp->ex_uuid) {
|
|
|
|
int i;
|
|
|
|
seq_puts(m, ",uuid=");
|
2014-05-23 12:00:19 +00:00
|
|
|
for (i = 0; i < EX_UUID_LEN; i++) {
|
2007-02-14 08:33:12 +00:00
|
|
|
if ((i&3) == 0 && i)
|
|
|
|
seq_putc(m, ':');
|
|
|
|
seq_printf(m, "%02x", exp->ex_uuid[i]);
|
|
|
|
}
|
|
|
|
}
|
2007-07-17 11:04:49 +00:00
|
|
|
show_secinfo(m, exp);
|
2007-02-14 08:33:12 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
seq_puts(m, ")\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2006-03-27 09:15:03 +00:00
|
|
|
static int svc_export_match(struct cache_head *a, struct cache_head *b)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-03-27 09:15:03 +00:00
|
|
|
struct svc_export *orig = container_of(a, struct svc_export, h);
|
|
|
|
struct svc_export *new = container_of(b, struct svc_export, h);
|
|
|
|
return orig->ex_client == new->ex_client &&
|
2015-03-15 15:13:32 +00:00
|
|
|
path_equal(&orig->ex_path, &new->ex_path);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-03-27 09:15:03 +00:00
|
|
|
|
|
|
|
static void svc_export_init(struct cache_head *cnew, struct cache_head *citem)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-03-27 09:15:03 +00:00
|
|
|
struct svc_export *new = container_of(cnew, struct svc_export, h);
|
|
|
|
struct svc_export *item = container_of(citem, struct svc_export, h);
|
|
|
|
|
2006-03-27 09:14:59 +00:00
|
|
|
kref_get(&item->ex_client->ref);
|
2005-04-16 22:20:36 +00:00
|
|
|
new->ex_client = item->ex_client;
|
2014-06-10 14:04:43 +00:00
|
|
|
new->ex_path = item->ex_path;
|
|
|
|
path_get(&item->ex_path);
|
2006-10-04 09:16:18 +00:00
|
|
|
new->ex_fslocs.locations = NULL;
|
|
|
|
new->ex_fslocs.locations_count = 0;
|
|
|
|
new->ex_fslocs.migrated = 0;
|
2016-07-10 19:55:58 +00:00
|
|
|
new->ex_layout_types = 0;
|
2013-02-02 10:55:08 +00:00
|
|
|
new->ex_uuid = NULL;
|
2012-03-28 15:09:08 +00:00
|
|
|
new->cd = item->cd;
|
2023-10-01 17:25:16 +00:00
|
|
|
export_stats_reset(new->ex_stats);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-27 09:15:03 +00:00
|
|
|
static void export_update(struct cache_head *cnew, struct cache_head *citem)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-03-27 09:15:03 +00:00
|
|
|
struct svc_export *new = container_of(cnew, struct svc_export, h);
|
|
|
|
struct svc_export *item = container_of(citem, struct svc_export, h);
|
2007-07-17 11:04:42 +00:00
|
|
|
int i;
|
2006-03-27 09:15:03 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
new->ex_flags = item->ex_flags;
|
|
|
|
new->ex_anon_uid = item->ex_anon_uid;
|
|
|
|
new->ex_anon_gid = item->ex_anon_gid;
|
|
|
|
new->ex_fsid = item->ex_fsid;
|
nfsd: implement pNFS operations
Add support for the GETDEVICEINFO, LAYOUTGET, LAYOUTCOMMIT and
LAYOUTRETURN NFSv4.1 operations, as well as backing code to manage
outstanding layouts and devices.
Layout management is very straight forward, with a nfs4_layout_stateid
structure that extends nfs4_stid to manage layout stateids as the
top-level structure. It is linked into the nfs4_file and nfs4_client
structures like the other stateids, and contains a linked list of
layouts that hang of the stateid. The actual layout operations are
implemented in layout drivers that are not part of this commit, but
will be added later.
The worst part of this commit is the management of the pNFS device IDs,
which suffers from a specification that is not sanely implementable due
to the fact that the device-IDs are global and not bound to an export,
and have a small enough size so that we can't store the fsid portion of
a file handle, and must never be reused. As we still do need perform all
export authentication and validation checks on a device ID passed to
GETDEVICEINFO we are caught between a rock and a hard place. To work
around this issue we add a new hash that maps from a 64-bit integer to a
fsid so that we can look up the export to authenticate against it,
a 32-bit integer as a generation that we can bump when changing the device,
and a currently unused 32-bit integer that could be used in the future
to handle more than a single device per export. Entries in this hash
table are never deleted as we can't reuse the ids anyway, and would have
a severe lifetime problem anyway as Linux export structures are temporary
structures that can go away under load.
Parts of the XDR data, structures and marshaling/unmarshaling code, as
well as many concepts are derived from the old pNFS server implementation
from Andy Adamson, Benny Halevy, Dean Hildebrand, Marc Eshel, Fred Isaman,
Mike Sager, Ricardo Labiaga and many others.
Signed-off-by: Christoph Hellwig <hch@lst.de>
2014-05-05 11:11:59 +00:00
|
|
|
new->ex_devid_map = item->ex_devid_map;
|
|
|
|
item->ex_devid_map = NULL;
|
2007-02-14 08:33:12 +00:00
|
|
|
new->ex_uuid = item->ex_uuid;
|
|
|
|
item->ex_uuid = NULL;
|
2006-10-04 09:16:18 +00:00
|
|
|
new->ex_fslocs.locations = item->ex_fslocs.locations;
|
|
|
|
item->ex_fslocs.locations = NULL;
|
|
|
|
new->ex_fslocs.locations_count = item->ex_fslocs.locations_count;
|
|
|
|
item->ex_fslocs.locations_count = 0;
|
|
|
|
new->ex_fslocs.migrated = item->ex_fslocs.migrated;
|
|
|
|
item->ex_fslocs.migrated = 0;
|
2016-07-10 19:55:58 +00:00
|
|
|
new->ex_layout_types = item->ex_layout_types;
|
2007-07-17 11:04:42 +00:00
|
|
|
new->ex_nflavors = item->ex_nflavors;
|
|
|
|
for (i = 0; i < MAX_SECINFO_LIST; i++) {
|
|
|
|
new->ex_flavors[i] = item->ex_flavors[i];
|
|
|
|
}
|
2023-04-20 17:56:31 +00:00
|
|
|
new->ex_xprtsec_modes = item->ex_xprtsec_modes;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-27 09:15:03 +00:00
|
|
|
static struct cache_head *svc_export_alloc(void)
|
|
|
|
{
|
|
|
|
struct svc_export *i = kmalloc(sizeof(*i), GFP_KERNEL);
|
2021-01-06 07:52:36 +00:00
|
|
|
if (!i)
|
|
|
|
return NULL;
|
|
|
|
|
2023-10-01 17:25:16 +00:00
|
|
|
i->ex_stats = kmalloc(sizeof(*(i->ex_stats)), GFP_KERNEL);
|
|
|
|
if (!i->ex_stats) {
|
|
|
|
kfree(i);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (export_stats_init(i->ex_stats)) {
|
|
|
|
kfree(i->ex_stats);
|
2021-01-06 07:52:36 +00:00
|
|
|
kfree(i);
|
2006-03-27 09:15:03 +00:00
|
|
|
return NULL;
|
2021-01-06 07:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &i->h;
|
2006-03-27 09:15:03 +00:00
|
|
|
}
|
|
|
|
|
2017-10-17 16:14:25 +00:00
|
|
|
static const struct cache_detail svc_export_cache_template = {
|
2006-03-27 09:15:03 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.hash_size = EXPORT_HASHMAX,
|
|
|
|
.name = "nfsd.export",
|
|
|
|
.cache_put = svc_export_put,
|
2020-03-01 23:21:42 +00:00
|
|
|
.cache_upcall = svc_export_upcall,
|
2013-02-04 11:02:45 +00:00
|
|
|
.cache_request = svc_export_request,
|
2006-03-27 09:15:03 +00:00
|
|
|
.cache_parse = svc_export_parse,
|
|
|
|
.cache_show = svc_export_show,
|
|
|
|
.match = svc_export_match,
|
|
|
|
.init = svc_export_init,
|
|
|
|
.update = export_update,
|
|
|
|
.alloc = svc_export_alloc,
|
|
|
|
};
|
|
|
|
|
2010-02-03 06:31:31 +00:00
|
|
|
static int
|
|
|
|
svc_export_hash(struct svc_export *exp)
|
2006-03-27 09:15:03 +00:00
|
|
|
{
|
|
|
|
int hash;
|
2010-02-03 06:31:31 +00:00
|
|
|
|
2006-03-27 09:15:03 +00:00
|
|
|
hash = hash_ptr(exp->ex_client, EXPORT_HASHBITS);
|
2008-02-15 03:38:39 +00:00
|
|
|
hash ^= hash_ptr(exp->ex_path.dentry, EXPORT_HASHBITS);
|
|
|
|
hash ^= hash_ptr(exp->ex_path.mnt, EXPORT_HASHBITS);
|
2010-02-03 06:31:31 +00:00
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct svc_export *
|
|
|
|
svc_export_lookup(struct svc_export *exp)
|
|
|
|
{
|
|
|
|
struct cache_head *ch;
|
|
|
|
int hash = svc_export_hash(exp);
|
2006-03-27 09:15:03 +00:00
|
|
|
|
2018-10-01 14:41:47 +00:00
|
|
|
ch = sunrpc_cache_lookup_rcu(exp->cd, &exp->h, hash);
|
2006-03-27 09:15:03 +00:00
|
|
|
if (ch)
|
|
|
|
return container_of(ch, struct svc_export, h);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-03-27 09:15:10 +00:00
|
|
|
static struct svc_export *
|
2006-03-27 09:15:03 +00:00
|
|
|
svc_export_update(struct svc_export *new, struct svc_export *old)
|
|
|
|
{
|
|
|
|
struct cache_head *ch;
|
2010-02-03 06:31:31 +00:00
|
|
|
int hash = svc_export_hash(old);
|
2006-03-27 09:15:03 +00:00
|
|
|
|
2012-03-28 15:09:08 +00:00
|
|
|
ch = sunrpc_cache_update(old->cd, &new->h, &old->h, hash);
|
2006-03-27 09:15:03 +00:00
|
|
|
if (ch)
|
|
|
|
return container_of(ch, struct svc_export, h);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
2006-03-27 09:15:10 +00:00
|
|
|
static struct svc_expkey *
|
2014-05-23 12:55:43 +00:00
|
|
|
exp_find_key(struct cache_detail *cd, struct auth_domain *clp, int fsid_type,
|
2012-03-28 15:09:50 +00:00
|
|
|
u32 *fsidv, struct cache_req *reqp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct svc_expkey key, *ek;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (!clp)
|
2007-07-17 11:04:40 +00:00
|
|
|
return ERR_PTR(-ENOENT);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
key.ek_client = clp;
|
|
|
|
key.ek_fsidtype = fsid_type;
|
|
|
|
memcpy(key.ek_fsid, fsidv, key_len(fsid_type));
|
|
|
|
|
2012-03-28 15:09:50 +00:00
|
|
|
ek = svc_expkey_lookup(cd, &key);
|
2007-07-17 11:04:40 +00:00
|
|
|
if (ek == NULL)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2012-03-28 15:09:50 +00:00
|
|
|
err = cache_check(cd, &ek->h, reqp);
|
2020-03-01 23:21:40 +00:00
|
|
|
if (err) {
|
|
|
|
trace_nfsd_exp_find_key(&key, err);
|
2007-07-17 11:04:40 +00:00
|
|
|
return ERR_PTR(err);
|
2020-03-01 23:21:40 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
return ek;
|
|
|
|
}
|
|
|
|
|
2014-05-23 12:55:43 +00:00
|
|
|
static struct svc_export *
|
|
|
|
exp_get_by_name(struct cache_detail *cd, struct auth_domain *clp,
|
|
|
|
const struct path *path, struct cache_req *reqp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct svc_export *exp, key;
|
2007-07-17 11:04:40 +00:00
|
|
|
int err;
|
2008-02-15 03:38:41 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!clp)
|
2007-07-17 11:04:40 +00:00
|
|
|
return ERR_PTR(-ENOENT);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
key.ex_client = clp;
|
2009-04-18 06:04:46 +00:00
|
|
|
key.ex_path = *path;
|
2012-03-28 15:09:42 +00:00
|
|
|
key.cd = cd;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-03-27 09:15:03 +00:00
|
|
|
exp = svc_export_lookup(&key);
|
2007-07-17 11:04:40 +00:00
|
|
|
if (exp == NULL)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2012-03-28 15:09:42 +00:00
|
|
|
err = cache_check(cd, &exp->h, reqp);
|
2020-03-01 23:21:40 +00:00
|
|
|
if (err) {
|
|
|
|
trace_nfsd_exp_get_by_name(&key, err);
|
2007-07-17 11:04:40 +00:00
|
|
|
return ERR_PTR(err);
|
2020-03-01 23:21:40 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
return exp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the export entry for a given dentry.
|
|
|
|
*/
|
2014-05-23 12:55:43 +00:00
|
|
|
static struct svc_export *
|
|
|
|
exp_parent(struct cache_detail *cd, struct auth_domain *clp, struct path *path)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-04-18 06:14:32 +00:00
|
|
|
struct dentry *saved = dget(path->dentry);
|
2014-05-23 12:55:43 +00:00
|
|
|
struct svc_export *exp = exp_get_by_name(cd, clp, path, NULL);
|
2009-04-18 06:14:32 +00:00
|
|
|
|
|
|
|
while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) {
|
|
|
|
struct dentry *parent = dget_parent(path->dentry);
|
|
|
|
dput(path->dentry);
|
|
|
|
path->dentry = parent;
|
2012-03-28 15:09:42 +00:00
|
|
|
exp = exp_get_by_name(cd, clp, path, NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-04-18 06:14:32 +00:00
|
|
|
dput(path->dentry);
|
|
|
|
path->dentry = saved;
|
2005-04-16 22:20:36 +00:00
|
|
|
return exp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Obtain the root fh on behalf of a client.
|
|
|
|
* This could be done in user space, but I feel that it adds some safety
|
|
|
|
* since its harder to fool a kernel module than a user space program.
|
|
|
|
*/
|
|
|
|
int
|
2014-05-23 12:55:43 +00:00
|
|
|
exp_rootfh(struct net *net, struct auth_domain *clp, char *name,
|
2012-03-28 15:09:42 +00:00
|
|
|
struct knfsd_fh *f, int maxsize)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct svc_export *exp;
|
2008-08-02 05:03:36 +00:00
|
|
|
struct path path;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct inode *inode;
|
|
|
|
struct svc_fh fh;
|
|
|
|
int err;
|
2012-04-11 11:13:21 +00:00
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
struct cache_detail *cd = nn->svc_export_cache;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err = -EPERM;
|
|
|
|
/* NB: we probably ought to check that it's NUL-terminated */
|
2008-08-02 05:03:36 +00:00
|
|
|
if (kern_path(name, 0, &path)) {
|
|
|
|
printk("nfsd: exp_rootfh path not found %s", name);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
2015-03-17 22:25:59 +00:00
|
|
|
inode = d_inode(path.dentry);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
dprintk("nfsd: exp_rootfh(%s [%p] %s:%s/%ld)\n",
|
2008-08-02 05:03:36 +00:00
|
|
|
name, path.dentry, clp->name,
|
2005-04-16 22:20:36 +00:00
|
|
|
inode->i_sb->s_id, inode->i_ino);
|
2012-03-28 15:09:42 +00:00
|
|
|
exp = exp_parent(cd, clp, &path);
|
2006-12-13 08:35:21 +00:00
|
|
|
if (IS_ERR(exp)) {
|
|
|
|
err = PTR_ERR(exp);
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fh must be initialized before calling fh_compose
|
|
|
|
*/
|
|
|
|
fh_init(&fh, maxsize);
|
2008-08-02 05:03:36 +00:00
|
|
|
if (fh_compose(&fh, exp, path.dentry, NULL))
|
2005-04-16 22:20:36 +00:00
|
|
|
err = -EINVAL;
|
|
|
|
else
|
|
|
|
err = 0;
|
|
|
|
memcpy(f, &fh.fh_handle, sizeof(struct knfsd_fh));
|
|
|
|
fh_put(&fh);
|
|
|
|
exp_put(exp);
|
|
|
|
out:
|
2008-08-02 05:03:36 +00:00
|
|
|
path_put(&path);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-03-28 15:09:42 +00:00
|
|
|
static struct svc_export *exp_find(struct cache_detail *cd,
|
|
|
|
struct auth_domain *clp, int fsid_type,
|
2007-10-16 08:27:52 +00:00
|
|
|
u32 *fsidv, struct cache_req *reqp)
|
2006-03-27 09:15:00 +00:00
|
|
|
{
|
|
|
|
struct svc_export *exp;
|
2012-04-11 11:13:28 +00:00
|
|
|
struct nfsd_net *nn = net_generic(cd->net, nfsd_net_id);
|
|
|
|
struct svc_expkey *ek = exp_find_key(nn->svc_expkey_cache, clp, fsid_type, fsidv, reqp);
|
2007-07-17 11:04:40 +00:00
|
|
|
if (IS_ERR(ek))
|
2008-02-07 08:15:26 +00:00
|
|
|
return ERR_CAST(ek);
|
2006-03-27 09:15:00 +00:00
|
|
|
|
2012-03-28 15:09:42 +00:00
|
|
|
exp = exp_get_by_name(cd, clp, &ek->ek_path, reqp);
|
2012-04-11 11:13:28 +00:00
|
|
|
cache_put(&ek->h, nn->svc_expkey_cache);
|
2006-03-27 09:15:00 +00:00
|
|
|
|
2007-07-17 11:04:40 +00:00
|
|
|
if (IS_ERR(exp))
|
2008-02-07 08:15:26 +00:00
|
|
|
return ERR_CAST(exp);
|
2006-03-27 09:15:00 +00:00
|
|
|
return exp;
|
|
|
|
}
|
|
|
|
|
2007-07-17 11:04:48 +00:00
|
|
|
__be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp)
|
|
|
|
{
|
2023-04-20 17:56:31 +00:00
|
|
|
struct exp_flavor_info *f, *end = exp->ex_flavors + exp->ex_nflavors;
|
|
|
|
struct svc_xprt *xprt = rqstp->rq_xprt;
|
|
|
|
|
|
|
|
if (exp->ex_xprtsec_modes & NFSEXP_XPRTSEC_NONE) {
|
|
|
|
if (!test_bit(XPT_TLS_SESSION, &xprt->xpt_flags))
|
|
|
|
goto ok;
|
|
|
|
}
|
|
|
|
if (exp->ex_xprtsec_modes & NFSEXP_XPRTSEC_TLS) {
|
|
|
|
if (test_bit(XPT_TLS_SESSION, &xprt->xpt_flags) &&
|
|
|
|
!test_bit(XPT_PEER_AUTH, &xprt->xpt_flags))
|
|
|
|
goto ok;
|
|
|
|
}
|
|
|
|
if (exp->ex_xprtsec_modes & NFSEXP_XPRTSEC_MTLS) {
|
|
|
|
if (test_bit(XPT_TLS_SESSION, &xprt->xpt_flags) &&
|
|
|
|
test_bit(XPT_PEER_AUTH, &xprt->xpt_flags))
|
|
|
|
goto ok;
|
|
|
|
}
|
|
|
|
goto denied;
|
2007-07-17 11:04:48 +00:00
|
|
|
|
2023-04-20 17:56:31 +00:00
|
|
|
ok:
|
2007-07-17 11:04:48 +00:00
|
|
|
/* legacy gss-only clients are always OK: */
|
|
|
|
if (exp->ex_client == rqstp->rq_gssclient)
|
|
|
|
return 0;
|
|
|
|
/* ip-address based client; check sec= export option: */
|
|
|
|
for (f = exp->ex_flavors; f < end; f++) {
|
2012-05-15 02:06:49 +00:00
|
|
|
if (f->pseudoflavor == rqstp->rq_cred.cr_flavor)
|
2007-07-17 11:04:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* defaults in absence of sec= options: */
|
|
|
|
if (exp->ex_nflavors == 0) {
|
2012-05-15 02:06:49 +00:00
|
|
|
if (rqstp->rq_cred.cr_flavor == RPC_AUTH_NULL ||
|
|
|
|
rqstp->rq_cred.cr_flavor == RPC_AUTH_UNIX)
|
2007-07-17 11:04:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-06-15 16:52:09 +00:00
|
|
|
|
|
|
|
/* If the compound op contains a spo_must_allowed op,
|
|
|
|
* it will be sent with integrity/protection which
|
|
|
|
* will have to be expressly allowed on mounts that
|
|
|
|
* don't support it
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (nfsd4_spo_must_allow(rqstp))
|
|
|
|
return 0;
|
|
|
|
|
2023-04-20 17:56:31 +00:00
|
|
|
denied:
|
2020-10-01 23:00:00 +00:00
|
|
|
return rqstp->rq_vers < 4 ? nfserr_acces : nfserr_wrongsec;
|
2007-07-17 11:04:48 +00:00
|
|
|
}
|
|
|
|
|
2007-07-17 11:04:44 +00:00
|
|
|
/*
|
2007-07-17 11:04:46 +00:00
|
|
|
* Uses rq_client and rq_gssclient to find an export; uses rq_client (an
|
|
|
|
* auth_unix client) if it's available and has secinfo information;
|
|
|
|
* otherwise, will try to use rq_gssclient.
|
|
|
|
*
|
2007-07-17 11:04:44 +00:00
|
|
|
* Called from functions that handle requests; functions that do work on
|
|
|
|
* behalf of mountd are passed a single client name to use, and should
|
|
|
|
* use exp_get_by_name() or exp_find().
|
|
|
|
*/
|
|
|
|
struct svc_export *
|
2009-04-18 06:42:05 +00:00
|
|
|
rqst_exp_get_by_name(struct svc_rqst *rqstp, struct path *path)
|
2007-07-17 11:04:44 +00:00
|
|
|
{
|
2007-07-19 08:49:18 +00:00
|
|
|
struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT);
|
2012-07-25 12:57:06 +00:00
|
|
|
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
|
2012-04-11 11:13:21 +00:00
|
|
|
struct cache_detail *cd = nn->svc_export_cache;
|
2007-07-17 11:04:46 +00:00
|
|
|
|
|
|
|
if (rqstp->rq_client == NULL)
|
|
|
|
goto gss;
|
knfsd: nfsd: set rq_client to ip-address-determined-domain
We want it to be possible for users to restrict exports both by IP address and
by pseudoflavor. The pseudoflavor information has previously been passed
using special auth_domains stored in the rq_client field. After the preceding
patch that stored the pseudoflavor in rq_pflavor, that's now superfluous; so
now we use rq_client for the ip information, as auth_null and auth_unix do.
However, we keep around the special auth_domain in the rq_gssclient field for
backwards compatibility purposes, so we can still do upcalls using the old
"gss/pseudoflavor" auth_domain if upcalls using the unix domain to give us an
appropriate export. This allows us to continue supporting old mountd.
In fact, for this first patch, we always use the "gss/pseudoflavor"
auth_domain (and only it) if it is available; thus rq_client is ignored in the
auth_gss case, and this patch on its own makes no change in behavior; that
will be left to later patches.
Note on idmap: I'm almost tempted to just replace the auth_domain in the idmap
upcall by a dummy value--no version of idmapd has ever used it, and it's
unlikely anyone really wants to perform idmapping differently depending on the
where the client is (they may want to perform *credential* mapping
differently, but that's a different matter--the idmapper just handles id's
used in getattr and setattr). But I'm updating the idmapd code anyway, just
out of general backwards-compatibility paranoia.
Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-17 11:04:46 +00:00
|
|
|
|
2007-07-17 11:04:46 +00:00
|
|
|
/* First try the auth_unix client: */
|
2012-03-28 15:09:42 +00:00
|
|
|
exp = exp_get_by_name(cd, rqstp->rq_client, path, &rqstp->rq_chandle);
|
2007-07-17 11:04:46 +00:00
|
|
|
if (PTR_ERR(exp) == -ENOENT)
|
|
|
|
goto gss;
|
|
|
|
if (IS_ERR(exp))
|
|
|
|
return exp;
|
|
|
|
/* If it has secinfo, assume there are no gss/... clients */
|
|
|
|
if (exp->ex_nflavors > 0)
|
|
|
|
return exp;
|
|
|
|
gss:
|
|
|
|
/* Otherwise, try falling back on gss client */
|
|
|
|
if (rqstp->rq_gssclient == NULL)
|
|
|
|
return exp;
|
2012-03-28 15:09:42 +00:00
|
|
|
gssexp = exp_get_by_name(cd, rqstp->rq_gssclient, path, &rqstp->rq_chandle);
|
2007-07-17 11:04:46 +00:00
|
|
|
if (PTR_ERR(gssexp) == -ENOENT)
|
|
|
|
return exp;
|
2007-07-19 08:49:18 +00:00
|
|
|
if (!IS_ERR(exp))
|
2007-07-17 11:04:46 +00:00
|
|
|
exp_put(exp);
|
|
|
|
return gssexp;
|
2007-07-17 11:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct svc_export *
|
|
|
|
rqst_exp_find(struct svc_rqst *rqstp, int fsid_type, u32 *fsidv)
|
|
|
|
{
|
2007-07-19 08:49:18 +00:00
|
|
|
struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT);
|
2012-07-25 12:57:06 +00:00
|
|
|
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
|
2012-04-11 11:13:21 +00:00
|
|
|
struct cache_detail *cd = nn->svc_export_cache;
|
2007-07-17 11:04:46 +00:00
|
|
|
|
|
|
|
if (rqstp->rq_client == NULL)
|
|
|
|
goto gss;
|
knfsd: nfsd: set rq_client to ip-address-determined-domain
We want it to be possible for users to restrict exports both by IP address and
by pseudoflavor. The pseudoflavor information has previously been passed
using special auth_domains stored in the rq_client field. After the preceding
patch that stored the pseudoflavor in rq_pflavor, that's now superfluous; so
now we use rq_client for the ip information, as auth_null and auth_unix do.
However, we keep around the special auth_domain in the rq_gssclient field for
backwards compatibility purposes, so we can still do upcalls using the old
"gss/pseudoflavor" auth_domain if upcalls using the unix domain to give us an
appropriate export. This allows us to continue supporting old mountd.
In fact, for this first patch, we always use the "gss/pseudoflavor"
auth_domain (and only it) if it is available; thus rq_client is ignored in the
auth_gss case, and this patch on its own makes no change in behavior; that
will be left to later patches.
Note on idmap: I'm almost tempted to just replace the auth_domain in the idmap
upcall by a dummy value--no version of idmapd has ever used it, and it's
unlikely anyone really wants to perform idmapping differently depending on the
where the client is (they may want to perform *credential* mapping
differently, but that's a different matter--the idmapper just handles id's
used in getattr and setattr). But I'm updating the idmapd code anyway, just
out of general backwards-compatibility paranoia.
Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-17 11:04:46 +00:00
|
|
|
|
2007-07-17 11:04:46 +00:00
|
|
|
/* First try the auth_unix client: */
|
2012-03-28 15:09:42 +00:00
|
|
|
exp = exp_find(cd, rqstp->rq_client, fsid_type,
|
|
|
|
fsidv, &rqstp->rq_chandle);
|
2007-07-17 11:04:46 +00:00
|
|
|
if (PTR_ERR(exp) == -ENOENT)
|
|
|
|
goto gss;
|
|
|
|
if (IS_ERR(exp))
|
|
|
|
return exp;
|
|
|
|
/* If it has secinfo, assume there are no gss/... clients */
|
|
|
|
if (exp->ex_nflavors > 0)
|
|
|
|
return exp;
|
|
|
|
gss:
|
|
|
|
/* Otherwise, try falling back on gss client */
|
|
|
|
if (rqstp->rq_gssclient == NULL)
|
|
|
|
return exp;
|
2012-03-28 15:09:42 +00:00
|
|
|
gssexp = exp_find(cd, rqstp->rq_gssclient, fsid_type, fsidv,
|
2007-07-17 11:04:46 +00:00
|
|
|
&rqstp->rq_chandle);
|
|
|
|
if (PTR_ERR(gssexp) == -ENOENT)
|
|
|
|
return exp;
|
2007-07-19 08:49:18 +00:00
|
|
|
if (!IS_ERR(exp))
|
2007-07-17 11:04:46 +00:00
|
|
|
exp_put(exp);
|
|
|
|
return gssexp;
|
2007-07-17 11:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct svc_export *
|
2009-04-18 07:00:46 +00:00
|
|
|
rqst_exp_parent(struct svc_rqst *rqstp, struct path *path)
|
2007-07-17 11:04:44 +00:00
|
|
|
{
|
2009-04-18 07:00:46 +00:00
|
|
|
struct dentry *saved = dget(path->dentry);
|
|
|
|
struct svc_export *exp = rqst_exp_get_by_name(rqstp, path);
|
2007-07-17 11:04:46 +00:00
|
|
|
|
2009-04-18 07:00:46 +00:00
|
|
|
while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) {
|
|
|
|
struct dentry *parent = dget_parent(path->dentry);
|
|
|
|
dput(path->dentry);
|
|
|
|
path->dentry = parent;
|
|
|
|
exp = rqst_exp_get_by_name(rqstp, path);
|
2007-07-17 11:04:46 +00:00
|
|
|
}
|
2009-04-18 07:00:46 +00:00
|
|
|
dput(path->dentry);
|
|
|
|
path->dentry = saved;
|
2007-07-17 11:04:46 +00:00
|
|
|
return exp;
|
2007-07-17 11:04:44 +00:00
|
|
|
}
|
2006-03-27 09:15:00 +00:00
|
|
|
|
2011-09-12 23:37:06 +00:00
|
|
|
struct svc_export *rqst_find_fsidzero_export(struct svc_rqst *rqstp)
|
2009-09-27 18:41:43 +00:00
|
|
|
{
|
|
|
|
u32 fsidv[2];
|
|
|
|
|
|
|
|
mk_fsid(FSID_NUM, fsidv, 0, 0, 0, NULL);
|
|
|
|
|
2010-02-08 18:42:26 +00:00
|
|
|
return rqst_exp_find(rqstp, FSID_NUM, fsidv);
|
2009-09-27 18:41:43 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Called when we need the filehandle for the root of the pseudofs,
|
|
|
|
* for a given NFSv4 client. The root is defined to be the
|
|
|
|
* export point with fsid==0
|
|
|
|
*/
|
2006-10-20 06:29:02 +00:00
|
|
|
__be32
|
2007-07-17 11:04:43 +00:00
|
|
|
exp_pseudoroot(struct svc_rqst *rqstp, struct svc_fh *fhp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-03-27 09:15:00 +00:00
|
|
|
struct svc_export *exp;
|
2006-10-20 06:29:02 +00:00
|
|
|
__be32 rv;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-09-12 23:37:06 +00:00
|
|
|
exp = rqst_find_fsidzero_export(rqstp);
|
2006-12-13 08:35:23 +00:00
|
|
|
if (IS_ERR(exp))
|
|
|
|
return nfserrno(PTR_ERR(exp));
|
2008-02-15 03:38:39 +00:00
|
|
|
rv = fh_compose(fhp, exp, exp->ex_path.dentry, NULL);
|
2006-10-04 09:16:10 +00:00
|
|
|
exp_put(exp);
|
2005-04-16 22:20:36 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct flags {
|
|
|
|
int flag;
|
|
|
|
char *name[2];
|
|
|
|
} expflags[] = {
|
|
|
|
{ NFSEXP_READONLY, {"ro", "rw"}},
|
|
|
|
{ NFSEXP_INSECURE_PORT, {"insecure", ""}},
|
|
|
|
{ NFSEXP_ROOTSQUASH, {"root_squash", "no_root_squash"}},
|
|
|
|
{ NFSEXP_ALLSQUASH, {"all_squash", ""}},
|
|
|
|
{ NFSEXP_ASYNC, {"async", "sync"}},
|
|
|
|
{ NFSEXP_GATHERED_WRITES, {"wdelay", "no_wdelay"}},
|
nfsd: allow turning off nfsv3 readdir_plus
One of our customer's application only needs file names, not file
attributes. With directories having 10K+ inodes (assuming buffer cache
has directory blocks cached having file names, but inode cache is
limited and hence need eviction of older cached inodes), older inodes
are evicted periodically. So if they keep on doing readdir(2) from NSF
client on multiple directories, some directory's files are periodically
removed from inode cache and hence new readdir(2) on same directory
requires disk access to bring back inodes again to inode cache.
As READDIRPLUS request fetches attributes also, doing getattr on each
file on server, it causes unnecessary disk accesses. If READDIRPLUS on
NFS client is returned with -ENOTSUPP, NFS client uses READDIR request
which just gets the names of the files in a directory, not attributes,
hence avoiding disk accesses on server.
There's already a corresponding client-side mount option, but an export
option reduces the need for configuration across multiple clients.
This flag affects NFSv3 only. If it turns out it's needed for NFSv4 as
well then we may have to figure out how to extend the behavior to NFSv4,
but it's not currently obvious how to do that.
Signed-off-by: Rajesh Ghanekar <rajesh_ghanekar@symantec.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
2014-08-02 02:17:30 +00:00
|
|
|
{ NFSEXP_NOREADDIRPLUS, {"nordirplus", ""}},
|
2005-04-16 22:20:36 +00:00
|
|
|
{ NFSEXP_NOHIDE, {"nohide", ""}},
|
|
|
|
{ NFSEXP_CROSSMOUNT, {"crossmnt", ""}},
|
|
|
|
{ NFSEXP_NOSUBTREECHECK, {"no_subtree_check", ""}},
|
|
|
|
{ NFSEXP_NOAUTHNLM, {"insecure_locks", ""}},
|
nfsd: introduce export flag for v4 pseudoroot
NFSv4 differs from v2 and v3 in that it presents a single unified
filesystem tree, whereas v2 and v3 exported multiple filesystem (whose
roots could be found using a separate mount protocol).
Our original NFSv4 server implementation asked the administrator to
designate a single filesystem as the NFSv4 root, then to mount
filesystems they wished to export underneath. (Often using bind mounts
of already-existing filesystems.)
This was conceptually simple, and allowed easy implementation, but
created a serious obstacle to upgrading between v2/v3: since the paths
to v4 filesystems were different, administrators would have to adjust
all the paths in client-side mount commands when switching to v4.
Various workarounds are possible. For example, the administrator could
export "/" and designate it as the v4 root. However, the security risks
of that approach are obvious, and in any case we shouldn't be requiring
the administrator to take extra steps to fix this problem; instead, the
server should present consistent paths across different versions by
default.
These patches take a modified version of that approach: we provide a new
export option which exports only a subset of a filesystem. With this
flag, it becomes safe for mountd to export "/" by default, with no need
for additional configuration.
We begin just by defining the new flag.
Signed-off-by: Steve Dickson <steved@redhat.com>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
2009-09-09 18:58:22 +00:00
|
|
|
{ NFSEXP_V4ROOT, {"v4root", ""}},
|
2015-04-01 08:37:05 +00:00
|
|
|
{ NFSEXP_PNFS, {"pnfs", ""}},
|
2017-01-03 17:30:11 +00:00
|
|
|
{ NFSEXP_SECURITY_LABEL, {"security_label", ""}},
|
2005-04-16 22:20:36 +00:00
|
|
|
{ 0, {"", ""}}
|
|
|
|
};
|
|
|
|
|
2007-07-17 11:04:49 +00:00
|
|
|
static void show_expflags(struct seq_file *m, int flags, int mask)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct flags *flg;
|
2007-07-17 11:04:49 +00:00
|
|
|
int state, first = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (flg = expflags; flg->flag; flg++) {
|
2007-07-17 11:04:49 +00:00
|
|
|
if (flg->flag & ~mask)
|
|
|
|
continue;
|
|
|
|
state = (flg->flag & flags) ? 0 : 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (*flg->name[state])
|
|
|
|
seq_printf(m, "%s%s", first++?",":"", flg->name[state]);
|
|
|
|
}
|
2007-07-17 11:04:49 +00:00
|
|
|
}
|
|
|
|
|
2007-07-17 11:04:49 +00:00
|
|
|
static void show_secinfo_flags(struct seq_file *m, int flags)
|
|
|
|
{
|
|
|
|
seq_printf(m, ",");
|
|
|
|
show_expflags(m, flags, NFSEXP_SECINFO_FLAGS);
|
|
|
|
}
|
|
|
|
|
2010-09-24 21:43:59 +00:00
|
|
|
static bool secinfo_flags_equal(int f, int g)
|
|
|
|
{
|
|
|
|
f &= NFSEXP_SECINFO_FLAGS;
|
|
|
|
g &= NFSEXP_SECINFO_FLAGS;
|
|
|
|
return f == g;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int show_secinfo_run(struct seq_file *m, struct exp_flavor_info **fp, struct exp_flavor_info *end)
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
flags = (*fp)->flags;
|
|
|
|
seq_printf(m, ",sec=%d", (*fp)->pseudoflavor);
|
|
|
|
(*fp)++;
|
|
|
|
while (*fp != end && secinfo_flags_equal(flags, (*fp)->flags)) {
|
|
|
|
seq_printf(m, ":%d", (*fp)->pseudoflavor);
|
|
|
|
(*fp)++;
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2007-07-17 11:04:49 +00:00
|
|
|
static void show_secinfo(struct seq_file *m, struct svc_export *exp)
|
|
|
|
{
|
|
|
|
struct exp_flavor_info *f;
|
|
|
|
struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
|
2010-09-24 21:43:59 +00:00
|
|
|
int flags;
|
2007-07-17 11:04:49 +00:00
|
|
|
|
|
|
|
if (exp->ex_nflavors == 0)
|
|
|
|
return;
|
2010-09-24 21:43:59 +00:00
|
|
|
f = exp->ex_flavors;
|
|
|
|
flags = show_secinfo_run(m, &f, end);
|
|
|
|
if (!secinfo_flags_equal(flags, exp->ex_flags))
|
|
|
|
show_secinfo_flags(m, flags);
|
|
|
|
while (f != end) {
|
|
|
|
flags = show_secinfo_run(m, &f, end);
|
|
|
|
show_secinfo_flags(m, flags);
|
2007-07-17 11:04:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-17 11:04:49 +00:00
|
|
|
static void exp_flags(struct seq_file *m, int flag, int fsid,
|
2013-02-02 14:42:53 +00:00
|
|
|
kuid_t anonu, kgid_t anong, struct nfsd4_fs_locations *fsloc)
|
2007-07-17 11:04:49 +00:00
|
|
|
{
|
2019-04-09 16:13:42 +00:00
|
|
|
struct user_namespace *userns = m->file->f_cred->user_ns;
|
|
|
|
|
2007-07-17 11:04:49 +00:00
|
|
|
show_expflags(m, flag, NFSEXP_ALLFLAGS);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (flag & NFSEXP_FSID)
|
2007-07-17 11:04:49 +00:00
|
|
|
seq_printf(m, ",fsid=%d", fsid);
|
2019-04-09 16:13:42 +00:00
|
|
|
if (!uid_eq(anonu, make_kuid(userns, (uid_t)-2)) &&
|
|
|
|
!uid_eq(anonu, make_kuid(userns, 0x10000-2)))
|
|
|
|
seq_printf(m, ",anonuid=%u", from_kuid_munged(userns, anonu));
|
|
|
|
if (!gid_eq(anong, make_kgid(userns, (gid_t)-2)) &&
|
|
|
|
!gid_eq(anong, make_kgid(userns, 0x10000-2)))
|
|
|
|
seq_printf(m, ",anongid=%u", from_kgid_munged(userns, anong));
|
2006-10-04 09:16:18 +00:00
|
|
|
if (fsloc && fsloc->locations_count > 0) {
|
|
|
|
char *loctype = (fsloc->migrated) ? "refer" : "replicas";
|
|
|
|
int i;
|
|
|
|
|
2007-07-17 11:04:49 +00:00
|
|
|
seq_printf(m, ",%s=", loctype);
|
2006-10-04 09:16:18 +00:00
|
|
|
seq_escape(m, fsloc->locations[0].path, ",;@ \t\n\\");
|
|
|
|
seq_putc(m, '@');
|
|
|
|
seq_escape(m, fsloc->locations[0].hosts, ",;@ \t\n\\");
|
|
|
|
for (i = 1; i < fsloc->locations_count; i++) {
|
|
|
|
seq_putc(m, ';');
|
|
|
|
seq_escape(m, fsloc->locations[i].path, ",;@ \t\n\\");
|
|
|
|
seq_putc(m, '@');
|
|
|
|
seq_escape(m, fsloc->locations[i].hosts, ",;@ \t\n\\");
|
|
|
|
}
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int e_show(struct seq_file *m, void *p)
|
|
|
|
{
|
|
|
|
struct cache_head *cp = p;
|
|
|
|
struct svc_export *exp = container_of(cp, struct svc_export, h);
|
2012-03-28 15:09:29 +00:00
|
|
|
struct cache_detail *cd = m->private;
|
2021-01-06 07:52:36 +00:00
|
|
|
bool export_stats = is_export_stats_file(m);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-10-02 09:17:49 +00:00
|
|
|
if (p == SEQ_START_TOKEN) {
|
2005-04-16 22:20:36 +00:00
|
|
|
seq_puts(m, "# Version 1.1\n");
|
2021-01-06 07:52:36 +00:00
|
|
|
if (export_stats)
|
|
|
|
seq_puts(m, "# Path Client Start-time\n#\tStats\n");
|
|
|
|
else
|
|
|
|
seq_puts(m, "# Path Client(Flags) # IPs\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-10 14:06:44 +00:00
|
|
|
exp_get(exp);
|
2012-03-28 15:09:29 +00:00
|
|
|
if (cache_check(cd, &exp->h, NULL))
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
2012-03-28 15:09:22 +00:00
|
|
|
exp_put(exp);
|
2012-03-28 15:09:29 +00:00
|
|
|
return svc_export_show(m, cd, cp);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-09-22 23:43:43 +00:00
|
|
|
const struct seq_operations nfs_exports_op = {
|
2018-10-01 14:41:47 +00:00
|
|
|
.start = cache_seq_start_rcu,
|
|
|
|
.next = cache_seq_next_rcu,
|
|
|
|
.stop = cache_seq_stop_rcu,
|
2005-04-16 22:20:36 +00:00
|
|
|
.show = e_show,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the exports module.
|
|
|
|
*/
|
2007-11-08 22:20:34 +00:00
|
|
|
int
|
2012-04-11 11:13:14 +00:00
|
|
|
nfsd_export_init(struct net *net)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-11-08 22:20:34 +00:00
|
|
|
int rv;
|
2012-04-11 11:13:21 +00:00
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
|
2017-11-08 05:55:22 +00:00
|
|
|
dprintk("nfsd: initializing export module (net: %x).\n", net->ns.inum);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-04-11 11:13:21 +00:00
|
|
|
nn->svc_export_cache = cache_create_net(&svc_export_cache_template, net);
|
|
|
|
if (IS_ERR(nn->svc_export_cache))
|
|
|
|
return PTR_ERR(nn->svc_export_cache);
|
|
|
|
rv = cache_register_net(nn->svc_export_cache, net);
|
2007-11-08 22:20:34 +00:00
|
|
|
if (rv)
|
2012-04-11 11:13:21 +00:00
|
|
|
goto destroy_export_cache;
|
|
|
|
|
2012-04-11 11:13:28 +00:00
|
|
|
nn->svc_expkey_cache = cache_create_net(&svc_expkey_cache_template, net);
|
|
|
|
if (IS_ERR(nn->svc_expkey_cache)) {
|
|
|
|
rv = PTR_ERR(nn->svc_expkey_cache);
|
2012-04-11 11:13:21 +00:00
|
|
|
goto unregister_export_cache;
|
2012-04-11 11:13:28 +00:00
|
|
|
}
|
|
|
|
rv = cache_register_net(nn->svc_expkey_cache, net);
|
|
|
|
if (rv)
|
|
|
|
goto destroy_expkey_cache;
|
2012-04-11 11:13:21 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-04-11 11:13:28 +00:00
|
|
|
destroy_expkey_cache:
|
|
|
|
cache_destroy_net(nn->svc_expkey_cache, net);
|
2012-04-11 11:13:21 +00:00
|
|
|
unregister_export_cache:
|
|
|
|
cache_unregister_net(nn->svc_export_cache, net);
|
|
|
|
destroy_export_cache:
|
|
|
|
cache_destroy_net(nn->svc_export_cache, net);
|
|
|
|
return rv;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush exports table - called when last nfsd thread is killed
|
|
|
|
*/
|
|
|
|
void
|
2012-04-11 11:13:21 +00:00
|
|
|
nfsd_export_flush(struct net *net)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-04-11 11:13:21 +00:00
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
|
2012-04-11 11:13:28 +00:00
|
|
|
cache_purge(nn->svc_expkey_cache);
|
2012-04-11 11:13:21 +00:00
|
|
|
cache_purge(nn->svc_export_cache);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shutdown the exports module.
|
|
|
|
*/
|
|
|
|
void
|
2012-04-11 11:13:14 +00:00
|
|
|
nfsd_export_shutdown(struct net *net)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-04-11 11:13:21 +00:00
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-11-08 05:55:22 +00:00
|
|
|
dprintk("nfsd: shutting down export module (net: %x).\n", net->ns.inum);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-04-11 11:13:28 +00:00
|
|
|
cache_unregister_net(nn->svc_expkey_cache, net);
|
2012-04-11 11:13:21 +00:00
|
|
|
cache_unregister_net(nn->svc_export_cache, net);
|
2012-04-11 11:13:28 +00:00
|
|
|
cache_destroy_net(nn->svc_expkey_cache, net);
|
2012-04-11 11:13:21 +00:00
|
|
|
cache_destroy_net(nn->svc_export_cache, net);
|
2012-04-11 11:13:28 +00:00
|
|
|
svcauth_unix_purge(net);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-11-08 05:55:22 +00:00
|
|
|
dprintk("nfsd: export shutdown complete (net: %x).\n", net->ns.inum);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|