| 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 (dhowells@redhat.com) |
| 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(error: -EPROTONOSUPPORT); |
| 102 | |
| 103 | if (!get_nfs_version(nfs)) |
| 104 | return ERR_PTR(error: -EAGAIN); |
| 105 | |
| 106 | return nfs; |
| 107 | } |
| 108 | |
| 109 | int get_nfs_version(struct nfs_subversion *nfs) |
| 110 | { |
| 111 | return try_module_get(module: nfs->owner); |
| 112 | } |
| 113 | EXPORT_SYMBOL_GPL(get_nfs_version); |
| 114 | |
| 115 | void put_nfs_version(struct nfs_subversion *nfs) |
| 116 | { |
| 117 | module_put(module: 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(sizeof(*clp), GFP_KERNEL)) == 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(r: &clp->cl_count, n: 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(s: cl_init->hostname, GFP_KERNEL); |
| 172 | if (!clp->cl_hostname) |
| 173 | goto error_cleanup; |
| 174 | } |
| 175 | |
| 176 | INIT_LIST_HEAD(list: &clp->cl_superblocks); |
| 177 | clp->cl_rpcclient = ERR_PTR(error: -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(net: cl_init->net, tracker: &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(tv: &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(nfs: clp->cl_nfs_mod); |
| 198 | error_dealloc: |
| 199 | kfree(objp: clp); |
| 200 | error_0: |
| 201 | return ERR_PTR(error: 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, id: 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(net: clp->cl_net, id: nfs_net_id); |
| 217 | |
| 218 | if (clp->cl_cb_ident) |
| 219 | idr_remove(&nn->cb_ident_idr, id: 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(ptr: clp->cl_rpcclient)) |
| 251 | rpc_shutdown_client(clp->cl_rpcclient); |
| 252 | |
| 253 | put_net_track(net: clp->cl_net, tracker: &clp->cl_ns_tracker); |
| 254 | put_nfs_version(nfs: clp->cl_nfs_mod); |
| 255 | kfree(objp: clp->cl_hostname); |
| 256 | kfree(objp: 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(net: clp->cl_net, id: nfs_net_id); |
| 272 | |
| 273 | if (refcount_dec_and_lock(r: &clp->cl_count, lock: &nn->nfs_client_lock)) { |
| 274 | list_del(entry: &clp->cl_share_link); |
| 275 | nfs_cb_idr_remove_locked(clp); |
| 276 | spin_unlock(lock: &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(net: data->net, id: 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(r: &clp->cl_count); |
| 306 | spin_unlock(lock: &nn->nfs_client_lock); |
| 307 | error = nfs_wait_client_init_complete(clp); |
| 308 | nfs_put_client(clp); |
| 309 | spin_lock(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(sap1: sap, sap2: clap)) |
| 332 | /* Match all xprt_switch full socket addresses */ |
| 333 | if (IS_ERR(ptr: clp->cl_rpcclient) || |
| 334 | !rpc_clnt_xprt_switch_has_addr(clnt: 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(r: &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(error: -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(net: cl_init->net, id: 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(error: -EINVAL); |
| 429 | } |
| 430 | |
| 431 | /* see if the client already exists */ |
| 432 | do { |
| 433 | spin_lock(lock: &nn->nfs_client_lock); |
| 434 | |
| 435 | clp = nfs_match_client(data: cl_init); |
| 436 | if (clp) { |
| 437 | spin_unlock(lock: &nn->nfs_client_lock); |
| 438 | if (new) |
| 439 | new->rpc_ops->free_client(new); |
| 440 | if (IS_ERR(ptr: clp)) |
| 441 | return clp; |
| 442 | return nfs_found_client(cl_init, clp); |
| 443 | } |
| 444 | if (new) { |
| 445 | list_add_tail(new: &new->cl_share_link, |
| 446 | head: &nn->nfs_client_list); |
| 447 | spin_unlock(lock: &nn->nfs_client_lock); |
| 448 | new = rpc_ops->init_client(new, cl_init); |
| 449 | if (!IS_ERR(ptr: new)) |
| 450 | nfs_local_probe_async(new); |
| 451 | return new; |
| 452 | } |
| 453 | |
| 454 | spin_unlock(lock: &nn->nfs_client_lock); |
| 455 | |
| 456 | new = rpc_ops->alloc_client(cl_init); |
| 457 | } while (!IS_ERR(ptr: 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(net: clp->cl_net, id: 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(ptr: clp->cl_rpcclient)) |
| 561 | return 0; |
| 562 | |
| 563 | clnt = rpc_create(args: &args); |
| 564 | if (IS_ERR(ptr: clnt)) { |
| 565 | dprintk("%s: cannot create RPC client. Error = %ld\n" , |
| 566 | __func__, PTR_ERR(clnt)); |
| 567 | return PTR_ERR(ptr: 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(host: 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: &nlm_init); |
| 622 | if (IS_ERR(ptr: host)) |
| 623 | return PTR_ERR(ptr: host); |
| 624 | |
| 625 | server->nlm_host = host; |
| 626 | server->destroy = nfs_destroy_server; |
| 627 | nfs_sysfs_link_rpc_client(server, clnt: 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(ptr: server->client)) { |
| 643 | dprintk("%s: couldn't create rpc_client!\n" , __func__); |
| 644 | return PTR_ERR(ptr: 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, clnt: 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, addr: &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(ptr: clp)) |
| 766 | return PTR_ERR(ptr: clp); |
| 767 | |
| 768 | server->nfs_client = clp; |
| 769 | nfs_sysfs_add_server(s: server); |
| 770 | nfs_sysfs_link_rpc_client(server, clnt: clp->cl_rpcclient, sysfs_prefix: "_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(iosize: ctx->rsize, proto: clp->cl_proto); |
| 793 | server->automount_inherit |= NFS_AUTOMOUNT_INHERIT_RSIZE; |
| 794 | } |
| 795 | if (ctx->wsize) { |
| 796 | server->wsize = nfs_io_size(iosize: ctx->wsize, proto: 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(iosize: fsinfo->rtpref, proto: clp->cl_proto); |
| 851 | if (server->wsize == 0) |
| 852 | server->wsize = nfs_io_size(iosize: fsinfo->wtpref, proto: clp->cl_proto); |
| 853 | |
| 854 | if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax) |
| 855 | server->rsize = nfs_io_size(iosize: fsinfo->rtmax, proto: clp->cl_proto); |
| 856 | if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax) |
| 857 | server->wsize = nfs_io_size(iosize: fsinfo->wtmax, proto: clp->cl_proto); |
| 858 | |
| 859 | raw_max_rpc_payload = rpc_max_payload(server->client); |
| 860 | max_rpc_payload = nfs_block_size(bsize: 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(bsize: fsinfo->wtmult, NULL); |
| 874 | |
| 875 | server->dtsize = nfs_block_size(bsize: 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: &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(net: clp->cl_net, id: nfs_net_id); |
| 1009 | |
| 1010 | spin_lock(lock: &nn->nfs_client_lock); |
| 1011 | list_add_tail_rcu(new: &server->client_link, head: &clp->cl_superblocks); |
| 1012 | list_add_tail(new: &server->master_link, head: &nn->nfs_volume_list); |
| 1013 | clear_bit(NFS_CS_STOP_RENEW, addr: &clp->cl_res_state); |
| 1014 | spin_unlock(lock: &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(net: clp->cl_net, id: nfs_net_id); |
| 1027 | spin_lock(lock: &nn->nfs_client_lock); |
| 1028 | list_del_rcu(entry: &server->client_link); |
| 1029 | if (list_empty(head: &clp->cl_superblocks)) |
| 1030 | set_bit(NFS_CS_STOP_RENEW, addr: &clp->cl_res_state); |
| 1031 | list_del(entry: &server->master_link); |
| 1032 | spin_unlock(lock: &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(sizeof(struct nfs_server), GFP_KERNEL); |
| 1048 | if (!server) |
| 1049 | return NULL; |
| 1050 | |
| 1051 | server->s_sysfs_id = ida_alloc(ida: &s_sysfs_ids, GFP_KERNEL); |
| 1052 | if (server->s_sysfs_id < 0) { |
| 1053 | kfree(objp: server); |
| 1054 | return NULL; |
| 1055 | } |
| 1056 | |
| 1057 | server->client = server->client_acl = ERR_PTR(error: -EINVAL); |
| 1058 | |
| 1059 | /* Zero out the NFS state stuff */ |
| 1060 | INIT_LIST_HEAD(list: &server->client_link); |
| 1061 | INIT_LIST_HEAD(list: &server->master_link); |
| 1062 | INIT_LIST_HEAD(list: &server->delegations); |
| 1063 | INIT_LIST_HEAD(list: &server->layouts); |
| 1064 | INIT_LIST_HEAD(list: &server->state_owners_lru); |
| 1065 | INIT_LIST_HEAD(list: &server->ss_copies); |
| 1066 | INIT_LIST_HEAD(list: &server->ss_src_copies); |
| 1067 | |
| 1068 | atomic_set(v: &server->active, i: 0); |
| 1069 | atomic_long_set(v: &server->nr_active_delegations, i: 0); |
| 1070 | |
| 1071 | server->io_stats = nfs_alloc_iostats(); |
| 1072 | if (!server->io_stats) { |
| 1073 | kfree(objp: server); |
| 1074 | return NULL; |
| 1075 | } |
| 1076 | |
| 1077 | server->change_attr_type = NFS4_CHANGE_TYPE_IS_UNDEFINED; |
| 1078 | |
| 1079 | init_waitqueue_head(&server->write_congestion_wait); |
| 1080 | atomic_long_set(v: &server->writeback, i: 0); |
| 1081 | |
| 1082 | atomic64_set(v: &server->owner_ctr, i: 0); |
| 1083 | |
| 1084 | pnfs_init_server(server); |
| 1085 | rpc_init_wait_queue(&server->uoc_rpcwaitq, "NFS UOC" ); |
| 1086 | |
| 1087 | return server; |
| 1088 | } |
| 1089 | EXPORT_SYMBOL_GPL(nfs_alloc_server); |
| 1090 | |
| 1091 | static void delayed_free(struct rcu_head *p) |
| 1092 | { |
| 1093 | struct nfs_server *server = container_of(p, struct nfs_server, rcu); |
| 1094 | |
| 1095 | nfs_free_iostats(stats: server->io_stats); |
| 1096 | kfree(objp: server); |
| 1097 | } |
| 1098 | |
| 1099 | /* |
| 1100 | * Free up a server record |
| 1101 | */ |
| 1102 | void nfs_free_server(struct nfs_server *server) |
| 1103 | { |
| 1104 | nfs_server_remove_lists(server); |
| 1105 | |
| 1106 | if (server->destroy != NULL) |
| 1107 | server->destroy(server); |
| 1108 | |
| 1109 | if (!IS_ERR(ptr: server->client_acl)) |
| 1110 | rpc_shutdown_client(server->client_acl); |
| 1111 | if (!IS_ERR(ptr: server->client)) |
| 1112 | rpc_shutdown_client(server->client); |
| 1113 | |
| 1114 | nfs_put_client(server->nfs_client); |
| 1115 | |
| 1116 | if (server->kobj.state_initialized) { |
| 1117 | nfs_sysfs_remove_server(s: server); |
| 1118 | kobject_put(kobj: &server->kobj); |
| 1119 | } |
| 1120 | ida_free(&s_sysfs_ids, id: server->s_sysfs_id); |
| 1121 | |
| 1122 | put_cred(cred: server->cred); |
| 1123 | nfs_release_automount_timer(); |
| 1124 | call_rcu(head: &server->rcu, func: delayed_free); |
| 1125 | } |
| 1126 | EXPORT_SYMBOL_GPL(nfs_free_server); |
| 1127 | |
| 1128 | /* |
| 1129 | * Create a version 2 or 3 volume record |
| 1130 | * - keyed on server and FSID |
| 1131 | */ |
| 1132 | struct nfs_server *nfs_create_server(struct fs_context *fc) |
| 1133 | { |
| 1134 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
| 1135 | struct nfs_server *server; |
| 1136 | struct nfs_fattr *fattr; |
| 1137 | int error; |
| 1138 | |
| 1139 | server = nfs_alloc_server(); |
| 1140 | if (!server) |
| 1141 | return ERR_PTR(error: -ENOMEM); |
| 1142 | |
| 1143 | server->cred = get_cred(cred: fc->cred); |
| 1144 | |
| 1145 | error = -ENOMEM; |
| 1146 | fattr = nfs_alloc_fattr(); |
| 1147 | if (fattr == NULL) |
| 1148 | goto error; |
| 1149 | |
| 1150 | /* Get a client representation */ |
| 1151 | error = nfs_init_server(server, fc); |
| 1152 | if (error < 0) |
| 1153 | goto error; |
| 1154 | |
| 1155 | /* Probe the root fh to retrieve its FSID */ |
| 1156 | error = nfs_probe_fsinfo(server, mntfh: ctx->mntfh, fattr); |
| 1157 | if (error < 0) |
| 1158 | goto error; |
| 1159 | if (server->nfs_client->rpc_ops->version == 3) { |
| 1160 | if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN) |
| 1161 | server->namelen = NFS3_MAXNAMLEN; |
| 1162 | if (!(ctx->flags & NFS_MOUNT_NORDIRPLUS)) |
| 1163 | server->caps |= NFS_CAP_READDIRPLUS; |
| 1164 | } else { |
| 1165 | if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN) |
| 1166 | server->namelen = NFS2_MAXNAMLEN; |
| 1167 | } |
| 1168 | /* Linux 'subtree_check' borkenness mandates this setting */ |
| 1169 | server->fh_expire_type = NFS_FH_VOL_RENAME; |
| 1170 | |
| 1171 | if (!(fattr->valid & NFS_ATTR_FATTR)) { |
| 1172 | error = ctx->nfs_mod->rpc_ops->getattr(server, ctx->mntfh, |
| 1173 | fattr, NULL); |
| 1174 | if (error < 0) { |
| 1175 | dprintk("nfs_create_server: getattr error = %d\n" , -error); |
| 1176 | goto error; |
| 1177 | } |
| 1178 | } |
| 1179 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 1180 | |
| 1181 | dprintk("Server FSID: %llx:%llx\n" , |
| 1182 | (unsigned long long) server->fsid.major, |
| 1183 | (unsigned long long) server->fsid.minor); |
| 1184 | |
| 1185 | nfs_server_insert_lists(server); |
| 1186 | server->mount_time = jiffies; |
| 1187 | nfs_free_fattr(fattr); |
| 1188 | return server; |
| 1189 | |
| 1190 | error: |
| 1191 | nfs_free_fattr(fattr); |
| 1192 | nfs_free_server(server); |
| 1193 | return ERR_PTR(error); |
| 1194 | } |
| 1195 | EXPORT_SYMBOL_GPL(nfs_create_server); |
| 1196 | |
| 1197 | /* |
| 1198 | * Clone an NFS2, NFS3 or NFS4 server record |
| 1199 | */ |
| 1200 | struct nfs_server *nfs_clone_server(struct nfs_server *source, |
| 1201 | struct nfs_fh *fh, |
| 1202 | struct nfs_fattr *fattr, |
| 1203 | rpc_authflavor_t flavor) |
| 1204 | { |
| 1205 | struct nfs_server *server; |
| 1206 | int error; |
| 1207 | |
| 1208 | server = nfs_alloc_server(); |
| 1209 | if (!server) |
| 1210 | return ERR_PTR(error: -ENOMEM); |
| 1211 | |
| 1212 | server->cred = get_cred(cred: source->cred); |
| 1213 | |
| 1214 | /* Copy data from the source */ |
| 1215 | server->nfs_client = source->nfs_client; |
| 1216 | server->destroy = source->destroy; |
| 1217 | refcount_inc(r: &server->nfs_client->cl_count); |
| 1218 | nfs_server_copy_userdata(server, source); |
| 1219 | |
| 1220 | server->fsid = fattr->fsid; |
| 1221 | |
| 1222 | nfs_sysfs_add_server(s: server); |
| 1223 | |
| 1224 | nfs_sysfs_link_rpc_client(server, |
| 1225 | clnt: server->nfs_client->cl_rpcclient, sysfs_prefix: "_state" ); |
| 1226 | |
| 1227 | error = nfs_init_server_rpcclient(server, |
| 1228 | source->client->cl_timeout, |
| 1229 | flavor); |
| 1230 | if (error < 0) |
| 1231 | goto out_free_server; |
| 1232 | |
| 1233 | nfs_server_set_init_caps(server); |
| 1234 | |
| 1235 | /* probe the filesystem info for this server filesystem */ |
| 1236 | error = nfs_probe_server(server, fh); |
| 1237 | if (error < 0) |
| 1238 | goto out_free_server; |
| 1239 | |
| 1240 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
| 1241 | server->namelen = NFS4_MAXNAMLEN; |
| 1242 | |
| 1243 | error = nfs_start_lockd(server); |
| 1244 | if (error < 0) |
| 1245 | goto out_free_server; |
| 1246 | |
| 1247 | nfs_server_insert_lists(server); |
| 1248 | server->mount_time = jiffies; |
| 1249 | |
| 1250 | return server; |
| 1251 | |
| 1252 | out_free_server: |
| 1253 | nfs_free_server(server); |
| 1254 | return ERR_PTR(error); |
| 1255 | } |
| 1256 | EXPORT_SYMBOL_GPL(nfs_clone_server); |
| 1257 | |
| 1258 | void nfs_clients_init(struct net *net) |
| 1259 | { |
| 1260 | struct nfs_net *nn = net_generic(net, id: nfs_net_id); |
| 1261 | |
| 1262 | INIT_LIST_HEAD(list: &nn->nfs_client_list); |
| 1263 | INIT_LIST_HEAD(list: &nn->nfs_volume_list); |
| 1264 | #if IS_ENABLED(CONFIG_NFS_V4) |
| 1265 | idr_init(idr: &nn->cb_ident_idr); |
| 1266 | #endif |
| 1267 | #if IS_ENABLED(CONFIG_NFS_V4_1) |
| 1268 | INIT_LIST_HEAD(list: &nn->nfs4_data_server_cache); |
| 1269 | spin_lock_init(&nn->nfs4_data_server_lock); |
| 1270 | #endif |
| 1271 | spin_lock_init(&nn->nfs_client_lock); |
| 1272 | nn->boot_time = ktime_get_real(); |
| 1273 | memset(&nn->rpcstats, 0, sizeof(nn->rpcstats)); |
| 1274 | nn->rpcstats.program = &nfs_program; |
| 1275 | |
| 1276 | nfs_netns_sysfs_setup(netns: nn, net); |
| 1277 | } |
| 1278 | |
| 1279 | void nfs_clients_exit(struct net *net) |
| 1280 | { |
| 1281 | struct nfs_net *nn = net_generic(net, id: nfs_net_id); |
| 1282 | |
| 1283 | nfs_netns_sysfs_destroy(netns: nn); |
| 1284 | nfs_cleanup_cb_ident_idr(net); |
| 1285 | WARN_ON_ONCE(!list_empty(&nn->nfs_client_list)); |
| 1286 | WARN_ON_ONCE(!list_empty(&nn->nfs_volume_list)); |
| 1287 | #if IS_ENABLED(CONFIG_NFS_V4_1) |
| 1288 | WARN_ON_ONCE(!list_empty(&nn->nfs4_data_server_cache)); |
| 1289 | #endif |
| 1290 | } |
| 1291 | |
| 1292 | #ifdef CONFIG_PROC_FS |
| 1293 | static void *nfs_server_list_start(struct seq_file *p, loff_t *pos); |
| 1294 | static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos); |
| 1295 | static void nfs_server_list_stop(struct seq_file *p, void *v); |
| 1296 | static int nfs_server_list_show(struct seq_file *m, void *v); |
| 1297 | |
| 1298 | static const struct seq_operations nfs_server_list_ops = { |
| 1299 | .start = nfs_server_list_start, |
| 1300 | .next = nfs_server_list_next, |
| 1301 | .stop = nfs_server_list_stop, |
| 1302 | .show = nfs_server_list_show, |
| 1303 | }; |
| 1304 | |
| 1305 | static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos); |
| 1306 | static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos); |
| 1307 | static void nfs_volume_list_stop(struct seq_file *p, void *v); |
| 1308 | static int nfs_volume_list_show(struct seq_file *m, void *v); |
| 1309 | |
| 1310 | static const struct seq_operations nfs_volume_list_ops = { |
| 1311 | .start = nfs_volume_list_start, |
| 1312 | .next = nfs_volume_list_next, |
| 1313 | .stop = nfs_volume_list_stop, |
| 1314 | .show = nfs_volume_list_show, |
| 1315 | }; |
| 1316 | |
| 1317 | /* |
| 1318 | * set up the iterator to start reading from the server list and return the first item |
| 1319 | */ |
| 1320 | static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos) |
| 1321 | __acquires(&nn->nfs_client_lock) |
| 1322 | { |
| 1323 | struct nfs_net *nn = net_generic(net: seq_file_net(seq: m), id: nfs_net_id); |
| 1324 | |
| 1325 | /* lock the list against modification */ |
| 1326 | spin_lock(lock: &nn->nfs_client_lock); |
| 1327 | return seq_list_start_head(head: &nn->nfs_client_list, pos: *_pos); |
| 1328 | } |
| 1329 | |
| 1330 | /* |
| 1331 | * move to next server |
| 1332 | */ |
| 1333 | static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos) |
| 1334 | { |
| 1335 | struct nfs_net *nn = net_generic(net: seq_file_net(seq: p), id: nfs_net_id); |
| 1336 | |
| 1337 | return seq_list_next(v, head: &nn->nfs_client_list, ppos: pos); |
| 1338 | } |
| 1339 | |
| 1340 | /* |
| 1341 | * clean up after reading from the transports list |
| 1342 | */ |
| 1343 | static void nfs_server_list_stop(struct seq_file *p, void *v) |
| 1344 | __releases(&nn->nfs_client_lock) |
| 1345 | { |
| 1346 | struct nfs_net *nn = net_generic(net: seq_file_net(seq: p), id: nfs_net_id); |
| 1347 | |
| 1348 | spin_unlock(lock: &nn->nfs_client_lock); |
| 1349 | } |
| 1350 | |
| 1351 | /* |
| 1352 | * display a header line followed by a load of call lines |
| 1353 | */ |
| 1354 | static int nfs_server_list_show(struct seq_file *m, void *v) |
| 1355 | { |
| 1356 | struct nfs_client *clp; |
| 1357 | struct nfs_net *nn = net_generic(net: seq_file_net(seq: m), id: nfs_net_id); |
| 1358 | |
| 1359 | /* display header on line 1 */ |
| 1360 | if (v == &nn->nfs_client_list) { |
| 1361 | seq_puts(m, s: "NV SERVER PORT USE HOSTNAME\n" ); |
| 1362 | return 0; |
| 1363 | } |
| 1364 | |
| 1365 | /* display one transport per line on subsequent lines */ |
| 1366 | clp = list_entry(v, struct nfs_client, cl_share_link); |
| 1367 | |
| 1368 | /* Check if the client is initialized */ |
| 1369 | if (clp->cl_cons_state != NFS_CS_READY) |
| 1370 | return 0; |
| 1371 | |
| 1372 | rcu_read_lock(); |
| 1373 | seq_printf(m, fmt: "v%u %s %s %3d %s\n" , |
| 1374 | clp->rpc_ops->version, |
| 1375 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
| 1376 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), |
| 1377 | refcount_read(r: &clp->cl_count), |
| 1378 | clp->cl_hostname); |
| 1379 | rcu_read_unlock(); |
| 1380 | |
| 1381 | return 0; |
| 1382 | } |
| 1383 | |
| 1384 | /* |
| 1385 | * set up the iterator to start reading from the volume list and return the first item |
| 1386 | */ |
| 1387 | static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos) |
| 1388 | __acquires(&nn->nfs_client_lock) |
| 1389 | { |
| 1390 | struct nfs_net *nn = net_generic(net: seq_file_net(seq: m), id: nfs_net_id); |
| 1391 | |
| 1392 | /* lock the list against modification */ |
| 1393 | spin_lock(lock: &nn->nfs_client_lock); |
| 1394 | return seq_list_start_head(head: &nn->nfs_volume_list, pos: *_pos); |
| 1395 | } |
| 1396 | |
| 1397 | /* |
| 1398 | * move to next volume |
| 1399 | */ |
| 1400 | static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos) |
| 1401 | { |
| 1402 | struct nfs_net *nn = net_generic(net: seq_file_net(seq: p), id: nfs_net_id); |
| 1403 | |
| 1404 | return seq_list_next(v, head: &nn->nfs_volume_list, ppos: pos); |
| 1405 | } |
| 1406 | |
| 1407 | /* |
| 1408 | * clean up after reading from the transports list |
| 1409 | */ |
| 1410 | static void nfs_volume_list_stop(struct seq_file *p, void *v) |
| 1411 | __releases(&nn->nfs_client_lock) |
| 1412 | { |
| 1413 | struct nfs_net *nn = net_generic(net: seq_file_net(seq: p), id: nfs_net_id); |
| 1414 | |
| 1415 | spin_unlock(lock: &nn->nfs_client_lock); |
| 1416 | } |
| 1417 | |
| 1418 | /* |
| 1419 | * display a header line followed by a load of call lines |
| 1420 | */ |
| 1421 | static int nfs_volume_list_show(struct seq_file *m, void *v) |
| 1422 | { |
| 1423 | struct nfs_server *server; |
| 1424 | struct nfs_client *clp; |
| 1425 | char dev[13]; // 8 for 2^24, 1 for ':', 3 for 2^8, 1 for '\0' |
| 1426 | char fsid[34]; // 2 * 16 for %llx, 1 for ':', 1 for '\0' |
| 1427 | struct nfs_net *nn = net_generic(net: seq_file_net(seq: m), id: nfs_net_id); |
| 1428 | |
| 1429 | /* display header on line 1 */ |
| 1430 | if (v == &nn->nfs_volume_list) { |
| 1431 | seq_puts(m, s: "NV SERVER PORT DEV FSID" |
| 1432 | " FSC\n" ); |
| 1433 | return 0; |
| 1434 | } |
| 1435 | /* display one transport per line on subsequent lines */ |
| 1436 | server = list_entry(v, struct nfs_server, master_link); |
| 1437 | clp = server->nfs_client; |
| 1438 | |
| 1439 | snprintf(buf: dev, size: sizeof(dev), fmt: "%u:%u" , |
| 1440 | MAJOR(server->s_dev), MINOR(server->s_dev)); |
| 1441 | |
| 1442 | snprintf(buf: fsid, size: sizeof(fsid), fmt: "%llx:%llx" , |
| 1443 | (unsigned long long) server->fsid.major, |
| 1444 | (unsigned long long) server->fsid.minor); |
| 1445 | |
| 1446 | rcu_read_lock(); |
| 1447 | seq_printf(m, fmt: "v%u %s %s %-12s %-33s %s\n" , |
| 1448 | clp->rpc_ops->version, |
| 1449 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
| 1450 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), |
| 1451 | dev, |
| 1452 | fsid, |
| 1453 | nfs_server_fscache_state(server)); |
| 1454 | rcu_read_unlock(); |
| 1455 | |
| 1456 | return 0; |
| 1457 | } |
| 1458 | |
| 1459 | int nfs_fs_proc_net_init(struct net *net) |
| 1460 | { |
| 1461 | struct nfs_net *nn = net_generic(net, id: nfs_net_id); |
| 1462 | struct proc_dir_entry *p; |
| 1463 | |
| 1464 | nn->proc_nfsfs = proc_net_mkdir(net, name: "nfsfs" , parent: net->proc_net); |
| 1465 | if (!nn->proc_nfsfs) |
| 1466 | goto error_0; |
| 1467 | |
| 1468 | /* a file of servers with which we're dealing */ |
| 1469 | p = proc_create_net("servers" , S_IFREG|S_IRUGO, nn->proc_nfsfs, |
| 1470 | &nfs_server_list_ops, sizeof(struct seq_net_private)); |
| 1471 | if (!p) |
| 1472 | goto error_1; |
| 1473 | |
| 1474 | /* a file of volumes that we have mounted */ |
| 1475 | p = proc_create_net("volumes" , S_IFREG|S_IRUGO, nn->proc_nfsfs, |
| 1476 | &nfs_volume_list_ops, sizeof(struct seq_net_private)); |
| 1477 | if (!p) |
| 1478 | goto error_1; |
| 1479 | return 0; |
| 1480 | |
| 1481 | error_1: |
| 1482 | remove_proc_subtree("nfsfs" , net->proc_net); |
| 1483 | error_0: |
| 1484 | return -ENOMEM; |
| 1485 | } |
| 1486 | |
| 1487 | void nfs_fs_proc_net_exit(struct net *net) |
| 1488 | { |
| 1489 | remove_proc_subtree("nfsfs" , net->proc_net); |
| 1490 | } |
| 1491 | |
| 1492 | /* |
| 1493 | * initialise the /proc/fs/nfsfs/ directory |
| 1494 | */ |
| 1495 | int __init nfs_fs_proc_init(void) |
| 1496 | { |
| 1497 | if (!proc_mkdir("fs/nfsfs" , NULL)) |
| 1498 | goto error_0; |
| 1499 | |
| 1500 | /* a file of servers with which we're dealing */ |
| 1501 | if (!proc_symlink("fs/nfsfs/servers" , NULL, "../../net/nfsfs/servers" )) |
| 1502 | goto error_1; |
| 1503 | |
| 1504 | /* a file of volumes that we have mounted */ |
| 1505 | if (!proc_symlink("fs/nfsfs/volumes" , NULL, "../../net/nfsfs/volumes" )) |
| 1506 | goto error_1; |
| 1507 | |
| 1508 | return 0; |
| 1509 | error_1: |
| 1510 | remove_proc_subtree("fs/nfsfs" , NULL); |
| 1511 | error_0: |
| 1512 | return -ENOMEM; |
| 1513 | } |
| 1514 | |
| 1515 | /* |
| 1516 | * clean up the /proc/fs/nfsfs/ directory |
| 1517 | */ |
| 1518 | void nfs_fs_proc_exit(void) |
| 1519 | { |
| 1520 | remove_proc_subtree("fs/nfsfs" , NULL); |
| 1521 | ida_destroy(ida: &s_sysfs_ids); |
| 1522 | } |
| 1523 | |
| 1524 | #endif /* CONFIG_PROC_FS */ |
| 1525 | |