| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* client.c: NFS client sharing and management code |
| 3 |
* |
| 4 |
* Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. |
| 5 |
* Written by David Howells ([email protected]) |
| 6 |
*/ |
| 7 |
|
| 8 |
|
| 9 |
#include <linux/module.h> |
| 10 |
#include <linux/init.h> |
| 11 |
#include <linux/sched.h> |
| 12 |
#include <linux/time.h> |
| 13 |
#include <linux/kernel.h> |
| 14 |
#include <linux/mm.h> |
| 15 |
#include <linux/string.h> |
| 16 |
#include <linux/stat.h> |
| 17 |
#include <linux/errno.h> |
| 18 |
#include <linux/unistd.h> |
| 19 |
#include <linux/sunrpc/addr.h> |
| 20 |
#include <linux/sunrpc/clnt.h> |
| 21 |
#include <linux/sunrpc/stats.h> |
| 22 |
#include <linux/sunrpc/metrics.h> |
| 23 |
#include <linux/sunrpc/xprtsock.h> |
| 24 |
#include <linux/sunrpc/xprtrdma.h> |
| 25 |
#include <linux/nfs_fs.h> |
| 26 |
#include <linux/nfs_mount.h> |
| 27 |
#include <linux/nfs4_mount.h> |
| 28 |
#include <linux/lockd/bind.h> |
| 29 |
#include <linux/seq_file.h> |
| 30 |
#include <linux/mount.h> |
| 31 |
#include <linux/vfs.h> |
| 32 |
#include <linux/inet.h> |
| 33 |
#include <linux/in6.h> |
| 34 |
#include <linux/slab.h> |
| 35 |
#include <linux/idr.h> |
| 36 |
#include <net/ipv6.h> |
| 37 |
#include <linux/nfs_xdr.h> |
| 38 |
#include <linux/sunrpc/bc_xprt.h> |
| 39 |
#include <linux/nsproxy.h> |
| 40 |
#include <linux/pid_namespace.h> |
| 41 |
#include <linux/nfslocalio.h> |
| 42 |
|
| 43 |
#include "nfs4_fs.h" |
| 44 |
#include "callback.h" |
| 45 |
#include "delegation.h" |
| 46 |
#include "iostat.h" |
| 47 |
#include "internal.h" |
| 48 |
#include "fscache.h" |
| 49 |
#include "pnfs.h" |
| 50 |
#include "nfs.h" |
| 51 |
#include "netns.h" |
| 52 |
#include "sysfs.h" |
| 53 |
#include "nfs42.h" |
| 54 |
|
| 55 |
#define NFSDBG_FACILITY NFSDBG_CLIENT |
| 56 |
|
| 57 |
static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); |
| 58 |
static DEFINE_RWLOCK(nfs_version_lock); |
| 59 |
|
| 60 |
static struct nfs_subversion *nfs_version_mods[5] = { |
| 61 |
[2] = NULL, |
| 62 |
[3] = NULL, |
| 63 |
[4] = NULL, |
| 64 |
}; |
| 65 |
|
| 66 |
/* |
| 67 |
* RPC cruft for NFS |
| 68 |
*/ |
| 69 |
static const struct rpc_version *nfs_version[5] = { |
| 70 |
[2] = NULL, |
| 71 |
[3] = NULL, |
| 72 |
[4] = NULL, |
| 73 |
}; |
| 74 |
|
| 75 |
const struct rpc_program nfs_program = { |
| 76 |
.name = "nfs", |
| 77 |
.number = NFS_PROGRAM, |
| 78 |
.nrvers = ARRAY_SIZE(nfs_version), |
| 79 |
.version = nfs_version, |
| 80 |
.pipe_dir_name = NFS_PIPE_DIRNAME, |
| 81 |
}; |
| 82 |
|
| 83 |
static struct nfs_subversion *__find_nfs_version(unsigned int version) |
| 84 |
{ |
| 85 |
struct nfs_subversion *nfs; |
| 86 |
|
| 87 |
read_lock(&nfs_version_lock); |
| 88 |
nfs = nfs_version_mods[version]; |
| 89 |
read_unlock(&nfs_version_lock); |
| 90 |
return nfs; |
| 91 |
} |
| 92 |
|
| 93 |
struct nfs_subversion *find_nfs_version(unsigned int version) |
| 94 |
{ |
| 95 |
struct nfs_subversion *nfs = __find_nfs_version(version); |
| 96 |
|
| 97 |
if (!nfs && request_module("nfsv%d", version) == 0) |
| 98 |
nfs = __find_nfs_version(version); |
| 99 |
|
| 100 |
if (!nfs) |
| 101 |
return ERR_PTR(-EPROTONOSUPPORT); |
| 102 |
|
| 103 |
if (!get_nfs_version(nfs)) |
| 104 |
return ERR_PTR(-EAGAIN); |
| 105 |
|
| 106 |
return nfs; |
| 107 |
} |
| 108 |
|
| 109 |
int get_nfs_version(struct nfs_subversion *nfs) |
| 110 |
{ |
| 111 |
return try_module_get(nfs->owner); |
| 112 |
} |
| 113 |
EXPORT_SYMBOL_GPL(get_nfs_version); |
| 114 |
|
| 115 |
void put_nfs_version(struct nfs_subversion *nfs) |
| 116 |
{ |
| 117 |
module_put(nfs->owner); |
| 118 |
} |
| 119 |
|
| 120 |
void register_nfs_version(struct nfs_subversion *nfs) |
| 121 |
{ |
| 122 |
write_lock(&nfs_version_lock); |
| 123 |
|
| 124 |
nfs_version_mods[nfs->rpc_ops->version] = nfs; |
| 125 |
nfs_version[nfs->rpc_ops->version] = nfs->rpc_vers; |
| 126 |
|
| 127 |
write_unlock(&nfs_version_lock); |
| 128 |
} |
| 129 |
EXPORT_SYMBOL_GPL(register_nfs_version); |
| 130 |
|
| 131 |
void unregister_nfs_version(struct nfs_subversion *nfs) |
| 132 |
{ |
| 133 |
write_lock(&nfs_version_lock); |
| 134 |
|
| 135 |
nfs_version[nfs->rpc_ops->version] = NULL; |
| 136 |
nfs_version_mods[nfs->rpc_ops->version] = NULL; |
| 137 |
|
| 138 |
write_unlock(&nfs_version_lock); |
| 139 |
} |
| 140 |
EXPORT_SYMBOL_GPL(unregister_nfs_version); |
| 141 |
|
| 142 |
/* |
| 143 |
* Allocate a shared client record |
| 144 |
* |
| 145 |
* Since these are allocated/deallocated very rarely, we don't |
| 146 |
* bother putting them in a slab cache... |
| 147 |
*/ |
| 148 |
struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) |
| 149 |
{ |
| 150 |
struct nfs_client *clp; |
| 151 |
int err = -ENOMEM; |
| 152 |
|
| 153 |
if ((clp = kzalloc_obj(*clp)) == NULL) |
| 154 |
goto error_0; |
| 155 |
|
| 156 |
clp->cl_minorversion = cl_init->minorversion; |
| 157 |
clp->cl_nfs_mod = cl_init->nfs_mod; |
| 158 |
if (!get_nfs_version(clp->cl_nfs_mod)) |
| 159 |
goto error_dealloc; |
| 160 |
|
| 161 |
clp->rpc_ops = clp->cl_nfs_mod->rpc_ops; |
| 162 |
|
| 163 |
refcount_set(&clp->cl_count, 1); |
| 164 |
clp->cl_cons_state = NFS_CS_INITING; |
| 165 |
|
| 166 |
memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen); |
| 167 |
clp->cl_addrlen = cl_init->addrlen; |
| 168 |
|
| 169 |
if (cl_init->hostname) { |
| 170 |
err = -ENOMEM; |
| 171 |
clp->cl_hostname = kstrdup(cl_init->hostname, GFP_KERNEL); |
| 172 |
if (!clp->cl_hostname) |
| 173 |
goto error_cleanup; |
| 174 |
} |
| 175 |
|
| 176 |
INIT_LIST_HEAD(&clp->cl_superblocks); |
| 177 |
clp->cl_rpcclient = ERR_PTR(-EINVAL); |
| 178 |
|
| 179 |
clp->cl_flags = cl_init->init_flags; |
| 180 |
clp->cl_proto = cl_init->proto; |
| 181 |
clp->cl_nconnect = cl_init->nconnect; |
| 182 |
clp->cl_max_connect = cl_init->max_connect ? cl_init->max_connect : 1; |
| 183 |
clp->cl_net = get_net_track(cl_init->net, &clp->cl_ns_tracker, GFP_KERNEL); |
| 184 |
|
| 185 |
#if IS_ENABLED(CONFIG_NFS_LOCALIO) |
| 186 |
seqlock_init(&clp->cl_boot_lock); |
| 187 |
ktime_get_real_ts64(&clp->cl_nfssvc_boot); |
| 188 |
nfs_uuid_init(&clp->cl_uuid); |
| 189 |
INIT_WORK(&clp->cl_local_probe_work, nfs_local_probe_async_work); |
| 190 |
#endif /* CONFIG_NFS_LOCALIO */ |
| 191 |
|
| 192 |
clp->cl_principal = "*"; |
| 193 |
clp->cl_xprtsec = cl_init->xprtsec; |
| 194 |
return clp; |
| 195 |
|
| 196 |
error_cleanup: |
| 197 |
put_nfs_version(clp->cl_nfs_mod); |
| 198 |
error_dealloc: |
| 199 |
kfree(clp); |
| 200 |
error_0: |
| 201 |
return ERR_PTR(err); |
| 202 |
} |
| 203 |
EXPORT_SYMBOL_GPL(nfs_alloc_client); |
| 204 |
|
| 205 |
#if IS_ENABLED(CONFIG_NFS_V4) |
| 206 |
static void nfs_cleanup_cb_ident_idr(struct net *net) |
| 207 |
{ |
| 208 |
struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 209 |
|
| 210 |
idr_destroy(&nn->cb_ident_idr); |
| 211 |
} |
| 212 |
|
| 213 |
/* nfs_client_lock held */ |
| 214 |
static void nfs_cb_idr_remove_locked(struct nfs_client *clp) |
| 215 |
{ |
| 216 |
struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 217 |
|
| 218 |
if (clp->cl_cb_ident) |
| 219 |
idr_remove(&nn->cb_ident_idr, clp->cl_cb_ident); |
| 220 |
} |
| 221 |
|
| 222 |
static void pnfs_init_server(struct nfs_server *server) |
| 223 |
{ |
| 224 |
rpc_init_wait_queue(&server->roc_rpcwaitq, "pNFS ROC"); |
| 225 |
} |
| 226 |
|
| 227 |
#else |
| 228 |
static void nfs_cleanup_cb_ident_idr(struct net *net) |
| 229 |
{ |
| 230 |
} |
| 231 |
|
| 232 |
static void nfs_cb_idr_remove_locked(struct nfs_client *clp) |
| 233 |
{ |
| 234 |
} |
| 235 |
|
| 236 |
static void pnfs_init_server(struct nfs_server *server) |
| 237 |
{ |
| 238 |
} |
| 239 |
|
| 240 |
#endif /* CONFIG_NFS_V4 */ |
| 241 |
|
| 242 |
/* |
| 243 |
* Destroy a shared client record |
| 244 |
*/ |
| 245 |
void nfs_free_client(struct nfs_client *clp) |
| 246 |
{ |
| 247 |
nfs_localio_disable_client(clp); |
| 248 |
|
| 249 |
/* -EIO all pending I/O */ |
| 250 |
if (!IS_ERR(clp->cl_rpcclient)) |
| 251 |
rpc_shutdown_client(clp->cl_rpcclient); |
| 252 |
|
| 253 |
put_net_track(clp->cl_net, &clp->cl_ns_tracker); |
| 254 |
put_nfs_version(clp->cl_nfs_mod); |
| 255 |
kfree(clp->cl_hostname); |
| 256 |
kfree(clp->cl_acceptor); |
| 257 |
kfree_rcu(clp, rcu); |
| 258 |
} |
| 259 |
EXPORT_SYMBOL_GPL(nfs_free_client); |
| 260 |
|
| 261 |
/* |
| 262 |
* Release a reference to a shared client record |
| 263 |
*/ |
| 264 |
void nfs_put_client(struct nfs_client *clp) |
| 265 |
{ |
| 266 |
struct nfs_net *nn; |
| 267 |
|
| 268 |
if (!clp) |
| 269 |
return; |
| 270 |
|
| 271 |
nn = net_generic(clp->cl_net, nfs_net_id); |
| 272 |
|
| 273 |
if (refcount_dec_and_lock(&clp->cl_count, &nn->nfs_client_lock)) { |
| 274 |
list_del(&clp->cl_share_link); |
| 275 |
nfs_cb_idr_remove_locked(clp); |
| 276 |
spin_unlock(&nn->nfs_client_lock); |
| 277 |
|
| 278 |
WARN_ON_ONCE(!list_empty(&clp->cl_superblocks)); |
| 279 |
|
| 280 |
clp->rpc_ops->free_client(clp); |
| 281 |
} |
| 282 |
} |
| 283 |
EXPORT_SYMBOL_GPL(nfs_put_client); |
| 284 |
|
| 285 |
/* |
| 286 |
* Find an nfs_client on the list that matches the initialisation data |
| 287 |
* that is supplied. |
| 288 |
*/ |
| 289 |
static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *data) |
| 290 |
{ |
| 291 |
struct nfs_client *clp; |
| 292 |
const struct sockaddr *sap = (struct sockaddr *)data->addr; |
| 293 |
struct nfs_net *nn = net_generic(data->net, nfs_net_id); |
| 294 |
int error; |
| 295 |
|
| 296 |
again: |
| 297 |
list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) { |
| 298 |
const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; |
| 299 |
/* Don't match clients that failed to initialise properly */ |
| 300 |
if (clp->cl_cons_state < 0) |
| 301 |
continue; |
| 302 |
|
| 303 |
/* If a client is still initializing then we need to wait */ |
| 304 |
if (clp->cl_cons_state > NFS_CS_READY) { |
| 305 |
refcount_inc(&clp->cl_count); |
| 306 |
spin_unlock(&nn->nfs_client_lock); |
| 307 |
error = nfs_wait_client_init_complete(clp); |
| 308 |
nfs_put_client(clp); |
| 309 |
spin_lock(&nn->nfs_client_lock); |
| 310 |
if (error < 0) |
| 311 |
return ERR_PTR(error); |
| 312 |
goto again; |
| 313 |
} |
| 314 |
|
| 315 |
/* Different NFS versions cannot share the same nfs_client */ |
| 316 |
if (clp->rpc_ops != data->nfs_mod->rpc_ops) |
| 317 |
continue; |
| 318 |
|
| 319 |
if (clp->cl_proto != data->proto) |
| 320 |
continue; |
| 321 |
/* Match nfsv4 minorversion */ |
| 322 |
if (clp->cl_minorversion != data->minorversion) |
| 323 |
continue; |
| 324 |
|
| 325 |
/* Match request for a dedicated DS */ |
| 326 |
if (test_bit(NFS_CS_DS, &data->init_flags) != |
| 327 |
test_bit(NFS_CS_DS, &clp->cl_flags)) |
| 328 |
continue; |
| 329 |
|
| 330 |
/* Match the full socket address */ |
| 331 |
if (!rpc_cmp_addr_port(sap, clap)) |
| 332 |
/* Match all xprt_switch full socket addresses */ |
| 333 |
if (IS_ERR(clp->cl_rpcclient) || |
| 334 |
!rpc_clnt_xprt_switch_has_addr(clp->cl_rpcclient, |
| 335 |
sap)) |
| 336 |
continue; |
| 337 |
|
| 338 |
/* Match the xprt security policy */ |
| 339 |
if (clp->cl_xprtsec.policy != data->xprtsec.policy) |
| 340 |
continue; |
| 341 |
if (clp->cl_xprtsec.policy == RPC_XPRTSEC_TLS_X509) { |
| 342 |
if (clp->cl_xprtsec.cert_serial != |
| 343 |
data->xprtsec.cert_serial) |
| 344 |
continue; |
| 345 |
if (clp->cl_xprtsec.privkey_serial != |
| 346 |
data->xprtsec.privkey_serial) |
| 347 |
continue; |
| 348 |
} |
| 349 |
|
| 350 |
refcount_inc(&clp->cl_count); |
| 351 |
return clp; |
| 352 |
} |
| 353 |
return NULL; |
| 354 |
} |
| 355 |
|
| 356 |
/* |
| 357 |
* Return true if @clp is done initializing, false if still working on it. |
| 358 |
* |
| 359 |
* Use nfs_client_init_status to check if it was successful. |
| 360 |
*/ |
| 361 |
bool nfs_client_init_is_complete(const struct nfs_client *clp) |
| 362 |
{ |
| 363 |
return clp->cl_cons_state <= NFS_CS_READY; |
| 364 |
} |
| 365 |
EXPORT_SYMBOL_GPL(nfs_client_init_is_complete); |
| 366 |
|
| 367 |
/* |
| 368 |
* Return 0 if @clp was successfully initialized, -errno otherwise. |
| 369 |
* |
| 370 |
* This must be called *after* nfs_client_init_is_complete() returns true, |
| 371 |
* otherwise it will pop WARN_ON_ONCE and return -EINVAL |
| 372 |
*/ |
| 373 |
int nfs_client_init_status(const struct nfs_client *clp) |
| 374 |
{ |
| 375 |
/* called without checking nfs_client_init_is_complete */ |
| 376 |
if (clp->cl_cons_state > NFS_CS_READY) { |
| 377 |
WARN_ON_ONCE(1); |
| 378 |
return -EINVAL; |
| 379 |
} |
| 380 |
return clp->cl_cons_state; |
| 381 |
} |
| 382 |
EXPORT_SYMBOL_GPL(nfs_client_init_status); |
| 383 |
|
| 384 |
int nfs_wait_client_init_complete(const struct nfs_client *clp) |
| 385 |
{ |
| 386 |
return wait_event_killable(nfs_client_active_wq, |
| 387 |
nfs_client_init_is_complete(clp)); |
| 388 |
} |
| 389 |
EXPORT_SYMBOL_GPL(nfs_wait_client_init_complete); |
| 390 |
|
| 391 |
/* |
| 392 |
* Found an existing client. Make sure it's ready before returning. |
| 393 |
*/ |
| 394 |
static struct nfs_client * |
| 395 |
nfs_found_client(const struct nfs_client_initdata *cl_init, |
| 396 |
struct nfs_client *clp) |
| 397 |
{ |
| 398 |
int error; |
| 399 |
|
| 400 |
error = nfs_wait_client_init_complete(clp); |
| 401 |
if (error < 0) { |
| 402 |
nfs_put_client(clp); |
| 403 |
return ERR_PTR(-ERESTARTSYS); |
| 404 |
} |
| 405 |
|
| 406 |
if (clp->cl_cons_state < NFS_CS_READY) { |
| 407 |
error = clp->cl_cons_state; |
| 408 |
nfs_put_client(clp); |
| 409 |
return ERR_PTR(error); |
| 410 |
} |
| 411 |
|
| 412 |
smp_rmb(); |
| 413 |
return clp; |
| 414 |
} |
| 415 |
|
| 416 |
/* |
| 417 |
* Look up a client by IP address and protocol version |
| 418 |
* - creates a new record if one doesn't yet exist |
| 419 |
*/ |
| 420 |
struct nfs_client *nfs_get_client(const struct nfs_client_initdata *cl_init) |
| 421 |
{ |
| 422 |
struct nfs_client *clp, *new = NULL; |
| 423 |
struct nfs_net *nn = net_generic(cl_init->net, nfs_net_id); |
| 424 |
const struct nfs_rpc_ops *rpc_ops = cl_init->nfs_mod->rpc_ops; |
| 425 |
|
| 426 |
if (cl_init->hostname == NULL) { |
| 427 |
WARN_ON(1); |
| 428 |
return ERR_PTR(-EINVAL); |
| 429 |
} |
| 430 |
|
| 431 |
/* see if the client already exists */ |
| 432 |
do { |
| 433 |
spin_lock(&nn->nfs_client_lock); |
| 434 |
|
| 435 |
clp = nfs_match_client(cl_init); |
| 436 |
if (clp) { |
| 437 |
spin_unlock(&nn->nfs_client_lock); |
| 438 |
if (new) |
| 439 |
new->rpc_ops->free_client(new); |
| 440 |
if (IS_ERR(clp)) |
| 441 |
return clp; |
| 442 |
return nfs_found_client(cl_init, clp); |
| 443 |
} |
| 444 |
if (new) { |
| 445 |
list_add_tail(&new->cl_share_link, |
| 446 |
&nn->nfs_client_list); |
| 447 |
spin_unlock(&nn->nfs_client_lock); |
| 448 |
new = rpc_ops->init_client(new, cl_init); |
| 449 |
if (!IS_ERR(new)) |
| 450 |
nfs_local_probe_async(new); |
| 451 |
return new; |
| 452 |
} |
| 453 |
|
| 454 |
spin_unlock(&nn->nfs_client_lock); |
| 455 |
|
| 456 |
new = rpc_ops->alloc_client(cl_init); |
| 457 |
} while (!IS_ERR(new)); |
| 458 |
|
| 459 |
return new; |
| 460 |
} |
| 461 |
EXPORT_SYMBOL_GPL(nfs_get_client); |
| 462 |
|
| 463 |
/* |
| 464 |
* Mark a server as ready or failed |
| 465 |
*/ |
| 466 |
void nfs_mark_client_ready(struct nfs_client *clp, int state) |
| 467 |
{ |
| 468 |
smp_wmb(); |
| 469 |
clp->cl_cons_state = state; |
| 470 |
wake_up_all(&nfs_client_active_wq); |
| 471 |
} |
| 472 |
EXPORT_SYMBOL_GPL(nfs_mark_client_ready); |
| 473 |
|
| 474 |
/* |
| 475 |
* Initialise the timeout values for a connection |
| 476 |
*/ |
| 477 |
void nfs_init_timeout_values(struct rpc_timeout *to, int proto, |
| 478 |
int timeo, int retrans) |
| 479 |
{ |
| 480 |
to->to_initval = timeo * HZ / 10; |
| 481 |
to->to_retries = retrans; |
| 482 |
|
| 483 |
switch (proto) { |
| 484 |
case XPRT_TRANSPORT_TCP: |
| 485 |
case XPRT_TRANSPORT_TCP_TLS: |
| 486 |
case XPRT_TRANSPORT_RDMA: |
| 487 |
if (retrans == NFS_UNSPEC_RETRANS) |
| 488 |
to->to_retries = NFS_DEF_TCP_RETRANS; |
| 489 |
if (timeo == NFS_UNSPEC_TIMEO || to->to_initval == 0) |
| 490 |
to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10; |
| 491 |
if (to->to_initval > NFS_MAX_TCP_TIMEOUT) |
| 492 |
to->to_initval = NFS_MAX_TCP_TIMEOUT; |
| 493 |
to->to_increment = to->to_initval; |
| 494 |
to->to_maxval = to->to_initval + (to->to_increment * to->to_retries); |
| 495 |
if (to->to_maxval > NFS_MAX_TCP_TIMEOUT) |
| 496 |
to->to_maxval = NFS_MAX_TCP_TIMEOUT; |
| 497 |
if (to->to_maxval < to->to_initval) |
| 498 |
to->to_maxval = to->to_initval; |
| 499 |
to->to_exponential = 0; |
| 500 |
break; |
| 501 |
case XPRT_TRANSPORT_UDP: |
| 502 |
if (retrans == NFS_UNSPEC_RETRANS) |
| 503 |
to->to_retries = NFS_DEF_UDP_RETRANS; |
| 504 |
if (timeo == NFS_UNSPEC_TIMEO || to->to_initval == 0) |
| 505 |
to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10; |
| 506 |
if (to->to_initval > NFS_MAX_UDP_TIMEOUT) |
| 507 |
to->to_initval = NFS_MAX_UDP_TIMEOUT; |
| 508 |
to->to_maxval = NFS_MAX_UDP_TIMEOUT; |
| 509 |
to->to_exponential = 1; |
| 510 |
break; |
| 511 |
default: |
| 512 |
BUG(); |
| 513 |
} |
| 514 |
} |
| 515 |
EXPORT_SYMBOL_GPL(nfs_init_timeout_values); |
| 516 |
|
| 517 |
/* |
| 518 |
* Create an RPC client handle |
| 519 |
*/ |
| 520 |
int nfs_create_rpc_client(struct nfs_client *clp, |
| 521 |
const struct nfs_client_initdata *cl_init, |
| 522 |
rpc_authflavor_t flavor) |
| 523 |
{ |
| 524 |
struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 525 |
struct rpc_clnt *clnt = NULL; |
| 526 |
struct rpc_create_args args = { |
| 527 |
.net = clp->cl_net, |
| 528 |
.protocol = clp->cl_proto, |
| 529 |
.nconnect = clp->cl_nconnect, |
| 530 |
.address = (struct sockaddr *)&clp->cl_addr, |
| 531 |
.addrsize = clp->cl_addrlen, |
| 532 |
.timeout = cl_init->timeparms, |
| 533 |
.servername = clp->cl_hostname, |
| 534 |
.nodename = cl_init->nodename, |
| 535 |
.program = &nfs_program, |
| 536 |
.stats = &nn->rpcstats, |
| 537 |
.version = clp->rpc_ops->version, |
| 538 |
.authflavor = flavor, |
| 539 |
.cred = cl_init->cred, |
| 540 |
.xprtsec = cl_init->xprtsec, |
| 541 |
.connect_timeout = cl_init->connect_timeout, |
| 542 |
.reconnect_timeout = cl_init->reconnect_timeout, |
| 543 |
}; |
| 544 |
|
| 545 |
if (test_bit(NFS_CS_DISCRTRY, &clp->cl_flags)) |
| 546 |
args.flags |= RPC_CLNT_CREATE_DISCRTRY; |
| 547 |
if (test_bit(NFS_CS_NO_RETRANS_TIMEOUT, &clp->cl_flags)) |
| 548 |
args.flags |= RPC_CLNT_CREATE_NO_RETRANS_TIMEOUT; |
| 549 |
if (test_bit(NFS_CS_NORESVPORT, &clp->cl_flags)) |
| 550 |
args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; |
| 551 |
if (test_bit(NFS_CS_INFINITE_SLOTS, &clp->cl_flags)) |
| 552 |
args.flags |= RPC_CLNT_CREATE_INFINITE_SLOTS; |
| 553 |
if (test_bit(NFS_CS_NOPING, &clp->cl_flags)) |
| 554 |
args.flags |= RPC_CLNT_CREATE_NOPING; |
| 555 |
if (test_bit(NFS_CS_REUSEPORT, &clp->cl_flags)) |
| 556 |
args.flags |= RPC_CLNT_CREATE_REUSEPORT; |
| 557 |
if (test_bit(NFS_CS_NETUNREACH_FATAL, &clp->cl_flags)) |
| 558 |
args.flags |= RPC_CLNT_CREATE_NETUNREACH_FATAL; |
| 559 |
|
| 560 |
if (!IS_ERR(clp->cl_rpcclient)) |
| 561 |
return 0; |
| 562 |
|
| 563 |
clnt = rpc_create(&args); |
| 564 |
if (IS_ERR(clnt)) { |
| 565 |
dprintk("%s: cannot create RPC client. Error = %ld\n", |
| 566 |
__func__, PTR_ERR(clnt)); |
| 567 |
return PTR_ERR(clnt); |
| 568 |
} |
| 569 |
|
| 570 |
clnt->cl_principal = clp->cl_principal; |
| 571 |
clp->cl_rpcclient = clnt; |
| 572 |
clnt->cl_max_connect = clp->cl_max_connect; |
| 573 |
return 0; |
| 574 |
} |
| 575 |
EXPORT_SYMBOL_GPL(nfs_create_rpc_client); |
| 576 |
|
| 577 |
/* |
| 578 |
* Version 2 or 3 client destruction |
| 579 |
*/ |
| 580 |
static void nfs_destroy_server(struct nfs_server *server) |
| 581 |
{ |
| 582 |
if (server->nlm_host) |
| 583 |
nlmclnt_done(server->nlm_host); |
| 584 |
} |
| 585 |
|
| 586 |
/* |
| 587 |
* Version 2 or 3 lockd setup |
| 588 |
*/ |
| 589 |
static int nfs_start_lockd(struct nfs_server *server) |
| 590 |
{ |
| 591 |
struct nlm_host *host; |
| 592 |
struct nfs_client *clp = server->nfs_client; |
| 593 |
struct nlmclnt_initdata nlm_init = { |
| 594 |
.hostname = clp->cl_hostname, |
| 595 |
.address = (struct sockaddr *)&clp->cl_addr, |
| 596 |
.addrlen = clp->cl_addrlen, |
| 597 |
.nfs_version = clp->rpc_ops->version, |
| 598 |
.noresvport = server->flags & NFS_MOUNT_NORESVPORT ? |
| 599 |
1 : 0, |
| 600 |
.net = clp->cl_net, |
| 601 |
.nlmclnt_ops = clp->cl_nfs_mod->rpc_ops->nlmclnt_ops, |
| 602 |
.cred = server->cred, |
| 603 |
}; |
| 604 |
|
| 605 |
if (nlm_init.nfs_version > 3) |
| 606 |
return 0; |
| 607 |
if ((server->flags & NFS_MOUNT_LOCAL_FLOCK) && |
| 608 |
(server->flags & NFS_MOUNT_LOCAL_FCNTL)) |
| 609 |
return 0; |
| 610 |
|
| 611 |
switch (clp->cl_proto) { |
| 612 |
default: |
| 613 |
nlm_init.protocol = IPPROTO_TCP; |
| 614 |
break; |
| 615 |
#ifndef CONFIG_NFS_DISABLE_UDP_SUPPORT |
| 616 |
case XPRT_TRANSPORT_UDP: |
| 617 |
nlm_init.protocol = IPPROTO_UDP; |
| 618 |
#endif |
| 619 |
} |
| 620 |
|
| 621 |
host = nlmclnt_init(&nlm_init); |
| 622 |
if (IS_ERR(host)) |
| 623 |
return PTR_ERR(host); |
| 624 |
|
| 625 |
server->nlm_host = host; |
| 626 |
server->destroy = nfs_destroy_server; |
| 627 |
nfs_sysfs_link_rpc_client(server, nlmclnt_rpc_clnt(host), NULL); |
| 628 |
return 0; |
| 629 |
} |
| 630 |
|
| 631 |
/* |
| 632 |
* Create a general RPC client |
| 633 |
*/ |
| 634 |
int nfs_init_server_rpcclient(struct nfs_server *server, |
| 635 |
const struct rpc_timeout *timeo, |
| 636 |
rpc_authflavor_t pseudoflavour) |
| 637 |
{ |
| 638 |
struct nfs_client *clp = server->nfs_client; |
| 639 |
|
| 640 |
server->client = rpc_clone_client_set_auth(clp->cl_rpcclient, |
| 641 |
pseudoflavour); |
| 642 |
if (IS_ERR(server->client)) { |
| 643 |
dprintk("%s: couldn't create rpc_client!\n", __func__); |
| 644 |
return PTR_ERR(server->client); |
| 645 |
} |
| 646 |
|
| 647 |
memcpy(&server->client->cl_timeout_default, |
| 648 |
timeo, |
| 649 |
sizeof(server->client->cl_timeout_default)); |
| 650 |
server->client->cl_timeout = &server->client->cl_timeout_default; |
| 651 |
server->client->cl_softrtry = 0; |
| 652 |
if (server->flags & NFS_MOUNT_SOFTERR) |
| 653 |
server->client->cl_softerr = 1; |
| 654 |
if (server->flags & NFS_MOUNT_SOFT) |
| 655 |
server->client->cl_softrtry = 1; |
| 656 |
|
| 657 |
nfs_sysfs_link_rpc_client(server, server->client, NULL); |
| 658 |
return 0; |
| 659 |
} |
| 660 |
EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient); |
| 661 |
|
| 662 |
/** |
| 663 |
* nfs_init_client - Initialise an NFS2 or NFS3 client |
| 664 |
* |
| 665 |
* @clp: nfs_client to initialise |
| 666 |
* @cl_init: Initialisation parameters |
| 667 |
* |
| 668 |
* Returns pointer to an NFS client, or an ERR_PTR value. |
| 669 |
*/ |
| 670 |
struct nfs_client *nfs_init_client(struct nfs_client *clp, |
| 671 |
const struct nfs_client_initdata *cl_init) |
| 672 |
{ |
| 673 |
int error; |
| 674 |
|
| 675 |
/* the client is already initialised */ |
| 676 |
if (clp->cl_cons_state == NFS_CS_READY) |
| 677 |
return clp; |
| 678 |
|
| 679 |
/* |
| 680 |
* Create a client RPC handle for doing FSSTAT with UNIX auth only |
| 681 |
* - RFC 2623, sec 2.3.2 |
| 682 |
*/ |
| 683 |
error = nfs_create_rpc_client(clp, cl_init, RPC_AUTH_UNIX); |
| 684 |
nfs_mark_client_ready(clp, error == 0 ? NFS_CS_READY : error); |
| 685 |
if (error < 0) { |
| 686 |
nfs_put_client(clp); |
| 687 |
clp = ERR_PTR(error); |
| 688 |
} |
| 689 |
return clp; |
| 690 |
} |
| 691 |
EXPORT_SYMBOL_GPL(nfs_init_client); |
| 692 |
|
| 693 |
static void nfs4_server_set_init_caps(struct nfs_server *server) |
| 694 |
{ |
| 695 |
#if IS_ENABLED(CONFIG_NFS_V4) |
| 696 |
/* Set the basic capabilities */ |
| 697 |
server->caps = server->nfs_client->cl_mvops->init_caps; |
| 698 |
if (server->flags & NFS_MOUNT_NORDIRPLUS) |
| 699 |
server->caps &= ~NFS_CAP_READDIRPLUS; |
| 700 |
if (server->nfs_client->cl_proto == XPRT_TRANSPORT_RDMA) |
| 701 |
server->caps &= ~NFS_CAP_READ_PLUS; |
| 702 |
|
| 703 |
/* |
| 704 |
* Don't use NFS uid/gid mapping if we're using AUTH_SYS or lower |
| 705 |
* authentication. |
| 706 |
*/ |
| 707 |
if (nfs4_disable_idmapping && |
| 708 |
server->client->cl_auth->au_flavor == RPC_AUTH_UNIX) |
| 709 |
server->caps |= NFS_CAP_UIDGID_NOMAP; |
| 710 |
#endif |
| 711 |
} |
| 712 |
|
| 713 |
void nfs_server_set_init_caps(struct nfs_server *server) |
| 714 |
{ |
| 715 |
switch (server->nfs_client->rpc_ops->version) { |
| 716 |
case 2: |
| 717 |
server->caps = NFS_CAP_HARDLINKS | NFS_CAP_SYMLINKS; |
| 718 |
break; |
| 719 |
case 3: |
| 720 |
server->caps = NFS_CAP_HARDLINKS | NFS_CAP_SYMLINKS; |
| 721 |
if (!(server->flags & NFS_MOUNT_NORDIRPLUS)) |
| 722 |
server->caps |= NFS_CAP_READDIRPLUS; |
| 723 |
break; |
| 724 |
default: |
| 725 |
nfs4_server_set_init_caps(server); |
| 726 |
break; |
| 727 |
} |
| 728 |
} |
| 729 |
EXPORT_SYMBOL_GPL(nfs_server_set_init_caps); |
| 730 |
|
| 731 |
/* |
| 732 |
* Create a version 2 or 3 client |
| 733 |
*/ |
| 734 |
static int nfs_init_server(struct nfs_server *server, |
| 735 |
const struct fs_context *fc) |
| 736 |
{ |
| 737 |
const struct nfs_fs_context *ctx = nfs_fc2context(fc); |
| 738 |
struct rpc_timeout timeparms; |
| 739 |
struct nfs_client_initdata cl_init = { |
| 740 |
.hostname = ctx->nfs_server.hostname, |
| 741 |
.addr = &ctx->nfs_server._address, |
| 742 |
.addrlen = ctx->nfs_server.addrlen, |
| 743 |
.nfs_mod = ctx->nfs_mod, |
| 744 |
.proto = ctx->nfs_server.protocol, |
| 745 |
.net = fc->net_ns, |
| 746 |
.timeparms = &timeparms, |
| 747 |
.cred = server->cred, |
| 748 |
.nconnect = ctx->nfs_server.nconnect, |
| 749 |
.init_flags = (1UL << NFS_CS_REUSEPORT), |
| 750 |
.xprtsec = ctx->xprtsec, |
| 751 |
}; |
| 752 |
struct nfs_client *clp; |
| 753 |
int error; |
| 754 |
|
| 755 |
nfs_init_timeout_values(&timeparms, ctx->nfs_server.protocol, |
| 756 |
ctx->timeo, ctx->retrans); |
| 757 |
if (ctx->flags & NFS_MOUNT_NORESVPORT) |
| 758 |
set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags); |
| 759 |
|
| 760 |
if (ctx->flags & NFS_MOUNT_NETUNREACH_FATAL) |
| 761 |
__set_bit(NFS_CS_NETUNREACH_FATAL, &cl_init.init_flags); |
| 762 |
|
| 763 |
/* Allocate or find a client reference we can use */ |
| 764 |
clp = nfs_get_client(&cl_init); |
| 765 |
if (IS_ERR(clp)) |
| 766 |
return PTR_ERR(clp); |
| 767 |
|
| 768 |
server->nfs_client = clp; |
| 769 |
nfs_sysfs_add_server(server); |
| 770 |
nfs_sysfs_link_rpc_client(server, clp->cl_rpcclient, "_state"); |
| 771 |
|
| 772 |
/* Initialise the client representation from the mount data */ |
| 773 |
server->flags = ctx->flags; |
| 774 |
server->options = ctx->options; |
| 775 |
|
| 776 |
switch (clp->rpc_ops->version) { |
| 777 |
case 2: |
| 778 |
server->fattr_valid = NFS_ATTR_FATTR_V2; |
| 779 |
break; |
| 780 |
case 3: |
| 781 |
server->fattr_valid = NFS_ATTR_FATTR_V3; |
| 782 |
break; |
| 783 |
default: |
| 784 |
server->fattr_valid = NFS_ATTR_FATTR_V4; |
| 785 |
} |
| 786 |
|
| 787 |
if (ctx->bsize) { |
| 788 |
server->bsize = ctx->bsize; |
| 789 |
server->automount_inherit |= NFS_AUTOMOUNT_INHERIT_BSIZE; |
| 790 |
} |
| 791 |
if (ctx->rsize) { |
| 792 |
server->rsize = nfs_io_size(ctx->rsize, clp->cl_proto); |
| 793 |
server->automount_inherit |= NFS_AUTOMOUNT_INHERIT_RSIZE; |
| 794 |
} |
| 795 |
if (ctx->wsize) { |
| 796 |
server->wsize = nfs_io_size(ctx->wsize, clp->cl_proto); |
| 797 |
server->automount_inherit |= NFS_AUTOMOUNT_INHERIT_WSIZE; |
| 798 |
} |
| 799 |
|
| 800 |
server->acregmin = ctx->acregmin * HZ; |
| 801 |
server->acregmax = ctx->acregmax * HZ; |
| 802 |
server->acdirmin = ctx->acdirmin * HZ; |
| 803 |
server->acdirmax = ctx->acdirmax * HZ; |
| 804 |
|
| 805 |
/* Start lockd here, before we might error out */ |
| 806 |
error = nfs_start_lockd(server); |
| 807 |
if (error < 0) |
| 808 |
goto error; |
| 809 |
|
| 810 |
server->port = ctx->nfs_server.port; |
| 811 |
server->auth_info = ctx->auth_info; |
| 812 |
|
| 813 |
error = nfs_init_server_rpcclient(server, &timeparms, |
| 814 |
ctx->selected_flavor); |
| 815 |
if (error < 0) |
| 816 |
goto error; |
| 817 |
|
| 818 |
nfs_server_set_init_caps(server); |
| 819 |
|
| 820 |
/* Preserve the values of mount_server-related mount options */ |
| 821 |
if (ctx->mount_server.addrlen) { |
| 822 |
memcpy(&server->mountd_address, &ctx->mount_server.address, |
| 823 |
ctx->mount_server.addrlen); |
| 824 |
server->mountd_addrlen = ctx->mount_server.addrlen; |
| 825 |
} |
| 826 |
server->mountd_version = ctx->mount_server.version; |
| 827 |
server->mountd_port = ctx->mount_server.port; |
| 828 |
server->mountd_protocol = ctx->mount_server.protocol; |
| 829 |
|
| 830 |
server->namelen = ctx->namlen; |
| 831 |
return 0; |
| 832 |
|
| 833 |
error: |
| 834 |
server->nfs_client = NULL; |
| 835 |
nfs_put_client(clp); |
| 836 |
return error; |
| 837 |
} |
| 838 |
|
| 839 |
/* |
| 840 |
* Load up the server record from information gained in an fsinfo record |
| 841 |
*/ |
| 842 |
static void nfs_server_set_fsinfo(struct nfs_server *server, |
| 843 |
struct nfs_fsinfo *fsinfo) |
| 844 |
{ |
| 845 |
struct nfs_client *clp = server->nfs_client; |
| 846 |
unsigned long max_rpc_payload, raw_max_rpc_payload; |
| 847 |
|
| 848 |
/* Work out a lot of parameters */ |
| 849 |
if (server->rsize == 0) |
| 850 |
server->rsize = nfs_io_size(fsinfo->rtpref, clp->cl_proto); |
| 851 |
if (server->wsize == 0) |
| 852 |
server->wsize = nfs_io_size(fsinfo->wtpref, clp->cl_proto); |
| 853 |
|
| 854 |
if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax) |
| 855 |
server->rsize = nfs_io_size(fsinfo->rtmax, clp->cl_proto); |
| 856 |
if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax) |
| 857 |
server->wsize = nfs_io_size(fsinfo->wtmax, clp->cl_proto); |
| 858 |
|
| 859 |
raw_max_rpc_payload = rpc_max_payload(server->client); |
| 860 |
max_rpc_payload = nfs_block_size(raw_max_rpc_payload, NULL); |
| 861 |
|
| 862 |
if (server->rsize > max_rpc_payload) |
| 863 |
server->rsize = max_rpc_payload; |
| 864 |
if (server->rsize > NFS_MAX_FILE_IO_SIZE) |
| 865 |
server->rsize = NFS_MAX_FILE_IO_SIZE; |
| 866 |
server->rpages = (server->rsize + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 867 |
|
| 868 |
if (server->wsize > max_rpc_payload) |
| 869 |
server->wsize = max_rpc_payload; |
| 870 |
if (server->wsize > NFS_MAX_FILE_IO_SIZE) |
| 871 |
server->wsize = NFS_MAX_FILE_IO_SIZE; |
| 872 |
|
| 873 |
server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL); |
| 874 |
|
| 875 |
server->dtsize = nfs_block_size(fsinfo->dtpref, NULL); |
| 876 |
if (server->dtsize > NFS_MAX_FILE_IO_SIZE) |
| 877 |
server->dtsize = NFS_MAX_FILE_IO_SIZE; |
| 878 |
if (server->dtsize > server->rsize) |
| 879 |
server->dtsize = server->rsize; |
| 880 |
|
| 881 |
if (server->flags & NFS_MOUNT_NOAC) { |
| 882 |
server->acregmin = server->acregmax = 0; |
| 883 |
server->acdirmin = server->acdirmax = 0; |
| 884 |
} |
| 885 |
|
| 886 |
server->maxfilesize = fsinfo->maxfilesize; |
| 887 |
|
| 888 |
server->change_attr_type = fsinfo->change_attr_type; |
| 889 |
|
| 890 |
server->clone_blksize = fsinfo->clone_blksize; |
| 891 |
/* We're airborne Set socket buffersize */ |
| 892 |
rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100); |
| 893 |
|
| 894 |
#ifdef CONFIG_NFS_V4_2 |
| 895 |
/* |
| 896 |
* Defaults until limited by the session parameters. |
| 897 |
*/ |
| 898 |
server->gxasize = min_t(unsigned int, raw_max_rpc_payload, |
| 899 |
XATTR_SIZE_MAX); |
| 900 |
server->sxasize = min_t(unsigned int, raw_max_rpc_payload, |
| 901 |
XATTR_SIZE_MAX); |
| 902 |
server->lxasize = min_t(unsigned int, raw_max_rpc_payload, |
| 903 |
nfs42_listxattr_xdrsize(XATTR_LIST_MAX)); |
| 904 |
|
| 905 |
if (fsinfo->xattr_support) |
| 906 |
server->caps |= NFS_CAP_XATTR; |
| 907 |
else |
| 908 |
server->caps &= ~NFS_CAP_XATTR; |
| 909 |
#endif |
| 910 |
} |
| 911 |
|
| 912 |
/* |
| 913 |
* Probe filesystem information, including the FSID on v2/v3 |
| 914 |
*/ |
| 915 |
static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr) |
| 916 |
{ |
| 917 |
struct nfs_fsinfo fsinfo; |
| 918 |
struct nfs_client *clp = server->nfs_client; |
| 919 |
int error; |
| 920 |
|
| 921 |
if (clp->rpc_ops->set_capabilities != NULL) { |
| 922 |
error = clp->rpc_ops->set_capabilities(server, mntfh); |
| 923 |
if (error < 0) |
| 924 |
return error; |
| 925 |
} |
| 926 |
|
| 927 |
fsinfo.fattr = fattr; |
| 928 |
fsinfo.nlayouttypes = 0; |
| 929 |
memset(fsinfo.layouttype, 0, sizeof(fsinfo.layouttype)); |
| 930 |
error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo); |
| 931 |
if (error < 0) |
| 932 |
return error; |
| 933 |
|
| 934 |
nfs_server_set_fsinfo(server, &fsinfo); |
| 935 |
|
| 936 |
/* Get some general file system info */ |
| 937 |
if (server->namelen == 0) { |
| 938 |
struct nfs_pathconf pathinfo; |
| 939 |
|
| 940 |
pathinfo.fattr = fattr; |
| 941 |
nfs_fattr_init(fattr); |
| 942 |
|
| 943 |
if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0) |
| 944 |
server->namelen = pathinfo.max_namelen; |
| 945 |
} |
| 946 |
|
| 947 |
if (clp->rpc_ops->discover_trunking != NULL && |
| 948 |
(server->caps & NFS_CAP_FS_LOCATIONS && |
| 949 |
(server->flags & NFS_MOUNT_TRUNK_DISCOVERY))) { |
| 950 |
error = clp->rpc_ops->discover_trunking(server, mntfh); |
| 951 |
if (error < 0) |
| 952 |
return error; |
| 953 |
} |
| 954 |
|
| 955 |
return 0; |
| 956 |
} |
| 957 |
|
| 958 |
/* |
| 959 |
* Grab the destination's particulars, including lease expiry time. |
| 960 |
* |
| 961 |
* Returns zero if probe succeeded and retrieved FSID matches the FSID |
| 962 |
* we have cached. |
| 963 |
*/ |
| 964 |
int nfs_probe_server(struct nfs_server *server, struct nfs_fh *mntfh) |
| 965 |
{ |
| 966 |
struct nfs_fattr *fattr; |
| 967 |
int error; |
| 968 |
|
| 969 |
fattr = nfs_alloc_fattr(); |
| 970 |
if (fattr == NULL) |
| 971 |
return -ENOMEM; |
| 972 |
|
| 973 |
/* Sanity: the probe won't work if the destination server |
| 974 |
* does not recognize the migrated FH. */ |
| 975 |
error = nfs_probe_fsinfo(server, mntfh, fattr); |
| 976 |
|
| 977 |
nfs_free_fattr(fattr); |
| 978 |
return error; |
| 979 |
} |
| 980 |
EXPORT_SYMBOL_GPL(nfs_probe_server); |
| 981 |
|
| 982 |
/* |
| 983 |
* Copy useful information when duplicating a server record |
| 984 |
*/ |
| 985 |
void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source) |
| 986 |
{ |
| 987 |
target->flags = source->flags; |
| 988 |
target->automount_inherit = source->automount_inherit; |
| 989 |
if (source->automount_inherit & NFS_AUTOMOUNT_INHERIT_BSIZE) |
| 990 |
target->bsize = source->bsize; |
| 991 |
if (source->automount_inherit & NFS_AUTOMOUNT_INHERIT_RSIZE) |
| 992 |
target->rsize = source->rsize; |
| 993 |
if (source->automount_inherit & NFS_AUTOMOUNT_INHERIT_WSIZE) |
| 994 |
target->wsize = source->wsize; |
| 995 |
target->acregmin = source->acregmin; |
| 996 |
target->acregmax = source->acregmax; |
| 997 |
target->acdirmin = source->acdirmin; |
| 998 |
target->acdirmax = source->acdirmax; |
| 999 |
target->options = source->options; |
| 1000 |
target->auth_info = source->auth_info; |
| 1001 |
target->port = source->port; |
| 1002 |
} |
| 1003 |
EXPORT_SYMBOL_GPL(nfs_server_copy_userdata); |
| 1004 |
|
| 1005 |
void nfs_server_insert_lists(struct nfs_server *server) |
| 1006 |
{ |
| 1007 |
struct nfs_client *clp = server->nfs_client; |
| 1008 |
struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 1009 |
|
| 1010 |
spin_lock(&nn->nfs_client_lock); |
| 1011 |
list_add_tail_rcu(&server->client_link, &clp->cl_superblocks); |
| 1012 |
list_add_tail(&server->master_link, &nn->nfs_volume_list); |
| 1013 |
clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); |
| 1014 |
spin_unlock(&nn->nfs_client_lock); |
| 1015 |
|
| 1016 |
} |
| 1017 |
EXPORT_SYMBOL_GPL(nfs_server_insert_lists); |
| 1018 |
|
| 1019 |
void nfs_server_remove_lists(struct nfs_server *server) |
| 1020 |
{ |
| 1021 |
struct nfs_client *clp = server->nfs_client; |
| 1022 |
struct nfs_net *nn; |
| 1023 |
|
| 1024 |
if (clp == NULL) |
| 1025 |
return; |
| 1026 |
nn = net_generic(clp->cl_net, nfs_net_id); |
| 1027 |
spin_lock(&nn->nfs_client_lock); |
| 1028 |
list_del_rcu(&server->client_link); |
| 1029 |
if (list_empty(&clp->cl_superblocks)) |
| 1030 |
set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); |
| 1031 |
list_del(&server->master_link); |
| 1032 |
spin_unlock(&nn->nfs_client_lock); |
| 1033 |
|
| 1034 |
synchronize_rcu(); |
| 1035 |
} |
| 1036 |
EXPORT_SYMBOL_GPL(nfs_server_remove_lists); |
| 1037 |
|
| 1038 |
static DEFINE_IDA(s_sysfs_ids); |
| 1039 |
|
| 1040 |
/* |
| 1041 |
* Allocate and initialise a server record |
| 1042 |
*/ |
| 1043 |
struct nfs_server *nfs_alloc_server(void) |
| 1044 |
{ |
| 1045 |
struct nfs_server *server; |
| 1046 |
|
| 1047 |
server = kzalloc_obj(struct nfs_server); |
| 1048 |
if (!server) |
| 1049 |
return NULL; |
| 1050 |
|
| 1051 |
server->s_sysfs_id = ida_alloc(&s_sysfs_ids, GFP_KERNEL); |
| 1052 |
if (server->s_sysfs_id < 0) { |
| 1053 |
kfree(server); |
| 1054 |
return NULL; |
| 1055 |
} |
| 1056 |
|
| 1057 |
server->client = server->client_acl = ERR_PTR(-EINVAL); |
| 1058 |
|
| 1059 |
/* Zero out the NFS state stuff */ |
| 1060 |
INIT_LIST_HEAD(&server->client_link); |
| 1061 |
INIT_LIST_HEAD(&server->master_link); |
| 1062 |
INIT_LIST_HEAD(&server->delegations); |
| 1063 |
spin_lock_init(&server->delegations_lock); |
| 1064 |
INIT_LIST_HEAD(&server->delegations_return); |
| 1065 |
INIT_LIST_HEAD(&server->delegations_lru); |
| 1066 |
INIT_LIST_HEAD(&server->delegations_delayed); |
| 1067 |
INIT_LIST_HEAD(&server->layouts); |
| 1068 |
INIT_LIST_HEAD(&server->state_owners_lru); |
| 1069 |
INIT_LIST_HEAD(&server->ss_copies); |
| 1070 |
INIT_LIST_HEAD(&server->ss_src_copies); |
| 1071 |
|
| 1072 |
atomic_set(&server->active, 0); |
| 1073 |
atomic_long_set(&server->nr_active_delegations, 0); |
| 1074 |
|
| 1075 |
server->io_stats = nfs_alloc_iostats(); |
| 1076 |
if (!server->io_stats) { |
| 1077 |
kfree(server); |
| 1078 |
return NULL; |
| 1079 |
} |
| 1080 |
|
| 1081 |
server->change_attr_type = NFS4_CHANGE_TYPE_IS_UNDEFINED; |
| 1082 |
|
| 1083 |
init_waitqueue_head(&server->write_congestion_wait); |
| 1084 |
atomic_long_set(&server->writeback, 0); |
| 1085 |
|
| 1086 |
atomic64_set(&server->owner_ctr, 0); |
| 1087 |
|
| 1088 |
pnfs_init_server(server); |
| 1089 |
rpc_init_wait_queue(&server->uoc_rpcwaitq, "NFS UOC"); |
| 1090 |
|
| 1091 |
return server; |
| 1092 |
} |
| 1093 |
EXPORT_SYMBOL_GPL(nfs_alloc_server); |
| 1094 |
|
| 1095 |
static void delayed_free(struct rcu_head *p) |
| 1096 |
{ |
| 1097 |
struct nfs_server *server = container_of(p, struct nfs_server, rcu); |
| 1098 |
|
| 1099 |
nfs_free_iostats(server->io_stats); |
| 1100 |
kfree(server); |
| 1101 |
} |
| 1102 |
|
| 1103 |
/* |
| 1104 |
* Free up a server record |
| 1105 |
*/ |
| 1106 |
void nfs_free_server(struct nfs_server *server) |
| 1107 |
{ |
| 1108 |
nfs_server_remove_lists(server); |
| 1109 |
|
| 1110 |
if (server->destroy != NULL) |
| 1111 |
server->destroy(server); |
| 1112 |
|
| 1113 |
if (!IS_ERR(server->client_acl)) |
| 1114 |
rpc_shutdown_client(server->client_acl); |
| 1115 |
if (!IS_ERR(server->client)) |
| 1116 |
rpc_shutdown_client(server->client); |
| 1117 |
|
| 1118 |
nfs_put_client(server->nfs_client); |
| 1119 |
|
| 1120 |
if (server->kobj.state_initialized) { |
| 1121 |
nfs_sysfs_remove_server(server); |
| 1122 |
kobject_put(&server->kobj); |
| 1123 |
} |
| 1124 |
ida_free(&s_sysfs_ids, server->s_sysfs_id); |
| 1125 |
|
| 1126 |
put_cred(server->cred); |
| 1127 |
nfs_release_automount_timer(); |
| 1128 |
call_rcu(&server->rcu, delayed_free); |
| 1129 |
} |
| 1130 |
EXPORT_SYMBOL_GPL(nfs_free_server); |
| 1131 |
|
| 1132 |
/* |
| 1133 |
* Create a version 2 or 3 volume record |
| 1134 |
* - keyed on server and FSID |
| 1135 |
*/ |
| 1136 |
struct nfs_server *nfs_create_server(struct fs_context *fc) |
| 1137 |
{ |
| 1138 |
struct nfs_fs_context *ctx = nfs_fc2context(fc); |
| 1139 |
struct nfs_server *server; |
| 1140 |
struct nfs_fattr *fattr; |
| 1141 |
int error; |
| 1142 |
|
| 1143 |
server = nfs_alloc_server(); |
| 1144 |
if (!server) |
| 1145 |
return ERR_PTR(-ENOMEM); |
| 1146 |
|
| 1147 |
server->cred = get_cred(fc->cred); |
| 1148 |
|
| 1149 |
error = -ENOMEM; |
| 1150 |
fattr = nfs_alloc_fattr(); |
| 1151 |
if (fattr == NULL) |
| 1152 |
goto error; |
| 1153 |
|
| 1154 |
/* Get a client representation */ |
| 1155 |
error = nfs_init_server(server, fc); |
| 1156 |
if (error < 0) |
| 1157 |
goto error; |
| 1158 |
|
| 1159 |
/* Probe the root fh to retrieve its FSID */ |
| 1160 |
error = nfs_probe_fsinfo(server, ctx->mntfh, fattr); |
| 1161 |
if (error < 0) |
| 1162 |
goto error; |
| 1163 |
if (server->nfs_client->rpc_ops->version == 3) { |
| 1164 |
if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN) |
| 1165 |
server->namelen = NFS3_MAXNAMLEN; |
| 1166 |
if (!(ctx->flags & NFS_MOUNT_NORDIRPLUS)) |
| 1167 |
server->caps |= NFS_CAP_READDIRPLUS; |
| 1168 |
} else { |
| 1169 |
if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN) |
| 1170 |
server->namelen = NFS2_MAXNAMLEN; |
| 1171 |
} |
| 1172 |
/* Linux 'subtree_check' borkenness mandates this setting */ |
| 1173 |
server->fh_expire_type = NFS_FH_VOL_RENAME; |
| 1174 |
|
| 1175 |
if (!(fattr->valid & NFS_ATTR_FATTR)) { |
| 1176 |
error = ctx->nfs_mod->rpc_ops->getattr(server, ctx->mntfh, |
| 1177 |
fattr, NULL); |
| 1178 |
if (error < 0) { |
| 1179 |
dprintk("nfs_create_server: getattr error = %d\n", -error); |
| 1180 |
goto error; |
| 1181 |
} |
| 1182 |
} |
| 1183 |
memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 1184 |
|
| 1185 |
dprintk("Server FSID: %llx:%llx\n", |
| 1186 |
(unsigned long long) server->fsid.major, |
| 1187 |
(unsigned long long) server->fsid.minor); |
| 1188 |
|
| 1189 |
nfs_server_insert_lists(server); |
| 1190 |
server->mount_time = jiffies; |
| 1191 |
nfs_free_fattr(fattr); |
| 1192 |
return server; |
| 1193 |
|
| 1194 |
error: |
| 1195 |
nfs_free_fattr(fattr); |
| 1196 |
nfs_free_server(server); |
| 1197 |
return ERR_PTR(error); |
| 1198 |
} |
| 1199 |
EXPORT_SYMBOL_GPL(nfs_create_server); |
| 1200 |
|
| 1201 |
/* |
| 1202 |
* Clone an NFS2, NFS3 or NFS4 server record |
| 1203 |
*/ |
| 1204 |
struct nfs_server *nfs_clone_server(struct nfs_server *source, |
| 1205 |
struct nfs_fh *fh, |
| 1206 |
struct nfs_fattr *fattr, |
| 1207 |
rpc_authflavor_t flavor) |
| 1208 |
{ |
| 1209 |
struct nfs_server *server; |
| 1210 |
int error; |
| 1211 |
|
| 1212 |
server = nfs_alloc_server(); |
| 1213 |
if (!server) |
| 1214 |
return ERR_PTR(-ENOMEM); |
| 1215 |
|
| 1216 |
server->cred = get_cred(source->cred); |
| 1217 |
|
| 1218 |
/* Copy data from the source */ |
| 1219 |
server->nfs_client = source->nfs_client; |
| 1220 |
server->destroy = source->destroy; |
| 1221 |
refcount_inc(&server->nfs_client->cl_count); |
| 1222 |
nfs_server_copy_userdata(server, source); |
| 1223 |
|
| 1224 |
server->fsid = fattr->fsid; |
| 1225 |
|
| 1226 |
nfs_sysfs_add_server(server); |
| 1227 |
|
| 1228 |
nfs_sysfs_link_rpc_client(server, |
| 1229 |
server->nfs_client->cl_rpcclient, "_state"); |
| 1230 |
|
| 1231 |
error = nfs_init_server_rpcclient(server, |
| 1232 |
source->client->cl_timeout, |
| 1233 |
flavor); |
| 1234 |
if (error < 0) |
| 1235 |
goto out_free_server; |
| 1236 |
|
| 1237 |
nfs_server_set_init_caps(server); |
| 1238 |
|
| 1239 |
/* probe the filesystem info for this server filesystem */ |
| 1240 |
error = nfs_probe_server(server, fh); |
| 1241 |
if (error < 0) |
| 1242 |
goto out_free_server; |
| 1243 |
|
| 1244 |
if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
| 1245 |
server->namelen = NFS4_MAXNAMLEN; |
| 1246 |
|
| 1247 |
error = nfs_start_lockd(server); |
| 1248 |
if (error < 0) |
| 1249 |
goto out_free_server; |
| 1250 |
|
| 1251 |
nfs_server_insert_lists(server); |
| 1252 |
server->mount_time = jiffies; |
| 1253 |
|
| 1254 |
return server; |
| 1255 |
|
| 1256 |
out_free_server: |
| 1257 |
nfs_free_server(server); |
| 1258 |
return ERR_PTR(error); |
| 1259 |
} |
| 1260 |
EXPORT_SYMBOL_GPL(nfs_clone_server); |
| 1261 |
|
| 1262 |
void nfs_clients_init(struct net *net) |
| 1263 |
{ |
| 1264 |
struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 1265 |
|
| 1266 |
INIT_LIST_HEAD(&nn->nfs_client_list); |
| 1267 |
INIT_LIST_HEAD(&nn->nfs_volume_list); |
| 1268 |
#if IS_ENABLED(CONFIG_NFS_V4) |
| 1269 |
idr_init(&nn->cb_ident_idr); |
| 1270 |
INIT_LIST_HEAD(&nn->nfs4_data_server_cache); |
| 1271 |
spin_lock_init(&nn->nfs4_data_server_lock); |
| 1272 |
#endif /* CONFIG_NFS_V4 */ |
| 1273 |
spin_lock_init(&nn->nfs_client_lock); |
| 1274 |
nn->boot_time = ktime_get_real(); |
| 1275 |
memset(&nn->rpcstats, 0, sizeof(nn->rpcstats)); |
| 1276 |
nn->rpcstats.program = &nfs_program; |
| 1277 |
|
| 1278 |
nfs_netns_sysfs_setup(nn, net); |
| 1279 |
} |
| 1280 |
|
| 1281 |
void nfs_clients_exit(struct net *net) |
| 1282 |
{ |
| 1283 |
struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 1284 |
|
| 1285 |
nfs_netns_sysfs_destroy(nn); |
| 1286 |
nfs_cleanup_cb_ident_idr(net); |
| 1287 |
WARN_ON_ONCE(!list_empty(&nn->nfs_client_list)); |
| 1288 |
WARN_ON_ONCE(!list_empty(&nn->nfs_volume_list)); |
| 1289 |
#if IS_ENABLED(CONFIG_NFS_V4) |
| 1290 |
WARN_ON_ONCE(!list_empty(&nn->nfs4_data_server_cache)); |
| 1291 |
#endif /* CONFIG_NFS_V4 */ |
| 1292 |
} |
| 1293 |
|
| 1294 |
#ifdef CONFIG_PROC_FS |
| 1295 |
static void *nfs_server_list_start(struct seq_file *p, loff_t *pos); |
| 1296 |
static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos); |
| 1297 |
static void nfs_server_list_stop(struct seq_file *p, void *v); |
| 1298 |
static int nfs_server_list_show(struct seq_file *m, void *v); |
| 1299 |
|
| 1300 |
static const struct seq_operations nfs_server_list_ops = { |
| 1301 |
.start = nfs_server_list_start, |
| 1302 |
.next = nfs_server_list_next, |
| 1303 |
.stop = nfs_server_list_stop, |
| 1304 |
.show = nfs_server_list_show, |
| 1305 |
}; |
| 1306 |
|
| 1307 |
static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos); |
| 1308 |
static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos); |
| 1309 |
static void nfs_volume_list_stop(struct seq_file *p, void *v); |
| 1310 |
static int nfs_volume_list_show(struct seq_file *m, void *v); |
| 1311 |
|
| 1312 |
static const struct seq_operations nfs_volume_list_ops = { |
| 1313 |
.start = nfs_volume_list_start, |
| 1314 |
.next = nfs_volume_list_next, |
| 1315 |
.stop = nfs_volume_list_stop, |
| 1316 |
.show = nfs_volume_list_show, |
| 1317 |
}; |
| 1318 |
|
| 1319 |
/* |
| 1320 |
* set up the iterator to start reading from the server list and return the first item |
| 1321 |
*/ |
| 1322 |
static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos) |
| 1323 |
__acquires(&nn->nfs_client_lock) |
| 1324 |
{ |
| 1325 |
struct nfs_net *nn = net_generic(seq_file_net(m), nfs_net_id); |
| 1326 |
|
| 1327 |
/* lock the list against modification */ |
| 1328 |
spin_lock(&nn->nfs_client_lock); |
| 1329 |
return seq_list_start_head(&nn->nfs_client_list, *_pos); |
| 1330 |
} |
| 1331 |
|
| 1332 |
/* |
| 1333 |
* move to next server |
| 1334 |
*/ |
| 1335 |
static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos) |
| 1336 |
{ |
| 1337 |
struct nfs_net *nn = net_generic(seq_file_net(p), nfs_net_id); |
| 1338 |
|
| 1339 |
return seq_list_next(v, &nn->nfs_client_list, pos); |
| 1340 |
} |
| 1341 |
|
| 1342 |
/* |
| 1343 |
* clean up after reading from the transports list |
| 1344 |
*/ |
| 1345 |
static void nfs_server_list_stop(struct seq_file *p, void *v) |
| 1346 |
__releases(&nn->nfs_client_lock) |
| 1347 |
{ |
| 1348 |
struct nfs_net *nn = net_generic(seq_file_net(p), nfs_net_id); |
| 1349 |
|
| 1350 |
spin_unlock(&nn->nfs_client_lock); |
| 1351 |
} |
| 1352 |
|
| 1353 |
/* |
| 1354 |
* display a header line followed by a load of call lines |
| 1355 |
*/ |
| 1356 |
static int nfs_server_list_show(struct seq_file *m, void *v) |
| 1357 |
{ |
| 1358 |
struct nfs_client *clp; |
| 1359 |
struct nfs_net *nn = net_generic(seq_file_net(m), nfs_net_id); |
| 1360 |
|
| 1361 |
/* display header on line 1 */ |
| 1362 |
if (v == &nn->nfs_client_list) { |
| 1363 |
seq_puts(m, "NV SERVER PORT USE HOSTNAME\n"); |
| 1364 |
return 0; |
| 1365 |
} |
| 1366 |
|
| 1367 |
/* display one transport per line on subsequent lines */ |
| 1368 |
clp = list_entry(v, struct nfs_client, cl_share_link); |
| 1369 |
|
| 1370 |
/* Check if the client is initialized */ |
| 1371 |
if (clp->cl_cons_state != NFS_CS_READY) |
| 1372 |
return 0; |
| 1373 |
|
| 1374 |
rcu_read_lock(); |
| 1375 |
seq_printf(m, "v%u %s %s %3d %s\n", |
| 1376 |
clp->rpc_ops->version, |
| 1377 |
rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
| 1378 |
rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), |
| 1379 |
refcount_read(&clp->cl_count), |
| 1380 |
clp->cl_hostname); |
| 1381 |
rcu_read_unlock(); |
| 1382 |
|
| 1383 |
return 0; |
| 1384 |
} |
| 1385 |
|
| 1386 |
/* |
| 1387 |
* set up the iterator to start reading from the volume list and return the first item |
| 1388 |
*/ |
| 1389 |
static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos) |
| 1390 |
__acquires(&nn->nfs_client_lock) |
| 1391 |
{ |
| 1392 |
struct nfs_net *nn = net_generic(seq_file_net(m), nfs_net_id); |
| 1393 |
|
| 1394 |
/* lock the list against modification */ |
| 1395 |
spin_lock(&nn->nfs_client_lock); |
| 1396 |
return seq_list_start_head(&nn->nfs_volume_list, *_pos); |
| 1397 |
} |
| 1398 |
|
| 1399 |
/* |
| 1400 |
* move to next volume |
| 1401 |
*/ |
| 1402 |
static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos) |
| 1403 |
{ |
| 1404 |
struct nfs_net *nn = net_generic(seq_file_net(p), nfs_net_id); |
| 1405 |
|
| 1406 |
return seq_list_next(v, &nn->nfs_volume_list, pos); |
| 1407 |
} |
| 1408 |
|
| 1409 |
/* |
| 1410 |
* clean up after reading from the transports list |
| 1411 |
*/ |
| 1412 |
static void nfs_volume_list_stop(struct seq_file *p, void *v) |
| 1413 |
__releases(&nn->nfs_client_lock) |
| 1414 |
{ |
| 1415 |
struct nfs_net *nn = net_generic(seq_file_net(p), nfs_net_id); |
| 1416 |
|
| 1417 |
spin_unlock(&nn->nfs_client_lock); |
| 1418 |
} |
| 1419 |
|
| 1420 |
/* |
| 1421 |
* display a header line followed by a load of call lines |
| 1422 |
*/ |
| 1423 |
static int nfs_volume_list_show(struct seq_file *m, void *v) |
| 1424 |
{ |
| 1425 |
struct nfs_server *server; |
| 1426 |
struct nfs_client *clp; |
| 1427 |
char dev[13]; // 8 for 2^24, 1 for ':', 3 for 2^8, 1 for '\0' |
| 1428 |
char fsid[34]; // 2 * 16 for %llx, 1 for ':', 1 for '\0' |
| 1429 |
struct nfs_net *nn = net_generic(seq_file_net(m), nfs_net_id); |
| 1430 |
|
| 1431 |
/* display header on line 1 */ |
| 1432 |
if (v == &nn->nfs_volume_list) { |
| 1433 |
seq_puts(m, "NV SERVER PORT DEV FSID" |
| 1434 |
" FSC\n"); |
| 1435 |
return 0; |
| 1436 |
} |
| 1437 |
/* display one transport per line on subsequent lines */ |
| 1438 |
server = list_entry(v, struct nfs_server, master_link); |
| 1439 |
clp = server->nfs_client; |
| 1440 |
|
| 1441 |
snprintf(dev, sizeof(dev), "%u:%u", |
| 1442 |
MAJOR(server->s_dev), MINOR(server->s_dev)); |
| 1443 |
|
| 1444 |
snprintf(fsid, sizeof(fsid), "%llx:%llx", |
| 1445 |
(unsigned long long) server->fsid.major, |
| 1446 |
(unsigned long long) server->fsid.minor); |
| 1447 |
|
| 1448 |
rcu_read_lock(); |
| 1449 |
seq_printf(m, "v%u %s %s %-12s %-33s %s\n", |
| 1450 |
clp->rpc_ops->version, |
| 1451 |
rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
| 1452 |
rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), |
| 1453 |
dev, |
| 1454 |
fsid, |
| 1455 |
nfs_server_fscache_state(server)); |
| 1456 |
rcu_read_unlock(); |
| 1457 |
|
| 1458 |
return 0; |
| 1459 |
} |
| 1460 |
|
| 1461 |
int nfs_fs_proc_net_init(struct net *net) |
| 1462 |
{ |
| 1463 |
struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 1464 |
struct proc_dir_entry *p; |
| 1465 |
|
| 1466 |
nn->proc_nfsfs = proc_net_mkdir(net, "nfsfs", net->proc_net); |
| 1467 |
if (!nn->proc_nfsfs) |
| 1468 |
goto error_0; |
| 1469 |
|
| 1470 |
/* a file of servers with which we're dealing */ |
| 1471 |
p = proc_create_net("servers", S_IFREG|S_IRUGO, nn->proc_nfsfs, |
| 1472 |
&nfs_server_list_ops, sizeof(struct seq_net_private)); |
| 1473 |
if (!p) |
| 1474 |
goto error_1; |
| 1475 |
|
| 1476 |
/* a file of volumes that we have mounted */ |
| 1477 |
p = proc_create_net("volumes", S_IFREG|S_IRUGO, nn->proc_nfsfs, |
| 1478 |
&nfs_volume_list_ops, sizeof(struct seq_net_private)); |
| 1479 |
if (!p) |
| 1480 |
goto error_1; |
| 1481 |
return 0; |
| 1482 |
|
| 1483 |
error_1: |
| 1484 |
remove_proc_subtree("nfsfs", net->proc_net); |
| 1485 |
error_0: |
| 1486 |
return -ENOMEM; |
| 1487 |
} |
| 1488 |
|
| 1489 |
void nfs_fs_proc_net_exit(struct net *net) |
| 1490 |
{ |
| 1491 |
remove_proc_subtree("nfsfs", net->proc_net); |
| 1492 |
} |
| 1493 |
|
| 1494 |
/* |
| 1495 |
* initialise the /proc/fs/nfsfs/ directory |
| 1496 |
*/ |
| 1497 |
int __init nfs_fs_proc_init(void) |
| 1498 |
{ |
| 1499 |
if (!proc_mkdir("fs/nfsfs", NULL)) |
| 1500 |
goto error_0; |
| 1501 |
|
| 1502 |
/* a file of servers with which we're dealing */ |
| 1503 |
if (!proc_symlink("fs/nfsfs/servers", NULL, "../../net/nfsfs/servers")) |
| 1504 |
goto error_1; |
| 1505 |
|
| 1506 |
/* a file of volumes that we have mounted */ |
| 1507 |
if (!proc_symlink("fs/nfsfs/volumes", NULL, "../../net/nfsfs/volumes")) |
| 1508 |
goto error_1; |
| 1509 |
|
| 1510 |
return 0; |
| 1511 |
error_1: |
| 1512 |
remove_proc_subtree("fs/nfsfs", NULL); |
| 1513 |
error_0: |
| 1514 |
return -ENOMEM; |
| 1515 |
} |
| 1516 |
|
| 1517 |
/* |
| 1518 |
* clean up the /proc/fs/nfsfs/ directory |
| 1519 |
*/ |
| 1520 |
void nfs_fs_proc_exit(void) |
| 1521 |
{ |
| 1522 |
remove_proc_subtree("fs/nfsfs", NULL); |
| 1523 |
ida_destroy(&s_sysfs_ids); |
| 1524 |
} |
| 1525 |
|
| 1526 |
#endif /* CONFIG_PROC_FS */ |