37
37
#define SEG_LOG_ERROR(t, p...) \
38
38
log_error(t " segment %s of logical volume %s.", ## p, \
39
config_parent_name(sn), seg->lv->name), 0;
39
dm_config_parent_name(sn), seg->lv->name), 0;
58
58
log_print(" Replicator volume\t%s", seg->rlog_lv->name);
61
/* Wrapper for get_config_uint32() with default value */
62
static uint32_t _get_config_uint32(const struct config_node *cn,
61
/* Wrapper for dm_config_get_uint32() with default value */
62
static uint32_t _get_config_uint32(const struct dm_config_node *cn,
68
return get_config_uint32(cn, path, &t) ? t : def;
68
return dm_config_get_uint32(cn, path, &t) ? t : def;
71
/* Wrapper for get_config_uint64() with default value */
72
static uint64_t _get_config_uint64(const struct config_node *cn,
71
/* Wrapper for dm_config_get_uint64() with default value */
72
static uint64_t _get_config_uint64(const struct dm_config_node *cn,
78
return get_config_uint64(cn, path, &t) ? t : def;
78
return dm_config_get_uint64(cn, path, &t) ? t : def;
88
88
/* Parse state string */
89
static replicator_state_t _get_state(const struct config_node *sn,
89
static replicator_state_t _get_state(const struct dm_config_node *sn,
90
90
const char *path, replicator_state_t def)
95
if (get_config_str(sn, path, &str)) {
95
if (dm_config_get_str(sn, path, &str)) {
96
96
for (i = 0; i < sizeof(_state_txt)/sizeof(_state_txt[0]); ++i)
97
97
if (strcasecmp(str, _state_txt[i]) == 0)
98
98
return (replicator_state_t) i;
117
117
/* Parse action string */
118
static dm_replicator_mode_t _get_op_mode(const struct config_node *sn,
118
static dm_replicator_mode_t _get_op_mode(const struct dm_config_node *sn,
119
119
const char *path, dm_replicator_mode_t def)
124
if (get_config_str(sn, path, &str)) {
124
if (dm_config_get_str(sn, path, &str)) {
125
125
for (i = 0; i < sizeof(_op_mode_txt)/sizeof(_op_mode_txt[0]); ++i)
126
126
if (strcasecmp(str, _op_mode_txt[i]) == 0) {
127
127
log_very_verbose("Setting %s to %s",
162
162
/* Parse replicator site element */
163
163
static int _add_site(struct lv_segment *seg,
165
const struct config_node *sn)
165
const struct dm_config_node *sn)
167
167
struct dm_pool *mem = seg->lv->vg->vgmem;
168
const struct config_node *cn;
168
const struct dm_config_node *cn;
169
169
struct replicator_site *rsite;
171
171
if (!(rsite = _get_site(seg->lv, key)))
174
if (!find_config_node(sn, "site_index"))
174
if (!dm_config_find_node(sn, "site_index"))
175
175
return SEG_LOG_ERROR("Mandatory site_index is missing for");
177
177
rsite->state = _get_state(sn, "state", REPLICATOR_STATE_PASSIVE);
207
if ((cn = find_config_node(sn, "volume_group"))) {
208
if (!cn->v || cn->v->type != CFG_STRING)
207
if ((cn = dm_config_find_node(sn, "volume_group"))) {
208
if (!cn->v || cn->v->type != DM_CFG_STRING)
209
209
return SEG_LOG_ERROR("volume_group must be a string in");
211
211
if (!(rsite->vg_name = dm_pool_strdup(mem, cn->v->v.str)))
221
221
/* Import replicator segment */
222
222
static int _replicator_text_import(struct lv_segment *seg,
223
const struct config_node *sn,
223
const struct dm_config_node *sn,
224
224
struct dm_hash_table *pv_hash __attribute__((unused)))
226
const struct config_node *cn;
226
const struct dm_config_node *cn;
227
227
struct logical_volume *rlog_lv;
229
229
if (!replicator_add_replicator_dev(seg->lv, NULL))
232
if (!(cn = find_config_node(sn, "replicator_log")) ||
233
!cn->v || cn->v->type != CFG_STRING)
232
if (!(cn = dm_config_find_node(sn, "replicator_log")) ||
233
!cn->v || cn->v->type != DM_CFG_STRING)
234
234
return SEG_LOG_ERROR("Replicator log type must be a string in");
236
236
if (!(rlog_lv = find_lv(seg->lv->vg, cn->v->v.str)))
237
237
return SEG_LOG_ERROR("Unknown replicator log %s in",
240
if (!(cn = find_config_node(sn, "replicator_log_type")) ||
241
!cn->v || cn->v->type != CFG_STRING)
240
if (!(cn = dm_config_find_node(sn, "replicator_log_type")) ||
241
!cn->v || cn->v->type != DM_CFG_STRING)
242
242
return SEG_LOG_ERROR("Replicator log's type must be a string in");
243
243
if (strcasecmp(cn->v->v.str, "ringbuffer"))
244
244
return SEG_LOG_ERROR("Only ringbuffer replicator log type is supported in");
444
444
static int _add_device(struct lv_segment *seg,
445
445
const char *site_name,
446
const struct config_node *sn,
446
const struct dm_config_node *sn,
449
449
struct dm_pool *mem = seg->lv->vg->vgmem;
453
453
struct replicator_device *rdev;
454
454
const char *dev_str = NULL;
455
455
const char *slog_str = NULL;
456
const struct config_node *cn;
456
const struct dm_config_node *cn;
458
458
dm_list_iterate_items(rdev, &rsite->rdevices)
459
459
if (rdev->replicator_dev == seg)
460
460
return SEG_LOG_ERROR("Duplicate site found in");
462
if ((cn = find_config_node(sn, "sync_log"))) {
462
if ((cn = dm_config_find_node(sn, "sync_log"))) {
463
463
if (!cn->v || !cn->v->v.str)
464
464
return SEG_LOG_ERROR("Sync log must be a string in");
465
465
slog_str = cn->v->v.str;
468
if (!(cn = find_config_node(sn, "logical_volume")) ||
468
if (!(cn = dm_config_find_node(sn, "logical_volume")) ||
469
469
!cn->v || !cn->v->v.str)
470
470
return SEG_LOG_ERROR("Logical volume must be a string in");
521
521
/* Import replicator segment */
522
522
static int _replicator_dev_text_import(struct lv_segment *seg,
523
const struct config_node *sn,
523
const struct dm_config_node *sn,
524
524
struct dm_hash_table *pv_hash __attribute__((unused)))
526
const struct config_node *cn;
526
const struct dm_config_node *cn;
527
527
struct logical_volume *replicator;
530
if (!(cn = find_config_node(sn, "replicator")))
530
if (!(cn = dm_config_find_node(sn, "replicator")))
531
531
return SEG_LOG_ERROR("Replicator is missing for");
533
533
if (!cn->v || !cn->v->v.str)
542
542
log_very_verbose("replicator=%s", replicator->name);
545
if (!find_config_node(sn, "device_index") ||
546
!get_config_uint64(sn, "device_index", &devidx))
545
if (!dm_config_find_node(sn, "device_index") ||
546
!dm_config_get_uint64(sn, "device_index", &devidx))
547
547
return SEG_LOG_ERROR("Could not read 'device_index' for");
549
549
/* Read devices from sites */
625
625
/* Create passive linear mapping */
626
626
log_very_verbose("Inactive replicator %s using %s.",
627
627
seg->lv->name, seg->lv->rdevice->lv->name);
628
if (!dm_tree_node_add_linear_target(node, seg->lv->size))
628
if (!add_linear_area_to_dtree(node, seg->lv->size, seg->lv->vg->extent_size,
629
cmd->use_linear_target,
630
seg->lv->vg->name, seg->lv->name))
630
632
if (!(rdev_dlid = build_dm_uuid(mem, seg->lv->rdevice->lv->lvid.s, NULL)))
756
758
#ifdef REPLICATOR_INTERNAL
757
int init_replicator_segtype(struct segtype_library *seglib)
759
int init_replicator_segtype(struct cmd_context *cmd, struct segtype_library *seglib)
758
760
#else /* Shared */
759
int init_multiple_segtype(struct segtype_library *seglib);
760
int init_multiple_segtype(struct segtype_library *seglib)
761
int init_multiple_segtype(struct cmd_context *cmd, struct segtype_library *seglib);
762
int init_multiple_segtype(struct cmd_context *cmd, struct segtype_library *seglib)
763
765
struct segment_type *segtype;
771
773
segtype->flags = SEG_REPLICATOR;
773
775
if (!lvm_register_segtype(seglib, segtype))
776
/* segtype is already destroyed */
776
779
log_very_verbose("Initialised segtype: " REPLICATOR_MODULE);
784
787
segtype->flags = SEG_REPLICATOR_DEV;
786
789
if (!lvm_register_segtype(seglib, segtype))
790
/* segtype is already destroyed */
789
793
log_very_verbose("Initialised segtype: " REPLICATOR_DEV_MODULE);