blob: 661a0f6112156ce554be5124c4cadec2294ce6cb [file] [log] [blame]
Andy Adamson16b374c2010-10-20 00:18:04 -04001/*
2 * Device operations for the pnfs nfs4 file layout driver.
3 *
4 * Copyright (c) 2002
5 * The Regents of the University of Michigan
6 * All Rights Reserved
7 *
8 * Dean Hildebrand <dhildebz@umich.edu>
9 * Garth Goodson <Garth.Goodson@netapp.com>
10 *
11 * Permission is granted to use, copy, create derivative works, and
12 * redistribute this software and such derivative works for any purpose,
13 * so long as the name of the University of Michigan is not used in
14 * any advertising or publicity pertaining to the use or distribution
15 * of this software without specific, written prior authorization. If
16 * the above copyright notice or any other identification of the
17 * University of Michigan is included in any copy of any portion of
18 * this software, then the disclaimer below must also be included.
19 *
20 * This software is provided as is, without representation or warranty
21 * of any kind either express or implied, including without limitation
22 * the implied warranties of merchantability, fitness for a particular
23 * purpose, or noninfringement. The Regents of the University of
24 * Michigan shall not be liable for any damages, including special,
25 * indirect, incidental, or consequential damages, with respect to any
26 * claim arising out of or in connection with the use of the software,
27 * even if it has been or is hereafter advised of the possibility of
28 * such damages.
29 */
30
31#include <linux/nfs_fs.h>
32#include <linux/vmalloc.h>
Andy Adamson98fc6852012-04-27 17:53:45 -040033#include <linux/module.h>
Jeff Layton59766872013-02-04 12:50:00 -050034#include <linux/sunrpc/addr.h>
Andy Adamson16b374c2010-10-20 00:18:04 -040035
36#include "internal.h"
Trond Myklebust73e39aa2012-11-26 12:49:34 -050037#include "nfs4session.h"
Andy Adamson16b374c2010-10-20 00:18:04 -040038#include "nfs4filelayout.h"
39
40#define NFSDBG_FACILITY NFSDBG_PNFS_LD
41
Andy Adamson98fc6852012-04-27 17:53:45 -040042static unsigned int dataserver_timeo = NFS4_DEF_DS_TIMEO;
43static unsigned int dataserver_retrans = NFS4_DEF_DS_RETRANS;
44
Andy Adamson16b374c2010-10-20 00:18:04 -040045/*
46 * Data server cache
47 *
48 * Data servers can be mapped to different device ids.
49 * nfs4_pnfs_ds reference counting
50 * - set to 1 on allocation
51 * - incremented when a device id maps a data server already in the cache.
52 * - decremented when deviceid is removed from the cache.
53 */
Trond Myklebust17280172012-03-11 13:11:00 -040054static DEFINE_SPINLOCK(nfs4_ds_cache_lock);
Andy Adamson16b374c2010-10-20 00:18:04 -040055static LIST_HEAD(nfs4_data_server_cache);
56
57/* Debug routines */
58void
59print_ds(struct nfs4_pnfs_ds *ds)
60{
61 if (ds == NULL) {
62 printk("%s NULL device\n", __func__);
63 return;
64 }
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040065 printk(" ds %s\n"
Andy Adamson16b374c2010-10-20 00:18:04 -040066 " ref count %d\n"
67 " client %p\n"
68 " cl_exchange_flags %x\n",
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040069 ds->ds_remotestr,
Andy Adamson16b374c2010-10-20 00:18:04 -040070 atomic_read(&ds->ds_count), ds->ds_clp,
71 ds->ds_clp ? ds->ds_clp->cl_exchange_flags : 0);
72}
73
Weston Andros Adamson14f9a602011-05-31 18:48:57 -040074static bool
75same_sockaddr(struct sockaddr *addr1, struct sockaddr *addr2)
Andy Adamson16b374c2010-10-20 00:18:04 -040076{
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040077 struct sockaddr_in *a, *b;
78 struct sockaddr_in6 *a6, *b6;
Andy Adamson16b374c2010-10-20 00:18:04 -040079
Weston Andros Adamson14f9a602011-05-31 18:48:57 -040080 if (addr1->sa_family != addr2->sa_family)
81 return false;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040082
Weston Andros Adamson14f9a602011-05-31 18:48:57 -040083 switch (addr1->sa_family) {
84 case AF_INET:
85 a = (struct sockaddr_in *)addr1;
86 b = (struct sockaddr_in *)addr2;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040087
Weston Andros Adamson14f9a602011-05-31 18:48:57 -040088 if (a->sin_addr.s_addr == b->sin_addr.s_addr &&
89 a->sin_port == b->sin_port)
90 return true;
91 break;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040092
Weston Andros Adamson14f9a602011-05-31 18:48:57 -040093 case AF_INET6:
94 a6 = (struct sockaddr_in6 *)addr1;
95 b6 = (struct sockaddr_in6 *)addr2;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040096
Weston Andros Adamson14f9a602011-05-31 18:48:57 -040097 /* LINKLOCAL addresses must have matching scope_id */
98 if (ipv6_addr_scope(&a6->sin6_addr) ==
99 IPV6_ADDR_SCOPE_LINKLOCAL &&
100 a6->sin6_scope_id != b6->sin6_scope_id)
101 return false;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400102
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400103 if (ipv6_addr_equal(&a6->sin6_addr, &b6->sin6_addr) &&
104 a6->sin6_port == b6->sin6_port)
105 return true;
106 break;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400107
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400108 default:
109 dprintk("%s: unhandled address family: %u\n",
110 __func__, addr1->sa_family);
111 return false;
112 }
113
114 return false;
115}
116
Trond Myklebust17280172012-03-11 13:11:00 -0400117static bool
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500118_same_data_server_addrs_locked(const struct list_head *dsaddrs1,
119 const struct list_head *dsaddrs2)
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400120{
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400121 struct nfs4_pnfs_ds_addr *da1, *da2;
122
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500123 /* step through both lists, comparing as we go */
124 for (da1 = list_first_entry(dsaddrs1, typeof(*da1), da_node),
125 da2 = list_first_entry(dsaddrs2, typeof(*da2), da_node);
126 da1 != NULL && da2 != NULL;
127 da1 = list_entry(da1->da_node.next, typeof(*da1), da_node),
128 da2 = list_entry(da2->da_node.next, typeof(*da2), da_node)) {
129 if (!same_sockaddr((struct sockaddr *)&da1->da_addr,
130 (struct sockaddr *)&da2->da_addr))
131 return false;
Andy Adamson16b374c2010-10-20 00:18:04 -0400132 }
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500133 if (da1 == NULL && da2 == NULL)
134 return true;
135
136 return false;
Andy Adamson16b374c2010-10-20 00:18:04 -0400137}
138
Andy Adamsond83217c2011-03-01 01:34:17 +0000139/*
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500140 * Lookup DS by addresses. nfs4_ds_cache_lock is held
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400141 */
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500142static struct nfs4_pnfs_ds *
143_data_server_lookup_locked(const struct list_head *dsaddrs)
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400144{
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500145 struct nfs4_pnfs_ds *ds;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400146
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500147 list_for_each_entry(ds, &nfs4_data_server_cache, ds_node)
148 if (_same_data_server_addrs_locked(&ds->ds_addrs, dsaddrs))
149 return ds;
150 return NULL;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400151}
152
153/*
Andy Adamsond83217c2011-03-01 01:34:17 +0000154 * Create an rpc connection to the nfs4_pnfs_ds data server
Weston Andros Adamson35dbbc92011-06-01 16:32:21 -0400155 * Currently only supports IPv4 and IPv6 addresses
Andy Adamsond83217c2011-03-01 01:34:17 +0000156 */
157static int
158nfs4_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds)
159{
Weston Andros Adamson7e574f02011-05-31 18:48:58 -0400160 struct nfs_client *clp = ERR_PTR(-EIO);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400161 struct nfs4_pnfs_ds_addr *da;
Andy Adamsond83217c2011-03-01 01:34:17 +0000162 int status = 0;
163
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400164 dprintk("--> %s DS %s au_flavor %d\n", __func__, ds->ds_remotestr,
Andy Adamsond83217c2011-03-01 01:34:17 +0000165 mds_srv->nfs_client->cl_rpcclient->cl_auth->au_flavor);
166
Weston Andros Adamson7e574f02011-05-31 18:48:58 -0400167 list_for_each_entry(da, &ds->ds_addrs, da_node) {
168 dprintk("%s: DS %s: trying address %s\n",
169 __func__, ds->ds_remotestr, da->da_remotestr);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400170
Weston Andros Adamson7e574f02011-05-31 18:48:58 -0400171 clp = nfs4_set_ds_client(mds_srv->nfs_client,
Andy Adamson98fc6852012-04-27 17:53:45 -0400172 (struct sockaddr *)&da->da_addr,
173 da->da_addrlen, IPPROTO_TCP,
174 dataserver_timeo, dataserver_retrans);
Weston Andros Adamson7e574f02011-05-31 18:48:58 -0400175 if (!IS_ERR(clp))
176 break;
177 }
178
Andy Adamsond83217c2011-03-01 01:34:17 +0000179 if (IS_ERR(clp)) {
180 status = PTR_ERR(clp);
181 goto out;
182 }
183
Trond Myklebust7b38c362012-05-23 13:23:31 -0400184 status = nfs4_init_ds_session(clp, mds_srv->nfs_client->cl_lease_time);
Andy Adamsond83217c2011-03-01 01:34:17 +0000185 if (status)
186 goto out_put;
187
188 ds->ds_clp = clp;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400189 dprintk("%s [new] addr: %s\n", __func__, ds->ds_remotestr);
Andy Adamsond83217c2011-03-01 01:34:17 +0000190out:
191 return status;
192out_put:
193 nfs_put_client(clp);
194 goto out;
195}
196
Andy Adamson16b374c2010-10-20 00:18:04 -0400197static void
198destroy_ds(struct nfs4_pnfs_ds *ds)
199{
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400200 struct nfs4_pnfs_ds_addr *da;
201
Andy Adamson16b374c2010-10-20 00:18:04 -0400202 dprintk("--> %s\n", __func__);
203 ifdebug(FACILITY)
204 print_ds(ds);
205
206 if (ds->ds_clp)
207 nfs_put_client(ds->ds_clp);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400208
209 while (!list_empty(&ds->ds_addrs)) {
210 da = list_first_entry(&ds->ds_addrs,
211 struct nfs4_pnfs_ds_addr,
212 da_node);
213 list_del_init(&da->da_node);
214 kfree(da->da_remotestr);
215 kfree(da);
216 }
217
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400218 kfree(ds->ds_remotestr);
Andy Adamson16b374c2010-10-20 00:18:04 -0400219 kfree(ds);
220}
221
Benny Halevy1775bc32011-05-20 13:47:33 +0200222void
Andy Adamson16b374c2010-10-20 00:18:04 -0400223nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
224{
225 struct nfs4_pnfs_ds *ds;
226 int i;
227
Benny Halevya1eaecb2011-05-19 22:14:47 -0400228 nfs4_print_deviceid(&dsaddr->id_node.deviceid);
Andy Adamson16b374c2010-10-20 00:18:04 -0400229
230 for (i = 0; i < dsaddr->ds_num; i++) {
231 ds = dsaddr->ds_list[i];
232 if (ds != NULL) {
233 if (atomic_dec_and_lock(&ds->ds_count,
234 &nfs4_ds_cache_lock)) {
235 list_del_init(&ds->ds_node);
236 spin_unlock(&nfs4_ds_cache_lock);
237 destroy_ds(ds);
238 }
239 }
240 }
241 kfree(dsaddr->stripe_indices);
242 kfree(dsaddr);
243}
244
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400245/*
246 * Create a string with a human readable address and port to avoid
247 * complicated setup around many dprinks.
248 */
249static char *
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400250nfs4_pnfs_remotestr(struct list_head *dsaddrs, gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400251{
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400252 struct nfs4_pnfs_ds_addr *da;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400253 char *remotestr;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400254 size_t len;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400255 char *p;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400256
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400257 len = 3; /* '{', '}' and eol */
258 list_for_each_entry(da, dsaddrs, da_node) {
259 len += strlen(da->da_remotestr) + 1; /* string plus comma */
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400260 }
261
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400262 remotestr = kzalloc(len, gfp_flags);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400263 if (!remotestr)
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400264 return NULL;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400265
266 p = remotestr;
267 *(p++) = '{';
268 len--;
269 list_for_each_entry(da, dsaddrs, da_node) {
270 size_t ll = strlen(da->da_remotestr);
271
272 if (ll > len)
273 goto out_err;
274
275 memcpy(p, da->da_remotestr, ll);
276 p += ll;
277 len -= ll;
278
279 if (len < 1)
280 goto out_err;
281 (*p++) = ',';
282 len--;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400283 }
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400284 if (len < 2)
285 goto out_err;
286 *(p++) = '}';
287 *p = '\0';
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400288 return remotestr;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400289out_err:
290 kfree(remotestr);
291 return NULL;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400292}
293
294static struct nfs4_pnfs_ds *
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400295nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags)
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400296{
297 struct nfs4_pnfs_ds *tmp_ds, *ds = NULL;
298 char *remotestr;
Andy Adamson16b374c2010-10-20 00:18:04 -0400299
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400300 if (list_empty(dsaddrs)) {
301 dprintk("%s: no addresses defined\n", __func__);
302 goto out;
303 }
304
305 ds = kzalloc(sizeof(*ds), gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400306 if (!ds)
307 goto out;
308
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400309 /* this is only used for debugging, so it's ok if its NULL */
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400310 remotestr = nfs4_pnfs_remotestr(dsaddrs, gfp_flags);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400311
Andy Adamson16b374c2010-10-20 00:18:04 -0400312 spin_lock(&nfs4_ds_cache_lock);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400313 tmp_ds = _data_server_lookup_locked(dsaddrs);
Andy Adamson16b374c2010-10-20 00:18:04 -0400314 if (tmp_ds == NULL) {
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400315 INIT_LIST_HEAD(&ds->ds_addrs);
316 list_splice_init(dsaddrs, &ds->ds_addrs);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400317 ds->ds_remotestr = remotestr;
Andy Adamson16b374c2010-10-20 00:18:04 -0400318 atomic_set(&ds->ds_count, 1);
319 INIT_LIST_HEAD(&ds->ds_node);
320 ds->ds_clp = NULL;
321 list_add(&ds->ds_node, &nfs4_data_server_cache);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400322 dprintk("%s add new data server %s\n", __func__,
323 ds->ds_remotestr);
Andy Adamson16b374c2010-10-20 00:18:04 -0400324 } else {
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400325 kfree(remotestr);
Andy Adamson16b374c2010-10-20 00:18:04 -0400326 kfree(ds);
327 atomic_inc(&tmp_ds->ds_count);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400328 dprintk("%s data server %s found, inc'ed ds_count to %d\n",
329 __func__, tmp_ds->ds_remotestr,
Andy Adamson16b374c2010-10-20 00:18:04 -0400330 atomic_read(&tmp_ds->ds_count));
331 ds = tmp_ds;
332 }
333 spin_unlock(&nfs4_ds_cache_lock);
334out:
335 return ds;
336}
337
338/*
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400339 * Currently only supports ipv4, ipv6 and one multi-path address.
Andy Adamson16b374c2010-10-20 00:18:04 -0400340 */
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400341static struct nfs4_pnfs_ds_addr *
Stanislav Kinsbursky17094272012-01-19 19:05:57 +0400342decode_ds_addr(struct net *net, struct xdr_stream *streamp, gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400343{
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400344 struct nfs4_pnfs_ds_addr *da = NULL;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400345 char *buf, *portstr;
Dan Carpenter13fff2f2012-01-12 10:07:35 +0300346 __be16 port;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400347 int nlen, rlen;
Andy Adamson16b374c2010-10-20 00:18:04 -0400348 int tmp[2];
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400349 __be32 *p;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400350 char *netid, *match_netid;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400351 size_t len, match_netid_len;
352 char *startsep = "";
353 char *endsep = "";
354
Andy Adamson16b374c2010-10-20 00:18:04 -0400355
356 /* r_netid */
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400357 p = xdr_inline_decode(streamp, 4);
358 if (unlikely(!p))
359 goto out_err;
Andy Adamson16b374c2010-10-20 00:18:04 -0400360 nlen = be32_to_cpup(p++);
Andy Adamson16b374c2010-10-20 00:18:04 -0400361
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400362 p = xdr_inline_decode(streamp, nlen);
363 if (unlikely(!p))
364 goto out_err;
Andy Adamson16b374c2010-10-20 00:18:04 -0400365
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400366 netid = kmalloc(nlen+1, gfp_flags);
367 if (unlikely(!netid))
Andy Adamson16b374c2010-10-20 00:18:04 -0400368 goto out_err;
Andy Adamson16b374c2010-10-20 00:18:04 -0400369
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400370 netid[nlen] = '\0';
371 memcpy(netid, p, nlen);
372
373 /* r_addr: ip/ip6addr with port in dec octets - see RFC 5665 */
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400374 p = xdr_inline_decode(streamp, 4);
375 if (unlikely(!p))
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400376 goto out_free_netid;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400377 rlen = be32_to_cpup(p);
378
379 p = xdr_inline_decode(streamp, rlen);
380 if (unlikely(!p))
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400381 goto out_free_netid;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400382
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400383 /* port is ".ABC.DEF", 8 chars max */
384 if (rlen > INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN + 8) {
Jesper Juhlad3d2ee2011-01-17 18:41:50 +0000385 dprintk("%s: Invalid address, length %d\n", __func__,
Andy Adamson16b374c2010-10-20 00:18:04 -0400386 rlen);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400387 goto out_free_netid;
Andy Adamson16b374c2010-10-20 00:18:04 -0400388 }
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400389 buf = kmalloc(rlen + 1, gfp_flags);
Stanislav Fomichevb9f81052011-02-05 23:13:01 +0000390 if (!buf) {
391 dprintk("%s: Not enough memory\n", __func__);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400392 goto out_free_netid;
Stanislav Fomichevb9f81052011-02-05 23:13:01 +0000393 }
Andy Adamson16b374c2010-10-20 00:18:04 -0400394 buf[rlen] = '\0';
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400395 memcpy(buf, p, rlen);
Andy Adamson16b374c2010-10-20 00:18:04 -0400396
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400397 /* replace port '.' with '-' */
398 portstr = strrchr(buf, '.');
399 if (!portstr) {
400 dprintk("%s: Failed finding expected dot in port\n",
401 __func__);
402 goto out_free_buf;
403 }
404 *portstr = '-';
405
406 /* find '.' between address and port */
407 portstr = strrchr(buf, '.');
408 if (!portstr) {
409 dprintk("%s: Failed finding expected dot between address and "
410 "port\n", __func__);
411 goto out_free_buf;
412 }
413 *portstr = '\0';
414
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400415 da = kzalloc(sizeof(*da), gfp_flags);
416 if (unlikely(!da))
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400417 goto out_free_buf;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400418
419 INIT_LIST_HEAD(&da->da_node);
420
Stanislav Kinsbursky17094272012-01-19 19:05:57 +0400421 if (!rpc_pton(net, buf, portstr-buf, (struct sockaddr *)&da->da_addr,
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400422 sizeof(da->da_addr))) {
423 dprintk("%s: error parsing address %s\n", __func__, buf);
424 goto out_free_da;
Andy Adamson16b374c2010-10-20 00:18:04 -0400425 }
426
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400427 portstr++;
428 sscanf(portstr, "%d-%d", &tmp[0], &tmp[1]);
Andy Adamson16b374c2010-10-20 00:18:04 -0400429 port = htons((tmp[0] << 8) | (tmp[1]));
430
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400431 switch (da->da_addr.ss_family) {
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400432 case AF_INET:
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400433 ((struct sockaddr_in *)&da->da_addr)->sin_port = port;
434 da->da_addrlen = sizeof(struct sockaddr_in);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400435 match_netid = "tcp";
436 match_netid_len = 3;
437 break;
438
439 case AF_INET6:
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400440 ((struct sockaddr_in6 *)&da->da_addr)->sin6_port = port;
441 da->da_addrlen = sizeof(struct sockaddr_in6);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400442 match_netid = "tcp6";
443 match_netid_len = 4;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400444 startsep = "[";
445 endsep = "]";
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400446 break;
447
448 default:
449 dprintk("%s: unsupported address family: %u\n",
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400450 __func__, da->da_addr.ss_family);
451 goto out_free_da;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400452 }
453
454 if (nlen != match_netid_len || strncmp(netid, match_netid, nlen)) {
455 dprintk("%s: ERROR: r_netid \"%s\" != \"%s\"\n",
456 __func__, netid, match_netid);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400457 goto out_free_da;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400458 }
459
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400460 /* save human readable address */
461 len = strlen(startsep) + strlen(buf) + strlen(endsep) + 7;
462 da->da_remotestr = kzalloc(len, gfp_flags);
463
464 /* NULL is ok, only used for dprintk */
465 if (da->da_remotestr)
466 snprintf(da->da_remotestr, len, "%s%s%s:%u", startsep,
467 buf, endsep, ntohs(port));
468
469 dprintk("%s: Parsed DS addr %s\n", __func__, da->da_remotestr);
470 kfree(buf);
471 kfree(netid);
472 return da;
473
474out_free_da:
475 kfree(da);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400476out_free_buf:
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400477 dprintk("%s: Error parsing DS addr: %s\n", __func__, buf);
Andy Adamson16b374c2010-10-20 00:18:04 -0400478 kfree(buf);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400479out_free_netid:
480 kfree(netid);
Andy Adamson16b374c2010-10-20 00:18:04 -0400481out_err:
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400482 return NULL;
Andy Adamson16b374c2010-10-20 00:18:04 -0400483}
484
485/* Decode opaque device data and return the result */
486static struct nfs4_file_layout_dsaddr*
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400487decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400488{
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400489 int i;
Andy Adamson16b374c2010-10-20 00:18:04 -0400490 u32 cnt, num;
491 u8 *indexp;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400492 __be32 *p;
493 u8 *stripe_indices;
494 u8 max_stripe_index;
495 struct nfs4_file_layout_dsaddr *dsaddr = NULL;
496 struct xdr_stream stream;
Benny Halevyf7da7a12011-05-19 14:16:47 -0400497 struct xdr_buf buf;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400498 struct page *scratch;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400499 struct list_head dsaddrs;
500 struct nfs4_pnfs_ds_addr *da;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400501
502 /* set up xdr stream */
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400503 scratch = alloc_page(gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400504 if (!scratch)
505 goto out_err;
506
Benny Halevyf7da7a12011-05-19 14:16:47 -0400507 xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400508 xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
Andy Adamson16b374c2010-10-20 00:18:04 -0400509
510 /* Get the stripe count (number of stripe index) */
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400511 p = xdr_inline_decode(&stream, 4);
512 if (unlikely(!p))
513 goto out_err_free_scratch;
514
515 cnt = be32_to_cpup(p);
Andy Adamson16b374c2010-10-20 00:18:04 -0400516 dprintk("%s stripe count %d\n", __func__, cnt);
517 if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500518 printk(KERN_WARNING "NFS: %s: stripe count %d greater than "
Andy Adamson16b374c2010-10-20 00:18:04 -0400519 "supported maximum %d\n", __func__,
520 cnt, NFS4_PNFS_MAX_STRIPE_CNT);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400521 goto out_err_free_scratch;
522 }
523
524 /* read stripe indices */
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400525 stripe_indices = kcalloc(cnt, sizeof(u8), gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400526 if (!stripe_indices)
527 goto out_err_free_scratch;
528
529 p = xdr_inline_decode(&stream, cnt << 2);
530 if (unlikely(!p))
531 goto out_err_free_stripe_indices;
532
533 indexp = &stripe_indices[0];
534 max_stripe_index = 0;
535 for (i = 0; i < cnt; i++) {
536 *indexp = be32_to_cpup(p++);
537 max_stripe_index = max(max_stripe_index, *indexp);
538 indexp++;
Andy Adamson16b374c2010-10-20 00:18:04 -0400539 }
540
541 /* Check the multipath list count */
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400542 p = xdr_inline_decode(&stream, 4);
543 if (unlikely(!p))
544 goto out_err_free_stripe_indices;
545
546 num = be32_to_cpup(p);
Andy Adamson16b374c2010-10-20 00:18:04 -0400547 dprintk("%s ds_num %u\n", __func__, num);
548 if (num > NFS4_PNFS_MAX_MULTI_CNT) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500549 printk(KERN_WARNING "NFS: %s: multipath count %d greater than "
Andy Adamson16b374c2010-10-20 00:18:04 -0400550 "supported maximum %d\n", __func__,
551 num, NFS4_PNFS_MAX_MULTI_CNT);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400552 goto out_err_free_stripe_indices;
Andy Adamson16b374c2010-10-20 00:18:04 -0400553 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400554
555 /* validate stripe indices are all < num */
556 if (max_stripe_index >= num) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500557 printk(KERN_WARNING "NFS: %s: stripe index %u >= num ds %u\n",
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400558 __func__, max_stripe_index, num);
559 goto out_err_free_stripe_indices;
560 }
561
Andy Adamson16b374c2010-10-20 00:18:04 -0400562 dsaddr = kzalloc(sizeof(*dsaddr) +
563 (sizeof(struct nfs4_pnfs_ds *) * (num - 1)),
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400564 gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400565 if (!dsaddr)
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400566 goto out_err_free_stripe_indices;
Andy Adamson16b374c2010-10-20 00:18:04 -0400567
568 dsaddr->stripe_count = cnt;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400569 dsaddr->stripe_indices = stripe_indices;
570 stripe_indices = NULL;
Andy Adamson16b374c2010-10-20 00:18:04 -0400571 dsaddr->ds_num = num;
Benny Halevy1775bc32011-05-20 13:47:33 +0200572 nfs4_init_deviceid_node(&dsaddr->id_node,
573 NFS_SERVER(ino)->pnfs_curr_ld,
574 NFS_SERVER(ino)->nfs_client,
Benny Halevya1eaecb2011-05-19 22:14:47 -0400575 &pdev->dev_id);
Andy Adamson16b374c2010-10-20 00:18:04 -0400576
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400577 INIT_LIST_HEAD(&dsaddrs);
578
Andy Adamson16b374c2010-10-20 00:18:04 -0400579 for (i = 0; i < dsaddr->ds_num; i++) {
580 int j;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400581 u32 mp_count;
Andy Adamson16b374c2010-10-20 00:18:04 -0400582
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400583 p = xdr_inline_decode(&stream, 4);
584 if (unlikely(!p))
585 goto out_err_free_deviceid;
586
587 mp_count = be32_to_cpup(p); /* multipath count */
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400588 for (j = 0; j < mp_count; j++) {
Chuck Lever73ea6662012-05-21 22:44:50 -0400589 da = decode_ds_addr(NFS_SERVER(ino)->nfs_client->cl_net,
Stanislav Kinsbursky17094272012-01-19 19:05:57 +0400590 &stream, gfp_flags);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400591 if (da)
592 list_add_tail(&da->da_node, &dsaddrs);
593 }
594 if (list_empty(&dsaddrs)) {
595 dprintk("%s: no suitable DS addresses found\n",
596 __func__);
597 goto out_err_free_deviceid;
598 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400599
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400600 dsaddr->ds_list[i] = nfs4_pnfs_ds_add(&dsaddrs, gfp_flags);
601 if (!dsaddr->ds_list[i])
602 goto out_err_drain_dsaddrs;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400603
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400604 /* If DS was already in cache, free ds addrs */
605 while (!list_empty(&dsaddrs)) {
606 da = list_first_entry(&dsaddrs,
607 struct nfs4_pnfs_ds_addr,
608 da_node);
609 list_del_init(&da->da_node);
610 kfree(da->da_remotestr);
611 kfree(da);
Andy Adamson16b374c2010-10-20 00:18:04 -0400612 }
613 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400614
615 __free_page(scratch);
Andy Adamson16b374c2010-10-20 00:18:04 -0400616 return dsaddr;
617
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400618out_err_drain_dsaddrs:
619 while (!list_empty(&dsaddrs)) {
620 da = list_first_entry(&dsaddrs, struct nfs4_pnfs_ds_addr,
621 da_node);
622 list_del_init(&da->da_node);
623 kfree(da->da_remotestr);
624 kfree(da);
625 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400626out_err_free_deviceid:
Andy Adamson16b374c2010-10-20 00:18:04 -0400627 nfs4_fl_free_deviceid(dsaddr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400628 /* stripe_indicies was part of dsaddr */
629 goto out_err_free_scratch;
630out_err_free_stripe_indices:
631 kfree(stripe_indices);
632out_err_free_scratch:
633 __free_page(scratch);
Andy Adamson16b374c2010-10-20 00:18:04 -0400634out_err:
635 dprintk("%s ERROR: returning NULL\n", __func__);
636 return NULL;
637}
638
639/*
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000640 * Decode the opaque device specified in 'dev' and add it to the cache of
641 * available devices.
Andy Adamson16b374c2010-10-20 00:18:04 -0400642 */
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000643static struct nfs4_file_layout_dsaddr *
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400644decode_and_add_device(struct inode *inode, struct pnfs_device *dev, gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400645{
Benny Halevya1eaecb2011-05-19 22:14:47 -0400646 struct nfs4_deviceid_node *d;
647 struct nfs4_file_layout_dsaddr *n, *new;
Andy Adamson16b374c2010-10-20 00:18:04 -0400648
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400649 new = decode_device(inode, dev, gfp_flags);
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000650 if (!new) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500651 printk(KERN_WARNING "NFS: %s: Could not decode or add device\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400652 __func__);
653 return NULL;
654 }
655
Benny Halevya1eaecb2011-05-19 22:14:47 -0400656 d = nfs4_insert_deviceid_node(&new->id_node);
657 n = container_of(d, struct nfs4_file_layout_dsaddr, id_node);
658 if (n != new) {
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000659 nfs4_fl_free_deviceid(new);
Benny Halevya1eaecb2011-05-19 22:14:47 -0400660 return n;
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000661 }
Andy Adamson16b374c2010-10-20 00:18:04 -0400662
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000663 return new;
Andy Adamson16b374c2010-10-20 00:18:04 -0400664}
665
666/*
667 * Retrieve the information for dev_id, add it to the list
668 * of available devices, and return it.
669 */
670struct nfs4_file_layout_dsaddr *
Trond Myklebust78e4e052012-09-18 21:02:29 -0400671filelayout_get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id, gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400672{
673 struct pnfs_device *pdev = NULL;
674 u32 max_resp_sz;
675 int max_pages;
676 struct page **pages = NULL;
677 struct nfs4_file_layout_dsaddr *dsaddr = NULL;
678 int rc, i;
679 struct nfs_server *server = NFS_SERVER(inode);
680
681 /*
682 * Use the session max response size as the basis for setting
683 * GETDEVICEINFO's maxcount
684 */
685 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
Andy Adamsone5265a02012-04-14 03:56:35 -0400686 max_pages = nfs_page_array_len(0, max_resp_sz);
Andy Adamson16b374c2010-10-20 00:18:04 -0400687 dprintk("%s inode %p max_resp_sz %u max_pages %d\n",
688 __func__, inode, max_resp_sz, max_pages);
689
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400690 pdev = kzalloc(sizeof(struct pnfs_device), gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400691 if (pdev == NULL)
692 return NULL;
693
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400694 pages = kzalloc(max_pages * sizeof(struct page *), gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400695 if (pages == NULL) {
696 kfree(pdev);
697 return NULL;
698 }
699 for (i = 0; i < max_pages; i++) {
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400700 pages[i] = alloc_page(gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400701 if (!pages[i])
702 goto out_free;
703 }
704
Andy Adamson16b374c2010-10-20 00:18:04 -0400705 memcpy(&pdev->dev_id, dev_id, sizeof(*dev_id));
706 pdev->layout_type = LAYOUT_NFSV4_1_FILES;
707 pdev->pages = pages;
708 pdev->pgbase = 0;
Andy Adamson05bf14a2012-06-06 23:57:13 -0400709 pdev->pglen = max_resp_sz;
Andy Adamson16b374c2010-10-20 00:18:04 -0400710 pdev->mincount = 0;
711
712 rc = nfs4_proc_getdeviceinfo(server, pdev);
713 dprintk("%s getdevice info returns %d\n", __func__, rc);
714 if (rc)
715 goto out_free;
716
717 /*
718 * Found new device, need to decode it and then add it to the
719 * list of known devices for this mountpoint.
720 */
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400721 dsaddr = decode_and_add_device(inode, pdev, gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400722out_free:
Andy Adamson16b374c2010-10-20 00:18:04 -0400723 for (i = 0; i < max_pages; i++)
724 __free_page(pages[i]);
725 kfree(pages);
726 kfree(pdev);
727 dprintk("<-- %s dsaddr %p\n", __func__, dsaddr);
728 return dsaddr;
729}
730
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000731void
732nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
Andy Adamson16b374c2010-10-20 00:18:04 -0400733{
Benny Halevy1775bc32011-05-20 13:47:33 +0200734 nfs4_put_deviceid_node(&dsaddr->id_node);
Andy Adamson16b374c2010-10-20 00:18:04 -0400735}
Fred Isamancfe7f412011-03-01 01:34:18 +0000736
737/*
738 * Want res = (offset - layout->pattern_offset)/ layout->stripe_unit
739 * Then: ((res + fsi) % dsaddr->stripe_count)
740 */
741u32
742nfs4_fl_calc_j_index(struct pnfs_layout_segment *lseg, loff_t offset)
743{
744 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
745 u64 tmp;
746
747 tmp = offset - flseg->pattern_offset;
748 do_div(tmp, flseg->stripe_unit);
749 tmp += flseg->first_stripe_index;
750 return do_div(tmp, flseg->dsaddr->stripe_count);
751}
752
753u32
754nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j)
755{
756 return FILELAYOUT_LSEG(lseg)->dsaddr->stripe_indices[j];
757}
758
759struct nfs_fh *
760nfs4_fl_select_ds_fh(struct pnfs_layout_segment *lseg, u32 j)
761{
762 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
763 u32 i;
764
765 if (flseg->stripe_type == STRIPE_SPARSE) {
766 if (flseg->num_fh == 1)
767 i = 0;
768 else if (flseg->num_fh == 0)
769 /* Use the MDS OPEN fh set in nfs_read_rpcsetup */
770 return NULL;
771 else
772 i = nfs4_fl_calc_ds_index(lseg, j);
773 } else
774 i = j;
775 return flseg->fh_array[i];
776}
777
Andy Adamsonc23266d2013-05-08 16:21:18 -0400778static void nfs4_wait_ds_connect(struct nfs4_pnfs_ds *ds)
779{
780 might_sleep();
781 wait_on_bit(&ds->ds_state, NFS4DS_CONNECTING,
782 nfs_wait_bit_killable, TASK_KILLABLE);
783}
784
785static void nfs4_clear_ds_conn_bit(struct nfs4_pnfs_ds *ds)
786{
787 smp_mb__before_clear_bit();
788 clear_bit(NFS4DS_CONNECTING, &ds->ds_state);
789 smp_mb__after_clear_bit();
790 wake_up_bit(&ds->ds_state, NFS4DS_CONNECTING);
791}
792
793
Fred Isamancfe7f412011-03-01 01:34:18 +0000794struct nfs4_pnfs_ds *
795nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx)
796{
797 struct nfs4_file_layout_dsaddr *dsaddr = FILELAYOUT_LSEG(lseg)->dsaddr;
798 struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx];
Andy Adamson554d4582012-04-27 17:53:42 -0400799 struct nfs4_deviceid_node *devid = FILELAYOUT_DEVID_NODE(lseg);
800
Trond Myklebust1dfed272012-09-18 19:51:12 -0400801 if (filelayout_test_devid_unavailable(devid))
Andy Adamson554d4582012-04-27 17:53:42 -0400802 return NULL;
Fred Isamancfe7f412011-03-01 01:34:18 +0000803
804 if (ds == NULL) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500805 printk(KERN_ERR "NFS: %s: No data server for offset index %d\n",
Fred Isamancfe7f412011-03-01 01:34:18 +0000806 __func__, ds_idx);
Trond Myklebust1dfed272012-09-18 19:51:12 -0400807 filelayout_mark_devid_invalid(devid);
808 return NULL;
Fred Isamancfe7f412011-03-01 01:34:18 +0000809 }
Andy Adamsonc23266d2013-05-08 16:21:18 -0400810 if (ds->ds_clp)
811 return ds;
Fred Isamancfe7f412011-03-01 01:34:18 +0000812
Andy Adamsonc23266d2013-05-08 16:21:18 -0400813 if (test_and_set_bit(NFS4DS_CONNECTING, &ds->ds_state) == 0) {
Andy Adamson568e8c42011-03-01 01:34:22 +0000814 struct nfs_server *s = NFS_SERVER(lseg->pls_layout->plh_inode);
Fred Isamancfe7f412011-03-01 01:34:18 +0000815 int err;
816
Andy Adamson568e8c42011-03-01 01:34:22 +0000817 err = nfs4_ds_connect(s, ds);
Trond Myklebust1dfed272012-09-18 19:51:12 -0400818 if (err) {
819 nfs4_mark_deviceid_unavailable(devid);
Andy Adamsonc23266d2013-05-08 16:21:18 -0400820 ds = NULL;
Trond Myklebust1dfed272012-09-18 19:51:12 -0400821 }
Andy Adamsonc23266d2013-05-08 16:21:18 -0400822 nfs4_clear_ds_conn_bit(ds);
823 } else {
824 /* Either ds is connected, or ds is NULL */
825 nfs4_wait_ds_connect(ds);
Fred Isamancfe7f412011-03-01 01:34:18 +0000826 }
827 return ds;
828}
Andy Adamson98fc6852012-04-27 17:53:45 -0400829
830module_param(dataserver_retrans, uint, 0644);
831MODULE_PARM_DESC(dataserver_retrans, "The number of times the NFSv4.1 client "
832 "retries a request before it attempts further "
833 " recovery action.");
834module_param(dataserver_timeo, uint, 0644);
835MODULE_PARM_DESC(dataserver_timeo, "The time (in tenths of a second) the "
836 "NFSv4.1 client waits for a response from a "
837 " data server before it retries an NFS request.");