/* Space for the array of pointers to per-bucket workspace */
c->working_size = sizeof(struct crush_work) +
c->max_buckets * sizeof(struct crush_work_bucket *);
for (b = 0; b < c->max_buckets; b++) { if (!c->buckets[b]) continue;
switch (c->buckets[b]->alg) { default: /* * The base case, permutation variables and * the pointer to the permutation array.
*/
c->working_size += sizeof(struct crush_work_bucket); break;
} /* Every bucket has a permutation array. */
c->working_size += c->buckets[b]->size * sizeof(__u32);
}
}
staticstruct crush_map *crush_decode(void *pbyval, void *end)
{ struct crush_map *c; int err; int i, j; void **p = &pbyval; void *start = pbyval;
u32 magic;
dout("crush_decode %p to %p len %d\n", *p, end, (int)(end - *p));
c = kzalloc(sizeof(*c), GFP_NOFS); if (c == NULL) return ERR_PTR(-ENOMEM);
switch (b->alg) { case CRUSH_BUCKET_UNIFORM:
err = crush_decode_uniform_bucket(p, end,
(struct crush_bucket_uniform *)b); if (err < 0) goto fail; break; case CRUSH_BUCKET_LIST:
err = crush_decode_list_bucket(p, end,
(struct crush_bucket_list *)b); if (err < 0) goto fail; break; case CRUSH_BUCKET_TREE:
err = crush_decode_tree_bucket(p, end,
(struct crush_bucket_tree *)b); if (err < 0) goto fail; break; case CRUSH_BUCKET_STRAW:
err = crush_decode_straw_bucket(p, end,
(struct crush_bucket_straw *)b); if (err < 0) goto fail; break; case CRUSH_BUCKET_STRAW2:
err = crush_decode_straw2_bucket(p, end,
(struct crush_bucket_straw2 *)b); if (err < 0) goto fail; break;
}
}
/* rules */
dout("rule vec is %p\n", c->rules); for (i = 0; i < c->max_rules; i++) {
u32 yes; struct crush_rule *r;
ceph_decode_32_safe(p, end, yes, bad); if (!yes) {
dout("crush_decode NO rule %d off %x %p to %p\n",
i, (int)(*p-start), *p, end);
c->rules[i] = NULL; continue;
}
dout("crush_decode rule %d off %x %p to %p\n",
i, (int)(*p-start), *p, end);
/* * rbtree of pg_mapping for handling pg_temp (explicit mapping of pgid * to a set of osds) and primary_temp (explicit primary setting)
*/
DEFINE_RB_FUNCS2(pg_mapping, struct ceph_pg_mapping, pgid, ceph_pg_compare,
RB_BYPTR, conststruct ceph_pg *, node)
/* * rbtree of pg pool info
*/
DEFINE_RB_FUNCS(pg_pool, struct ceph_pg_pool_info, id, node)
if (ev >= 14) { /* skip erasure_code_profile */
len = ceph_decode_32(p);
*p += len;
}
/* * last_force_op_resend_preluminous, will be overridden if the * map was encoded with RESEND_ON_SPLIT
*/ if (ev >= 15)
pi->last_force_request_resend = ceph_decode_32(p); else
pi->last_force_request_resend = 0;
ceph_decode_32_safe(p, end, num, bad);
dout(" %d pool names\n", num); while (num--) {
ceph_decode_64_safe(p, end, pool, bad);
ceph_decode_32_safe(p, end, len, bad);
dout(" pool %llu len %d\n", pool, len);
ceph_decode_need(p, end, len, bad);
pi = lookup_pg_pool(&map->pg_pools, pool); if (pi) { char *name = kstrndup(*p, len, GFP_NOFS);
if (!name) return -ENOMEM;
kfree(pi->name);
pi->name = name;
dout(" name is %s\n", pi->name);
}
*p += len;
} return 0;
bad: return -EINVAL;
}
/* * CRUSH workspaces * * workspace_manager framework borrowed from fs/btrfs/compression.c. * Two simplifications: there is only one type of workspace and there * is always at least one workspace.
*/ staticstruct crush_work *alloc_workspace(conststruct crush_map *c)
{ struct crush_work *work;
size_t work_size;
while (!list_empty(&wsm->idle_ws)) {
work = list_first_entry(&wsm->idle_ws, struct crush_work,
item);
list_del_init(&work->item);
free_workspace(work);
}
atomic_set(&wsm->total_ws, 0);
wsm->free_ws = 0;
}
/* * Finds an available workspace or allocates a new one. If it's not * possible to allocate a new one, waits until there is one.
*/ staticstruct crush_work *get_workspace(struct workspace_manager *wsm, conststruct crush_map *c)
{ struct crush_work *work; int cpus = num_online_cpus();
again:
spin_lock(&wsm->ws_lock); if (!list_empty(&wsm->idle_ws)) {
work = list_first_entry(&wsm->idle_ws, struct crush_work,
item);
list_del_init(&work->item);
wsm->free_ws--;
spin_unlock(&wsm->ws_lock); return work;
} if (atomic_read(&wsm->total_ws) > cpus) {
DEFINE_WAIT(wait);
work = alloc_workspace(c); if (!work) {
atomic_dec(&wsm->total_ws);
wake_up(&wsm->ws_wait);
/* * Do not return the error but go back to waiting. We * have the initial workspace and the CRUSH computation * time is bounded so we will get it eventually.
*/
WARN_ON(atomic_read(&wsm->total_ws) < 1); goto again;
} return work;
}
/* * Puts a workspace back on the list or frees it if we have enough * idle ones sitting around.
*/ staticvoid put_workspace(struct workspace_manager *wsm, struct crush_work *work)
{
spin_lock(&wsm->ws_lock); if (wsm->free_ws <= num_online_cpus()) {
list_add(&work->item, &wsm->idle_ws);
wsm->free_ws++;
spin_unlock(&wsm->ws_lock); goto wake;
}
spin_unlock(&wsm->ws_lock);
free_workspace(work);
atomic_dec(&wsm->total_ws);
wake: if (wq_has_sleeper(&wsm->ws_wait))
wake_up(&wsm->ws_wait);
}
/* * Return 0 or error. On success, *v is set to 0 for old (v6) osdmaps, * to struct_v of the client_data section for new (v7 and above) * osdmaps.
*/ staticint get_osdmap_client_data_v(void **p, void *end, constchar *prefix, u8 *v)
{
u8 struct_v;
if (struct_v >= 5) { for (i = 0; i < map->max_osd; i++)
map->osd_state[i] = ceph_decode_32(p);
} else { for (i = 0; i < map->max_osd; i++)
map->osd_state[i] = ceph_decode_8(p);
}
if (ceph_decode_32(p) != map->max_osd) goto e_inval;
for (i = 0; i < map->max_osd; i++)
map->osd_weight[i] = ceph_decode_32(p);
if (ceph_decode_32(p) != map->max_osd) goto e_inval;
for (i = 0; i < map->max_osd; i++) { struct ceph_entity_addr *addr = &map->osd_addr[i];
if (struct_v >= 8)
err = ceph_decode_entity_addrvec(p, end, msgr2, addr); else
err = ceph_decode_entity_addr(p, end, addr); if (err) goto bad;
dout("%s osd%d addr %s\n", __func__, i, ceph_pr_addr(addr));
}
e_inval:
err = -EINVAL;
bad:
pr_err("corrupt full osdmap (%d) epoch %d off %d (%p of %p-%p)\n",
err, epoch, (int)(*p - start), *p, start, end);
print_hex_dump(KERN_DEBUG, "osdmap: ",
DUMP_PREFIX_OFFSET, 16, 1,
start, end - start, true); return err;
}
/* * Allocate and decode a full map.
*/ struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end, bool msgr2)
{ struct ceph_osdmap *map; int ret;
map = ceph_osdmap_alloc(); if (!map) return ERR_PTR(-ENOMEM);
ret = osdmap_decode(p, end, msgr2, map); if (ret) {
ceph_osdmap_destroy(map); return ERR_PTR(ret);
}
return map;
}
/* * Encoding order is (new_up_client, new_state, new_weight). Need to * apply in the (new_weight, new_state, new_up_client) order, because * an incremental map may look like e.g. * * new_up_client: { osd=6, addr=... } # set osd_state and addr * new_state: { osd=6, xorstate=EXISTS } # clear osd_state
*/ staticint decode_new_up_state_weight(void **p, void *end, u8 struct_v, bool msgr2, struct ceph_osdmap *map)
{ void *new_up_client; void *new_state; void *new_weight_end;
u32 len; int ret; int i;
new_up_client = *p;
ceph_decode_32_safe(p, end, len, e_inval); for (i = 0; i < len; ++i) { struct ceph_entity_addr addr;
ceph_decode_skip_32(p, end, e_inval); if (struct_v >= 7)
ret = ceph_decode_entity_addrvec(p, end, msgr2, &addr); else
ret = ceph_decode_entity_addr(p, end, &addr); if (ret) return ret;
}
/* * If we are marking in, set the EXISTS, and clear the * AUTOOUT and NEW bits.
*/ if (w) {
map->osd_state[osd] |= CEPH_OSD_EXISTS;
map->osd_state[osd] &= ~(CEPH_OSD_AUTOOUT |
CEPH_OSD_NEW);
}
}
new_weight_end = *p;
/* new_state (up/down) */
*p = new_state;
len = ceph_decode_32(p); while (len--) {
s32 osd;
u32 xorstate;
osd = ceph_decode_32(p); if (struct_v >= 5)
xorstate = ceph_decode_32(p); else
xorstate = ceph_decode_8(p); if (xorstate == 0)
xorstate = CEPH_OSD_UP;
BUG_ON(osd >= map->max_osd); if ((map->osd_state[osd] & CEPH_OSD_UP) &&
(xorstate & CEPH_OSD_UP))
osdmap_info(map, "osd%d down\n", osd); if ((map->osd_state[osd] & CEPH_OSD_EXISTS) &&
(xorstate & CEPH_OSD_EXISTS)) {
osdmap_info(map, "osd%d does not exist\n", osd);
ret = set_primary_affinity(map, osd,
CEPH_OSD_DEFAULT_PRIMARY_AFFINITY); if (ret) return ret;
memset(map->osd_addr + osd, 0, sizeof(*map->osd_addr));
map->osd_state[osd] = 0;
} else {
map->osd_state[osd] ^= xorstate;
}
}
/* new_up_client */
*p = new_up_client;
len = ceph_decode_32(p); while (len--) {
s32 osd; struct ceph_entity_addr addr;
osd = ceph_decode_32(p);
BUG_ON(osd >= map->max_osd); if (struct_v >= 7)
ret = ceph_decode_entity_addrvec(p, end, msgr2, &addr); else
ret = ceph_decode_entity_addr(p, end, &addr); if (ret) return ret;
/* * If oid doesn't fit into inline buffer, allocate.
*/ int ceph_oid_aprintf(struct ceph_object_id *oid, gfp_t gfp, constchar *fmt, ...)
{
va_list ap; int ret;
va_start(ap, fmt);
ret = oid_aprintf_vargs(oid, gfp, fmt, ap);
va_end(ap);
if (any_change && !__osds_equal(old_acting, new_acting)) returntrue;
returnfalse;
}
/* * Map an object into a PG. * * Should only be called with target_oid and target_oloc (as opposed to * base_oid and base_oloc), since tiering isn't taken into account.
*/ void __ceph_object_locator_to_pg(struct ceph_pg_pool_info *pi, conststruct ceph_object_id *oid, conststruct ceph_object_locator *oloc, struct ceph_pg *raw_pgid)
{
WARN_ON(pi->id != oloc->pool);
/* * Map a raw PG (full precision ps) into an actual PG.
*/ staticvoid raw_pg_to_pg(struct ceph_pg_pool_info *pi, conststruct ceph_pg *raw_pgid, struct ceph_pg *pgid)
{
pgid->pool = raw_pgid->pool;
pgid->seed = ceph_stable_mod(raw_pgid->seed, pi->pg_num,
pi->pg_num_mask);
}
/* * Map a raw PG (full precision ps) into a placement ps (placement * seed). Include pool id in that value so that different pools don't * use the same seeds.
*/ static u32 raw_pg_to_pps(struct ceph_pg_pool_info *pi, conststruct ceph_pg *raw_pgid)
{ if (pi->flags & CEPH_POOL_FLAG_HASHPSPOOL) { /* hash pool id and seed so that pool PGs do not overlap */ return crush_hash32_2(CRUSH_HASH_RJENKINS1,
ceph_stable_mod(raw_pgid->seed,
pi->pgp_num,
pi->pgp_num_mask),
raw_pgid->pool);
} else { /* * legacy behavior: add ps and pool together. this is * not a great approach because the PGs from each pool * will overlap on top of each other: 0.5 == 1.4 == * 2.3 == ...
*/ return ceph_stable_mod(raw_pgid->seed, pi->pgp_num,
pi->pgp_num_mask) +
(unsigned)raw_pgid->pool;
}
}
/* * Magic value used for a "default" fallback choose_args, used if the * crush_choose_arg_map passed to do_crush() does not exist. If this * also doesn't exist, fall back to canonical weights.
*/ #define CEPH_DEFAULT_CHOOSE_ARGS -1
staticint do_crush(struct ceph_osdmap *map, int ruleno, int x, int *result, int result_max, const __u32 *weight, int weight_max,
s64 choose_args_index)
{ struct crush_choose_arg_map *arg_map; struct crush_work *work; int r;
BUG_ON(result_max > CEPH_PG_MAX_SIZE);
arg_map = lookup_choose_arg_map(&map->crush->choose_args,
choose_args_index); if (!arg_map)
arg_map = lookup_choose_arg_map(&map->crush->choose_args,
CEPH_DEFAULT_CHOOSE_ARGS);
/* shift left */ for (i = 0; i < set->size; i++) { if (!ceph_osd_exists(osdmap, set->osds[i])) {
removed++; continue;
} if (removed)
set->osds[i - removed] = set->osds[i];
}
set->size -= removed;
} else { /* set dne devices to NONE */ for (i = 0; i < set->size; i++) { if (!ceph_osd_exists(osdmap, set->osds[i]))
set->osds[i] = CRUSH_ITEM_NONE;
}
}
}
/* * Calculate raw set (CRUSH output) for given PG and filter out * nonexistent OSDs. ->primary is undefined for a raw set. * * Placement seed (CRUSH input) is returned through @ppps.
*/ staticvoid pg_to_raw_osds(struct ceph_osdmap *osdmap, struct ceph_pg_pool_info *pi, conststruct ceph_pg *raw_pgid, struct ceph_osds *raw,
u32 *ppps)
{
u32 pps = raw_pg_to_pps(pi, raw_pgid); int ruleno; int len;
ceph_osds_init(raw); if (ppps)
*ppps = pps;
ruleno = crush_find_rule(osdmap->crush, pi->crush_ruleset, pi->type,
pi->size); if (ruleno < 0) {
pr_err("no crush rule: pool %lld ruleset %d type %d size %d\n",
pi->id, pi->crush_ruleset, pi->type, pi->size); return;
}
if (pi->size > ARRAY_SIZE(raw->osds)) {
pr_err_ratelimited("pool %lld ruleset %d type %d too wide: size %d > %zu\n",
pi->id, pi->crush_ruleset, pi->type, pi->size,
ARRAY_SIZE(raw->osds)); return;
}
len = do_crush(osdmap, ruleno, pps, raw->osds, pi->size,
osdmap->osd_weight, osdmap->max_osd, pi->id); if (len < 0) {
pr_err("error %d from crush rule %d: pool %lld ruleset %d type %d size %d\n",
len, ruleno, pi->id, pi->crush_ruleset, pi->type,
pi->size); return;
}
pg = lookup_pg_mapping(&osdmap->pg_upmap, pgid); if (pg) { /* make sure targets aren't marked out */ for (i = 0; i < pg->pg_upmap.len; i++) { int osd = pg->pg_upmap.osds[i];
if (osd != CRUSH_ITEM_NONE &&
osd < osdmap->max_osd &&
osdmap->osd_weight[osd] == 0) { /* reject/ignore explicit mapping */ return;
}
} for (i = 0; i < pg->pg_upmap.len; i++)
raw->osds[i] = pg->pg_upmap.osds[i];
raw->size = pg->pg_upmap.len; /* check and apply pg_upmap_items, if any */
}
pg = lookup_pg_mapping(&osdmap->pg_upmap_items, pgid); if (pg) { /* * Note: this approach does not allow a bidirectional swap, * e.g., [[1,2],[2,1]] applied to [0,1,2] -> [0,2,1].
*/ for (i = 0; i < pg->pg_upmap_items.len; i++) { int from = pg->pg_upmap_items.from_to[i][0]; int to = pg->pg_upmap_items.from_to[i][1]; int pos = -1; bool exists = false;
/* make sure replacement doesn't already appear */ for (j = 0; j < raw->size; j++) { int osd = raw->osds[j];
if (osd == to) {
exists = true; break;
} /* ignore mapping if target is marked out */ if (osd == from && pos < 0 &&
!(to != CRUSH_ITEM_NONE &&
to < osdmap->max_osd &&
osdmap->osd_weight[to] == 0)) {
pos = j;
}
} if (!exists && pos >= 0)
raw->osds[pos] = to;
}
}
}
/* * Given raw set, calculate up set and up primary. By definition of an * up set, the result won't contain nonexistent or down OSDs. * * This is done in-place - on return @set is the up set. If it's * empty, ->primary will remain undefined.
*/ staticvoid raw_to_up_osds(struct ceph_osdmap *osdmap, struct ceph_pg_pool_info *pi, struct ceph_osds *set)
{ int i;
/* ->primary is undefined for a raw set */
BUG_ON(set->primary != -1);
if (ceph_can_shift_osds(pi)) { int removed = 0;
/* shift left */ for (i = 0; i < set->size; i++) { if (ceph_osd_is_down(osdmap, set->osds[i])) {
removed++; continue;
} if (removed)
set->osds[i - removed] = set->osds[i];
}
set->size -= removed; if (set->size > 0)
set->primary = set->osds[0];
} else { /* set down/dne devices to NONE */ for (i = set->size - 1; i >= 0; i--) { if (ceph_osd_is_down(osdmap, set->osds[i]))
set->osds[i] = CRUSH_ITEM_NONE; else
set->primary = set->osds[i];
}
}
}
staticvoid apply_primary_affinity(struct ceph_osdmap *osdmap, struct ceph_pg_pool_info *pi,
u32 pps, struct ceph_osds *up)
{ int i; int pos = -1;
/* * Do we have any non-default primary_affinity values for these * osds?
*/ if (!osdmap->osd_primary_affinity) return;
for (i = 0; i < up->size; i++) { int osd = up->osds[i];
if (osd != CRUSH_ITEM_NONE &&
osdmap->osd_primary_affinity[osd] !=
CEPH_OSD_DEFAULT_PRIMARY_AFFINITY) { break;
}
} if (i == up->size) return;
/* * Pick the primary. Feed both the seed (for the pg) and the * osd into the hash/rng so that a proportional fraction of an * osd's pgs get rejected as primary.
*/ for (i = 0; i < up->size; i++) { int osd = up->osds[i];
u32 aff;
if (osd == CRUSH_ITEM_NONE) continue;
aff = osdmap->osd_primary_affinity[osd]; if (aff < CEPH_OSD_MAX_PRIMARY_AFFINITY &&
(crush_hash32_2(CRUSH_HASH_RJENKINS1,
pps, osd) >> 16) >= aff) { /* * We chose not to use this primary. Note it * anyway as a fallback in case we don't pick * anyone else, but keep looking.
*/ if (pos < 0)
pos = i;
} else {
pos = i; break;
}
} if (pos < 0) return;
up->primary = up->osds[pos];
if (ceph_can_shift_osds(pi) && pos > 0) { /* move the new primary to the front */ for (i = pos; i > 0; i--)
up->osds[i] = up->osds[i - 1];
up->osds[0] = up->primary;
}
}
/* * Get pg_temp and primary_temp mappings for given PG. * * Note that a PG may have none, only pg_temp, only primary_temp or * both pg_temp and primary_temp mappings. This means @temp isn't * always a valid OSD set on return: in the "only primary_temp" case, * @temp will have its ->primary >= 0 but ->size == 0.
*/ staticvoid get_temp_osds(struct ceph_osdmap *osdmap, struct ceph_pg_pool_info *pi, conststruct ceph_pg *pgid, struct ceph_osds *temp)
{ struct ceph_pg_mapping *pg; int i;
ceph_osds_init(temp);
/* pg_temp? */
pg = lookup_pg_mapping(&osdmap->pg_temp, pgid); if (pg) { for (i = 0; i < pg->pg_temp.len; i++) { if (ceph_osd_is_down(osdmap, pg->pg_temp.osds[i])) { if (ceph_can_shift_osds(pi)) continue;
/* * Map a PG to its acting set as well as its up set. * * Acting set is used for data mapping purposes, while up set can be * recorded for detecting interval changes and deciding whether to * resend a request.
*/ void ceph_pg_to_up_acting_osds(struct ceph_osdmap *osdmap, struct ceph_pg_pool_info *pi, conststruct ceph_pg *raw_pgid, struct ceph_osds *up, struct ceph_osds *acting)
{ struct ceph_pg pgid;
u32 pps;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.