Lines Matching +full:mi +full:- +full:v
1 // SPDX-License-Identifier: GPL-2.0
4 #include "sb-members.h"
5 #include "super-io.h"
14 return ((BCH_GROUP_DELETED(l) > BCH_GROUP_DELETED(r)) - in group_cmp()
16 ((BCH_GROUP_PARENT(l) > BCH_GROUP_PARENT(r)) - in group_cmp()
18 strncmp(l->label, r->label, sizeof(l->label)); in group_cmp()
31 for (i = 0; i < sb->nr_devices; i++) { in bch2_sb_disk_groups_validate()
38 group_id = BCH_MEMBER_GROUP(&m) - 1; in bch2_sb_disk_groups_validate()
43 return -BCH_ERR_invalid_sb_disk_groups; in bch2_sb_disk_groups_validate()
46 if (BCH_GROUP_DELETED(&groups->entries[group_id])) { in bch2_sb_disk_groups_validate()
48 return -BCH_ERR_invalid_sb_disk_groups; in bch2_sb_disk_groups_validate()
56 g = groups->entries + i; in bch2_sb_disk_groups_validate()
61 len = strnlen(g->label, sizeof(g->label)); in bch2_sb_disk_groups_validate()
64 return -BCH_ERR_invalid_sb_disk_groups; in bch2_sb_disk_groups_validate()
70 return -BCH_ERR_ENOMEM_disk_groups_validate; in bch2_sb_disk_groups_validate()
72 memcpy(sorted, groups->entries, nr_groups * sizeof(*sorted)); in bch2_sb_disk_groups_validate()
80 (int) sizeof(g->label), g->label); in bch2_sb_disk_groups_validate()
81 ret = -BCH_ERR_invalid_sb_disk_groups; in bch2_sb_disk_groups_validate()
91 out->atomic++; in bch2_disk_groups_to_text()
94 struct bch_disk_groups_cpu *g = rcu_dereference(c->disk_groups); in bch2_disk_groups_to_text()
98 for (unsigned i = 0; i < g->nr; i++) { in bch2_disk_groups_to_text()
102 if (g->entries[i].deleted) { in bch2_disk_groups_to_text()
107 prt_printf(out, "[parent %d devs", g->entries[i].parent); in bch2_disk_groups_to_text()
108 for_each_member_device_rcu(c, ca, &g->entries[i].devs) in bch2_disk_groups_to_text()
109 prt_printf(out, " %s", ca->name); in bch2_disk_groups_to_text()
115 out->atomic--; in bch2_disk_groups_to_text()
127 for (g = groups->entries; in bch2_sb_disk_groups_to_text()
128 g < groups->entries + nr_groups; in bch2_sb_disk_groups_to_text()
130 if (g != groups->entries) in bch2_sb_disk_groups_to_text()
137 BCH_GROUP_PARENT(g), g->label); in bch2_sb_disk_groups_to_text()
152 lockdep_assert_held(&c->sb_lock); in bch2_sb_disk_groups_to_cpu()
154 groups = bch2_sb_field_get(c->disk_sb.sb, disk_groups); in bch2_sb_disk_groups_to_cpu()
162 return -BCH_ERR_ENOMEM_disk_groups_to_cpu; in bch2_sb_disk_groups_to_cpu()
164 cpu_g->nr = nr_groups; in bch2_sb_disk_groups_to_cpu()
167 struct bch_disk_group *src = &groups->entries[i]; in bch2_sb_disk_groups_to_cpu()
168 struct bch_disk_group_cpu *dst = &cpu_g->entries[i]; in bch2_sb_disk_groups_to_cpu()
170 dst->deleted = BCH_GROUP_DELETED(src); in bch2_sb_disk_groups_to_cpu()
171 dst->parent = BCH_GROUP_PARENT(src); in bch2_sb_disk_groups_to_cpu()
172 memcpy(dst->label, src->label, sizeof(dst->label)); in bch2_sb_disk_groups_to_cpu()
175 for (i = 0; i < c->disk_sb.sb->nr_devices; i++) { in bch2_sb_disk_groups_to_cpu()
176 struct bch_member m = bch2_sb_member_get(c->disk_sb.sb, i); in bch2_sb_disk_groups_to_cpu()
184 dst = &cpu_g->entries[g - 1]; in bch2_sb_disk_groups_to_cpu()
185 __set_bit(i, dst->devs.d); in bch2_sb_disk_groups_to_cpu()
186 g = dst->parent; in bch2_sb_disk_groups_to_cpu()
190 old_g = rcu_dereference_protected(c->disk_groups, in bch2_sb_disk_groups_to_cpu()
191 lockdep_is_held(&c->sb_lock)); in bch2_sb_disk_groups_to_cpu()
192 rcu_assign_pointer(c->disk_groups, cpu_g); in bch2_sb_disk_groups_to_cpu()
211 struct bch_dev *ca = t.dev < c->sb.nr_devices in bch2_target_to_mask()
212 ? rcu_dereference(c->devs[t.dev]) in bch2_target_to_mask()
214 devs = ca ? &ca->self : NULL; in bch2_target_to_mask()
218 struct bch_disk_groups_cpu *g = rcu_dereference(c->disk_groups); in bch2_target_to_mask()
220 devs = g && t.group < g->nr && !g->entries[t.group].deleted in bch2_target_to_mask()
221 ? &g->entries[t.group].devs in bch2_target_to_mask()
249 g = rcu_dereference(c->disk_groups); in bch2_dev_in_target()
250 m = g && t.group < g->nr && !g->entries[t.group].deleted in bch2_dev_in_target()
251 ? &g->entries[t.group].devs in bch2_dev_in_target()
254 ret = m ? test_bit(dev, m->d) : false; in bch2_dev_in_target()
271 return -EINVAL; in __bch2_disk_group_find()
274 struct bch_disk_group *g = groups->entries + i; in __bch2_disk_group_find()
281 strnlen(g->label, sizeof(g->label)) == namelen && in __bch2_disk_group_find()
282 !memcmp(name, g->label, namelen)) in __bch2_disk_group_find()
286 return -1; in __bch2_disk_group_find()
293 bch2_sb_field_get(sb->sb, disk_groups); in __bch2_disk_group_add()
298 return -EINVAL; in __bch2_disk_group_add()
301 i < nr_groups && !BCH_GROUP_DELETED(&groups->entries[i]); in __bch2_disk_group_add()
313 return -BCH_ERR_ENOSPC_disk_label_add; in __bch2_disk_group_add()
320 g = &groups->entries[i]; in __bch2_disk_group_add()
322 memcpy(g->label, name, namelen); in __bch2_disk_group_add()
323 if (namelen < sizeof(g->label)) in __bch2_disk_group_add()
324 g->label[namelen] = '\0'; in __bch2_disk_group_add()
335 bch2_sb_field_get(sb->sb, disk_groups); in bch2_disk_path_find()
336 int v = -1; in bch2_disk_path_find() local
340 unsigned len = next - name; in bch2_disk_path_find()
345 v = __bch2_disk_group_find(groups, v + 1, name, len); in bch2_disk_path_find()
347 } while (*name && v >= 0); in bch2_disk_path_find()
349 return v; in bch2_disk_path_find()
356 int v = -1; in bch2_disk_path_find_or_create() local
360 unsigned len = next - name; in bch2_disk_path_find_or_create()
365 groups = bch2_sb_field_get(sb->sb, disk_groups); in bch2_disk_path_find_or_create()
367 v = __bch2_disk_group_find(groups, parent, name, len); in bch2_disk_path_find_or_create()
368 if (v < 0) in bch2_disk_path_find_or_create()
369 v = __bch2_disk_group_add(sb, parent, name, len); in bch2_disk_path_find_or_create()
370 if (v < 0) in bch2_disk_path_find_or_create()
371 return v; in bch2_disk_path_find_or_create()
373 parent = v + 1; in bch2_disk_path_find_or_create()
375 } while (*name && v >= 0); in bch2_disk_path_find_or_create()
377 return v; in bch2_disk_path_find_or_create()
380 void bch2_disk_path_to_text(struct printbuf *out, struct bch_fs *c, unsigned v) in bch2_disk_path_to_text() argument
387 out->atomic++; in bch2_disk_path_to_text()
389 groups = rcu_dereference(c->disk_groups); in bch2_disk_path_to_text()
397 if (v >= groups->nr) in bch2_disk_path_to_text()
400 g = groups->entries + v; in bch2_disk_path_to_text()
402 if (g->deleted) in bch2_disk_path_to_text()
405 path[nr++] = v; in bch2_disk_path_to_text()
407 if (!g->parent) in bch2_disk_path_to_text()
410 v = g->parent - 1; in bch2_disk_path_to_text()
414 v = path[--nr]; in bch2_disk_path_to_text()
415 g = groups->entries + v; in bch2_disk_path_to_text()
417 prt_printf(out, "%.*s", (int) sizeof(g->label), g->label); in bch2_disk_path_to_text()
423 out->atomic--; in bch2_disk_path_to_text()
426 prt_printf(out, "invalid label %u", v); in bch2_disk_path_to_text()
430 void bch2_disk_path_to_text_sb(struct printbuf *out, struct bch_sb *sb, unsigned v) in bch2_disk_path_to_text_sb() argument
442 if (v >= disk_groups_nr(groups)) in bch2_disk_path_to_text_sb()
445 g = groups->entries + v; in bch2_disk_path_to_text_sb()
450 path[nr++] = v; in bch2_disk_path_to_text_sb()
455 v = BCH_GROUP_PARENT(g) - 1; in bch2_disk_path_to_text_sb()
459 v = path[--nr]; in bch2_disk_path_to_text_sb()
460 g = groups->entries + v; in bch2_disk_path_to_text_sb()
462 prt_printf(out, "%.*s", (int) sizeof(g->label), g->label); in bch2_disk_path_to_text_sb()
468 prt_printf(out, "invalid label %u", v); in bch2_disk_path_to_text_sb()
473 lockdep_assert_held(&c->sb_lock); in __bch2_dev_group_set()
477 struct bch_member *mi = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx); in __bch2_dev_group_set() local
478 SET_BCH_MEMBER_GROUP(mi, 0); in __bch2_dev_group_set()
480 int v = bch2_disk_path_find_or_create(&c->disk_sb, name); in __bch2_dev_group_set() local
481 if (v < 0) in __bch2_dev_group_set()
482 return v; in __bch2_dev_group_set()
484 struct bch_member *mi = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx); in __bch2_dev_group_set() local
485 SET_BCH_MEMBER_GROUP(mi, v + 1); in __bch2_dev_group_set()
495 mutex_lock(&c->sb_lock); in bch2_dev_group_set()
498 mutex_unlock(&c->sb_lock); in bch2_dev_group_set()
510 return -EINVAL; in bch2_opt_target_parse()
513 return -BCH_ERR_option_needs_open_fs; in bch2_opt_target_parse()
523 *res = dev_to_target(ca->dev_idx); in bch2_opt_target_parse()
528 mutex_lock(&c->sb_lock); in bch2_opt_target_parse()
529 g = bch2_disk_path_find(&c->disk_sb, val); in bch2_opt_target_parse()
530 mutex_unlock(&c->sb_lock); in bch2_opt_target_parse()
537 return -EINVAL; in bch2_opt_target_parse()
540 void bch2_target_to_text(struct printbuf *out, struct bch_fs *c, unsigned v) in bch2_target_to_text() argument
542 struct target t = target_decode(v); in bch2_target_to_text()
551 out->atomic++; in bch2_target_to_text()
553 ca = t.dev < c->sb.nr_devices in bch2_target_to_text()
554 ? rcu_dereference(c->devs[t.dev]) in bch2_target_to_text()
557 if (ca && percpu_ref_tryget(&ca->io_ref[READ])) { in bch2_target_to_text()
558 prt_printf(out, "/dev/%s", ca->name); in bch2_target_to_text()
559 percpu_ref_put(&ca->io_ref[READ]); in bch2_target_to_text()
567 out->atomic--; in bch2_target_to_text()
578 static void bch2_target_to_text_sb(struct printbuf *out, struct bch_sb *sb, unsigned v) in bch2_target_to_text_sb() argument
580 struct target t = target_decode(v); in bch2_target_to_text_sb()
609 u64 v) in bch2_opt_target_to_text() argument
612 bch2_target_to_text(out, c, v); in bch2_opt_target_to_text()
614 bch2_target_to_text_sb(out, sb, v); in bch2_opt_target_to_text()