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