Skip to content

Commit 56bcd0f

Browse files
Mike SnitzerAnna Schumaker
authored andcommitted
nfs: implement client 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 for subsequent lookup and verification by the NFS server. If matched, the NFS server populates members in the nfs_uuid_t struct. The NFS client then transfers these nfs_uuid_t struct member pointers to the nfs_client struct and cleans up the nfs_uuid_t struct. See: fs/nfs/localio.c:nfs_local_probe() 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. Localio is only supported when UNIX-style authentication (AUTH_UNIX, aka AUTH_SYS) is used (enforced by fs/nfs/localio.c:nfs_local_probe()). 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. Having a nonce (single-use uuid) is better than using the same uuid for the life of the server, and sending it proactively by client rather than reactively by the server is also safer. 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 b9f5dd5 commit 56bcd0f

File tree

2 files changed

+132
-6
lines changed

2 files changed

+132
-6
lines changed

fs/nfs/client.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,10 @@ struct nfs_client *nfs_get_client(const struct nfs_client_initdata *cl_init)
434434
list_add_tail(&new->cl_share_link,
435435
&nn->nfs_client_list);
436436
spin_unlock(&nn->nfs_client_lock);
437-
nfs_local_probe(new);
438-
return rpc_ops->init_client(new, cl_init);
437+
new = rpc_ops->init_client(new, cl_init);
438+
if (!IS_ERR(new))
439+
nfs_local_probe(new);
440+
return new;
439441
}
440442

441443
spin_unlock(&nn->nfs_client_lock);

fs/nfs/localio.c

Lines changed: 128 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,77 @@ static void nfs_local_fsync_work(struct work_struct *work);
5151
static bool localio_enabled __read_mostly = true;
5252
module_param(localio_enabled, bool, 0644);
5353

54+
static inline bool nfs_client_is_local(const struct nfs_client *clp)
55+
{
56+
return !!test_bit(NFS_CS_LOCAL_IO, &clp->cl_flags);
57+
}
58+
5459
bool nfs_server_is_local(const struct nfs_client *clp)
5560
{
56-
return test_bit(NFS_CS_LOCAL_IO, &clp->cl_flags) != 0 &&
57-
localio_enabled;
61+
return nfs_client_is_local(clp) && localio_enabled;
5862
}
5963
EXPORT_SYMBOL_GPL(nfs_server_is_local);
6064

65+
/*
66+
* UUID_IS_LOCAL XDR functions
67+
*/
68+
69+
static void localio_xdr_enc_uuidargs(struct rpc_rqst *req,
70+
struct xdr_stream *xdr,
71+
const void *data)
72+
{
73+
const u8 *uuid = data;
74+
75+
encode_opaque_fixed(xdr, uuid, UUID_SIZE);
76+
}
77+
78+
static int localio_xdr_dec_uuidres(struct rpc_rqst *req,
79+
struct xdr_stream *xdr,
80+
void *result)
81+
{
82+
/* void return */
83+
return 0;
84+
}
85+
86+
static const struct rpc_procinfo nfs_localio_procedures[] = {
87+
[LOCALIOPROC_UUID_IS_LOCAL] = {
88+
.p_proc = LOCALIOPROC_UUID_IS_LOCAL,
89+
.p_encode = localio_xdr_enc_uuidargs,
90+
.p_decode = localio_xdr_dec_uuidres,
91+
.p_arglen = XDR_QUADLEN(UUID_SIZE),
92+
.p_replen = 0,
93+
.p_statidx = LOCALIOPROC_UUID_IS_LOCAL,
94+
.p_name = "UUID_IS_LOCAL",
95+
},
96+
};
97+
98+
static unsigned int nfs_localio_counts[ARRAY_SIZE(nfs_localio_procedures)];
99+
static const struct rpc_version nfslocalio_version1 = {
100+
.number = 1,
101+
.nrprocs = ARRAY_SIZE(nfs_localio_procedures),
102+
.procs = nfs_localio_procedures,
103+
.counts = nfs_localio_counts,
104+
};
105+
106+
static const struct rpc_version *nfslocalio_version[] = {
107+
[1] = &nfslocalio_version1,
108+
};
109+
110+
extern const struct rpc_program nfslocalio_program;
111+
static struct rpc_stat nfslocalio_rpcstat = { &nfslocalio_program };
112+
113+
const struct rpc_program nfslocalio_program = {
114+
.name = "nfslocalio",
115+
.number = NFS_LOCALIO_PROGRAM,
116+
.nrvers = ARRAY_SIZE(nfslocalio_version),
117+
.version = nfslocalio_version,
118+
.stats = &nfslocalio_rpcstat,
119+
};
120+
61121
/*
62122
* nfs_local_enable - enable local i/o for an nfs_client
63123
*/
64-
static __maybe_unused void nfs_local_enable(struct nfs_client *clp)
124+
static void nfs_local_enable(struct nfs_client *clp)
65125
{
66126
spin_lock(&clp->cl_localio_lock);
67127
set_bit(NFS_CS_LOCAL_IO, &clp->cl_flags);
@@ -82,11 +142,74 @@ void nfs_local_disable(struct nfs_client *clp)
82142
spin_unlock(&clp->cl_localio_lock);
83143
}
84144

