objio_osd.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * pNFS Objects layout implementation over open-osd initiator library
  3. *
  4. * Copyright (C) 2009 Panasas Inc. [year of first publication]
  5. * All rights reserved.
  6. *
  7. * Benny Halevy <bhalevy@panasas.com>
  8. * Boaz Harrosh <ooo@electrozaur.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2
  12. * See the file COPYING included with this distribution for more details.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. *
  18. * 1. Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. * 3. Neither the name of the Panasas company nor the names of its
  24. * contributors may be used to endorse or promote products derived
  25. * from this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  28. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  29. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  31. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  34. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. */
  39. #include <linux/module.h>
  40. #include <scsi/osd_ore.h>
  41. #include "objlayout.h"
  42. #include "../internal.h"
  43. #define NFSDBG_FACILITY NFSDBG_PNFS_LD
  44. struct objio_dev_ent {
  45. struct nfs4_deviceid_node id_node;
  46. struct ore_dev od;
  47. };
  48. static void
  49. objio_free_deviceid_node(struct nfs4_deviceid_node *d)
  50. {
  51. struct objio_dev_ent *de = container_of(d, struct objio_dev_ent, id_node);
  52. dprintk("%s: free od=%p\n", __func__, de->od.od);
  53. osduld_put_device(de->od.od);
  54. kfree_rcu(d, rcu);
  55. }
  56. struct objio_segment {
  57. struct pnfs_layout_segment lseg;
  58. struct ore_layout layout;
  59. struct ore_components oc;
  60. };
  61. static inline struct objio_segment *
  62. OBJIO_LSEG(struct pnfs_layout_segment *lseg)
  63. {
  64. return container_of(lseg, struct objio_segment, lseg);
  65. }
  66. struct objio_state {
  67. /* Generic layer */
  68. struct objlayout_io_res oir;
  69. bool sync;
  70. /*FIXME: Support for extra_bytes at ore_get_rw_state() */
  71. struct ore_io_state *ios;
  72. };
  73. /* Send and wait for a get_device_info of devices in the layout,
  74. then look them up with the osd_initiator library */
  75. struct nfs4_deviceid_node *
  76. objio_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
  77. gfp_t gfp_flags)
  78. {
  79. struct pnfs_osd_deviceaddr *deviceaddr;
  80. struct objio_dev_ent *ode = NULL;
  81. struct osd_dev *od;
  82. struct osd_dev_info odi;
  83. bool retry_flag = true;
  84. __be32 *p;
  85. int err;
  86. deviceaddr = kzalloc(sizeof(*deviceaddr), gfp_flags);
  87. if (!deviceaddr)
  88. return NULL;
  89. p = page_address(pdev->pages[0]);
  90. pnfs_osd_xdr_decode_deviceaddr(deviceaddr, p);
  91. odi.systemid_len = deviceaddr->oda_systemid.len;
  92. if (odi.systemid_len > sizeof(odi.systemid)) {
  93. dprintk("%s: odi.systemid_len > sizeof(systemid=%zd)\n",
  94. __func__, sizeof(odi.systemid));
  95. err = -EINVAL;
  96. goto out;
  97. } else if (odi.systemid_len)
  98. memcpy(odi.systemid, deviceaddr->oda_systemid.data,
  99. odi.systemid_len);
  100. odi.osdname_len = deviceaddr->oda_osdname.len;
  101. odi.osdname = (u8 *)deviceaddr->oda_osdname.data;
  102. if (!odi.osdname_len && !odi.systemid_len) {
  103. dprintk("%s: !odi.osdname_len && !odi.systemid_len\n",
  104. __func__);
  105. err = -ENODEV;
  106. goto out;
  107. }
  108. retry_lookup:
  109. od = osduld_info_lookup(&odi);
  110. if (IS_ERR(od)) {
  111. err = PTR_ERR(od);
  112. dprintk("%s: osduld_info_lookup => %d\n", __func__, err);
  113. if (err == -ENODEV && retry_flag) {
  114. err = objlayout_autologin(deviceaddr);
  115. if (likely(!err)) {
  116. retry_flag = false;
  117. goto retry_lookup;
  118. }
  119. }
  120. goto out;
  121. }
  122. dprintk("Adding new dev_id(%llx:%llx)\n",
  123. _DEVID_LO(&pdev->dev_id), _DEVID_HI(&pdev->dev_id));
  124. ode = kzalloc(sizeof(*ode), gfp_flags);
  125. if (!ode) {
  126. dprintk("%s: -ENOMEM od=%p\n", __func__, od);
  127. goto out;
  128. }
  129. nfs4_init_deviceid_node(&ode->id_node, server, &pdev->dev_id);
  130. kfree(deviceaddr);
  131. ode->od.od = od;
  132. return &ode->id_node;
  133. out:
  134. kfree(deviceaddr);
  135. return NULL;
  136. }
  137. static void copy_single_comp(struct ore_components *oc, unsigned c,
  138. struct pnfs_osd_object_cred *src_comp)
  139. {
  140. struct ore_comp *ocomp = &oc->comps[c];
  141. WARN_ON(src_comp->oc_cap_key.cred_len > 0); /* libosd is NO_SEC only */
  142. WARN_ON(src_comp->oc_cap.cred_len > sizeof(ocomp->cred));
  143. ocomp->obj.partition = src_comp->oc_object_id.oid_partition_id;
  144. ocomp->obj.id = src_comp->oc_object_id.oid_object_id;
  145. memcpy(ocomp->cred, src_comp->oc_cap.cred, sizeof(ocomp->cred));
  146. }
  147. static int __alloc_objio_seg(unsigned numdevs, gfp_t gfp_flags,
  148. struct objio_segment **pseg)
  149. {
  150. /* This is the in memory structure of the objio_segment
  151. *
  152. * struct __alloc_objio_segment {
  153. * struct objio_segment olseg;
  154. * struct ore_dev *ods[numdevs];
  155. * struct ore_comp comps[numdevs];
  156. * } *aolseg;
  157. * NOTE: The code as above compiles and runs perfectly. It is elegant,
  158. * type safe and compact. At some Past time Linus has decided he does not
  159. * like variable length arrays, For the sake of this principal we uglify
  160. * the code as below.
  161. */
  162. struct objio_segment *lseg;
  163. size_t lseg_size = sizeof(*lseg) +
  164. numdevs * sizeof(lseg->oc.ods[0]) +
  165. numdevs * sizeof(*lseg->oc.comps);
  166. lseg = kzalloc(lseg_size, gfp_flags);
  167. if (unlikely(!lseg)) {
  168. dprintk("%s: Failed allocation numdevs=%d size=%zd\n", __func__,
  169. numdevs, lseg_size);
  170. return -ENOMEM;
  171. }
  172. lseg->oc.numdevs = numdevs;
  173. lseg->oc.single_comp = EC_MULTPLE_COMPS;
  174. lseg->oc.ods = (void *)(lseg + 1);
  175. lseg->oc.comps = (void *)(lseg->oc.ods + numdevs);
  176. *pseg = lseg;
  177. return 0;
  178. }
  179. int objio_alloc_lseg(struct pnfs_layout_segment **outp,
  180. struct pnfs_layout_hdr *pnfslay,
  181. struct pnfs_layout_range *range,
  182. struct xdr_stream *xdr,
  183. gfp_t gfp_flags)
  184. {
  185. struct nfs_server *server = NFS_SERVER(pnfslay->plh_inode);
  186. struct objio_segment *objio_seg;
  187. struct pnfs_osd_xdr_decode_layout_iter iter;
  188. struct pnfs_osd_layout layout;
  189. struct pnfs_osd_object_cred src_comp;
  190. unsigned cur_comp;
  191. int err;
  192. err = pnfs_osd_xdr_decode_layout_map(&layout, &iter, xdr);
  193. if (unlikely(err))
  194. return err;
  195. err = __alloc_objio_seg(layout.olo_num_comps, gfp_flags, &objio_seg);
  196. if (unlikely(err))
  197. return err;
  198. objio_seg->layout.stripe_unit = layout.olo_map.odm_stripe_unit;
  199. objio_seg->layout.group_width = layout.olo_map.odm_group_width;
  200. objio_seg->layout.group_depth = layout.olo_map.odm_group_depth;
  201. objio_seg->layout.mirrors_p1 = layout.olo_map.odm_mirror_cnt + 1;
  202. objio_seg->layout.raid_algorithm = layout.olo_map.odm_raid_algorithm;
  203. err = ore_verify_layout(layout.olo_map.odm_num_comps,
  204. &objio_seg->layout);
  205. if (unlikely(err))
  206. goto err;
  207. objio_seg->oc.first_dev = layout.olo_comps_index;
  208. cur_comp = 0;
  209. while (pnfs_osd_xdr_decode_layout_comp(&src_comp, &iter, xdr, &err)) {
  210. struct nfs4_deviceid_node *d;
  211. struct objio_dev_ent *ode;
  212. copy_single_comp(&objio_seg->oc, cur_comp, &src_comp);
  213. d = nfs4_find_get_deviceid(server,
  214. &src_comp.oc_object_id.oid_device_id,
  215. pnfslay->plh_lc_cred, gfp_flags);
  216. if (!d) {
  217. err = -ENXIO;
  218. goto err;
  219. }
  220. ode = container_of(d, struct objio_dev_ent, id_node);
  221. objio_seg->oc.ods[cur_comp++] = &ode->od;
  222. }
  223. /* pnfs_osd_xdr_decode_layout_comp returns false on error */
  224. if (unlikely(err))
  225. goto err;
  226. *outp = &objio_seg->lseg;
  227. return 0;
  228. err:
  229. kfree(objio_seg);
  230. dprintk("%s: Error: return %d\n", __func__, err);
  231. *outp = NULL;
  232. return err;
  233. }
  234. void objio_free_lseg(struct pnfs_layout_segment *lseg)
  235. {
  236. int i;
  237. struct objio_segment *objio_seg = OBJIO_LSEG(lseg);
  238. for (i = 0; i < objio_seg->oc.numdevs; i++) {
  239. struct ore_dev *od = objio_seg->oc.ods[i];
  240. struct objio_dev_ent *ode;
  241. if (!od)
  242. break;
  243. ode = container_of(od, typeof(*ode), od);
  244. nfs4_put_deviceid_node(&ode->id_node);
  245. }
  246. kfree(objio_seg);
  247. }
  248. static int
  249. objio_alloc_io_state(struct pnfs_layout_hdr *pnfs_layout_type, bool is_reading,
  250. struct pnfs_layout_segment *lseg, struct page **pages, unsigned pgbase,
  251. loff_t offset, size_t count, void *rpcdata, gfp_t gfp_flags,
  252. struct objio_state **outp)
  253. {
  254. struct objio_segment *objio_seg = OBJIO_LSEG(lseg);
  255. struct ore_io_state *ios;
  256. int ret;
  257. struct __alloc_objio_state {
  258. struct objio_state objios;
  259. struct pnfs_osd_ioerr ioerrs[objio_seg->oc.numdevs];
  260. } *aos;
  261. aos = kzalloc(sizeof(*aos), gfp_flags);
  262. if (unlikely(!aos))
  263. return -ENOMEM;
  264. objlayout_init_ioerrs(&aos->objios.oir, objio_seg->oc.numdevs,
  265. aos->ioerrs, rpcdata, pnfs_layout_type);
  266. ret = ore_get_rw_state(&objio_seg->layout, &objio_seg->oc, is_reading,
  267. offset, count, &ios);
  268. if (unlikely(ret)) {
  269. kfree(aos);
  270. return ret;
  271. }
  272. ios->pages = pages;
  273. ios->pgbase = pgbase;
  274. ios->private = aos;
  275. BUG_ON(ios->nr_pages > (pgbase + count + PAGE_SIZE - 1) >> PAGE_SHIFT);
  276. aos->objios.sync = 0;
  277. aos->objios.ios = ios;
  278. *outp = &aos->objios;
  279. return 0;
  280. }
  281. void objio_free_result(struct objlayout_io_res *oir)
  282. {
  283. struct objio_state *objios = container_of(oir, struct objio_state, oir);
  284. ore_put_io_state(objios->ios);
  285. kfree(objios);
  286. }
  287. static enum pnfs_osd_errno osd_pri_2_pnfs_err(enum osd_err_priority oep)
  288. {
  289. switch (oep) {
  290. case OSD_ERR_PRI_NO_ERROR:
  291. return (enum pnfs_osd_errno)0;
  292. case OSD_ERR_PRI_CLEAR_PAGES:
  293. BUG_ON(1);
  294. return 0;
  295. case OSD_ERR_PRI_RESOURCE:
  296. return PNFS_OSD_ERR_RESOURCE;
  297. case OSD_ERR_PRI_BAD_CRED:
  298. return PNFS_OSD_ERR_BAD_CRED;
  299. case OSD_ERR_PRI_NO_ACCESS:
  300. return PNFS_OSD_ERR_NO_ACCESS;
  301. case OSD_ERR_PRI_UNREACHABLE:
  302. return PNFS_OSD_ERR_UNREACHABLE;
  303. case OSD_ERR_PRI_NOT_FOUND:
  304. return PNFS_OSD_ERR_NOT_FOUND;
  305. case OSD_ERR_PRI_NO_SPACE:
  306. return PNFS_OSD_ERR_NO_SPACE;
  307. default:
  308. WARN_ON(1);
  309. /* fallthrough */
  310. case OSD_ERR_PRI_EIO:
  311. return PNFS_OSD_ERR_EIO;
  312. }
  313. }
  314. static void __on_dev_error(struct ore_io_state *ios,
  315. struct ore_dev *od, unsigned dev_index, enum osd_err_priority oep,
  316. u64 dev_offset, u64 dev_len)
  317. {
  318. struct objio_state *objios = ios->private;
  319. struct pnfs_osd_objid pooid;
  320. struct objio_dev_ent *ode = container_of(od, typeof(*ode), od);
  321. /* FIXME: what to do with more-then-one-group layouts. We need to
  322. * translate from ore_io_state index to oc->comps index
  323. */
  324. unsigned comp = dev_index;
  325. pooid.oid_device_id = ode->id_node.deviceid;
  326. pooid.oid_partition_id = ios->oc->comps[comp].obj.partition;
  327. pooid.oid_object_id = ios->oc->comps[comp].obj.id;
  328. objlayout_io_set_result(&objios->oir, comp,
  329. &pooid, osd_pri_2_pnfs_err(oep),
  330. dev_offset, dev_len, !ios->reading);
  331. }
  332. /*
  333. * read
  334. */
  335. static void _read_done(struct ore_io_state *ios, void *private)
  336. {
  337. struct objio_state *objios = private;
  338. ssize_t status;
  339. int ret = ore_check_io(ios, &__on_dev_error);
  340. /* FIXME: _io_free(ios) can we dealocate the libosd resources; */
  341. if (likely(!ret))
  342. status = ios->length;
  343. else
  344. status = ret;
  345. objlayout_read_done(&objios->oir, status, objios->sync);
  346. }
  347. int objio_read_pagelist(struct nfs_pgio_header *hdr)
  348. {
  349. struct objio_state *objios;
  350. int ret;
  351. ret = objio_alloc_io_state(NFS_I(hdr->inode)->layout, true,
  352. hdr->lseg, hdr->args.pages, hdr->args.pgbase,
  353. hdr->args.offset, hdr->args.count, hdr,
  354. GFP_KERNEL, &objios);
  355. if (unlikely(ret))
  356. return ret;
  357. objios->ios->done = _read_done;
  358. dprintk("%s: offset=0x%llx length=0x%x\n", __func__,
  359. hdr->args.offset, hdr->args.count);
  360. ret = ore_read(objios->ios);
  361. if (unlikely(ret))
  362. objio_free_result(&objios->oir);
  363. return ret;
  364. }
  365. /*
  366. * write
  367. */
  368. static void _write_done(struct ore_io_state *ios, void *private)
  369. {
  370. struct objio_state *objios = private;
  371. ssize_t status;
  372. int ret = ore_check_io(ios, &__on_dev_error);
  373. /* FIXME: _io_free(ios) can we dealocate the libosd resources; */
  374. if (likely(!ret)) {
  375. /* FIXME: should be based on the OSD's persistence model
  376. * See OSD2r05 Section 4.13 Data persistence model */
  377. objios->oir.committed = NFS_FILE_SYNC;
  378. status = ios->length;
  379. } else {
  380. status = ret;
  381. }
  382. objlayout_write_done(&objios->oir, status, objios->sync);
  383. }
  384. static struct page *__r4w_get_page(void *priv, u64 offset, bool *uptodate)
  385. {
  386. struct objio_state *objios = priv;
  387. struct nfs_pgio_header *hdr = objios->oir.rpcdata;
  388. struct address_space *mapping = hdr->inode->i_mapping;
  389. pgoff_t index = offset / PAGE_SIZE;
  390. struct page *page;
  391. loff_t i_size = i_size_read(hdr->inode);
  392. if (offset >= i_size) {
  393. *uptodate = true;
  394. dprintk("%s: g_zero_page index=0x%lx\n", __func__, index);
  395. return ZERO_PAGE(0);
  396. }
  397. page = find_get_page(mapping, index);
  398. if (!page) {
  399. page = find_or_create_page(mapping, index, GFP_NOFS);
  400. if (unlikely(!page)) {
  401. dprintk("%s: grab_cache_page Failed index=0x%lx\n",
  402. __func__, index);
  403. return NULL;
  404. }
  405. unlock_page(page);
  406. }
  407. *uptodate = PageUptodate(page);
  408. dprintk("%s: index=0x%lx uptodate=%d\n", __func__, index, *uptodate);
  409. return page;
  410. }
  411. static void __r4w_put_page(void *priv, struct page *page)
  412. {
  413. dprintk("%s: index=0x%lx\n", __func__,
  414. (page == ZERO_PAGE(0)) ? -1UL : page->index);
  415. if (ZERO_PAGE(0) != page)
  416. page_cache_release(page);
  417. return;
  418. }
  419. static const struct _ore_r4w_op _r4w_op = {
  420. .get_page = &__r4w_get_page,
  421. .put_page = &__r4w_put_page,
  422. };
  423. int objio_write_pagelist(struct nfs_pgio_header *hdr, int how)
  424. {
  425. struct objio_state *objios;
  426. int ret;
  427. ret = objio_alloc_io_state(NFS_I(hdr->inode)->layout, false,
  428. hdr->lseg, hdr->args.pages, hdr->args.pgbase,
  429. hdr->args.offset, hdr->args.count, hdr, GFP_NOFS,
  430. &objios);
  431. if (unlikely(ret))
  432. return ret;
  433. objios->sync = 0 != (how & FLUSH_SYNC);
  434. objios->ios->r4w = &_r4w_op;
  435. if (!objios->sync)
  436. objios->ios->done = _write_done;
  437. dprintk("%s: offset=0x%llx length=0x%x\n", __func__,
  438. hdr->args.offset, hdr->args.count);
  439. ret = ore_write(objios->ios);
  440. if (unlikely(ret)) {
  441. objio_free_result(&objios->oir);
  442. return ret;
  443. }
  444. if (objios->sync)
  445. _write_done(objios->ios, objios);
  446. return 0;
  447. }
  448. /*
  449. * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number
  450. * of bytes (maximum @req->wb_bytes) that can be coalesced.
  451. */
  452. static size_t objio_pg_test(struct nfs_pageio_descriptor *pgio,
  453. struct nfs_page *prev, struct nfs_page *req)
  454. {
  455. struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(pgio);
  456. unsigned int size;
  457. size = pnfs_generic_pg_test(pgio, prev, req);
  458. if (!size || mirror->pg_count + req->wb_bytes >
  459. (unsigned long)pgio->pg_layout_private)
  460. return 0;
  461. return min(size, req->wb_bytes);
  462. }
  463. static void objio_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
  464. {
  465. pnfs_generic_pg_init_read(pgio, req);
  466. if (unlikely(pgio->pg_lseg == NULL))
  467. return; /* Not pNFS */
  468. pgio->pg_layout_private = (void *)
  469. OBJIO_LSEG(pgio->pg_lseg)->layout.max_io_length;
  470. }
  471. static bool aligned_on_raid_stripe(u64 offset, struct ore_layout *layout,
  472. unsigned long *stripe_end)
  473. {
  474. u32 stripe_off;
  475. unsigned stripe_size;
  476. if (layout->raid_algorithm == PNFS_OSD_RAID_0)
  477. return true;
  478. stripe_size = layout->stripe_unit *
  479. (layout->group_width - layout->parity);
  480. div_u64_rem(offset, stripe_size, &stripe_off);
  481. if (!stripe_off)
  482. return true;
  483. *stripe_end = stripe_size - stripe_off;
  484. return false;
  485. }
  486. static void objio_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
  487. {
  488. unsigned long stripe_end = 0;
  489. u64 wb_size;
  490. if (pgio->pg_dreq == NULL)
  491. wb_size = i_size_read(pgio->pg_inode) - req_offset(req);
  492. else
  493. wb_size = nfs_dreq_bytes_left(pgio->pg_dreq);
  494. pnfs_generic_pg_init_write(pgio, req, wb_size);
  495. if (unlikely(pgio->pg_lseg == NULL))
  496. return; /* Not pNFS */
  497. if (req->wb_offset ||
  498. !aligned_on_raid_stripe(req->wb_index * PAGE_SIZE,
  499. &OBJIO_LSEG(pgio->pg_lseg)->layout,
  500. &stripe_end)) {
  501. pgio->pg_layout_private = (void *)stripe_end;
  502. } else {
  503. pgio->pg_layout_private = (void *)
  504. OBJIO_LSEG(pgio->pg_lseg)->layout.max_io_length;
  505. }
  506. }
  507. static const struct nfs_pageio_ops objio_pg_read_ops = {
  508. .pg_init = objio_init_read,
  509. .pg_test = objio_pg_test,
  510. .pg_doio = pnfs_generic_pg_readpages,
  511. .pg_cleanup = pnfs_generic_pg_cleanup,
  512. };
  513. static const struct nfs_pageio_ops objio_pg_write_ops = {
  514. .pg_init = objio_init_write,
  515. .pg_test = objio_pg_test,
  516. .pg_doio = pnfs_generic_pg_writepages,
  517. .pg_cleanup = pnfs_generic_pg_cleanup,
  518. };
  519. static struct pnfs_layoutdriver_type objlayout_type = {
  520. .id = LAYOUT_OSD2_OBJECTS,
  521. .name = "LAYOUT_OSD2_OBJECTS",
  522. .flags = PNFS_LAYOUTRET_ON_SETATTR |
  523. PNFS_LAYOUTRET_ON_ERROR,
  524. .max_deviceinfo_size = PAGE_SIZE,
  525. .owner = THIS_MODULE,
  526. .alloc_layout_hdr = objlayout_alloc_layout_hdr,
  527. .free_layout_hdr = objlayout_free_layout_hdr,
  528. .alloc_lseg = objlayout_alloc_lseg,
  529. .free_lseg = objlayout_free_lseg,
  530. .read_pagelist = objlayout_read_pagelist,
  531. .write_pagelist = objlayout_write_pagelist,
  532. .pg_read_ops = &objio_pg_read_ops,
  533. .pg_write_ops = &objio_pg_write_ops,
  534. .sync = pnfs_generic_sync,
  535. .free_deviceid_node = objio_free_deviceid_node,
  536. .encode_layoutcommit = objlayout_encode_layoutcommit,
  537. .encode_layoutreturn = objlayout_encode_layoutreturn,
  538. };
  539. MODULE_DESCRIPTION("pNFS Layout Driver for OSD2 objects");
  540. MODULE_AUTHOR("Benny Halevy <bhalevy@panasas.com>");
  541. MODULE_LICENSE("GPL");
  542. static int __init
  543. objlayout_init(void)
  544. {
  545. int ret = pnfs_register_layoutdriver(&objlayout_type);
  546. if (ret)
  547. printk(KERN_INFO
  548. "NFS: %s: Registering OSD pNFS Layout Driver failed: error=%d\n",
  549. __func__, ret);
  550. else
  551. printk(KERN_INFO "NFS: %s: Registered OSD pNFS Layout Driver\n",
  552. __func__);
  553. return ret;
  554. }
  555. static void __exit
  556. objlayout_exit(void)
  557. {
  558. pnfs_unregister_layoutdriver(&objlayout_type);
  559. printk(KERN_INFO "NFS: %s: Unregistered OSD pNFS Layout Driver\n",
  560. __func__);
  561. }
  562. MODULE_ALIAS("nfs-layouttype4-2");
  563. module_init(objlayout_init);
  564. module_exit(objlayout_exit);