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