blob: 3a000084cd2176cc763c66b01a03a6b8129097e4 [file] [log] [blame]
Boaz Harroshb14f8ab2008-10-27 18:27:55 +02001/*
2 * Copyright (C) 2005, 2006
Boaz Harrosh27d2e142009-06-14 17:23:09 +03003 * Avishay Traeger (avishay@gmail.com)
Boaz Harroshb14f8ab2008-10-27 18:27:55 +02004 * Copyright (C) 2008, 2009
5 * Boaz Harrosh <bharrosh@panasas.com>
6 *
7 * This file is part of exofs.
8 *
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.
14 *
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.
19 *
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
23 */
24
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Boaz Harrosh5d952b82010-02-01 13:35:51 +020026#include <asm/div64.h>
Boaz Harroshb14f8ab2008-10-27 18:27:55 +020027
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070028#include <scsi/osd_ore.h>
Boaz Harroshb14f8ab2008-10-27 18:27:55 +020029
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070030#define ORE_ERR(fmt, a...) printk(KERN_ERR "ore: " fmt, ##a)
Boaz Harrosh34ce4e7c2009-12-15 19:34:17 +020031
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070032#ifdef CONFIG_EXOFS_DEBUG
33#define ORE_DBGMSG(fmt, a...) \
34 printk(KERN_NOTICE "ore @%s:%d: " fmt, __func__, __LINE__, ##a)
35#else
36#define ORE_DBGMSG(fmt, a...) \
37 do { if (0) printk(fmt, ##a); } while (0)
38#endif
39
40/* u64 has problems with printk this will cast it to unsigned long long */
41#define _LLU(x) (unsigned long long)(x)
42
43#define ORE_DBGMSG2(M...) do {} while (0)
44/* #define ORE_DBGMSG2 ORE_DBGMSG */
45
46static u8 *_ios_cred(struct ore_io_state *ios, unsigned index)
Boaz Harrosh9e9db452011-08-05 15:06:04 -070047{
48 return ios->comps->comps[index & ios->comps->single_comp].cred;
49}
50
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070051static struct osd_obj_id *_ios_obj(struct ore_io_state *ios, unsigned index)
Boaz Harrosh9e9db452011-08-05 15:06:04 -070052{
53 return &ios->comps->comps[index & ios->comps->single_comp].obj;
54}
55
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070056static struct osd_dev *_ios_od(struct ore_io_state *ios, unsigned index)
Boaz Harrosh9e9db452011-08-05 15:06:04 -070057{
58 return ios->comps->ods[index];
59}
60
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070061int ore_get_rw_state(struct ore_layout *layout, struct ore_components *comps,
62 bool is_reading, u64 offset, u64 length,
63 struct ore_io_state **pios)
Boaz Harroshb14f8ab2008-10-27 18:27:55 +020064{
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070065 struct ore_io_state *ios;
Boaz Harroshb14f8ab2008-10-27 18:27:55 +020066
Boaz Harrosh06886a52009-11-08 14:54:08 +020067 /*TODO: Maybe use kmem_cach per sbi of size
Boaz Harrosh45d3abc2010-01-28 11:46:16 +020068 * exofs_io_state_size(layout->s_numdevs)
Boaz Harrosh06886a52009-11-08 14:54:08 +020069 */
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070070 ios = kzalloc(ore_io_state_size(comps->numdevs), GFP_KERNEL);
Boaz Harrosh06886a52009-11-08 14:54:08 +020071 if (unlikely(!ios)) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070072 ORE_DBGMSG("Failed kzalloc bytes=%d\n",
73 ore_io_state_size(comps->numdevs));
Boaz Harrosh06886a52009-11-08 14:54:08 +020074 *pios = NULL;
75 return -ENOMEM;
Boaz Harroshb14f8ab2008-10-27 18:27:55 +020076 }
77
Boaz Harrosh45d3abc2010-01-28 11:46:16 +020078 ios->layout = layout;
Boaz Harrosh9e9db452011-08-05 15:06:04 -070079 ios->comps = comps;
Boaz Harroshe1042ba2010-11-16 20:09:58 +020080 ios->offset = offset;
81 ios->length = length;
82 ios->reading = is_reading;
83
Boaz Harrosh06886a52009-11-08 14:54:08 +020084 *pios = ios;
85 return 0;
86}
Boaz Harroshb14f8ab2008-10-27 18:27:55 +020087
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070088int ore_get_io_state(struct ore_layout *layout, struct ore_components *comps,
89 struct ore_io_state **ios)
Boaz Harroshe1042ba2010-11-16 20:09:58 +020090{
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070091 return ore_get_rw_state(layout, comps, true, 0, 0, ios);
Boaz Harroshe1042ba2010-11-16 20:09:58 +020092}
93
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070094void ore_put_io_state(struct ore_io_state *ios)
Boaz Harrosh06886a52009-11-08 14:54:08 +020095{
96 if (ios) {
97 unsigned i;
98
99 for (i = 0; i < ios->numdevs; i++) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700100 struct ore_per_dev_state *per_dev = &ios->per_dev[i];
Boaz Harrosh06886a52009-11-08 14:54:08 +0200101
102 if (per_dev->or)
103 osd_end_request(per_dev->or);
104 if (per_dev->bio)
105 bio_put(per_dev->bio);
106 }
107
108 kfree(ios);
109 }
110}
111
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700112static void _sync_done(struct ore_io_state *ios, void *p)
Boaz Harrosh06886a52009-11-08 14:54:08 +0200113{
114 struct completion *waiting = p;
115
116 complete(waiting);
117}
118
119static void _last_io(struct kref *kref)
120{
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700121 struct ore_io_state *ios = container_of(
122 kref, struct ore_io_state, kref);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200123
124 ios->done(ios, ios->private);
125}
126
127static void _done_io(struct osd_request *or, void *p)
128{
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700129 struct ore_io_state *ios = p;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200130
131 kref_put(&ios->kref, _last_io);
132}
133
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700134static int ore_io_execute(struct ore_io_state *ios)
Boaz Harrosh06886a52009-11-08 14:54:08 +0200135{
136 DECLARE_COMPLETION_ONSTACK(wait);
137 bool sync = (ios->done == NULL);
138 int i, ret;
139
140 if (sync) {
141 ios->done = _sync_done;
142 ios->private = &wait;
143 }
144
145 for (i = 0; i < ios->numdevs; i++) {
146 struct osd_request *or = ios->per_dev[i].or;
147 if (unlikely(!or))
148 continue;
149
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700150 ret = osd_finalize_request(or, 0, _ios_cred(ios, i), NULL);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200151 if (unlikely(ret)) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700152 ORE_DBGMSG("Failed to osd_finalize_request() => %d\n",
Boaz Harrosh06886a52009-11-08 14:54:08 +0200153 ret);
154 return ret;
155 }
156 }
157
158 kref_init(&ios->kref);
159
160 for (i = 0; i < ios->numdevs; i++) {
161 struct osd_request *or = ios->per_dev[i].or;
162 if (unlikely(!or))
163 continue;
164
165 kref_get(&ios->kref);
166 osd_execute_request_async(or, _done_io, ios);
167 }
168
169 kref_put(&ios->kref, _last_io);
170 ret = 0;
171
172 if (sync) {
173 wait_for_completion(&wait);
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700174 ret = ore_check_io(ios, NULL);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200175 }
Boaz Harroshb14f8ab2008-10-27 18:27:55 +0200176 return ret;
177}
178
Boaz Harrosh22ddc552010-01-19 19:24:45 +0200179static void _clear_bio(struct bio *bio)
180{
181 struct bio_vec *bv;
182 unsigned i;
183
184 __bio_for_each_segment(bv, bio, i, 0) {
185 unsigned this_count = bv->bv_len;
186
187 if (likely(PAGE_SIZE == this_count))
188 clear_highpage(bv->bv_page);
189 else
190 zero_user(bv->bv_page, bv->bv_offset, this_count);
191 }
192}
193
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700194int ore_check_io(struct ore_io_state *ios, u64 *resid)
Boaz Harrosh06886a52009-11-08 14:54:08 +0200195{
196 enum osd_err_priority acumulated_osd_err = 0;
197 int acumulated_lin_err = 0;
198 int i;
199
200 for (i = 0; i < ios->numdevs; i++) {
201 struct osd_sense_info osi;
Boaz Harrosh22ddc552010-01-19 19:24:45 +0200202 struct osd_request *or = ios->per_dev[i].or;
203 int ret;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200204
Boaz Harrosh22ddc552010-01-19 19:24:45 +0200205 if (unlikely(!or))
206 continue;
207
208 ret = osd_req_decode_sense(or, &osi);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200209 if (likely(!ret))
210 continue;
211
Boaz Harrosh22ddc552010-01-19 19:24:45 +0200212 if (OSD_ERR_PRI_CLEAR_PAGES == osi.osd_err_pri) {
213 /* start read offset passed endof file */
214 _clear_bio(ios->per_dev[i].bio);
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700215 ORE_DBGMSG("start read offset passed end of file "
Boaz Harrosh22ddc552010-01-19 19:24:45 +0200216 "offset=0x%llx, length=0x%llx\n",
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200217 _LLU(ios->per_dev[i].offset),
218 _LLU(ios->per_dev[i].length));
Boaz Harrosh22ddc552010-01-19 19:24:45 +0200219
220 continue; /* we recovered */
Boaz Harrosh06886a52009-11-08 14:54:08 +0200221 }
222
223 if (osi.osd_err_pri >= acumulated_osd_err) {
224 acumulated_osd_err = osi.osd_err_pri;
225 acumulated_lin_err = ret;
226 }
227 }
228
229 /* TODO: raid specific residual calculations */
230 if (resid) {
231 if (likely(!acumulated_lin_err))
232 *resid = 0;
233 else
234 *resid = ios->length;
235 }
236
237 return acumulated_lin_err;
238}
239
Boaz Harroshb367e782010-02-07 19:18:58 +0200240/*
241 * L - logical offset into the file
242 *
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200243 * U - The number of bytes in a stripe within a group
Boaz Harroshb367e782010-02-07 19:18:58 +0200244 *
245 * U = stripe_unit * group_width
246 *
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200247 * T - The number of bytes striped within a group of component objects
248 * (before advancing to the next group)
Boaz Harroshb367e782010-02-07 19:18:58 +0200249 *
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200250 * T = stripe_unit * group_width * group_depth
251 *
252 * S - The number of bytes striped across all component objects
253 * before the pattern repeats
254 *
255 * S = stripe_unit * group_width * group_depth * group_count
256 *
257 * M - The "major" (i.e., across all components) stripe number
258 *
259 * M = L / S
260 *
261 * G - Counts the groups from the beginning of the major stripe
262 *
263 * G = (L - (M * S)) / T [or (L % S) / T]
264 *
265 * H - The byte offset within the group
266 *
267 * H = (L - (M * S)) % T [or (L % S) % T]
268 *
269 * N - The "minor" (i.e., across the group) stripe number
270 *
271 * N = H / U
Boaz Harroshb367e782010-02-07 19:18:58 +0200272 *
273 * C - The component index coresponding to L
274 *
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200275 * C = (H - (N * U)) / stripe_unit + G * group_width
276 * [or (L % U) / stripe_unit + G * group_width]
Boaz Harroshb367e782010-02-07 19:18:58 +0200277 *
278 * O - The component offset coresponding to L
279 *
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200280 * O = L % stripe_unit + N * stripe_unit + M * group_depth * stripe_unit
Boaz Harroshb367e782010-02-07 19:18:58 +0200281 */
Boaz Harroshb367e782010-02-07 19:18:58 +0200282struct _striping_info {
283 u64 obj_offset;
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200284 u64 group_length;
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700285 u64 M; /* for truncate */
Boaz Harroshb367e782010-02-07 19:18:58 +0200286 unsigned dev;
287 unsigned unit_off;
288};
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200289
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700290static void _calc_stripe_info(struct ore_layout *layout, u64 file_offset,
Boaz Harroshb367e782010-02-07 19:18:58 +0200291 struct _striping_info *si)
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200292{
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700293 u32 stripe_unit = layout->stripe_unit;
294 u32 group_width = layout->group_width;
295 u64 group_depth = layout->group_depth;
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200296
Boaz Harroshb367e782010-02-07 19:18:58 +0200297 u32 U = stripe_unit * group_width;
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200298 u64 T = U * group_depth;
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700299 u64 S = T * layout->group_count;
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200300 u64 M = div64_u64(file_offset, S);
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200301
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200302 /*
303 G = (L - (M * S)) / T
304 H = (L - (M * S)) % T
305 */
306 u64 LmodS = file_offset - M * S;
307 u32 G = div64_u64(LmodS, T);
308 u64 H = LmodS - G * T;
Boaz Harroshb367e782010-02-07 19:18:58 +0200309
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200310 u32 N = div_u64(H, U);
311
312 /* "H - (N * U)" is just "H % U" so it's bound to u32 */
313 si->dev = (u32)(H - (N * U)) / stripe_unit + G * group_width;
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700314 si->dev *= layout->mirrors_p1;
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200315
316 div_u64_rem(file_offset, stripe_unit, &si->unit_off);
317
318 si->obj_offset = si->unit_off + (N * stripe_unit) +
319 (M * group_depth * stripe_unit);
320
321 si->group_length = T - H;
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700322 si->M = M;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200323}
324
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700325static int _add_stripe_unit(struct ore_io_state *ios, unsigned *cur_pg,
326 unsigned pgbase, struct ore_per_dev_state *per_dev,
Boaz Harrosh86093aa2010-01-28 18:24:06 +0200327 int cur_len)
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200328{
Boaz Harrosh86093aa2010-01-28 18:24:06 +0200329 unsigned pg = *cur_pg;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200330 struct request_queue *q =
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700331 osd_request_queue(_ios_od(ios, per_dev->dev));
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200332
333 per_dev->length += cur_len;
334
335 if (per_dev->bio == NULL) {
336 unsigned pages_in_stripe = ios->layout->group_width *
337 (ios->layout->stripe_unit / PAGE_SIZE);
Boaz Harrosh86093aa2010-01-28 18:24:06 +0200338 unsigned bio_size = (ios->nr_pages + pages_in_stripe) /
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200339 ios->layout->group_width;
340
341 per_dev->bio = bio_kmalloc(GFP_KERNEL, bio_size);
342 if (unlikely(!per_dev->bio)) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700343 ORE_DBGMSG("Failed to allocate BIO size=%u\n",
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200344 bio_size);
345 return -ENOMEM;
346 }
347 }
348
349 while (cur_len > 0) {
Boaz Harrosh86093aa2010-01-28 18:24:06 +0200350 unsigned pglen = min_t(unsigned, PAGE_SIZE - pgbase, cur_len);
351 unsigned added_len;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200352
Boaz Harrosh86093aa2010-01-28 18:24:06 +0200353 BUG_ON(ios->nr_pages <= pg);
354 cur_len -= pglen;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200355
Boaz Harrosh86093aa2010-01-28 18:24:06 +0200356 added_len = bio_add_pc_page(q, per_dev->bio, ios->pages[pg],
357 pglen, pgbase);
358 if (unlikely(pglen != added_len))
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200359 return -ENOMEM;
Boaz Harrosh86093aa2010-01-28 18:24:06 +0200360 pgbase = 0;
361 ++pg;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200362 }
363 BUG_ON(cur_len);
364
Boaz Harrosh86093aa2010-01-28 18:24:06 +0200365 *cur_pg = pg;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200366 return 0;
367}
368
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700369static int _prepare_one_group(struct ore_io_state *ios, u64 length,
Boaz Harrosh6e316092010-07-29 17:08:13 +0300370 struct _striping_info *si)
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200371{
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200372 unsigned stripe_unit = ios->layout->stripe_unit;
Boaz Harroshb367e782010-02-07 19:18:58 +0200373 unsigned mirrors_p1 = ios->layout->mirrors_p1;
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200374 unsigned devs_in_group = ios->layout->group_width * mirrors_p1;
Boaz Harroshb367e782010-02-07 19:18:58 +0200375 unsigned dev = si->dev;
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200376 unsigned first_dev = dev - (dev % devs_in_group);
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200377 unsigned max_comp = ios->numdevs ? ios->numdevs - mirrors_p1 : 0;
378 unsigned cur_pg = ios->pages_consumed;
Boaz Harrosh86093aa2010-01-28 18:24:06 +0200379 int ret = 0;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200380
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200381 while (length) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700382 struct ore_per_dev_state *per_dev = &ios->per_dev[dev];
Boaz Harroshb367e782010-02-07 19:18:58 +0200383 unsigned cur_len, page_off = 0;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200384
385 if (!per_dev->length) {
Boaz Harroshb367e782010-02-07 19:18:58 +0200386 per_dev->dev = dev;
387 if (dev < si->dev) {
388 per_dev->offset = si->obj_offset + stripe_unit -
389 si->unit_off;
390 cur_len = stripe_unit;
391 } else if (dev == si->dev) {
392 per_dev->offset = si->obj_offset;
393 cur_len = stripe_unit - si->unit_off;
394 page_off = si->unit_off & ~PAGE_MASK;
395 BUG_ON(page_off && (page_off != ios->pgbase));
396 } else { /* dev > si->dev */
397 per_dev->offset = si->obj_offset - si->unit_off;
398 cur_len = stripe_unit;
399 }
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200400
Boaz Harrosh6e316092010-07-29 17:08:13 +0300401 if (max_comp < dev)
402 max_comp = dev;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200403 } else {
Boaz Harroshb367e782010-02-07 19:18:58 +0200404 cur_len = stripe_unit;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200405 }
Boaz Harroshb367e782010-02-07 19:18:58 +0200406 if (cur_len >= length)
407 cur_len = length;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200408
Boaz Harrosh86093aa2010-01-28 18:24:06 +0200409 ret = _add_stripe_unit(ios, &cur_pg, page_off , per_dev,
410 cur_len);
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200411 if (unlikely(ret))
412 goto out;
413
Boaz Harrosh6e316092010-07-29 17:08:13 +0300414 dev += mirrors_p1;
415 dev = (dev % devs_in_group) + first_dev;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200416
417 length -= cur_len;
418 }
419out:
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200420 ios->numdevs = max_comp + mirrors_p1;
421 ios->pages_consumed = cur_pg;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200422 return ret;
423}
424
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700425static int _prepare_for_striping(struct ore_io_state *ios)
Boaz Harroshb367e782010-02-07 19:18:58 +0200426{
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200427 u64 length = ios->length;
Boaz Harrosh5002dd12010-08-02 20:06:46 +0300428 u64 offset = ios->offset;
Boaz Harroshb367e782010-02-07 19:18:58 +0200429 struct _striping_info si;
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200430 int ret = 0;
Boaz Harroshb367e782010-02-07 19:18:58 +0200431
Boaz Harroshb367e782010-02-07 19:18:58 +0200432 if (!ios->pages) {
433 if (ios->kern_buff) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700434 struct ore_per_dev_state *per_dev = &ios->per_dev[0];
Boaz Harroshb367e782010-02-07 19:18:58 +0200435
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700436 _calc_stripe_info(ios->layout, ios->offset, &si);
Boaz Harroshb367e782010-02-07 19:18:58 +0200437 per_dev->offset = si.obj_offset;
438 per_dev->dev = si.dev;
439
440 /* no cross device without page array */
441 BUG_ON((ios->layout->group_width > 1) &&
442 (si.unit_off + ios->length >
443 ios->layout->stripe_unit));
444 }
445 ios->numdevs = ios->layout->mirrors_p1;
446 return 0;
447 }
448
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200449 while (length) {
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700450 _calc_stripe_info(ios->layout, offset, &si);
Boaz Harrosh5002dd12010-08-02 20:06:46 +0300451
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200452 if (length < si.group_length)
453 si.group_length = length;
454
Boaz Harrosh6e316092010-07-29 17:08:13 +0300455 ret = _prepare_one_group(ios, si.group_length, &si);
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200456 if (unlikely(ret))
457 goto out;
458
Boaz Harrosh5002dd12010-08-02 20:06:46 +0300459 offset += si.group_length;
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200460 length -= si.group_length;
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200461 }
462
463out:
464 return ret;
Boaz Harroshb367e782010-02-07 19:18:58 +0200465}
466
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700467int ore_create(struct ore_io_state *ios)
Boaz Harrosh06886a52009-11-08 14:54:08 +0200468{
469 int i, ret;
470
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700471 for (i = 0; i < ios->comps->numdevs; i++) {
Boaz Harrosh06886a52009-11-08 14:54:08 +0200472 struct osd_request *or;
473
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700474 or = osd_start_request(_ios_od(ios, i), GFP_KERNEL);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200475 if (unlikely(!or)) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700476 ORE_ERR("%s: osd_start_request failed\n", __func__);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200477 ret = -ENOMEM;
478 goto out;
479 }
480 ios->per_dev[i].or = or;
481 ios->numdevs++;
482
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700483 osd_req_create_object(or, _ios_obj(ios, i));
Boaz Harrosh06886a52009-11-08 14:54:08 +0200484 }
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700485 ret = ore_io_execute(ios);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200486
487out:
488 return ret;
489}
490
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700491int ore_remove(struct ore_io_state *ios)
Boaz Harrosh06886a52009-11-08 14:54:08 +0200492{
493 int i, ret;
494
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700495 for (i = 0; i < ios->comps->numdevs; i++) {
Boaz Harrosh06886a52009-11-08 14:54:08 +0200496 struct osd_request *or;
497
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700498 or = osd_start_request(_ios_od(ios, i), GFP_KERNEL);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200499 if (unlikely(!or)) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700500 ORE_ERR("%s: osd_start_request failed\n", __func__);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200501 ret = -ENOMEM;
502 goto out;
503 }
504 ios->per_dev[i].or = or;
505 ios->numdevs++;
506
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700507 osd_req_remove_object(or, _ios_obj(ios, i));
Boaz Harrosh06886a52009-11-08 14:54:08 +0200508 }
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700509 ret = ore_io_execute(ios);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200510
511out:
512 return ret;
513}
514
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700515static int _write_mirror(struct ore_io_state *ios, int cur_comp)
Boaz Harrosh06886a52009-11-08 14:54:08 +0200516{
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700517 struct ore_per_dev_state *master_dev = &ios->per_dev[cur_comp];
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200518 unsigned dev = ios->per_dev[cur_comp].dev;
519 unsigned last_comp = cur_comp + ios->layout->mirrors_p1;
520 int ret = 0;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200521
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200522 if (ios->pages && !master_dev->length)
523 return 0; /* Just an empty slot */
524
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200525 for (; cur_comp < last_comp; ++cur_comp, ++dev) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700526 struct ore_per_dev_state *per_dev = &ios->per_dev[cur_comp];
Boaz Harrosh06886a52009-11-08 14:54:08 +0200527 struct osd_request *or;
528
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700529 or = osd_start_request(_ios_od(ios, dev), GFP_KERNEL);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200530 if (unlikely(!or)) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700531 ORE_ERR("%s: osd_start_request failed\n", __func__);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200532 ret = -ENOMEM;
533 goto out;
534 }
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200535 per_dev->or = or;
536 per_dev->offset = master_dev->offset;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200537
Boaz Harrosh86093aa2010-01-28 18:24:06 +0200538 if (ios->pages) {
Boaz Harrosh06886a52009-11-08 14:54:08 +0200539 struct bio *bio;
540
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200541 if (per_dev != master_dev) {
Boaz Harrosh04dc1e82009-11-16 16:03:05 +0200542 bio = bio_kmalloc(GFP_KERNEL,
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200543 master_dev->bio->bi_max_vecs);
Boaz Harrosh04dc1e82009-11-16 16:03:05 +0200544 if (unlikely(!bio)) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700545 ORE_DBGMSG(
Paul Bolle426d3102010-08-07 12:30:03 +0200546 "Failed to allocate BIO size=%u\n",
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200547 master_dev->bio->bi_max_vecs);
Boaz Harrosh04dc1e82009-11-16 16:03:05 +0200548 ret = -ENOMEM;
549 goto out;
550 }
551
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200552 __bio_clone(bio, master_dev->bio);
Boaz Harrosh04dc1e82009-11-16 16:03:05 +0200553 bio->bi_bdev = NULL;
554 bio->bi_next = NULL;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200555 per_dev->length = master_dev->length;
556 per_dev->bio = bio;
557 per_dev->dev = dev;
Boaz Harrosh04dc1e82009-11-16 16:03:05 +0200558 } else {
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200559 bio = master_dev->bio;
560 /* FIXME: bio_set_dir() */
Christoph Hellwig7b6d91d2010-08-07 18:20:39 +0200561 bio->bi_rw |= REQ_WRITE;
Boaz Harrosh04dc1e82009-11-16 16:03:05 +0200562 }
Boaz Harrosh06886a52009-11-08 14:54:08 +0200563
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700564 osd_req_write(or, _ios_obj(ios, dev), per_dev->offset,
565 bio, per_dev->length);
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700566 ORE_DBGMSG("write(0x%llx) offset=0x%llx "
Boaz Harrosh34ce4e7c2009-12-15 19:34:17 +0200567 "length=0x%llx dev=%d\n",
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700568 _LLU(_ios_obj(ios, dev)->id),
569 _LLU(per_dev->offset),
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200570 _LLU(per_dev->length), dev);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200571 } else if (ios->kern_buff) {
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700572 ret = osd_req_write_kern(or, _ios_obj(ios, dev),
573 per_dev->offset,
574 ios->kern_buff, ios->length);
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200575 if (unlikely(ret))
576 goto out;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700577 ORE_DBGMSG2("write_kern(0x%llx) offset=0x%llx "
Boaz Harrosh34ce4e7c2009-12-15 19:34:17 +0200578 "length=0x%llx dev=%d\n",
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700579 _LLU(_ios_obj(ios, dev)->id),
580 _LLU(per_dev->offset),
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200581 _LLU(ios->length), dev);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200582 } else {
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700583 osd_req_set_attributes(or, _ios_obj(ios, dev));
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700584 ORE_DBGMSG2("obj(0x%llx) set_attributes=%d dev=%d\n",
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700585 _LLU(_ios_obj(ios, dev)->id),
586 ios->out_attr_len, dev);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200587 }
588
589 if (ios->out_attr)
590 osd_req_add_set_attr_list(or, ios->out_attr,
591 ios->out_attr_len);
592
593 if (ios->in_attr)
594 osd_req_add_get_attr_list(or, ios->in_attr,
595 ios->in_attr_len);
596 }
Boaz Harrosh06886a52009-11-08 14:54:08 +0200597
598out:
599 return ret;
600}
601
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700602int ore_write(struct ore_io_state *ios)
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200603{
604 int i;
605 int ret;
606
607 ret = _prepare_for_striping(ios);
608 if (unlikely(ret))
609 return ret;
610
611 for (i = 0; i < ios->numdevs; i += ios->layout->mirrors_p1) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700612 ret = _write_mirror(ios, i);
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200613 if (unlikely(ret))
614 return ret;
615 }
616
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700617 ret = ore_io_execute(ios);
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200618 return ret;
619}
620
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700621static int _read_mirror(struct ore_io_state *ios, unsigned cur_comp)
Boaz Harrosh06886a52009-11-08 14:54:08 +0200622{
Boaz Harrosh46f4d972010-02-01 11:37:30 +0200623 struct osd_request *or;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700624 struct ore_per_dev_state *per_dev = &ios->per_dev[cur_comp];
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700625 struct osd_obj_id *obj = _ios_obj(ios, cur_comp);
626 unsigned first_dev = (unsigned)obj->id;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200627
Boaz Harrosh50a76fd2010-02-11 13:01:39 +0200628 if (ios->pages && !per_dev->length)
629 return 0; /* Just an empty slot */
630
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200631 first_dev = per_dev->dev + first_dev % ios->layout->mirrors_p1;
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700632 or = osd_start_request(_ios_od(ios, first_dev), GFP_KERNEL);
Boaz Harrosh46f4d972010-02-01 11:37:30 +0200633 if (unlikely(!or)) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700634 ORE_ERR("%s: osd_start_request failed\n", __func__);
Boaz Harrosh46f4d972010-02-01 11:37:30 +0200635 return -ENOMEM;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200636 }
Boaz Harrosh46f4d972010-02-01 11:37:30 +0200637 per_dev->or = or;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200638
Boaz Harrosh86093aa2010-01-28 18:24:06 +0200639 if (ios->pages) {
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700640 osd_req_read(or, obj, per_dev->offset,
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200641 per_dev->bio, per_dev->length);
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700642 ORE_DBGMSG("read(0x%llx) offset=0x%llx length=0x%llx"
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700643 " dev=%d\n", _LLU(obj->id),
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200644 _LLU(per_dev->offset), _LLU(per_dev->length),
Boaz Harrosh46f4d972010-02-01 11:37:30 +0200645 first_dev);
646 } else if (ios->kern_buff) {
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700647 int ret = osd_req_read_kern(or, obj, per_dev->offset,
Boaz Harrosh46f4d972010-02-01 11:37:30 +0200648 ios->kern_buff, ios->length);
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700649 ORE_DBGMSG2("read_kern(0x%llx) offset=0x%llx "
Boaz Harrosh46f4d972010-02-01 11:37:30 +0200650 "length=0x%llx dev=%d ret=>%d\n",
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700651 _LLU(obj->id), _LLU(per_dev->offset),
Boaz Harrosh46f4d972010-02-01 11:37:30 +0200652 _LLU(ios->length), first_dev, ret);
653 if (unlikely(ret))
654 return ret;
655 } else {
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700656 osd_req_get_attributes(or, obj);
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700657 ORE_DBGMSG2("obj(0x%llx) get_attributes=%d dev=%d\n",
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700658 _LLU(obj->id),
659 ios->in_attr_len, first_dev);
Boaz Harrosh46f4d972010-02-01 11:37:30 +0200660 }
Boaz Harrosh46f4d972010-02-01 11:37:30 +0200661 if (ios->out_attr)
662 osd_req_add_set_attr_list(or, ios->out_attr, ios->out_attr_len);
663
664 if (ios->in_attr)
665 osd_req_add_get_attr_list(or, ios->in_attr, ios->in_attr_len);
666
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200667 return 0;
668}
669
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700670int ore_read(struct ore_io_state *ios)
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200671{
672 int i;
673 int ret;
674
675 ret = _prepare_for_striping(ios);
676 if (unlikely(ret))
677 return ret;
678
679 for (i = 0; i < ios->numdevs; i += ios->layout->mirrors_p1) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700680 ret = _read_mirror(ios, i);
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200681 if (unlikely(ret))
682 return ret;
683 }
684
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700685 ret = ore_io_execute(ios);
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200686 return ret;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200687}
688
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700689int extract_attr_from_ios(struct ore_io_state *ios, struct osd_attr *attr)
Boaz Harroshb14f8ab2008-10-27 18:27:55 +0200690{
691 struct osd_attr cur_attr = {.attr_page = 0}; /* start with zeros */
692 void *iter = NULL;
693 int nelem;
694
695 do {
696 nelem = 1;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200697 osd_req_decode_get_attr_list(ios->per_dev[0].or,
698 &cur_attr, &nelem, &iter);
Boaz Harroshb14f8ab2008-10-27 18:27:55 +0200699 if ((cur_attr.attr_page == attr->attr_page) &&
700 (cur_attr.attr_id == attr->attr_id)) {
701 attr->len = cur_attr.len;
702 attr->val_ptr = cur_attr.val_ptr;
703 return 0;
704 }
705 } while (iter);
706
707 return -EIO;
708}
Boaz Harrosh06886a52009-11-08 14:54:08 +0200709
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700710static int _truncate_mirrors(struct ore_io_state *ios, unsigned cur_comp,
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200711 struct osd_attr *attr)
712{
713 int last_comp = cur_comp + ios->layout->mirrors_p1;
714
715 for (; cur_comp < last_comp; ++cur_comp) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700716 struct ore_per_dev_state *per_dev = &ios->per_dev[cur_comp];
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200717 struct osd_request *or;
718
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700719 or = osd_start_request(_ios_od(ios, cur_comp), GFP_KERNEL);
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200720 if (unlikely(!or)) {
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700721 ORE_ERR("%s: osd_start_request failed\n", __func__);
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200722 return -ENOMEM;
723 }
724 per_dev->or = or;
725
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700726 osd_req_set_attributes(or, _ios_obj(ios, cur_comp));
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200727 osd_req_add_set_attr_list(or, attr, 1);
728 }
729
730 return 0;
731}
732
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700733struct _trunc_info {
734 struct _striping_info si;
735 u64 prev_group_obj_off;
736 u64 next_group_obj_off;
737
738 unsigned first_group_dev;
739 unsigned nex_group_dev;
740 unsigned max_devs;
741};
742
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700743void _calc_trunk_info(struct ore_layout *layout, u64 file_offset,
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700744 struct _trunc_info *ti)
745{
746 unsigned stripe_unit = layout->stripe_unit;
747
748 _calc_stripe_info(layout, file_offset, &ti->si);
749
750 ti->prev_group_obj_off = ti->si.M * stripe_unit;
751 ti->next_group_obj_off = ti->si.M ? (ti->si.M - 1) * stripe_unit : 0;
752
753 ti->first_group_dev = ti->si.dev - (ti->si.dev % layout->group_width);
754 ti->nex_group_dev = ti->first_group_dev + layout->group_width;
755 ti->max_devs = layout->group_width * layout->group_count;
756}
757
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700758int ore_truncate(struct ore_layout *layout, struct ore_components *comps,
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700759 u64 size)
Boaz Harrosh06886a52009-11-08 14:54:08 +0200760{
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700761 struct ore_io_state *ios;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200762 struct exofs_trunc_attr {
763 struct osd_attr attr;
764 __be64 newsize;
765 } *size_attrs;
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700766 struct _trunc_info ti;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200767 int i, ret;
768
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700769 ret = ore_get_io_state(layout, comps, &ios);
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200770 if (unlikely(ret))
771 return ret;
772
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700773 _calc_trunk_info(ios->layout, size, &ti);
774
775 size_attrs = kcalloc(ti.max_devs, sizeof(*size_attrs),
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200776 GFP_KERNEL);
777 if (unlikely(!size_attrs)) {
778 ret = -ENOMEM;
779 goto out;
780 }
Boaz Harrosh06886a52009-11-08 14:54:08 +0200781
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700782 ios->numdevs = ios->comps->numdevs;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200783
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700784 for (i = 0; i < ti.max_devs; ++i) {
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200785 struct exofs_trunc_attr *size_attr = &size_attrs[i];
786 u64 obj_size;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200787
Boaz Harrosh16f75bb2011-08-03 20:44:16 -0700788 if (i < ti.first_group_dev)
789 obj_size = ti.prev_group_obj_off;
790 else if (i >= ti.nex_group_dev)
791 obj_size = ti.next_group_obj_off;
792 else if (i < ti.si.dev) /* dev within this group */
793 obj_size = ti.si.obj_offset +
794 ios->layout->stripe_unit - ti.si.unit_off;
795 else if (i == ti.si.dev)
796 obj_size = ti.si.obj_offset;
797 else /* i > ti.dev */
798 obj_size = ti.si.obj_offset - ti.si.unit_off;
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200799
800 size_attr->newsize = cpu_to_be64(obj_size);
801 size_attr->attr = g_attr_logical_length;
802 size_attr->attr.val_ptr = &size_attr->newsize;
803
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700804 ORE_DBGMSG("trunc(0x%llx) obj_offset=0x%llx dev=%d\n",
Boaz Harrosh9e9db452011-08-05 15:06:04 -0700805 _LLU(comps->comps->obj.id), _LLU(obj_size), i);
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200806 ret = _truncate_mirrors(ios, i * ios->layout->mirrors_p1,
807 &size_attr->attr);
808 if (unlikely(ret))
Boaz Harrosh06886a52009-11-08 14:54:08 +0200809 goto out;
Boaz Harrosh06886a52009-11-08 14:54:08 +0200810 }
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700811 ret = ore_io_execute(ios);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200812
813out:
Boaz Harrosh5d952b82010-02-01 13:35:51 +0200814 kfree(size_attrs);
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700815 ore_put_io_state(ios);
Boaz Harrosh06886a52009-11-08 14:54:08 +0200816 return ret;
817}
Boaz Harrosh85e44df2011-05-16 15:26:47 +0300818
819const struct osd_attr g_attr_logical_length = ATTR_DEF(
820 OSD_APAGE_OBJECT_INFORMATION, OSD_ATTR_OI_LOGICAL_LENGTH, 8);