Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005, 2006 |
Boaz Harrosh | 27d2e14 | 2009-06-14 17:23:09 +0300 | [diff] [blame] | 3 | * Avishay Traeger (avishay@gmail.com) |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 4 | * Copyright (C) 2008, 2009 |
| 5 | * Boaz Harrosh <bharrosh@panasas.com> |
| 6 | * |
| 7 | * This file is part of exofs. |
| 8 | * |
| 9 | * exofs is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation. Since it is based on ext2, and the only |
| 12 | * valid version of GPL for the Linux kernel is version 2, the only valid |
| 13 | * version of GPL for exofs is version 2. |
| 14 | * |
| 15 | * exofs is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with exofs; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | */ |
| 24 | |
| 25 | #include <scsi/scsi_device.h> |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 26 | |
| 27 | #include "exofs.h" |
| 28 | |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 29 | #define EXOFS_DBGMSG2(M...) do {} while (0) |
| 30 | /* #define EXOFS_DBGMSG2 EXOFS_DBGMSG */ |
| 31 | |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 32 | void exofs_make_credential(u8 cred_a[OSD_CAP_LEN], const struct osd_obj_id *obj) |
| 33 | { |
| 34 | osd_sec_init_nosec_doall_caps(cred_a, obj, false, true); |
| 35 | } |
| 36 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 37 | int exofs_read_kern(struct osd_dev *od, u8 *cred, struct osd_obj_id *obj, |
| 38 | u64 offset, void *p, unsigned length) |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 39 | { |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 40 | struct osd_request *or = osd_start_request(od, GFP_KERNEL); |
| 41 | /* struct osd_sense_info osi = {.key = 0};*/ |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 42 | int ret; |
| 43 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 44 | if (unlikely(!or)) { |
| 45 | EXOFS_DBGMSG("%s: osd_start_request failed.\n", __func__); |
| 46 | return -ENOMEM; |
| 47 | } |
| 48 | ret = osd_req_read_kern(or, obj, offset, p, length); |
| 49 | if (unlikely(ret)) { |
| 50 | EXOFS_DBGMSG("%s: osd_req_read_kern failed.\n", __func__); |
| 51 | goto out; |
| 52 | } |
| 53 | |
| 54 | ret = osd_finalize_request(or, 0, cred, NULL); |
| 55 | if (unlikely(ret)) { |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 56 | EXOFS_DBGMSG("Faild to osd_finalize_request() => %d\n", ret); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 57 | goto out; |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | ret = osd_execute_request(or); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 61 | if (unlikely(ret)) |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 62 | EXOFS_DBGMSG("osd_execute_request() => %d\n", ret); |
| 63 | /* osd_req_decode_sense(or, ret); */ |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 64 | |
| 65 | out: |
| 66 | osd_end_request(or); |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 67 | return ret; |
| 68 | } |
| 69 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 70 | int exofs_get_io_state(struct exofs_sb_info *sbi, struct exofs_io_state** pios) |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 71 | { |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 72 | struct exofs_io_state *ios; |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 73 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 74 | /*TODO: Maybe use kmem_cach per sbi of size |
| 75 | * exofs_io_state_size(sbi->s_numdevs) |
| 76 | */ |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 77 | ios = kzalloc(exofs_io_state_size(sbi->s_numdevs), GFP_KERNEL); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 78 | if (unlikely(!ios)) { |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 79 | EXOFS_DBGMSG("Faild kzalloc bytes=%d\n", |
| 80 | exofs_io_state_size(sbi->s_numdevs)); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 81 | *pios = NULL; |
| 82 | return -ENOMEM; |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 85 | ios->sbi = sbi; |
| 86 | ios->obj.partition = sbi->s_pid; |
| 87 | *pios = ios; |
| 88 | return 0; |
| 89 | } |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 90 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 91 | void exofs_put_io_state(struct exofs_io_state *ios) |
| 92 | { |
| 93 | if (ios) { |
| 94 | unsigned i; |
| 95 | |
| 96 | for (i = 0; i < ios->numdevs; i++) { |
| 97 | struct exofs_per_dev_state *per_dev = &ios->per_dev[i]; |
| 98 | |
| 99 | if (per_dev->or) |
| 100 | osd_end_request(per_dev->or); |
| 101 | if (per_dev->bio) |
| 102 | bio_put(per_dev->bio); |
| 103 | } |
| 104 | |
| 105 | kfree(ios); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | static void _sync_done(struct exofs_io_state *ios, void *p) |
| 110 | { |
| 111 | struct completion *waiting = p; |
| 112 | |
| 113 | complete(waiting); |
| 114 | } |
| 115 | |
| 116 | static void _last_io(struct kref *kref) |
| 117 | { |
| 118 | struct exofs_io_state *ios = container_of( |
| 119 | kref, struct exofs_io_state, kref); |
| 120 | |
| 121 | ios->done(ios, ios->private); |
| 122 | } |
| 123 | |
| 124 | static void _done_io(struct osd_request *or, void *p) |
| 125 | { |
| 126 | struct exofs_io_state *ios = p; |
| 127 | |
| 128 | kref_put(&ios->kref, _last_io); |
| 129 | } |
| 130 | |
| 131 | static int exofs_io_execute(struct exofs_io_state *ios) |
| 132 | { |
| 133 | DECLARE_COMPLETION_ONSTACK(wait); |
| 134 | bool sync = (ios->done == NULL); |
| 135 | int i, ret; |
| 136 | |
| 137 | if (sync) { |
| 138 | ios->done = _sync_done; |
| 139 | ios->private = &wait; |
| 140 | } |
| 141 | |
| 142 | for (i = 0; i < ios->numdevs; i++) { |
| 143 | struct osd_request *or = ios->per_dev[i].or; |
| 144 | if (unlikely(!or)) |
| 145 | continue; |
| 146 | |
| 147 | ret = osd_finalize_request(or, 0, ios->cred, NULL); |
| 148 | if (unlikely(ret)) { |
| 149 | EXOFS_DBGMSG("Faild to osd_finalize_request() => %d\n", |
| 150 | ret); |
| 151 | return ret; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | kref_init(&ios->kref); |
| 156 | |
| 157 | for (i = 0; i < ios->numdevs; i++) { |
| 158 | struct osd_request *or = ios->per_dev[i].or; |
| 159 | if (unlikely(!or)) |
| 160 | continue; |
| 161 | |
| 162 | kref_get(&ios->kref); |
| 163 | osd_execute_request_async(or, _done_io, ios); |
| 164 | } |
| 165 | |
| 166 | kref_put(&ios->kref, _last_io); |
| 167 | ret = 0; |
| 168 | |
| 169 | if (sync) { |
| 170 | wait_for_completion(&wait); |
| 171 | ret = exofs_check_io(ios, NULL); |
| 172 | } |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 173 | return ret; |
| 174 | } |
| 175 | |
Boaz Harrosh | 22ddc55 | 2010-01-19 19:24:45 +0200 | [diff] [blame^] | 176 | static void _clear_bio(struct bio *bio) |
| 177 | { |
| 178 | struct bio_vec *bv; |
| 179 | unsigned i; |
| 180 | |
| 181 | __bio_for_each_segment(bv, bio, i, 0) { |
| 182 | unsigned this_count = bv->bv_len; |
| 183 | |
| 184 | if (likely(PAGE_SIZE == this_count)) |
| 185 | clear_highpage(bv->bv_page); |
| 186 | else |
| 187 | zero_user(bv->bv_page, bv->bv_offset, this_count); |
| 188 | } |
| 189 | } |
| 190 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 191 | int exofs_check_io(struct exofs_io_state *ios, u64 *resid) |
| 192 | { |
| 193 | enum osd_err_priority acumulated_osd_err = 0; |
| 194 | int acumulated_lin_err = 0; |
| 195 | int i; |
| 196 | |
| 197 | for (i = 0; i < ios->numdevs; i++) { |
| 198 | struct osd_sense_info osi; |
Boaz Harrosh | 22ddc55 | 2010-01-19 19:24:45 +0200 | [diff] [blame^] | 199 | struct osd_request *or = ios->per_dev[i].or; |
| 200 | int ret; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 201 | |
Boaz Harrosh | 22ddc55 | 2010-01-19 19:24:45 +0200 | [diff] [blame^] | 202 | if (unlikely(!or)) |
| 203 | continue; |
| 204 | |
| 205 | ret = osd_req_decode_sense(or, &osi); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 206 | if (likely(!ret)) |
| 207 | continue; |
| 208 | |
Boaz Harrosh | 22ddc55 | 2010-01-19 19:24:45 +0200 | [diff] [blame^] | 209 | if (OSD_ERR_PRI_CLEAR_PAGES == osi.osd_err_pri) { |
| 210 | /* start read offset passed endof file */ |
| 211 | _clear_bio(ios->per_dev[i].bio); |
| 212 | EXOFS_DBGMSG("start read offset passed end of file " |
| 213 | "offset=0x%llx, length=0x%llx\n", |
| 214 | _LLU(ios->offset), |
| 215 | _LLU(ios->length)); |
| 216 | |
| 217 | continue; /* we recovered */ |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | if (osi.osd_err_pri >= acumulated_osd_err) { |
| 221 | acumulated_osd_err = osi.osd_err_pri; |
| 222 | acumulated_lin_err = ret; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | /* TODO: raid specific residual calculations */ |
| 227 | if (resid) { |
| 228 | if (likely(!acumulated_lin_err)) |
| 229 | *resid = 0; |
| 230 | else |
| 231 | *resid = ios->length; |
| 232 | } |
| 233 | |
| 234 | return acumulated_lin_err; |
| 235 | } |
| 236 | |
| 237 | int exofs_sbi_create(struct exofs_io_state *ios) |
| 238 | { |
| 239 | int i, ret; |
| 240 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 241 | for (i = 0; i < ios->sbi->s_numdevs; i++) { |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 242 | struct osd_request *or; |
| 243 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 244 | or = osd_start_request(ios->sbi->s_ods[i], GFP_KERNEL); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 245 | if (unlikely(!or)) { |
| 246 | EXOFS_ERR("%s: osd_start_request failed\n", __func__); |
| 247 | ret = -ENOMEM; |
| 248 | goto out; |
| 249 | } |
| 250 | ios->per_dev[i].or = or; |
| 251 | ios->numdevs++; |
| 252 | |
| 253 | osd_req_create_object(or, &ios->obj); |
| 254 | } |
| 255 | ret = exofs_io_execute(ios); |
| 256 | |
| 257 | out: |
| 258 | return ret; |
| 259 | } |
| 260 | |
| 261 | int exofs_sbi_remove(struct exofs_io_state *ios) |
| 262 | { |
| 263 | int i, ret; |
| 264 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 265 | for (i = 0; i < ios->sbi->s_numdevs; i++) { |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 266 | struct osd_request *or; |
| 267 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 268 | or = osd_start_request(ios->sbi->s_ods[i], GFP_KERNEL); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 269 | if (unlikely(!or)) { |
| 270 | EXOFS_ERR("%s: osd_start_request failed\n", __func__); |
| 271 | ret = -ENOMEM; |
| 272 | goto out; |
| 273 | } |
| 274 | ios->per_dev[i].or = or; |
| 275 | ios->numdevs++; |
| 276 | |
| 277 | osd_req_remove_object(or, &ios->obj); |
| 278 | } |
| 279 | ret = exofs_io_execute(ios); |
| 280 | |
| 281 | out: |
| 282 | return ret; |
| 283 | } |
| 284 | |
| 285 | int exofs_sbi_write(struct exofs_io_state *ios) |
| 286 | { |
| 287 | int i, ret; |
| 288 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 289 | for (i = 0; i < ios->sbi->s_numdevs; i++) { |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 290 | struct osd_request *or; |
| 291 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 292 | or = osd_start_request(ios->sbi->s_ods[i], GFP_KERNEL); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 293 | if (unlikely(!or)) { |
| 294 | EXOFS_ERR("%s: osd_start_request failed\n", __func__); |
| 295 | ret = -ENOMEM; |
| 296 | goto out; |
| 297 | } |
| 298 | ios->per_dev[i].or = or; |
| 299 | ios->numdevs++; |
| 300 | |
| 301 | if (ios->bio) { |
| 302 | struct bio *bio; |
| 303 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 304 | if (i != 0) { |
| 305 | bio = bio_kmalloc(GFP_KERNEL, |
| 306 | ios->bio->bi_max_vecs); |
| 307 | if (unlikely(!bio)) { |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 308 | EXOFS_DBGMSG( |
| 309 | "Faild to allocate BIO size=%u\n", |
| 310 | ios->bio->bi_max_vecs); |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 311 | ret = -ENOMEM; |
| 312 | goto out; |
| 313 | } |
| 314 | |
| 315 | __bio_clone(bio, ios->bio); |
| 316 | bio->bi_bdev = NULL; |
| 317 | bio->bi_next = NULL; |
| 318 | ios->per_dev[i].bio = bio; |
| 319 | } else { |
| 320 | bio = ios->bio; |
| 321 | } |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 322 | |
| 323 | osd_req_write(or, &ios->obj, ios->offset, bio, |
| 324 | ios->length); |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 325 | EXOFS_DBGMSG("write(0x%llx) offset=0x%llx " |
| 326 | "length=0x%llx dev=%d\n", |
| 327 | _LLU(ios->obj.id), _LLU(ios->offset), |
| 328 | _LLU(ios->length), i); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 329 | } else if (ios->kern_buff) { |
| 330 | osd_req_write_kern(or, &ios->obj, ios->offset, |
| 331 | ios->kern_buff, ios->length); |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 332 | EXOFS_DBGMSG2("write_kern(0x%llx) offset=0x%llx " |
| 333 | "length=0x%llx dev=%d\n", |
| 334 | _LLU(ios->obj.id), _LLU(ios->offset), |
| 335 | _LLU(ios->length), i); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 336 | } else { |
| 337 | osd_req_set_attributes(or, &ios->obj); |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 338 | EXOFS_DBGMSG2("obj(0x%llx) set_attributes=%d dev=%d\n", |
| 339 | _LLU(ios->obj.id), ios->out_attr_len, i); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | if (ios->out_attr) |
| 343 | osd_req_add_set_attr_list(or, ios->out_attr, |
| 344 | ios->out_attr_len); |
| 345 | |
| 346 | if (ios->in_attr) |
| 347 | osd_req_add_get_attr_list(or, ios->in_attr, |
| 348 | ios->in_attr_len); |
| 349 | } |
| 350 | ret = exofs_io_execute(ios); |
| 351 | |
| 352 | out: |
| 353 | return ret; |
| 354 | } |
| 355 | |
| 356 | int exofs_sbi_read(struct exofs_io_state *ios) |
| 357 | { |
| 358 | int i, ret; |
| 359 | |
| 360 | for (i = 0; i < 1; i++) { |
| 361 | struct osd_request *or; |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 362 | unsigned first_dev = (unsigned)ios->obj.id; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 363 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 364 | first_dev %= ios->sbi->s_numdevs; |
| 365 | or = osd_start_request(ios->sbi->s_ods[first_dev], GFP_KERNEL); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 366 | if (unlikely(!or)) { |
| 367 | EXOFS_ERR("%s: osd_start_request failed\n", __func__); |
| 368 | ret = -ENOMEM; |
| 369 | goto out; |
| 370 | } |
| 371 | ios->per_dev[i].or = or; |
| 372 | ios->numdevs++; |
| 373 | |
| 374 | if (ios->bio) { |
| 375 | osd_req_read(or, &ios->obj, ios->offset, ios->bio, |
| 376 | ios->length); |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 377 | EXOFS_DBGMSG("read(0x%llx) offset=0x%llx length=0x%llx" |
| 378 | " dev=%d\n", _LLU(ios->obj.id), |
| 379 | _LLU(ios->offset), |
| 380 | _LLU(ios->length), |
| 381 | first_dev); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 382 | } else if (ios->kern_buff) { |
| 383 | osd_req_read_kern(or, &ios->obj, ios->offset, |
| 384 | ios->kern_buff, ios->length); |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 385 | EXOFS_DBGMSG2("read_kern(0x%llx) offset=0x%llx " |
| 386 | "length=0x%llx dev=%d\n", |
| 387 | _LLU(ios->obj.id), |
| 388 | _LLU(ios->offset), |
| 389 | _LLU(ios->length), |
| 390 | first_dev); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 391 | } else { |
| 392 | osd_req_get_attributes(or, &ios->obj); |
Boaz Harrosh | 34ce4e7 | 2009-12-15 19:34:17 +0200 | [diff] [blame] | 393 | EXOFS_DBGMSG2("obj(0x%llx) get_attributes=%d dev=%d\n", |
| 394 | _LLU(ios->obj.id), ios->in_attr_len, |
| 395 | first_dev); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | if (ios->out_attr) |
| 399 | osd_req_add_set_attr_list(or, ios->out_attr, |
| 400 | ios->out_attr_len); |
| 401 | |
| 402 | if (ios->in_attr) |
| 403 | osd_req_add_get_attr_list(or, ios->in_attr, |
| 404 | ios->in_attr_len); |
| 405 | } |
| 406 | ret = exofs_io_execute(ios); |
| 407 | |
| 408 | out: |
| 409 | return ret; |
| 410 | } |
| 411 | |
| 412 | 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] | 413 | { |
| 414 | struct osd_attr cur_attr = {.attr_page = 0}; /* start with zeros */ |
| 415 | void *iter = NULL; |
| 416 | int nelem; |
| 417 | |
| 418 | do { |
| 419 | nelem = 1; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 420 | osd_req_decode_get_attr_list(ios->per_dev[0].or, |
| 421 | &cur_attr, &nelem, &iter); |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 422 | if ((cur_attr.attr_page == attr->attr_page) && |
| 423 | (cur_attr.attr_id == attr->attr_id)) { |
| 424 | attr->len = cur_attr.len; |
| 425 | attr->val_ptr = cur_attr.val_ptr; |
| 426 | return 0; |
| 427 | } |
| 428 | } while (iter); |
| 429 | |
| 430 | return -EIO; |
| 431 | } |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 432 | |
| 433 | int exofs_oi_truncate(struct exofs_i_info *oi, u64 size) |
| 434 | { |
| 435 | struct exofs_sb_info *sbi = oi->vfs_inode.i_sb->s_fs_info; |
| 436 | struct exofs_io_state *ios; |
| 437 | struct osd_attr attr; |
| 438 | __be64 newsize; |
| 439 | int i, ret; |
| 440 | |
| 441 | if (exofs_get_io_state(sbi, &ios)) |
| 442 | return -ENOMEM; |
| 443 | |
| 444 | ios->obj.id = exofs_oi_objno(oi); |
| 445 | ios->cred = oi->i_cred; |
| 446 | |
| 447 | newsize = cpu_to_be64(size); |
| 448 | attr = g_attr_logical_length; |
| 449 | attr.val_ptr = &newsize; |
| 450 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 451 | for (i = 0; i < sbi->s_numdevs; i++) { |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 452 | struct osd_request *or; |
| 453 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 454 | or = osd_start_request(sbi->s_ods[i], GFP_KERNEL); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 455 | if (unlikely(!or)) { |
| 456 | EXOFS_ERR("%s: osd_start_request failed\n", __func__); |
| 457 | ret = -ENOMEM; |
| 458 | goto out; |
| 459 | } |
| 460 | ios->per_dev[i].or = or; |
| 461 | ios->numdevs++; |
| 462 | |
| 463 | osd_req_set_attributes(or, &ios->obj); |
| 464 | osd_req_add_set_attr_list(or, &attr, 1); |
| 465 | } |
| 466 | ret = exofs_io_execute(ios); |
| 467 | |
| 468 | out: |
| 469 | exofs_put_io_state(ios); |
| 470 | return ret; |
| 471 | } |