Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 2 | #include <linux/ceph/ceph_debug.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 3 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 5 | #include <linux/slab.h> |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 6 | #include <asm/div64.h> |
| 7 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 8 | #include <linux/ceph/libceph.h> |
| 9 | #include <linux/ceph/osdmap.h> |
| 10 | #include <linux/ceph/decode.h> |
| 11 | #include <linux/crush/hash.h> |
| 12 | #include <linux/crush/mapper.h> |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 13 | |
| 14 | char *ceph_osdmap_state_str(char *str, int len, int state) |
| 15 | { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 16 | if (!len) |
Cong Ding | 1ec3911 | 2013-01-25 17:48:59 -0600 | [diff] [blame] | 17 | return str; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 18 | |
Cong Ding | 1ec3911 | 2013-01-25 17:48:59 -0600 | [diff] [blame] | 19 | if ((state & CEPH_OSD_EXISTS) && (state & CEPH_OSD_UP)) |
| 20 | snprintf(str, len, "exists, up"); |
| 21 | else if (state & CEPH_OSD_EXISTS) |
| 22 | snprintf(str, len, "exists"); |
| 23 | else if (state & CEPH_OSD_UP) |
| 24 | snprintf(str, len, "up"); |
| 25 | else |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 26 | snprintf(str, len, "doesn't exist"); |
Cong Ding | 1ec3911 | 2013-01-25 17:48:59 -0600 | [diff] [blame] | 27 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 28 | return str; |
| 29 | } |
| 30 | |
| 31 | /* maps */ |
| 32 | |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 33 | static int calc_bits_of(unsigned int t) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 34 | { |
| 35 | int b = 0; |
| 36 | while (t) { |
| 37 | t = t >> 1; |
| 38 | b++; |
| 39 | } |
| 40 | return b; |
| 41 | } |
| 42 | |
| 43 | /* |
| 44 | * the foo_mask is the smallest value 2^n-1 that is >= foo. |
| 45 | */ |
| 46 | static void calc_pg_masks(struct ceph_pg_pool_info *pi) |
| 47 | { |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 48 | pi->pg_num_mask = (1 << calc_bits_of(pi->pg_num-1)) - 1; |
| 49 | pi->pgp_num_mask = (1 << calc_bits_of(pi->pgp_num-1)) - 1; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /* |
| 53 | * decode crush map |
| 54 | */ |
| 55 | static int crush_decode_uniform_bucket(void **p, void *end, |
| 56 | struct crush_bucket_uniform *b) |
| 57 | { |
| 58 | dout("crush_decode_uniform_bucket %p to %p\n", *p, end); |
| 59 | ceph_decode_need(p, end, (1+b->h.size) * sizeof(u32), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 60 | b->item_weight = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 61 | return 0; |
| 62 | bad: |
| 63 | return -EINVAL; |
| 64 | } |
| 65 | |
| 66 | static int crush_decode_list_bucket(void **p, void *end, |
| 67 | struct crush_bucket_list *b) |
| 68 | { |
| 69 | int j; |
| 70 | dout("crush_decode_list_bucket %p to %p\n", *p, end); |
| 71 | b->item_weights = kcalloc(b->h.size, sizeof(u32), GFP_NOFS); |
| 72 | if (b->item_weights == NULL) |
| 73 | return -ENOMEM; |
| 74 | b->sum_weights = kcalloc(b->h.size, sizeof(u32), GFP_NOFS); |
| 75 | if (b->sum_weights == NULL) |
| 76 | return -ENOMEM; |
| 77 | ceph_decode_need(p, end, 2 * b->h.size * sizeof(u32), bad); |
| 78 | for (j = 0; j < b->h.size; j++) { |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 79 | b->item_weights[j] = ceph_decode_32(p); |
| 80 | b->sum_weights[j] = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 81 | } |
| 82 | return 0; |
| 83 | bad: |
| 84 | return -EINVAL; |
| 85 | } |
| 86 | |
| 87 | static int crush_decode_tree_bucket(void **p, void *end, |
| 88 | struct crush_bucket_tree *b) |
| 89 | { |
| 90 | int j; |
| 91 | dout("crush_decode_tree_bucket %p to %p\n", *p, end); |
| 92 | ceph_decode_32_safe(p, end, b->num_nodes, bad); |
| 93 | b->node_weights = kcalloc(b->num_nodes, sizeof(u32), GFP_NOFS); |
| 94 | if (b->node_weights == NULL) |
| 95 | return -ENOMEM; |
| 96 | ceph_decode_need(p, end, b->num_nodes * sizeof(u32), bad); |
| 97 | for (j = 0; j < b->num_nodes; j++) |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 98 | b->node_weights[j] = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 99 | return 0; |
| 100 | bad: |
| 101 | return -EINVAL; |
| 102 | } |
| 103 | |
| 104 | static int crush_decode_straw_bucket(void **p, void *end, |
| 105 | struct crush_bucket_straw *b) |
| 106 | { |
| 107 | int j; |
| 108 | dout("crush_decode_straw_bucket %p to %p\n", *p, end); |
| 109 | b->item_weights = kcalloc(b->h.size, sizeof(u32), GFP_NOFS); |
| 110 | if (b->item_weights == NULL) |
| 111 | return -ENOMEM; |
| 112 | b->straws = kcalloc(b->h.size, sizeof(u32), GFP_NOFS); |
| 113 | if (b->straws == NULL) |
| 114 | return -ENOMEM; |
| 115 | ceph_decode_need(p, end, 2 * b->h.size * sizeof(u32), bad); |
| 116 | for (j = 0; j < b->h.size; j++) { |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 117 | b->item_weights[j] = ceph_decode_32(p); |
| 118 | b->straws[j] = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 119 | } |
| 120 | return 0; |
| 121 | bad: |
| 122 | return -EINVAL; |
| 123 | } |
| 124 | |
Sage Weil | 546f04e | 2012-07-30 18:15:23 -0700 | [diff] [blame] | 125 | static int skip_name_map(void **p, void *end) |
| 126 | { |
| 127 | int len; |
| 128 | ceph_decode_32_safe(p, end, len ,bad); |
| 129 | while (len--) { |
| 130 | int strlen; |
| 131 | *p += sizeof(u32); |
| 132 | ceph_decode_32_safe(p, end, strlen, bad); |
| 133 | *p += strlen; |
| 134 | } |
| 135 | return 0; |
| 136 | bad: |
| 137 | return -EINVAL; |
| 138 | } |
| 139 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 140 | static struct crush_map *crush_decode(void *pbyval, void *end) |
| 141 | { |
| 142 | struct crush_map *c; |
| 143 | int err = -EINVAL; |
| 144 | int i, j; |
| 145 | void **p = &pbyval; |
| 146 | void *start = pbyval; |
| 147 | u32 magic; |
Sage Weil | 546f04e | 2012-07-30 18:15:23 -0700 | [diff] [blame] | 148 | u32 num_name_maps; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 149 | |
| 150 | dout("crush_decode %p to %p len %d\n", *p, end, (int)(end - *p)); |
| 151 | |
| 152 | c = kzalloc(sizeof(*c), GFP_NOFS); |
| 153 | if (c == NULL) |
| 154 | return ERR_PTR(-ENOMEM); |
| 155 | |
Sage Weil | 546f04e | 2012-07-30 18:15:23 -0700 | [diff] [blame] | 156 | /* set tunables to default values */ |
| 157 | c->choose_local_tries = 2; |
| 158 | c->choose_local_fallback_tries = 5; |
| 159 | c->choose_total_tries = 19; |
Jim Schutt | 1604f48 | 2012-11-30 09:15:25 -0700 | [diff] [blame] | 160 | c->chooseleaf_descend_once = 0; |
Sage Weil | 546f04e | 2012-07-30 18:15:23 -0700 | [diff] [blame] | 161 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 162 | ceph_decode_need(p, end, 4*sizeof(u32), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 163 | magic = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 164 | if (magic != CRUSH_MAGIC) { |
| 165 | pr_err("crush_decode magic %x != current %x\n", |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 166 | (unsigned int)magic, (unsigned int)CRUSH_MAGIC); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 167 | goto bad; |
| 168 | } |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 169 | c->max_buckets = ceph_decode_32(p); |
| 170 | c->max_rules = ceph_decode_32(p); |
| 171 | c->max_devices = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 172 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 173 | c->buckets = kcalloc(c->max_buckets, sizeof(*c->buckets), GFP_NOFS); |
| 174 | if (c->buckets == NULL) |
| 175 | goto badmem; |
| 176 | c->rules = kcalloc(c->max_rules, sizeof(*c->rules), GFP_NOFS); |
| 177 | if (c->rules == NULL) |
| 178 | goto badmem; |
| 179 | |
| 180 | /* buckets */ |
| 181 | for (i = 0; i < c->max_buckets; i++) { |
| 182 | int size = 0; |
| 183 | u32 alg; |
| 184 | struct crush_bucket *b; |
| 185 | |
| 186 | ceph_decode_32_safe(p, end, alg, bad); |
| 187 | if (alg == 0) { |
| 188 | c->buckets[i] = NULL; |
| 189 | continue; |
| 190 | } |
| 191 | dout("crush_decode bucket %d off %x %p to %p\n", |
| 192 | i, (int)(*p-start), *p, end); |
| 193 | |
| 194 | switch (alg) { |
| 195 | case CRUSH_BUCKET_UNIFORM: |
| 196 | size = sizeof(struct crush_bucket_uniform); |
| 197 | break; |
| 198 | case CRUSH_BUCKET_LIST: |
| 199 | size = sizeof(struct crush_bucket_list); |
| 200 | break; |
| 201 | case CRUSH_BUCKET_TREE: |
| 202 | size = sizeof(struct crush_bucket_tree); |
| 203 | break; |
| 204 | case CRUSH_BUCKET_STRAW: |
| 205 | size = sizeof(struct crush_bucket_straw); |
| 206 | break; |
| 207 | default: |
Sage Weil | 30dc638 | 2009-12-21 14:49:37 -0800 | [diff] [blame] | 208 | err = -EINVAL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 209 | goto bad; |
| 210 | } |
| 211 | BUG_ON(size == 0); |
| 212 | b = c->buckets[i] = kzalloc(size, GFP_NOFS); |
| 213 | if (b == NULL) |
| 214 | goto badmem; |
| 215 | |
| 216 | ceph_decode_need(p, end, 4*sizeof(u32), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 217 | b->id = ceph_decode_32(p); |
| 218 | b->type = ceph_decode_16(p); |
Sage Weil | fb69039 | 2009-11-07 20:18:22 -0800 | [diff] [blame] | 219 | b->alg = ceph_decode_8(p); |
| 220 | b->hash = ceph_decode_8(p); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 221 | b->weight = ceph_decode_32(p); |
| 222 | b->size = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 223 | |
| 224 | dout("crush_decode bucket size %d off %x %p to %p\n", |
| 225 | b->size, (int)(*p-start), *p, end); |
| 226 | |
| 227 | b->items = kcalloc(b->size, sizeof(__s32), GFP_NOFS); |
| 228 | if (b->items == NULL) |
| 229 | goto badmem; |
| 230 | b->perm = kcalloc(b->size, sizeof(u32), GFP_NOFS); |
| 231 | if (b->perm == NULL) |
| 232 | goto badmem; |
| 233 | b->perm_n = 0; |
| 234 | |
| 235 | ceph_decode_need(p, end, b->size*sizeof(u32), bad); |
| 236 | for (j = 0; j < b->size; j++) |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 237 | b->items[j] = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 238 | |
| 239 | switch (b->alg) { |
| 240 | case CRUSH_BUCKET_UNIFORM: |
| 241 | err = crush_decode_uniform_bucket(p, end, |
| 242 | (struct crush_bucket_uniform *)b); |
| 243 | if (err < 0) |
| 244 | goto bad; |
| 245 | break; |
| 246 | case CRUSH_BUCKET_LIST: |
| 247 | err = crush_decode_list_bucket(p, end, |
| 248 | (struct crush_bucket_list *)b); |
| 249 | if (err < 0) |
| 250 | goto bad; |
| 251 | break; |
| 252 | case CRUSH_BUCKET_TREE: |
| 253 | err = crush_decode_tree_bucket(p, end, |
| 254 | (struct crush_bucket_tree *)b); |
| 255 | if (err < 0) |
| 256 | goto bad; |
| 257 | break; |
| 258 | case CRUSH_BUCKET_STRAW: |
| 259 | err = crush_decode_straw_bucket(p, end, |
| 260 | (struct crush_bucket_straw *)b); |
| 261 | if (err < 0) |
| 262 | goto bad; |
| 263 | break; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | /* rules */ |
| 268 | dout("rule vec is %p\n", c->rules); |
| 269 | for (i = 0; i < c->max_rules; i++) { |
| 270 | u32 yes; |
| 271 | struct crush_rule *r; |
| 272 | |
| 273 | ceph_decode_32_safe(p, end, yes, bad); |
| 274 | if (!yes) { |
| 275 | dout("crush_decode NO rule %d off %x %p to %p\n", |
| 276 | i, (int)(*p-start), *p, end); |
| 277 | c->rules[i] = NULL; |
| 278 | continue; |
| 279 | } |
| 280 | |
| 281 | dout("crush_decode rule %d off %x %p to %p\n", |
| 282 | i, (int)(*p-start), *p, end); |
| 283 | |
| 284 | /* len */ |
| 285 | ceph_decode_32_safe(p, end, yes, bad); |
| 286 | #if BITS_PER_LONG == 32 |
Sage Weil | 30dc638 | 2009-12-21 14:49:37 -0800 | [diff] [blame] | 287 | err = -EINVAL; |
Xi Wang | 6448669 | 2012-02-16 11:55:48 -0500 | [diff] [blame] | 288 | if (yes > (ULONG_MAX - sizeof(*r)) |
| 289 | / sizeof(struct crush_rule_step)) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 290 | goto bad; |
| 291 | #endif |
| 292 | r = c->rules[i] = kmalloc(sizeof(*r) + |
| 293 | yes*sizeof(struct crush_rule_step), |
| 294 | GFP_NOFS); |
| 295 | if (r == NULL) |
| 296 | goto badmem; |
| 297 | dout(" rule %d is at %p\n", i, r); |
| 298 | r->len = yes; |
| 299 | ceph_decode_copy_safe(p, end, &r->mask, 4, bad); /* 4 u8's */ |
| 300 | ceph_decode_need(p, end, r->len*3*sizeof(u32), bad); |
| 301 | for (j = 0; j < r->len; j++) { |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 302 | r->steps[j].op = ceph_decode_32(p); |
| 303 | r->steps[j].arg1 = ceph_decode_32(p); |
| 304 | r->steps[j].arg2 = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
| 308 | /* ignore trailing name maps. */ |
Sage Weil | 546f04e | 2012-07-30 18:15:23 -0700 | [diff] [blame] | 309 | for (num_name_maps = 0; num_name_maps < 3; num_name_maps++) { |
| 310 | err = skip_name_map(p, end); |
| 311 | if (err < 0) |
| 312 | goto done; |
| 313 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 314 | |
Sage Weil | 546f04e | 2012-07-30 18:15:23 -0700 | [diff] [blame] | 315 | /* tunables */ |
| 316 | ceph_decode_need(p, end, 3*sizeof(u32), done); |
| 317 | c->choose_local_tries = ceph_decode_32(p); |
| 318 | c->choose_local_fallback_tries = ceph_decode_32(p); |
| 319 | c->choose_total_tries = ceph_decode_32(p); |
| 320 | dout("crush decode tunable choose_local_tries = %d", |
| 321 | c->choose_local_tries); |
| 322 | dout("crush decode tunable choose_local_fallback_tries = %d", |
| 323 | c->choose_local_fallback_tries); |
| 324 | dout("crush decode tunable choose_total_tries = %d", |
| 325 | c->choose_total_tries); |
| 326 | |
Jim Schutt | 1604f48 | 2012-11-30 09:15:25 -0700 | [diff] [blame] | 327 | ceph_decode_need(p, end, sizeof(u32), done); |
| 328 | c->chooseleaf_descend_once = ceph_decode_32(p); |
| 329 | dout("crush decode tunable chooseleaf_descend_once = %d", |
| 330 | c->chooseleaf_descend_once); |
| 331 | |
Sage Weil | 546f04e | 2012-07-30 18:15:23 -0700 | [diff] [blame] | 332 | done: |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 333 | dout("crush_decode success\n"); |
| 334 | return c; |
| 335 | |
| 336 | badmem: |
| 337 | err = -ENOMEM; |
| 338 | bad: |
| 339 | dout("crush_decode fail %d\n", err); |
| 340 | crush_destroy(c); |
| 341 | return ERR_PTR(err); |
| 342 | } |
| 343 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 344 | /* |
Sage Weil | 9794b14 | 2010-02-16 15:53:32 -0800 | [diff] [blame] | 345 | * rbtree of pg_mapping for handling pg_temp (explicit mapping of pgid |
| 346 | * to a set of osds) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 347 | */ |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 348 | static int pgid_cmp(struct ceph_pg l, struct ceph_pg r) |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 349 | { |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 350 | if (l.pool < r.pool) |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 351 | return -1; |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 352 | if (l.pool > r.pool) |
| 353 | return 1; |
| 354 | if (l.seed < r.seed) |
| 355 | return -1; |
| 356 | if (l.seed > r.seed) |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 357 | return 1; |
| 358 | return 0; |
| 359 | } |
| 360 | |
Sage Weil | 991abb6 | 2009-10-08 22:22:37 -0700 | [diff] [blame] | 361 | static int __insert_pg_mapping(struct ceph_pg_mapping *new, |
| 362 | struct rb_root *root) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 363 | { |
| 364 | struct rb_node **p = &root->rb_node; |
| 365 | struct rb_node *parent = NULL; |
| 366 | struct ceph_pg_mapping *pg = NULL; |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 367 | int c; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 368 | |
Sage Weil | 8adc8b3 | 2011-09-28 10:11:04 -0700 | [diff] [blame] | 369 | dout("__insert_pg_mapping %llx %p\n", *(u64 *)&new->pgid, new); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 370 | while (*p) { |
| 371 | parent = *p; |
| 372 | pg = rb_entry(parent, struct ceph_pg_mapping, node); |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 373 | c = pgid_cmp(new->pgid, pg->pgid); |
| 374 | if (c < 0) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 375 | p = &(*p)->rb_left; |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 376 | else if (c > 0) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 377 | p = &(*p)->rb_right; |
| 378 | else |
Sage Weil | 991abb6 | 2009-10-08 22:22:37 -0700 | [diff] [blame] | 379 | return -EEXIST; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | rb_link_node(&new->node, parent, p); |
| 383 | rb_insert_color(&new->node, root); |
Sage Weil | 991abb6 | 2009-10-08 22:22:37 -0700 | [diff] [blame] | 384 | return 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Sage Weil | 9794b14 | 2010-02-16 15:53:32 -0800 | [diff] [blame] | 387 | static struct ceph_pg_mapping *__lookup_pg_mapping(struct rb_root *root, |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 388 | struct ceph_pg pgid) |
Sage Weil | 9794b14 | 2010-02-16 15:53:32 -0800 | [diff] [blame] | 389 | { |
| 390 | struct rb_node *n = root->rb_node; |
| 391 | struct ceph_pg_mapping *pg; |
| 392 | int c; |
| 393 | |
| 394 | while (n) { |
| 395 | pg = rb_entry(n, struct ceph_pg_mapping, node); |
| 396 | c = pgid_cmp(pgid, pg->pgid); |
Sage Weil | 8adc8b3 | 2011-09-28 10:11:04 -0700 | [diff] [blame] | 397 | if (c < 0) { |
Sage Weil | 9794b14 | 2010-02-16 15:53:32 -0800 | [diff] [blame] | 398 | n = n->rb_left; |
Sage Weil | 8adc8b3 | 2011-09-28 10:11:04 -0700 | [diff] [blame] | 399 | } else if (c > 0) { |
Sage Weil | 9794b14 | 2010-02-16 15:53:32 -0800 | [diff] [blame] | 400 | n = n->rb_right; |
Sage Weil | 8adc8b3 | 2011-09-28 10:11:04 -0700 | [diff] [blame] | 401 | } else { |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 402 | dout("__lookup_pg_mapping %lld.%x got %p\n", |
| 403 | pgid.pool, pgid.seed, pg); |
Sage Weil | 9794b14 | 2010-02-16 15:53:32 -0800 | [diff] [blame] | 404 | return pg; |
Sage Weil | 8adc8b3 | 2011-09-28 10:11:04 -0700 | [diff] [blame] | 405 | } |
Sage Weil | 9794b14 | 2010-02-16 15:53:32 -0800 | [diff] [blame] | 406 | } |
| 407 | return NULL; |
| 408 | } |
| 409 | |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 410 | static int __remove_pg_mapping(struct rb_root *root, struct ceph_pg pgid) |
Sage Weil | 8adc8b3 | 2011-09-28 10:11:04 -0700 | [diff] [blame] | 411 | { |
| 412 | struct ceph_pg_mapping *pg = __lookup_pg_mapping(root, pgid); |
| 413 | |
| 414 | if (pg) { |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 415 | dout("__remove_pg_mapping %lld.%x %p\n", pgid.pool, pgid.seed, |
| 416 | pg); |
Sage Weil | 8adc8b3 | 2011-09-28 10:11:04 -0700 | [diff] [blame] | 417 | rb_erase(&pg->node, root); |
| 418 | kfree(pg); |
| 419 | return 0; |
| 420 | } |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 421 | dout("__remove_pg_mapping %lld.%x dne\n", pgid.pool, pgid.seed); |
Sage Weil | 8adc8b3 | 2011-09-28 10:11:04 -0700 | [diff] [blame] | 422 | return -ENOENT; |
| 423 | } |
| 424 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 425 | /* |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 426 | * rbtree of pg pool info |
| 427 | */ |
| 428 | static int __insert_pg_pool(struct rb_root *root, struct ceph_pg_pool_info *new) |
| 429 | { |
| 430 | struct rb_node **p = &root->rb_node; |
| 431 | struct rb_node *parent = NULL; |
| 432 | struct ceph_pg_pool_info *pi = NULL; |
| 433 | |
| 434 | while (*p) { |
| 435 | parent = *p; |
| 436 | pi = rb_entry(parent, struct ceph_pg_pool_info, node); |
| 437 | if (new->id < pi->id) |
| 438 | p = &(*p)->rb_left; |
| 439 | else if (new->id > pi->id) |
| 440 | p = &(*p)->rb_right; |
| 441 | else |
| 442 | return -EEXIST; |
| 443 | } |
| 444 | |
| 445 | rb_link_node(&new->node, parent, p); |
| 446 | rb_insert_color(&new->node, root); |
| 447 | return 0; |
| 448 | } |
| 449 | |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 450 | static struct ceph_pg_pool_info *__lookup_pg_pool(struct rb_root *root, u64 id) |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 451 | { |
| 452 | struct ceph_pg_pool_info *pi; |
| 453 | struct rb_node *n = root->rb_node; |
| 454 | |
| 455 | while (n) { |
| 456 | pi = rb_entry(n, struct ceph_pg_pool_info, node); |
| 457 | if (id < pi->id) |
| 458 | n = n->rb_left; |
| 459 | else if (id > pi->id) |
| 460 | n = n->rb_right; |
| 461 | else |
| 462 | return pi; |
| 463 | } |
| 464 | return NULL; |
| 465 | } |
| 466 | |
Ilya Dryomov | ce7f6a2 | 2014-01-27 17:40:19 +0200 | [diff] [blame] | 467 | struct ceph_pg_pool_info *ceph_pg_pool_by_id(struct ceph_osdmap *map, u64 id) |
| 468 | { |
| 469 | return __lookup_pg_pool(&map->pg_pools, id); |
| 470 | } |
| 471 | |
Alex Elder | 72afc71 | 2012-10-30 19:40:33 -0500 | [diff] [blame] | 472 | const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id) |
| 473 | { |
| 474 | struct ceph_pg_pool_info *pi; |
| 475 | |
| 476 | if (id == CEPH_NOPOOL) |
| 477 | return NULL; |
| 478 | |
| 479 | if (WARN_ON_ONCE(id > (u64) INT_MAX)) |
| 480 | return NULL; |
| 481 | |
| 482 | pi = __lookup_pg_pool(&map->pg_pools, (int) id); |
| 483 | |
| 484 | return pi ? pi->name : NULL; |
| 485 | } |
| 486 | EXPORT_SYMBOL(ceph_pg_pool_name_by_id); |
| 487 | |
Yehuda Sadeh | 7669a2c | 2010-05-17 12:31:35 -0700 | [diff] [blame] | 488 | int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name) |
| 489 | { |
| 490 | struct rb_node *rbp; |
| 491 | |
| 492 | for (rbp = rb_first(&map->pg_pools); rbp; rbp = rb_next(rbp)) { |
| 493 | struct ceph_pg_pool_info *pi = |
| 494 | rb_entry(rbp, struct ceph_pg_pool_info, node); |
| 495 | if (pi->name && strcmp(pi->name, name) == 0) |
| 496 | return pi->id; |
| 497 | } |
| 498 | return -ENOENT; |
| 499 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 500 | EXPORT_SYMBOL(ceph_pg_poolid_by_name); |
Yehuda Sadeh | 7669a2c | 2010-05-17 12:31:35 -0700 | [diff] [blame] | 501 | |
Sage Weil | 2844a76 | 2010-04-09 15:46:42 -0700 | [diff] [blame] | 502 | static void __remove_pg_pool(struct rb_root *root, struct ceph_pg_pool_info *pi) |
| 503 | { |
| 504 | rb_erase(&pi->node, root); |
| 505 | kfree(pi->name); |
| 506 | kfree(pi); |
| 507 | } |
| 508 | |
Ilya Dryomov | 0f70c7e | 2014-03-21 19:05:27 +0200 | [diff] [blame^] | 509 | static int decode_pool(void **p, void *end, struct ceph_pg_pool_info *pi) |
Sage Weil | efd7576 | 2010-03-17 10:05:28 -0700 | [diff] [blame] | 510 | { |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 511 | u8 ev, cv; |
| 512 | unsigned len, num; |
| 513 | void *pool_end; |
Sage Weil | 73a7e69 | 2010-08-02 11:00:55 -0700 | [diff] [blame] | 514 | |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 515 | ceph_decode_need(p, end, 2 + 4, bad); |
| 516 | ev = ceph_decode_8(p); /* encoding version */ |
| 517 | cv = ceph_decode_8(p); /* compat version */ |
| 518 | if (ev < 5) { |
| 519 | pr_warning("got v %d < 5 cv %d of ceph_pg_pool\n", ev, cv); |
| 520 | return -EINVAL; |
| 521 | } |
Ilya Dryomov | 17a13e40 | 2014-01-27 17:40:19 +0200 | [diff] [blame] | 522 | if (cv > 9) { |
| 523 | pr_warning("got v %d cv %d > 9 of ceph_pg_pool\n", ev, cv); |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 524 | return -EINVAL; |
| 525 | } |
| 526 | len = ceph_decode_32(p); |
| 527 | ceph_decode_need(p, end, len, bad); |
| 528 | pool_end = *p + len; |
Sage Weil | 73a7e69 | 2010-08-02 11:00:55 -0700 | [diff] [blame] | 529 | |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 530 | pi->type = ceph_decode_8(p); |
| 531 | pi->size = ceph_decode_8(p); |
| 532 | pi->crush_ruleset = ceph_decode_8(p); |
| 533 | pi->object_hash = ceph_decode_8(p); |
| 534 | |
| 535 | pi->pg_num = ceph_decode_32(p); |
| 536 | pi->pgp_num = ceph_decode_32(p); |
| 537 | |
| 538 | *p += 4 + 4; /* skip lpg* */ |
| 539 | *p += 4; /* skip last_change */ |
| 540 | *p += 8 + 4; /* skip snap_seq, snap_epoch */ |
| 541 | |
| 542 | /* skip snaps */ |
| 543 | num = ceph_decode_32(p); |
| 544 | while (num--) { |
| 545 | *p += 8; /* snapid key */ |
| 546 | *p += 1 + 1; /* versions */ |
| 547 | len = ceph_decode_32(p); |
| 548 | *p += len; |
Sage Weil | 73a7e69 | 2010-08-02 11:00:55 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Ilya Dryomov | 17a13e40 | 2014-01-27 17:40:19 +0200 | [diff] [blame] | 551 | /* skip removed_snaps */ |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 552 | num = ceph_decode_32(p); |
| 553 | *p += num * (8 + 8); |
| 554 | |
| 555 | *p += 8; /* skip auid */ |
| 556 | pi->flags = ceph_decode_64(p); |
Ilya Dryomov | 17a13e40 | 2014-01-27 17:40:19 +0200 | [diff] [blame] | 557 | *p += 4; /* skip crash_replay_interval */ |
| 558 | |
| 559 | if (ev >= 7) |
| 560 | *p += 1; /* skip min_size */ |
| 561 | |
| 562 | if (ev >= 8) |
| 563 | *p += 8 + 8; /* skip quota_max_* */ |
| 564 | |
| 565 | if (ev >= 9) { |
| 566 | /* skip tiers */ |
| 567 | num = ceph_decode_32(p); |
| 568 | *p += num * 8; |
| 569 | |
| 570 | *p += 8; /* skip tier_of */ |
| 571 | *p += 1; /* skip cache_mode */ |
| 572 | |
| 573 | pi->read_tier = ceph_decode_64(p); |
| 574 | pi->write_tier = ceph_decode_64(p); |
| 575 | } else { |
| 576 | pi->read_tier = -1; |
| 577 | pi->write_tier = -1; |
| 578 | } |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 579 | |
| 580 | /* ignore the rest */ |
| 581 | |
| 582 | *p = pool_end; |
| 583 | calc_pg_masks(pi); |
Sage Weil | 73a7e69 | 2010-08-02 11:00:55 -0700 | [diff] [blame] | 584 | return 0; |
| 585 | |
| 586 | bad: |
| 587 | return -EINVAL; |
Sage Weil | efd7576 | 2010-03-17 10:05:28 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Ilya Dryomov | 0f70c7e | 2014-03-21 19:05:27 +0200 | [diff] [blame^] | 590 | static int decode_pool_names(void **p, void *end, struct ceph_osdmap *map) |
Sage Weil | 2844a76 | 2010-04-09 15:46:42 -0700 | [diff] [blame] | 591 | { |
| 592 | struct ceph_pg_pool_info *pi; |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 593 | u32 num, len; |
| 594 | u64 pool; |
Sage Weil | 2844a76 | 2010-04-09 15:46:42 -0700 | [diff] [blame] | 595 | |
| 596 | ceph_decode_32_safe(p, end, num, bad); |
| 597 | dout(" %d pool names\n", num); |
| 598 | while (num--) { |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 599 | ceph_decode_64_safe(p, end, pool, bad); |
Sage Weil | 2844a76 | 2010-04-09 15:46:42 -0700 | [diff] [blame] | 600 | ceph_decode_32_safe(p, end, len, bad); |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 601 | dout(" pool %llu len %d\n", pool, len); |
Xi Wang | ad3b904 | 2012-06-06 19:35:55 -0500 | [diff] [blame] | 602 | ceph_decode_need(p, end, len, bad); |
Sage Weil | 2844a76 | 2010-04-09 15:46:42 -0700 | [diff] [blame] | 603 | pi = __lookup_pg_pool(&map->pg_pools, pool); |
| 604 | if (pi) { |
Xi Wang | ad3b904 | 2012-06-06 19:35:55 -0500 | [diff] [blame] | 605 | char *name = kstrndup(*p, len, GFP_NOFS); |
| 606 | |
| 607 | if (!name) |
| 608 | return -ENOMEM; |
Sage Weil | 2844a76 | 2010-04-09 15:46:42 -0700 | [diff] [blame] | 609 | kfree(pi->name); |
Xi Wang | ad3b904 | 2012-06-06 19:35:55 -0500 | [diff] [blame] | 610 | pi->name = name; |
| 611 | dout(" name is %s\n", pi->name); |
Sage Weil | 2844a76 | 2010-04-09 15:46:42 -0700 | [diff] [blame] | 612 | } |
| 613 | *p += len; |
| 614 | } |
| 615 | return 0; |
| 616 | |
| 617 | bad: |
| 618 | return -EINVAL; |
| 619 | } |
| 620 | |
| 621 | /* |
| 622 | * osd map |
| 623 | */ |
| 624 | void ceph_osdmap_destroy(struct ceph_osdmap *map) |
| 625 | { |
| 626 | dout("osdmap_destroy %p\n", map); |
| 627 | if (map->crush) |
| 628 | crush_destroy(map->crush); |
| 629 | while (!RB_EMPTY_ROOT(&map->pg_temp)) { |
| 630 | struct ceph_pg_mapping *pg = |
| 631 | rb_entry(rb_first(&map->pg_temp), |
| 632 | struct ceph_pg_mapping, node); |
| 633 | rb_erase(&pg->node, &map->pg_temp); |
| 634 | kfree(pg); |
| 635 | } |
| 636 | while (!RB_EMPTY_ROOT(&map->pg_pools)) { |
| 637 | struct ceph_pg_pool_info *pi = |
| 638 | rb_entry(rb_first(&map->pg_pools), |
| 639 | struct ceph_pg_pool_info, node); |
| 640 | __remove_pg_pool(&map->pg_pools, pi); |
| 641 | } |
| 642 | kfree(map->osd_state); |
| 643 | kfree(map->osd_weight); |
| 644 | kfree(map->osd_addr); |
| 645 | kfree(map); |
| 646 | } |
| 647 | |
| 648 | /* |
| 649 | * adjust max osd value. reallocate arrays. |
| 650 | */ |
| 651 | static int osdmap_set_max_osd(struct ceph_osdmap *map, int max) |
| 652 | { |
| 653 | u8 *state; |
| 654 | struct ceph_entity_addr *addr; |
| 655 | u32 *weight; |
| 656 | |
| 657 | state = kcalloc(max, sizeof(*state), GFP_NOFS); |
| 658 | addr = kcalloc(max, sizeof(*addr), GFP_NOFS); |
| 659 | weight = kcalloc(max, sizeof(*weight), GFP_NOFS); |
| 660 | if (state == NULL || addr == NULL || weight == NULL) { |
| 661 | kfree(state); |
| 662 | kfree(addr); |
| 663 | kfree(weight); |
| 664 | return -ENOMEM; |
| 665 | } |
| 666 | |
| 667 | /* copy old? */ |
| 668 | if (map->osd_state) { |
| 669 | memcpy(state, map->osd_state, map->max_osd*sizeof(*state)); |
| 670 | memcpy(addr, map->osd_addr, map->max_osd*sizeof(*addr)); |
| 671 | memcpy(weight, map->osd_weight, map->max_osd*sizeof(*weight)); |
| 672 | kfree(map->osd_state); |
| 673 | kfree(map->osd_addr); |
| 674 | kfree(map->osd_weight); |
| 675 | } |
| 676 | |
| 677 | map->osd_state = state; |
| 678 | map->osd_weight = weight; |
| 679 | map->osd_addr = addr; |
| 680 | map->max_osd = max; |
| 681 | return 0; |
| 682 | } |
| 683 | |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 684 | /* |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 685 | * decode a full map. |
| 686 | */ |
Ilya Dryomov | a2505d6 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 687 | static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 688 | { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 689 | u16 version; |
Ilya Dryomov | 38a8d56 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 690 | u32 epoch = 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 691 | void *start = *p; |
Ilya Dryomov | 3977058 | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 692 | u32 max; |
| 693 | u32 len, i; |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 694 | int err; |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 695 | struct ceph_pg_pool_info *pi; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 696 | |
Ilya Dryomov | a2505d6 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 697 | dout("%s %p to %p len %d\n", __func__, *p, end, (int)(end - *p)); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 698 | |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 699 | ceph_decode_16_safe(p, end, version, e_inval); |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 700 | if (version > 6) { |
| 701 | pr_warning("got unknown v %d > 6 of osdmap\n", version); |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 702 | goto e_inval; |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 703 | } |
| 704 | if (version < 6) { |
| 705 | pr_warning("got old v %d < 6 of osdmap\n", version); |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 706 | goto e_inval; |
Sage Weil | 02f90c6 | 2010-02-04 16:18:10 -0800 | [diff] [blame] | 707 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 708 | |
Ilya Dryomov | 53bbaba | 2014-03-13 16:36:16 +0200 | [diff] [blame] | 709 | /* fsid, epoch, created, modified */ |
| 710 | ceph_decode_need(p, end, sizeof(map->fsid) + sizeof(u32) + |
| 711 | sizeof(map->created) + sizeof(map->modified), e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 712 | ceph_decode_copy(p, &map->fsid, sizeof(map->fsid)); |
Ilya Dryomov | 38a8d56 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 713 | epoch = map->epoch = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 714 | ceph_decode_copy(p, &map->created, sizeof(map->created)); |
| 715 | ceph_decode_copy(p, &map->modified, sizeof(map->modified)); |
| 716 | |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 717 | ceph_decode_32_safe(p, end, max, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 718 | while (max--) { |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 719 | ceph_decode_need(p, end, 8 + 2, e_inval); |
Sage Weil | 2844a76 | 2010-04-09 15:46:42 -0700 | [diff] [blame] | 720 | pi = kzalloc(sizeof(*pi), GFP_NOFS); |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 721 | if (!pi) { |
| 722 | err = -ENOMEM; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 723 | goto bad; |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 724 | } |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 725 | pi->id = ceph_decode_64(p); |
Ilya Dryomov | 0f70c7e | 2014-03-21 19:05:27 +0200 | [diff] [blame^] | 726 | err = decode_pool(p, end, pi); |
Jesper Juhl | b0aee35 | 2010-12-24 23:01:12 +0100 | [diff] [blame] | 727 | if (err < 0) { |
| 728 | kfree(pi); |
Sage Weil | 73a7e69 | 2010-08-02 11:00:55 -0700 | [diff] [blame] | 729 | goto bad; |
Jesper Juhl | b0aee35 | 2010-12-24 23:01:12 +0100 | [diff] [blame] | 730 | } |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 731 | __insert_pg_pool(&map->pg_pools, pi); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 732 | } |
Sage Weil | 2844a76 | 2010-04-09 15:46:42 -0700 | [diff] [blame] | 733 | |
Ilya Dryomov | 0f70c7e | 2014-03-21 19:05:27 +0200 | [diff] [blame^] | 734 | /* pool_name */ |
| 735 | err = decode_pool_names(p, end, map); |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 736 | if (err) |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 737 | goto bad; |
Sage Weil | 2844a76 | 2010-04-09 15:46:42 -0700 | [diff] [blame] | 738 | |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 739 | ceph_decode_32_safe(p, end, map->pool_max, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 740 | |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 741 | ceph_decode_32_safe(p, end, map->flags, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 742 | |
Ilya Dryomov | 3977058 | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 743 | /* max_osd */ |
| 744 | ceph_decode_32_safe(p, end, max, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 745 | |
| 746 | /* (re)alloc osd arrays */ |
| 747 | err = osdmap_set_max_osd(map, max); |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 748 | if (err) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 749 | goto bad; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 750 | |
Ilya Dryomov | 2d88b2e | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 751 | /* osd_state, osd_weight, osd_addrs->client_addr */ |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 752 | ceph_decode_need(p, end, 3*sizeof(u32) + |
| 753 | map->max_osd*(1 + sizeof(*map->osd_weight) + |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 754 | sizeof(*map->osd_addr)), e_inval); |
| 755 | |
Ilya Dryomov | 2d88b2e | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 756 | if (ceph_decode_32(p) != map->max_osd) |
| 757 | goto e_inval; |
| 758 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 759 | ceph_decode_copy(p, map->osd_state, map->max_osd); |
| 760 | |
Ilya Dryomov | 2d88b2e | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 761 | if (ceph_decode_32(p) != map->max_osd) |
| 762 | goto e_inval; |
| 763 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 764 | for (i = 0; i < map->max_osd; i++) |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 765 | map->osd_weight[i] = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 766 | |
Ilya Dryomov | 2d88b2e | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 767 | if (ceph_decode_32(p) != map->max_osd) |
| 768 | goto e_inval; |
| 769 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 770 | ceph_decode_copy(p, map->osd_addr, map->max_osd*sizeof(*map->osd_addr)); |
Sage Weil | 63f2d21 | 2009-11-03 15:17:56 -0800 | [diff] [blame] | 771 | for (i = 0; i < map->max_osd; i++) |
| 772 | ceph_decode_addr(&map->osd_addr[i]); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 773 | |
| 774 | /* pg_temp */ |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 775 | ceph_decode_32_safe(p, end, len, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 776 | for (i = 0; i < len; i++) { |
| 777 | int n, j; |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 778 | struct ceph_pg pgid; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 779 | struct ceph_pg_mapping *pg; |
| 780 | |
Alex Elder | ef4859d | 2013-04-01 18:58:26 -0500 | [diff] [blame] | 781 | err = ceph_decode_pgid(p, end, &pgid); |
Sage Weil | d6c0dd6 | 2013-03-06 14:57:03 -0800 | [diff] [blame] | 782 | if (err) |
| 783 | goto bad; |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 784 | ceph_decode_need(p, end, sizeof(u32), e_inval); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 785 | n = ceph_decode_32(p); |
Xi Wang | e91a9b6 | 2012-06-06 19:35:55 -0500 | [diff] [blame] | 786 | if (n > (UINT_MAX - sizeof(*pg)) / sizeof(u32)) |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 787 | goto e_inval; |
| 788 | ceph_decode_need(p, end, n * sizeof(u32), e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 789 | pg = kmalloc(sizeof(*pg) + n*sizeof(u32), GFP_NOFS); |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 790 | if (!pg) { |
| 791 | err = -ENOMEM; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 792 | goto bad; |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 793 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 794 | pg->pgid = pgid; |
| 795 | pg->len = n; |
| 796 | for (j = 0; j < n; j++) |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 797 | pg->osds[j] = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 798 | |
Sage Weil | 991abb6 | 2009-10-08 22:22:37 -0700 | [diff] [blame] | 799 | err = __insert_pg_mapping(pg, &map->pg_temp); |
| 800 | if (err) |
| 801 | goto bad; |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 802 | dout(" added pg_temp %lld.%x len %d\n", pgid.pool, pgid.seed, |
| 803 | len); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | /* crush */ |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 807 | ceph_decode_32_safe(p, end, len, e_inval); |
Ilya Dryomov | 9902e68 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 808 | map->crush = crush_decode(*p, min(*p + len, end)); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 809 | if (IS_ERR(map->crush)) { |
| 810 | err = PTR_ERR(map->crush); |
| 811 | map->crush = NULL; |
| 812 | goto bad; |
| 813 | } |
Ilya Dryomov | 9902e68 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 814 | *p += len; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 815 | |
Ilya Dryomov | 38a8d56 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 816 | /* ignore the rest */ |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 817 | *p = end; |
| 818 | |
Ilya Dryomov | 38a8d56 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 819 | dout("full osdmap epoch %d max_osd %d\n", map->epoch, map->max_osd); |
Ilya Dryomov | a2505d6 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 820 | return 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 821 | |
Ilya Dryomov | 597b52f | 2014-03-13 16:36:14 +0200 | [diff] [blame] | 822 | e_inval: |
| 823 | err = -EINVAL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 824 | bad: |
Ilya Dryomov | 38a8d56 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 825 | pr_err("corrupt full osdmap (%d) epoch %d off %d (%p of %p-%p)\n", |
| 826 | err, epoch, (int)(*p - start), *p, start, end); |
| 827 | print_hex_dump(KERN_DEBUG, "osdmap: ", |
| 828 | DUMP_PREFIX_OFFSET, 16, 1, |
| 829 | start, end - start, true); |
Ilya Dryomov | a2505d6 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 830 | return err; |
| 831 | } |
| 832 | |
| 833 | /* |
| 834 | * Allocate and decode a full map. |
| 835 | */ |
| 836 | struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end) |
| 837 | { |
| 838 | struct ceph_osdmap *map; |
| 839 | int ret; |
| 840 | |
| 841 | map = kzalloc(sizeof(*map), GFP_NOFS); |
| 842 | if (!map) |
| 843 | return ERR_PTR(-ENOMEM); |
| 844 | |
| 845 | map->pg_temp = RB_ROOT; |
| 846 | mutex_init(&map->crush_scratch_mutex); |
| 847 | |
| 848 | ret = osdmap_decode(p, end, map); |
| 849 | if (ret) { |
| 850 | ceph_osdmap_destroy(map); |
| 851 | return ERR_PTR(ret); |
| 852 | } |
| 853 | |
| 854 | return map; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | /* |
| 858 | * decode and apply an incremental map update. |
| 859 | */ |
| 860 | struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, |
| 861 | struct ceph_osdmap *map, |
| 862 | struct ceph_messenger *msgr) |
| 863 | { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 864 | struct crush_map *newcrush = NULL; |
| 865 | struct ceph_fsid fsid; |
| 866 | u32 epoch = 0; |
| 867 | struct ceph_timespec modified; |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 868 | s32 len; |
| 869 | u64 pool; |
| 870 | __s64 new_pool_max; |
| 871 | __s32 new_flags, max; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 872 | void *start = *p; |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 873 | int err; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 874 | u16 version; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 875 | |
Ilya Dryomov | 38a8d56 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 876 | dout("%s %p to %p len %d\n", __func__, *p, end, (int)(end - *p)); |
| 877 | |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 878 | ceph_decode_16_safe(p, end, version, e_inval); |
Sage Weil | d6c0dd6 | 2013-03-06 14:57:03 -0800 | [diff] [blame] | 879 | if (version != 6) { |
| 880 | pr_warning("got unknown v %d != 6 of inc osdmap\n", version); |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 881 | goto e_inval; |
Sage Weil | 02f90c6 | 2010-02-04 16:18:10 -0800 | [diff] [blame] | 882 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 883 | |
Ilya Dryomov | 53bbaba | 2014-03-13 16:36:16 +0200 | [diff] [blame] | 884 | /* fsid, epoch, modified, new_pool_max, new_flags */ |
| 885 | ceph_decode_need(p, end, sizeof(fsid) + sizeof(u32) + sizeof(modified) + |
| 886 | sizeof(u64) + sizeof(u32), e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 887 | ceph_decode_copy(p, &fsid, sizeof(fsid)); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 888 | epoch = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 889 | BUG_ON(epoch != map->epoch+1); |
| 890 | ceph_decode_copy(p, &modified, sizeof(modified)); |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 891 | new_pool_max = ceph_decode_64(p); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 892 | new_flags = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 893 | |
| 894 | /* full map? */ |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 895 | ceph_decode_32_safe(p, end, len, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 896 | if (len > 0) { |
| 897 | dout("apply_incremental full map len %d, %p to %p\n", |
| 898 | len, *p, end); |
Ilya Dryomov | a2505d6 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 899 | return ceph_osdmap_decode(p, min(*p+len, end)); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /* new crush? */ |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 903 | ceph_decode_32_safe(p, end, len, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 904 | if (len > 0) { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 905 | newcrush = crush_decode(*p, min(*p+len, end)); |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 906 | if (IS_ERR(newcrush)) { |
| 907 | err = PTR_ERR(newcrush); |
| 908 | newcrush = NULL; |
| 909 | goto bad; |
| 910 | } |
Sage Weil | cebc5be | 2010-06-17 10:22:48 -0700 | [diff] [blame] | 911 | *p += len; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | /* new flags? */ |
| 915 | if (new_flags >= 0) |
| 916 | map->flags = new_flags; |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 917 | if (new_pool_max >= 0) |
| 918 | map->pool_max = new_pool_max; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 919 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 920 | /* new max? */ |
Ilya Dryomov | 53bbaba | 2014-03-13 16:36:16 +0200 | [diff] [blame] | 921 | ceph_decode_32_safe(p, end, max, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 922 | if (max >= 0) { |
| 923 | err = osdmap_set_max_osd(map, max); |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 924 | if (err) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 925 | goto bad; |
| 926 | } |
| 927 | |
| 928 | map->epoch++; |
Sage Weil | 3145666 | 2011-05-12 15:18:43 -0700 | [diff] [blame] | 929 | map->modified = modified; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 930 | if (newcrush) { |
| 931 | if (map->crush) |
| 932 | crush_destroy(map->crush); |
| 933 | map->crush = newcrush; |
| 934 | newcrush = NULL; |
| 935 | } |
| 936 | |
| 937 | /* new_pool */ |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 938 | ceph_decode_32_safe(p, end, len, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 939 | while (len--) { |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 940 | struct ceph_pg_pool_info *pi; |
Sage Weil | 361be86 | 2010-01-25 16:03:02 -0800 | [diff] [blame] | 941 | |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 942 | ceph_decode_64_safe(p, end, pool, e_inval); |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 943 | pi = __lookup_pg_pool(&map->pg_pools, pool); |
| 944 | if (!pi) { |
Sage Weil | 2844a76 | 2010-04-09 15:46:42 -0700 | [diff] [blame] | 945 | pi = kzalloc(sizeof(*pi), GFP_NOFS); |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 946 | if (!pi) { |
| 947 | err = -ENOMEM; |
| 948 | goto bad; |
| 949 | } |
| 950 | pi->id = pool; |
| 951 | __insert_pg_pool(&map->pg_pools, pi); |
| 952 | } |
Ilya Dryomov | 0f70c7e | 2014-03-21 19:05:27 +0200 | [diff] [blame^] | 953 | err = decode_pool(p, end, pi); |
Sage Weil | 73a7e69 | 2010-08-02 11:00:55 -0700 | [diff] [blame] | 954 | if (err < 0) |
| 955 | goto bad; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 956 | } |
Ilya Dryomov | 9464d00 | 2014-03-13 16:36:16 +0200 | [diff] [blame] | 957 | |
Ilya Dryomov | 0f70c7e | 2014-03-21 19:05:27 +0200 | [diff] [blame^] | 958 | /* new_pool_names */ |
| 959 | err = decode_pool_names(p, end, map); |
Ilya Dryomov | 9464d00 | 2014-03-13 16:36:16 +0200 | [diff] [blame] | 960 | if (err) |
| 961 | goto bad; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 962 | |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 963 | /* old_pool */ |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 964 | ceph_decode_32_safe(p, end, len, e_inval); |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 965 | while (len--) { |
| 966 | struct ceph_pg_pool_info *pi; |
| 967 | |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 968 | ceph_decode_64_safe(p, end, pool, e_inval); |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 969 | pi = __lookup_pg_pool(&map->pg_pools, pool); |
Sage Weil | 2844a76 | 2010-04-09 15:46:42 -0700 | [diff] [blame] | 970 | if (pi) |
| 971 | __remove_pg_pool(&map->pg_pools, pi); |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 972 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 973 | |
| 974 | /* new_up */ |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 975 | ceph_decode_32_safe(p, end, len, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 976 | while (len--) { |
| 977 | u32 osd; |
| 978 | struct ceph_entity_addr addr; |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 979 | ceph_decode_32_safe(p, end, osd, e_inval); |
| 980 | ceph_decode_copy_safe(p, end, &addr, sizeof(addr), e_inval); |
Sage Weil | 63f2d21 | 2009-11-03 15:17:56 -0800 | [diff] [blame] | 981 | ceph_decode_addr(&addr); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 982 | pr_info("osd%d up\n", osd); |
| 983 | BUG_ON(osd >= map->max_osd); |
| 984 | map->osd_state[osd] |= CEPH_OSD_UP; |
| 985 | map->osd_addr[osd] = addr; |
| 986 | } |
| 987 | |
Sage Weil | 7662d8f | 2011-05-03 12:52:05 -0700 | [diff] [blame] | 988 | /* new_state */ |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 989 | ceph_decode_32_safe(p, end, len, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 990 | while (len--) { |
| 991 | u32 osd; |
Sage Weil | 7662d8f | 2011-05-03 12:52:05 -0700 | [diff] [blame] | 992 | u8 xorstate; |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 993 | ceph_decode_32_safe(p, end, osd, e_inval); |
Sage Weil | 7662d8f | 2011-05-03 12:52:05 -0700 | [diff] [blame] | 994 | xorstate = **(u8 **)p; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 995 | (*p)++; /* clean flag */ |
Sage Weil | 7662d8f | 2011-05-03 12:52:05 -0700 | [diff] [blame] | 996 | if (xorstate == 0) |
| 997 | xorstate = CEPH_OSD_UP; |
| 998 | if (xorstate & CEPH_OSD_UP) |
| 999 | pr_info("osd%d down\n", osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1000 | if (osd < map->max_osd) |
Sage Weil | 7662d8f | 2011-05-03 12:52:05 -0700 | [diff] [blame] | 1001 | map->osd_state[osd] ^= xorstate; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | /* new_weight */ |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 1005 | ceph_decode_32_safe(p, end, len, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1006 | while (len--) { |
| 1007 | u32 osd, off; |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 1008 | ceph_decode_need(p, end, sizeof(u32)*2, e_inval); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 1009 | osd = ceph_decode_32(p); |
| 1010 | off = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1011 | pr_info("osd%d weight 0x%x %s\n", osd, off, |
| 1012 | off == CEPH_OSD_IN ? "(in)" : |
| 1013 | (off == CEPH_OSD_OUT ? "(out)" : "")); |
| 1014 | if (osd < map->max_osd) |
| 1015 | map->osd_weight[osd] = off; |
| 1016 | } |
| 1017 | |
| 1018 | /* new_pg_temp */ |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 1019 | ceph_decode_32_safe(p, end, len, e_inval); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1020 | while (len--) { |
| 1021 | struct ceph_pg_mapping *pg; |
| 1022 | int j; |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 1023 | struct ceph_pg pgid; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1024 | u32 pglen; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1025 | |
Alex Elder | ef4859d | 2013-04-01 18:58:26 -0500 | [diff] [blame] | 1026 | err = ceph_decode_pgid(p, end, &pgid); |
Sage Weil | d6c0dd6 | 2013-03-06 14:57:03 -0800 | [diff] [blame] | 1027 | if (err) |
| 1028 | goto bad; |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 1029 | ceph_decode_need(p, end, sizeof(u32), e_inval); |
Sage Weil | d6c0dd6 | 2013-03-06 14:57:03 -0800 | [diff] [blame] | 1030 | pglen = ceph_decode_32(p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1031 | if (pglen) { |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 1032 | ceph_decode_need(p, end, pglen*sizeof(u32), e_inval); |
Sage Weil | 6bd9adb | 2012-05-21 09:45:23 -0700 | [diff] [blame] | 1033 | |
| 1034 | /* removing existing (if any) */ |
| 1035 | (void) __remove_pg_mapping(&map->pg_temp, pgid); |
| 1036 | |
| 1037 | /* insert */ |
Sage Weil | 0ed7285 | 2012-10-29 11:01:42 -0700 | [diff] [blame] | 1038 | if (pglen > (UINT_MAX - sizeof(*pg)) / sizeof(u32)) |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 1039 | goto e_inval; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1040 | pg = kmalloc(sizeof(*pg) + sizeof(u32)*pglen, GFP_NOFS); |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 1041 | if (!pg) { |
| 1042 | err = -ENOMEM; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1043 | goto bad; |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 1044 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1045 | pg->pgid = pgid; |
| 1046 | pg->len = pglen; |
Sage Weil | 7067f79 | 2009-12-21 16:02:37 -0800 | [diff] [blame] | 1047 | for (j = 0; j < pglen; j++) |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 1048 | pg->osds[j] = ceph_decode_32(p); |
Sage Weil | 991abb6 | 2009-10-08 22:22:37 -0700 | [diff] [blame] | 1049 | err = __insert_pg_mapping(pg, &map->pg_temp); |
Sage Weil | bc4fdca | 2010-07-20 16:19:56 -0700 | [diff] [blame] | 1050 | if (err) { |
| 1051 | kfree(pg); |
Sage Weil | 991abb6 | 2009-10-08 22:22:37 -0700 | [diff] [blame] | 1052 | goto bad; |
Sage Weil | bc4fdca | 2010-07-20 16:19:56 -0700 | [diff] [blame] | 1053 | } |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 1054 | dout(" added pg_temp %lld.%x len %d\n", pgid.pool, |
| 1055 | pgid.seed, pglen); |
Sage Weil | 8adc8b3 | 2011-09-28 10:11:04 -0700 | [diff] [blame] | 1056 | } else { |
| 1057 | /* remove */ |
| 1058 | __remove_pg_mapping(&map->pg_temp, pgid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1059 | } |
| 1060 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1061 | |
| 1062 | /* ignore the rest */ |
| 1063 | *p = end; |
Ilya Dryomov | 38a8d56 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 1064 | |
| 1065 | dout("inc osdmap epoch %d max_osd %d\n", map->epoch, map->max_osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1066 | return map; |
| 1067 | |
Ilya Dryomov | 86f1742 | 2014-03-13 16:36:15 +0200 | [diff] [blame] | 1068 | e_inval: |
| 1069 | err = -EINVAL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1070 | bad: |
Ilya Dryomov | 38a8d56 | 2014-03-13 16:36:13 +0200 | [diff] [blame] | 1071 | pr_err("corrupt inc osdmap (%d) epoch %d off %d (%p of %p-%p)\n", |
| 1072 | err, epoch, (int)(*p - start), *p, start, end); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 1073 | print_hex_dump(KERN_DEBUG, "osdmap: ", |
| 1074 | DUMP_PREFIX_OFFSET, 16, 1, |
| 1075 | start, end - start, true); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1076 | if (newcrush) |
| 1077 | crush_destroy(newcrush); |
| 1078 | return ERR_PTR(err); |
| 1079 | } |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | /* |
| 1085 | * calculate file layout from given offset, length. |
| 1086 | * fill in correct oid, logical length, and object extent |
| 1087 | * offset, length. |
| 1088 | * |
| 1089 | * for now, we write only a single su, until we can |
| 1090 | * pass a stride back to the caller. |
| 1091 | */ |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame] | 1092 | int ceph_calc_file_object_mapping(struct ceph_file_layout *layout, |
Alex Elder | e8afad6 | 2012-11-14 09:38:19 -0600 | [diff] [blame] | 1093 | u64 off, u64 len, |
Sage Weil | 645a102 | 2009-10-28 15:15:05 -0700 | [diff] [blame] | 1094 | u64 *ono, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1095 | u64 *oxoff, u64 *oxlen) |
| 1096 | { |
| 1097 | u32 osize = le32_to_cpu(layout->fl_object_size); |
| 1098 | u32 su = le32_to_cpu(layout->fl_stripe_unit); |
| 1099 | u32 sc = le32_to_cpu(layout->fl_stripe_count); |
| 1100 | u32 bl, stripeno, stripepos, objsetno; |
| 1101 | u32 su_per_object; |
Noah Watkins | ff1d1f7 | 2009-10-30 12:57:30 -0700 | [diff] [blame] | 1102 | u64 t, su_offset; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1103 | |
Alex Elder | e8afad6 | 2012-11-14 09:38:19 -0600 | [diff] [blame] | 1104 | dout("mapping %llu~%llu osize %u fl_su %u\n", off, len, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1105 | osize, su); |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame] | 1106 | if (su == 0 || sc == 0) |
| 1107 | goto invalid; |
Noah Watkins | 35e054a | 2009-10-28 14:04:48 -0700 | [diff] [blame] | 1108 | su_per_object = osize / su; |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame] | 1109 | if (su_per_object == 0) |
| 1110 | goto invalid; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1111 | dout("osize %u / su %u = su_per_object %u\n", osize, su, |
| 1112 | su_per_object); |
| 1113 | |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame] | 1114 | if ((su & ~PAGE_MASK) != 0) |
| 1115 | goto invalid; |
| 1116 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1117 | /* bl = *off / su; */ |
| 1118 | t = off; |
| 1119 | do_div(t, su); |
| 1120 | bl = t; |
| 1121 | dout("off %llu / su %u = bl %u\n", off, su, bl); |
| 1122 | |
| 1123 | stripeno = bl / sc; |
| 1124 | stripepos = bl % sc; |
| 1125 | objsetno = stripeno / su_per_object; |
| 1126 | |
Sage Weil | 645a102 | 2009-10-28 15:15:05 -0700 | [diff] [blame] | 1127 | *ono = objsetno * sc + stripepos; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 1128 | dout("objset %u * sc %u = ono %u\n", objsetno, sc, (unsigned int)*ono); |
Sage Weil | 645a102 | 2009-10-28 15:15:05 -0700 | [diff] [blame] | 1129 | |
| 1130 | /* *oxoff = *off % layout->fl_stripe_unit; # offset in su */ |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1131 | t = off; |
Noah Watkins | ff1d1f7 | 2009-10-30 12:57:30 -0700 | [diff] [blame] | 1132 | su_offset = do_div(t, su); |
| 1133 | *oxoff = su_offset + (stripeno % su_per_object) * su; |
Sage Weil | 645a102 | 2009-10-28 15:15:05 -0700 | [diff] [blame] | 1134 | |
Noah Watkins | ff1d1f7 | 2009-10-30 12:57:30 -0700 | [diff] [blame] | 1135 | /* |
| 1136 | * Calculate the length of the extent being written to the selected |
Alex Elder | e8afad6 | 2012-11-14 09:38:19 -0600 | [diff] [blame] | 1137 | * object. This is the minimum of the full length requested (len) or |
Noah Watkins | ff1d1f7 | 2009-10-30 12:57:30 -0700 | [diff] [blame] | 1138 | * the remainder of the current stripe being written to. |
| 1139 | */ |
Alex Elder | e8afad6 | 2012-11-14 09:38:19 -0600 | [diff] [blame] | 1140 | *oxlen = min_t(u64, len, su - su_offset); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1141 | |
| 1142 | dout(" obj extent %llu~%llu\n", *oxoff, *oxlen); |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame] | 1143 | return 0; |
| 1144 | |
| 1145 | invalid: |
| 1146 | dout(" invalid layout\n"); |
| 1147 | *ono = 0; |
| 1148 | *oxoff = 0; |
| 1149 | *oxlen = 0; |
| 1150 | return -EINVAL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1151 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1152 | EXPORT_SYMBOL(ceph_calc_file_object_mapping); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1153 | |
| 1154 | /* |
Ilya Dryomov | 7c13cb6 | 2014-01-27 17:40:19 +0200 | [diff] [blame] | 1155 | * Calculate mapping of a (oloc, oid) pair to a PG. Should only be |
| 1156 | * called with target's (oloc, oid), since tiering isn't taken into |
| 1157 | * account. |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1158 | */ |
Ilya Dryomov | 7c13cb6 | 2014-01-27 17:40:19 +0200 | [diff] [blame] | 1159 | int ceph_oloc_oid_to_pg(struct ceph_osdmap *osdmap, |
| 1160 | struct ceph_object_locator *oloc, |
| 1161 | struct ceph_object_id *oid, |
| 1162 | struct ceph_pg *pg_out) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1163 | { |
Ilya Dryomov | 7c13cb6 | 2014-01-27 17:40:19 +0200 | [diff] [blame] | 1164 | struct ceph_pg_pool_info *pi; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1165 | |
Ilya Dryomov | 7c13cb6 | 2014-01-27 17:40:19 +0200 | [diff] [blame] | 1166 | pi = __lookup_pg_pool(&osdmap->pg_pools, oloc->pool); |
| 1167 | if (!pi) |
Sage Weil | 4fc51be | 2010-02-16 15:55:03 -0800 | [diff] [blame] | 1168 | return -EIO; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1169 | |
Ilya Dryomov | 7c13cb6 | 2014-01-27 17:40:19 +0200 | [diff] [blame] | 1170 | pg_out->pool = oloc->pool; |
| 1171 | pg_out->seed = ceph_str_hash(pi->object_hash, oid->name, |
| 1172 | oid->name_len); |
| 1173 | |
| 1174 | dout("%s '%.*s' pgid %llu.%x\n", __func__, oid->name_len, oid->name, |
| 1175 | pg_out->pool, pg_out->seed); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1176 | return 0; |
| 1177 | } |
Ilya Dryomov | 7c13cb6 | 2014-01-27 17:40:19 +0200 | [diff] [blame] | 1178 | EXPORT_SYMBOL(ceph_oloc_oid_to_pg); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1179 | |
Ilya Dryomov | 9d52147 | 2014-01-31 17:54:26 +0200 | [diff] [blame] | 1180 | static int do_crush(struct ceph_osdmap *map, int ruleno, int x, |
| 1181 | int *result, int result_max, |
| 1182 | const __u32 *weight, int weight_max) |
Ilya Dryomov | e8ef19c | 2013-12-24 21:19:24 +0200 | [diff] [blame] | 1183 | { |
Ilya Dryomov | 9d52147 | 2014-01-31 17:54:26 +0200 | [diff] [blame] | 1184 | int r; |
Ilya Dryomov | e8ef19c | 2013-12-24 21:19:24 +0200 | [diff] [blame] | 1185 | |
Ilya Dryomov | 9d52147 | 2014-01-31 17:54:26 +0200 | [diff] [blame] | 1186 | BUG_ON(result_max > CEPH_PG_MAX_SIZE); |
| 1187 | |
| 1188 | mutex_lock(&map->crush_scratch_mutex); |
| 1189 | r = crush_do_rule(map->crush, ruleno, x, result, result_max, |
| 1190 | weight, weight_max, map->crush_scratch_ary); |
| 1191 | mutex_unlock(&map->crush_scratch_mutex); |
| 1192 | |
| 1193 | return r; |
Ilya Dryomov | e8ef19c | 2013-12-24 21:19:24 +0200 | [diff] [blame] | 1194 | } |
| 1195 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1196 | /* |
| 1197 | * Calculate raw osd vector for the given pgid. Return pointer to osd |
| 1198 | * array, or NULL on failure. |
| 1199 | */ |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 1200 | static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg pgid, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1201 | int *osds, int *num) |
| 1202 | { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1203 | struct ceph_pg_mapping *pg; |
| 1204 | struct ceph_pg_pool_info *pool; |
| 1205 | int ruleno; |
Sage Weil | 83ca14f | 2013-02-26 10:39:09 -0800 | [diff] [blame] | 1206 | int r; |
| 1207 | u32 pps; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1208 | |
Sage Weil | 83ca14f | 2013-02-26 10:39:09 -0800 | [diff] [blame] | 1209 | pool = __lookup_pg_pool(&osdmap->pg_pools, pgid.pool); |
Sage Weil | 782e182 | 2011-09-28 10:08:27 -0700 | [diff] [blame] | 1210 | if (!pool) |
| 1211 | return NULL; |
| 1212 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1213 | /* pg_temp? */ |
Sage Weil | 83ca14f | 2013-02-26 10:39:09 -0800 | [diff] [blame] | 1214 | pgid.seed = ceph_stable_mod(pgid.seed, pool->pg_num, |
Sage Weil | 9542cf0 | 2013-08-28 17:17:29 -0700 | [diff] [blame] | 1215 | pool->pg_num_mask); |
Sage Weil | 9794b14 | 2010-02-16 15:53:32 -0800 | [diff] [blame] | 1216 | pg = __lookup_pg_mapping(&osdmap->pg_temp, pgid); |
| 1217 | if (pg) { |
| 1218 | *num = pg->len; |
| 1219 | return pg->osds; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | /* crush */ |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 1223 | ruleno = crush_find_rule(osdmap->crush, pool->crush_ruleset, |
| 1224 | pool->type, pool->size); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1225 | if (ruleno < 0) { |
Sage Weil | 83ca14f | 2013-02-26 10:39:09 -0800 | [diff] [blame] | 1226 | pr_err("no crush rule pool %lld ruleset %d type %d size %d\n", |
| 1227 | pgid.pool, pool->crush_ruleset, pool->type, |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 1228 | pool->size); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1229 | return NULL; |
| 1230 | } |
| 1231 | |
Sage Weil | 83ca14f | 2013-02-26 10:39:09 -0800 | [diff] [blame] | 1232 | if (pool->flags & CEPH_POOL_FLAG_HASHPSPOOL) { |
| 1233 | /* hash pool id and seed sothat pool PGs do not overlap */ |
| 1234 | pps = crush_hash32_2(CRUSH_HASH_RJENKINS1, |
| 1235 | ceph_stable_mod(pgid.seed, pool->pgp_num, |
| 1236 | pool->pgp_num_mask), |
| 1237 | pgid.pool); |
| 1238 | } else { |
| 1239 | /* |
| 1240 | * legacy ehavior: add ps and pool together. this is |
| 1241 | * not a great approach because the PGs from each pool |
| 1242 | * will overlap on top of each other: 0.5 == 1.4 == |
| 1243 | * 2.3 == ... |
| 1244 | */ |
| 1245 | pps = ceph_stable_mod(pgid.seed, pool->pgp_num, |
| 1246 | pool->pgp_num_mask) + |
| 1247 | (unsigned)pgid.pool; |
| 1248 | } |
Ilya Dryomov | 9d52147 | 2014-01-31 17:54:26 +0200 | [diff] [blame] | 1249 | r = do_crush(osdmap, ruleno, pps, osds, min_t(int, pool->size, *num), |
| 1250 | osdmap->osd_weight, osdmap->max_osd); |
Sage Weil | 8b39326 | 2012-05-07 15:37:23 -0700 | [diff] [blame] | 1251 | if (r < 0) { |
Sage Weil | 83ca14f | 2013-02-26 10:39:09 -0800 | [diff] [blame] | 1252 | pr_err("error %d from crush rule: pool %lld ruleset %d type %d" |
| 1253 | " size %d\n", r, pgid.pool, pool->crush_ruleset, |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 1254 | pool->type, pool->size); |
Sage Weil | 8b39326 | 2012-05-07 15:37:23 -0700 | [diff] [blame] | 1255 | return NULL; |
| 1256 | } |
| 1257 | *num = r; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1258 | return osds; |
| 1259 | } |
| 1260 | |
| 1261 | /* |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 1262 | * Return acting set for given pgid. |
| 1263 | */ |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 1264 | int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, struct ceph_pg pgid, |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 1265 | int *acting) |
| 1266 | { |
| 1267 | int rawosds[CEPH_PG_MAX_SIZE], *osds; |
| 1268 | int i, o, num = CEPH_PG_MAX_SIZE; |
| 1269 | |
| 1270 | osds = calc_pg_raw(osdmap, pgid, rawosds, &num); |
| 1271 | if (!osds) |
| 1272 | return -1; |
| 1273 | |
| 1274 | /* primary is first up osd */ |
| 1275 | o = 0; |
| 1276 | for (i = 0; i < num; i++) |
| 1277 | if (ceph_osd_is_up(osdmap, osds[i])) |
| 1278 | acting[o++] = osds[i]; |
| 1279 | return o; |
| 1280 | } |
| 1281 | |
| 1282 | /* |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1283 | * Return primary osd for given pgid, or -1 if none. |
| 1284 | */ |
Sage Weil | 5b191d9 | 2013-02-23 10:38:16 -0800 | [diff] [blame] | 1285 | int ceph_calc_pg_primary(struct ceph_osdmap *osdmap, struct ceph_pg pgid) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1286 | { |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 1287 | int rawosds[CEPH_PG_MAX_SIZE], *osds; |
| 1288 | int i, num = CEPH_PG_MAX_SIZE; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1289 | |
| 1290 | osds = calc_pg_raw(osdmap, pgid, rawosds, &num); |
| 1291 | if (!osds) |
| 1292 | return -1; |
| 1293 | |
| 1294 | /* primary is first up osd */ |
| 1295 | for (i = 0; i < num; i++) |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 1296 | if (ceph_osd_is_up(osdmap, osds[i])) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1297 | return osds[i]; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1298 | return -1; |
| 1299 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1300 | EXPORT_SYMBOL(ceph_calc_pg_primary); |