Skip to content

Commit 2a33a85

Browse files
Mike SnitzerAnna Schumaker
authored andcommitted
nfs_common: add NFS LOCALIO auxiliary protocol enablement
fs/nfs_common/nfslocalio.c provides interfaces that enable an NFS client to generate a nonce (single-use UUID) and associated nfs_uuid_t struct, register it with nfs_common for subsequent lookup and verification by the NFS server and if matched the NFS server populates members in the nfs_uuid_t struct. nfs_common's nfs_uuids list is the basis for localio enablement, as such it has members that point to nfsd memory for direct use by the client (e.g. 'net' is the server's network namespace, through it the client can access nn->nfsd_serv). This commit also provides the base nfs_uuid_t interfaces to allow proper net namespace refcounting for the LOCALIO use case. CONFIG_NFS_LOCALIO controls the nfs_common, NFS server and NFS client enablement for LOCALIO. If both NFS_FS=m and NFSD=m then NFS_COMMON_LOCALIO_SUPPORT=m and nfs_localio.ko is built (and provides nfs_common's LOCALIO support). # lsmod | grep nfs_localio nfs_localio 12288 2 nfsd,nfs sunrpc 745472 35 nfs_localio,nfsd,auth_rpcgss,lockd,nfsv3,nfs Signed-off-by: Mike Snitzer <snitzer@kernel.org> Co-developed-by: NeilBrown <neilb@suse.de> Signed-off-by: NeilBrown <neilb@suse.de> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
1 parent 86ab08b commit 2a33a85

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed

fs/Kconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,29 @@ config NFS_COMMON
382382
depends on NFSD || NFS_FS || LOCKD
383383
default y
384384

385+
config NFS_COMMON_LOCALIO_SUPPORT
386+
tristate
387+
default n
388+
default y if NFSD=y || NFS_FS=y
389+
default m if NFSD=m && NFS_FS=m
390+
select SUNRPC
391+
392+
config NFS_LOCALIO
393+
bool "NFS client and server support for LOCALIO auxiliary protocol"
394+
depends on NFSD && NFS_FS
395+
select NFS_COMMON_LOCALIO_SUPPORT
396+
default n
397+
help
398+
Some NFS servers support an auxiliary NFS LOCALIO protocol
399+
that is not an official part of the NFS protocol.
400+
401+
This option enables support for the LOCALIO protocol in the
402+
kernel's NFS server and client. Enable this to permit local
403+
NFS clients to bypass the network when issuing reads and
404+
writes to the local NFS server.
405+
406+
If unsure, say N.
407+
385408
config NFS_V4_2_SSC_HELPER
386409
bool
387410
default y if NFS_V4_2

fs/nfs_common/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
obj-$(CONFIG_NFS_ACL_SUPPORT) += nfs_acl.o
77
nfs_acl-objs := nfsacl.o
88

9+
obj-$(CONFIG_NFS_COMMON_LOCALIO_SUPPORT) += nfs_localio.o
10+
nfs_localio-objs := nfslocalio.o
11+
912
obj-$(CONFIG_GRACE_PERIOD) += grace.o
1013
obj-$(CONFIG_NFS_V4_2_SSC_HELPER) += nfs_ssc.o
1114

fs/nfs_common/nfslocalio.c

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright (C) 2024 Mike Snitzer <snitzer@hammerspace.com>
4+
* Copyright (C) 2024 NeilBrown <neilb@suse.de>
5+
*/
6+
7+
#include <linux/module.h>
8+
#include <linux/rculist.h>
9+
#include <linux/nfslocalio.h>
10+
#include <net/netns/generic.h>
11+
12+
MODULE_LICENSE("GPL");
13+
MODULE_DESCRIPTION("NFS localio protocol bypass support");
14+
15+
static DEFINE_SPINLOCK(nfs_uuid_lock);
16+
17+
/*
18+
* Global list of nfs_uuid_t instances
19+
* that is protected by nfs_uuid_lock.
20+
*/
21+
static LIST_HEAD(nfs_uuids);
22+
23+
void nfs_uuid_begin(nfs_uuid_t *nfs_uuid)
24+
{
25+
nfs_uuid->net = NULL;
26+
nfs_uuid->dom = NULL;
27+
uuid_gen(&nfs_uuid->uuid);
28+
29+
spin_lock(&nfs_uuid_lock);
30+
list_add_tail_rcu(&nfs_uuid->list, &nfs_uuids);
31+
spin_unlock(&nfs_uuid_lock);
32+
}
33+
EXPORT_SYMBOL_GPL(nfs_uuid_begin);
34+
35+
void nfs_uuid_end(nfs_uuid_t *nfs_uuid)
36+
{
37+
if (nfs_uuid->net == NULL) {
38+
spin_lock(&nfs_uuid_lock);
39+
list_del_init(&nfs_uuid->list);
40+
spin_unlock(&nfs_uuid_lock);
41+
}
42+
}
43+
EXPORT_SYMBOL_GPL(nfs_uuid_end);
44+
45+
static nfs_uuid_t * nfs_uuid_lookup_locked(const uuid_t *uuid)
46+
{
47+
nfs_uuid_t *nfs_uuid;
48+
49+
list_for_each_entry(nfs_uuid, &nfs_uuids, list)
50+
if (uuid_equal(&nfs_uuid->uuid, uuid))
51+
return nfs_uuid;
52+
53+
return NULL;
54+
}
55+
56+
static struct module *nfsd_mod;
57+
58+
void nfs_uuid_is_local(const uuid_t *uuid, struct list_head *list,
59+
struct net *net, struct auth_domain *dom,
60+
struct module *mod)
61+
{
62+
nfs_uuid_t *nfs_uuid;
63+
64+
spin_lock(&nfs_uuid_lock);
65+
nfs_uuid = nfs_uuid_lookup_locked(uuid);
66+
if (nfs_uuid) {
67+
kref_get(&dom->ref);
68+
nfs_uuid->dom = dom;
69+
/*
70+
* We don't hold a ref on the net, but instead put
71+
* ourselves on a list so the net pointer can be
72+
* invalidated.
73+
*/
74+
list_move(&nfs_uuid->list, list);
75+
nfs_uuid->net = net;
76+
77+
__module_get(mod);
78+
nfsd_mod = mod;
79+
}
80+
spin_unlock(&nfs_uuid_lock);
81+
}
82+
EXPORT_SYMBOL_GPL(nfs_uuid_is_local);
83+
84+
static void nfs_uuid_put_locked(nfs_uuid_t *nfs_uuid)
85+
{
86+
if (nfs_uuid->net) {
87+
module_put(nfsd_mod);
88+
nfs_uuid->net = NULL;
89+
}
90+
if (nfs_uuid->dom) {
91+
auth_domain_put(nfs_uuid->dom);
92+
nfs_uuid->dom = NULL;
93+
}
94+
list_del_init(&nfs_uuid->list);
95+
}
96+
97+
void nfs_uuid_invalidate_clients(struct list_head *list)
98+
{
99+
nfs_uuid_t *nfs_uuid, *tmp;
100+
101+
spin_lock(&nfs_uuid_lock);
102+
list_for_each_entry_safe(nfs_uuid, tmp, list, list)
103+
nfs_uuid_put_locked(nfs_uuid);
104+
spin_unlock(&nfs_uuid_lock);
105+
}
106+
EXPORT_SYMBOL_GPL(nfs_uuid_invalidate_clients);
107+
108+
void nfs_uuid_invalidate_one_client(nfs_uuid_t *nfs_uuid)
109+
{
110+
if (nfs_uuid->net) {
111+
spin_lock(&nfs_uuid_lock);
112+
nfs_uuid_put_locked(nfs_uuid);
113+
spin_unlock(&nfs_uuid_lock);
114+
}
115+
}
116+
EXPORT_SYMBOL_GPL(nfs_uuid_invalidate_one_client);

include/linux/nfslocalio.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (C) 2024 Mike Snitzer <snitzer@hammerspace.com>
4+
* Copyright (C) 2024 NeilBrown <neilb@suse.de>
5+
*/
6+
#ifndef __LINUX_NFSLOCALIO_H
7+
#define __LINUX_NFSLOCALIO_H
8+
9+
#include <linux/module.h>
10+
#include <linux/list.h>
11+
#include <linux/uuid.h>
12+
#include <linux/sunrpc/svcauth.h>
13+
#include <linux/nfs.h>
14+
#include <net/net_namespace.h>
15+
16+
/*
17+
* Useful to allow a client to negotiate if localio
18+
* possible with its server.
19+
*
20+
* See Documentation/filesystems/nfs/localio.rst for more detail.
21+
*/
22+
typedef struct {
23+
uuid_t uuid;
24+
struct list_head list;
25+
struct net *net; /* nfsd's network namespace */
26+
struct auth_domain *dom; /* auth_domain for localio */
27+
} nfs_uuid_t;
28+
29+
void nfs_uuid_begin(nfs_uuid_t *);
30+
void nfs_uuid_end(nfs_uuid_t *);
31+
void nfs_uuid_is_local(const uuid_t *, struct list_head *,
32+
struct net *, struct auth_domain *, struct module *);
33+
void nfs_uuid_invalidate_clients(struct list_head *list);
34+
void nfs_uuid_invalidate_one_client(nfs_uuid_t *nfs_uuid);
35+
36+
#endif /* __LINUX_NFSLOCALIO_H */

0 commit comments

Comments
 (0)