static int _thin_pool_add_message(struct lv_segment *seg, const char *key, const struct dm_config_node *sn) { const char *lv_name = NULL; struct logical_volume *lv = NULL; uint32_t delete_id = 0; dm_thin_message_t type; /* Message must have only one from: create, delete */ if (dm_config_get_str(sn, "create", &lv_name)) { if (!(lv = find_lv(seg->lv->vg, lv_name))) return SEG_LOG_ERROR("Unknown LV %s for create message in", lv_name); /* FIXME: switch to _SNAP later, if the created LV has an origin */ type = DM_THIN_MESSAGE_CREATE_THIN; } else if (dm_config_get_uint32(sn, "delete", &delete_id)) type = DM_THIN_MESSAGE_DELETE; else return SEG_LOG_ERROR("Unknown message in"); if (!attach_pool_message(seg, type, lv, delete_id, 1)) return_0; return 1; }
/* Wrapper for dm_config_get_uint32() with default value */ static uint32_t _get_config_uint32(const struct dm_config_node *cn, const char *path, uint32_t def) { uint32_t t; return dm_config_get_uint32(cn, path, &t) ? t : def; }
static int _raid_text_import_area_count(const struct dm_config_node *sn, uint32_t *area_count) { if (!dm_config_get_uint32(sn, "device_count", area_count)) { log_error("Couldn't read 'device_count' for " "segment '%s'.", dm_config_parent_name(sn)); return 0; } return 1; }
static void test_clone(void) { struct dm_config_tree *tree = dm_config_from_string(conf); struct dm_config_node *n = dm_config_clone_node(tree, tree->root, 1); const struct dm_config_value *value; /* Check that the nodes are actually distinct. */ CU_ASSERT(n != tree->root); CU_ASSERT(n->sib != tree->root->sib); CU_ASSERT(dm_config_find_node(n, "physical_volumes") != NULL); CU_ASSERT(dm_config_find_node(tree->root, "physical_volumes") != NULL); CU_ASSERT(dm_config_find_node(n, "physical_volumes") != dm_config_find_node(tree->root, "physical_volumes")); CU_ASSERT(dm_config_has_node(n, "id")); CU_ASSERT(dm_config_has_node(n, "physical_volumes")); CU_ASSERT(dm_config_has_node(n, "physical_volumes/pv0")); CU_ASSERT(dm_config_has_node(n, "physical_volumes/pv0/id")); CU_ASSERT(!strcmp(dm_config_find_str(n, "id", "foo"), "yada-yada")); CU_ASSERT(!strcmp(dm_config_find_str(n, "idt", "foo"), "foo")); CU_ASSERT(!strcmp(dm_config_find_str(n, "physical_volumes/pv0/bb", "foo"), "foo")); CU_ASSERT(!strcmp(dm_config_find_str(n, "physical_volumes/pv0/id", "foo"), "abcd-efgh")); CU_ASSERT(!dm_config_get_uint32(n, "id", NULL)); CU_ASSERT(dm_config_get_uint32(n, "extent_size", NULL)); /* FIXME: Currently everything parses as a list, even if it's not */ // CU_ASSERT(!dm_config_get_list(tree->root, "id", NULL)); // CU_ASSERT(!dm_config_get_list(tree->root, "extent_size", NULL)); CU_ASSERT(dm_config_get_list(n, "flags", &value)); CU_ASSERT(value->next == NULL); /* an empty list */ CU_ASSERT(dm_config_get_list(n, "status", &value)); CU_ASSERT(value->next != NULL); /* a non-empty list */ dm_config_destroy(tree); }
static int _import_bool(const struct dm_config_node *n, const char *name, bool *b) { uint32_t t; if (dm_config_has_node(n, name)) { if (!dm_config_get_uint32(n, name, &t)) return _bad_field(name); if (t) { *b = true; return 1; } } *b = false; return 1; }
static int _striped_text_import(struct lv_segment *seg, const struct dm_config_node *sn, struct dm_hash_table *pv_hash) { const struct dm_config_value *cv; if ((seg->area_count != 1) && !dm_config_get_uint32(sn, "stripe_size", &seg->stripe_size)) { log_error("Couldn't read stripe_size for segment %s " "of logical volume %s.", dm_config_parent_name(sn), seg->lv->name); return 0; } if (!dm_config_get_list(sn, "stripes", &cv)) { log_error("Couldn't find stripes array for segment %s " "of logical volume %s.", dm_config_parent_name(sn), seg->lv->name); return 0; } seg->area_len /= seg->area_count; return text_import_areas(seg, sn, cv, pv_hash, 0); }