Skip to content

Commit 946af9b

Browse files
Mike SnitzerAnna Schumaker
authored andcommitted
nfsd: implement server support for NFS_LOCALIO_PROGRAM
The LOCALIO auxiliary RPC protocol consists of a single "UUID_IS_LOCAL" RPC method that allows the Linux NFS client to verify the local Linux NFS server can see the nonce (single-use UUID) the client generated and made available in nfs_common. The server expects this protocol to use the same transport as NFS and NFSACL for its RPCs. This protocol isn't part of an IETF standard, nor does it need to be considering it is Linux-to-Linux auxiliary RPC protocol that amounts to an implementation detail. The UUID_IS_LOCAL method encodes the client generated uuid_t in terms of the fixed UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR methods are used instead of the less efficient variable sized methods. The RPC program number for the NFS_LOCALIO_PROGRAM is 400122 (as assigned by IANA, see https://www.iana.org/assignments/rpc-program-numbers/ ): Linux Kernel Organization 400122 nfslocalio Signed-off-by: Mike Snitzer <snitzer@kernel.org> [neilb: factored out and simplified single localio protocol] Co-developed-by: NeilBrown <neilb@suse.de> Signed-off-by: NeilBrown <neilb@suse.de> Acked-by: Chuck Lever <chuck.lever@oracle.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
1 parent fa49838 commit 946af9b

File tree

4 files changed

+110
-1
lines changed

4 files changed

+110
-1
lines changed

fs/nfsd/localio.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
#include <linux/nfs.h>
1515
#include <linux/nfs_common.h>
1616
#include <linux/nfslocalio.h>
17+
#include <linux/nfs_fs.h>
18+
#include <linux/nfs_xdr.h>
1719
#include <linux/string.h>
1820

1921
#include "nfsd.h"
2022
#include "vfs.h"
2123
#include "netns.h"
2224
#include "filecache.h"
25+
#include "cache.h"
2326

