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