174
175
const char *lv_name,
175
176
struct dm_list *allocatable_pvs,
176
177
alloc_policy_t alloc,
177
struct dm_list **lvs_changed)
178
struct dm_list **lvs_changed,
179
181
struct logical_volume *lv_mirr, *lv;
180
182
struct lv_list *lvl;
181
183
uint32_t log_count = 0;
182
184
int lv_found = 0;
183
185
int lv_skipped = 0;
186
int lv_active_count = 0;
187
int lv_exclusive_count = 0;
185
189
/* FIXME Cope with non-contiguous => splitting existing segments */
186
190
if (!(lv_mirr = lv_create_empty("pvmove%d", NULL,
212
216
if (lv_is_origin(lv) || lv_is_cow(lv)) {
214
log_print("Skipping snapshot-related LV %s", lv->name);
218
log_print_unless_silent("Skipping snapshot-related LV %s", lv->name);
217
221
if (lv->status & MIRRORED) {
219
log_print("Skipping mirror LV %s", lv->name);
223
log_print_unless_silent("Skipping mirror LV %s", lv->name);
222
226
if (lv->status & MIRROR_LOG) {
224
log_print("Skipping mirror log LV %s", lv->name);
228
log_print_unless_silent("Skipping mirror log LV %s", lv->name);
227
231
if (lv->status & MIRROR_IMAGE) {
229
log_print("Skipping mirror image LV %s", lv->name);
233
log_print_unless_silent("Skipping mirror image LV %s", lv->name);
232
236
if (lv->status & LOCKED) {
234
log_print("Skipping locked LV %s", lv->name);
238
log_print_unless_silent("Skipping locked LV %s", lv->name);
242
if (vg_is_clustered(vg) &&
243
lv_is_active_exclusive_remotely(lv)) {
245
log_print_unless_silent("Skipping LV %s which is activated "
246
"exclusively on remote node.", lv->name);
250
if (vg_is_clustered(vg)) {
251
if (lv_is_active_exclusive_locally(lv))
252
lv_exclusive_count++;
253
else if (lv_is_active(lv))
237
257
if (!_insert_pvmove_mirrors(cmd, lv_mirr, source_pvl, lv,
277
if (vg_is_clustered(vg) && lv_active_count && *exclusive) {
278
log_error("Cannot move in clustered VG %s, "
279
"clustered mirror (cmirror) not detected "
280
"and LVs are activated non-exclusively.",
285
if (vg_is_clustered(vg) && lv_exclusive_count) {
286
if (lv_active_count) {
287
log_error("Cannot move in clustered VG %s "
288
"if some LVs are activated "
289
"exclusively while others don't.",
257
296
if (!lv_add_mirrors(cmd, lv_mirr, 1, 1, 0, 0, log_count,
258
297
allocatable_pvs, alloc, MIRROR_BY_SEG)) {
259
298
log_error("Failed to convert pvmove LV to mirrored");
358
397
struct logical_volume *lv_mirr,
359
398
struct dm_list *lvs_changed, unsigned flags)
361
unsigned exclusive = _pvmove_is_exclusive(cmd, vg);
400
unsigned exclusive = (flags & PVMOVE_EXCLUSIVE) ? 1 : 0;
362
401
unsigned first_time = (flags & PVMOVE_FIRST_TIME) ? 1 : 0;
371
410
if (!_suspend_lvs(cmd, first_time, lv_mirr, lvs_changed, vg)) {
372
log_error("ABORTING: Volume group metadata update failed. (first_time: %d)", first_time);
411
log_error("ABORTING: Temporary pvmove mirror %s failed.", first_time ? "activation" : "reload");
373
412
/* FIXME Add a recovery path for first time too. */
374
413
if (!first_time && !revert_lv(cmd, lv_mirr))
390
429
/* Only the first mirror segment gets activated as a mirror */
391
430
/* FIXME: Add option to use a log */
392
431
if (first_time) {
432
if (!exclusive && _pvmove_is_exclusive(cmd, vg))
393
435
if (!_activate_lv(cmd, lv_mirr, exclusive)) {
394
436
if (test_mode()) {
470
512
exclusive = _pvmove_is_exclusive(cmd, vg);
472
514
if ((lv_mirr = find_pvmove_lv(vg, pv_dev(pv), PVMOVE))) {
473
log_print("Detected pvmove in progress for %s", pv_name);
515
log_print_unless_silent("Detected pvmove in progress for %s", pv_name);
474
516
if (argc || lv_name)
475
517
log_error("Ignoring remaining command line arguments");
530
flags &= ~PVMOVE_FIRST_TIME;
490
532
/* Determine PE ranges to be moved */
491
533
if (!(source_pvl = create_pv_list(cmd->mem, vg, 1,
518
560
/* init_pvmove(1); */
519
561
/* vg->status |= PVMOVE; */
563
if (flags & PVMOVE_FIRST_TIME) {
565
flags |= PVMOVE_EXCLUSIVE;
522
566
if (!_update_metadata
523
(cmd, vg, lv_mirr, lvs_changed, PVMOVE_FIRST_TIME))
567
(cmd, vg, lv_mirr, lvs_changed, flags))