2 * pNFS Objects layout implementation over open-osd initiator library
4 * Copyright (C) 2009 Panasas Inc. [year of first publication]
7 * Benny Halevy <bhalevy@panasas.com>
8 * Boaz Harrosh <bharrosh@panasas.com>
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.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
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.
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.
40 #include <linux/module.h>
41 #include <scsi/osd_initiator.h>
43 #include "objlayout.h"
45 #define NFSDBG_FACILITY NFSDBG_PNFS_LD
47 #define _LLU(x) ((unsigned long long)x)
49 enum { BIO_MAX_PAGES_KMALLOC =
50 (PAGE_SIZE - sizeof(struct bio)) / sizeof(struct bio_vec),
53 struct objio_dev_ent {
54 struct nfs4_deviceid_node id_node;
59 objio_free_deviceid_node(struct nfs4_deviceid_node *d)
61 struct objio_dev_ent *de = container_of(d, struct objio_dev_ent, id_node);
63 dprintk("%s: free od=%p\n", __func__, de->od);
64 osduld_put_device(de->od);
68 static struct objio_dev_ent *_dev_list_find(const struct nfs_server *nfss,
69 const struct nfs4_deviceid *d_id)
71 struct nfs4_deviceid_node *d;
72 struct objio_dev_ent *de;
74 d = nfs4_find_get_deviceid(nfss->pnfs_curr_ld, nfss->nfs_client, d_id);
78 de = container_of(d, struct objio_dev_ent, id_node);
82 static struct objio_dev_ent *
83 _dev_list_add(const struct nfs_server *nfss,
84 const struct nfs4_deviceid *d_id, struct osd_dev *od,
87 struct nfs4_deviceid_node *d;
88 struct objio_dev_ent *de = kzalloc(sizeof(*de), gfp_flags);
89 struct objio_dev_ent *n;
92 dprintk("%s: -ENOMEM od=%p\n", __func__, od);
96 dprintk("%s: Adding od=%p\n", __func__, od);
97 nfs4_init_deviceid_node(&de->id_node,
103 d = nfs4_insert_deviceid_node(&de->id_node);
104 n = container_of(d, struct objio_dev_ent, id_node);
106 dprintk("%s: Race with other n->od=%p\n", __func__, n->od);
107 objio_free_deviceid_node(&de->id_node);
111 atomic_inc(&de->id_node.ref);
115 struct caps_buffers {
116 u8 caps_key[OSD_CRYPTO_KEYID_SIZE];
117 u8 creds[OSD_CAP_LEN];
120 struct objio_segment {
121 struct pnfs_layout_segment lseg;
123 struct pnfs_osd_object_cred *comps;
126 unsigned stripe_unit;
127 unsigned group_width; /* Data stripe_units without integrity comps */
129 unsigned group_count;
131 unsigned comps_index;
133 /* variable length */
134 struct objio_dev_ent *ods[];
137 static inline struct objio_segment *
138 OBJIO_LSEG(struct pnfs_layout_segment *lseg)
140 return container_of(lseg, struct objio_segment, lseg);
144 typedef ssize_t (*objio_done_fn)(struct objio_state *ios);
148 struct objlayout_io_state ol_state;
150 struct objio_segment *layout;
156 unsigned long length;
157 unsigned numdevs; /* Actually used devs in this IO */
158 /* A per-device variable array of size numdevs */
159 struct _objio_per_comp {
161 struct osd_request *or;
162 unsigned long length;
168 /* Send and wait for a get_device_info of devices in the layout,
169 then look them up with the osd_initiator library */
170 static struct objio_dev_ent *_device_lookup(struct pnfs_layout_hdr *pnfslay,
171 struct objio_segment *objio_seg, unsigned comp,
174 struct pnfs_osd_deviceaddr *deviceaddr;
175 struct nfs4_deviceid *d_id;
176 struct objio_dev_ent *ode;
178 struct osd_dev_info odi;
181 d_id = &objio_seg->comps[comp].oc_object_id.oid_device_id;
183 ode = _dev_list_find(NFS_SERVER(pnfslay->plh_inode), d_id);
187 err = objlayout_get_deviceinfo(pnfslay, d_id, &deviceaddr, gfp_flags);
189 dprintk("%s: objlayout_get_deviceinfo dev(%llx:%llx) =>%d\n",
190 __func__, _DEVID_LO(d_id), _DEVID_HI(d_id), err);
194 odi.systemid_len = deviceaddr->oda_systemid.len;
195 if (odi.systemid_len > sizeof(odi.systemid)) {
198 } else if (odi.systemid_len)
199 memcpy(odi.systemid, deviceaddr->oda_systemid.data,
201 odi.osdname_len = deviceaddr->oda_osdname.len;
202 odi.osdname = (u8 *)deviceaddr->oda_osdname.data;
204 if (!odi.osdname_len && !odi.systemid_len) {
205 dprintk("%s: !odi.osdname_len && !odi.systemid_len\n",
211 od = osduld_info_lookup(&odi);
212 if (unlikely(IS_ERR(od))) {
214 dprintk("%s: osduld_info_lookup => %d\n", __func__, err);
218 ode = _dev_list_add(NFS_SERVER(pnfslay->plh_inode), d_id, od,
222 dprintk("%s: return=%d\n", __func__, err);
223 objlayout_put_deviceinfo(deviceaddr);
224 return err ? ERR_PTR(err) : ode;
227 static int objio_devices_lookup(struct pnfs_layout_hdr *pnfslay,
228 struct objio_segment *objio_seg,
234 /* lookup all devices */
235 for (i = 0; i < objio_seg->num_comps; i++) {
236 struct objio_dev_ent *ode;
238 ode = _device_lookup(pnfslay, objio_seg, i, gfp_flags);
239 if (unlikely(IS_ERR(ode))) {
243 objio_seg->ods[i] = ode;
248 dprintk("%s: return=%d\n", __func__, err);
252 static int _verify_data_map(struct pnfs_osd_layout *layout)
254 struct pnfs_osd_data_map *data_map = &layout->olo_map;
258 /* FIXME: Only raid0 for now. if not go through MDS */
259 if (data_map->odm_raid_algorithm != PNFS_OSD_RAID_0) {
260 printk(KERN_ERR "Only RAID_0 for now\n");
263 if (0 != (data_map->odm_num_comps % (data_map->odm_mirror_cnt + 1))) {
264 printk(KERN_ERR "Data Map wrong, num_comps=%u mirrors=%u\n",
265 data_map->odm_num_comps, data_map->odm_mirror_cnt);
269 if (data_map->odm_group_width)
270 group_width = data_map->odm_group_width;
272 group_width = data_map->odm_num_comps /
273 (data_map->odm_mirror_cnt + 1);
275 stripe_length = (u64)data_map->odm_stripe_unit * group_width;
276 if (stripe_length >= (1ULL << 32)) {
277 printk(KERN_ERR "Total Stripe length(0x%llx)"
278 " >= 32bit is not supported\n", _LLU(stripe_length));
282 if (0 != (data_map->odm_stripe_unit & ~PAGE_MASK)) {
283 printk(KERN_ERR "Stripe Unit(0x%llx)"
284 " must be Multples of PAGE_SIZE(0x%lx)\n",
285 _LLU(data_map->odm_stripe_unit), PAGE_SIZE);
292 static void copy_single_comp(struct pnfs_osd_object_cred *cur_comp,
293 struct pnfs_osd_object_cred *src_comp,
294 struct caps_buffers *caps_p)
296 WARN_ON(src_comp->oc_cap_key.cred_len > sizeof(caps_p->caps_key));
297 WARN_ON(src_comp->oc_cap.cred_len > sizeof(caps_p->creds));
299 *cur_comp = *src_comp;
301 memcpy(caps_p->caps_key, src_comp->oc_cap_key.cred,
302 sizeof(caps_p->caps_key));
303 cur_comp->oc_cap_key.cred = caps_p->caps_key;
305 memcpy(caps_p->creds, src_comp->oc_cap.cred,
306 sizeof(caps_p->creds));
307 cur_comp->oc_cap.cred = caps_p->creds;
310 int objio_alloc_lseg(struct pnfs_layout_segment **outp,
311 struct pnfs_layout_hdr *pnfslay,
312 struct pnfs_layout_range *range,
313 struct xdr_stream *xdr,
316 struct objio_segment *objio_seg;
317 struct pnfs_osd_xdr_decode_layout_iter iter;
318 struct pnfs_osd_layout layout;
319 struct pnfs_osd_object_cred *cur_comp, src_comp;
320 struct caps_buffers *caps_p;
323 err = pnfs_osd_xdr_decode_layout_map(&layout, &iter, xdr);
327 err = _verify_data_map(&layout);
331 objio_seg = kzalloc(sizeof(*objio_seg) +
332 sizeof(objio_seg->ods[0]) * layout.olo_num_comps +
333 sizeof(*objio_seg->comps) * layout.olo_num_comps +
334 sizeof(struct caps_buffers) * layout.olo_num_comps,
339 objio_seg->comps = (void *)(objio_seg->ods + layout.olo_num_comps);
340 cur_comp = objio_seg->comps;
341 caps_p = (void *)(cur_comp + layout.olo_num_comps);
342 while (pnfs_osd_xdr_decode_layout_comp(&src_comp, &iter, xdr, &err))
343 copy_single_comp(cur_comp++, &src_comp, caps_p++);
347 objio_seg->num_comps = layout.olo_num_comps;
348 objio_seg->comps_index = layout.olo_comps_index;
349 err = objio_devices_lookup(pnfslay, objio_seg, gfp_flags);
353 objio_seg->mirrors_p1 = layout.olo_map.odm_mirror_cnt + 1;
354 objio_seg->stripe_unit = layout.olo_map.odm_stripe_unit;
355 if (layout.olo_map.odm_group_width) {
356 objio_seg->group_width = layout.olo_map.odm_group_width;
357 objio_seg->group_depth = layout.olo_map.odm_group_depth;
358 objio_seg->group_count = layout.olo_map.odm_num_comps /
359 objio_seg->mirrors_p1 /
360 objio_seg->group_width;
362 objio_seg->group_width = layout.olo_map.odm_num_comps /
363 objio_seg->mirrors_p1;
364 objio_seg->group_depth = -1;
365 objio_seg->group_count = 1;
368 *outp = &objio_seg->lseg;
373 dprintk("%s: Error: return %d\n", __func__, err);
378 void objio_free_lseg(struct pnfs_layout_segment *lseg)
381 struct objio_segment *objio_seg = OBJIO_LSEG(lseg);
383 for (i = 0; i < objio_seg->num_comps; i++) {
384 if (!objio_seg->ods[i])
386 nfs4_put_deviceid_node(&objio_seg->ods[i]->id_node);
391 int objio_alloc_io_state(struct pnfs_layout_segment *lseg,
392 struct objlayout_io_state **outp,
395 struct objio_segment *objio_seg = OBJIO_LSEG(lseg);
396 struct objio_state *ios;
397 const unsigned first_size = sizeof(*ios) +
398 objio_seg->num_comps * sizeof(ios->per_dev[0]);
399 const unsigned sec_size = objio_seg->num_comps *
400 sizeof(ios->ol_state.ioerrs[0]);
402 ios = kzalloc(first_size + sec_size, gfp_flags);
406 ios->layout = objio_seg;
407 ios->ol_state.ioerrs = ((void *)ios) + first_size;
408 ios->ol_state.num_comps = objio_seg->num_comps;
410 *outp = &ios->ol_state;
414 void objio_free_io_state(struct objlayout_io_state *ol_state)
416 struct objio_state *ios = container_of(ol_state, struct objio_state,
422 enum pnfs_osd_errno osd_pri_2_pnfs_err(enum osd_err_priority oep)
425 case OSD_ERR_PRI_NO_ERROR:
426 return (enum pnfs_osd_errno)0;
428 case OSD_ERR_PRI_CLEAR_PAGES:
432 case OSD_ERR_PRI_RESOURCE:
433 return PNFS_OSD_ERR_RESOURCE;
434 case OSD_ERR_PRI_BAD_CRED:
435 return PNFS_OSD_ERR_BAD_CRED;
436 case OSD_ERR_PRI_NO_ACCESS:
437 return PNFS_OSD_ERR_NO_ACCESS;
438 case OSD_ERR_PRI_UNREACHABLE:
439 return PNFS_OSD_ERR_UNREACHABLE;
440 case OSD_ERR_PRI_NOT_FOUND:
441 return PNFS_OSD_ERR_NOT_FOUND;
442 case OSD_ERR_PRI_NO_SPACE:
443 return PNFS_OSD_ERR_NO_SPACE;
447 case OSD_ERR_PRI_EIO:
448 return PNFS_OSD_ERR_EIO;
452 static void _clear_bio(struct bio *bio)
457 __bio_for_each_segment(bv, bio, i, 0) {
458 unsigned this_count = bv->bv_len;
460 if (likely(PAGE_SIZE == this_count))
461 clear_highpage(bv->bv_page);
463 zero_user(bv->bv_page, bv->bv_offset, this_count);
467 static int _io_check(struct objio_state *ios, bool is_write)
469 enum osd_err_priority oep = OSD_ERR_PRI_NO_ERROR;
473 for (i = 0; i < ios->numdevs; i++) {
474 struct osd_sense_info osi;
475 struct osd_request *or = ios->per_dev[i].or;
482 ret = osd_req_decode_sense(or, &osi);
486 if (OSD_ERR_PRI_CLEAR_PAGES == osi.osd_err_pri) {
487 /* start read offset passed endof file */
489 _clear_bio(ios->per_dev[i].bio);
490 dprintk("%s: start read offset passed end of file "
491 "offset=0x%llx, length=0x%lx\n", __func__,
492 _LLU(ios->per_dev[i].offset),
493 ios->per_dev[i].length);
495 continue; /* we recovered */
497 dev = ios->per_dev[i].dev;
498 objlayout_io_set_result(&ios->ol_state, dev,
499 &ios->layout->comps[dev].oc_object_id,
500 osd_pri_2_pnfs_err(osi.osd_err_pri),
501 ios->per_dev[i].offset,
502 ios->per_dev[i].length,
505 if (osi.osd_err_pri >= oep) {
506 oep = osi.osd_err_pri;
515 * Common IO state helpers.
517 static void _io_free(struct objio_state *ios)
521 for (i = 0; i < ios->numdevs; i++) {
522 struct _objio_per_comp *per_dev = &ios->per_dev[i];
525 osd_end_request(per_dev->or);
530 bio_put(per_dev->bio);
536 struct osd_dev *_io_od(struct objio_state *ios, unsigned dev)
538 unsigned min_dev = ios->layout->comps_index;
539 unsigned max_dev = min_dev + ios->layout->num_comps;
541 BUG_ON(dev < min_dev || max_dev <= dev);
542 return ios->layout->ods[dev - min_dev]->od;
545 struct _striping_info {
552 static void _calc_stripe_info(struct objio_state *ios, u64 file_offset,
553 struct _striping_info *si)
555 u32 stripe_unit = ios->layout->stripe_unit;
556 u32 group_width = ios->layout->group_width;
557 u64 group_depth = ios->layout->group_depth;
558 u32 U = stripe_unit * group_width;
560 u64 T = U * group_depth;
561 u64 S = T * ios->layout->group_count;
562 u64 M = div64_u64(file_offset, S);
565 G = (L - (M * S)) / T
566 H = (L - (M * S)) % T
568 u64 LmodU = file_offset - M * S;
569 u32 G = div64_u64(LmodU, T);
570 u64 H = LmodU - G * T;
572 u32 N = div_u64(H, U);
574 div_u64_rem(file_offset, stripe_unit, &si->unit_off);
575 si->obj_offset = si->unit_off + (N * stripe_unit) +
576 (M * group_depth * stripe_unit);
578 /* "H - (N * U)" is just "H % U" so it's bound to u32 */
579 si->dev = (u32)(H - (N * U)) / stripe_unit + G * group_width;
580 si->dev *= ios->layout->mirrors_p1;
582 si->group_length = T - H;
585 static int _add_stripe_unit(struct objio_state *ios, unsigned *cur_pg,
586 unsigned pgbase, struct _objio_per_comp *per_dev, int cur_len,
589 unsigned pg = *cur_pg;
590 struct request_queue *q =
591 osd_request_queue(_io_od(ios, per_dev->dev));
593 per_dev->length += cur_len;
595 if (per_dev->bio == NULL) {
596 unsigned stripes = ios->layout->num_comps /
597 ios->layout->mirrors_p1;
598 unsigned pages_in_stripe = stripes *
599 (ios->layout->stripe_unit / PAGE_SIZE);
600 unsigned bio_size = (ios->ol_state.nr_pages + pages_in_stripe) /
603 if (BIO_MAX_PAGES_KMALLOC < bio_size)
604 bio_size = BIO_MAX_PAGES_KMALLOC;
606 per_dev->bio = bio_kmalloc(gfp_flags, bio_size);
607 if (unlikely(!per_dev->bio)) {
608 dprintk("Faild to allocate BIO size=%u\n", bio_size);
613 while (cur_len > 0) {
614 unsigned pglen = min_t(unsigned, PAGE_SIZE - pgbase, cur_len);
617 BUG_ON(ios->ol_state.nr_pages <= pg);
620 added_len = bio_add_pc_page(q, per_dev->bio,
621 ios->ol_state.pages[pg], pglen, pgbase);
622 if (unlikely(pglen != added_len))
633 static int _prepare_one_group(struct objio_state *ios, u64 length,
634 struct _striping_info *si, unsigned *last_pg,
637 unsigned stripe_unit = ios->layout->stripe_unit;
638 unsigned mirrors_p1 = ios->layout->mirrors_p1;
639 unsigned devs_in_group = ios->layout->group_width * mirrors_p1;
640 unsigned dev = si->dev;
641 unsigned first_dev = dev - (dev % devs_in_group);
642 unsigned max_comp = ios->numdevs ? ios->numdevs - mirrors_p1 : 0;
643 unsigned cur_pg = *last_pg;
647 struct _objio_per_comp *per_dev = &ios->per_dev[dev];
648 unsigned cur_len, page_off = 0;
650 if (!per_dev->length) {
653 per_dev->offset = si->obj_offset + stripe_unit -
655 cur_len = stripe_unit;
656 } else if (dev == si->dev) {
657 per_dev->offset = si->obj_offset;
658 cur_len = stripe_unit - si->unit_off;
659 page_off = si->unit_off & ~PAGE_MASK;
661 (page_off != ios->ol_state.pgbase));
662 } else { /* dev > si->dev */
663 per_dev->offset = si->obj_offset - si->unit_off;
664 cur_len = stripe_unit;
670 cur_len = stripe_unit;
672 if (cur_len >= length)
675 ret = _add_stripe_unit(ios, &cur_pg, page_off , per_dev,
681 dev = (dev % devs_in_group) + first_dev;
684 ios->length += cur_len;
687 ios->numdevs = max_comp + mirrors_p1;
692 static int _io_rw_pagelist(struct objio_state *ios, gfp_t gfp_flags)
694 u64 length = ios->ol_state.count;
695 u64 offset = ios->ol_state.offset;
696 struct _striping_info si;
697 unsigned last_pg = 0;
701 _calc_stripe_info(ios, offset, &si);
703 if (length < si.group_length)
704 si.group_length = length;
706 ret = _prepare_one_group(ios, si.group_length, &si, &last_pg, gfp_flags);
710 offset += si.group_length;
711 length -= si.group_length;
721 static ssize_t _sync_done(struct objio_state *ios)
723 struct completion *waiting = ios->private;
729 static void _last_io(struct kref *kref)
731 struct objio_state *ios = container_of(kref, struct objio_state, kref);
736 static void _done_io(struct osd_request *or, void *p)
738 struct objio_state *ios = p;
740 kref_put(&ios->kref, _last_io);
743 static ssize_t _io_exec(struct objio_state *ios)
745 DECLARE_COMPLETION_ONSTACK(wait);
746 ssize_t status = 0; /* sync status */
748 objio_done_fn saved_done_fn = ios->done;
749 bool sync = ios->ol_state.sync;
752 ios->done = _sync_done;
753 ios->private = &wait;
756 kref_init(&ios->kref);
758 for (i = 0; i < ios->numdevs; i++) {
759 struct osd_request *or = ios->per_dev[i].or;
764 kref_get(&ios->kref);
765 osd_execute_request_async(or, _done_io, ios);
768 kref_put(&ios->kref, _last_io);
771 wait_for_completion(&wait);
772 status = saved_done_fn(ios);
781 static ssize_t _read_done(struct objio_state *ios)
784 int ret = _io_check(ios, false);
789 status = ios->length;
793 objlayout_read_done(&ios->ol_state, status, ios->ol_state.sync);
797 static int _read_mirrors(struct objio_state *ios, unsigned cur_comp)
799 struct osd_request *or = NULL;
800 struct _objio_per_comp *per_dev = &ios->per_dev[cur_comp];
801 unsigned dev = per_dev->dev;
802 struct pnfs_osd_object_cred *cred =
803 &ios->layout->comps[dev];
804 struct osd_obj_id obj = {
805 .partition = cred->oc_object_id.oid_partition_id,
806 .id = cred->oc_object_id.oid_object_id,
810 or = osd_start_request(_io_od(ios, dev), GFP_KERNEL);
817 osd_req_read(or, &obj, per_dev->offset, per_dev->bio, per_dev->length);
819 ret = osd_finalize_request(or, 0, cred->oc_cap.cred, NULL);
821 dprintk("%s: Faild to osd_finalize_request() => %d\n",
826 dprintk("%s:[%d] dev=%d obj=0x%llx start=0x%llx length=0x%lx\n",
827 __func__, cur_comp, dev, obj.id, _LLU(per_dev->offset),
834 static ssize_t _read_exec(struct objio_state *ios)
839 for (i = 0; i < ios->numdevs; i += ios->layout->mirrors_p1) {
840 if (!ios->per_dev[i].length)
842 ret = _read_mirrors(ios, i);
847 ios->done = _read_done;
848 return _io_exec(ios); /* In sync mode exec returns the io status */
855 ssize_t objio_read_pagelist(struct objlayout_io_state *ol_state)
857 struct objio_state *ios = container_of(ol_state, struct objio_state,
861 ret = _io_rw_pagelist(ios, GFP_KERNEL);
865 return _read_exec(ios);
871 static ssize_t _write_done(struct objio_state *ios)
874 int ret = _io_check(ios, true);
879 /* FIXME: should be based on the OSD's persistence model
880 * See OSD2r05 Section 4.13 Data persistence model */
881 ios->ol_state.committed = NFS_FILE_SYNC;
882 status = ios->length;
887 objlayout_write_done(&ios->ol_state, status, ios->ol_state.sync);
891 static int _write_mirrors(struct objio_state *ios, unsigned cur_comp)
893 struct _objio_per_comp *master_dev = &ios->per_dev[cur_comp];
894 unsigned dev = ios->per_dev[cur_comp].dev;
895 unsigned last_comp = cur_comp + ios->layout->mirrors_p1;
898 for (; cur_comp < last_comp; ++cur_comp, ++dev) {
899 struct osd_request *or = NULL;
900 struct pnfs_osd_object_cred *cred =
901 &ios->layout->comps[dev];
902 struct osd_obj_id obj = {
903 .partition = cred->oc_object_id.oid_partition_id,
904 .id = cred->oc_object_id.oid_object_id,
906 struct _objio_per_comp *per_dev = &ios->per_dev[cur_comp];
909 or = osd_start_request(_io_od(ios, dev), GFP_NOFS);
916 if (per_dev != master_dev) {
917 bio = bio_kmalloc(GFP_NOFS,
918 master_dev->bio->bi_max_vecs);
919 if (unlikely(!bio)) {
920 dprintk("Faild to allocate BIO size=%u\n",
921 master_dev->bio->bi_max_vecs);
926 __bio_clone(bio, master_dev->bio);
931 per_dev->length = master_dev->length;
932 per_dev->offset = master_dev->offset;
934 bio = master_dev->bio;
935 bio->bi_rw |= REQ_WRITE;
938 osd_req_write(or, &obj, per_dev->offset, bio, per_dev->length);
940 ret = osd_finalize_request(or, 0, cred->oc_cap.cred, NULL);
942 dprintk("%s: Faild to osd_finalize_request() => %d\n",
947 dprintk("%s:[%d] dev=%d obj=0x%llx start=0x%llx length=0x%lx\n",
948 __func__, cur_comp, dev, obj.id, _LLU(per_dev->offset),
956 static ssize_t _write_exec(struct objio_state *ios)
961 for (i = 0; i < ios->numdevs; i += ios->layout->mirrors_p1) {
962 if (!ios->per_dev[i].length)
964 ret = _write_mirrors(ios, i);
969 ios->done = _write_done;
970 return _io_exec(ios); /* In sync mode exec returns the io->status */
977 ssize_t objio_write_pagelist(struct objlayout_io_state *ol_state, bool stable)
979 struct objio_state *ios = container_of(ol_state, struct objio_state,
983 /* TODO: ios->stable = stable; */
984 ret = _io_rw_pagelist(ios, GFP_NOFS);
988 return _write_exec(ios);
991 static struct pnfs_layoutdriver_type objlayout_type = {
992 .id = LAYOUT_OSD2_OBJECTS,
993 .name = "LAYOUT_OSD2_OBJECTS",
994 .flags = PNFS_LAYOUTRET_ON_SETATTR,
996 .alloc_layout_hdr = objlayout_alloc_layout_hdr,
997 .free_layout_hdr = objlayout_free_layout_hdr,
999 .alloc_lseg = objlayout_alloc_lseg,
1000 .free_lseg = objlayout_free_lseg,
1002 .read_pagelist = objlayout_read_pagelist,
1003 .write_pagelist = objlayout_write_pagelist,
1004 .pg_test = pnfs_generic_pg_test,
1006 .free_deviceid_node = objio_free_deviceid_node,
1008 .encode_layoutcommit = objlayout_encode_layoutcommit,
1009 .encode_layoutreturn = objlayout_encode_layoutreturn,
1012 MODULE_DESCRIPTION("pNFS Layout Driver for OSD2 objects");
1013 MODULE_AUTHOR("Benny Halevy <bhalevy@panasas.com>");
1014 MODULE_LICENSE("GPL");
1017 objlayout_init(void)
1019 int ret = pnfs_register_layoutdriver(&objlayout_type);
1023 "%s: Registering OSD pNFS Layout Driver failed: error=%d\n",
1026 printk(KERN_INFO "%s: Registered OSD pNFS Layout Driver\n",
1032 objlayout_exit(void)
1034 pnfs_unregister_layoutdriver(&objlayout_type);
1035 printk(KERN_INFO "%s: Unregistered OSD pNFS Layout Driver\n",
1039 module_init(objlayout_init);
1040 module_exit(objlayout_exit);