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_ore.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.od);
64 osduld_put_device(de->od.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.od);
107 objio_free_deviceid_node(&de->id_node);
114 struct objio_segment {
115 struct pnfs_layout_segment lseg;
117 struct ore_layout layout;
118 struct ore_components oc;
121 static inline struct objio_segment *
122 OBJIO_LSEG(struct pnfs_layout_segment *lseg)
124 return container_of(lseg, struct objio_segment, lseg);
128 typedef int (*objio_done_fn)(struct objio_state *ios);
132 struct objlayout_io_res oir;
141 struct ore_layout *layout;
142 struct ore_components *oc;
148 unsigned long length;
149 unsigned numdevs; /* Actually used devs in this IO */
150 /* A per-device variable array of size numdevs */
151 struct _objio_per_comp {
153 struct osd_request *or;
154 unsigned long length;
160 /* Send and wait for a get_device_info of devices in the layout,
161 then look them up with the osd_initiator library */
162 static int objio_devices_lookup(struct pnfs_layout_hdr *pnfslay,
163 struct objio_segment *objio_seg, unsigned c, struct nfs4_deviceid *d_id,
166 struct pnfs_osd_deviceaddr *deviceaddr;
167 struct objio_dev_ent *ode;
169 struct osd_dev_info odi;
172 ode = _dev_list_find(NFS_SERVER(pnfslay->plh_inode), d_id);
174 objio_seg->oc.ods[c] = &ode->od; /* must use container_of */
178 err = objlayout_get_deviceinfo(pnfslay, d_id, &deviceaddr, gfp_flags);
180 dprintk("%s: objlayout_get_deviceinfo dev(%llx:%llx) =>%d\n",
181 __func__, _DEVID_LO(d_id), _DEVID_HI(d_id), err);
185 odi.systemid_len = deviceaddr->oda_systemid.len;
186 if (odi.systemid_len > sizeof(odi.systemid)) {
187 dprintk("%s: odi.systemid_len > sizeof(systemid=%zd)\n",
188 __func__, sizeof(odi.systemid));
191 } else if (odi.systemid_len)
192 memcpy(odi.systemid, deviceaddr->oda_systemid.data,
194 odi.osdname_len = deviceaddr->oda_osdname.len;
195 odi.osdname = (u8 *)deviceaddr->oda_osdname.data;
197 if (!odi.osdname_len && !odi.systemid_len) {
198 dprintk("%s: !odi.osdname_len && !odi.systemid_len\n",
204 od = osduld_info_lookup(&odi);
205 if (unlikely(IS_ERR(od))) {
207 dprintk("%s: osduld_info_lookup => %d\n", __func__, err);
211 ode = _dev_list_add(NFS_SERVER(pnfslay->plh_inode), d_id, od,
213 objio_seg->oc.ods[c] = &ode->od; /* must use container_of */
214 dprintk("Adding new dev_id(%llx:%llx)\n",
215 _DEVID_LO(d_id), _DEVID_HI(d_id));
217 objlayout_put_deviceinfo(deviceaddr);
222 static int _verify_data_map(struct pnfs_osd_layout *layout)
224 struct pnfs_osd_data_map *data_map = &layout->olo_map;
228 /* FIXME: Only raid0 for now. if not go through MDS */
229 if (data_map->odm_raid_algorithm != PNFS_OSD_RAID_0) {
230 printk(KERN_ERR "Only RAID_0 for now\n");
233 if (0 != (data_map->odm_num_comps % (data_map->odm_mirror_cnt + 1))) {
234 printk(KERN_ERR "Data Map wrong, num_comps=%u mirrors=%u\n",
235 data_map->odm_num_comps, data_map->odm_mirror_cnt);
239 if (data_map->odm_group_width)
240 group_width = data_map->odm_group_width;
242 group_width = data_map->odm_num_comps /
243 (data_map->odm_mirror_cnt + 1);
245 stripe_length = (u64)data_map->odm_stripe_unit * group_width;
246 if (stripe_length >= (1ULL << 32)) {
247 printk(KERN_ERR "Total Stripe length(0x%llx)"
248 " >= 32bit is not supported\n", _LLU(stripe_length));
252 if (0 != (data_map->odm_stripe_unit & ~PAGE_MASK)) {
253 printk(KERN_ERR "Stripe Unit(0x%llx)"
254 " must be Multples of PAGE_SIZE(0x%lx)\n",
255 _LLU(data_map->odm_stripe_unit), PAGE_SIZE);
263 static void copy_single_comp(struct ore_components *oc, unsigned c,
264 struct pnfs_osd_object_cred *src_comp)
266 struct ore_comp *ocomp = &oc->comps[c];
268 WARN_ON(src_comp->oc_cap_key.cred_len > 0); /* libosd is NO_SEC only */
269 WARN_ON(src_comp->oc_cap.cred_len > sizeof(ocomp->cred));
271 ocomp->obj.partition = src_comp->oc_object_id.oid_partition_id;
272 ocomp->obj.id = src_comp->oc_object_id.oid_object_id;
274 memcpy(ocomp->cred, src_comp->oc_cap.cred, sizeof(ocomp->cred));
277 int __alloc_objio_seg(unsigned numdevs, gfp_t gfp_flags,
278 struct objio_segment **pseg)
280 struct __alloc_objio_segment {
281 struct objio_segment olseg;
282 struct ore_dev *ods[numdevs];
283 struct ore_comp comps[numdevs];
286 aolseg = kzalloc(sizeof(*aolseg), gfp_flags);
287 if (unlikely(!aolseg)) {
288 dprintk("%s: Faild allocation numdevs=%d size=%zd\n", __func__,
289 numdevs, sizeof(*aolseg));
293 aolseg->olseg.oc.numdevs = numdevs;
294 aolseg->olseg.oc.single_comp = EC_MULTPLE_COMPS;
295 aolseg->olseg.oc.comps = aolseg->comps;
296 aolseg->olseg.oc.ods = aolseg->ods;
298 *pseg = &aolseg->olseg;
302 int objio_alloc_lseg(struct pnfs_layout_segment **outp,
303 struct pnfs_layout_hdr *pnfslay,
304 struct pnfs_layout_range *range,
305 struct xdr_stream *xdr,
308 struct objio_segment *objio_seg;
309 struct pnfs_osd_xdr_decode_layout_iter iter;
310 struct pnfs_osd_layout layout;
311 struct pnfs_osd_object_cred src_comp;
315 err = pnfs_osd_xdr_decode_layout_map(&layout, &iter, xdr);
319 err = __alloc_objio_seg(layout.olo_num_comps, gfp_flags, &objio_seg);
323 objio_seg->layout.stripe_unit = layout.olo_map.odm_stripe_unit;
324 objio_seg->layout.group_width = layout.olo_map.odm_group_width;
325 objio_seg->layout.group_depth = layout.olo_map.odm_group_depth;
326 objio_seg->layout.mirrors_p1 = layout.olo_map.odm_mirror_cnt + 1;
327 objio_seg->layout.raid_algorithm = layout.olo_map.odm_raid_algorithm;
329 err = ore_verify_layout(layout.olo_map.odm_num_comps,
334 objio_seg->oc.first_dev = layout.olo_comps_index;
336 while (pnfs_osd_xdr_decode_layout_comp(&src_comp, &iter, xdr, &err)) {
337 copy_single_comp(&objio_seg->oc, cur_comp, &src_comp);
338 err = objio_devices_lookup(pnfslay, objio_seg, cur_comp,
339 &src_comp.oc_object_id.oid_device_id,
345 /* pnfs_osd_xdr_decode_layout_comp returns false on error */
349 *outp = &objio_seg->lseg;
354 dprintk("%s: Error: return %d\n", __func__, err);
359 void objio_free_lseg(struct pnfs_layout_segment *lseg)
362 struct objio_segment *objio_seg = OBJIO_LSEG(lseg);
364 for (i = 0; i < objio_seg->oc.numdevs; i++) {
365 struct ore_dev *od = objio_seg->oc.ods[i];
366 struct objio_dev_ent *ode;
370 ode = container_of(od, typeof(*ode), od);
371 nfs4_put_deviceid_node(&ode->id_node);
377 objio_alloc_io_state(struct pnfs_layout_hdr *pnfs_layout_type,
378 struct pnfs_layout_segment *lseg, struct page **pages, unsigned pgbase,
379 loff_t offset, size_t count, void *rpcdata, gfp_t gfp_flags,
380 struct objio_state **outp)
382 struct objio_segment *objio_seg = OBJIO_LSEG(lseg);
383 struct objio_state *ios;
384 struct __alloc_objio_state {
385 struct objio_state objios;
386 struct _objio_per_comp per_dev[objio_seg->oc.numdevs];
387 struct pnfs_osd_ioerr ioerrs[objio_seg->oc.numdevs];
390 aos = kzalloc(sizeof(*aos), gfp_flags);
396 ios->layout = &objio_seg->layout;
397 ios->oc = &objio_seg->oc;
398 objlayout_init_ioerrs(&aos->objios.oir, objio_seg->oc.numdevs,
399 aos->ioerrs, rpcdata, pnfs_layout_type);
402 ios->pgbase = pgbase;
403 ios->nr_pages = (pgbase + count + PAGE_SIZE - 1) >> PAGE_SHIFT;
404 ios->offset = offset;
407 BUG_ON(ios->nr_pages > (pgbase + count + PAGE_SIZE - 1) >> PAGE_SHIFT);
413 void objio_free_result(struct objlayout_io_res *oir)
415 struct objio_state *ios = container_of(oir, struct objio_state, oir);
420 enum pnfs_osd_errno osd_pri_2_pnfs_err(enum osd_err_priority oep)
423 case OSD_ERR_PRI_NO_ERROR:
424 return (enum pnfs_osd_errno)0;
426 case OSD_ERR_PRI_CLEAR_PAGES:
430 case OSD_ERR_PRI_RESOURCE:
431 return PNFS_OSD_ERR_RESOURCE;
432 case OSD_ERR_PRI_BAD_CRED:
433 return PNFS_OSD_ERR_BAD_CRED;
434 case OSD_ERR_PRI_NO_ACCESS:
435 return PNFS_OSD_ERR_NO_ACCESS;
436 case OSD_ERR_PRI_UNREACHABLE:
437 return PNFS_OSD_ERR_UNREACHABLE;
438 case OSD_ERR_PRI_NOT_FOUND:
439 return PNFS_OSD_ERR_NOT_FOUND;
440 case OSD_ERR_PRI_NO_SPACE:
441 return PNFS_OSD_ERR_NO_SPACE;
445 case OSD_ERR_PRI_EIO:
446 return PNFS_OSD_ERR_EIO;
450 static void __on_dev_error(struct objio_state *ios, bool is_write,
451 struct ore_dev *od, unsigned dev_index, enum osd_err_priority oep,
452 u64 dev_offset, u64 dev_len)
454 struct objio_state *objios = ios->private;
455 struct pnfs_osd_objid pooid;
456 struct objio_dev_ent *ode = container_of(od, typeof(*ode), od);
457 /* FIXME: what to do with more-then-one-group layouts. We need to
458 * translate from ore_io_state index to oc->comps index
460 unsigned comp = dev_index;
462 pooid.oid_device_id = ode->id_node.deviceid;
463 pooid.oid_partition_id = ios->oc->comps[comp].obj.partition;
464 pooid.oid_object_id = ios->oc->comps[comp].obj.id;
466 objlayout_io_set_result(&objios->oir, comp,
467 &pooid, osd_pri_2_pnfs_err(oep),
468 dev_offset, dev_len, is_write);
471 static void _clear_bio(struct bio *bio)
476 __bio_for_each_segment(bv, bio, i, 0) {
477 unsigned this_count = bv->bv_len;
479 if (likely(PAGE_SIZE == this_count))
480 clear_highpage(bv->bv_page);
482 zero_user(bv->bv_page, bv->bv_offset, this_count);
486 static int _io_check(struct objio_state *ios, bool is_write)
488 enum osd_err_priority oep = OSD_ERR_PRI_NO_ERROR;
492 for (i = 0; i < ios->numdevs; i++) {
493 struct osd_sense_info osi;
494 struct osd_request *or = ios->per_dev[i].or;
500 ret = osd_req_decode_sense(or, &osi);
504 if (OSD_ERR_PRI_CLEAR_PAGES == osi.osd_err_pri) {
505 /* start read offset passed endof file */
507 _clear_bio(ios->per_dev[i].bio);
508 dprintk("%s: start read offset passed end of file "
509 "offset=0x%llx, length=0x%lx\n", __func__,
510 _LLU(ios->per_dev[i].offset),
511 ios->per_dev[i].length);
513 continue; /* we recovered */
515 __on_dev_error(ios, is_write, ios->oc->ods[i],
516 ios->per_dev[i].dev, osi.osd_err_pri,
517 ios->per_dev[i].offset, ios->per_dev[i].length);
519 if (osi.osd_err_pri >= oep) {
520 oep = osi.osd_err_pri;
529 * Common IO state helpers.
531 static void _io_free(struct objio_state *ios)
535 for (i = 0; i < ios->numdevs; i++) {
536 struct _objio_per_comp *per_dev = &ios->per_dev[i];
539 osd_end_request(per_dev->or);
544 bio_put(per_dev->bio);
550 struct osd_dev *_io_od(struct objio_state *ios, unsigned dev)
552 unsigned min_dev = ios->oc->first_dev;
553 unsigned max_dev = min_dev + ios->oc->numdevs;
555 BUG_ON(dev < min_dev || max_dev <= dev);
556 return ios->oc->ods[dev - min_dev]->od;
559 struct _striping_info {
566 static void _calc_stripe_info(struct objio_state *ios, u64 file_offset,
567 struct _striping_info *si)
569 u32 stripe_unit = ios->layout->stripe_unit;
570 u32 group_width = ios->layout->group_width;
571 u64 group_depth = ios->layout->group_depth;
572 u32 U = stripe_unit * group_width;
574 u64 T = U * group_depth;
575 u64 S = T * ios->layout->group_count;
576 u64 M = div64_u64(file_offset, S);
579 G = (L - (M * S)) / T
580 H = (L - (M * S)) % T
582 u64 LmodU = file_offset - M * S;
583 u32 G = div64_u64(LmodU, T);
584 u64 H = LmodU - G * T;
586 u32 N = div_u64(H, U);
588 div_u64_rem(file_offset, stripe_unit, &si->unit_off);
589 si->obj_offset = si->unit_off + (N * stripe_unit) +
590 (M * group_depth * stripe_unit);
592 /* "H - (N * U)" is just "H % U" so it's bound to u32 */
593 si->dev = (u32)(H - (N * U)) / stripe_unit + G * group_width;
594 si->dev *= ios->layout->mirrors_p1;
596 si->group_length = T - H;
599 static int _add_stripe_unit(struct objio_state *ios, unsigned *cur_pg,
600 unsigned pgbase, struct _objio_per_comp *per_dev, int len,
603 unsigned pg = *cur_pg;
605 struct request_queue *q =
606 osd_request_queue(_io_od(ios, per_dev->dev));
608 if (per_dev->bio == NULL) {
609 unsigned pages_in_stripe = ios->layout->group_width *
610 (ios->layout->stripe_unit / PAGE_SIZE);
611 unsigned bio_size = (ios->nr_pages + pages_in_stripe) /
612 ios->layout->group_width;
614 if (BIO_MAX_PAGES_KMALLOC < bio_size)
615 bio_size = BIO_MAX_PAGES_KMALLOC;
617 per_dev->bio = bio_kmalloc(gfp_flags, bio_size);
618 if (unlikely(!per_dev->bio)) {
619 dprintk("Faild to allocate BIO size=%u\n", bio_size);
624 while (cur_len > 0) {
625 unsigned pglen = min_t(unsigned, PAGE_SIZE - pgbase, cur_len);
628 BUG_ON(ios->nr_pages <= pg);
631 added_len = bio_add_pc_page(q, per_dev->bio,
632 ios->pages[pg], pglen, pgbase);
633 if (unlikely(pglen != added_len))
640 per_dev->length += len;
645 static int _prepare_one_group(struct objio_state *ios, u64 length,
646 struct _striping_info *si, unsigned *last_pg,
649 unsigned stripe_unit = ios->layout->stripe_unit;
650 unsigned mirrors_p1 = ios->layout->mirrors_p1;
651 unsigned devs_in_group = ios->layout->group_width * mirrors_p1;
652 unsigned dev = si->dev;
653 unsigned first_dev = dev - (dev % devs_in_group);
654 unsigned max_comp = ios->numdevs ? ios->numdevs - mirrors_p1 : 0;
655 unsigned cur_pg = *last_pg;
659 struct _objio_per_comp *per_dev = &ios->per_dev[dev - first_dev];
660 unsigned cur_len, page_off = 0;
662 if (!per_dev->length) {
665 per_dev->offset = si->obj_offset + stripe_unit -
667 cur_len = stripe_unit;
668 } else if (dev == si->dev) {
669 per_dev->offset = si->obj_offset;
670 cur_len = stripe_unit - si->unit_off;
671 page_off = si->unit_off & ~PAGE_MASK;
673 (page_off != ios->pgbase));
674 } else { /* dev > si->dev */
675 per_dev->offset = si->obj_offset - si->unit_off;
676 cur_len = stripe_unit;
679 if (max_comp < dev - first_dev)
680 max_comp = dev - first_dev;
682 cur_len = stripe_unit;
684 if (cur_len >= length)
687 ret = _add_stripe_unit(ios, &cur_pg, page_off , per_dev,
693 dev = (dev % devs_in_group) + first_dev;
696 ios->length += cur_len;
699 ios->numdevs = max_comp + mirrors_p1;
704 static int _io_rw_pagelist(struct objio_state *ios, gfp_t gfp_flags)
706 u64 length = ios->count;
707 u64 offset = ios->offset;
708 struct _striping_info si;
709 unsigned last_pg = 0;
713 _calc_stripe_info(ios, offset, &si);
715 if (length < si.group_length)
716 si.group_length = length;
718 ret = _prepare_one_group(ios, si.group_length, &si, &last_pg, gfp_flags);
722 offset += si.group_length;
723 length -= si.group_length;
733 static int _sync_done(struct objio_state *ios)
735 struct completion *waiting = ios->private;
741 static void _last_io(struct kref *kref)
743 struct objio_state *ios = container_of(kref, struct objio_state, kref);
748 static void _done_io(struct osd_request *or, void *p)
750 struct objio_state *ios = p;
752 kref_put(&ios->kref, _last_io);
755 static int _io_exec(struct objio_state *ios)
757 DECLARE_COMPLETION_ONSTACK(wait);
760 objio_done_fn saved_done_fn = ios->done;
761 bool sync = ios->sync;
764 ios->done = _sync_done;
765 ios->private = &wait;
768 kref_init(&ios->kref);
770 for (i = 0; i < ios->numdevs; i++) {
771 struct osd_request *or = ios->per_dev[i].or;
776 kref_get(&ios->kref);
777 osd_execute_request_async(or, _done_io, ios);
780 kref_put(&ios->kref, _last_io);
783 wait_for_completion(&wait);
784 ret = saved_done_fn(ios);
793 static int _read_done(struct objio_state *ios)
796 int ret = _io_check(ios, false);
801 status = ios->length;
805 objlayout_read_done(&ios->oir, status, ios->sync);
809 static int _read_mirrors(struct objio_state *ios, unsigned cur_comp)
811 struct osd_request *or = NULL;
812 struct _objio_per_comp *per_dev = &ios->per_dev[cur_comp];
813 unsigned dev = per_dev->dev;
814 struct ore_comp *cred =
815 &ios->oc->comps[cur_comp];
816 struct osd_obj_id obj = cred->obj;
819 or = osd_start_request(_io_od(ios, dev), GFP_KERNEL);
826 osd_req_read(or, &obj, per_dev->offset, per_dev->bio, per_dev->length);
828 ret = osd_finalize_request(or, 0, cred->cred, NULL);
830 dprintk("%s: Faild to osd_finalize_request() => %d\n",
835 dprintk("%s:[%d] dev=%d obj=0x%llx start=0x%llx length=0x%lx\n",
836 __func__, cur_comp, dev, obj.id, _LLU(per_dev->offset),
843 static int _read_exec(struct objio_state *ios)
848 for (i = 0; i < ios->numdevs; i += ios->layout->mirrors_p1) {
849 if (!ios->per_dev[i].length)
851 ret = _read_mirrors(ios, i);
856 ios->done = _read_done;
857 return _io_exec(ios);
864 int objio_read_pagelist(struct nfs_read_data *rdata)
866 struct objio_state *ios;
869 ret = objio_alloc_io_state(NFS_I(rdata->inode)->layout,
870 rdata->lseg, rdata->args.pages, rdata->args.pgbase,
871 rdata->args.offset, rdata->args.count, rdata,
876 ret = _io_rw_pagelist(ios, GFP_KERNEL);
880 return _read_exec(ios);
886 static int _write_done(struct objio_state *ios)
889 int ret = _io_check(ios, true);
894 /* FIXME: should be based on the OSD's persistence model
895 * See OSD2r05 Section 4.13 Data persistence model */
896 ios->oir.committed = NFS_FILE_SYNC;
897 status = ios->length;
902 objlayout_write_done(&ios->oir, status, ios->sync);
906 static int _write_mirrors(struct objio_state *ios, unsigned cur_comp)
908 struct _objio_per_comp *master_dev = &ios->per_dev[cur_comp];
909 unsigned dev = ios->per_dev[cur_comp].dev;
910 unsigned last_comp = cur_comp + ios->layout->mirrors_p1;
913 for (; cur_comp < last_comp; ++cur_comp, ++dev) {
914 struct osd_request *or = NULL;
915 struct ore_comp *cred = &ios->oc->comps[cur_comp];
916 struct osd_obj_id obj = cred->obj;
917 struct _objio_per_comp *per_dev = &ios->per_dev[cur_comp];
920 or = osd_start_request(_io_od(ios, dev), GFP_NOFS);
927 if (per_dev != master_dev) {
928 bio = bio_kmalloc(GFP_NOFS,
929 master_dev->bio->bi_max_vecs);
930 if (unlikely(!bio)) {
931 dprintk("Faild to allocate BIO size=%u\n",
932 master_dev->bio->bi_max_vecs);
937 __bio_clone(bio, master_dev->bio);
942 per_dev->length = master_dev->length;
943 per_dev->offset = master_dev->offset;
945 bio = master_dev->bio;
946 bio->bi_rw |= REQ_WRITE;
949 osd_req_write(or, &obj, per_dev->offset, bio, per_dev->length);
951 ret = osd_finalize_request(or, 0, cred->cred, NULL);
953 dprintk("%s: Faild to osd_finalize_request() => %d\n",
958 dprintk("%s:[%d] dev=%d obj=0x%llx start=0x%llx length=0x%lx\n",
959 __func__, cur_comp, dev, obj.id, _LLU(per_dev->offset),
967 static int _write_exec(struct objio_state *ios)
972 for (i = 0; i < ios->numdevs; i += ios->layout->mirrors_p1) {
973 if (!ios->per_dev[i].length)
975 ret = _write_mirrors(ios, i);
980 ios->done = _write_done;
981 return _io_exec(ios);
988 int objio_write_pagelist(struct nfs_write_data *wdata, int how)
990 struct objio_state *ios;
993 ret = objio_alloc_io_state(NFS_I(wdata->inode)->layout,
994 wdata->lseg, wdata->args.pages, wdata->args.pgbase,
995 wdata->args.offset, wdata->args.count, wdata, GFP_NOFS,
1000 ios->sync = 0 != (how & FLUSH_SYNC);
1002 /* TODO: ios->stable = stable; */
1003 ret = _io_rw_pagelist(ios, GFP_NOFS);
1007 return _write_exec(ios);
1010 static bool objio_pg_test(struct nfs_pageio_descriptor *pgio,
1011 struct nfs_page *prev, struct nfs_page *req)
1013 if (!pnfs_generic_pg_test(pgio, prev, req))
1016 return pgio->pg_count + req->wb_bytes <=
1017 OBJIO_LSEG(pgio->pg_lseg)->layout.max_io_length;
1020 static const struct nfs_pageio_ops objio_pg_read_ops = {
1021 .pg_init = pnfs_generic_pg_init_read,
1022 .pg_test = objio_pg_test,
1023 .pg_doio = pnfs_generic_pg_readpages,
1026 static const struct nfs_pageio_ops objio_pg_write_ops = {
1027 .pg_init = pnfs_generic_pg_init_write,
1028 .pg_test = objio_pg_test,
1029 .pg_doio = pnfs_generic_pg_writepages,
1032 static struct pnfs_layoutdriver_type objlayout_type = {
1033 .id = LAYOUT_OSD2_OBJECTS,
1034 .name = "LAYOUT_OSD2_OBJECTS",
1035 .flags = PNFS_LAYOUTRET_ON_SETATTR,
1037 .alloc_layout_hdr = objlayout_alloc_layout_hdr,
1038 .free_layout_hdr = objlayout_free_layout_hdr,
1040 .alloc_lseg = objlayout_alloc_lseg,
1041 .free_lseg = objlayout_free_lseg,
1043 .read_pagelist = objlayout_read_pagelist,
1044 .write_pagelist = objlayout_write_pagelist,
1045 .pg_read_ops = &objio_pg_read_ops,
1046 .pg_write_ops = &objio_pg_write_ops,
1048 .free_deviceid_node = objio_free_deviceid_node,
1050 .encode_layoutcommit = objlayout_encode_layoutcommit,
1051 .encode_layoutreturn = objlayout_encode_layoutreturn,
1054 MODULE_DESCRIPTION("pNFS Layout Driver for OSD2 objects");
1055 MODULE_AUTHOR("Benny Halevy <bhalevy@panasas.com>");
1056 MODULE_LICENSE("GPL");
1059 objlayout_init(void)
1061 int ret = pnfs_register_layoutdriver(&objlayout_type);
1065 "%s: Registering OSD pNFS Layout Driver failed: error=%d\n",
1068 printk(KERN_INFO "%s: Registered OSD pNFS Layout Driver\n",
1074 objlayout_exit(void)
1076 pnfs_unregister_layoutdriver(&objlayout_type);
1077 printk(KERN_INFO "%s: Unregistered OSD pNFS Layout Driver\n",
1081 MODULE_ALIAS("nfs-layouttype4-2");
1083 module_init(objlayout_init);
1084 module_exit(objlayout_exit);