blob: c610f84ff030a63fcf5baf7877594908b0b6d4d8 [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>
Andy Adamson16b374c2010-10-20 00:18:04 -040034
35#include "internal.h"
36#include "nfs4filelayout.h"
37
38#define NFSDBG_FACILITY NFSDBG_PNFS_LD
39
Andy Adamson98fc6852012-04-27 17:53:45 -040040static unsigned int dataserver_timeo = NFS4_DEF_DS_TIMEO;
41static unsigned int dataserver_retrans = NFS4_DEF_DS_RETRANS;
42
Andy Adamson16b374c2010-10-20 00:18:04 -040043/*
44 * Data server cache
45 *
46 * Data servers can be mapped to different device ids.
47 * nfs4_pnfs_ds reference counting
48 * - set to 1 on allocation
49 * - incremented when a device id maps a data server already in the cache.
50 * - decremented when deviceid is removed from the cache.
51 */
Trond Myklebust17280172012-03-11 13:11:00 -040052static DEFINE_SPINLOCK(nfs4_ds_cache_lock);
Andy Adamson16b374c2010-10-20 00:18:04 -040053static LIST_HEAD(nfs4_data_server_cache);
54
55/* Debug routines */
56void
57print_ds(struct nfs4_pnfs_ds *ds)
58{
59 if (ds == NULL) {
60 printk("%s NULL device\n", __func__);
61 return;
62 }
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040063 printk(" ds %s\n"
Andy Adamson16b374c2010-10-20 00:18:04 -040064 " ref count %d\n"
65 " client %p\n"
66 " cl_exchange_flags %x\n",
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040067 ds->ds_remotestr,
Andy Adamson16b374c2010-10-20 00:18:04 -040068 atomic_read(&ds->ds_count), ds->ds_clp,
69 ds->ds_clp ? ds->ds_clp->cl_exchange_flags : 0);
70}
71
Weston Andros Adamson14f9a602011-05-31 18:48:57 -040072static bool
73same_sockaddr(struct sockaddr *addr1, struct sockaddr *addr2)
Andy Adamson16b374c2010-10-20 00:18:04 -040074{
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040075 struct sockaddr_in *a, *b;
76 struct sockaddr_in6 *a6, *b6;
Andy Adamson16b374c2010-10-20 00:18:04 -040077
Weston Andros Adamson14f9a602011-05-31 18:48:57 -040078 if (addr1->sa_family != addr2->sa_family)
79 return false;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040080
Weston Andros Adamson14f9a602011-05-31 18:48:57 -040081 switch (addr1->sa_family) {
82 case AF_INET:
83 a = (struct sockaddr_in *)addr1;
84 b = (struct sockaddr_in *)addr2;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040085
Weston Andros Adamson14f9a602011-05-31 18:48:57 -040086 if (a->sin_addr.s_addr == b->sin_addr.s_addr &&
87 a->sin_port == b->sin_port)
88 return true;
89 break;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040090
Weston Andros Adamson14f9a602011-05-31 18:48:57 -040091 case AF_INET6:
92 a6 = (struct sockaddr_in6 *)addr1;
93 b6 = (struct sockaddr_in6 *)addr2;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -040094
Weston Andros Adamson14f9a602011-05-31 18:48:57 -040095 /* LINKLOCAL addresses must have matching scope_id */
96 if (ipv6_addr_scope(&a6->sin6_addr) ==
97 IPV6_ADDR_SCOPE_LINKLOCAL &&
98 a6->sin6_scope_id != b6->sin6_scope_id)
99 return false;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400100
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400101 if (ipv6_addr_equal(&a6->sin6_addr, &b6->sin6_addr) &&
102 a6->sin6_port == b6->sin6_port)
103 return true;
104 break;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400105
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400106 default:
107 dprintk("%s: unhandled address family: %u\n",
108 __func__, addr1->sa_family);
109 return false;
110 }
111
112 return false;
113}
114
Trond Myklebust17280172012-03-11 13:11:00 -0400115static bool
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500116_same_data_server_addrs_locked(const struct list_head *dsaddrs1,
117 const struct list_head *dsaddrs2)
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400118{
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400119 struct nfs4_pnfs_ds_addr *da1, *da2;
120
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500121 /* step through both lists, comparing as we go */
122 for (da1 = list_first_entry(dsaddrs1, typeof(*da1), da_node),
123 da2 = list_first_entry(dsaddrs2, typeof(*da2), da_node);
124 da1 != NULL && da2 != NULL;
125 da1 = list_entry(da1->da_node.next, typeof(*da1), da_node),
126 da2 = list_entry(da2->da_node.next, typeof(*da2), da_node)) {
127 if (!same_sockaddr((struct sockaddr *)&da1->da_addr,
128 (struct sockaddr *)&da2->da_addr))
129 return false;
Andy Adamson16b374c2010-10-20 00:18:04 -0400130 }
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500131 if (da1 == NULL && da2 == NULL)
132 return true;
133
134 return false;
Andy Adamson16b374c2010-10-20 00:18:04 -0400135}
136
Andy Adamsond83217c2011-03-01 01:34:17 +0000137/*
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500138 * Lookup DS by addresses. nfs4_ds_cache_lock is held
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400139 */
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500140static struct nfs4_pnfs_ds *
141_data_server_lookup_locked(const struct list_head *dsaddrs)
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400142{
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500143 struct nfs4_pnfs_ds *ds;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400144
Weston Andros Adamson2d3fe012012-02-03 15:45:40 -0500145 list_for_each_entry(ds, &nfs4_data_server_cache, ds_node)
146 if (_same_data_server_addrs_locked(&ds->ds_addrs, dsaddrs))
147 return ds;
148 return NULL;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400149}
150
151/*
Andy Adamsonb4a29672012-04-27 17:53:52 -0400152 * Lookup DS by nfs_client pointer. Zero data server client pointer
153 */
154void nfs4_ds_disconnect(struct nfs_client *clp)
155{
156 struct nfs4_pnfs_ds *ds;
157 struct nfs_client *found = NULL;
158
159 dprintk("%s clp %p\n", __func__, clp);
160 spin_lock(&nfs4_ds_cache_lock);
161 list_for_each_entry(ds, &nfs4_data_server_cache, ds_node)
162 if (ds->ds_clp && ds->ds_clp == clp) {
163 found = ds->ds_clp;
164 ds->ds_clp = NULL;
165 }
166 spin_unlock(&nfs4_ds_cache_lock);
167 if (found) {
168 set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
169 nfs_put_client(clp);
170 }
171}
172
173/*
Andy Adamsond83217c2011-03-01 01:34:17 +0000174 * Create an rpc connection to the nfs4_pnfs_ds data server
Weston Andros Adamson35dbbc92011-06-01 16:32:21 -0400175 * Currently only supports IPv4 and IPv6 addresses
Andy Adamsond83217c2011-03-01 01:34:17 +0000176 */
177static int
178nfs4_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds)
179{
Weston Andros Adamson7e574f02011-05-31 18:48:58 -0400180 struct nfs_client *clp = ERR_PTR(-EIO);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400181 struct nfs4_pnfs_ds_addr *da;
Andy Adamsond83217c2011-03-01 01:34:17 +0000182 int status = 0;
183
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400184 dprintk("--> %s DS %s au_flavor %d\n", __func__, ds->ds_remotestr,
Andy Adamsond83217c2011-03-01 01:34:17 +0000185 mds_srv->nfs_client->cl_rpcclient->cl_auth->au_flavor);
186
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400187 BUG_ON(list_empty(&ds->ds_addrs));
188
Weston Andros Adamson7e574f02011-05-31 18:48:58 -0400189 list_for_each_entry(da, &ds->ds_addrs, da_node) {
190 dprintk("%s: DS %s: trying address %s\n",
191 __func__, ds->ds_remotestr, da->da_remotestr);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400192
Weston Andros Adamson7e574f02011-05-31 18:48:58 -0400193 clp = nfs4_set_ds_client(mds_srv->nfs_client,
Andy Adamson98fc6852012-04-27 17:53:45 -0400194 (struct sockaddr *)&da->da_addr,
195 da->da_addrlen, IPPROTO_TCP,
196 dataserver_timeo, dataserver_retrans);
Weston Andros Adamson7e574f02011-05-31 18:48:58 -0400197 if (!IS_ERR(clp))
198 break;
199 }
200
Andy Adamsond83217c2011-03-01 01:34:17 +0000201 if (IS_ERR(clp)) {
202 status = PTR_ERR(clp);
203 goto out;
204 }
205
206 if ((clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) != 0) {
207 if (!is_ds_client(clp)) {
208 status = -ENODEV;
209 goto out_put;
210 }
211 ds->ds_clp = clp;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400212 dprintk("%s [existing] server=%s\n", __func__,
213 ds->ds_remotestr);
Andy Adamsond83217c2011-03-01 01:34:17 +0000214 goto out;
215 }
216
217 /*
218 * Do not set NFS_CS_CHECK_LEASE_TIME instead set the DS lease to
219 * be equal to the MDS lease. Renewal is scheduled in create_session.
220 */
221 spin_lock(&mds_srv->nfs_client->cl_lock);
222 clp->cl_lease_time = mds_srv->nfs_client->cl_lease_time;
223 spin_unlock(&mds_srv->nfs_client->cl_lock);
224 clp->cl_last_renewal = jiffies;
225
226 /* New nfs_client */
227 status = nfs4_init_ds_session(clp);
228 if (status)
229 goto out_put;
230
231 ds->ds_clp = clp;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400232 dprintk("%s [new] addr: %s\n", __func__, ds->ds_remotestr);
Andy Adamsond83217c2011-03-01 01:34:17 +0000233out:
234 return status;
235out_put:
236 nfs_put_client(clp);
237 goto out;
238}
239
Andy Adamson16b374c2010-10-20 00:18:04 -0400240static void
241destroy_ds(struct nfs4_pnfs_ds *ds)
242{
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400243 struct nfs4_pnfs_ds_addr *da;
244
Andy Adamson16b374c2010-10-20 00:18:04 -0400245 dprintk("--> %s\n", __func__);
246 ifdebug(FACILITY)
247 print_ds(ds);
248
249 if (ds->ds_clp)
250 nfs_put_client(ds->ds_clp);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400251
252 while (!list_empty(&ds->ds_addrs)) {
253 da = list_first_entry(&ds->ds_addrs,
254 struct nfs4_pnfs_ds_addr,
255 da_node);
256 list_del_init(&da->da_node);
257 kfree(da->da_remotestr);
258 kfree(da);
259 }
260
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400261 kfree(ds->ds_remotestr);
Andy Adamson16b374c2010-10-20 00:18:04 -0400262 kfree(ds);
263}
264
Benny Halevy1775bc32011-05-20 13:47:33 +0200265void
Andy Adamson16b374c2010-10-20 00:18:04 -0400266nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
267{
268 struct nfs4_pnfs_ds *ds;
269 int i;
270
Benny Halevya1eaecb2011-05-19 22:14:47 -0400271 nfs4_print_deviceid(&dsaddr->id_node.deviceid);
Andy Adamson16b374c2010-10-20 00:18:04 -0400272
273 for (i = 0; i < dsaddr->ds_num; i++) {
274 ds = dsaddr->ds_list[i];
275 if (ds != NULL) {
276 if (atomic_dec_and_lock(&ds->ds_count,
277 &nfs4_ds_cache_lock)) {
278 list_del_init(&ds->ds_node);
279 spin_unlock(&nfs4_ds_cache_lock);
280 destroy_ds(ds);
281 }
282 }
283 }
284 kfree(dsaddr->stripe_indices);
285 kfree(dsaddr);
286}
287
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400288/*
289 * Create a string with a human readable address and port to avoid
290 * complicated setup around many dprinks.
291 */
292static char *
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400293nfs4_pnfs_remotestr(struct list_head *dsaddrs, gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400294{
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400295 struct nfs4_pnfs_ds_addr *da;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400296 char *remotestr;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400297 size_t len;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400298 char *p;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400299
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400300 len = 3; /* '{', '}' and eol */
301 list_for_each_entry(da, dsaddrs, da_node) {
302 len += strlen(da->da_remotestr) + 1; /* string plus comma */
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400303 }
304
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400305 remotestr = kzalloc(len, gfp_flags);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400306 if (!remotestr)
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400307 return NULL;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400308
309 p = remotestr;
310 *(p++) = '{';
311 len--;
312 list_for_each_entry(da, dsaddrs, da_node) {
313 size_t ll = strlen(da->da_remotestr);
314
315 if (ll > len)
316 goto out_err;
317
318 memcpy(p, da->da_remotestr, ll);
319 p += ll;
320 len -= ll;
321
322 if (len < 1)
323 goto out_err;
324 (*p++) = ',';
325 len--;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400326 }
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400327 if (len < 2)
328 goto out_err;
329 *(p++) = '}';
330 *p = '\0';
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400331 return remotestr;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400332out_err:
333 kfree(remotestr);
334 return NULL;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400335}
336
337static struct nfs4_pnfs_ds *
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400338nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags)
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400339{
340 struct nfs4_pnfs_ds *tmp_ds, *ds = NULL;
341 char *remotestr;
Andy Adamson16b374c2010-10-20 00:18:04 -0400342
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400343 if (list_empty(dsaddrs)) {
344 dprintk("%s: no addresses defined\n", __func__);
345 goto out;
346 }
347
348 ds = kzalloc(sizeof(*ds), gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400349 if (!ds)
350 goto out;
351
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400352 /* this is only used for debugging, so it's ok if its NULL */
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400353 remotestr = nfs4_pnfs_remotestr(dsaddrs, gfp_flags);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400354
Andy Adamson16b374c2010-10-20 00:18:04 -0400355 spin_lock(&nfs4_ds_cache_lock);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400356 tmp_ds = _data_server_lookup_locked(dsaddrs);
Andy Adamson16b374c2010-10-20 00:18:04 -0400357 if (tmp_ds == NULL) {
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400358 INIT_LIST_HEAD(&ds->ds_addrs);
359 list_splice_init(dsaddrs, &ds->ds_addrs);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400360 ds->ds_remotestr = remotestr;
Andy Adamson16b374c2010-10-20 00:18:04 -0400361 atomic_set(&ds->ds_count, 1);
362 INIT_LIST_HEAD(&ds->ds_node);
363 ds->ds_clp = NULL;
364 list_add(&ds->ds_node, &nfs4_data_server_cache);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400365 dprintk("%s add new data server %s\n", __func__,
366 ds->ds_remotestr);
Andy Adamson16b374c2010-10-20 00:18:04 -0400367 } else {
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400368 kfree(remotestr);
Andy Adamson16b374c2010-10-20 00:18:04 -0400369 kfree(ds);
370 atomic_inc(&tmp_ds->ds_count);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400371 dprintk("%s data server %s found, inc'ed ds_count to %d\n",
372 __func__, tmp_ds->ds_remotestr,
Andy Adamson16b374c2010-10-20 00:18:04 -0400373 atomic_read(&tmp_ds->ds_count));
374 ds = tmp_ds;
375 }
376 spin_unlock(&nfs4_ds_cache_lock);
377out:
378 return ds;
379}
380
381/*
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400382 * Currently only supports ipv4, ipv6 and one multi-path address.
Andy Adamson16b374c2010-10-20 00:18:04 -0400383 */
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400384static struct nfs4_pnfs_ds_addr *
Stanislav Kinsbursky17094272012-01-19 19:05:57 +0400385decode_ds_addr(struct net *net, struct xdr_stream *streamp, gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400386{
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400387 struct nfs4_pnfs_ds_addr *da = NULL;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400388 char *buf, *portstr;
Dan Carpenter13fff2f2012-01-12 10:07:35 +0300389 __be16 port;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400390 int nlen, rlen;
Andy Adamson16b374c2010-10-20 00:18:04 -0400391 int tmp[2];
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400392 __be32 *p;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400393 char *netid, *match_netid;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400394 size_t len, match_netid_len;
395 char *startsep = "";
396 char *endsep = "";
397
Andy Adamson16b374c2010-10-20 00:18:04 -0400398
399 /* r_netid */
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400400 p = xdr_inline_decode(streamp, 4);
401 if (unlikely(!p))
402 goto out_err;
Andy Adamson16b374c2010-10-20 00:18:04 -0400403 nlen = be32_to_cpup(p++);
Andy Adamson16b374c2010-10-20 00:18:04 -0400404
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400405 p = xdr_inline_decode(streamp, nlen);
406 if (unlikely(!p))
407 goto out_err;
Andy Adamson16b374c2010-10-20 00:18:04 -0400408
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400409 netid = kmalloc(nlen+1, gfp_flags);
410 if (unlikely(!netid))
Andy Adamson16b374c2010-10-20 00:18:04 -0400411 goto out_err;
Andy Adamson16b374c2010-10-20 00:18:04 -0400412
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400413 netid[nlen] = '\0';
414 memcpy(netid, p, nlen);
415
416 /* r_addr: ip/ip6addr with port in dec octets - see RFC 5665 */
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400417 p = xdr_inline_decode(streamp, 4);
418 if (unlikely(!p))
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400419 goto out_free_netid;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400420 rlen = be32_to_cpup(p);
421
422 p = xdr_inline_decode(streamp, rlen);
423 if (unlikely(!p))
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400424 goto out_free_netid;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400425
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400426 /* port is ".ABC.DEF", 8 chars max */
427 if (rlen > INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN + 8) {
Jesper Juhlad3d2ee2011-01-17 18:41:50 +0000428 dprintk("%s: Invalid address, length %d\n", __func__,
Andy Adamson16b374c2010-10-20 00:18:04 -0400429 rlen);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400430 goto out_free_netid;
Andy Adamson16b374c2010-10-20 00:18:04 -0400431 }
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400432 buf = kmalloc(rlen + 1, gfp_flags);
Stanislav Fomichevb9f81052011-02-05 23:13:01 +0000433 if (!buf) {
434 dprintk("%s: Not enough memory\n", __func__);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400435 goto out_free_netid;
Stanislav Fomichevb9f81052011-02-05 23:13:01 +0000436 }
Andy Adamson16b374c2010-10-20 00:18:04 -0400437 buf[rlen] = '\0';
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400438 memcpy(buf, p, rlen);
Andy Adamson16b374c2010-10-20 00:18:04 -0400439
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400440 /* replace port '.' with '-' */
441 portstr = strrchr(buf, '.');
442 if (!portstr) {
443 dprintk("%s: Failed finding expected dot in port\n",
444 __func__);
445 goto out_free_buf;
446 }
447 *portstr = '-';
448
449 /* find '.' between address and port */
450 portstr = strrchr(buf, '.');
451 if (!portstr) {
452 dprintk("%s: Failed finding expected dot between address and "
453 "port\n", __func__);
454 goto out_free_buf;
455 }
456 *portstr = '\0';
457
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400458 da = kzalloc(sizeof(*da), gfp_flags);
459 if (unlikely(!da))
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400460 goto out_free_buf;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400461
462 INIT_LIST_HEAD(&da->da_node);
463
Stanislav Kinsbursky17094272012-01-19 19:05:57 +0400464 if (!rpc_pton(net, buf, portstr-buf, (struct sockaddr *)&da->da_addr,
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400465 sizeof(da->da_addr))) {
466 dprintk("%s: error parsing address %s\n", __func__, buf);
467 goto out_free_da;
Andy Adamson16b374c2010-10-20 00:18:04 -0400468 }
469
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400470 portstr++;
471 sscanf(portstr, "%d-%d", &tmp[0], &tmp[1]);
Andy Adamson16b374c2010-10-20 00:18:04 -0400472 port = htons((tmp[0] << 8) | (tmp[1]));
473
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400474 switch (da->da_addr.ss_family) {
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400475 case AF_INET:
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400476 ((struct sockaddr_in *)&da->da_addr)->sin_port = port;
477 da->da_addrlen = sizeof(struct sockaddr_in);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400478 match_netid = "tcp";
479 match_netid_len = 3;
480 break;
481
482 case AF_INET6:
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400483 ((struct sockaddr_in6 *)&da->da_addr)->sin6_port = port;
484 da->da_addrlen = sizeof(struct sockaddr_in6);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400485 match_netid = "tcp6";
486 match_netid_len = 4;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400487 startsep = "[";
488 endsep = "]";
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400489 break;
490
491 default:
492 dprintk("%s: unsupported address family: %u\n",
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400493 __func__, da->da_addr.ss_family);
494 goto out_free_da;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400495 }
496
497 if (nlen != match_netid_len || strncmp(netid, match_netid, nlen)) {
498 dprintk("%s: ERROR: r_netid \"%s\" != \"%s\"\n",
499 __func__, netid, match_netid);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400500 goto out_free_da;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400501 }
502
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400503 /* save human readable address */
504 len = strlen(startsep) + strlen(buf) + strlen(endsep) + 7;
505 da->da_remotestr = kzalloc(len, gfp_flags);
506
507 /* NULL is ok, only used for dprintk */
508 if (da->da_remotestr)
509 snprintf(da->da_remotestr, len, "%s%s%s:%u", startsep,
510 buf, endsep, ntohs(port));
511
512 dprintk("%s: Parsed DS addr %s\n", __func__, da->da_remotestr);
513 kfree(buf);
514 kfree(netid);
515 return da;
516
517out_free_da:
518 kfree(da);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400519out_free_buf:
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400520 dprintk("%s: Error parsing DS addr: %s\n", __func__, buf);
Andy Adamson16b374c2010-10-20 00:18:04 -0400521 kfree(buf);
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400522out_free_netid:
523 kfree(netid);
Andy Adamson16b374c2010-10-20 00:18:04 -0400524out_err:
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400525 return NULL;
Andy Adamson16b374c2010-10-20 00:18:04 -0400526}
527
528/* Decode opaque device data and return the result */
529static struct nfs4_file_layout_dsaddr*
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400530decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400531{
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400532 int i;
Andy Adamson16b374c2010-10-20 00:18:04 -0400533 u32 cnt, num;
534 u8 *indexp;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400535 __be32 *p;
536 u8 *stripe_indices;
537 u8 max_stripe_index;
538 struct nfs4_file_layout_dsaddr *dsaddr = NULL;
539 struct xdr_stream stream;
Benny Halevyf7da7a12011-05-19 14:16:47 -0400540 struct xdr_buf buf;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400541 struct page *scratch;
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400542 struct list_head dsaddrs;
543 struct nfs4_pnfs_ds_addr *da;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400544
545 /* set up xdr stream */
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400546 scratch = alloc_page(gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400547 if (!scratch)
548 goto out_err;
549
Benny Halevyf7da7a12011-05-19 14:16:47 -0400550 xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400551 xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
Andy Adamson16b374c2010-10-20 00:18:04 -0400552
553 /* Get the stripe count (number of stripe index) */
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400554 p = xdr_inline_decode(&stream, 4);
555 if (unlikely(!p))
556 goto out_err_free_scratch;
557
558 cnt = be32_to_cpup(p);
Andy Adamson16b374c2010-10-20 00:18:04 -0400559 dprintk("%s stripe count %d\n", __func__, cnt);
560 if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500561 printk(KERN_WARNING "NFS: %s: stripe count %d greater than "
Andy Adamson16b374c2010-10-20 00:18:04 -0400562 "supported maximum %d\n", __func__,
563 cnt, NFS4_PNFS_MAX_STRIPE_CNT);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400564 goto out_err_free_scratch;
565 }
566
567 /* read stripe indices */
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400568 stripe_indices = kcalloc(cnt, sizeof(u8), gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400569 if (!stripe_indices)
570 goto out_err_free_scratch;
571
572 p = xdr_inline_decode(&stream, cnt << 2);
573 if (unlikely(!p))
574 goto out_err_free_stripe_indices;
575
576 indexp = &stripe_indices[0];
577 max_stripe_index = 0;
578 for (i = 0; i < cnt; i++) {
579 *indexp = be32_to_cpup(p++);
580 max_stripe_index = max(max_stripe_index, *indexp);
581 indexp++;
Andy Adamson16b374c2010-10-20 00:18:04 -0400582 }
583
584 /* Check the multipath list count */
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400585 p = xdr_inline_decode(&stream, 4);
586 if (unlikely(!p))
587 goto out_err_free_stripe_indices;
588
589 num = be32_to_cpup(p);
Andy Adamson16b374c2010-10-20 00:18:04 -0400590 dprintk("%s ds_num %u\n", __func__, num);
591 if (num > NFS4_PNFS_MAX_MULTI_CNT) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500592 printk(KERN_WARNING "NFS: %s: multipath count %d greater than "
Andy Adamson16b374c2010-10-20 00:18:04 -0400593 "supported maximum %d\n", __func__,
594 num, NFS4_PNFS_MAX_MULTI_CNT);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400595 goto out_err_free_stripe_indices;
Andy Adamson16b374c2010-10-20 00:18:04 -0400596 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400597
598 /* validate stripe indices are all < num */
599 if (max_stripe_index >= num) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500600 printk(KERN_WARNING "NFS: %s: stripe index %u >= num ds %u\n",
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400601 __func__, max_stripe_index, num);
602 goto out_err_free_stripe_indices;
603 }
604
Andy Adamson16b374c2010-10-20 00:18:04 -0400605 dsaddr = kzalloc(sizeof(*dsaddr) +
606 (sizeof(struct nfs4_pnfs_ds *) * (num - 1)),
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400607 gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400608 if (!dsaddr)
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400609 goto out_err_free_stripe_indices;
Andy Adamson16b374c2010-10-20 00:18:04 -0400610
611 dsaddr->stripe_count = cnt;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400612 dsaddr->stripe_indices = stripe_indices;
613 stripe_indices = NULL;
Andy Adamson16b374c2010-10-20 00:18:04 -0400614 dsaddr->ds_num = num;
Benny Halevy1775bc32011-05-20 13:47:33 +0200615 nfs4_init_deviceid_node(&dsaddr->id_node,
616 NFS_SERVER(ino)->pnfs_curr_ld,
617 NFS_SERVER(ino)->nfs_client,
Benny Halevya1eaecb2011-05-19 22:14:47 -0400618 &pdev->dev_id);
Andy Adamson16b374c2010-10-20 00:18:04 -0400619
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400620 INIT_LIST_HEAD(&dsaddrs);
621
Andy Adamson16b374c2010-10-20 00:18:04 -0400622 for (i = 0; i < dsaddr->ds_num; i++) {
623 int j;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400624 u32 mp_count;
Andy Adamson16b374c2010-10-20 00:18:04 -0400625
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400626 p = xdr_inline_decode(&stream, 4);
627 if (unlikely(!p))
628 goto out_err_free_deviceid;
629
630 mp_count = be32_to_cpup(p); /* multipath count */
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400631 for (j = 0; j < mp_count; j++) {
Chuck Lever73ea6662012-05-21 22:44:50 -0400632 da = decode_ds_addr(NFS_SERVER(ino)->nfs_client->cl_net,
Stanislav Kinsbursky17094272012-01-19 19:05:57 +0400633 &stream, gfp_flags);
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400634 if (da)
635 list_add_tail(&da->da_node, &dsaddrs);
636 }
637 if (list_empty(&dsaddrs)) {
638 dprintk("%s: no suitable DS addresses found\n",
639 __func__);
640 goto out_err_free_deviceid;
641 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400642
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400643 dsaddr->ds_list[i] = nfs4_pnfs_ds_add(&dsaddrs, gfp_flags);
644 if (!dsaddr->ds_list[i])
645 goto out_err_drain_dsaddrs;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400646
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400647 /* If DS was already in cache, free ds addrs */
648 while (!list_empty(&dsaddrs)) {
649 da = list_first_entry(&dsaddrs,
650 struct nfs4_pnfs_ds_addr,
651 da_node);
652 list_del_init(&da->da_node);
653 kfree(da->da_remotestr);
654 kfree(da);
Andy Adamson16b374c2010-10-20 00:18:04 -0400655 }
656 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400657
658 __free_page(scratch);
Andy Adamson16b374c2010-10-20 00:18:04 -0400659 return dsaddr;
660
Weston Andros Adamson14f9a602011-05-31 18:48:57 -0400661out_err_drain_dsaddrs:
662 while (!list_empty(&dsaddrs)) {
663 da = list_first_entry(&dsaddrs, struct nfs4_pnfs_ds_addr,
664 da_node);
665 list_del_init(&da->da_node);
666 kfree(da->da_remotestr);
667 kfree(da);
668 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400669out_err_free_deviceid:
Andy Adamson16b374c2010-10-20 00:18:04 -0400670 nfs4_fl_free_deviceid(dsaddr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400671 /* stripe_indicies was part of dsaddr */
672 goto out_err_free_scratch;
673out_err_free_stripe_indices:
674 kfree(stripe_indices);
675out_err_free_scratch:
676 __free_page(scratch);
Andy Adamson16b374c2010-10-20 00:18:04 -0400677out_err:
678 dprintk("%s ERROR: returning NULL\n", __func__);
679 return NULL;
680}
681
682/*
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000683 * Decode the opaque device specified in 'dev' and add it to the cache of
684 * available devices.
Andy Adamson16b374c2010-10-20 00:18:04 -0400685 */
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000686static struct nfs4_file_layout_dsaddr *
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400687decode_and_add_device(struct inode *inode, struct pnfs_device *dev, gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400688{
Benny Halevya1eaecb2011-05-19 22:14:47 -0400689 struct nfs4_deviceid_node *d;
690 struct nfs4_file_layout_dsaddr *n, *new;
Andy Adamson16b374c2010-10-20 00:18:04 -0400691
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400692 new = decode_device(inode, dev, gfp_flags);
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000693 if (!new) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500694 printk(KERN_WARNING "NFS: %s: Could not decode or add device\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400695 __func__);
696 return NULL;
697 }
698
Benny Halevya1eaecb2011-05-19 22:14:47 -0400699 d = nfs4_insert_deviceid_node(&new->id_node);
700 n = container_of(d, struct nfs4_file_layout_dsaddr, id_node);
701 if (n != new) {
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000702 nfs4_fl_free_deviceid(new);
Benny Halevya1eaecb2011-05-19 22:14:47 -0400703 return n;
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000704 }
Andy Adamson16b374c2010-10-20 00:18:04 -0400705
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000706 return new;
Andy Adamson16b374c2010-10-20 00:18:04 -0400707}
708
709/*
710 * Retrieve the information for dev_id, add it to the list
711 * of available devices, and return it.
712 */
713struct nfs4_file_layout_dsaddr *
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400714get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id, gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400715{
716 struct pnfs_device *pdev = NULL;
717 u32 max_resp_sz;
718 int max_pages;
719 struct page **pages = NULL;
720 struct nfs4_file_layout_dsaddr *dsaddr = NULL;
721 int rc, i;
722 struct nfs_server *server = NFS_SERVER(inode);
723
724 /*
725 * Use the session max response size as the basis for setting
726 * GETDEVICEINFO's maxcount
727 */
728 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
Andy Adamsone5265a02012-04-14 03:56:35 -0400729 max_pages = nfs_page_array_len(0, max_resp_sz);
Andy Adamson16b374c2010-10-20 00:18:04 -0400730 dprintk("%s inode %p max_resp_sz %u max_pages %d\n",
731 __func__, inode, max_resp_sz, max_pages);
732
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400733 pdev = kzalloc(sizeof(struct pnfs_device), gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400734 if (pdev == NULL)
735 return NULL;
736
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400737 pages = kzalloc(max_pages * sizeof(struct page *), gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400738 if (pages == NULL) {
739 kfree(pdev);
740 return NULL;
741 }
742 for (i = 0; i < max_pages; i++) {
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400743 pages[i] = alloc_page(gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400744 if (!pages[i])
745 goto out_free;
746 }
747
Andy Adamson16b374c2010-10-20 00:18:04 -0400748 memcpy(&pdev->dev_id, dev_id, sizeof(*dev_id));
749 pdev->layout_type = LAYOUT_NFSV4_1_FILES;
750 pdev->pages = pages;
751 pdev->pgbase = 0;
752 pdev->pglen = PAGE_SIZE * max_pages;
753 pdev->mincount = 0;
754
755 rc = nfs4_proc_getdeviceinfo(server, pdev);
756 dprintk("%s getdevice info returns %d\n", __func__, rc);
757 if (rc)
758 goto out_free;
759
760 /*
761 * Found new device, need to decode it and then add it to the
762 * list of known devices for this mountpoint.
763 */
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400764 dsaddr = decode_and_add_device(inode, pdev, gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400765out_free:
Andy Adamson16b374c2010-10-20 00:18:04 -0400766 for (i = 0; i < max_pages; i++)
767 __free_page(pages[i]);
768 kfree(pages);
769 kfree(pdev);
770 dprintk("<-- %s dsaddr %p\n", __func__, dsaddr);
771 return dsaddr;
772}
773
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000774void
775nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
Andy Adamson16b374c2010-10-20 00:18:04 -0400776{
Benny Halevy1775bc32011-05-20 13:47:33 +0200777 nfs4_put_deviceid_node(&dsaddr->id_node);
Andy Adamson16b374c2010-10-20 00:18:04 -0400778}
Fred Isamancfe7f412011-03-01 01:34:18 +0000779
780/*
781 * Want res = (offset - layout->pattern_offset)/ layout->stripe_unit
782 * Then: ((res + fsi) % dsaddr->stripe_count)
783 */
784u32
785nfs4_fl_calc_j_index(struct pnfs_layout_segment *lseg, loff_t offset)
786{
787 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
788 u64 tmp;
789
790 tmp = offset - flseg->pattern_offset;
791 do_div(tmp, flseg->stripe_unit);
792 tmp += flseg->first_stripe_index;
793 return do_div(tmp, flseg->dsaddr->stripe_count);
794}
795
796u32
797nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j)
798{
799 return FILELAYOUT_LSEG(lseg)->dsaddr->stripe_indices[j];
800}
801
802struct nfs_fh *
803nfs4_fl_select_ds_fh(struct pnfs_layout_segment *lseg, u32 j)
804{
805 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
806 u32 i;
807
808 if (flseg->stripe_type == STRIPE_SPARSE) {
809 if (flseg->num_fh == 1)
810 i = 0;
811 else if (flseg->num_fh == 0)
812 /* Use the MDS OPEN fh set in nfs_read_rpcsetup */
813 return NULL;
814 else
815 i = nfs4_fl_calc_ds_index(lseg, j);
816 } else
817 i = j;
818 return flseg->fh_array[i];
819}
820
821struct nfs4_pnfs_ds *
822nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx)
823{
824 struct nfs4_file_layout_dsaddr *dsaddr = FILELAYOUT_LSEG(lseg)->dsaddr;
825 struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx];
Andy Adamson554d4582012-04-27 17:53:42 -0400826 struct nfs4_deviceid_node *devid = FILELAYOUT_DEVID_NODE(lseg);
827
828 if (filelayout_test_devid_invalid(devid))
829 return NULL;
Fred Isamancfe7f412011-03-01 01:34:18 +0000830
831 if (ds == NULL) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500832 printk(KERN_ERR "NFS: %s: No data server for offset index %d\n",
Fred Isamancfe7f412011-03-01 01:34:18 +0000833 __func__, ds_idx);
Andy Adamson554d4582012-04-27 17:53:42 -0400834 goto mark_dev_invalid;
Fred Isamancfe7f412011-03-01 01:34:18 +0000835 }
836
837 if (!ds->ds_clp) {
Andy Adamson568e8c42011-03-01 01:34:22 +0000838 struct nfs_server *s = NFS_SERVER(lseg->pls_layout->plh_inode);
Fred Isamancfe7f412011-03-01 01:34:18 +0000839 int err;
840
Andy Adamson568e8c42011-03-01 01:34:22 +0000841 err = nfs4_ds_connect(s, ds);
Andy Adamson554d4582012-04-27 17:53:42 -0400842 if (err)
843 goto mark_dev_invalid;
Fred Isamancfe7f412011-03-01 01:34:18 +0000844 }
845 return ds;
Andy Adamson554d4582012-04-27 17:53:42 -0400846
847mark_dev_invalid:
848 filelayout_mark_devid_invalid(devid);
849 return NULL;
Fred Isamancfe7f412011-03-01 01:34:18 +0000850}
Andy Adamson98fc6852012-04-27 17:53:45 -0400851
852module_param(dataserver_retrans, uint, 0644);
853MODULE_PARM_DESC(dataserver_retrans, "The number of times the NFSv4.1 client "
854 "retries a request before it attempts further "
855 " recovery action.");
856module_param(dataserver_timeo, uint, 0644);
857MODULE_PARM_DESC(dataserver_timeo, "The time (in tenths of a second) the "
858 "NFSv4.1 client waits for a response from a "
859 " data server before it retries an NFS request.");