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