objio_osd.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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 <bharrosh@panasas.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. #define NFSDBG_FACILITY NFSDBG_PNFS_LD
  43. struct objio_dev_ent {
  44. struct nfs4_deviceid_node id_node;
  45. struct ore_dev od;
  46. };
  47. static void
  48. objio_free_deviceid_node(struct nfs4_deviceid_node *d)
  49. {
  50. struct objio_dev_ent *de = container_of(d, struct objio_dev_ent, id_node);
  51. dprintk("%s: free od=%p\n", __func__, de->od.od);
  52. osduld_put_device(de->od.od);
  53. kfree(de);
  54. }
  55. static struct objio_dev_ent *_dev_list_find(const struct nfs_server *nfss,
  56. const struct nfs4_deviceid *d_id)
  57. {
  58. struct nfs4_deviceid_node *d;
  59. struct objio_dev_ent *de;
  60. d = nfs4_find_get_deviceid(nfss->pnfs_curr_ld, nfss->nfs_client, d_id);
  61. if (!d)
  62. return NULL;
  63. de = container_of(d, struct objio_dev_ent, id_node);
  64. return de;
  65. }
  66. static struct objio_dev_ent *
  67. _dev_list_add(const struct nfs_server *nfss,
  68. const struct nfs4_deviceid *d_id, struct osd_dev *od,
  69. gfp_t gfp_flags)
  70. {
  71. struct nfs4_deviceid_node *d;
  72. struct objio_dev_ent *de = kzalloc(sizeof(*de), gfp_flags);
  73. struct objio_dev_ent *n;
  74. if (!de) {
  75. dprintk("%s: -ENOMEM od=%p\n", __func__, od);
  76. return NULL;
  77. }
  78. dprintk("%s: Adding od=%p\n", __func__, od);
  79. nfs4_init_deviceid_node(&de->id_node,
  80. nfss->pnfs_curr_ld,
  81. nfss->nfs_client,
  82. d_id);
  83. de->od.od = od;
  84. d = nfs4_insert_deviceid_node(&de->id_node);
  85. n = container_of(d, struct objio_dev_ent, id_node);
  86. if (n != de) {
  87. dprintk("%s: Race with other n->od=%p\n", __func__, n->od.od);
  88. objio_free_deviceid_node(&de->id_node);
  89. de = n;
  90. }
  91. return de;
  92. }
  93. struct objio_segment {
  94. struct pnfs_layout_segment lseg;
  95. struct ore_layout layout;
  96. struct ore_components oc;
  97. };
  98. static inline struct objio_segment *
  99. OBJIO_LSEG(struct pnfs_layout_segment *lseg)
  100. {
  101. return container_of(lseg, struct objio_segment, lseg);
  102. }
  103. struct objio_state {
  104. /* Generic layer */
  105. struct objlayout_io_res oir;
  106. bool sync;
  107. /*FIXME: Support for extra_bytes at ore_get_rw_state() */
  108. struct ore_io_state *ios;
  109. };
  110. /* Send and wait for a get_device_info of devices in the layout,
  111. then look them up with the osd_initiator library */
  112. static int objio_devices_lookup(struct pnfs_layout_hdr *pnfslay,
  113. struct objio_segment *objio_seg, unsigned c, struct nfs4_deviceid *d_id,
  114. gfp_t gfp_flags)
  115. {
  116. struct pnfs_osd_deviceaddr *deviceaddr;
  117. struct objio_dev_ent *ode;
  118. struct osd_dev *od;
  119. struct osd_dev_info odi;
  120. bool retry_flag = true;
  121. int err;
  122. ode = _dev_list_find(NFS_SERVER(pnfslay->plh_inode), d_id);
  123. if (ode) {
  124. objio_seg->oc.ods[c] = &ode->od; /* must use container_of */
  125. return 0;
  126. }
  127. err = objlayout_get_deviceinfo(pnfslay, d_id, &deviceaddr, gfp_flags);
  128. if (unlikely(err)) {
  129. dprintk("%s: objlayout_get_deviceinfo dev(%llx:%llx) =>%d\n",
  130. __func__, _DEVID_LO(d_id), _DEVID_HI(d_id), err);
  131. return err;
  132. }
  133. odi.systemid_len = deviceaddr->oda_systemid.len;
  134. if (odi.systemid_len > sizeof(odi.systemid)) {
  135. dprintk("%s: odi.systemid_len > sizeof(systemid=%zd)\n",
  136. __func__, sizeof(odi.systemid));
  137. err = -EINVAL;
  138. goto out;
  139. } else if (odi.systemid_len)
  140. memcpy(odi.systemid, deviceaddr->oda_systemid.data,
  141. odi.systemid_len);
  142. odi.osdname_len = deviceaddr->oda_osdname.len;
  143. odi.osdname = (u8 *)deviceaddr->oda_osdname.data;
  144. if (!odi.osdname_len && !odi.systemid_len) {
  145. dprintk("%s: !odi.osdname_len && !odi.systemid_len\n",
  146. __func__);
  147. err = -ENODEV;
  148. goto out;
  149. }
  150. retry_lookup:
  151. od = osduld_info_lookup(&odi);
  152. if (unlikely(IS_ERR(od))) {
  153. err = PTR_ERR(od);
  154. dprintk("%s: osduld_info_lookup => %d\n", __func__, err);
  155. if (err == -ENODEV && retry_flag) {
  156. err = objlayout_autologin(deviceaddr);
  157. if (likely(!err)) {
  158. retry_flag = false;
  159. goto retry_lookup;
  160. }
  161. }
  162. goto out;
  163. }
  164. ode = _dev_list_add(NFS_SERVER(pnfslay->plh_inode), d_id, od,
  165. gfp_flags);
  166. objio_seg->oc.ods[c] = &ode->od; /* must use container_of */
  167. dprintk("Adding new dev_id(%llx:%llx)\n",
  168. _DEVID_LO(d_id), _DEVID_HI(d_id));
  169. out:
  170. objlayout_put_deviceinfo(deviceaddr);
  171. return err;
  172. }
  173. static void copy_single_comp(struct ore_components *oc, unsigned c,
  174. struct pnfs_osd_object_cred *src_comp)
  175. {
  176. struct ore_comp *ocomp = &oc->comps[c];
  177. WARN_ON(src_comp->oc_cap_key.cred_len > 0); /* libosd is NO_SEC only */
  178. WARN_ON(src_comp->oc_cap.cred_len > sizeof(ocomp->cred));
  179. ocomp->obj.partition = src_comp->oc_object_id.oid_partition_id;
  180. ocomp->obj.id = src_comp->oc_object_id.oid_object_id;
  181. memcpy(ocomp->cred, src_comp->oc_cap.cred, sizeof(ocomp->cred));
  182. }
  183. int __alloc_objio_seg(unsigned numdevs, gfp_t gfp_flags,
  184. struct objio_segment **pseg)
  185. {
  186. /* This is the in memory structure of the objio_segment
  187. *
  188. * struct __alloc_objio_segment {
  189. * struct objio_segment olseg;
  190. * struct ore_dev *ods[numdevs];
  191. * struct ore_comp comps[numdevs];
  192. * } *aolseg;
  193. * NOTE: The code as above compiles and runs perfectly. It is elegant,
  194. * type safe and compact. At some Past time Linus has decided he does not
  195. * like variable length arrays, For the sake of this principal we uglify
  196. * the code as below.
  197. */
  198. struct objio_segment *lseg;
  199. size_t lseg_size = sizeof(*lseg) +
  200. numdevs * sizeof(lseg->oc.ods[0]) +
  201. numdevs * sizeof(*lseg->oc.comps);
  202. lseg = kzalloc(lseg_size, gfp_flags);
  203. if (unlikely(!lseg)) {
  204. dprintk("%s: Faild allocation numdevs=%d size=%zd\n", __func__,
  205. numdevs, lseg_size);
  206. return -ENOMEM;
  207. }
  208. lseg->oc.numdevs = numdevs;
  209. lseg->oc.single_comp = EC_MULTPLE_COMPS;
  210. lseg->oc.ods = (void *)(lseg + 1);
  211. lseg->oc.comps = (void *)(lseg->oc.ods + numdevs);
  212. *pseg = lseg;
  213. return 0;
  214. }
  215. int objio_alloc_lseg(struct pnfs_layout_segment **outp,
  216. struct pnfs_layout_hdr *pnfslay,
  217. struct pnfs_layout_range *range,
  218. struct xdr_stream *xdr,
  219. gfp_t gfp_flags)
  220. {
  221. struct objio_segment *objio_seg;
  222. struct pnfs_osd_xdr_decode_layout_iter iter;
  223. struct pnfs_osd_layout layout;
  224. struct pnfs_osd_object_cred src_comp;
  225. unsigned cur_comp;
  226. int err;
  227. err = pnfs_osd_xdr_decode_layout_map(&layout, &iter, xdr);
  228. if (unlikely(err))
  229. return err;
  230. err = __alloc_objio_seg(layout.olo_num_comps, gfp_flags, &objio_seg);
  231. if (unlikely(err))
  232. return err;
  233. objio_seg->layout.stripe_unit = layout.olo_map.odm_stripe_unit;
  234. objio_seg->layout.group_width = layout.olo_map.odm_group_width;
  235. objio_seg->layout.group_depth = layout.olo_map.odm_group_depth;
  236. objio_seg->layout.mirrors_p1 = layout.olo_map.odm_mirror_cnt + 1;
  237. objio_seg->layout.raid_algorithm = layout.olo_map.odm_raid_algorithm;
  238. err = ore_verify_layout(layout.olo_map.odm_num_comps,
  239. &objio_seg->layout);
  240. if (unlikely(err))
  241. goto err;
  242. objio_seg->oc.first_dev = layout.olo_comps_index;
  243. cur_comp = 0;
  244. while (pnfs_osd_xdr_decode_layout_comp(&src_comp, &iter, xdr, &err)) {
  245. copy_single_comp(&objio_seg->oc, cur_comp, &src_comp);
  246. err = objio_devices_lookup(pnfslay, objio_seg, cur_comp,
  247. &src_comp.oc_object_id.oid_device_id,
  248. gfp_flags);
  249. if (err)
  250. goto err;
  251. ++cur_comp;
  252. }
  253. /* pnfs_osd_xdr_decode_layout_comp returns false on error */
  254. if (unlikely(err))
  255. goto err;
  256. *outp = &objio_seg->lseg;
  257. return 0;
  258. err:
  259. kfree(objio_seg);
  260. dprintk("%s: Error: return %d\n", __func__, err);
  261. *outp = NULL;
  262. return err;
  263. }
  264. void objio_free_lseg(struct pnfs_layout_segment *lseg)
  265. {
  266. int i;
  267. struct objio_segment *objio_seg = OBJIO_LSEG(lseg);
  268. for (i = 0; i < objio_seg->oc.numdevs; i++) {
  269. struct ore_dev *od = objio_seg->oc.ods[i];
  270. struct objio_dev_ent *ode;
  271. if (!od)
  272. break;
  273. ode = container_of(od, typeof(*ode), od);
  274. nfs4_put_deviceid_node(&ode->id_node);
  275. }
  276. kfree(objio_seg);
  277. }
  278. static int
  279. objio_alloc_io_state(struct pnfs_layout_hdr *pnfs_layout_type, bool is_reading,
  280. struct pnfs_layout_segment *lseg, struct page **pages, unsigned pgbase,
  281. loff_t offset, size_t count, void *rpcdata, gfp_t gfp_flags,
  282. struct objio_state **outp)
  283. {
  284. struct objio_segment *objio_seg = OBJIO_LSEG(lseg);
  285. struct ore_io_state *ios;
  286. int ret;
  287. struct __alloc_objio_state {
  288. struct objio_state objios;
  289. struct pnfs_osd_ioerr ioerrs[objio_seg->oc.numdevs];
  290. } *aos;
  291. aos = kzalloc(sizeof(*aos), gfp_flags);
  292. if (unlikely(!aos))
  293. return -ENOMEM;
  294. objlayout_init_ioerrs(&aos->objios.oir, objio_seg->oc.numdevs,
  295. aos->ioerrs, rpcdata, pnfs_layout_type);
  296. ret = ore_get_rw_state(&objio_seg->layout, &objio_seg->oc, is_reading,
  297. offset, count, &ios);
  298. if (unlikely(ret)) {
  299. kfree(aos);
  300. return ret;
  301. }
  302. ios->pages = pages;
  303. ios->pgbase = pgbase;
  304. ios->private = aos;
  305. BUG_ON(ios->nr_pages > (pgbase + count + PAGE_SIZE - 1) >> PAGE_SHIFT);
  306. aos->objios.sync = 0;
  307. aos->objios.ios = ios;
  308. *outp = &aos->objios;
  309. return 0;
  310. }
  311. void objio_free_result(struct objlayout_io_res *oir)
  312. {
  313. struct objio_state *objios = container_of(oir, struct objio_state, oir);
  314. ore_put_io_state(objios->ios);
  315. kfree(objios);
  316. }
  317. enum pnfs_osd_errno osd_pri_2_pnfs_err(enum osd_err_priority oep)
  318. {
  319. switch (oep) {
  320. case OSD_ERR_PRI_NO_ERROR:
  321. return (enum pnfs_osd_errno)0;
  322. case OSD_ERR_PRI_CLEAR_PAGES:
  323. BUG_ON(1);
  324. return 0;
  325. case OSD_ERR_PRI_RESOURCE:
  326. return PNFS_OSD_ERR_RESOURCE;
  327. case OSD_ERR_PRI_BAD_CRED:
  328. return PNFS_OSD_ERR_BAD_CRED;
  329. case OSD_ERR_PRI_NO_ACCESS:
  330. return PNFS_OSD_ERR_NO_ACCESS;
  331. case OSD_ERR_PRI_UNREACHABLE:
  332. return PNFS_OSD_ERR_UNREACHABLE;
  333. case OSD_ERR_PRI_NOT_FOUND:
  334. return PNFS_OSD_ERR_NOT_FOUND;
  335. case OSD_ERR_PRI_NO_SPACE:
  336. return PNFS_OSD_ERR_NO_SPACE;
  337. default:
  338. WARN_ON(1);
  339. /* fallthrough */
  340. case OSD_ERR_PRI_EIO:
  341. return PNFS_OSD_ERR_EIO;
  342. }
  343. }
  344. static void __on_dev_error(struct ore_io_state *ios,
  345. struct ore_dev *od, unsigned dev_index, enum osd_err_priority oep,
  346. u64 dev_offset, u64 dev_len)
  347. {
  348. struct objio_state *objios = ios->private;
  349. struct pnfs_osd_objid pooid;
  350. struct objio_dev_ent *ode = container_of(od, typeof(*ode), od);
  351. /* FIXME: what to do with more-then-one-group layouts. We need to
  352. * translate from ore_io_state index to oc->comps index
  353. */
  354. unsigned comp = dev_index;
  355. pooid.oid_device_id = ode->id_node.deviceid;
  356. pooid.oid_partition_id = ios->oc->comps[comp].obj.partition;
  357. pooid.oid_object_id = ios->oc->comps[comp].obj.id;
  358. objlayout_io_set_result(&objios->oir, comp,
  359. &pooid, osd_pri_2_pnfs_err(oep),
  360. dev_offset, dev_len, !ios->reading);
  361. }
  362. /*
  363. * read
  364. */
  365. static void _read_done(struct ore_io_state *ios, void *private)
  366. {
  367. struct objio_state *objios = private;
  368. ssize_t status;
  369. int ret = ore_check_io(ios, &__on_dev_error);
  370. /* FIXME: _io_free(ios) can we dealocate the libosd resources; */
  371. if (likely(!ret))
  372. status = ios->length;
  373. else
  374. status = ret;
  375. objlayout_read_done(&objios->oir, status, objios->sync);
  376. }
  377. int objio_read_pagelist(struct nfs_read_data *rdata)
  378. {
  379. struct objio_state *objios;
  380. int ret;
  381. ret = objio_alloc_io_state(NFS_I(rdata->inode)->layout, true,
  382. rdata->lseg, rdata->args.pages, rdata->args.pgbase,
  383. rdata->args.offset, rdata->args.count, rdata,
  384. GFP_KERNEL, &objios);
  385. if (unlikely(ret))
  386. return ret;
  387. objios->ios->done = _read_done;
  388. dprintk("%s: offset=0x%llx length=0x%x\n", __func__,
  389. rdata->args.offset, rdata->args.count);
  390. ret = ore_read(objios->ios);
  391. if (unlikely(ret))
  392. objio_free_result(&objios->oir);
  393. return ret;
  394. }
  395. /*
  396. * write
  397. */
  398. static void _write_done(struct ore_io_state *ios, void *private)
  399. {
  400. struct objio_state *objios = private;
  401. ssize_t status;
  402. int ret = ore_check_io(ios, &__on_dev_error);
  403. /* FIXME: _io_free(ios) can we dealocate the libosd resources; */
  404. if (likely(!ret)) {
  405. /* FIXME: should be based on the OSD's persistence model
  406. * See OSD2r05 Section 4.13 Data persistence model */
  407. objios->oir.committed = NFS_FILE_SYNC;
  408. status = ios->length;
  409. } else {
  410. status = ret;
  411. }
  412. objlayout_write_done(&objios->oir, status, objios->sync);
  413. }
  414. static struct page *__r4w_get_page(void *priv, u64 offset, bool *uptodate)
  415. {
  416. struct objio_state *objios = priv;
  417. struct nfs_write_data *wdata = objios->oir.rpcdata;
  418. pgoff_t index = offset / PAGE_SIZE;
  419. struct page *page;
  420. loff_t i_size = i_size_read(wdata->inode);
  421. if (offset >= i_size) {
  422. *uptodate = true;
  423. dprintk("%s: g_zero_page index=0x%lx\n", __func__, index);
  424. return ZERO_PAGE(0);
  425. }
  426. page = find_get_page(wdata->inode->i_mapping, index);
  427. if (!page) {
  428. page = find_or_create_page(wdata->inode->i_mapping,
  429. index, GFP_NOFS);
  430. if (unlikely(!page)) {
  431. dprintk("%s: grab_cache_page Failed index=0x%lx\n",
  432. __func__, index);
  433. return NULL;
  434. }
  435. unlock_page(page);
  436. }
  437. if (PageDirty(page) || PageWriteback(page))
  438. *uptodate = true;
  439. else
  440. *uptodate = PageUptodate(page);
  441. dprintk("%s: index=0x%lx uptodate=%d\n", __func__, index, *uptodate);
  442. return page;
  443. }
  444. static void __r4w_put_page(void *priv, struct page *page)
  445. {
  446. dprintk("%s: index=0x%lx\n", __func__,
  447. (page == ZERO_PAGE(0)) ? -1UL : page->index);
  448. if (ZERO_PAGE(0) != page)
  449. page_cache_release(page);
  450. return;
  451. }
  452. static const struct _ore_r4w_op _r4w_op = {
  453. .get_page = &__r4w_get_page,
  454. .put_page = &__r4w_put_page,
  455. };
  456. int objio_write_pagelist(struct nfs_write_data *wdata, int how)
  457. {
  458. struct objio_state *objios;
  459. int ret;
  460. ret = objio_alloc_io_state(NFS_I(wdata->inode)->layout, false,
  461. wdata->lseg, wdata->args.pages, wdata->args.pgbase,
  462. wdata->args.offset, wdata->args.count, wdata, GFP_NOFS,
  463. &objios);
  464. if (unlikely(ret))
  465. return ret;
  466. objios->sync = 0 != (how & FLUSH_SYNC);
  467. objios->ios->r4w = &_r4w_op;
  468. if (!objios->sync)
  469. objios->ios->done = _write_done;
  470. dprintk("%s: offset=0x%llx length=0x%x\n", __func__,
  471. wdata->args.offset, wdata->args.count);
  472. ret = ore_write(objios->ios);
  473. if (unlikely(ret)) {
  474. objio_free_result(&objios->oir);
  475. return ret;
  476. }
  477. if (objios->sync)
  478. _write_done(objios->ios, objios);
  479. return 0;
  480. }
  481. static bool objio_pg_test(struct nfs_pageio_descriptor *pgio,
  482. struct nfs_page *prev, struct nfs_page *req)
  483. {
  484. if (!pnfs_generic_pg_test(pgio, prev, req))
  485. return false;
  486. return pgio->pg_count + req->wb_bytes <=
  487. OBJIO_LSEG(pgio->pg_lseg)->layout.max_io_length;
  488. }
  489. static const struct nfs_pageio_ops objio_pg_read_ops = {
  490. .pg_init = pnfs_generic_pg_init_read,
  491. .pg_test = objio_pg_test,
  492. .pg_doio = pnfs_generic_pg_readpages,
  493. };
  494. static const struct nfs_pageio_ops objio_pg_write_ops = {
  495. .pg_init = pnfs_generic_pg_init_write,
  496. .pg_test = objio_pg_test,
  497. .pg_doio = pnfs_generic_pg_writepages,
  498. };
  499. static struct pnfs_layoutdriver_type objlayout_type = {
  500. .id = LAYOUT_OSD2_OBJECTS,
  501. .name = "LAYOUT_OSD2_OBJECTS",
  502. .flags = PNFS_LAYOUTRET_ON_SETATTR |
  503. PNFS_LAYOUTRET_ON_ERROR,
  504. .owner = THIS_MODULE,
  505. .alloc_layout_hdr = objlayout_alloc_layout_hdr,
  506. .free_layout_hdr = objlayout_free_layout_hdr,
  507. .alloc_lseg = objlayout_alloc_lseg,
  508. .free_lseg = objlayout_free_lseg,
  509. .read_pagelist = objlayout_read_pagelist,
  510. .write_pagelist = objlayout_write_pagelist,
  511. .pg_read_ops = &objio_pg_read_ops,
  512. .pg_write_ops = &objio_pg_write_ops,
  513. .free_deviceid_node = objio_free_deviceid_node,
  514. .encode_layoutcommit = objlayout_encode_layoutcommit,
  515. .encode_layoutreturn = objlayout_encode_layoutreturn,
  516. };
  517. MODULE_DESCRIPTION("pNFS Layout Driver for OSD2 objects");
  518. MODULE_AUTHOR("Benny Halevy <bhalevy@panasas.com>");
  519. MODULE_LICENSE("GPL");
  520. static int __init
  521. objlayout_init(void)
  522. {
  523. int ret = pnfs_register_layoutdriver(&objlayout_type);
  524. if (ret)
  525. printk(KERN_INFO
  526. "NFS: %s: Registering OSD pNFS Layout Driver failed: error=%d\n",
  527. __func__, ret);
  528. else
  529. printk(KERN_INFO "NFS: %s: Registered OSD pNFS Layout Driver\n",
  530. __func__);
  531. return ret;
  532. }
  533. static void __exit
  534. objlayout_exit(void)
  535. {
  536. pnfs_unregister_layoutdriver(&objlayout_type);
  537. printk(KERN_INFO "NFS: %s: Unregistered OSD pNFS Layout Driver\n",
  538. __func__);
  539. }
  540. MODULE_ALIAS("nfs-layouttype4-2");
  541. module_init(objlayout_init);
  542. module_exit(objlayout_exit);