Lines Matching +full:- +full:g +full:-
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()
26 struct bch_disk_group *g, *sorted = NULL; in bch2_sb_disk_groups_validate() local
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()
58 if (BCH_GROUP_DELETED(g)) 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()
75 for (g = sorted; g + 1 < sorted + nr_groups; g++) in bch2_sb_disk_groups_validate()
76 if (!BCH_GROUP_DELETED(g) && in bch2_sb_disk_groups_validate()
77 !group_cmp(&g[0], &g[1])) { in bch2_sb_disk_groups_validate()
79 BCH_GROUP_PARENT(g), 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() local
95 if (!g) 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()
124 struct bch_disk_group *g; in bch2_sb_disk_groups_to_text() local
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()
129 g++) { in bch2_sb_disk_groups_to_text()
130 if (g != groups->entries) in bch2_sb_disk_groups_to_text()
133 if (BCH_GROUP_DELETED(g)) in bch2_sb_disk_groups_to_text()
137 BCH_GROUP_PARENT(g), g->label); in bch2_sb_disk_groups_to_text()
150 unsigned i, g, nr_groups; in bch2_sb_disk_groups_to_cpu() local
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()
182 g = BCH_MEMBER_GROUP(&m); in bch2_sb_disk_groups_to_cpu()
183 while (g) { 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() local
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()
244 struct bch_disk_groups_cpu *g; in bch2_dev_in_target() local
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() local
276 if (BCH_GROUP_DELETED(g)) in __bch2_disk_group_find()
279 if (!BCH_GROUP_DELETED(g) && in __bch2_disk_group_find()
280 BCH_GROUP_PARENT(g) == parent && 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()
295 struct bch_disk_group *g; in __bch2_disk_group_add() local
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()
325 SET_BCH_GROUP_DELETED(g, 0); in __bch2_disk_group_add()
326 SET_BCH_GROUP_PARENT(g, parent); in __bch2_disk_group_add()
327 SET_BCH_GROUP_DATA_ALLOWED(g, ~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()
340 unsigned len = next - name; in bch2_disk_path_find()
356 int v = -1; in bch2_disk_path_find_or_create()
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()
383 struct bch_disk_group_cpu *g; in bch2_disk_path_to_text() local
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()
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()
434 struct bch_disk_group *g; in bch2_disk_path_to_text_sb() local
445 g = groups->entries + v; in bch2_disk_path_to_text_sb()
447 if (BCH_GROUP_DELETED(g)) in bch2_disk_path_to_text_sb()
452 if (!BCH_GROUP_PARENT(g)) 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()
474 int ret, v = -1; in __bch2_dev_group_set()
479 v = bch2_disk_path_find_or_create(&c->disk_sb, name); in __bch2_dev_group_set()
487 mi = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx); in __bch2_dev_group_set()
496 mutex_lock(&c->sb_lock); in bch2_dev_group_set()
499 mutex_unlock(&c->sb_lock); in bch2_dev_group_set()
508 int g; in bch2_opt_target_parse() local
511 return -EINVAL; in bch2_opt_target_parse()
514 return -BCH_ERR_option_needs_open_fs; in bch2_opt_target_parse()
524 *res = dev_to_target(ca->dev_idx); in bch2_opt_target_parse()
529 mutex_lock(&c->sb_lock); in bch2_opt_target_parse()
530 g = bch2_disk_path_find(&c->disk_sb, val); in bch2_opt_target_parse()
531 mutex_unlock(&c->sb_lock); in bch2_opt_target_parse()
533 if (g >= 0) { in bch2_opt_target_parse()
534 *res = group_to_target(g); in bch2_opt_target_parse()
538 return -EINVAL; in bch2_opt_target_parse()
552 out->atomic++; in bch2_target_to_text()
554 ca = t.dev < c->sb.nr_devices in bch2_target_to_text()
555 ? rcu_dereference(c->devs[t.dev]) in bch2_target_to_text()
558 if (ca && percpu_ref_tryget(&ca->io_ref)) { in bch2_target_to_text()
559 prt_printf(out, "/dev/%s", ca->name); in bch2_target_to_text()
560 percpu_ref_put(&ca->io_ref); in bch2_target_to_text()
568 out->atomic--; in bch2_target_to_text()