2 * Copyright (C) 2005, 2006
3 * Avishay Traeger (avishay@gmail.com)
4 * Copyright (C) 2008, 2009
5 * Boaz Harrosh <bharrosh@panasas.com>
7 * This file is part of exofs.
9 * exofs is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation. Since it is based on ext2, and the only
12 * valid version of GPL for the Linux kernel is version 2, the only valid
13 * version of GPL for exofs is version 2.
15 * exofs is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with exofs; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <linux/slab.h>
26 #include <asm/div64.h>
28 #include <scsi/osd_ore.h>
30 #define ORE_ERR(fmt, a...) printk(KERN_ERR "ore: " fmt, ##a)
32 #ifdef CONFIG_EXOFS_DEBUG
33 #define ORE_DBGMSG(fmt, a...) \
34 printk(KERN_NOTICE "ore @%s:%d: " fmt, __func__, __LINE__, ##a)
36 #define ORE_DBGMSG(fmt, a...) \
37 do { if (0) printk(fmt, ##a); } while (0)
40 /* u64 has problems with printk this will cast it to unsigned long long */
41 #define _LLU(x) (unsigned long long)(x)
43 #define ORE_DBGMSG2(M...) do {} while (0)
44 /* #define ORE_DBGMSG2 ORE_DBGMSG */
46 MODULE_AUTHOR("Boaz Harrosh <bharrosh@panasas.com>");
47 MODULE_DESCRIPTION("Objects Raid Engine ore.ko");
48 MODULE_LICENSE("GPL");
50 /* ore_verify_layout does a couple of things:
51 * 1. Given a minimum number of needed parameters fixes up the rest of the
52 * members to be operatonals for the ore. The needed parameters are those
53 * that are defined by the pnfs-objects layout STD.
54 * 2. Check to see if the current ore code actually supports these parameters
55 * for example stripe_unit must be a multple of the system PAGE_SIZE,
57 * 3. Cache some havily used calculations that will be needed by users.
60 enum { BIO_MAX_PAGES_KMALLOC =
61 (PAGE_SIZE - sizeof(struct bio)) / sizeof(struct bio_vec),};
63 int ore_verify_layout(unsigned total_comps, struct ore_layout *layout)
67 /* FIXME: Only raid0 is supported for now. */
68 if (layout->raid_algorithm != PNFS_OSD_RAID_0) {
69 ORE_ERR("Only RAID_0 for now\n");
72 if (0 != (layout->stripe_unit & ~PAGE_MASK)) {
73 ORE_ERR("Stripe Unit(0x%llx)"
74 " must be Multples of PAGE_SIZE(0x%lx)\n",
75 _LLU(layout->stripe_unit), PAGE_SIZE);
78 if (layout->group_width) {
79 if (!layout->group_depth) {
80 ORE_ERR("group_depth == 0 && group_width != 0\n");
83 if (total_comps < (layout->group_width * layout->mirrors_p1)) {
84 ORE_ERR("Data Map wrong, "
85 "numdevs=%d < group_width=%d * mirrors=%d\n",
86 total_comps, layout->group_width,
90 layout->group_count = total_comps / layout->mirrors_p1 /
93 if (layout->group_depth) {
94 printk(KERN_NOTICE "Warning: group_depth ignored "
95 "group_width == 0 && group_depth == %lld\n",
96 _LLU(layout->group_depth));
98 layout->group_width = total_comps / layout->mirrors_p1;
99 layout->group_depth = -1;
100 layout->group_count = 1;
103 stripe_length = (u64)layout->group_width * layout->stripe_unit;
104 if (stripe_length >= (1ULL << 32)) {
105 ORE_ERR("Stripe_length(0x%llx) >= 32bit is not supported\n",
106 _LLU(stripe_length));
110 layout->max_io_length =
111 (BIO_MAX_PAGES_KMALLOC * PAGE_SIZE - layout->stripe_unit) *
115 EXPORT_SYMBOL(ore_verify_layout);
117 static u8 *_ios_cred(struct ore_io_state *ios, unsigned index)
119 return ios->oc->comps[index & ios->oc->single_comp].cred;
122 static struct osd_obj_id *_ios_obj(struct ore_io_state *ios, unsigned index)
124 return &ios->oc->comps[index & ios->oc->single_comp].obj;
127 static struct osd_dev *_ios_od(struct ore_io_state *ios, unsigned index)
129 ORE_DBGMSG2("oc->first_dev=%d oc->numdevs=%d i=%d oc->ods=%p\n",
130 ios->oc->first_dev, ios->oc->numdevs, index,
133 return ore_comp_dev(ios->oc, index);
136 static int _get_io_state(struct ore_layout *layout,
137 struct ore_components *oc, unsigned numdevs,
138 struct ore_io_state **pios)
140 struct ore_io_state *ios;
142 /*TODO: Maybe use kmem_cach per sbi of size
143 * exofs_io_state_size(layout->s_numdevs)
145 ios = kzalloc(ore_io_state_size(numdevs), GFP_KERNEL);
146 if (unlikely(!ios)) {
147 ORE_DBGMSG("Failed kzalloc bytes=%d\n",
148 ore_io_state_size(numdevs));
153 ios->layout = layout;
159 /* Allocate an io_state for only a single group of devices
161 * If a user needs to call ore_read/write() this version must be used becase it
162 * allocates extra stuff for striping and raid.
163 * The ore might decide to only IO less then @length bytes do to alignmets
164 * and constrains as follows:
165 * - The IO cannot cross group boundary.
166 * - In raid5/6 The end of the IO must align at end of a stripe eg.
167 * (@offset + @length) % strip_size == 0. Or the complete range is within a
169 * - Memory condition only permitted a shorter IO. (A user can use @length=~0
170 * And check the returned ios->length for max_io_size.)
172 * The caller must check returned ios->length (and/or ios->nr_pages) and
173 * re-issue these pages that fall outside of ios->length
175 int ore_get_rw_state(struct ore_layout *layout, struct ore_components *oc,
176 bool is_reading, u64 offset, u64 length,
177 struct ore_io_state **pios)
179 struct ore_io_state *ios;
180 unsigned numdevs = layout->group_width * layout->mirrors_p1;
183 ret = _get_io_state(layout, oc, numdevs, pios);
188 ios->reading = is_reading;
189 ios->offset = offset;
192 ore_calc_stripe_info(layout, offset, &ios->si);
193 ios->length = (length <= ios->si.group_length) ? length :
194 ios->si.group_length;
195 ios->nr_pages = (ios->length + PAGE_SIZE - 1) / PAGE_SIZE;
200 EXPORT_SYMBOL(ore_get_rw_state);
202 /* Allocate an io_state for all the devices in the comps array
204 * This version of io_state allocation is used mostly by create/remove
205 * and trunc where we currently need all the devices. The only wastful
206 * bit is the read/write_attributes with no IO. Those sites should
207 * be converted to use ore_get_rw_state() with length=0
209 int ore_get_io_state(struct ore_layout *layout, struct ore_components *oc,
210 struct ore_io_state **pios)
212 return _get_io_state(layout, oc, oc->numdevs, pios);
214 EXPORT_SYMBOL(ore_get_io_state);
216 void ore_put_io_state(struct ore_io_state *ios)
221 for (i = 0; i < ios->numdevs; i++) {
222 struct ore_per_dev_state *per_dev = &ios->per_dev[i];
225 osd_end_request(per_dev->or);
227 bio_put(per_dev->bio);
233 EXPORT_SYMBOL(ore_put_io_state);
235 static void _sync_done(struct ore_io_state *ios, void *p)
237 struct completion *waiting = p;
242 static void _last_io(struct kref *kref)
244 struct ore_io_state *ios = container_of(
245 kref, struct ore_io_state, kref);
247 ios->done(ios, ios->private);
250 static void _done_io(struct osd_request *or, void *p)
252 struct ore_io_state *ios = p;
254 kref_put(&ios->kref, _last_io);
257 static int ore_io_execute(struct ore_io_state *ios)
259 DECLARE_COMPLETION_ONSTACK(wait);
260 bool sync = (ios->done == NULL);
264 ios->done = _sync_done;
265 ios->private = &wait;
268 for (i = 0; i < ios->numdevs; i++) {
269 struct osd_request *or = ios->per_dev[i].or;
273 ret = osd_finalize_request(or, 0, _ios_cred(ios, i), NULL);
275 ORE_DBGMSG("Failed to osd_finalize_request() => %d\n",
281 kref_init(&ios->kref);
283 for (i = 0; i < ios->numdevs; i++) {
284 struct osd_request *or = ios->per_dev[i].or;
288 kref_get(&ios->kref);
289 osd_execute_request_async(or, _done_io, ios);
292 kref_put(&ios->kref, _last_io);
296 wait_for_completion(&wait);
297 ret = ore_check_io(ios, NULL);
302 static void _clear_bio(struct bio *bio)
307 __bio_for_each_segment(bv, bio, i, 0) {
308 unsigned this_count = bv->bv_len;
310 if (likely(PAGE_SIZE == this_count))
311 clear_highpage(bv->bv_page);
313 zero_user(bv->bv_page, bv->bv_offset, this_count);
317 int ore_check_io(struct ore_io_state *ios, ore_on_dev_error on_dev_error)
319 enum osd_err_priority acumulated_osd_err = 0;
320 int acumulated_lin_err = 0;
323 for (i = 0; i < ios->numdevs; i++) {
324 struct osd_sense_info osi;
325 struct ore_per_dev_state *per_dev = &ios->per_dev[i];
326 struct osd_request *or = per_dev->or;
332 ret = osd_req_decode_sense(or, &osi);
336 if (OSD_ERR_PRI_CLEAR_PAGES == osi.osd_err_pri) {
337 /* start read offset passed endof file */
338 _clear_bio(per_dev->bio);
339 ORE_DBGMSG("start read offset passed end of file "
340 "offset=0x%llx, length=0x%llx\n",
341 _LLU(per_dev->offset),
342 _LLU(per_dev->length));
344 continue; /* we recovered */
348 u64 residual = ios->reading ?
349 or->in.residual : or->out.residual;
350 u64 offset = (ios->offset + ios->length) - residual;
351 struct ore_dev *od = ios->oc->ods[
352 per_dev->dev - ios->oc->first_dev];
354 on_dev_error(ios, od, per_dev->dev, osi.osd_err_pri,
357 if (osi.osd_err_pri >= acumulated_osd_err) {
358 acumulated_osd_err = osi.osd_err_pri;
359 acumulated_lin_err = ret;
363 return acumulated_lin_err;
365 EXPORT_SYMBOL(ore_check_io);
368 * L - logical offset into the file
370 * U - The number of bytes in a stripe within a group
372 * U = stripe_unit * group_width
374 * T - The number of bytes striped within a group of component objects
375 * (before advancing to the next group)
377 * T = stripe_unit * group_width * group_depth
379 * S - The number of bytes striped across all component objects
380 * before the pattern repeats
382 * S = stripe_unit * group_width * group_depth * group_count
384 * M - The "major" (i.e., across all components) stripe number
388 * G - Counts the groups from the beginning of the major stripe
390 * G = (L - (M * S)) / T [or (L % S) / T]
392 * H - The byte offset within the group
394 * H = (L - (M * S)) % T [or (L % S) % T]
396 * N - The "minor" (i.e., across the group) stripe number
400 * C - The component index coresponding to L
402 * C = (H - (N * U)) / stripe_unit + G * group_width
403 * [or (L % U) / stripe_unit + G * group_width]
405 * O - The component offset coresponding to L
407 * O = L % stripe_unit + N * stripe_unit + M * group_depth * stripe_unit
409 void ore_calc_stripe_info(struct ore_layout *layout, u64 file_offset,
410 struct ore_striping_info *si)
412 u32 stripe_unit = layout->stripe_unit;
413 u32 group_width = layout->group_width;
414 u64 group_depth = layout->group_depth;
416 u32 U = stripe_unit * group_width;
417 u64 T = U * group_depth;
418 u64 S = T * layout->group_count;
419 u64 M = div64_u64(file_offset, S);
422 G = (L - (M * S)) / T
423 H = (L - (M * S)) % T
425 u64 LmodS = file_offset - M * S;
426 u32 G = div64_u64(LmodS, T);
427 u64 H = LmodS - G * T;
429 u32 N = div_u64(H, U);
431 /* "H - (N * U)" is just "H % U" so it's bound to u32 */
432 si->dev = (u32)(H - (N * U)) / stripe_unit + G * group_width;
433 si->dev *= layout->mirrors_p1;
435 div_u64_rem(file_offset, stripe_unit, &si->unit_off);
437 si->obj_offset = si->unit_off + (N * stripe_unit) +
438 (M * group_depth * stripe_unit);
440 si->group_length = T - H;
443 EXPORT_SYMBOL(ore_calc_stripe_info);
445 static int _add_stripe_unit(struct ore_io_state *ios, unsigned *cur_pg,
446 unsigned pgbase, struct ore_per_dev_state *per_dev,
449 unsigned pg = *cur_pg;
450 struct request_queue *q =
451 osd_request_queue(_ios_od(ios, per_dev->dev));
452 unsigned len = cur_len;
455 if (per_dev->bio == NULL) {
456 unsigned pages_in_stripe = ios->layout->group_width *
457 (ios->layout->stripe_unit / PAGE_SIZE);
458 unsigned bio_size = (ios->nr_pages + pages_in_stripe) /
459 ios->layout->group_width;
461 per_dev->bio = bio_kmalloc(GFP_KERNEL, bio_size);
462 if (unlikely(!per_dev->bio)) {
463 ORE_DBGMSG("Failed to allocate BIO size=%u\n",
470 while (cur_len > 0) {
471 unsigned pglen = min_t(unsigned, PAGE_SIZE - pgbase, cur_len);
474 BUG_ON(ios->nr_pages <= pg);
477 added_len = bio_add_pc_page(q, per_dev->bio, ios->pages[pg],
479 if (unlikely(pglen != added_len)) {
488 per_dev->length += len;
491 out: /* we fail the complete unit on an error eg don't advance
492 * per_dev->length and cur_pg. This means that we might have a bigger
493 * bio than the CDB requested length (per_dev->length). That's fine
494 * only the oposite is fatal.
499 static int _prepare_for_striping(struct ore_io_state *ios)
501 struct ore_striping_info *si = &ios->si;
502 unsigned stripe_unit = ios->layout->stripe_unit;
503 unsigned mirrors_p1 = ios->layout->mirrors_p1;
504 unsigned devs_in_group = ios->layout->group_width * mirrors_p1;
505 unsigned dev = si->dev;
506 unsigned first_dev = dev - (dev % devs_in_group);
507 unsigned cur_pg = ios->pages_consumed;
508 u64 length = ios->length;
512 ios->numdevs = ios->layout->mirrors_p1;
516 BUG_ON(length > si->group_length);
519 unsigned comp = dev - first_dev;
520 struct ore_per_dev_state *per_dev = &ios->per_dev[comp];
521 unsigned cur_len, page_off = 0;
523 if (!per_dev->length) {
526 per_dev->offset = si->obj_offset + stripe_unit -
528 cur_len = stripe_unit;
529 } else if (dev == si->dev) {
530 per_dev->offset = si->obj_offset;
531 cur_len = stripe_unit - si->unit_off;
532 page_off = si->unit_off & ~PAGE_MASK;
533 BUG_ON(page_off && (page_off != ios->pgbase));
534 } else { /* dev > si->dev */
535 per_dev->offset = si->obj_offset - si->unit_off;
536 cur_len = stripe_unit;
539 cur_len = stripe_unit;
541 if (cur_len >= length)
544 ret = _add_stripe_unit(ios, &cur_pg, page_off , per_dev,
550 dev = (dev % devs_in_group) + first_dev;
555 ios->numdevs = devs_in_group;
556 ios->pages_consumed = cur_pg;
558 if (length == ios->length)
561 ios->length -= length;
566 int ore_create(struct ore_io_state *ios)
570 for (i = 0; i < ios->oc->numdevs; i++) {
571 struct osd_request *or;
573 or = osd_start_request(_ios_od(ios, i), GFP_KERNEL);
575 ORE_ERR("%s: osd_start_request failed\n", __func__);
579 ios->per_dev[i].or = or;
582 osd_req_create_object(or, _ios_obj(ios, i));
584 ret = ore_io_execute(ios);
589 EXPORT_SYMBOL(ore_create);
591 int ore_remove(struct ore_io_state *ios)
595 for (i = 0; i < ios->oc->numdevs; i++) {
596 struct osd_request *or;
598 or = osd_start_request(_ios_od(ios, i), GFP_KERNEL);
600 ORE_ERR("%s: osd_start_request failed\n", __func__);
604 ios->per_dev[i].or = or;
607 osd_req_remove_object(or, _ios_obj(ios, i));
609 ret = ore_io_execute(ios);
614 EXPORT_SYMBOL(ore_remove);
616 static int _write_mirror(struct ore_io_state *ios, int cur_comp)
618 struct ore_per_dev_state *master_dev = &ios->per_dev[cur_comp];
619 unsigned dev = ios->per_dev[cur_comp].dev;
620 unsigned last_comp = cur_comp + ios->layout->mirrors_p1;
623 if (ios->pages && !master_dev->length)
624 return 0; /* Just an empty slot */
626 for (; cur_comp < last_comp; ++cur_comp, ++dev) {
627 struct ore_per_dev_state *per_dev = &ios->per_dev[cur_comp];
628 struct osd_request *or;
630 or = osd_start_request(_ios_od(ios, dev), GFP_KERNEL);
632 ORE_ERR("%s: osd_start_request failed\n", __func__);
641 if (per_dev != master_dev) {
642 bio = bio_kmalloc(GFP_KERNEL,
643 master_dev->bio->bi_max_vecs);
644 if (unlikely(!bio)) {
646 "Failed to allocate BIO size=%u\n",
647 master_dev->bio->bi_max_vecs);
652 __bio_clone(bio, master_dev->bio);
655 per_dev->offset = master_dev->offset;
656 per_dev->length = master_dev->length;
660 bio = master_dev->bio;
661 /* FIXME: bio_set_dir() */
662 bio->bi_rw |= REQ_WRITE;
665 osd_req_write(or, _ios_obj(ios, dev), per_dev->offset,
666 bio, per_dev->length);
667 ORE_DBGMSG("write(0x%llx) offset=0x%llx "
668 "length=0x%llx dev=%d\n",
669 _LLU(_ios_obj(ios, dev)->id),
670 _LLU(per_dev->offset),
671 _LLU(per_dev->length), dev);
672 } else if (ios->kern_buff) {
673 per_dev->offset = ios->si.obj_offset;
674 per_dev->dev = ios->si.dev + dev;
676 /* no cross device without page array */
677 BUG_ON((ios->layout->group_width > 1) &&
678 (ios->si.unit_off + ios->length >
679 ios->layout->stripe_unit));
681 ret = osd_req_write_kern(or, _ios_obj(ios, per_dev->dev),
683 ios->kern_buff, ios->length);
686 ORE_DBGMSG2("write_kern(0x%llx) offset=0x%llx "
687 "length=0x%llx dev=%d\n",
688 _LLU(_ios_obj(ios, dev)->id),
689 _LLU(per_dev->offset),
690 _LLU(ios->length), per_dev->dev);
692 osd_req_set_attributes(or, _ios_obj(ios, dev));
693 ORE_DBGMSG2("obj(0x%llx) set_attributes=%d dev=%d\n",
694 _LLU(_ios_obj(ios, dev)->id),
695 ios->out_attr_len, dev);
699 osd_req_add_set_attr_list(or, ios->out_attr,
703 osd_req_add_get_attr_list(or, ios->in_attr,
711 int ore_write(struct ore_io_state *ios)
716 ret = _prepare_for_striping(ios);
720 for (i = 0; i < ios->numdevs; i += ios->layout->mirrors_p1) {
721 ret = _write_mirror(ios, i);
726 ret = ore_io_execute(ios);
729 EXPORT_SYMBOL(ore_write);
731 static int _read_mirror(struct ore_io_state *ios, unsigned cur_comp)
733 struct osd_request *or;
734 struct ore_per_dev_state *per_dev = &ios->per_dev[cur_comp];
735 struct osd_obj_id *obj = _ios_obj(ios, cur_comp);
736 unsigned first_dev = (unsigned)obj->id;
738 if (ios->pages && !per_dev->length)
739 return 0; /* Just an empty slot */
741 first_dev = per_dev->dev + first_dev % ios->layout->mirrors_p1;
742 or = osd_start_request(_ios_od(ios, first_dev), GFP_KERNEL);
744 ORE_ERR("%s: osd_start_request failed\n", __func__);
750 osd_req_read(or, obj, per_dev->offset,
751 per_dev->bio, per_dev->length);
752 ORE_DBGMSG("read(0x%llx) offset=0x%llx length=0x%llx"
753 " dev=%d\n", _LLU(obj->id),
754 _LLU(per_dev->offset), _LLU(per_dev->length),
757 BUG_ON(ios->kern_buff);
759 osd_req_get_attributes(or, obj);
760 ORE_DBGMSG2("obj(0x%llx) get_attributes=%d dev=%d\n",
762 ios->in_attr_len, first_dev);
765 osd_req_add_set_attr_list(or, ios->out_attr, ios->out_attr_len);
768 osd_req_add_get_attr_list(or, ios->in_attr, ios->in_attr_len);
773 int ore_read(struct ore_io_state *ios)
778 ret = _prepare_for_striping(ios);
782 for (i = 0; i < ios->numdevs; i += ios->layout->mirrors_p1) {
783 ret = _read_mirror(ios, i);
788 ret = ore_io_execute(ios);
791 EXPORT_SYMBOL(ore_read);
793 int extract_attr_from_ios(struct ore_io_state *ios, struct osd_attr *attr)
795 struct osd_attr cur_attr = {.attr_page = 0}; /* start with zeros */
801 osd_req_decode_get_attr_list(ios->per_dev[0].or,
802 &cur_attr, &nelem, &iter);
803 if ((cur_attr.attr_page == attr->attr_page) &&
804 (cur_attr.attr_id == attr->attr_id)) {
805 attr->len = cur_attr.len;
806 attr->val_ptr = cur_attr.val_ptr;
813 EXPORT_SYMBOL(extract_attr_from_ios);
815 static int _truncate_mirrors(struct ore_io_state *ios, unsigned cur_comp,
816 struct osd_attr *attr)
818 int last_comp = cur_comp + ios->layout->mirrors_p1;
820 for (; cur_comp < last_comp; ++cur_comp) {
821 struct ore_per_dev_state *per_dev = &ios->per_dev[cur_comp];
822 struct osd_request *or;
824 or = osd_start_request(_ios_od(ios, cur_comp), GFP_KERNEL);
826 ORE_ERR("%s: osd_start_request failed\n", __func__);
831 osd_req_set_attributes(or, _ios_obj(ios, cur_comp));
832 osd_req_add_set_attr_list(or, attr, 1);
839 struct ore_striping_info si;
840 u64 prev_group_obj_off;
841 u64 next_group_obj_off;
843 unsigned first_group_dev;
844 unsigned nex_group_dev;
847 static void _calc_trunk_info(struct ore_layout *layout, u64 file_offset,
848 struct _trunc_info *ti)
850 unsigned stripe_unit = layout->stripe_unit;
852 ore_calc_stripe_info(layout, file_offset, &ti->si);
854 ti->prev_group_obj_off = ti->si.M * stripe_unit;
855 ti->next_group_obj_off = ti->si.M ? (ti->si.M - 1) * stripe_unit : 0;
857 ti->first_group_dev = ti->si.dev - (ti->si.dev % layout->group_width);
858 ti->nex_group_dev = ti->first_group_dev + layout->group_width;
861 int ore_truncate(struct ore_layout *layout, struct ore_components *oc,
864 struct ore_io_state *ios;
865 struct exofs_trunc_attr {
866 struct osd_attr attr;
869 struct _trunc_info ti;
872 ret = ore_get_io_state(layout, oc, &ios);
876 _calc_trunk_info(ios->layout, size, &ti);
878 size_attrs = kcalloc(ios->oc->numdevs, sizeof(*size_attrs),
880 if (unlikely(!size_attrs)) {
885 ios->numdevs = ios->oc->numdevs;
887 for (i = 0; i < ios->numdevs; ++i) {
888 struct exofs_trunc_attr *size_attr = &size_attrs[i];
891 if (i < ti.first_group_dev)
892 obj_size = ti.prev_group_obj_off;
893 else if (i >= ti.nex_group_dev)
894 obj_size = ti.next_group_obj_off;
895 else if (i < ti.si.dev) /* dev within this group */
896 obj_size = ti.si.obj_offset +
897 ios->layout->stripe_unit - ti.si.unit_off;
898 else if (i == ti.si.dev)
899 obj_size = ti.si.obj_offset;
900 else /* i > ti.dev */
901 obj_size = ti.si.obj_offset - ti.si.unit_off;
903 size_attr->newsize = cpu_to_be64(obj_size);
904 size_attr->attr = g_attr_logical_length;
905 size_attr->attr.val_ptr = &size_attr->newsize;
907 ORE_DBGMSG("trunc(0x%llx) obj_offset=0x%llx dev=%d\n",
908 _LLU(oc->comps->obj.id), _LLU(obj_size), i);
909 ret = _truncate_mirrors(ios, i * ios->layout->mirrors_p1,
914 ret = ore_io_execute(ios);
918 ore_put_io_state(ios);
921 EXPORT_SYMBOL(ore_truncate);
923 const struct osd_attr g_attr_logical_length = ATTR_DEF(
924 OSD_APAGE_OBJECT_INFORMATION, OSD_ATTR_OI_LOGICAL_LENGTH, 8);
925 EXPORT_SYMBOL(g_attr_logical_length);