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