Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nfs4client.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
3  * Written by David Howells ([email protected])
4  */
5 #include <linux/module.h>
6 #include <linux/nfs_fs.h>
7 #include <linux/nfs_idmap.h>
8 #include <linux/nfs_mount.h>
9 #include <linux/sunrpc/auth.h>
10 #include <linux/sunrpc/xprt.h>
11 #include <linux/sunrpc/bc_xprt.h>
12 #include "internal.h"
13 #include "callback.h"
14 #include "delegation.h"
15 #include "pnfs.h"
16 #include "netns.h"
17 
18 #define NFSDBG_FACILITY NFSDBG_CLIENT
19 
20 /*
21  * Get a unique NFSv4.0 callback identifier which will be used
22  * by the V4.0 callback service to lookup the nfs_client struct
23  */
24 static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion)
25 {
26  int ret = 0;
27  struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
28 
29  if (clp->rpc_ops->version != 4 || minorversion != 0)
30  return ret;
31 retry:
32  if (!idr_pre_get(&nn->cb_ident_idr, GFP_KERNEL))
33  return -ENOMEM;
34  spin_lock(&nn->nfs_client_lock);
35  ret = idr_get_new(&nn->cb_ident_idr, clp, &clp->cl_cb_ident);
36  spin_unlock(&nn->nfs_client_lock);
37  if (ret == -EAGAIN)
38  goto retry;
39  return ret;
40 }
41 
42 #ifdef CONFIG_NFS_V4_1
43 static void nfs4_shutdown_session(struct nfs_client *clp)
44 {
45  if (nfs4_has_session(clp)) {
46  nfs4_destroy_session(clp->cl_session);
47  nfs4_destroy_clientid(clp);
48  }
49 
50 }
51 #else /* CONFIG_NFS_V4_1 */
52 static void nfs4_shutdown_session(struct nfs_client *clp)
53 {
54 }
55 #endif /* CONFIG_NFS_V4_1 */
56 
57 struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init)
58 {
59  int err;
60  struct nfs_client *clp = nfs_alloc_client(cl_init);
61  if (IS_ERR(clp))
62  return clp;
63 
64  err = nfs_get_cb_ident_idr(clp, cl_init->minorversion);
65  if (err)
66  goto error;
67 
68  spin_lock_init(&clp->cl_lock);
69  INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state);
70  rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client");
71  clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
72  clp->cl_minorversion = cl_init->minorversion;
73  clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion];
74  return clp;
75 
76 error:
77  nfs_free_client(clp);
78  return ERR_PTR(err);
79 }
80 
81 /*
82  * Destroy the NFS4 callback service
83  */
84 static void nfs4_destroy_callback(struct nfs_client *clp)
85 {
87  nfs_callback_down(clp->cl_mvops->minor_version, clp->cl_net);
88 }
89 
90 static void nfs4_shutdown_client(struct nfs_client *clp)
91 {
93  nfs4_kill_renewd(clp);
94  nfs4_shutdown_session(clp);
95  nfs4_destroy_callback(clp);
97  nfs_idmap_delete(clp);
98 
99  rpc_destroy_wait_queue(&clp->cl_rpcwaitq);
100  kfree(clp->cl_serverowner);
101  kfree(clp->cl_serverscope);
102  kfree(clp->cl_implid);
103 }
104 
105 void nfs4_free_client(struct nfs_client *clp)
106 {
107  nfs4_shutdown_client(clp);
108  nfs_free_client(clp);
109 }
110 
111 /*
112  * Initialize the NFS4 callback service
113  */
114 static int nfs4_init_callback(struct nfs_client *clp)
115 {
116  int error;
117 
118  if (clp->rpc_ops->version == 4) {
119  struct rpc_xprt *xprt;
120 
121  xprt = rcu_dereference_raw(clp->cl_rpcclient->cl_xprt);
122 
123  if (nfs4_has_session(clp)) {
124  error = xprt_setup_backchannel(xprt,
126  if (error < 0)
127  return error;
128  }
129 
130  error = nfs_callback_up(clp->cl_mvops->minor_version, xprt);
131  if (error < 0) {
132  dprintk("%s: failed to start callback. Error = %d\n",
133  __func__, error);
134  return error;
135  }
137  }
138  return 0;
139 }
140 
141 /*
142  * Initialize the minor version specific parts of an NFS4 client record
143  */
144 static int nfs4_init_client_minor_version(struct nfs_client *clp)
145 {
146 #if defined(CONFIG_NFS_V4_1)
147  if (clp->cl_mvops->minor_version) {
148  struct nfs4_session *session = NULL;
149  /*
150  * Create the session and mark it expired.
151  * When a SEQUENCE operation encounters the expired session
152  * it will do session recovery to initialize it.
153  */
154  session = nfs4_alloc_session(clp);
155  if (!session)
156  return -ENOMEM;
157 
158  clp->cl_session = session;
159  /*
160  * The create session reply races with the server back
161  * channel probe. Mark the client NFS_CS_SESSION_INITING
162  * so that the client back channel can find the
163  * nfs_client struct
164  */
166  }
167 #endif /* CONFIG_NFS_V4_1 */
168 
169  return nfs4_init_callback(clp);
170 }
171 
183  const struct rpc_timeout *timeparms,
184  const char *ip_addr,
185  rpc_authflavor_t authflavour)
186 {
187  char buf[INET6_ADDRSTRLEN + 1];
188  struct nfs_client *old;
189  int error;
190 
191  if (clp->cl_cons_state == NFS_CS_READY) {
192  /* the client is initialised already */
193  dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp);
194  return clp;
195  }
196 
197  /* Check NFS protocol revision and initialize RPC op vector */
198  clp->rpc_ops = &nfs_v4_clientops;
199 
201  error = nfs_create_rpc_client(clp, timeparms, authflavour);
202  if (error < 0)
203  goto error;
204 
205  /* If no clientaddr= option was specified, find a usable cb address */
206  if (ip_addr == NULL) {
207  struct sockaddr_storage cb_addr;
208  struct sockaddr *sap = (struct sockaddr *)&cb_addr;
209 
210  error = rpc_localaddr(clp->cl_rpcclient, sap, sizeof(cb_addr));
211  if (error < 0)
212  goto error;
213  error = rpc_ntop(sap, buf, sizeof(buf));
214  if (error < 0)
215  goto error;
216  ip_addr = (const char *)buf;
217  }
218  strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
219 
220  error = nfs_idmap_new(clp);
221  if (error < 0) {
222  dprintk("%s: failed to create idmapper. Error = %d\n",
223  __func__, error);
224  goto error;
225  }
227 
228  error = nfs4_init_client_minor_version(clp);
229  if (error < 0)
230  goto error;
231 
232  if (!nfs4_has_session(clp))
234 
235  error = nfs4_discover_server_trunking(clp, &old);
236  if (error < 0)
237  goto error;
238  if (clp != old) {
239  clp->cl_preserve_clid = true;
240  nfs_put_client(clp);
241  clp = old;
242  atomic_inc(&clp->cl_count);
243  }
244 
245  return clp;
246 
247 error:
248  nfs_mark_client_ready(clp, error);
249  nfs_put_client(clp);
250  dprintk("<-- nfs4_init_client() = xerror %d\n", error);
251  return ERR_PTR(error);
252 }
253 
254 /*
255  * SETCLIENTID just did a callback update with the callback ident in
256  * "drop," but server trunking discovery claims "drop" and "keep" are
257  * actually the same server. Swap the callback IDs so that "keep"
258  * will continue to use the callback ident the server now knows about,
259  * and so that "keep"'s original callback ident is destroyed when
260  * "drop" is freed.
261  */
262 static void nfs4_swap_callback_idents(struct nfs_client *keep,
263  struct nfs_client *drop)
264 {
265  struct nfs_net *nn = net_generic(keep->cl_net, nfs_net_id);
266  unsigned int save = keep->cl_cb_ident;
267 
268  if (keep->cl_cb_ident == drop->cl_cb_ident)
269  return;
270 
271  dprintk("%s: keeping callback ident %u and dropping ident %u\n",
272  __func__, keep->cl_cb_ident, drop->cl_cb_ident);
273 
274  spin_lock(&nn->nfs_client_lock);
275 
276  idr_replace(&nn->cb_ident_idr, keep, drop->cl_cb_ident);
277  keep->cl_cb_ident = drop->cl_cb_ident;
278 
279  idr_replace(&nn->cb_ident_idr, drop, save);
280  drop->cl_cb_ident = save;
281 
282  spin_unlock(&nn->nfs_client_lock);
283 }
284 
299  struct nfs_client **result,
300  struct rpc_cred *cred)
301 {
302  struct nfs_net *nn = net_generic(new->cl_net, nfs_net_id);
303  struct nfs_client *pos, *n, *prev = NULL;
304  struct nfs4_setclientid_res clid = {
305  .clientid = new->cl_clientid,
306  .confirm = new->cl_confirm,
307  };
308  int status;
309 
310  spin_lock(&nn->nfs_client_lock);
311  list_for_each_entry_safe(pos, n, &nn->nfs_client_list, cl_share_link) {
312  /* If "pos" isn't marked ready, we can't trust the
313  * remaining fields in "pos" */
314  if (pos->cl_cons_state < NFS_CS_READY)
315  continue;
316 
317  if (pos->rpc_ops != new->rpc_ops)
318  continue;
319 
320  if (pos->cl_proto != new->cl_proto)
321  continue;
322 
323  if (pos->cl_minorversion != new->cl_minorversion)
324  continue;
325 
326  if (pos->cl_clientid != new->cl_clientid)
327  continue;
328 
329  atomic_inc(&pos->cl_count);
330  spin_unlock(&nn->nfs_client_lock);
331 
332  if (prev)
333  nfs_put_client(prev);
334 
335  status = nfs4_proc_setclientid_confirm(pos, &clid, cred);
336  if (status == 0) {
337  nfs4_swap_callback_idents(pos, new);
338 
339  nfs_put_client(pos);
340  *result = pos;
341  dprintk("NFS: <-- %s using nfs_client = %p ({%d})\n",
342  __func__, pos, atomic_read(&pos->cl_count));
343  return 0;
344  }
345  if (status != -NFS4ERR_STALE_CLIENTID) {
346  nfs_put_client(pos);
347  dprintk("NFS: <-- %s status = %d, no result\n",
348  __func__, status);
349  return status;
350  }
351 
352  spin_lock(&nn->nfs_client_lock);
353  prev = pos;
354  }
355 
356  /*
357  * No matching nfs_client found. This should be impossible,
358  * because the new nfs_client has already been added to
359  * nfs_client_list by nfs_get_client().
360  *
361  * Don't BUG(), since the caller is holding a mutex.
362  */
363  if (prev)
364  nfs_put_client(prev);
365  spin_unlock(&nn->nfs_client_lock);
366  pr_err("NFS: %s Error: no matching nfs_client found\n", __func__);
367  return -NFS4ERR_STALE_CLIENTID;
368 }
369 
370 #ifdef CONFIG_NFS_V4_1
371 /*
372  * Returns true if the client IDs match
373  */
374 static bool nfs4_match_clientids(struct nfs_client *a, struct nfs_client *b)
375 {
376  if (a->cl_clientid != b->cl_clientid) {
377  dprintk("NFS: --> %s client ID %llx does not match %llx\n",
378  __func__, a->cl_clientid, b->cl_clientid);
379  return false;
380  }
381  dprintk("NFS: --> %s client ID %llx matches %llx\n",
382  __func__, a->cl_clientid, b->cl_clientid);
383  return true;
384 }
385 
386 /*
387  * Returns true if the server owners match
388  */
389 static bool
390 nfs4_match_serverowners(struct nfs_client *a, struct nfs_client *b)
391 {
392  struct nfs41_server_owner *o1 = a->cl_serverowner;
393  struct nfs41_server_owner *o2 = b->cl_serverowner;
394 
395  if (o1->minor_id != o2->minor_id) {
396  dprintk("NFS: --> %s server owner minor IDs do not match\n",
397  __func__);
398  return false;
399  }
400 
401  if (o1->major_id_sz != o2->major_id_sz)
402  goto out_major_mismatch;
403  if (memcmp(o1->major_id, o2->major_id, o1->major_id_sz) != 0)
404  goto out_major_mismatch;
405 
406  dprintk("NFS: --> %s server owners match\n", __func__);
407  return true;
408 
409 out_major_mismatch:
410  dprintk("NFS: --> %s server owner major IDs do not match\n",
411  __func__);
412  return false;
413 }
414 
428 int nfs41_walk_client_list(struct nfs_client *new,
429  struct nfs_client **result,
430  struct rpc_cred *cred)
431 {
432  struct nfs_net *nn = net_generic(new->cl_net, nfs_net_id);
433  struct nfs_client *pos, *n, *prev = NULL;
434  int error;
435 
436  spin_lock(&nn->nfs_client_lock);
438  /* If "pos" isn't marked ready, we can't trust the
439  * remaining fields in "pos", especially the client
440  * ID and serverowner fields. Wait for CREATE_SESSION
441  * to finish. */
442  if (pos->cl_cons_state < NFS_CS_READY) {
443  atomic_inc(&pos->cl_count);
444  spin_unlock(&nn->nfs_client_lock);
445 
446  if (prev)
447  nfs_put_client(prev);
448  prev = pos;
449 
450  error = nfs_wait_client_init_complete(pos);
451  if (error < 0) {
452  nfs_put_client(pos);
453  spin_lock(&nn->nfs_client_lock);
454  continue;
455  }
456 
457  spin_lock(&nn->nfs_client_lock);
458  }
459 
460  if (pos->rpc_ops != new->rpc_ops)
461  continue;
462 
463  if (pos->cl_proto != new->cl_proto)
464  continue;
465 
466  if (pos->cl_minorversion != new->cl_minorversion)
467  continue;
468 
469  if (!nfs4_match_clientids(pos, new))
470  continue;
471 
472  if (!nfs4_match_serverowners(pos, new))
473  continue;
474 
475  spin_unlock(&nn->nfs_client_lock);
476  dprintk("NFS: <-- %s using nfs_client = %p ({%d})\n",
477  __func__, pos, atomic_read(&pos->cl_count));
478 
479  *result = pos;
480  return 0;
481  }
482 
483  /*
484  * No matching nfs_client found. This should be impossible,
485  * because the new nfs_client has already been added to
486  * nfs_client_list by nfs_get_client().
487  *
488  * Don't BUG(), since the caller is holding a mutex.
489  */
490  spin_unlock(&nn->nfs_client_lock);
491  pr_err("NFS: %s Error: no matching nfs_client found\n", __func__);
492  return -NFS4ERR_STALE_CLIENTID;
493 }
494 #endif /* CONFIG_NFS_V4_1 */
495 
496 static void nfs4_destroy_server(struct nfs_server *server)
497 {
499  unset_pnfs_layoutdriver(server);
500  nfs4_purge_state_owners(server);
501 }
502 
503 /*
504  * NFSv4.0 callback thread helper
505  *
506  * Find a client by callback identifier
507  */
508 struct nfs_client *
509 nfs4_find_client_ident(struct net *net, int cb_ident)
510 {
511  struct nfs_client *clp;
512  struct nfs_net *nn = net_generic(net, nfs_net_id);
513 
514  spin_lock(&nn->nfs_client_lock);
515  clp = idr_find(&nn->cb_ident_idr, cb_ident);
516  if (clp)
517  atomic_inc(&clp->cl_count);
518  spin_unlock(&nn->nfs_client_lock);
519  return clp;
520 }
521 
522 #if defined(CONFIG_NFS_V4_1)
523 /* Common match routine for v4.0 and v4.1 callback services */
524 static bool nfs4_cb_match_client(const struct sockaddr *addr,
525  struct nfs_client *clp, u32 minorversion)
526 {
527  struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
528 
529  /* Don't match clients that failed to initialise */
530  if (!(clp->cl_cons_state == NFS_CS_READY ||
532  return false;
533 
534  smp_rmb();
535 
536  /* Match the version and minorversion */
537  if (clp->rpc_ops->version != 4 ||
538  clp->cl_minorversion != minorversion)
539  return false;
540 
541  /* Match only the IP address, not the port number */
542  if (!nfs_sockaddr_match_ipaddr(addr, clap))
543  return false;
544 
545  return true;
546 }
547 
548 /*
549  * NFSv4.1 callback thread helper
550  * For CB_COMPOUND calls, find a client by IP address, protocol version,
551  * minorversion, and sessionID
552  *
553  * Returns NULL if no such client
554  */
555 struct nfs_client *
556 nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr,
557  struct nfs4_sessionid *sid)
558 {
559  struct nfs_client *clp;
560  struct nfs_net *nn = net_generic(net, nfs_net_id);
561 
562  spin_lock(&nn->nfs_client_lock);
563  list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
564  if (nfs4_cb_match_client(addr, clp, 1) == false)
565  continue;
566 
567  if (!nfs4_has_session(clp))
568  continue;
569 
570  /* Match sessionid*/
571  if (memcmp(clp->cl_session->sess_id.data,
572  sid->data, NFS4_MAX_SESSIONID_LEN) != 0)
573  continue;
574 
575  atomic_inc(&clp->cl_count);
576  spin_unlock(&nn->nfs_client_lock);
577  return clp;
578  }
579  spin_unlock(&nn->nfs_client_lock);
580  return NULL;
581 }
582 
583 #else /* CONFIG_NFS_V4_1 */
584 
585 struct nfs_client *
586 nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr,
587  struct nfs4_sessionid *sid)
588 {
589  return NULL;
590 }
591 #endif /* CONFIG_NFS_V4_1 */
592 
593 /*
594  * Set up an NFS4 client
595  */
596 static int nfs4_set_client(struct nfs_server *server,
597  const char *hostname,
598  const struct sockaddr *addr,
599  const size_t addrlen,
600  const char *ip_addr,
601  rpc_authflavor_t authflavour,
602  int proto, const struct rpc_timeout *timeparms,
603  u32 minorversion, struct net *net)
604 {
605  struct nfs_client_initdata cl_init = {
606  .hostname = hostname,
607  .addr = addr,
608  .addrlen = addrlen,
609  .nfs_mod = &nfs_v4,
610  .proto = proto,
611  .minorversion = minorversion,
612  .net = net,
613  };
614  struct nfs_client *clp;
615  int error;
616 
617  dprintk("--> nfs4_set_client()\n");
618 
619  if (server->flags & NFS_MOUNT_NORESVPORT)
621 
622  /* Allocate or find a client reference we can use */
623  clp = nfs_get_client(&cl_init, timeparms, ip_addr, authflavour);
624  if (IS_ERR(clp)) {
625  error = PTR_ERR(clp);
626  goto error;
627  }
628 
629  /*
630  * Query for the lease time on clientid setup or renewal
631  *
632  * Note that this will be set on nfs_clients that were created
633  * only for the DS role and did not set this bit, but now will
634  * serve a dual role.
635  */
637 
638  server->nfs_client = clp;
639  dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp);
640  return 0;
641 error:
642  dprintk("<-- nfs4_set_client() = xerror %d\n", error);
643  return error;
644 }
645 
646 /*
647  * Set up a pNFS Data Server client.
648  *
649  * Return any existing nfs_client that matches server address,port,version
650  * and minorversion.
651  *
652  * For a new nfs_client, use a soft mount (default), a low retrans and a
653  * low timeout interval so that if a connection is lost, we retry through
654  * the MDS.
655  */
656 struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
657  const struct sockaddr *ds_addr, int ds_addrlen,
658  int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans)
659 {
660  struct nfs_client_initdata cl_init = {
661  .addr = ds_addr,
662  .addrlen = ds_addrlen,
663  .nfs_mod = &nfs_v4,
664  .proto = ds_proto,
665  .minorversion = mds_clp->cl_minorversion,
666  .net = mds_clp->cl_net,
667  };
668  struct rpc_timeout ds_timeout;
669  struct nfs_client *clp;
670 
671  /*
672  * Set an authflavor equual to the MDS value. Use the MDS nfs_client
673  * cl_ipaddr so as to use the same EXCHANGE_ID co_ownerid as the MDS
674  * (section 13.1 RFC 5661).
675  */
676  nfs_init_timeout_values(&ds_timeout, ds_proto, ds_timeo, ds_retrans);
677  clp = nfs_get_client(&cl_init, &ds_timeout, mds_clp->cl_ipaddr,
678  mds_clp->cl_rpcclient->cl_auth->au_flavor);
679 
680  dprintk("<-- %s %p\n", __func__, clp);
681  return clp;
682 }
684 
685 /*
686  * Session has been established, and the client marked ready.
687  * Set the mount rsize and wsize with negotiated fore channel
688  * attributes which will be bound checked in nfs_server_set_fsinfo.
689  */
690 static void nfs4_session_set_rwsize(struct nfs_server *server)
691 {
692 #ifdef CONFIG_NFS_V4_1
693  struct nfs4_session *sess;
694  u32 server_resp_sz;
695  u32 server_rqst_sz;
696 
697  if (!nfs4_has_session(server->nfs_client))
698  return;
699  sess = server->nfs_client->cl_session;
700  server_resp_sz = sess->fc_attrs.max_resp_sz - nfs41_maxread_overhead;
701  server_rqst_sz = sess->fc_attrs.max_rqst_sz - nfs41_maxwrite_overhead;
702 
703  if (server->rsize > server_resp_sz)
704  server->rsize = server_resp_sz;
705  if (server->wsize > server_rqst_sz)
706  server->wsize = server_rqst_sz;
707 #endif /* CONFIG_NFS_V4_1 */
708 }
709 
710 static int nfs4_server_common_setup(struct nfs_server *server,
711  struct nfs_fh *mntfh)
712 {
713  struct nfs_fattr *fattr;
714  int error;
715 
716  BUG_ON(!server->nfs_client);
717  BUG_ON(!server->nfs_client->rpc_ops);
718  BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
719 
720  /* data servers support only a subset of NFSv4.1 */
721  if (is_ds_only_client(server->nfs_client))
722  return -EPROTONOSUPPORT;
723 
724  fattr = nfs_alloc_fattr();
725  if (fattr == NULL)
726  return -ENOMEM;
727 
728  /* We must ensure the session is initialised first */
729  error = nfs4_init_session(server);
730  if (error < 0)
731  goto out;
732 
733  /* Probe the root fh to retrieve its FSID and filehandle */
734  error = nfs4_get_rootfh(server, mntfh);
735  if (error < 0)
736  goto out;
737 
738  dprintk("Server FSID: %llx:%llx\n",
739  (unsigned long long) server->fsid.major,
740  (unsigned long long) server->fsid.minor);
741  dprintk("Mount FH: %d\n", mntfh->size);
742 
743  nfs4_session_set_rwsize(server);
744 
745  error = nfs_probe_fsinfo(server, mntfh, fattr);
746  if (error < 0)
747  goto out;
748 
749  if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
750  server->namelen = NFS4_MAXNAMLEN;
751 
752  nfs_server_insert_lists(server);
753  server->mount_time = jiffies;
754  server->destroy = nfs4_destroy_server;
755 out:
756  nfs_free_fattr(fattr);
757  return error;
758 }
759 
760 /*
761  * Create a version 4 volume record
762  */
763 static int nfs4_init_server(struct nfs_server *server,
764  const struct nfs_parsed_mount_data *data)
765 {
766  struct rpc_timeout timeparms;
767  int error;
768 
769  dprintk("--> nfs4_init_server()\n");
770 
771  nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
772  data->timeo, data->retrans);
773 
774  /* Initialise the client representation from the mount data */
775  server->flags = data->flags;
777  if (!(data->flags & NFS_MOUNT_NORDIRPLUS))
778  server->caps |= NFS_CAP_READDIRPLUS;
779  server->options = data->options;
780 
781  /* Get a client record */
782  error = nfs4_set_client(server,
783  data->nfs_server.hostname,
784  (const struct sockaddr *)&data->nfs_server.address,
785  data->nfs_server.addrlen,
786  data->client_address,
787  data->auth_flavors[0],
788  data->nfs_server.protocol,
789  &timeparms,
790  data->minorversion,
791  data->net);
792  if (error < 0)
793  goto error;
794 
795  /*
796  * Don't use NFS uid/gid mapping if we're using AUTH_SYS or lower
797  * authentication.
798  */
799  if (nfs4_disable_idmapping && data->auth_flavors[0] == RPC_AUTH_UNIX)
800  server->caps |= NFS_CAP_UIDGID_NOMAP;
801 
802  if (data->rsize)
803  server->rsize = nfs_block_size(data->rsize, NULL);
804  if (data->wsize)
805  server->wsize = nfs_block_size(data->wsize, NULL);
806 
807  server->acregmin = data->acregmin * HZ;
808  server->acregmax = data->acregmax * HZ;
809  server->acdirmin = data->acdirmin * HZ;
810  server->acdirmax = data->acdirmax * HZ;
811 
812  server->port = data->nfs_server.port;
813 
814  error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
815 
816 error:
817  /* Done */
818  dprintk("<-- nfs4_init_server() = %d\n", error);
819  return error;
820 }
821 
822 /*
823  * Create a version 4 volume record
824  * - keyed on server and FSID
825  */
826 /*struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
827  struct nfs_fh *mntfh)*/
828 struct nfs_server *nfs4_create_server(struct nfs_mount_info *mount_info,
829  struct nfs_subversion *nfs_mod)
830 {
831  struct nfs_server *server;
832  int error;
833 
834  dprintk("--> nfs4_create_server()\n");
835 
836  server = nfs_alloc_server();
837  if (!server)
838  return ERR_PTR(-ENOMEM);
839 
840  /* set up the general RPC client */
841  error = nfs4_init_server(server, mount_info->parsed);
842  if (error < 0)
843  goto error;
844 
845  error = nfs4_server_common_setup(server, mount_info->mntfh);
846  if (error < 0)
847  goto error;
848 
849  dprintk("<-- nfs4_create_server() = %p\n", server);
850  return server;
851 
852 error:
853  nfs_free_server(server);
854  dprintk("<-- nfs4_create_server() = error %d\n", error);
855  return ERR_PTR(error);
856 }
857 
858 /*
859  * Create an NFS4 referral server record
860  */
862  struct nfs_fh *mntfh)
863 {
864  struct nfs_client *parent_client;
865  struct nfs_server *server, *parent_server;
866  int error;
867 
868  dprintk("--> nfs4_create_referral_server()\n");
869 
870  server = nfs_alloc_server();
871  if (!server)
872  return ERR_PTR(-ENOMEM);
873 
874  parent_server = NFS_SB(data->sb);
875  parent_client = parent_server->nfs_client;
876 
877  /* Initialise the client representation from the parent server */
878  nfs_server_copy_userdata(server, parent_server);
880 
881  /* Get a client representation.
882  * Note: NFSv4 always uses TCP, */
883  error = nfs4_set_client(server, data->hostname,
884  data->addr,
885  data->addrlen,
886  parent_client->cl_ipaddr,
887  data->authflavor,
888  rpc_protocol(parent_server->client),
889  parent_server->client->cl_timeout,
890  parent_client->cl_mvops->minor_version,
891  parent_client->cl_net);
892  if (error < 0)
893  goto error;
894 
895  error = nfs_init_server_rpcclient(server, parent_server->client->cl_timeout, data->authflavor);
896  if (error < 0)
897  goto error;
898 
899  error = nfs4_server_common_setup(server, mntfh);
900  if (error < 0)
901  goto error;
902 
903  dprintk("<-- nfs_create_referral_server() = %p\n", server);
904  return server;
905 
906 error:
907  nfs_free_server(server);
908  dprintk("<-- nfs4_create_referral_server() = error %d\n", error);
909  return ERR_PTR(error);
910 }