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