145+
/*
146+
* nfs_init_localioclient - Initialise an NFS localio client connection
147+
*/
148+
static struct rpc_clnt *nfs_init_localioclient(struct nfs_client *clp)
149+
{
150+
struct rpc_clnt *rpcclient_localio;
151+
152+
rpcclient_localio = rpc_bind_new_program(clp->cl_rpcclient,
153+
&nfslocalio_program, 1);
154+
155+
dprintk_rcu("%s: server (%s) %s NFS LOCALIO.\n",
156+
__func__, rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR),
157+
(IS_ERR(rpcclient_localio) ? "does not support" : "supports"));
158+
159+
return rpcclient_localio;
160+
}
161+
162+
static bool nfs_server_uuid_is_local(struct nfs_client *clp)
163+
{
164+
u8 uuid[UUID_SIZE];
165+
struct rpc_message msg = {
166+
.rpc_argp = &uuid,
167+
};
168+
struct rpc_clnt *rpcclient_localio;
169+
int status;
170+
171+
rpcclient_localio = nfs_init_localioclient(clp);
172+
if (IS_ERR(rpcclient_localio))
173+
return false;
174+
175+
export_uuid(uuid, &clp->cl_uuid.uuid);
176+
177+
msg.rpc_proc = &nfs_localio_procedures[LOCALIOPROC_UUID_IS_LOCAL];
178+
status = rpc_call_sync(rpcclient_localio, &msg, 0);
179+
dprintk("%s: NFS reply UUID_IS_LOCAL: status=%d\n",
180+
__func__, status);
181+
rpc_shutdown_client(rpcclient_localio);
182+
183+
/* Server is only local if it initialized required struct members */
184+
if (status || !clp->cl_uuid.net || !clp->cl_uuid.dom)
185+
return false;
186+
187+
return true;
188+
}
189+
85190
/*
86191
* nfs_local_probe - probe local i/o support for an nfs_server and nfs_client
192+
* - called after alloc_client and init_client (so cl_rpcclient exists)
193+
* - this function is idempotent, it can be called for old or new clients
87194
*/
88195
void nfs_local_probe(struct nfs_client *clp)
89196
{
197+
/* Disallow localio if disabled via sysfs or AUTH_SYS isn't used */
198+
if (!localio_enabled ||
199+
clp->cl_rpcclient->cl_auth->au_flavor != RPC_AUTH_UNIX) {
200+
nfs_local_disable(clp);
201+
return;
202+
}
203+
204+
if (nfs_client_is_local(clp)) {
205+
/* If already enabled, disable and re-enable */
206+
nfs_local_disable(clp);
207+
}
208+
209+
nfs_uuid_begin(&clp->cl_uuid);
210+
if (nfs_server_uuid_is_local(clp))
211+
nfs_local_enable(clp);
212+
nfs_uuid_end(&clp->cl_uuid);
90213
}
91214
EXPORT_SYMBOL_GPL(nfs_local_probe);
92215

@@ -116,7 +239,8 @@ nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred,
116239
case -ENOMEM:
117240
case -ENXIO:
118241
case -ENOENT:
119-
nfs_local_disable(clp);
242+
/* Revalidate localio, will disable if unsupported */
243+
nfs_local_probe(clp);
120244
}
121245
return NULL;
122246
}

0 commit comments

Comments
 (0)