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