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