nfs4filelayoutdev.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /*
  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. #include <linux/nfs_fs.h>
  31. #include <linux/vmalloc.h>
  32. #include "internal.h"
  33. #include "nfs4filelayout.h"
  34. #define NFSDBG_FACILITY NFSDBG_PNFS_LD
  35. /*
  36. * Data server cache
  37. *
  38. * Data servers can be mapped to different device ids.
  39. * nfs4_pnfs_ds reference counting
  40. * - set to 1 on allocation
  41. * - incremented when a device id maps a data server already in the cache.
  42. * - decremented when deviceid is removed from the cache.
  43. */
  44. DEFINE_SPINLOCK(nfs4_ds_cache_lock);
  45. static LIST_HEAD(nfs4_data_server_cache);
  46. /* Debug routines */
  47. void
  48. print_ds(struct nfs4_pnfs_ds *ds)
  49. {
  50. if (ds == NULL) {
  51. printk("%s NULL device\n", __func__);
  52. return;
  53. }
  54. printk(" ip_addr %x port %hu\n"
  55. " ref count %d\n"
  56. " client %p\n"
  57. " cl_exchange_flags %x\n",
  58. ntohl(ds->ds_ip_addr), ntohs(ds->ds_port),
  59. atomic_read(&ds->ds_count), ds->ds_clp,
  60. ds->ds_clp ? ds->ds_clp->cl_exchange_flags : 0);
  61. }
  62. /* nfs4_ds_cache_lock is held */
  63. static struct nfs4_pnfs_ds *
  64. _data_server_lookup_locked(u32 ip_addr, u32 port)
  65. {
  66. struct nfs4_pnfs_ds *ds;
  67. dprintk("_data_server_lookup: ip_addr=%x port=%hu\n",
  68. ntohl(ip_addr), ntohs(port));
  69. list_for_each_entry(ds, &nfs4_data_server_cache, ds_node) {
  70. if (ds->ds_ip_addr == ip_addr &&
  71. ds->ds_port == port) {
  72. return ds;
  73. }
  74. }
  75. return NULL;
  76. }
  77. /*
  78. * Create an rpc connection to the nfs4_pnfs_ds data server
  79. * Currently only support IPv4
  80. */
  81. static int
  82. nfs4_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds)
  83. {
  84. struct nfs_client *clp;
  85. struct sockaddr_in sin;
  86. int status = 0;
  87. dprintk("--> %s ip:port %x:%hu au_flavor %d\n", __func__,
  88. ntohl(ds->ds_ip_addr), ntohs(ds->ds_port),
  89. mds_srv->nfs_client->cl_rpcclient->cl_auth->au_flavor);
  90. sin.sin_family = AF_INET;
  91. sin.sin_addr.s_addr = ds->ds_ip_addr;
  92. sin.sin_port = ds->ds_port;
  93. clp = nfs4_set_ds_client(mds_srv->nfs_client, (struct sockaddr *)&sin,
  94. sizeof(sin), IPPROTO_TCP);
  95. if (IS_ERR(clp)) {
  96. status = PTR_ERR(clp);
  97. goto out;
  98. }
  99. if ((clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) != 0) {
  100. if (!is_ds_client(clp)) {
  101. status = -ENODEV;
  102. goto out_put;
  103. }
  104. ds->ds_clp = clp;
  105. dprintk("%s [existing] ip=%x, port=%hu\n", __func__,
  106. ntohl(ds->ds_ip_addr), ntohs(ds->ds_port));
  107. goto out;
  108. }
  109. /*
  110. * Do not set NFS_CS_CHECK_LEASE_TIME instead set the DS lease to
  111. * be equal to the MDS lease. Renewal is scheduled in create_session.
  112. */
  113. spin_lock(&mds_srv->nfs_client->cl_lock);
  114. clp->cl_lease_time = mds_srv->nfs_client->cl_lease_time;
  115. spin_unlock(&mds_srv->nfs_client->cl_lock);
  116. clp->cl_last_renewal = jiffies;
  117. /* New nfs_client */
  118. status = nfs4_init_ds_session(clp);
  119. if (status)
  120. goto out_put;
  121. ds->ds_clp = clp;
  122. dprintk("%s [new] ip=%x, port=%hu\n", __func__, ntohl(ds->ds_ip_addr),
  123. ntohs(ds->ds_port));
  124. out:
  125. return status;
  126. out_put:
  127. nfs_put_client(clp);
  128. goto out;
  129. }
  130. static void
  131. destroy_ds(struct nfs4_pnfs_ds *ds)
  132. {
  133. dprintk("--> %s\n", __func__);
  134. ifdebug(FACILITY)
  135. print_ds(ds);
  136. if (ds->ds_clp)
  137. nfs_put_client(ds->ds_clp);
  138. kfree(ds);
  139. }
  140. void
  141. nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
  142. {
  143. struct nfs4_pnfs_ds *ds;
  144. int i;
  145. nfs4_print_deviceid(&dsaddr->id_node.deviceid);
  146. for (i = 0; i < dsaddr->ds_num; i++) {
  147. ds = dsaddr->ds_list[i];
  148. if (ds != NULL) {
  149. if (atomic_dec_and_lock(&ds->ds_count,
  150. &nfs4_ds_cache_lock)) {
  151. list_del_init(&ds->ds_node);
  152. spin_unlock(&nfs4_ds_cache_lock);
  153. destroy_ds(ds);
  154. }
  155. }
  156. }
  157. kfree(dsaddr->stripe_indices);
  158. kfree(dsaddr);
  159. }
  160. static struct nfs4_pnfs_ds *
  161. nfs4_pnfs_ds_add(struct inode *inode, u32 ip_addr, u32 port, gfp_t gfp_flags)
  162. {
  163. struct nfs4_pnfs_ds *tmp_ds, *ds;
  164. ds = kzalloc(sizeof(*tmp_ds), gfp_flags);
  165. if (!ds)
  166. goto out;
  167. spin_lock(&nfs4_ds_cache_lock);
  168. tmp_ds = _data_server_lookup_locked(ip_addr, port);
  169. if (tmp_ds == NULL) {
  170. ds->ds_ip_addr = ip_addr;
  171. ds->ds_port = port;
  172. atomic_set(&ds->ds_count, 1);
  173. INIT_LIST_HEAD(&ds->ds_node);
  174. ds->ds_clp = NULL;
  175. list_add(&ds->ds_node, &nfs4_data_server_cache);
  176. dprintk("%s add new data server ip 0x%x\n", __func__,
  177. ds->ds_ip_addr);
  178. } else {
  179. kfree(ds);
  180. atomic_inc(&tmp_ds->ds_count);
  181. dprintk("%s data server found ip 0x%x, inc'ed ds_count to %d\n",
  182. __func__, tmp_ds->ds_ip_addr,
  183. atomic_read(&tmp_ds->ds_count));
  184. ds = tmp_ds;
  185. }
  186. spin_unlock(&nfs4_ds_cache_lock);
  187. out:
  188. return ds;
  189. }
  190. /*
  191. * Currently only support ipv4, and one multi-path address.
  192. */
  193. static struct nfs4_pnfs_ds *
  194. decode_and_add_ds(struct xdr_stream *streamp, struct inode *inode, gfp_t gfp_flags)
  195. {
  196. struct nfs4_pnfs_ds *ds = NULL;
  197. char *buf;
  198. const char *ipend, *pstr;
  199. u32 ip_addr, port;
  200. int nlen, rlen, i;
  201. int tmp[2];
  202. __be32 *p;
  203. /* r_netid */
  204. p = xdr_inline_decode(streamp, 4);
  205. if (unlikely(!p))
  206. goto out_err;
  207. nlen = be32_to_cpup(p++);
  208. p = xdr_inline_decode(streamp, nlen);
  209. if (unlikely(!p))
  210. goto out_err;
  211. /* Check that netid is "tcp" */
  212. if (nlen != 3 || memcmp((char *)p, "tcp", 3)) {
  213. dprintk("%s: ERROR: non ipv4 TCP r_netid\n", __func__);
  214. goto out_err;
  215. }
  216. /* r_addr */
  217. p = xdr_inline_decode(streamp, 4);
  218. if (unlikely(!p))
  219. goto out_err;
  220. rlen = be32_to_cpup(p);
  221. p = xdr_inline_decode(streamp, rlen);
  222. if (unlikely(!p))
  223. goto out_err;
  224. /* ipv6 length plus port is legal */
  225. if (rlen > INET6_ADDRSTRLEN + 8) {
  226. dprintk("%s: Invalid address, length %d\n", __func__,
  227. rlen);
  228. goto out_err;
  229. }
  230. buf = kmalloc(rlen + 1, gfp_flags);
  231. if (!buf) {
  232. dprintk("%s: Not enough memory\n", __func__);
  233. goto out_err;
  234. }
  235. buf[rlen] = '\0';
  236. memcpy(buf, p, rlen);
  237. /* replace the port dots with dashes for the in4_pton() delimiter*/
  238. for (i = 0; i < 2; i++) {
  239. char *res = strrchr(buf, '.');
  240. if (!res) {
  241. dprintk("%s: Failed finding expected dots in port\n",
  242. __func__);
  243. goto out_free;
  244. }
  245. *res = '-';
  246. }
  247. /* Currently only support ipv4 address */
  248. if (in4_pton(buf, rlen, (u8 *)&ip_addr, '-', &ipend) == 0) {
  249. dprintk("%s: Only ipv4 addresses supported\n", __func__);
  250. goto out_free;
  251. }
  252. /* port */
  253. pstr = ipend;
  254. sscanf(pstr, "-%d-%d", &tmp[0], &tmp[1]);
  255. port = htons((tmp[0] << 8) | (tmp[1]));
  256. ds = nfs4_pnfs_ds_add(inode, ip_addr, port, gfp_flags);
  257. dprintk("%s: Decoded address and port %s\n", __func__, buf);
  258. out_free:
  259. kfree(buf);
  260. out_err:
  261. return ds;
  262. }
  263. /* Decode opaque device data and return the result */
  264. static struct nfs4_file_layout_dsaddr*
  265. decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
  266. {
  267. int i;
  268. u32 cnt, num;
  269. u8 *indexp;
  270. __be32 *p;
  271. u8 *stripe_indices;
  272. u8 max_stripe_index;
  273. struct nfs4_file_layout_dsaddr *dsaddr = NULL;
  274. struct xdr_stream stream;
  275. struct xdr_buf buf;
  276. struct page *scratch;
  277. /* set up xdr stream */
  278. scratch = alloc_page(gfp_flags);
  279. if (!scratch)
  280. goto out_err;
  281. xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen);
  282. xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
  283. /* Get the stripe count (number of stripe index) */
  284. p = xdr_inline_decode(&stream, 4);
  285. if (unlikely(!p))
  286. goto out_err_free_scratch;
  287. cnt = be32_to_cpup(p);
  288. dprintk("%s stripe count %d\n", __func__, cnt);
  289. if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) {
  290. printk(KERN_WARNING "%s: stripe count %d greater than "
  291. "supported maximum %d\n", __func__,
  292. cnt, NFS4_PNFS_MAX_STRIPE_CNT);
  293. goto out_err_free_scratch;
  294. }
  295. /* read stripe indices */
  296. stripe_indices = kcalloc(cnt, sizeof(u8), gfp_flags);
  297. if (!stripe_indices)
  298. goto out_err_free_scratch;
  299. p = xdr_inline_decode(&stream, cnt << 2);
  300. if (unlikely(!p))
  301. goto out_err_free_stripe_indices;
  302. indexp = &stripe_indices[0];
  303. max_stripe_index = 0;
  304. for (i = 0; i < cnt; i++) {
  305. *indexp = be32_to_cpup(p++);
  306. max_stripe_index = max(max_stripe_index, *indexp);
  307. indexp++;
  308. }
  309. /* Check the multipath list count */
  310. p = xdr_inline_decode(&stream, 4);
  311. if (unlikely(!p))
  312. goto out_err_free_stripe_indices;
  313. num = be32_to_cpup(p);
  314. dprintk("%s ds_num %u\n", __func__, num);
  315. if (num > NFS4_PNFS_MAX_MULTI_CNT) {
  316. printk(KERN_WARNING "%s: multipath count %d greater than "
  317. "supported maximum %d\n", __func__,
  318. num, NFS4_PNFS_MAX_MULTI_CNT);
  319. goto out_err_free_stripe_indices;
  320. }
  321. /* validate stripe indices are all < num */
  322. if (max_stripe_index >= num) {
  323. printk(KERN_WARNING "%s: stripe index %u >= num ds %u\n",
  324. __func__, max_stripe_index, num);
  325. goto out_err_free_stripe_indices;
  326. }
  327. dsaddr = kzalloc(sizeof(*dsaddr) +
  328. (sizeof(struct nfs4_pnfs_ds *) * (num - 1)),
  329. gfp_flags);
  330. if (!dsaddr)
  331. goto out_err_free_stripe_indices;
  332. dsaddr->stripe_count = cnt;
  333. dsaddr->stripe_indices = stripe_indices;
  334. stripe_indices = NULL;
  335. dsaddr->ds_num = num;
  336. nfs4_init_deviceid_node(&dsaddr->id_node,
  337. NFS_SERVER(ino)->pnfs_curr_ld,
  338. NFS_SERVER(ino)->nfs_client,
  339. &pdev->dev_id);
  340. for (i = 0; i < dsaddr->ds_num; i++) {
  341. int j;
  342. u32 mp_count;
  343. p = xdr_inline_decode(&stream, 4);
  344. if (unlikely(!p))
  345. goto out_err_free_deviceid;
  346. mp_count = be32_to_cpup(p); /* multipath count */
  347. if (mp_count > 1) {
  348. printk(KERN_WARNING
  349. "%s: Multipath count %d not supported, "
  350. "skipping all greater than 1\n", __func__,
  351. mp_count);
  352. }
  353. for (j = 0; j < mp_count; j++) {
  354. if (j == 0) {
  355. dsaddr->ds_list[i] = decode_and_add_ds(&stream,
  356. ino, gfp_flags);
  357. if (dsaddr->ds_list[i] == NULL)
  358. goto out_err_free_deviceid;
  359. } else {
  360. u32 len;
  361. /* skip extra multipath */
  362. /* read len, skip */
  363. p = xdr_inline_decode(&stream, 4);
  364. if (unlikely(!p))
  365. goto out_err_free_deviceid;
  366. len = be32_to_cpup(p);
  367. p = xdr_inline_decode(&stream, len);
  368. if (unlikely(!p))
  369. goto out_err_free_deviceid;
  370. /* read len, skip */
  371. p = xdr_inline_decode(&stream, 4);
  372. if (unlikely(!p))
  373. goto out_err_free_deviceid;
  374. len = be32_to_cpup(p);
  375. p = xdr_inline_decode(&stream, len);
  376. if (unlikely(!p))
  377. goto out_err_free_deviceid;
  378. }
  379. }
  380. }
  381. __free_page(scratch);
  382. return dsaddr;
  383. out_err_free_deviceid:
  384. nfs4_fl_free_deviceid(dsaddr);
  385. /* stripe_indicies was part of dsaddr */
  386. goto out_err_free_scratch;
  387. out_err_free_stripe_indices:
  388. kfree(stripe_indices);
  389. out_err_free_scratch:
  390. __free_page(scratch);
  391. out_err:
  392. dprintk("%s ERROR: returning NULL\n", __func__);
  393. return NULL;
  394. }
  395. /*
  396. * Decode the opaque device specified in 'dev' and add it to the cache of
  397. * available devices.
  398. */
  399. static struct nfs4_file_layout_dsaddr *
  400. decode_and_add_device(struct inode *inode, struct pnfs_device *dev, gfp_t gfp_flags)
  401. {
  402. struct nfs4_deviceid_node *d;
  403. struct nfs4_file_layout_dsaddr *n, *new;
  404. new = decode_device(inode, dev, gfp_flags);
  405. if (!new) {
  406. printk(KERN_WARNING "%s: Could not decode or add device\n",
  407. __func__);
  408. return NULL;
  409. }
  410. d = nfs4_insert_deviceid_node(&new->id_node);
  411. n = container_of(d, struct nfs4_file_layout_dsaddr, id_node);
  412. if (n != new) {
  413. nfs4_fl_free_deviceid(new);
  414. return n;
  415. }
  416. return new;
  417. }
  418. /*
  419. * Retrieve the information for dev_id, add it to the list
  420. * of available devices, and return it.
  421. */
  422. struct nfs4_file_layout_dsaddr *
  423. get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id, gfp_t gfp_flags)
  424. {
  425. struct pnfs_device *pdev = NULL;
  426. u32 max_resp_sz;
  427. int max_pages;
  428. struct page **pages = NULL;
  429. struct nfs4_file_layout_dsaddr *dsaddr = NULL;
  430. int rc, i;
  431. struct nfs_server *server = NFS_SERVER(inode);
  432. /*
  433. * Use the session max response size as the basis for setting
  434. * GETDEVICEINFO's maxcount
  435. */
  436. max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
  437. max_pages = max_resp_sz >> PAGE_SHIFT;
  438. dprintk("%s inode %p max_resp_sz %u max_pages %d\n",
  439. __func__, inode, max_resp_sz, max_pages);
  440. pdev = kzalloc(sizeof(struct pnfs_device), gfp_flags);
  441. if (pdev == NULL)
  442. return NULL;
  443. pages = kzalloc(max_pages * sizeof(struct page *), gfp_flags);
  444. if (pages == NULL) {
  445. kfree(pdev);
  446. return NULL;
  447. }
  448. for (i = 0; i < max_pages; i++) {
  449. pages[i] = alloc_page(gfp_flags);
  450. if (!pages[i])
  451. goto out_free;
  452. }
  453. memcpy(&pdev->dev_id, dev_id, sizeof(*dev_id));
  454. pdev->layout_type = LAYOUT_NFSV4_1_FILES;
  455. pdev->pages = pages;
  456. pdev->pgbase = 0;
  457. pdev->pglen = PAGE_SIZE * max_pages;
  458. pdev->mincount = 0;
  459. rc = nfs4_proc_getdeviceinfo(server, pdev);
  460. dprintk("%s getdevice info returns %d\n", __func__, rc);
  461. if (rc)
  462. goto out_free;
  463. /*
  464. * Found new device, need to decode it and then add it to the
  465. * list of known devices for this mountpoint.
  466. */
  467. dsaddr = decode_and_add_device(inode, pdev, gfp_flags);
  468. out_free:
  469. for (i = 0; i < max_pages; i++)
  470. __free_page(pages[i]);
  471. kfree(pages);
  472. kfree(pdev);
  473. dprintk("<-- %s dsaddr %p\n", __func__, dsaddr);
  474. return dsaddr;
  475. }
  476. void
  477. nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
  478. {
  479. nfs4_put_deviceid_node(&dsaddr->id_node);
  480. }
  481. /*
  482. * Want res = (offset - layout->pattern_offset)/ layout->stripe_unit
  483. * Then: ((res + fsi) % dsaddr->stripe_count)
  484. */
  485. u32
  486. nfs4_fl_calc_j_index(struct pnfs_layout_segment *lseg, loff_t offset)
  487. {
  488. struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
  489. u64 tmp;
  490. tmp = offset - flseg->pattern_offset;
  491. do_div(tmp, flseg->stripe_unit);
  492. tmp += flseg->first_stripe_index;
  493. return do_div(tmp, flseg->dsaddr->stripe_count);
  494. }
  495. u32
  496. nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j)
  497. {
  498. return FILELAYOUT_LSEG(lseg)->dsaddr->stripe_indices[j];
  499. }
  500. struct nfs_fh *
  501. nfs4_fl_select_ds_fh(struct pnfs_layout_segment *lseg, u32 j)
  502. {
  503. struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
  504. u32 i;
  505. if (flseg->stripe_type == STRIPE_SPARSE) {
  506. if (flseg->num_fh == 1)
  507. i = 0;
  508. else if (flseg->num_fh == 0)
  509. /* Use the MDS OPEN fh set in nfs_read_rpcsetup */
  510. return NULL;
  511. else
  512. i = nfs4_fl_calc_ds_index(lseg, j);
  513. } else
  514. i = j;
  515. return flseg->fh_array[i];
  516. }
  517. static void
  518. filelayout_mark_devid_negative(struct nfs4_file_layout_dsaddr *dsaddr,
  519. int err, u32 ds_addr)
  520. {
  521. u32 *p = (u32 *)&dsaddr->id_node.deviceid;
  522. printk(KERN_ERR "NFS: data server %x connection error %d."
  523. " Deviceid [%x%x%x%x] marked out of use.\n",
  524. ds_addr, err, p[0], p[1], p[2], p[3]);
  525. spin_lock(&nfs4_ds_cache_lock);
  526. dsaddr->flags |= NFS4_DEVICE_ID_NEG_ENTRY;
  527. spin_unlock(&nfs4_ds_cache_lock);
  528. }
  529. struct nfs4_pnfs_ds *
  530. nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx)
  531. {
  532. struct nfs4_file_layout_dsaddr *dsaddr = FILELAYOUT_LSEG(lseg)->dsaddr;
  533. struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx];
  534. if (ds == NULL) {
  535. printk(KERN_ERR "%s: No data server for offset index %d\n",
  536. __func__, ds_idx);
  537. return NULL;
  538. }
  539. if (!ds->ds_clp) {
  540. struct nfs_server *s = NFS_SERVER(lseg->pls_layout->plh_inode);
  541. int err;
  542. if (dsaddr->flags & NFS4_DEVICE_ID_NEG_ENTRY) {
  543. /* Already tried to connect, don't try again */
  544. dprintk("%s Deviceid marked out of use\n", __func__);
  545. return NULL;
  546. }
  547. err = nfs4_ds_connect(s, ds);
  548. if (err) {
  549. filelayout_mark_devid_negative(dsaddr, err,
  550. ntohl(ds->ds_ip_addr));
  551. return NULL;
  552. }
  553. }
  554. return ds;
  555. }