4 * Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
6 * This file is part of LVM2.
8 * This copyrighted material is made available to anyone wishing to use,
9 * modify, copy, or redistribute it subject to the terms and conditions
10 * of the GNU Lesser General Public License v.2.1.
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include "polldaemon.h"
21 struct lvconvert_params
{
27 const char *lv_name_full
;
38 struct segment_type
*segtype
;
47 static int _lvconvert_name_params(struct lvconvert_params
*lp
,
48 struct cmd_context
*cmd
,
49 int *pargc
, char ***pargv
)
52 const char *vg_name
= NULL
;
56 log_error("Please specify a logical volume to act as "
57 "the snapshot origin.");
61 lp
->origin
= *pargv
[0];
62 (*pargv
)++, (*pargc
)--;
63 if (!(lp
->vg_name
= extract_vgname(cmd
, lp
->origin
))) {
64 log_error("The origin name should include the "
69 /* Strip the volume group from the origin */
70 if ((ptr
= strrchr(lp
->origin
, (int) '/')))
75 log_error("Please provide logical volume path");
79 lp
->lv_name
= lp
->lv_name_full
= (*pargv
)[0];
80 (*pargv
)++, (*pargc
)--;
82 if (strchr(lp
->lv_name_full
, '/') &&
83 (vg_name
= extract_vgname(cmd
, lp
->lv_name_full
)) &&
84 lp
->vg_name
&& strcmp(vg_name
, lp
->vg_name
)) {
85 log_error("Please use a single volume group name "
86 "(\"%s\" or \"%s\")", vg_name
, lp
->vg_name
);
91 lp
->vg_name
= vg_name
;
93 if (!validate_name(lp
->vg_name
)) {
94 log_error("Please provide a valid volume group name");
98 if ((ptr
= strrchr(lp
->lv_name_full
, '/')))
99 lp
->lv_name
= ptr
+ 1;
101 if (!apply_lvname_restrictions(lp
->lv_name
))
107 static int _read_params(struct lvconvert_params
*lp
, struct cmd_context
*cmd
,
108 int argc
, char **argv
)
111 int pagesize
= lvm_getpagesize();
113 memset(lp
, 0, sizeof(*lp
));
115 if (arg_count(cmd
, snapshot_ARG
) &&
116 (arg_count(cmd
, mirrorlog_ARG
) || arg_count(cmd
, mirrors_ARG
) ||
117 arg_count(cmd
, repair_ARG
))) {
118 log_error("--snapshot argument cannot be mixed "
119 "with --mirrors, --repair or --log");
123 if (!arg_count(cmd
, background_ARG
))
124 lp
->wait_completion
= 1;
126 if (arg_count(cmd
, snapshot_ARG
))
129 if (arg_count(cmd
, mirrors_ARG
)) {
130 lp
->mirrors
= arg_uint_value(cmd
, mirrors_ARG
, 0);
131 lp
->mirrors_sign
= arg_sign_value(cmd
, mirrors_ARG
, 0);
134 lp
->alloc
= arg_uint_value(cmd
, alloc_ARG
, ALLOC_INHERIT
);
137 if (arg_count(cmd
, regionsize_ARG
)) {
138 log_error("--regionsize is only available with mirrors");
142 if (arg_sign_value(cmd
, chunksize_ARG
, 0) == SIGN_MINUS
) {
143 log_error("Negative chunk size is invalid");
146 lp
->chunk_size
= arg_uint_value(cmd
, chunksize_ARG
, 8);
147 if (lp
->chunk_size
< 8 || lp
->chunk_size
> 1024 ||
148 (lp
->chunk_size
& (lp
->chunk_size
- 1))) {
149 log_error("Chunk size must be a power of 2 in the "
153 log_verbose("Setting chunksize to %d sectors.", lp
->chunk_size
);
155 if (!(lp
->segtype
= get_segtype_from_string(cmd
, "snapshot")))
158 lp
->zero
= strcmp(arg_str_value(cmd
, zero_ARG
,
159 (lp
->segtype
->flags
&
160 SEG_CANNOT_BE_ZEROED
) ?
163 } else { /* Mirrors */
164 if (arg_count(cmd
, chunksize_ARG
)) {
165 log_error("--chunksize is only available with "
170 if (arg_count(cmd
, zero_ARG
)) {
171 log_error("--zero is only available with snapshots");
176 * --regionsize is only valid if converting an LV into a mirror.
177 * Checked when we know the state of the LV being converted.
180 if (arg_count(cmd
, regionsize_ARG
)) {
181 if (arg_sign_value(cmd
, regionsize_ARG
, 0) ==
183 log_error("Negative regionsize is invalid");
186 lp
->region_size
= arg_uint_value(cmd
, regionsize_ARG
, 0);
188 region_size
= 2 * find_config_tree_int(cmd
,
189 "activation/mirror_region_size",
190 DEFAULT_MIRROR_REGION_SIZE
);
191 if (region_size
< 0) {
192 log_error("Negative regionsize in "
193 "configuration file is invalid");
196 lp
->region_size
= region_size
;
199 if (lp
->region_size
% (pagesize
>> SECTOR_SHIFT
)) {
200 log_error("Region size (%" PRIu32
") must be "
201 "a multiple of machine memory "
203 lp
->region_size
, pagesize
>> SECTOR_SHIFT
);
207 if (lp
->region_size
& (lp
->region_size
- 1)) {
208 log_error("Region size (%" PRIu32
209 ") must be a power of 2", lp
->region_size
);
213 if (!lp
->region_size
) {
214 log_error("Non-zero region size must be supplied.");
218 if (!(lp
->segtype
= get_segtype_from_string(cmd
, "mirror")))
222 if (activation() && lp
->segtype
->ops
->target_present
&&
223 !lp
->segtype
->ops
->target_present(cmd
, NULL
, NULL
)) {
224 log_error("%s: Required device-mapper target(s) not "
225 "detected in your kernel", lp
->segtype
->name
);
229 if (!_lvconvert_name_params(lp
, cmd
, &argc
, &argv
))
238 static struct volume_group
*_get_lvconvert_vg(struct cmd_context
*cmd
,
239 const char *lv_name
, const char *uuid
)
243 return vg_read_for_update(cmd
, extract_vgname(cmd
, lv_name
),
247 static struct logical_volume
*_get_lvconvert_lv(struct cmd_context
*cmd
__attribute((unused
)),
248 struct volume_group
*vg
,
251 uint32_t lv_type
__attribute((unused
)))
253 struct logical_volume
*lv
= find_lv(vg
, name
);
255 if (!lv
|| (uuid
&& strcmp(uuid
, (char *)&lv
->lvid
)))
261 static int _update_lvconvert_mirror(struct cmd_context
*cmd
__attribute((unused
)),
262 struct volume_group
*vg
__attribute((unused
)),
263 struct logical_volume
*lv
__attribute((unused
)),
264 struct dm_list
*lvs_changed
__attribute((unused
)),
265 unsigned flags
__attribute((unused
)))
267 /* lvconvert mirror doesn't require periodical metadata update */
271 static int _finish_lvconvert_mirror(struct cmd_context
*cmd
,
272 struct volume_group
*vg
,
273 struct logical_volume
*lv
,
274 struct dm_list
*lvs_changed
__attribute((unused
)))
278 if (!collapse_mirrored_lv(lv
)) {
279 log_error("Failed to remove temporary sync layer.");
283 lv
->status
&= ~CONVERTING
;
285 log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv
->name
);
290 if (!suspend_lv(cmd
, lv
)) {
291 log_error("Failed to lock %s", lv
->name
);
296 if (!vg_commit(vg
)) {
301 log_very_verbose("Updating \"%s\" in kernel", lv
->name
);
303 if (!resume_lv(cmd
, lv
)) {
304 log_error("Problem reactivating %s", lv
->name
);
309 log_print("Logical volume %s converted.", lv
->name
);
315 static struct poll_functions _lvconvert_mirror_fns
= {
316 .get_copy_vg
= _get_lvconvert_vg
,
317 .get_copy_lv
= _get_lvconvert_lv
,
318 .poll_progress
= poll_mirror_progress
,
319 .update_metadata
= _update_lvconvert_mirror
,
320 .finish_copy
= _finish_lvconvert_mirror
,
323 int lvconvert_poll(struct cmd_context
*cmd
, struct logical_volume
*lv
,
326 int len
= strlen(lv
->vg
->name
) + strlen(lv
->name
) + 2;
327 char *uuid
= alloca(sizeof(lv
->lvid
));
328 char *lv_full_name
= alloca(len
);
331 if (!uuid
|| !lv_full_name
)
334 if (!dm_snprintf(lv_full_name
, len
, "%s/%s", lv
->vg
->name
, lv
->name
))
337 memcpy(uuid
, &lv
->lvid
, sizeof(lv
->lvid
));
339 return poll_daemon(cmd
, lv_full_name
, uuid
, background
, 0,
340 &_lvconvert_mirror_fns
, "Converted");
343 static int _insert_lvconvert_layer(struct cmd_context
*cmd
,
344 struct logical_volume
*lv
)
346 char *format
, *layer_name
;
351 * We would like to give the same number for this layer
352 * and the newly added mimage.
353 * However, LV name of newly added mimage is determined *after*
354 * the LV name of this layer is determined.
356 * So, use generate_lv_name() to generate mimage name first
357 * and take the number from it.
360 len
= strlen(lv
->name
) + 32;
361 if (!(format
= alloca(len
)) ||
362 !(layer_name
= alloca(len
)) ||
363 dm_snprintf(format
, len
, "%s_mimage_%%d", lv
->name
) < 0) {
364 log_error("lvconvert: layer name allocation failed.");
368 if (!generate_lv_name(lv
->vg
, format
, layer_name
, len
) ||
369 sscanf(layer_name
, format
, &i
) != 1) {
370 log_error("lvconvert: layer name generation failed.");
374 if (dm_snprintf(layer_name
, len
, MIRROR_SYNC_LAYER
"_%d", i
) < 0) {
375 log_error("layer name allocation failed.");
379 if (!insert_layer_for_lv(cmd
, lv
, 0, layer_name
)) {
380 log_error("Failed to insert resync layer");
387 static int _area_missing(struct lv_segment
*lvseg
, int s
)
389 if (seg_type(lvseg
, s
) == AREA_LV
) {
390 if (seg_lv(lvseg
, s
)->status
& PARTIAL_LV
)
392 } else if ((seg_type(lvseg
, s
) == AREA_PV
) &&
393 (seg_pv(lvseg
, s
)->status
& MISSING_PV
))
399 /* FIXME we want to handle mirror stacks here... */
400 static int _failed_mirrors_count(struct logical_volume
*lv
)
402 struct lv_segment
*lvseg
;
406 dm_list_iterate_items(lvseg
, &lv
->segments
) {
407 if (!seg_is_mirrored(lvseg
))
409 for (s
= 0; s
< lvseg
->area_count
; s
++)
410 if (_area_missing(lvseg
, s
))
417 static struct dm_list
*_failed_pv_list(struct volume_group
*vg
)
419 struct dm_list
*failed_pvs
;
420 struct pv_list
*pvl
, *new_pvl
;
422 if (!(failed_pvs
= dm_pool_alloc(vg
->vgmem
, sizeof(*failed_pvs
)))) {
423 log_error("Allocation of list of failed_pvs failed.");
427 dm_list_init(failed_pvs
);
429 dm_list_iterate_items(pvl
, &vg
->pvs
) {
430 if (!(pvl
->pv
->status
& MISSING_PV
))
433 if (!(new_pvl
= dm_pool_alloc(vg
->vgmem
, sizeof(*new_pvl
)))) {
434 log_error("Allocation of failed_pvs list entry failed.");
437 new_pvl
->pv
= pvl
->pv
;
438 dm_list_add(failed_pvs
, &new_pvl
->list
);
445 * Walk down the stacked mirror LV to the original mirror LV.
447 static struct logical_volume
*_original_lv(struct logical_volume
*lv
)
449 struct logical_volume
*next_lv
= lv
, *tmp_lv
;
451 while ((tmp_lv
= find_temporary_mirror(next_lv
)))
457 static void _lvconvert_mirrors_repair_ask(struct cmd_context
*cmd
,
458 int failed_log
, int failed_mirrors
,
459 int *replace_log
, int *replace_mirrors
)
461 const char *leg_policy
= NULL
, *log_policy
= NULL
;
463 int force
= arg_count(cmd
, force_ARG
);
464 int yes
= arg_count(cmd
, yes_ARG
);
466 *replace_log
= *replace_mirrors
= 1;
468 if (arg_count(cmd
, use_policies_ARG
)) {
469 leg_policy
= find_config_tree_str(cmd
,
470 "activation/mirror_device_fault_policy",
471 DEFAULT_MIRROR_DEVICE_FAULT_POLICY
);
472 log_policy
= find_config_tree_str(cmd
,
473 "activation/mirror_log_fault_policy",
474 DEFAULT_MIRROR_LOG_FAULT_POLICY
);
475 *replace_mirrors
= strcmp(leg_policy
, "remove");
476 *replace_log
= strcmp(log_policy
, "remove");
483 if (force
!= PROMPT
) {
484 *replace_log
= *replace_mirrors
= 0;
489 yes_no_prompt("Attempt to replace failed mirror log? [y/n]: ") == 'n') {
493 if (failed_mirrors
&&
494 yes_no_prompt("Attempt to replace failed mirror images "
495 "(requires full device resync)? [y/n]: ") == 'n') {
496 *replace_mirrors
= 0;
500 static int _using_corelog(struct logical_volume
*lv
)
502 return !first_seg(_original_lv(lv
))->log_lv
;
505 static int _lv_update_log_type(struct cmd_context
*cmd
,
506 struct lvconvert_params
*lp
,
507 struct logical_volume
*lv
,
510 struct logical_volume
*original_lv
= _original_lv(lv
);
511 if (_using_corelog(lv
) && !corelog
) {
512 if (!add_mirror_log(cmd
, original_lv
, 1,
513 adjusted_mirror_region_size(
519 } else if (!_using_corelog(lv
) && corelog
) {
520 if (!remove_mirror_log(cmd
, original_lv
,
521 lp
->pv_count
? lp
->pvh
: NULL
))
527 static int _lvconvert_mirrors(struct cmd_context
*cmd
, struct logical_volume
*lv
,
528 struct lvconvert_params
*lp
)
530 struct lv_segment
*seg
;
531 uint32_t existing_mirrors
;
532 const char *mirrorlog
;
533 unsigned corelog
= 0;
535 struct logical_volume
*log_lv
, *layer_lv
;
536 int failed_mirrors
= 0, failed_log
= 0;
537 struct dm_list
*old_pvh
= NULL
, *remove_pvs
= NULL
;
539 int repair
= arg_count(cmd
, repair_ARG
);
540 int replace_log
= 1, replace_mirrors
= 1;
543 existing_mirrors
= lv_mirror_count(lv
);
545 /* If called with no argument, try collapsing the resync layers */
546 if (!arg_count(cmd
, mirrors_ARG
) && !arg_count(cmd
, mirrorlog_ARG
) &&
547 !arg_count(cmd
, corelog_ARG
) && !arg_count(cmd
, regionsize_ARG
) &&
549 if (find_temporary_mirror(lv
) || (lv
->status
& CONVERTING
))
550 lp
->need_polling
= 1;
554 if (arg_count(cmd
, mirrors_ARG
) && repair
) {
555 log_error("You may only use one of --mirrors and --repair.");
560 * Adjust required number of mirrors
562 * We check mirrors_ARG again to see if it
563 * was supplied. If not, they want the mirror
564 * count to remain the same. They may be changing
567 if (!arg_count(cmd
, mirrors_ARG
))
568 lp
->mirrors
= existing_mirrors
;
569 else if (lp
->mirrors_sign
== SIGN_PLUS
)
570 lp
->mirrors
= existing_mirrors
+ lp
->mirrors
;
571 else if (lp
->mirrors_sign
== SIGN_MINUS
)
572 lp
->mirrors
= existing_mirrors
- lp
->mirrors
;
577 cmd
->handles_missing_pvs
= 1;
578 cmd
->partial_activation
= 1;
579 lp
->need_polling
= 0;
580 if (!(lv
->status
& PARTIAL_LV
)) {
581 log_error("The mirror is consistent, nothing to repair.");
584 if ((failed_mirrors
= _failed_mirrors_count(lv
)) < 0)
586 lp
->mirrors
-= failed_mirrors
;
587 log_error("Mirror status: %d of %d images failed.",
588 failed_mirrors
, existing_mirrors
);
590 if (!(lp
->pvh
= _failed_pv_list(lv
->vg
)))
592 log_lv
=first_seg(lv
)->log_lv
;
593 if (!log_lv
|| log_lv
->status
& PARTIAL_LV
)
594 failed_log
= corelog
= 1;
597 * Did the user try to subtract more legs than available?
599 if (lp
->mirrors
< 1) {
600 log_error("Logical volume %s only has %" PRIu32
" mirrors.",
601 lv
->name
, existing_mirrors
);
608 if (arg_count(cmd
, corelog_ARG
))
611 mirrorlog
= arg_str_value(cmd
, mirrorlog_ARG
,
612 corelog
? "core" : DEFAULT_MIRRORLOG
);
613 if (!strcmp("disk", mirrorlog
)) {
615 log_error("--mirrorlog disk and --corelog "
620 } else if (!strcmp("core", mirrorlog
))
623 log_error("Unknown mirrorlog type: %s", mirrorlog
);
627 log_verbose("Setting logging type to %s", mirrorlog
);
631 * Region size must not change on existing mirrors
633 if (arg_count(cmd
, regionsize_ARG
) && (lv
->status
& MIRRORED
) &&
634 (lp
->region_size
!= seg
->region_size
)) {
635 log_error("Mirror log region size cannot be changed on "
636 "an existing mirror.");
641 * For the most part, we cannot handle multi-segment mirrors. Bail out
642 * early if we have encountered one.
644 if ((lv
->status
& MIRRORED
) && dm_list_size(&lv
->segments
) != 1) {
645 log_error("Logical volume %s has multiple "
646 "mirror segments.", lv
->name
);
651 _lvconvert_mirrors_repair_ask(cmd
, failed_log
, failed_mirrors
,
652 &replace_log
, &replace_mirrors
);
656 * Converting from mirror to linear
658 if ((lp
->mirrors
== 1)) {
659 if (!(lv
->status
& MIRRORED
)) {
660 log_error("Logical volume %s is already not mirrored.",
669 if (lp
->mirrors
< existing_mirrors
) {
670 /* Reduce number of mirrors */
671 if (repair
|| lp
->pv_count
)
672 remove_pvs
= lp
->pvh
;
673 if (!lv_remove_mirrors(cmd
, lv
, existing_mirrors
- lp
->mirrors
,
674 (corelog
|| lp
->mirrors
== 1) ? 1U : 0U,
677 if (lp
->mirrors
> 1 &&
678 !_lv_update_log_type(cmd
, lp
, lv
, corelog
))
680 } else if (!(lv
->status
& MIRRORED
)) {
682 * Converting from linear to mirror
685 /* FIXME Share code with lvcreate */
687 /* FIXME Why is this restriction here? Fix it! */
688 dm_list_iterate_items(seg
, &lv
->segments
) {
689 if (seg_is_striped(seg
) && seg
->area_count
> 1) {
690 log_error("Mirrors of striped volumes are not yet supported.");
696 * FIXME should we give not only lp->pvh, but also all PVs
697 * currently taken by the mirror? Would make more sense from
700 if (!lv_add_mirrors(cmd
, lv
, lp
->mirrors
- 1, 1,
701 adjusted_mirror_region_size(
705 corelog
? 0U : 1U, lp
->pvh
, lp
->alloc
,
708 if (lp
->wait_completion
)
709 lp
->need_polling
= 1;
710 } else if (lp
->mirrors
> existing_mirrors
|| failed_mirrors
) {
711 if (lv
->status
& MIRROR_NOTSYNCED
) {
712 log_error("Can't add mirror to out-of-sync mirrored "
713 "LV: use lvchange --resync first.");
718 * We allow snapshots of mirrors, but for now, we
719 * do not allow up converting mirrors that are under
720 * snapshots. The layering logic is somewhat complex,
721 * and preliminary test show that the conversion can't
722 * seem to get the correct %'age of completion.
724 if (lv_is_origin(lv
)) {
725 log_error("Can't add additional mirror images to "
726 "mirrors that are under snapshots");
731 * Log addition/removal should be done before the layer
732 * insertion to make the end result consistent with
733 * linear-to-mirror conversion.
735 if (!_lv_update_log_type(cmd
, lp
, lv
, corelog
))
737 /* Insert a temporary layer for syncing,
738 * only if the original lv is using disk log. */
739 if (seg
->log_lv
&& !_insert_lvconvert_layer(cmd
, lv
)) {
740 log_error("Failed to insert resync layer");
743 /* FIXME: can't have multiple mlogs. force corelog. */
744 if (!lv_add_mirrors(cmd
, lv
, lp
->mirrors
- existing_mirrors
, 1,
745 adjusted_mirror_region_size(
749 0U, lp
->pvh
, lp
->alloc
,
751 layer_lv
= seg_lv(first_seg(lv
), 0);
752 if (!remove_layer_from_lv(lv
, layer_lv
) ||
753 !deactivate_lv(cmd
, layer_lv
) ||
754 !lv_remove(layer_lv
) || !vg_write(lv
->vg
) ||
755 !vg_commit(lv
->vg
)) {
756 log_error("ABORTING: Failed to remove "
757 "temporary mirror layer %s.",
759 log_error("Manual cleanup with vgcfgrestore "
760 "and dmsetup may be required.");
765 lv
->status
|= CONVERTING
;
766 lp
->need_polling
= 1;
769 if (lp
->mirrors
== existing_mirrors
) {
770 if (_using_corelog(lv
) != corelog
) {
771 if (!_lv_update_log_type(cmd
, lp
, lv
, corelog
))
774 log_error("Logical volume %s already has %"
775 PRIu32
" mirror(s).", lv
->name
,
777 if (lv
->status
& CONVERTING
)
778 lp
->need_polling
= 1;
783 log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv
->name
);
785 if (!vg_write(lv
->vg
))
788 if (!suspend_lv(cmd
, lv
)) {
789 log_error("Failed to lock %s", lv
->name
);
794 if (!vg_commit(lv
->vg
)) {
799 log_very_verbose("Updating \"%s\" in kernel", lv
->name
);
801 if (!resume_lv(cmd
, lv
)) {
802 log_error("Problem reactivating %s", lv
->name
);
806 if (failed_log
|| failed_mirrors
) {
808 if (failed_log
&& replace_log
)
809 failed_log
= corelog
= 0;
811 lp
->mirrors
+= failed_mirrors
;
813 existing_mirrors
= lv_mirror_count(lv
);
814 /* Now replace missing devices. */
815 if (replace_log
|| replace_mirrors
)
819 if (!lp
->need_polling
)
820 log_print("Logical volume %s converted.", lv
->name
);
828 static int lvconvert_snapshot(struct cmd_context
*cmd
,
829 struct logical_volume
*lv
,
830 struct lvconvert_params
*lp
)
832 struct logical_volume
*org
;
835 if (!(org
= find_lv(lv
->vg
, lp
->origin
))) {
836 log_error("Couldn't find origin volume '%s'.", lp
->origin
);
841 log_error("Unable to use \"%s\" as both snapshot and origin.",
846 if (org
->status
& (LOCKED
|PVMOVE
|MIRRORED
) || lv_is_cow(org
)) {
847 log_error("Unable to create a snapshot of a %s LV.",
848 org
->status
& LOCKED
? "locked" :
849 org
->status
& PVMOVE
? "pvmove" :
850 org
->status
& MIRRORED
? "mirrored" :
855 if (!lp
->zero
|| !(lv
->status
& LVM_WRITE
))
856 log_warn("WARNING: \"%s\" not zeroed", lv
->name
);
857 else if (!set_lv(cmd
, lv
, UINT64_C(0), 0)) {
858 log_error("Aborting. Failed to wipe snapshot "
863 if (!deactivate_lv(cmd
, lv
)) {
864 log_error("Couldn't deactivate LV %s.", lv
->name
);
868 if (!vg_add_snapshot(org
, lv
, NULL
, org
->le_count
, lp
->chunk_size
)) {
869 log_error("Couldn't create snapshot.");
873 /* store vg on disk(s) */
874 if (!vg_write(lv
->vg
))
877 if (!suspend_lv(cmd
, org
)) {
878 log_error("Failed to suspend origin %s", org
->name
);
883 if (!vg_commit(lv
->vg
))
886 if (!resume_lv(cmd
, org
)) {
887 log_error("Problem reactivating origin %s", org
->name
);
891 log_print("Logical volume %s converted to snapshot.", lv
->name
);
898 static int lvconvert_single(struct cmd_context
*cmd
, struct logical_volume
*lv
,
901 struct lvconvert_params
*lp
= handle
;
903 if (lv
->status
& LOCKED
) {
904 log_error("Cannot convert locked LV %s", lv
->name
);
909 log_error("Can't convert snapshot logical volume \"%s\"",
914 if (lv
->status
& PVMOVE
) {
915 log_error("Unable to convert pvmove LV %s", lv
->name
);
919 if (arg_count(cmd
, repair_ARG
) && !(lv
->status
& MIRRORED
)) {
920 log_error("Can't repair non-mirrored LV \"%s\".", lv
->name
);
925 if (lv
->status
& MIRRORED
) {
926 log_error("Unable to convert mirrored LV \"%s\" into a snapshot.", lv
->name
);
929 if (!archive(lv
->vg
)) {
933 if (!lvconvert_snapshot(cmd
, lv
, lp
)) {
937 } else if (arg_count(cmd
, mirrors_ARG
) || (lv
->status
& MIRRORED
)) {
938 if (!archive(lv
->vg
)) {
942 if (!_lvconvert_mirrors(cmd
, lv
, lp
)) {
948 return ECMD_PROCESSED
;
951 int lvconvert(struct cmd_context
* cmd
, int argc
, char **argv
)
953 struct volume_group
*vg
;
955 struct lvconvert_params lp
;
956 int ret
= ECMD_FAILED
;
958 int saved_ignore_suspended_devices
= ignore_suspended_devices();
960 if (!_read_params(&lp
, cmd
, argc
, argv
)) {
962 return EINVALID_CMD_LINE
;
965 if (arg_count(cmd
, repair_ARG
)) {
966 init_ignore_suspended_devices(1);
967 cmd
->handles_missing_pvs
= 1;
970 log_verbose("Checking for existing volume group \"%s\"", lp
.vg_name
);
972 vg
= vg_read_for_update(cmd
, lp
.vg_name
, NULL
, 0);
973 if (vg_read_error(vg
))
976 if (!(lvl
= find_lv_in_vg(vg
, lp
.lv_name
))) {
977 log_error("Logical volume \"%s\" not found in "
978 "volume group \"%s\"", lp
.lv_name
, lp
.vg_name
);
983 if (!(lp
.pvh
= create_pv_list(cmd
->mem
, vg
, lp
.pv_count
,
989 ret
= lvconvert_single(cmd
, lvl
->lv
, &lp
);
992 unlock_vg(cmd
, lp
.vg_name
);
994 if (ret
== ECMD_PROCESSED
&& lp
.need_polling
) {
995 if (!lv_info(cmd
, lvl
->lv
, &info
, 1, 0) || !info
.exists
) {
996 log_print("Conversion starts after activation");
999 ret
= lvconvert_poll(cmd
, lvl
->lv
,
1000 lp
.wait_completion
? 0 : 1U);
1003 init_ignore_suspended_devices(saved_ignore_suspended_devices
);