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