Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005, 2006 |
Boaz Harrosh | 27d2e14 | 2009-06-14 17:23:09 +0300 | [diff] [blame] | 3 | * Avishay Traeger (avishay@gmail.com) |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 4 | * 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 | |
| 25 | #include <scsi/scsi_device.h> |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 26 | #include <asm/div64.h> |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 27 | |
| 28 | #include "exofs.h" |
| 29 | |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 30 | #define EXOFS_DBGMSG2(M...) do {} while (0) |
| 31 | /* #define EXOFS_DBGMSG2 EXOFS_DBGMSG */ |
| 32 | |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 33 | void exofs_make_credential(u8 cred_a[OSD_CAP_LEN], const struct osd_obj_id *obj) |
| 34 | { |
| 35 | osd_sec_init_nosec_doall_caps(cred_a, obj, false, true); |
| 36 | } |
| 37 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 38 | int exofs_read_kern(struct osd_dev *od, u8 *cred, struct osd_obj_id *obj, |
| 39 | u64 offset, void *p, unsigned length) |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 40 | { |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 41 | struct osd_request *or = osd_start_request(od, GFP_KERNEL); |
| 42 | /* struct osd_sense_info osi = {.key = 0};*/ |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 43 | int ret; |
| 44 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 45 | if (unlikely(!or)) { |
| 46 | EXOFS_DBGMSG("%s: osd_start_request failed.\n", __func__); |
| 47 | return -ENOMEM; |
| 48 | } |
| 49 | ret = osd_req_read_kern(or, obj, offset, p, length); |
| 50 | if (unlikely(ret)) { |
| 51 | EXOFS_DBGMSG("%s: osd_req_read_kern failed.\n", __func__); |
| 52 | goto out; |
| 53 | } |
| 54 | |
| 55 | ret = osd_finalize_request(or, 0, cred, NULL); |
| 56 | if (unlikely(ret)) { |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 57 | EXOFS_DBGMSG("Faild to osd_finalize_request() => %d\n", ret); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 58 | goto out; |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | ret = osd_execute_request(or); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 62 | if (unlikely(ret)) |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 63 | EXOFS_DBGMSG("osd_execute_request() => %d\n", ret); |
| 64 | /* osd_req_decode_sense(or, ret); */ |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 65 | |
| 66 | out: |
| 67 | osd_end_request(or); |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 68 | return ret; |
| 69 | } |
| 70 | |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 71 | int exofs_get_io_state(struct exofs_layout *layout, |
| 72 | struct exofs_io_state **pios) |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 73 | { |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 74 | struct exofs_io_state *ios; |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 75 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 76 | /*TODO: Maybe use kmem_cach per sbi of size |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 77 | * exofs_io_state_size(layout->s_numdevs) |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 78 | */ |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 79 | ios = kzalloc(exofs_io_state_size(layout->s_numdevs), GFP_KERNEL); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 80 | if (unlikely(!ios)) { |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 81 | EXOFS_DBGMSG("Faild kzalloc bytes=%d\n", |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 82 | exofs_io_state_size(layout->s_numdevs)); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 83 | *pios = NULL; |
| 84 | return -ENOMEM; |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 87 | ios->layout = layout; |
| 88 | ios->obj.partition = layout->s_pid; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 89 | *pios = ios; |
| 90 | return 0; |
| 91 | } |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 92 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 93 | void exofs_put_io_state(struct exofs_io_state *ios) |
| 94 | { |
| 95 | if (ios) { |
| 96 | unsigned i; |
| 97 | |
| 98 | for (i = 0; i < ios->numdevs; i++) { |
| 99 | struct exofs_per_dev_state *per_dev = &ios->per_dev[i]; |
| 100 | |
| 101 | if (per_dev->or) |
| 102 | osd_end_request(per_dev->or); |
| 103 | if (per_dev->bio) |
| 104 | bio_put(per_dev->bio); |
| 105 | } |
| 106 | |
| 107 | kfree(ios); |
| 108 | } |
| 109 | } |
| 110 | |
Boaz Harrosh | d9c740d | 2010-01-28 11:58:08 +0200 | [diff] [blame] | 111 | unsigned exofs_layout_od_id(struct exofs_layout *layout, |
| 112 | osd_id obj_no, unsigned layout_index) |
| 113 | { |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 114 | /* switch (layout->lay_func) { |
| 115 | case LAYOUT_MOVING_WINDOW: |
| 116 | {*/ |
| 117 | unsigned dev_mod = obj_no; |
| 118 | |
| 119 | return (layout_index + dev_mod * layout->mirrors_p1) % |
| 120 | layout->s_numdevs; |
| 121 | /* } |
| 122 | case LAYOUT_FUNC_IMPLICT: |
| 123 | return layout->devs[layout_index]; |
| 124 | }*/ |
Boaz Harrosh | d9c740d | 2010-01-28 11:58:08 +0200 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | static inline struct osd_dev *exofs_ios_od(struct exofs_io_state *ios, |
| 128 | unsigned layout_index) |
| 129 | { |
| 130 | return ios->layout->s_ods[ |
| 131 | exofs_layout_od_id(ios->layout, ios->obj.id, layout_index)]; |
| 132 | } |
| 133 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 134 | static void _sync_done(struct exofs_io_state *ios, void *p) |
| 135 | { |
| 136 | struct completion *waiting = p; |
| 137 | |
| 138 | complete(waiting); |
| 139 | } |
| 140 | |
| 141 | static void _last_io(struct kref *kref) |
| 142 | { |
| 143 | struct exofs_io_state *ios = container_of( |
| 144 | kref, struct exofs_io_state, kref); |
| 145 | |
| 146 | ios->done(ios, ios->private); |
| 147 | } |
| 148 | |
| 149 | static void _done_io(struct osd_request *or, void *p) |
| 150 | { |
| 151 | struct exofs_io_state *ios = p; |
| 152 | |
| 153 | kref_put(&ios->kref, _last_io); |
| 154 | } |
| 155 | |
| 156 | static int exofs_io_execute(struct exofs_io_state *ios) |
| 157 | { |
| 158 | DECLARE_COMPLETION_ONSTACK(wait); |
| 159 | bool sync = (ios->done == NULL); |
| 160 | int i, ret; |
| 161 | |
| 162 | if (sync) { |
| 163 | ios->done = _sync_done; |
| 164 | ios->private = &wait; |
| 165 | } |
| 166 | |
| 167 | for (i = 0; i < ios->numdevs; i++) { |
| 168 | struct osd_request *or = ios->per_dev[i].or; |
| 169 | if (unlikely(!or)) |
| 170 | continue; |
| 171 | |
| 172 | ret = osd_finalize_request(or, 0, ios->cred, NULL); |
| 173 | if (unlikely(ret)) { |
| 174 | EXOFS_DBGMSG("Faild to osd_finalize_request() => %d\n", |
| 175 | ret); |
| 176 | return ret; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | kref_init(&ios->kref); |
| 181 | |
| 182 | for (i = 0; i < ios->numdevs; i++) { |
| 183 | struct osd_request *or = ios->per_dev[i].or; |
| 184 | if (unlikely(!or)) |
| 185 | continue; |
| 186 | |
| 187 | kref_get(&ios->kref); |
| 188 | osd_execute_request_async(or, _done_io, ios); |
| 189 | } |
| 190 | |
| 191 | kref_put(&ios->kref, _last_io); |
| 192 | ret = 0; |
| 193 | |
| 194 | if (sync) { |
| 195 | wait_for_completion(&wait); |
| 196 | ret = exofs_check_io(ios, NULL); |
| 197 | } |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 198 | return ret; |
| 199 | } |
| 200 | |
Boaz Harrosh | 22ddc55 | 2010-01-19 19:24:45 +0200 | [diff] [blame] | 201 | static void _clear_bio(struct bio *bio) |
| 202 | { |
| 203 | struct bio_vec *bv; |
| 204 | unsigned i; |
| 205 | |
| 206 | __bio_for_each_segment(bv, bio, i, 0) { |
| 207 | unsigned this_count = bv->bv_len; |
| 208 | |
| 209 | if (likely(PAGE_SIZE == this_count)) |
| 210 | clear_highpage(bv->bv_page); |
| 211 | else |
| 212 | zero_user(bv->bv_page, bv->bv_offset, this_count); |
| 213 | } |
| 214 | } |
| 215 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 216 | int exofs_check_io(struct exofs_io_state *ios, u64 *resid) |
| 217 | { |
| 218 | enum osd_err_priority acumulated_osd_err = 0; |
| 219 | int acumulated_lin_err = 0; |
| 220 | int i; |
| 221 | |
| 222 | for (i = 0; i < ios->numdevs; i++) { |
| 223 | struct osd_sense_info osi; |
Boaz Harrosh | 22ddc55 | 2010-01-19 19:24:45 +0200 | [diff] [blame] | 224 | struct osd_request *or = ios->per_dev[i].or; |
| 225 | int ret; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 226 | |
Boaz Harrosh | 22ddc55 | 2010-01-19 19:24:45 +0200 | [diff] [blame] | 227 | if (unlikely(!or)) |
| 228 | continue; |
| 229 | |
| 230 | ret = osd_req_decode_sense(or, &osi); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 231 | if (likely(!ret)) |
| 232 | continue; |
| 233 | |
Boaz Harrosh | 22ddc55 | 2010-01-19 19:24:45 +0200 | [diff] [blame] | 234 | if (OSD_ERR_PRI_CLEAR_PAGES == osi.osd_err_pri) { |
| 235 | /* start read offset passed endof file */ |
| 236 | _clear_bio(ios->per_dev[i].bio); |
| 237 | EXOFS_DBGMSG("start read offset passed end of file " |
| 238 | "offset=0x%llx, length=0x%llx\n", |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 239 | _LLU(ios->per_dev[i].offset), |
| 240 | _LLU(ios->per_dev[i].length)); |
Boaz Harrosh | 22ddc55 | 2010-01-19 19:24:45 +0200 | [diff] [blame] | 241 | |
| 242 | continue; /* we recovered */ |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | if (osi.osd_err_pri >= acumulated_osd_err) { |
| 246 | acumulated_osd_err = osi.osd_err_pri; |
| 247 | acumulated_lin_err = ret; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | /* TODO: raid specific residual calculations */ |
| 252 | if (resid) { |
| 253 | if (likely(!acumulated_lin_err)) |
| 254 | *resid = 0; |
| 255 | else |
| 256 | *resid = ios->length; |
| 257 | } |
| 258 | |
| 259 | return acumulated_lin_err; |
| 260 | } |
| 261 | |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 262 | /* |
| 263 | * L - logical offset into the file |
| 264 | * |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 265 | * U - The number of bytes in a stripe within a group |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 266 | * |
| 267 | * U = stripe_unit * group_width |
| 268 | * |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 269 | * T - The number of bytes striped within a group of component objects |
| 270 | * (before advancing to the next group) |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 271 | * |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 272 | * T = stripe_unit * group_width * group_depth |
| 273 | * |
| 274 | * S - The number of bytes striped across all component objects |
| 275 | * before the pattern repeats |
| 276 | * |
| 277 | * S = stripe_unit * group_width * group_depth * group_count |
| 278 | * |
| 279 | * M - The "major" (i.e., across all components) stripe number |
| 280 | * |
| 281 | * M = L / S |
| 282 | * |
| 283 | * G - Counts the groups from the beginning of the major stripe |
| 284 | * |
| 285 | * G = (L - (M * S)) / T [or (L % S) / T] |
| 286 | * |
| 287 | * H - The byte offset within the group |
| 288 | * |
| 289 | * H = (L - (M * S)) % T [or (L % S) % T] |
| 290 | * |
| 291 | * N - The "minor" (i.e., across the group) stripe number |
| 292 | * |
| 293 | * N = H / U |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 294 | * |
| 295 | * C - The component index coresponding to L |
| 296 | * |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 297 | * C = (H - (N * U)) / stripe_unit + G * group_width |
| 298 | * [or (L % U) / stripe_unit + G * group_width] |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 299 | * |
| 300 | * O - The component offset coresponding to L |
| 301 | * |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 302 | * O = L % stripe_unit + N * stripe_unit + M * group_depth * stripe_unit |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 303 | */ |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 304 | struct _striping_info { |
| 305 | u64 obj_offset; |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 306 | u64 group_length; |
| 307 | u64 total_group_length; |
| 308 | u64 Major; |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 309 | unsigned dev; |
| 310 | unsigned unit_off; |
| 311 | }; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 312 | |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 313 | static void _calc_stripe_info(struct exofs_io_state *ios, u64 file_offset, |
| 314 | struct _striping_info *si) |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 315 | { |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 316 | u32 stripe_unit = ios->layout->stripe_unit; |
| 317 | u32 group_width = ios->layout->group_width; |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 318 | u64 group_depth = ios->layout->group_depth; |
| 319 | |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 320 | u32 U = stripe_unit * group_width; |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 321 | u64 T = U * group_depth; |
| 322 | u64 S = T * ios->layout->group_count; |
| 323 | u64 M = div64_u64(file_offset, S); |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 324 | |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 325 | /* |
| 326 | G = (L - (M * S)) / T |
| 327 | H = (L - (M * S)) % T |
| 328 | */ |
| 329 | u64 LmodS = file_offset - M * S; |
| 330 | u32 G = div64_u64(LmodS, T); |
| 331 | u64 H = LmodS - G * T; |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 332 | |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 333 | u32 N = div_u64(H, U); |
| 334 | |
| 335 | /* "H - (N * U)" is just "H % U" so it's bound to u32 */ |
| 336 | si->dev = (u32)(H - (N * U)) / stripe_unit + G * group_width; |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 337 | si->dev *= ios->layout->mirrors_p1; |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 338 | |
| 339 | div_u64_rem(file_offset, stripe_unit, &si->unit_off); |
| 340 | |
| 341 | si->obj_offset = si->unit_off + (N * stripe_unit) + |
| 342 | (M * group_depth * stripe_unit); |
| 343 | |
| 344 | si->group_length = T - H; |
| 345 | si->total_group_length = T; |
| 346 | si->Major = M; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 347 | } |
| 348 | |
Boaz Harrosh | 86093aa | 2010-01-28 18:24:06 +0200 | [diff] [blame] | 349 | static int _add_stripe_unit(struct exofs_io_state *ios, unsigned *cur_pg, |
| 350 | unsigned pgbase, struct exofs_per_dev_state *per_dev, |
| 351 | int cur_len) |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 352 | { |
Boaz Harrosh | 86093aa | 2010-01-28 18:24:06 +0200 | [diff] [blame] | 353 | unsigned pg = *cur_pg; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 354 | struct request_queue *q = |
| 355 | osd_request_queue(exofs_ios_od(ios, per_dev->dev)); |
| 356 | |
| 357 | per_dev->length += cur_len; |
| 358 | |
| 359 | if (per_dev->bio == NULL) { |
| 360 | unsigned pages_in_stripe = ios->layout->group_width * |
| 361 | (ios->layout->stripe_unit / PAGE_SIZE); |
Boaz Harrosh | 86093aa | 2010-01-28 18:24:06 +0200 | [diff] [blame] | 362 | unsigned bio_size = (ios->nr_pages + pages_in_stripe) / |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 363 | ios->layout->group_width; |
| 364 | |
| 365 | per_dev->bio = bio_kmalloc(GFP_KERNEL, bio_size); |
| 366 | if (unlikely(!per_dev->bio)) { |
| 367 | EXOFS_DBGMSG("Faild to allocate BIO size=%u\n", |
| 368 | bio_size); |
| 369 | return -ENOMEM; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | while (cur_len > 0) { |
Boaz Harrosh | 86093aa | 2010-01-28 18:24:06 +0200 | [diff] [blame] | 374 | unsigned pglen = min_t(unsigned, PAGE_SIZE - pgbase, cur_len); |
| 375 | unsigned added_len; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 376 | |
Boaz Harrosh | 86093aa | 2010-01-28 18:24:06 +0200 | [diff] [blame] | 377 | BUG_ON(ios->nr_pages <= pg); |
| 378 | cur_len -= pglen; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 379 | |
Boaz Harrosh | 86093aa | 2010-01-28 18:24:06 +0200 | [diff] [blame] | 380 | added_len = bio_add_pc_page(q, per_dev->bio, ios->pages[pg], |
| 381 | pglen, pgbase); |
| 382 | if (unlikely(pglen != added_len)) |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 383 | return -ENOMEM; |
Boaz Harrosh | 86093aa | 2010-01-28 18:24:06 +0200 | [diff] [blame] | 384 | pgbase = 0; |
| 385 | ++pg; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 386 | } |
| 387 | BUG_ON(cur_len); |
| 388 | |
Boaz Harrosh | 86093aa | 2010-01-28 18:24:06 +0200 | [diff] [blame] | 389 | *cur_pg = pg; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 390 | return 0; |
| 391 | } |
| 392 | |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 393 | static int _prepare_one_group(struct exofs_io_state *ios, u64 length, |
| 394 | struct _striping_info *si, unsigned first_comp) |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 395 | { |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 396 | unsigned stripe_unit = ios->layout->stripe_unit; |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 397 | unsigned mirrors_p1 = ios->layout->mirrors_p1; |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 398 | unsigned devs_in_group = ios->layout->group_width * mirrors_p1; |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 399 | unsigned dev = si->dev; |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 400 | unsigned first_dev = dev - (dev % devs_in_group); |
| 401 | unsigned comp = first_comp + (dev - first_dev); |
| 402 | unsigned max_comp = ios->numdevs ? ios->numdevs - mirrors_p1 : 0; |
| 403 | unsigned cur_pg = ios->pages_consumed; |
Boaz Harrosh | 86093aa | 2010-01-28 18:24:06 +0200 | [diff] [blame] | 404 | int ret = 0; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 405 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 406 | while (length) { |
| 407 | struct exofs_per_dev_state *per_dev = &ios->per_dev[comp]; |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 408 | unsigned cur_len, page_off = 0; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 409 | |
| 410 | if (!per_dev->length) { |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 411 | per_dev->dev = dev; |
| 412 | if (dev < si->dev) { |
| 413 | per_dev->offset = si->obj_offset + stripe_unit - |
| 414 | si->unit_off; |
| 415 | cur_len = stripe_unit; |
| 416 | } else if (dev == si->dev) { |
| 417 | per_dev->offset = si->obj_offset; |
| 418 | cur_len = stripe_unit - si->unit_off; |
| 419 | page_off = si->unit_off & ~PAGE_MASK; |
| 420 | BUG_ON(page_off && (page_off != ios->pgbase)); |
| 421 | } else { /* dev > si->dev */ |
| 422 | per_dev->offset = si->obj_offset - si->unit_off; |
| 423 | cur_len = stripe_unit; |
| 424 | } |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 425 | |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 426 | if (max_comp < comp) |
| 427 | max_comp = comp; |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 428 | |
| 429 | dev += mirrors_p1; |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 430 | dev = (dev % devs_in_group) + first_dev; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 431 | } else { |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 432 | cur_len = stripe_unit; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 433 | } |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 434 | if (cur_len >= length) |
| 435 | cur_len = length; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 436 | |
Boaz Harrosh | 86093aa | 2010-01-28 18:24:06 +0200 | [diff] [blame] | 437 | ret = _add_stripe_unit(ios, &cur_pg, page_off , per_dev, |
| 438 | cur_len); |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 439 | if (unlikely(ret)) |
| 440 | goto out; |
| 441 | |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 442 | comp += mirrors_p1; |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 443 | comp = (comp % devs_in_group) + first_comp; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 444 | |
| 445 | length -= cur_len; |
| 446 | } |
| 447 | out: |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 448 | ios->numdevs = max_comp + mirrors_p1; |
| 449 | ios->pages_consumed = cur_pg; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 450 | return ret; |
| 451 | } |
| 452 | |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 453 | static int _prepare_for_striping(struct exofs_io_state *ios) |
| 454 | { |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 455 | u64 length = ios->length; |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 456 | struct _striping_info si; |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 457 | unsigned devs_in_group = ios->layout->group_width * |
| 458 | ios->layout->mirrors_p1; |
| 459 | unsigned first_comp = 0; |
| 460 | int ret = 0; |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 461 | |
| 462 | _calc_stripe_info(ios, ios->offset, &si); |
| 463 | |
| 464 | if (!ios->pages) { |
| 465 | if (ios->kern_buff) { |
| 466 | struct exofs_per_dev_state *per_dev = &ios->per_dev[0]; |
| 467 | |
| 468 | per_dev->offset = si.obj_offset; |
| 469 | per_dev->dev = si.dev; |
| 470 | |
| 471 | /* no cross device without page array */ |
| 472 | BUG_ON((ios->layout->group_width > 1) && |
| 473 | (si.unit_off + ios->length > |
| 474 | ios->layout->stripe_unit)); |
| 475 | } |
| 476 | ios->numdevs = ios->layout->mirrors_p1; |
| 477 | return 0; |
| 478 | } |
| 479 | |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 480 | while (length) { |
| 481 | if (length < si.group_length) |
| 482 | si.group_length = length; |
| 483 | |
| 484 | ret = _prepare_one_group(ios, si.group_length, &si, first_comp); |
| 485 | if (unlikely(ret)) |
| 486 | goto out; |
| 487 | |
| 488 | length -= si.group_length; |
| 489 | |
| 490 | si.group_length = si.total_group_length; |
| 491 | si.unit_off = 0; |
| 492 | ++si.Major; |
| 493 | si.obj_offset = si.Major * ios->layout->stripe_unit * |
| 494 | ios->layout->group_depth; |
| 495 | |
| 496 | si.dev = (si.dev - (si.dev % devs_in_group)) + devs_in_group; |
| 497 | si.dev %= ios->layout->s_numdevs; |
| 498 | |
| 499 | first_comp += devs_in_group; |
| 500 | first_comp %= ios->layout->s_numdevs; |
| 501 | } |
| 502 | |
| 503 | out: |
| 504 | return ret; |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 505 | } |
| 506 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 507 | int exofs_sbi_create(struct exofs_io_state *ios) |
| 508 | { |
| 509 | int i, ret; |
| 510 | |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 511 | for (i = 0; i < ios->layout->s_numdevs; i++) { |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 512 | struct osd_request *or; |
| 513 | |
Boaz Harrosh | d9c740d | 2010-01-28 11:58:08 +0200 | [diff] [blame] | 514 | or = osd_start_request(exofs_ios_od(ios, i), GFP_KERNEL); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 515 | if (unlikely(!or)) { |
| 516 | EXOFS_ERR("%s: osd_start_request failed\n", __func__); |
| 517 | ret = -ENOMEM; |
| 518 | goto out; |
| 519 | } |
| 520 | ios->per_dev[i].or = or; |
| 521 | ios->numdevs++; |
| 522 | |
| 523 | osd_req_create_object(or, &ios->obj); |
| 524 | } |
| 525 | ret = exofs_io_execute(ios); |
| 526 | |
| 527 | out: |
| 528 | return ret; |
| 529 | } |
| 530 | |
| 531 | int exofs_sbi_remove(struct exofs_io_state *ios) |
| 532 | { |
| 533 | int i, ret; |
| 534 | |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 535 | for (i = 0; i < ios->layout->s_numdevs; i++) { |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 536 | struct osd_request *or; |
| 537 | |
Boaz Harrosh | d9c740d | 2010-01-28 11:58:08 +0200 | [diff] [blame] | 538 | or = osd_start_request(exofs_ios_od(ios, i), GFP_KERNEL); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 539 | if (unlikely(!or)) { |
| 540 | EXOFS_ERR("%s: osd_start_request failed\n", __func__); |
| 541 | ret = -ENOMEM; |
| 542 | goto out; |
| 543 | } |
| 544 | ios->per_dev[i].or = or; |
| 545 | ios->numdevs++; |
| 546 | |
| 547 | osd_req_remove_object(or, &ios->obj); |
| 548 | } |
| 549 | ret = exofs_io_execute(ios); |
| 550 | |
| 551 | out: |
| 552 | return ret; |
| 553 | } |
| 554 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 555 | static int _sbi_write_mirror(struct exofs_io_state *ios, int cur_comp) |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 556 | { |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 557 | struct exofs_per_dev_state *master_dev = &ios->per_dev[cur_comp]; |
| 558 | unsigned dev = ios->per_dev[cur_comp].dev; |
| 559 | unsigned last_comp = cur_comp + ios->layout->mirrors_p1; |
| 560 | int ret = 0; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 561 | |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 562 | if (ios->pages && !master_dev->length) |
| 563 | return 0; /* Just an empty slot */ |
| 564 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 565 | for (; cur_comp < last_comp; ++cur_comp, ++dev) { |
| 566 | struct exofs_per_dev_state *per_dev = &ios->per_dev[cur_comp]; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 567 | struct osd_request *or; |
| 568 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 569 | or = osd_start_request(exofs_ios_od(ios, dev), GFP_KERNEL); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 570 | if (unlikely(!or)) { |
| 571 | EXOFS_ERR("%s: osd_start_request failed\n", __func__); |
| 572 | ret = -ENOMEM; |
| 573 | goto out; |
| 574 | } |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 575 | per_dev->or = or; |
| 576 | per_dev->offset = master_dev->offset; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 577 | |
Boaz Harrosh | 86093aa | 2010-01-28 18:24:06 +0200 | [diff] [blame] | 578 | if (ios->pages) { |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 579 | struct bio *bio; |
| 580 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 581 | if (per_dev != master_dev) { |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 582 | bio = bio_kmalloc(GFP_KERNEL, |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 583 | master_dev->bio->bi_max_vecs); |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 584 | if (unlikely(!bio)) { |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 585 | EXOFS_DBGMSG( |
| 586 | "Faild to allocate BIO size=%u\n", |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 587 | master_dev->bio->bi_max_vecs); |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 588 | ret = -ENOMEM; |
| 589 | goto out; |
| 590 | } |
| 591 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 592 | __bio_clone(bio, master_dev->bio); |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 593 | bio->bi_bdev = NULL; |
| 594 | bio->bi_next = NULL; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 595 | per_dev->length = master_dev->length; |
| 596 | per_dev->bio = bio; |
| 597 | per_dev->dev = dev; |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 598 | } else { |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 599 | bio = master_dev->bio; |
| 600 | /* FIXME: bio_set_dir() */ |
| 601 | bio->bi_rw |= (1 << BIO_RW); |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 602 | } |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 603 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 604 | osd_req_write(or, &ios->obj, per_dev->offset, bio, |
| 605 | per_dev->length); |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 606 | EXOFS_DBGMSG("write(0x%llx) offset=0x%llx " |
| 607 | "length=0x%llx dev=%d\n", |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 608 | _LLU(ios->obj.id), _LLU(per_dev->offset), |
| 609 | _LLU(per_dev->length), dev); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 610 | } else if (ios->kern_buff) { |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 611 | ret = osd_req_write_kern(or, &ios->obj, per_dev->offset, |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 612 | ios->kern_buff, ios->length); |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 613 | if (unlikely(ret)) |
| 614 | goto out; |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 615 | EXOFS_DBGMSG2("write_kern(0x%llx) offset=0x%llx " |
| 616 | "length=0x%llx dev=%d\n", |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 617 | _LLU(ios->obj.id), _LLU(per_dev->offset), |
| 618 | _LLU(ios->length), dev); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 619 | } else { |
| 620 | osd_req_set_attributes(or, &ios->obj); |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 621 | EXOFS_DBGMSG2("obj(0x%llx) set_attributes=%d dev=%d\n", |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 622 | _LLU(ios->obj.id), ios->out_attr_len, dev); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | if (ios->out_attr) |
| 626 | osd_req_add_set_attr_list(or, ios->out_attr, |
| 627 | ios->out_attr_len); |
| 628 | |
| 629 | if (ios->in_attr) |
| 630 | osd_req_add_get_attr_list(or, ios->in_attr, |
| 631 | ios->in_attr_len); |
| 632 | } |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 633 | |
| 634 | out: |
| 635 | return ret; |
| 636 | } |
| 637 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 638 | int exofs_sbi_write(struct exofs_io_state *ios) |
| 639 | { |
| 640 | int i; |
| 641 | int ret; |
| 642 | |
| 643 | ret = _prepare_for_striping(ios); |
| 644 | if (unlikely(ret)) |
| 645 | return ret; |
| 646 | |
| 647 | for (i = 0; i < ios->numdevs; i += ios->layout->mirrors_p1) { |
| 648 | ret = _sbi_write_mirror(ios, i); |
| 649 | if (unlikely(ret)) |
| 650 | return ret; |
| 651 | } |
| 652 | |
| 653 | ret = exofs_io_execute(ios); |
| 654 | return ret; |
| 655 | } |
| 656 | |
| 657 | static int _sbi_read_mirror(struct exofs_io_state *ios, unsigned cur_comp) |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 658 | { |
Boaz Harrosh | 46f4d97 | 2010-02-01 11:37:30 +0200 | [diff] [blame] | 659 | struct osd_request *or; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 660 | struct exofs_per_dev_state *per_dev = &ios->per_dev[cur_comp]; |
Boaz Harrosh | 46f4d97 | 2010-02-01 11:37:30 +0200 | [diff] [blame] | 661 | unsigned first_dev = (unsigned)ios->obj.id; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 662 | |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame^] | 663 | if (ios->pages && !per_dev->length) |
| 664 | return 0; /* Just an empty slot */ |
| 665 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 666 | first_dev = per_dev->dev + first_dev % ios->layout->mirrors_p1; |
Boaz Harrosh | d9c740d | 2010-01-28 11:58:08 +0200 | [diff] [blame] | 667 | or = osd_start_request(exofs_ios_od(ios, first_dev), GFP_KERNEL); |
Boaz Harrosh | 46f4d97 | 2010-02-01 11:37:30 +0200 | [diff] [blame] | 668 | if (unlikely(!or)) { |
| 669 | EXOFS_ERR("%s: osd_start_request failed\n", __func__); |
| 670 | return -ENOMEM; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 671 | } |
Boaz Harrosh | 46f4d97 | 2010-02-01 11:37:30 +0200 | [diff] [blame] | 672 | per_dev->or = or; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 673 | |
Boaz Harrosh | 86093aa | 2010-01-28 18:24:06 +0200 | [diff] [blame] | 674 | if (ios->pages) { |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 675 | osd_req_read(or, &ios->obj, per_dev->offset, |
| 676 | per_dev->bio, per_dev->length); |
Boaz Harrosh | 46f4d97 | 2010-02-01 11:37:30 +0200 | [diff] [blame] | 677 | EXOFS_DBGMSG("read(0x%llx) offset=0x%llx length=0x%llx" |
| 678 | " dev=%d\n", _LLU(ios->obj.id), |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 679 | _LLU(per_dev->offset), _LLU(per_dev->length), |
Boaz Harrosh | 46f4d97 | 2010-02-01 11:37:30 +0200 | [diff] [blame] | 680 | first_dev); |
| 681 | } else if (ios->kern_buff) { |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 682 | int ret = osd_req_read_kern(or, &ios->obj, per_dev->offset, |
Boaz Harrosh | 46f4d97 | 2010-02-01 11:37:30 +0200 | [diff] [blame] | 683 | ios->kern_buff, ios->length); |
Boaz Harrosh | 46f4d97 | 2010-02-01 11:37:30 +0200 | [diff] [blame] | 684 | EXOFS_DBGMSG2("read_kern(0x%llx) offset=0x%llx " |
| 685 | "length=0x%llx dev=%d ret=>%d\n", |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 686 | _LLU(ios->obj.id), _LLU(per_dev->offset), |
Boaz Harrosh | 46f4d97 | 2010-02-01 11:37:30 +0200 | [diff] [blame] | 687 | _LLU(ios->length), first_dev, ret); |
| 688 | if (unlikely(ret)) |
| 689 | return ret; |
| 690 | } else { |
| 691 | osd_req_get_attributes(or, &ios->obj); |
| 692 | EXOFS_DBGMSG2("obj(0x%llx) get_attributes=%d dev=%d\n", |
| 693 | _LLU(ios->obj.id), ios->in_attr_len, first_dev); |
| 694 | } |
Boaz Harrosh | 46f4d97 | 2010-02-01 11:37:30 +0200 | [diff] [blame] | 695 | if (ios->out_attr) |
| 696 | osd_req_add_set_attr_list(or, ios->out_attr, ios->out_attr_len); |
| 697 | |
| 698 | if (ios->in_attr) |
| 699 | osd_req_add_get_attr_list(or, ios->in_attr, ios->in_attr_len); |
| 700 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | int exofs_sbi_read(struct exofs_io_state *ios) |
| 705 | { |
| 706 | int i; |
| 707 | int ret; |
| 708 | |
| 709 | ret = _prepare_for_striping(ios); |
| 710 | if (unlikely(ret)) |
| 711 | return ret; |
| 712 | |
| 713 | for (i = 0; i < ios->numdevs; i += ios->layout->mirrors_p1) { |
| 714 | ret = _sbi_read_mirror(ios, i); |
| 715 | if (unlikely(ret)) |
| 716 | return ret; |
| 717 | } |
| 718 | |
| 719 | ret = exofs_io_execute(ios); |
| 720 | return ret; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | int extract_attr_from_ios(struct exofs_io_state *ios, struct osd_attr *attr) |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 724 | { |
| 725 | struct osd_attr cur_attr = {.attr_page = 0}; /* start with zeros */ |
| 726 | void *iter = NULL; |
| 727 | int nelem; |
| 728 | |
| 729 | do { |
| 730 | nelem = 1; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 731 | osd_req_decode_get_attr_list(ios->per_dev[0].or, |
| 732 | &cur_attr, &nelem, &iter); |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 733 | if ((cur_attr.attr_page == attr->attr_page) && |
| 734 | (cur_attr.attr_id == attr->attr_id)) { |
| 735 | attr->len = cur_attr.len; |
| 736 | attr->val_ptr = cur_attr.val_ptr; |
| 737 | return 0; |
| 738 | } |
| 739 | } while (iter); |
| 740 | |
| 741 | return -EIO; |
| 742 | } |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 743 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 744 | static int _truncate_mirrors(struct exofs_io_state *ios, unsigned cur_comp, |
| 745 | struct osd_attr *attr) |
| 746 | { |
| 747 | int last_comp = cur_comp + ios->layout->mirrors_p1; |
| 748 | |
| 749 | for (; cur_comp < last_comp; ++cur_comp) { |
| 750 | struct exofs_per_dev_state *per_dev = &ios->per_dev[cur_comp]; |
| 751 | struct osd_request *or; |
| 752 | |
| 753 | or = osd_start_request(exofs_ios_od(ios, cur_comp), GFP_KERNEL); |
| 754 | if (unlikely(!or)) { |
| 755 | EXOFS_ERR("%s: osd_start_request failed\n", __func__); |
| 756 | return -ENOMEM; |
| 757 | } |
| 758 | per_dev->or = or; |
| 759 | |
| 760 | osd_req_set_attributes(or, &ios->obj); |
| 761 | osd_req_add_set_attr_list(or, attr, 1); |
| 762 | } |
| 763 | |
| 764 | return 0; |
| 765 | } |
| 766 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 767 | int exofs_oi_truncate(struct exofs_i_info *oi, u64 size) |
| 768 | { |
| 769 | struct exofs_sb_info *sbi = oi->vfs_inode.i_sb->s_fs_info; |
| 770 | struct exofs_io_state *ios; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 771 | struct exofs_trunc_attr { |
| 772 | struct osd_attr attr; |
| 773 | __be64 newsize; |
| 774 | } *size_attrs; |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 775 | struct _striping_info si; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 776 | int i, ret; |
| 777 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 778 | ret = exofs_get_io_state(&sbi->layout, &ios); |
| 779 | if (unlikely(ret)) |
| 780 | return ret; |
| 781 | |
| 782 | size_attrs = kcalloc(ios->layout->group_width, sizeof(*size_attrs), |
| 783 | GFP_KERNEL); |
| 784 | if (unlikely(!size_attrs)) { |
| 785 | ret = -ENOMEM; |
| 786 | goto out; |
| 787 | } |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 788 | |
| 789 | ios->obj.id = exofs_oi_objno(oi); |
| 790 | ios->cred = oi->i_cred; |
| 791 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 792 | ios->numdevs = ios->layout->s_numdevs; |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 793 | _calc_stripe_info(ios, size, &si); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 794 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 795 | for (i = 0; i < ios->layout->group_width; ++i) { |
| 796 | struct exofs_trunc_attr *size_attr = &size_attrs[i]; |
| 797 | u64 obj_size; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 798 | |
Boaz Harrosh | b367e78 | 2010-02-07 19:18:58 +0200 | [diff] [blame] | 799 | if (i < si.dev) |
| 800 | obj_size = si.obj_offset + |
| 801 | ios->layout->stripe_unit - si.unit_off; |
| 802 | else if (i == si.dev) |
| 803 | obj_size = si.obj_offset; |
| 804 | else /* i > si.dev */ |
| 805 | obj_size = si.obj_offset - si.unit_off; |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 806 | |
| 807 | size_attr->newsize = cpu_to_be64(obj_size); |
| 808 | size_attr->attr = g_attr_logical_length; |
| 809 | size_attr->attr.val_ptr = &size_attr->newsize; |
| 810 | |
| 811 | ret = _truncate_mirrors(ios, i * ios->layout->mirrors_p1, |
| 812 | &size_attr->attr); |
| 813 | if (unlikely(ret)) |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 814 | goto out; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 815 | } |
| 816 | ret = exofs_io_execute(ios); |
| 817 | |
| 818 | out: |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 819 | kfree(size_attrs); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 820 | exofs_put_io_state(ios); |
| 821 | return ret; |
| 822 | } |