Lines Matching +full:dout +full:- +full:default
1 // SPDX-License-Identifier: GPL-2.0
24 printk(KERN_INFO "%s (%pU e%u): %pV", KBUILD_MODNAME, &map->fsid, in osdmap_info()
25 map->epoch, &vaf); in osdmap_info()
60 * the foo_mask is the smallest value 2^n-1 that is >= foo.
64 pi->pg_num_mask = (1 << calc_bits_of(pi->pg_num-1)) - 1; in calc_pg_masks()
65 pi->pgp_num_mask = (1 << calc_bits_of(pi->pgp_num-1)) - 1; in calc_pg_masks()
74 dout("crush_decode_uniform_bucket %p to %p\n", *p, end); in crush_decode_uniform_bucket()
75 ceph_decode_need(p, end, (1+b->h.size) * sizeof(u32), bad); in crush_decode_uniform_bucket()
76 b->item_weight = ceph_decode_32(p); in crush_decode_uniform_bucket()
79 return -EINVAL; in crush_decode_uniform_bucket()
86 dout("crush_decode_list_bucket %p to %p\n", *p, end); in crush_decode_list_bucket()
87 b->item_weights = kcalloc(b->h.size, sizeof(u32), GFP_NOFS); in crush_decode_list_bucket()
88 if (b->item_weights == NULL) in crush_decode_list_bucket()
89 return -ENOMEM; in crush_decode_list_bucket()
90 b->sum_weights = kcalloc(b->h.size, sizeof(u32), GFP_NOFS); in crush_decode_list_bucket()
91 if (b->sum_weights == NULL) in crush_decode_list_bucket()
92 return -ENOMEM; in crush_decode_list_bucket()
93 ceph_decode_need(p, end, 2 * b->h.size * sizeof(u32), bad); in crush_decode_list_bucket()
94 for (j = 0; j < b->h.size; j++) { in crush_decode_list_bucket()
95 b->item_weights[j] = ceph_decode_32(p); in crush_decode_list_bucket()
96 b->sum_weights[j] = ceph_decode_32(p); in crush_decode_list_bucket()
100 return -EINVAL; in crush_decode_list_bucket()
107 dout("crush_decode_tree_bucket %p to %p\n", *p, end); in crush_decode_tree_bucket()
108 ceph_decode_8_safe(p, end, b->num_nodes, bad); in crush_decode_tree_bucket()
109 b->node_weights = kcalloc(b->num_nodes, sizeof(u32), GFP_NOFS); in crush_decode_tree_bucket()
110 if (b->node_weights == NULL) in crush_decode_tree_bucket()
111 return -ENOMEM; in crush_decode_tree_bucket()
112 ceph_decode_need(p, end, b->num_nodes * sizeof(u32), bad); in crush_decode_tree_bucket()
113 for (j = 0; j < b->num_nodes; j++) in crush_decode_tree_bucket()
114 b->node_weights[j] = ceph_decode_32(p); in crush_decode_tree_bucket()
117 return -EINVAL; in crush_decode_tree_bucket()
124 dout("crush_decode_straw_bucket %p to %p\n", *p, end); in crush_decode_straw_bucket()
125 b->item_weights = kcalloc(b->h.size, sizeof(u32), GFP_NOFS); in crush_decode_straw_bucket()
126 if (b->item_weights == NULL) in crush_decode_straw_bucket()
127 return -ENOMEM; in crush_decode_straw_bucket()
128 b->straws = kcalloc(b->h.size, sizeof(u32), GFP_NOFS); in crush_decode_straw_bucket()
129 if (b->straws == NULL) in crush_decode_straw_bucket()
130 return -ENOMEM; in crush_decode_straw_bucket()
131 ceph_decode_need(p, end, 2 * b->h.size * sizeof(u32), bad); in crush_decode_straw_bucket()
132 for (j = 0; j < b->h.size; j++) { in crush_decode_straw_bucket()
133 b->item_weights[j] = ceph_decode_32(p); in crush_decode_straw_bucket()
134 b->straws[j] = ceph_decode_32(p); in crush_decode_straw_bucket()
138 return -EINVAL; in crush_decode_straw_bucket()
145 dout("crush_decode_straw2_bucket %p to %p\n", *p, end); in crush_decode_straw2_bucket()
146 b->item_weights = kcalloc(b->h.size, sizeof(u32), GFP_NOFS); in crush_decode_straw2_bucket()
147 if (b->item_weights == NULL) in crush_decode_straw2_bucket()
148 return -ENOMEM; in crush_decode_straw2_bucket()
149 ceph_decode_need(p, end, b->h.size * sizeof(u32), bad); in crush_decode_straw2_bucket()
150 for (j = 0; j < b->h.size; j++) in crush_decode_straw2_bucket()
151 b->item_weights[j] = ceph_decode_32(p); in crush_decode_straw2_bucket()
154 return -EINVAL; in crush_decode_straw2_bucket()
171 RB_CLEAR_NODE(&cn->cn_node); in alloc_crush_name()
177 WARN_ON(!RB_EMPTY_NODE(&cn->cn_node)); in free_crush_name()
189 while (n--) { in DEFINE_RB_FUNCS()
200 return -ENOMEM; in DEFINE_RB_FUNCS()
202 cn->cn_id = id; in DEFINE_RB_FUNCS()
203 memcpy(cn->cn_name, *p, name_len); in DEFINE_RB_FUNCS()
204 cn->cn_name[name_len] = '\0'; in DEFINE_RB_FUNCS()
209 return -EEXIST; in DEFINE_RB_FUNCS()
216 return -EINVAL; in DEFINE_RB_FUNCS()
238 RB_CLEAR_NODE(&arg_map->node); in alloc_choose_arg_map()
247 WARN_ON(!RB_EMPTY_NODE(&arg_map->node)); in free_choose_arg_map()
249 for (i = 0; i < arg_map->size; i++) { in free_choose_arg_map()
250 struct crush_choose_arg *arg = &arg_map->args[i]; in free_choose_arg_map()
252 for (j = 0; j < arg->weight_set_size; j++) in free_choose_arg_map()
253 kfree(arg->weight_set[j].weights); in free_choose_arg_map()
254 kfree(arg->weight_set); in free_choose_arg_map()
255 kfree(arg->ids); in free_choose_arg_map()
257 kfree(arg_map->args); in free_choose_arg_map()
267 while (!RB_EMPTY_ROOT(&c->choose_args)) { in clear_choose_args()
269 rb_entry(rb_first(&c->choose_args), in clear_choose_args()
272 erase_choose_arg_map(&c->choose_args, arg_map); in clear_choose_args()
289 ret = -ENOMEM; in decode_array_32_alloc()
302 ret = -EINVAL; in decode_array_32_alloc()
309 * Assumes @arg is zero-initialized.
315 ceph_decode_32_safe(p, end, arg->weight_set_size, e_inval); in decode_choose_arg()
316 if (arg->weight_set_size) { in decode_choose_arg()
319 arg->weight_set = kmalloc_array(arg->weight_set_size, in decode_choose_arg()
320 sizeof(*arg->weight_set), in decode_choose_arg()
322 if (!arg->weight_set) in decode_choose_arg()
323 return -ENOMEM; in decode_choose_arg()
325 for (i = 0; i < arg->weight_set_size; i++) { in decode_choose_arg()
326 struct crush_weight_set *w = &arg->weight_set[i]; in decode_choose_arg()
328 w->weights = decode_array_32_alloc(p, end, &w->size); in decode_choose_arg()
329 if (IS_ERR(w->weights)) { in decode_choose_arg()
330 ret = PTR_ERR(w->weights); in decode_choose_arg()
331 w->weights = NULL; in decode_choose_arg()
337 arg->ids = decode_array_32_alloc(p, end, &arg->ids_size); in decode_choose_arg()
338 if (IS_ERR(arg->ids)) { in decode_choose_arg()
339 ret = PTR_ERR(arg->ids); in decode_choose_arg()
340 arg->ids = NULL; in decode_choose_arg()
347 return -EINVAL; in decode_choose_arg()
357 while (num_choose_arg_maps--) { in decode_choose_args()
360 ret = -ENOMEM; in decode_choose_args()
364 ceph_decode_64_safe(p, end, arg_map->choose_args_index, in decode_choose_args()
366 arg_map->size = c->max_buckets; in decode_choose_args()
367 arg_map->args = kcalloc(arg_map->size, sizeof(*arg_map->args), in decode_choose_args()
369 if (!arg_map->args) { in decode_choose_args()
370 ret = -ENOMEM; in decode_choose_args()
375 while (num_buckets--) { in decode_choose_args()
380 if (bucket_index >= arg_map->size) in decode_choose_args()
383 arg = &arg_map->args[bucket_index]; in decode_choose_args()
388 if (arg->ids_size && in decode_choose_args()
389 arg->ids_size != c->buckets[bucket_index]->size) in decode_choose_args()
393 insert_choose_arg_map(&c->choose_args, arg_map); in decode_choose_args()
399 ret = -EINVAL; in decode_choose_args()
409 /* Space for the array of pointers to per-bucket workspace */ in crush_finalize()
410 c->working_size = sizeof(struct crush_work) + in crush_finalize()
411 c->max_buckets * sizeof(struct crush_work_bucket *); in crush_finalize()
413 for (b = 0; b < c->max_buckets; b++) { in crush_finalize()
414 if (!c->buckets[b]) in crush_finalize()
417 switch (c->buckets[b]->alg) { in crush_finalize()
418 default: in crush_finalize()
423 c->working_size += sizeof(struct crush_work_bucket); in crush_finalize()
427 c->working_size += c->buckets[b]->size * sizeof(__u32); in crush_finalize()
440 dout("crush_decode %p to %p len %d\n", *p, end, (int)(end - *p)); in crush_decode()
444 return ERR_PTR(-ENOMEM); in crush_decode()
446 c->type_names = RB_ROOT; in crush_decode()
447 c->names = RB_ROOT; in crush_decode()
448 c->choose_args = RB_ROOT; in crush_decode()
450 /* set tunables to default values */ in crush_decode()
451 c->choose_local_tries = 2; in crush_decode()
452 c->choose_local_fallback_tries = 5; in crush_decode()
453 c->choose_total_tries = 19; in crush_decode()
454 c->chooseleaf_descend_once = 0; in crush_decode()
463 c->max_buckets = ceph_decode_32(p); in crush_decode()
464 c->max_rules = ceph_decode_32(p); in crush_decode()
465 c->max_devices = ceph_decode_32(p); in crush_decode()
467 c->buckets = kcalloc(c->max_buckets, sizeof(*c->buckets), GFP_NOFS); in crush_decode()
468 if (c->buckets == NULL) in crush_decode()
470 c->rules = kcalloc(c->max_rules, sizeof(*c->rules), GFP_NOFS); in crush_decode()
471 if (c->rules == NULL) in crush_decode()
475 for (i = 0; i < c->max_buckets; i++) { in crush_decode()
482 c->buckets[i] = NULL; in crush_decode()
485 dout("crush_decode bucket %d off %x %p to %p\n", in crush_decode()
486 i, (int)(*p-start), *p, end); in crush_decode()
504 default: in crush_decode()
508 b = c->buckets[i] = kzalloc(size, GFP_NOFS); in crush_decode()
513 b->id = ceph_decode_32(p); in crush_decode()
514 b->type = ceph_decode_16(p); in crush_decode()
515 b->alg = ceph_decode_8(p); in crush_decode()
516 b->hash = ceph_decode_8(p); in crush_decode()
517 b->weight = ceph_decode_32(p); in crush_decode()
518 b->size = ceph_decode_32(p); in crush_decode()
520 dout("crush_decode bucket size %d off %x %p to %p\n", in crush_decode()
521 b->size, (int)(*p-start), *p, end); in crush_decode()
523 b->items = kcalloc(b->size, sizeof(__s32), GFP_NOFS); in crush_decode()
524 if (b->items == NULL) in crush_decode()
527 ceph_decode_need(p, end, b->size*sizeof(u32), bad); in crush_decode()
528 for (j = 0; j < b->size; j++) in crush_decode()
529 b->items[j] = ceph_decode_32(p); in crush_decode()
531 switch (b->alg) { in crush_decode()
566 dout("rule vec is %p\n", c->rules); in crush_decode()
567 for (i = 0; i < c->max_rules; i++) { in crush_decode()
573 dout("crush_decode NO rule %d off %x %p to %p\n", in crush_decode()
574 i, (int)(*p-start), *p, end); in crush_decode()
575 c->rules[i] = NULL; in crush_decode()
579 dout("crush_decode rule %d off %x %p to %p\n", in crush_decode()
580 i, (int)(*p-start), *p, end); in crush_decode()
585 if (yes > (ULONG_MAX - sizeof(*r)) in crush_decode()
592 dout(" rule %d is at %p\n", i, r); in crush_decode()
593 c->rules[i] = r; in crush_decode()
594 r->len = yes; in crush_decode()
595 ceph_decode_copy_safe(p, end, &r->mask, 4, bad); /* 4 u8's */ in crush_decode()
596 ceph_decode_need(p, end, r->len*3*sizeof(u32), bad); in crush_decode()
597 for (j = 0; j < r->len; j++) { in crush_decode()
598 r->steps[j].op = ceph_decode_32(p); in crush_decode()
599 r->steps[j].arg1 = ceph_decode_32(p); in crush_decode()
600 r->steps[j].arg2 = ceph_decode_32(p); in crush_decode()
604 err = decode_crush_names(p, end, &c->type_names); in crush_decode()
608 err = decode_crush_names(p, end, &c->names); in crush_decode()
616 c->choose_local_tries = ceph_decode_32(p); in crush_decode()
617 c->choose_local_fallback_tries = ceph_decode_32(p); in crush_decode()
618 c->choose_total_tries = ceph_decode_32(p); in crush_decode()
619 dout("crush decode tunable choose_local_tries = %d\n", in crush_decode()
620 c->choose_local_tries); in crush_decode()
621 dout("crush decode tunable choose_local_fallback_tries = %d\n", in crush_decode()
622 c->choose_local_fallback_tries); in crush_decode()
623 dout("crush decode tunable choose_total_tries = %d\n", in crush_decode()
624 c->choose_total_tries); in crush_decode()
627 c->chooseleaf_descend_once = ceph_decode_32(p); in crush_decode()
628 dout("crush decode tunable chooseleaf_descend_once = %d\n", in crush_decode()
629 c->chooseleaf_descend_once); in crush_decode()
632 c->chooseleaf_vary_r = ceph_decode_8(p); in crush_decode()
633 dout("crush decode tunable chooseleaf_vary_r = %d\n", in crush_decode()
634 c->chooseleaf_vary_r); in crush_decode()
641 c->chooseleaf_stable = ceph_decode_8(p); in crush_decode()
642 dout("crush decode tunable chooseleaf_stable = %d\n", in crush_decode()
643 c->chooseleaf_stable); in crush_decode()
662 dout("crush_decode success\n"); in crush_decode()
666 err = -ENOMEM; in crush_decode()
668 dout("crush_decode fail %d\n", err); in crush_decode()
673 err = -EINVAL; in crush_decode()
679 if (lhs->pool < rhs->pool) in ceph_pg_compare()
680 return -1; in ceph_pg_compare()
681 if (lhs->pool > rhs->pool) in ceph_pg_compare()
683 if (lhs->seed < rhs->seed) in ceph_pg_compare()
684 return -1; in ceph_pg_compare()
685 if (lhs->seed > rhs->seed) in ceph_pg_compare()
695 ret = ceph_pg_compare(&lhs->pgid, &rhs->pgid); in ceph_spg_compare()
699 if (lhs->shard < rhs->shard) in ceph_spg_compare()
700 return -1; in ceph_spg_compare()
701 if (lhs->shard > rhs->shard) in ceph_spg_compare()
715 RB_CLEAR_NODE(&pg->node); in alloc_pg_mapping()
721 WARN_ON(!RB_EMPTY_NODE(&pg->node)); in free_pg_mapping()
740 return lookup_pg_pool(&map->pg_pools, id); in DEFINE_RB_FUNCS2()
753 pi = lookup_pg_pool(&map->pg_pools, id); in ceph_pg_pool_name_by_id()
754 return pi ? pi->name : NULL; in ceph_pg_pool_name_by_id()
762 for (rbp = rb_first(&map->pg_pools); rbp; rbp = rb_next(rbp)) { in ceph_pg_poolid_by_name()
765 if (pi->name && strcmp(pi->name, name) == 0) in ceph_pg_poolid_by_name()
766 return pi->id; in ceph_pg_poolid_by_name()
768 return -ENOENT; in ceph_pg_poolid_by_name()
776 pi = lookup_pg_pool(&map->pg_pools, id); in ceph_pg_pool_flags()
777 return pi ? pi->flags : 0; in ceph_pg_pool_flags()
784 kfree(pi->name); in __remove_pg_pool()
799 return -EINVAL; in decode_pool()
803 return -EINVAL; in decode_pool()
809 pi->type = ceph_decode_8(p); in decode_pool()
810 pi->size = ceph_decode_8(p); in decode_pool()
811 pi->crush_ruleset = ceph_decode_8(p); in decode_pool()
812 pi->object_hash = ceph_decode_8(p); in decode_pool()
814 pi->pg_num = ceph_decode_32(p); in decode_pool()
815 pi->pgp_num = ceph_decode_32(p); in decode_pool()
823 while (num--) { in decode_pool()
835 pi->flags = ceph_decode_64(p); in decode_pool()
839 pi->min_size = ceph_decode_8(p); in decode_pool()
841 pi->min_size = pi->size - pi->size / 2; in decode_pool()
854 pi->read_tier = ceph_decode_64(p); in decode_pool()
855 pi->write_tier = ceph_decode_64(p); in decode_pool()
857 pi->read_tier = -1; in decode_pool()
858 pi->write_tier = -1; in decode_pool()
864 while (num--) { in decode_pool()
905 pi->last_force_request_resend = ceph_decode_32(p); in decode_pool()
907 pi->last_force_request_resend = 0; in decode_pool()
940 pi->last_force_request_resend = ceph_decode_32(p); in decode_pool()
949 return -EINVAL; in decode_pool()
959 dout(" %d pool names\n", num); in decode_pool_names()
960 while (num--) { in decode_pool_names()
963 dout(" pool %llu len %d\n", pool, len); in decode_pool_names()
965 pi = lookup_pg_pool(&map->pg_pools, pool); in decode_pool_names()
970 return -ENOMEM; in decode_pool_names()
971 kfree(pi->name); in decode_pool_names()
972 pi->name = name; in decode_pool_names()
973 dout(" name is %s\n", pi->name); in decode_pool_names()
980 return -EINVAL; in decode_pool_names()
995 WARN_ON(!c->working_size); in alloc_workspace()
997 dout("%s work_size %zu bytes\n", __func__, work_size); in alloc_workspace()
1003 INIT_LIST_HEAD(&work->item); in alloc_workspace()
1010 WARN_ON(!list_empty(&work->item)); in free_workspace()
1016 INIT_LIST_HEAD(&wsm->idle_ws); in init_workspace_manager()
1017 spin_lock_init(&wsm->ws_lock); in init_workspace_manager()
1018 atomic_set(&wsm->total_ws, 0); in init_workspace_manager()
1019 wsm->free_ws = 0; in init_workspace_manager()
1020 init_waitqueue_head(&wsm->ws_wait); in init_workspace_manager()
1026 WARN_ON(!list_empty(&wsm->idle_ws)); in add_initial_workspace()
1028 list_add(&work->item, &wsm->idle_ws); in add_initial_workspace()
1029 atomic_set(&wsm->total_ws, 1); in add_initial_workspace()
1030 wsm->free_ws = 1; in add_initial_workspace()
1037 while (!list_empty(&wsm->idle_ws)) { in cleanup_workspace_manager()
1038 work = list_first_entry(&wsm->idle_ws, struct crush_work, in cleanup_workspace_manager()
1040 list_del_init(&work->item); in cleanup_workspace_manager()
1043 atomic_set(&wsm->total_ws, 0); in cleanup_workspace_manager()
1044 wsm->free_ws = 0; in cleanup_workspace_manager()
1058 spin_lock(&wsm->ws_lock); in get_workspace()
1059 if (!list_empty(&wsm->idle_ws)) { in get_workspace()
1060 work = list_first_entry(&wsm->idle_ws, struct crush_work, in get_workspace()
1062 list_del_init(&work->item); in get_workspace()
1063 wsm->free_ws--; in get_workspace()
1064 spin_unlock(&wsm->ws_lock); in get_workspace()
1068 if (atomic_read(&wsm->total_ws) > cpus) { in get_workspace()
1071 spin_unlock(&wsm->ws_lock); in get_workspace()
1072 prepare_to_wait(&wsm->ws_wait, &wait, TASK_UNINTERRUPTIBLE); in get_workspace()
1073 if (atomic_read(&wsm->total_ws) > cpus && !wsm->free_ws) in get_workspace()
1075 finish_wait(&wsm->ws_wait, &wait); in get_workspace()
1078 atomic_inc(&wsm->total_ws); in get_workspace()
1079 spin_unlock(&wsm->ws_lock); in get_workspace()
1083 atomic_dec(&wsm->total_ws); in get_workspace()
1084 wake_up(&wsm->ws_wait); in get_workspace()
1091 WARN_ON(atomic_read(&wsm->total_ws) < 1); in get_workspace()
1104 spin_lock(&wsm->ws_lock); in put_workspace()
1105 if (wsm->free_ws <= num_online_cpus()) { in put_workspace()
1106 list_add(&work->item, &wsm->idle_ws); in put_workspace()
1107 wsm->free_ws++; in put_workspace()
1108 spin_unlock(&wsm->ws_lock); in put_workspace()
1111 spin_unlock(&wsm->ws_lock); in put_workspace()
1114 atomic_dec(&wsm->total_ws); in put_workspace()
1116 if (wq_has_sleeper(&wsm->ws_wait)) in put_workspace()
1117 wake_up(&wsm->ws_wait); in put_workspace()
1131 map->pg_pools = RB_ROOT; in ceph_osdmap_alloc()
1132 map->pool_max = -1; in ceph_osdmap_alloc()
1133 map->pg_temp = RB_ROOT; in ceph_osdmap_alloc()
1134 map->primary_temp = RB_ROOT; in ceph_osdmap_alloc()
1135 map->pg_upmap = RB_ROOT; in ceph_osdmap_alloc()
1136 map->pg_upmap_items = RB_ROOT; in ceph_osdmap_alloc()
1138 init_workspace_manager(&map->crush_wsm); in ceph_osdmap_alloc()
1145 dout("osdmap_destroy %p\n", map); in ceph_osdmap_destroy()
1147 if (map->crush) in ceph_osdmap_destroy()
1148 crush_destroy(map->crush); in ceph_osdmap_destroy()
1149 cleanup_workspace_manager(&map->crush_wsm); in ceph_osdmap_destroy()
1151 while (!RB_EMPTY_ROOT(&map->pg_temp)) { in ceph_osdmap_destroy()
1153 rb_entry(rb_first(&map->pg_temp), in ceph_osdmap_destroy()
1155 erase_pg_mapping(&map->pg_temp, pg); in ceph_osdmap_destroy()
1158 while (!RB_EMPTY_ROOT(&map->primary_temp)) { in ceph_osdmap_destroy()
1160 rb_entry(rb_first(&map->primary_temp), in ceph_osdmap_destroy()
1162 erase_pg_mapping(&map->primary_temp, pg); in ceph_osdmap_destroy()
1165 while (!RB_EMPTY_ROOT(&map->pg_upmap)) { in ceph_osdmap_destroy()
1167 rb_entry(rb_first(&map->pg_upmap), in ceph_osdmap_destroy()
1169 rb_erase(&pg->node, &map->pg_upmap); in ceph_osdmap_destroy()
1172 while (!RB_EMPTY_ROOT(&map->pg_upmap_items)) { in ceph_osdmap_destroy()
1174 rb_entry(rb_first(&map->pg_upmap_items), in ceph_osdmap_destroy()
1176 rb_erase(&pg->node, &map->pg_upmap_items); in ceph_osdmap_destroy()
1179 while (!RB_EMPTY_ROOT(&map->pg_pools)) { in ceph_osdmap_destroy()
1181 rb_entry(rb_first(&map->pg_pools), in ceph_osdmap_destroy()
1183 __remove_pg_pool(&map->pg_pools, pi); in ceph_osdmap_destroy()
1185 kvfree(map->osd_state); in ceph_osdmap_destroy()
1186 kvfree(map->osd_weight); in ceph_osdmap_destroy()
1187 kvfree(map->osd_addr); in ceph_osdmap_destroy()
1188 kvfree(map->osd_primary_affinity); in ceph_osdmap_destroy()
1205 dout("%s old %u new %u\n", __func__, map->max_osd, max); in osdmap_set_max_osd()
1206 if (max == map->max_osd) in osdmap_set_max_osd()
1216 return -ENOMEM; in osdmap_set_max_osd()
1219 to_copy = min(map->max_osd, max); in osdmap_set_max_osd()
1220 if (map->osd_state) { in osdmap_set_max_osd()
1221 memcpy(state, map->osd_state, to_copy * sizeof(*state)); in osdmap_set_max_osd()
1222 memcpy(weight, map->osd_weight, to_copy * sizeof(*weight)); in osdmap_set_max_osd()
1223 memcpy(addr, map->osd_addr, to_copy * sizeof(*addr)); in osdmap_set_max_osd()
1224 kvfree(map->osd_state); in osdmap_set_max_osd()
1225 kvfree(map->osd_weight); in osdmap_set_max_osd()
1226 kvfree(map->osd_addr); in osdmap_set_max_osd()
1229 map->osd_state = state; in osdmap_set_max_osd()
1230 map->osd_weight = weight; in osdmap_set_max_osd()
1231 map->osd_addr = addr; in osdmap_set_max_osd()
1232 for (i = map->max_osd; i < max; i++) { in osdmap_set_max_osd()
1233 map->osd_state[i] = 0; in osdmap_set_max_osd()
1234 map->osd_weight[i] = CEPH_OSD_OUT; in osdmap_set_max_osd()
1235 memset(map->osd_addr + i, 0, sizeof(*map->osd_addr)); in osdmap_set_max_osd()
1238 if (map->osd_primary_affinity) { in osdmap_set_max_osd()
1244 return -ENOMEM; in osdmap_set_max_osd()
1246 memcpy(affinity, map->osd_primary_affinity, in osdmap_set_max_osd()
1248 kvfree(map->osd_primary_affinity); in osdmap_set_max_osd()
1250 map->osd_primary_affinity = affinity; in osdmap_set_max_osd()
1251 for (i = map->max_osd; i < max; i++) in osdmap_set_max_osd()
1252 map->osd_primary_affinity[i] = in osdmap_set_max_osd()
1256 map->max_osd = max; in osdmap_set_max_osd()
1271 return -ENOMEM; in osdmap_set_crush()
1274 if (map->crush) in osdmap_set_crush()
1275 crush_destroy(map->crush); in osdmap_set_crush()
1276 cleanup_workspace_manager(&map->crush_wsm); in osdmap_set_crush()
1277 map->crush = crush; in osdmap_set_crush()
1278 add_initial_workspace(&map->crush_wsm, work); in osdmap_set_crush()
1304 return -EINVAL; in get_osdmap_client_data_v()
1314 return -EINVAL; in get_osdmap_client_data_v()
1320 *p -= 1; in get_osdmap_client_data_v()
1325 return -EINVAL; in get_osdmap_client_data_v()
1336 return -EINVAL; in get_osdmap_client_data_v()
1345 while (n--) { in __decode_pools()
1352 pi = lookup_pg_pool(&map->pg_pools, pool); in __decode_pools()
1356 return -ENOMEM; in __decode_pools()
1358 RB_CLEAR_NODE(&pi->node); in __decode_pools()
1359 pi->id = pool; in __decode_pools()
1361 if (!__insert_pg_pool(&map->pg_pools, pi)) { in __decode_pools()
1363 return -EEXIST; in __decode_pools()
1375 return -EINVAL; in __decode_pools()
1398 while (n--) { in decode_pg_mapping()
1420 pg->pgid = pgid; /* struct */ in decode_pg_mapping()
1429 return -EINVAL; in decode_pg_mapping()
1441 if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32)) in __decode_pg_temp()
1442 return ERR_PTR(-EINVAL); in __decode_pg_temp()
1447 return ERR_PTR(-ENOMEM); in __decode_pg_temp()
1449 pg->pg_temp.len = len; in __decode_pg_temp()
1451 pg->pg_temp.osds[i] = ceph_decode_32(p); in __decode_pg_temp()
1456 return ERR_PTR(-EINVAL); in __decode_pg_temp()
1461 return decode_pg_mapping(p, end, &map->pg_temp, __decode_pg_temp, in decode_pg_temp()
1467 return decode_pg_mapping(p, end, &map->pg_temp, __decode_pg_temp, in decode_new_pg_temp()
1478 if (osd == (u32)-1 && incremental) in __decode_primary_temp()
1479 return NULL; /* new_primary_temp: -1 to remove */ in __decode_primary_temp()
1483 return ERR_PTR(-ENOMEM); in __decode_primary_temp()
1485 pg->primary_temp.osd = osd; in __decode_primary_temp()
1489 return ERR_PTR(-EINVAL); in __decode_primary_temp()
1494 return decode_pg_mapping(p, end, &map->primary_temp, in decode_primary_temp()
1501 return decode_pg_mapping(p, end, &map->primary_temp, in decode_new_primary_temp()
1507 BUG_ON(osd >= map->max_osd); in ceph_get_primary_affinity()
1509 if (!map->osd_primary_affinity) in ceph_get_primary_affinity()
1512 return map->osd_primary_affinity[osd]; in ceph_get_primary_affinity()
1517 BUG_ON(osd >= map->max_osd); in set_primary_affinity()
1519 if (!map->osd_primary_affinity) { in set_primary_affinity()
1522 map->osd_primary_affinity = kvmalloc( in set_primary_affinity()
1523 array_size(map->max_osd, sizeof(*map->osd_primary_affinity)), in set_primary_affinity()
1525 if (!map->osd_primary_affinity) in set_primary_affinity()
1526 return -ENOMEM; in set_primary_affinity()
1528 for (i = 0; i < map->max_osd; i++) in set_primary_affinity()
1529 map->osd_primary_affinity[i] = in set_primary_affinity()
1533 map->osd_primary_affinity[osd] = aff; in set_primary_affinity()
1545 kvfree(map->osd_primary_affinity); in decode_primary_affinity()
1546 map->osd_primary_affinity = NULL; in decode_primary_affinity()
1549 if (len != map->max_osd) in decode_primary_affinity()
1552 ceph_decode_need(p, end, map->max_osd*sizeof(u32), e_inval); in decode_primary_affinity()
1554 for (i = 0; i < map->max_osd; i++) { in decode_primary_affinity()
1565 return -EINVAL; in decode_primary_affinity()
1574 while (n--) { in decode_new_primary_affinity()
1585 osdmap_info(map, "osd%d primary-affinity 0x%x\n", osd, aff); in decode_new_primary_affinity()
1591 return -EINVAL; in decode_new_primary_affinity()
1602 return decode_pg_mapping(p, end, &map->pg_upmap, __decode_pg_upmap, in decode_pg_upmap()
1608 return decode_pg_mapping(p, end, &map->pg_upmap, __decode_pg_upmap, in decode_new_pg_upmap()
1614 return decode_pg_mapping(p, end, &map->pg_upmap, NULL, true); in decode_old_pg_upmap()
1624 if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32))) in __decode_pg_upmap_items()
1625 return ERR_PTR(-EINVAL); in __decode_pg_upmap_items()
1630 return ERR_PTR(-ENOMEM); in __decode_pg_upmap_items()
1632 pg->pg_upmap_items.len = len; in __decode_pg_upmap_items()
1634 pg->pg_upmap_items.from_to[i][0] = ceph_decode_32(p); in __decode_pg_upmap_items()
1635 pg->pg_upmap_items.from_to[i][1] = ceph_decode_32(p); in __decode_pg_upmap_items()
1641 return ERR_PTR(-EINVAL); in __decode_pg_upmap_items()
1646 return decode_pg_mapping(p, end, &map->pg_upmap_items, in decode_pg_upmap_items()
1653 return decode_pg_mapping(p, end, &map->pg_upmap_items, in decode_new_pg_upmap_items()
1660 return decode_pg_mapping(p, end, &map->pg_upmap_items, NULL, true); in decode_old_pg_upmap_items()
1676 dout("%s %p to %p len %d\n", __func__, *p, end, (int)(end - *p)); in osdmap_decode()
1683 ceph_decode_need(p, end, sizeof(map->fsid) + sizeof(u32) + in osdmap_decode()
1684 sizeof(map->created) + sizeof(map->modified), e_inval); in osdmap_decode()
1685 ceph_decode_copy(p, &map->fsid, sizeof(map->fsid)); in osdmap_decode()
1686 epoch = map->epoch = ceph_decode_32(p); in osdmap_decode()
1687 ceph_decode_copy(p, &map->created, sizeof(map->created)); in osdmap_decode()
1688 ceph_decode_copy(p, &map->modified, sizeof(map->modified)); in osdmap_decode()
1700 ceph_decode_32_safe(p, end, map->pool_max, e_inval); in osdmap_decode()
1702 ceph_decode_32_safe(p, end, map->flags, e_inval); in osdmap_decode()
1712 /* osd_state, osd_weight, osd_addrs->client_addr */ in osdmap_decode()
1714 map->max_osd*(struct_v >= 5 ? sizeof(u32) : in osdmap_decode()
1716 sizeof(*map->osd_weight), e_inval); in osdmap_decode()
1717 if (ceph_decode_32(p) != map->max_osd) in osdmap_decode()
1721 for (i = 0; i < map->max_osd; i++) in osdmap_decode()
1722 map->osd_state[i] = ceph_decode_32(p); in osdmap_decode()
1724 for (i = 0; i < map->max_osd; i++) in osdmap_decode()
1725 map->osd_state[i] = ceph_decode_8(p); in osdmap_decode()
1728 if (ceph_decode_32(p) != map->max_osd) in osdmap_decode()
1731 for (i = 0; i < map->max_osd; i++) in osdmap_decode()
1732 map->osd_weight[i] = ceph_decode_32(p); in osdmap_decode()
1734 if (ceph_decode_32(p) != map->max_osd) in osdmap_decode()
1737 for (i = 0; i < map->max_osd; i++) { in osdmap_decode()
1738 struct ceph_entity_addr *addr = &map->osd_addr[i]; in osdmap_decode()
1747 dout("%s osd%d addr %s\n", __func__, i, ceph_pr_addr(addr)); in osdmap_decode()
1768 WARN_ON(map->osd_primary_affinity); in osdmap_decode()
1793 WARN_ON(!RB_EMPTY_ROOT(&map->pg_upmap)); in osdmap_decode()
1794 WARN_ON(!RB_EMPTY_ROOT(&map->pg_upmap_items)); in osdmap_decode()
1800 dout("full osdmap epoch %d max_osd %d\n", map->epoch, map->max_osd); in osdmap_decode()
1804 err = -EINVAL; in osdmap_decode()
1806 pr_err("corrupt full osdmap (%d) epoch %d off %d (%p of %p-%p)\n", in osdmap_decode()
1807 err, epoch, (int)(*p - start), *p, start, end); in osdmap_decode()
1810 start, end - start, true); in osdmap_decode()
1824 return ERR_PTR(-ENOMEM); in ceph_osdmap_decode()
1875 while (len--) { in decode_new_up_state_weight()
1882 BUG_ON(osd >= map->max_osd); in decode_new_up_state_weight()
1886 map->osd_weight[osd] = w; in decode_new_up_state_weight()
1893 map->osd_state[osd] |= CEPH_OSD_EXISTS; in decode_new_up_state_weight()
1894 map->osd_state[osd] &= ~(CEPH_OSD_AUTOOUT | in decode_new_up_state_weight()
1903 while (len--) { in decode_new_up_state_weight()
1914 BUG_ON(osd >= map->max_osd); in decode_new_up_state_weight()
1915 if ((map->osd_state[osd] & CEPH_OSD_UP) && in decode_new_up_state_weight()
1918 if ((map->osd_state[osd] & CEPH_OSD_EXISTS) && in decode_new_up_state_weight()
1925 memset(map->osd_addr + osd, 0, sizeof(*map->osd_addr)); in decode_new_up_state_weight()
1926 map->osd_state[osd] = 0; in decode_new_up_state_weight()
1928 map->osd_state[osd] ^= xorstate; in decode_new_up_state_weight()
1935 while (len--) { in decode_new_up_state_weight()
1940 BUG_ON(osd >= map->max_osd); in decode_new_up_state_weight()
1948 dout("%s osd%d addr %s\n", __func__, osd, ceph_pr_addr(&addr)); in decode_new_up_state_weight()
1951 map->osd_state[osd] |= CEPH_OSD_EXISTS | CEPH_OSD_UP; in decode_new_up_state_weight()
1952 map->osd_addr[osd] = addr; in decode_new_up_state_weight()
1959 return -EINVAL; in decode_new_up_state_weight()
1979 dout("%s %p to %p len %d\n", __func__, *p, end, (int)(end - *p)); in osdmap_apply_incremental()
1990 BUG_ON(epoch != map->epoch+1); in osdmap_apply_incremental()
1998 dout("apply_incremental full map len %d, %p to %p\n", in osdmap_apply_incremental()
2015 map->flags = new_flags; in osdmap_apply_incremental()
2017 map->pool_max = new_pool_max; in osdmap_apply_incremental()
2027 map->epoch++; in osdmap_apply_incremental()
2028 map->modified = modified; in osdmap_apply_incremental()
2042 while (len--) { in osdmap_apply_incremental()
2046 pi = lookup_pg_pool(&map->pg_pools, pool); in osdmap_apply_incremental()
2048 __remove_pg_pool(&map->pg_pools, pi); in osdmap_apply_incremental()
2104 dout("inc osdmap epoch %d max_osd %d\n", map->epoch, map->max_osd); in osdmap_apply_incremental()
2108 err = -EINVAL; in osdmap_apply_incremental()
2110 pr_err("corrupt inc osdmap (%d) epoch %d off %d (%p of %p-%p)\n", in osdmap_apply_incremental()
2111 err, epoch, (int)(*p - start), *p, start, end); in osdmap_apply_incremental()
2114 start, end - start, true); in osdmap_apply_incremental()
2123 dest->pool = src->pool; in ceph_oloc_copy()
2124 if (src->pool_ns) in ceph_oloc_copy()
2125 dest->pool_ns = ceph_get_string(src->pool_ns); in ceph_oloc_copy()
2127 dest->pool_ns = NULL; in ceph_oloc_copy()
2133 ceph_put_string(oloc->pool_ns); in ceph_oloc_destroy()
2142 if (src->name != src->inline_name) { in ceph_oid_copy()
2144 dest->name = kmalloc(src->name_len + 1, in ceph_oid_copy()
2147 dest->name = dest->inline_name; in ceph_oid_copy()
2149 memcpy(dest->name, src->name, src->name_len + 1); in ceph_oid_copy()
2150 dest->name_len = src->name_len; in ceph_oid_copy()
2161 len = vsnprintf(oid->inline_name, sizeof(oid->inline_name), fmt, ap); in oid_printf_vargs()
2162 if (len >= sizeof(oid->inline_name)) in oid_printf_vargs()
2165 oid->name_len = len; in oid_printf_vargs()
2198 return -ENOMEM; in oid_aprintf_vargs()
2200 oid->name = external_name; in oid_aprintf_vargs()
2201 WARN_ON(vsnprintf(oid->name, len + 1, fmt, ap) != len); in oid_aprintf_vargs()
2202 oid->name_len = len; in oid_aprintf_vargs()
2227 if (oid->name != oid->inline_name) in ceph_oid_destroy()
2228 kfree(oid->name); in ceph_oid_destroy()
2238 if (lhs->size == rhs->size && in __osds_equal()
2239 !memcmp(lhs->osds, rhs->osds, rhs->size * sizeof(rhs->osds[0]))) in __osds_equal()
2252 lhs->primary == rhs->primary) in osds_equal()
2260 /* non-empty set */ in osds_valid()
2261 if (set->size > 0 && set->primary >= 0) in osds_valid()
2265 if (!set->size && set->primary == -1) in osds_valid()
2268 /* empty !can_shift_osds set - all NONE */ in osds_valid()
2269 if (set->size > 0 && set->primary == -1) { in osds_valid()
2272 for (i = 0; i < set->size; i++) { in osds_valid()
2273 if (set->osds[i] != CRUSH_ITEM_NONE) in osds_valid()
2276 if (i == set->size) in osds_valid()
2285 memcpy(dest->osds, src->osds, src->size * sizeof(src->osds[0])); in ceph_osds_copy()
2286 dest->size = src->size; in ceph_osds_copy()
2287 dest->primary = src->primary; in ceph_osds_copy()
2294 int old_mask = (1 << old_bits) - 1; in ceph_pg_is_split()
2297 WARN_ON(pgid->seed >= old_pg_num); in ceph_pg_is_split()
2302 int next_bit = n << (old_bits - 1); in ceph_pg_is_split()
2303 u32 s = next_bit | pgid->seed; in ceph_pg_is_split()
2305 if (s < old_pg_num || s == pgid->seed) in ceph_pg_is_split()
2311 if (s == pgid->seed) in ceph_pg_is_split()
2347 for (i = 0; i < acting->size; i++) { in calc_pg_rank()
2348 if (acting->osds[i] == osd) in calc_pg_rank()
2352 return -1; in calc_pg_rank()
2358 if (!old_acting->size && !new_acting->size) in primary_changed()
2361 if (!old_acting->size ^ !new_acting->size) in primary_changed()
2364 if (old_acting->primary != new_acting->primary) in primary_changed()
2367 if (calc_pg_rank(old_acting->primary, old_acting) != in primary_changed()
2368 calc_pg_rank(new_acting->primary, new_acting)) in primary_changed()
2398 WARN_ON(pi->id != oloc->pool); in __ceph_object_locator_to_pg()
2400 if (!oloc->pool_ns) { in __ceph_object_locator_to_pg()
2401 raw_pgid->pool = oloc->pool; in __ceph_object_locator_to_pg()
2402 raw_pgid->seed = ceph_str_hash(pi->object_hash, oid->name, in __ceph_object_locator_to_pg()
2403 oid->name_len); in __ceph_object_locator_to_pg()
2404 dout("%s %s -> raw_pgid %llu.%x\n", __func__, oid->name, in __ceph_object_locator_to_pg()
2405 raw_pgid->pool, raw_pgid->seed); in __ceph_object_locator_to_pg()
2409 int nsl = oloc->pool_ns->len; in __ceph_object_locator_to_pg()
2410 size_t total = nsl + 1 + oid->name_len; in __ceph_object_locator_to_pg()
2414 memcpy(buf, oloc->pool_ns->str, nsl); in __ceph_object_locator_to_pg()
2416 memcpy(buf + nsl + 1, oid->name, oid->name_len); in __ceph_object_locator_to_pg()
2417 raw_pgid->pool = oloc->pool; in __ceph_object_locator_to_pg()
2418 raw_pgid->seed = ceph_str_hash(pi->object_hash, buf, total); in __ceph_object_locator_to_pg()
2421 dout("%s %s ns %.*s -> raw_pgid %llu.%x\n", __func__, in __ceph_object_locator_to_pg()
2422 oid->name, nsl, oloc->pool_ns->str, in __ceph_object_locator_to_pg()
2423 raw_pgid->pool, raw_pgid->seed); in __ceph_object_locator_to_pg()
2434 pi = ceph_pg_pool_by_id(osdmap, oloc->pool); in ceph_object_locator_to_pg()
2436 return -ENOENT; in ceph_object_locator_to_pg()
2450 pgid->pool = raw_pgid->pool; in raw_pg_to_pg()
2451 pgid->seed = ceph_stable_mod(raw_pgid->seed, pi->pg_num, in raw_pg_to_pg()
2452 pi->pg_num_mask); in raw_pg_to_pg()
2463 if (pi->flags & CEPH_POOL_FLAG_HASHPSPOOL) { in raw_pg_to_pps()
2466 ceph_stable_mod(raw_pgid->seed, in raw_pg_to_pps()
2467 pi->pgp_num, in raw_pg_to_pps()
2468 pi->pgp_num_mask), in raw_pg_to_pps()
2469 raw_pgid->pool); in raw_pg_to_pps()
2477 return ceph_stable_mod(raw_pgid->seed, pi->pgp_num, in raw_pg_to_pps()
2478 pi->pgp_num_mask) + in raw_pg_to_pps()
2479 (unsigned)raw_pgid->pool; in raw_pg_to_pps()
2484 * Magic value used for a "default" fallback choose_args, used if the
2488 #define CEPH_DEFAULT_CHOOSE_ARGS -1
2501 arg_map = lookup_choose_arg_map(&map->crush->choose_args, in do_crush()
2504 arg_map = lookup_choose_arg_map(&map->crush->choose_args, in do_crush()
2507 work = get_workspace(&map->crush_wsm, map->crush); in do_crush()
2508 r = crush_do_rule(map->crush, ruleno, x, result, result_max, in do_crush()
2510 arg_map ? arg_map->args : NULL); in do_crush()
2511 put_workspace(&map->crush_wsm, work); in do_crush()
2525 for (i = 0; i < set->size; i++) { in remove_nonexistent_osds()
2526 if (!ceph_osd_exists(osdmap, set->osds[i])) { in remove_nonexistent_osds()
2531 set->osds[i - removed] = set->osds[i]; in remove_nonexistent_osds()
2533 set->size -= removed; in remove_nonexistent_osds()
2536 for (i = 0; i < set->size; i++) { in remove_nonexistent_osds()
2537 if (!ceph_osd_exists(osdmap, set->osds[i])) in remove_nonexistent_osds()
2538 set->osds[i] = CRUSH_ITEM_NONE; in remove_nonexistent_osds()
2545 * nonexistent OSDs. ->primary is undefined for a raw set.
2563 ruleno = crush_find_rule(osdmap->crush, pi->crush_ruleset, pi->type, in pg_to_raw_osds()
2564 pi->size); in pg_to_raw_osds()
2567 pi->id, pi->crush_ruleset, pi->type, pi->size); in pg_to_raw_osds()
2571 if (pi->size > ARRAY_SIZE(raw->osds)) { in pg_to_raw_osds()
2573 pi->id, pi->crush_ruleset, pi->type, pi->size, in pg_to_raw_osds()
2574 ARRAY_SIZE(raw->osds)); in pg_to_raw_osds()
2578 len = do_crush(osdmap, ruleno, pps, raw->osds, pi->size, in pg_to_raw_osds()
2579 osdmap->osd_weight, osdmap->max_osd, pi->id); in pg_to_raw_osds()
2582 len, ruleno, pi->id, pi->crush_ruleset, pi->type, in pg_to_raw_osds()
2583 pi->size); in pg_to_raw_osds()
2587 raw->size = len; in pg_to_raw_osds()
2599 pg = lookup_pg_mapping(&osdmap->pg_upmap, pgid); in apply_upmap()
2602 for (i = 0; i < pg->pg_upmap.len; i++) { in apply_upmap()
2603 int osd = pg->pg_upmap.osds[i]; in apply_upmap()
2606 osd < osdmap->max_osd && in apply_upmap()
2607 osdmap->osd_weight[osd] == 0) { in apply_upmap()
2612 for (i = 0; i < pg->pg_upmap.len; i++) in apply_upmap()
2613 raw->osds[i] = pg->pg_upmap.osds[i]; in apply_upmap()
2614 raw->size = pg->pg_upmap.len; in apply_upmap()
2618 pg = lookup_pg_mapping(&osdmap->pg_upmap_items, pgid); in apply_upmap()
2622 * e.g., [[1,2],[2,1]] applied to [0,1,2] -> [0,2,1]. in apply_upmap()
2624 for (i = 0; i < pg->pg_upmap_items.len; i++) { in apply_upmap()
2625 int from = pg->pg_upmap_items.from_to[i][0]; in apply_upmap()
2626 int to = pg->pg_upmap_items.from_to[i][1]; in apply_upmap()
2627 int pos = -1; in apply_upmap()
2631 for (j = 0; j < raw->size; j++) { in apply_upmap()
2632 int osd = raw->osds[j]; in apply_upmap()
2641 to < osdmap->max_osd && in apply_upmap()
2642 osdmap->osd_weight[to] == 0)) { in apply_upmap()
2647 raw->osds[pos] = to; in apply_upmap()
2656 * This is done in-place - on return @set is the up set. If it's
2657 * empty, ->primary will remain undefined.
2665 /* ->primary is undefined for a raw set */ in raw_to_up_osds()
2666 BUG_ON(set->primary != -1); in raw_to_up_osds()
2672 for (i = 0; i < set->size; i++) { in raw_to_up_osds()
2673 if (ceph_osd_is_down(osdmap, set->osds[i])) { in raw_to_up_osds()
2678 set->osds[i - removed] = set->osds[i]; in raw_to_up_osds()
2680 set->size -= removed; in raw_to_up_osds()
2681 if (set->size > 0) in raw_to_up_osds()
2682 set->primary = set->osds[0]; in raw_to_up_osds()
2685 for (i = set->size - 1; i >= 0; i--) { in raw_to_up_osds()
2686 if (ceph_osd_is_down(osdmap, set->osds[i])) in raw_to_up_osds()
2687 set->osds[i] = CRUSH_ITEM_NONE; in raw_to_up_osds()
2689 set->primary = set->osds[i]; in raw_to_up_osds()
2700 int pos = -1; in apply_primary_affinity()
2703 * Do we have any non-default primary_affinity values for these in apply_primary_affinity()
2706 if (!osdmap->osd_primary_affinity) in apply_primary_affinity()
2709 for (i = 0; i < up->size; i++) { in apply_primary_affinity()
2710 int osd = up->osds[i]; in apply_primary_affinity()
2713 osdmap->osd_primary_affinity[osd] != in apply_primary_affinity()
2718 if (i == up->size) in apply_primary_affinity()
2726 for (i = 0; i < up->size; i++) { in apply_primary_affinity()
2727 int osd = up->osds[i]; in apply_primary_affinity()
2733 aff = osdmap->osd_primary_affinity[osd]; in apply_primary_affinity()
2752 up->primary = up->osds[pos]; in apply_primary_affinity()
2756 for (i = pos; i > 0; i--) in apply_primary_affinity()
2757 up->osds[i] = up->osds[i - 1]; in apply_primary_affinity()
2758 up->osds[0] = up->primary; in apply_primary_affinity()
2768 * @temp will have its ->primary >= 0 but ->size == 0.
2781 pg = lookup_pg_mapping(&osdmap->pg_temp, pgid); in get_temp_osds()
2783 for (i = 0; i < pg->pg_temp.len; i++) { in get_temp_osds()
2784 if (ceph_osd_is_down(osdmap, pg->pg_temp.osds[i])) { in get_temp_osds()
2788 temp->osds[temp->size++] = CRUSH_ITEM_NONE; in get_temp_osds()
2790 temp->osds[temp->size++] = pg->pg_temp.osds[i]; in get_temp_osds()
2795 for (i = 0; i < temp->size; i++) { in get_temp_osds()
2796 if (temp->osds[i] != CRUSH_ITEM_NONE) { in get_temp_osds()
2797 temp->primary = temp->osds[i]; in get_temp_osds()
2804 pg = lookup_pg_mapping(&osdmap->primary_temp, pgid); in get_temp_osds()
2806 temp->primary = pg->primary_temp.osd; in get_temp_osds()
2825 WARN_ON(pi->id != raw_pgid->pool); in ceph_pg_to_up_acting_osds()
2833 if (!acting->size) { in ceph_pg_to_up_acting_osds()
2834 memcpy(acting->osds, up->osds, up->size * sizeof(up->osds[0])); in ceph_pg_to_up_acting_osds()
2835 acting->size = up->size; in ceph_pg_to_up_acting_osds()
2836 if (acting->primary == -1) in ceph_pg_to_up_acting_osds()
2837 acting->primary = up->primary; in ceph_pg_to_up_acting_osds()
2851 WARN_ON(pi->id != raw_pgid->pool); in ceph_pg_to_primary_shard()
2855 spgid->pgid = pgid; /* struct */ in ceph_pg_to_primary_shard()
2856 spgid->shard = CEPH_SPG_NOSHARD; in ceph_pg_to_primary_shard()
2863 spgid->pgid = pgid; /* struct */ in ceph_pg_to_primary_shard()
2864 spgid->shard = i; in ceph_pg_to_primary_shard()
2873 * Return acting primary for given PG, or -1 if none.
2881 pi = ceph_pg_pool_by_id(osdmap, raw_pgid->pool); in ceph_pg_to_acting_primary()
2883 return -1; in ceph_pg_to_acting_primary()
2899 RB_CLEAR_NODE(&loc->cl_node); in alloc_crush_loc()
2905 WARN_ON(!RB_EMPTY_NODE(&loc->cl_node)); in free_crush_loc()
2913 return strcmp(loc1->cl_type_name, loc2->cl_type_name) ?: in crush_loc_compare()
2914 strcmp(loc1->cl_name, loc2->cl_name); in crush_loc_compare()
2932 dout("%s '%s'\n", __func__, crush_location); in DEFINE_RB_FUNCS2()
2936 return -EINVAL; in DEFINE_RB_FUNCS2()
2938 type_name_len = colon - type_name; in DEFINE_RB_FUNCS2()
2940 return -EINVAL; in DEFINE_RB_FUNCS2()
2945 return -EINVAL; in DEFINE_RB_FUNCS2()
2949 return -ENOMEM; in DEFINE_RB_FUNCS2()
2951 loc->cl_loc.cl_type_name = loc->cl_data; in DEFINE_RB_FUNCS2()
2952 memcpy(loc->cl_loc.cl_type_name, type_name, type_name_len); in DEFINE_RB_FUNCS2()
2953 loc->cl_loc.cl_type_name[type_name_len] = '\0'; in DEFINE_RB_FUNCS2()
2955 loc->cl_loc.cl_name = loc->cl_data + type_name_len + 1; in DEFINE_RB_FUNCS2()
2956 memcpy(loc->cl_loc.cl_name, name, name_len); in DEFINE_RB_FUNCS2()
2957 loc->cl_loc.cl_name[name_len] = '\0'; in DEFINE_RB_FUNCS2()
2961 return -EEXIST; in DEFINE_RB_FUNCS2()
2964 dout("%s type_name '%s' name '%s'\n", __func__, in DEFINE_RB_FUNCS2()
2965 loc->cl_loc.cl_type_name, loc->cl_loc.cl_name); in DEFINE_RB_FUNCS2()
2983 ret = crush_loc_compare(&loc1->cl_loc, &loc2->cl_loc); in ceph_compare_crush_locs()
2989 return -1; in ceph_compare_crush_locs()
3007 * [a-zA-Z0-9-_.]+
3015 *name != '-' && *name != '_' && *name != '.') in is_valid_crush_name()
3040 for (i = 0; i < c->max_buckets; i++) { in get_immediate_parent()
3041 b = c->buckets[i]; in get_immediate_parent()
3045 /* ignore per-class shadow hierarchy */ in get_immediate_parent()
3046 cn = lookup_crush_name(&c->names, b->id); in get_immediate_parent()
3047 if (!cn || !is_valid_crush_name(cn->cn_name)) in get_immediate_parent()
3050 for (j = 0; j < b->size; j++) { in get_immediate_parent()
3051 if (b->items[j] != id) in get_immediate_parent()
3054 *parent_type_id = b->type; in get_immediate_parent()
3055 type_cn = lookup_crush_name(&c->type_names, b->type); in get_immediate_parent()
3056 parent_loc->cl_type_name = type_cn->cn_name; in get_immediate_parent()
3057 parent_loc->cl_name = cn->cn_name; in get_immediate_parent()
3058 return b->id; in get_immediate_parent()
3069 * for the lowest-valued bucket type for which the location of
3076 * as "rack=foo1 rack=foo2 datacenter=bar" is allowed -- @locs
3079 * - 3 for OSDs in racks foo1 and foo2
3080 * - 8 for OSDs in data center bar
3081 * - -1 for all other OSDs
3096 * depth-first traversal. in ceph_get_crush_locality()
3099 id = get_immediate_parent(osdmap->crush, id, &type_id, &loc); in ceph_get_crush_locality()
3101 return -1; /* not local */ in ceph_get_crush_locality()