2427
static const struct nfsd_localio_operations nfsd_localio_ops = {
2528
.nfsd_serv_try_get = nfsd_serv_try_get,
@@ -90,3 +93,77 @@ nfsd_open_local_fh(struct net *net, struct auth_domain *dom,
9093
return localio;
9194
}
9295
EXPORT_SYMBOL_GPL(nfsd_open_local_fh);
96+
97+
/*
98+
* UUID_IS_LOCAL XDR functions
99+
*/
100+
101+
static __be32 localio_proc_null(struct svc_rqst *rqstp)
102+
{
103+
return rpc_success;
104+
}
105+
106+
struct localio_uuidarg {
107+
uuid_t uuid;
108+
};
109+
110+
static __be32 localio_proc_uuid_is_local(struct svc_rqst *rqstp)
111+
{
112+
struct localio_uuidarg *argp = rqstp->rq_argp;
113+
struct net *net = SVC_NET(rqstp);
114+
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
115+
116+
nfs_uuid_is_local(&argp->uuid, &nn->local_clients,
117+
net, rqstp->rq_client, THIS_MODULE);
118+
119+
return rpc_success;
120+
}
121+
122+
static bool localio_decode_uuidarg(struct svc_rqst *rqstp,
123+
struct xdr_stream *xdr)
124+
{
125+
struct localio_uuidarg *argp = rqstp->rq_argp;
126+
u8 uuid[UUID_SIZE];
127+
128+
if (decode_opaque_fixed(xdr, uuid, UUID_SIZE))
129+
return false;
130+
import_uuid(&argp->uuid, uuid);
131+
132+
return true;
133+
}
134+
135+
static const struct svc_procedure localio_procedures1[] = {
136+
[LOCALIOPROC_NULL] = {
137+
.pc_func = localio_proc_null,
138+
.pc_decode = nfssvc_decode_voidarg,
139+
.pc_encode = nfssvc_encode_voidres,
140+
.pc_argsize = sizeof(struct nfsd_voidargs),
141+
.pc_ressize = sizeof(struct nfsd_voidres),
142+
.pc_cachetype = RC_NOCACHE,
143+
.pc_xdrressize = 0,
144+
.pc_name = "NULL",
145+
},
146+
[LOCALIOPROC_UUID_IS_LOCAL] = {
147+
.pc_func = localio_proc_uuid_is_local,
148+
.pc_decode = localio_decode_uuidarg,
149+
.pc_encode = nfssvc_encode_voidres,
150+
.pc_argsize = sizeof(struct localio_uuidarg),
151+
.pc_argzero = sizeof(struct localio_uuidarg),
152+
.pc_ressize = sizeof(struct nfsd_voidres),
153+
.pc_cachetype = RC_NOCACHE,
154+
.pc_name = "UUID_IS_LOCAL",
155+
},
156+
};
157+
158+
#define LOCALIO_NR_PROCEDURES ARRAY_SIZE(localio_procedures1)
159+
static DEFINE_PER_CPU_ALIGNED(unsigned long,
160+
localio_count[LOCALIO_NR_PROCEDURES]);
161+
const struct svc_version localio_version1 = {
162+
.vs_vers = 1,
163+
.vs_nproc = LOCALIO_NR_PROCEDURES,
164+
.vs_proc = localio_procedures1,
165+
.vs_dispatch = nfsd_dispatch,
166+
.vs_count = localio_count,
167+
.vs_xdrsize = XDR_QUADLEN(UUID_SIZE),
168+
.vs_hidden = true,
169+
};

fs/nfsd/nfsd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ extern const struct svc_version nfsd_acl_version3;
146146
#endif
147147
#endif
148148

149+
#if IS_ENABLED(CONFIG_NFS_LOCALIO)
150+
extern const struct svc_version localio_version1;
151+
#endif
152+
149153
struct nfsd_net;
150154

151155
enum vers_op {NFSD_SET, NFSD_CLEAR, NFSD_TEST, NFSD_AVAIL };

fs/nfsd/nfssvc.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ DEFINE_SPINLOCK(nfsd_drc_lock);
8080
unsigned long nfsd_drc_max_mem;
8181
unsigned long nfsd_drc_mem_used;
8282

83+
#if IS_ENABLED(CONFIG_NFS_LOCALIO)
84+
static const struct svc_version *localio_versions[] = {
85+
[1] = &localio_version1,
86+
};
87+
88+
#define NFSD_LOCALIO_NRVERS ARRAY_SIZE(localio_versions)
89+
90+
#endif /* CONFIG_NFS_LOCALIO */
91+
8392
#if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
8493
static const struct svc_version *nfsd_acl_version[] = {
8594
# if defined(CONFIG_NFSD_V2_ACL)
@@ -128,6 +137,18 @@ struct svc_program nfsd_programs[] = {
128137
.pg_rpcbind_set = nfsd_acl_rpcbind_set,
129138
},
130139
#endif /* defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) */
140+
#if IS_ENABLED(CONFIG_NFS_LOCALIO)
141+
{
142+
.pg_prog = NFS_LOCALIO_PROGRAM,
143+
.pg_nvers = NFSD_LOCALIO_NRVERS,
144+
.pg_vers = localio_versions,
145+
.pg_name = "nfslocalio",
146+
.pg_class = "nfsd",
147+
.pg_authenticate = svc_set_client,
148+
.pg_init_request = svc_generic_init_request,
149+
.pg_rpcbind_set = svc_generic_rpcbind_set,
150+
}
151+
#endif /* CONFIG_NFS_LOCALIO */
131152
};
132153

133154
bool nfsd_support_version(int vers)
@@ -949,7 +970,7 @@ nfsd(void *vrqstp)
949970
}
950971

951972
/**
952-
* nfsd_dispatch - Process an NFS or NFSACL Request
973+
* nfsd_dispatch - Process an NFS or NFSACL or LOCALIO Request
953974
* @rqstp: incoming request
954975
*
955976
* This RPC dispatcher integrates the NFS server's duplicate reply cache.

include/linux/nfs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
#include <linux/crc32.h>
1414
#include <uapi/linux/nfs.h>
1515

16+
/* The LOCALIO program is entirely private to Linux and is
17+
* NOT part of the uapi.
18+
*/
19+
#define NFS_LOCALIO_PROGRAM 400122
20+
#define LOCALIOPROC_NULL 0
21+
#define LOCALIOPROC_UUID_IS_LOCAL 1
22+
1623
/*
1724
* This is the kernel NFS client file handle representation
1825
*/

0 commit comments

Comments
 (0)