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