From: Zdenek Kabelac Date: Mon, 26 Nov 2012 22:45:35 +0000 (+0100) Subject: thin: allow restore with --force X-Git-Tag: v2_02_99~639 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=09b7ceea95edb2b54074cbd5d3b2009b5bf1dd4e;p=lvm2.git thin: allow restore with --force Allow restoring metadata with thin pool volumes. No validation is done for this case within vgcfgrestore tool - thus incorrect metadata may lead to destruction of pool content. --- diff --git a/WHATS_NEW b/WHATS_NEW index 2c6ad4c08..1655a7eef 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.99 - =================================== + Allow forced vgcfgrestore of lvm2 metadata with thin volumes. Recognise STEC skd devices in filter. Recognise Violin Memory vtms devices in filter. Add lvm.conf thin pool defs thin_pool_{chunk_size|discards|zero}. diff --git a/lib/format_text/archiver.c b/lib/format_text/archiver.c index ccefb4cea..8599e3b28 100644 --- a/lib/format_text/archiver.c +++ b/lib/format_text/archiver.c @@ -347,7 +347,7 @@ int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg) /* ORPHAN and VG locks held before calling this */ int backup_restore_from_file(struct cmd_context *cmd, const char *vg_name, - const char *file) + const char *file, int force) { struct volume_group *vg; int missing_pvs, r = 0; @@ -360,14 +360,20 @@ int backup_restore_from_file(struct cmd_context *cmd, const char *vg_name, return_0; /* FIXME: Restore support is missing for now */ - dm_list_iterate_items(lvl, &vg->lvs) + dm_list_iterate_items(lvl, &vg->lvs) { if (lv_is_thin_type(lvl->lv)) { - log_error("Cannot restore Volume Group %s with " - "thin logical volumes. " - "(not yet supported).", vg->name); - r = 0; - goto out; + if (!force) { + log_error("Consider using option --force to restore " + "Volume Group %s with thin volumes.", + vg->name); + goto out; + } else { + log_warn("WARNING: Forced restore of Volume Group " + "%s with thin volumes.", vg->name); + break; + } } + } missing_pvs = vg_missing_pv_count(vg); if (missing_pvs == 0) @@ -381,7 +387,7 @@ out: return r; } -int backup_restore(struct cmd_context *cmd, const char *vg_name) +int backup_restore(struct cmd_context *cmd, const char *vg_name, int force) { char path[PATH_MAX]; @@ -391,7 +397,7 @@ int backup_restore(struct cmd_context *cmd, const char *vg_name) return 0; } - return backup_restore_from_file(cmd, vg_name, path); + return backup_restore_from_file(cmd, vg_name, path, force); } int backup_to_file(const char *file, const char *desc, struct volume_group *vg) diff --git a/lib/format_text/archiver.h b/lib/format_text/archiver.h index 7346f93be..ddff687fc 100644 --- a/lib/format_text/archiver.h +++ b/lib/format_text/archiver.h @@ -53,8 +53,8 @@ struct volume_group *backup_read_vg(struct cmd_context *cmd, const char *vg_name, const char *file); int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg); int backup_restore_from_file(struct cmd_context *cmd, const char *vg_name, - const char *file); -int backup_restore(struct cmd_context *cmd, const char *vg_name); + const char *file, int force); +int backup_restore(struct cmd_context *cmd, const char *vg_name, int force); int backup_to_file(const char *file, const char *desc, struct volume_group *vg); diff --git a/man/vgcfgrestore.8.in b/man/vgcfgrestore.8.in index 3b7b038b2..7b8dd5914 100644 --- a/man/vgcfgrestore.8.in +++ b/man/vgcfgrestore.8.in @@ -6,6 +6,7 @@ vgcfgrestore \- restore volume group descriptor area .RB [ \-d | \-\-debug ] .RB [ \-f | \-\-file .RI < filename >] +.RB [ \-\-force ] .RB [ \-l [ l ]| \-\-list ] .RB [ \-h | \-\-help ] .RB [ \-M | \-\-metadatatype @@ -32,6 +33,14 @@ May be used with the \fB\-f\fP option. Does not restore \fIVolumeGroupName\fP. Name of LVM metadata backup file Specifies a metadata backup or archive file to be used for restoring VolumeGroupName. Often this file has been created with \fBvgcfgbackup\fP. +.TP +.B \-\-force +To restore metadata with thin pool volumes, user currently +needs to use this flag. The tool DOES NOT make any validation. +.br +WARNING: Restoring lvm2 metadata that are not matching thin pool +kernel metadata may lead to the destruction of the pool content. +Use with extreme caution. .SH REPLACING PHYSICAL VOLUMES \fBvgdisplay \-\-partial \-\-verbose\fP will show you the UUIDs and sizes of any PVs that are no longer present. diff --git a/tools/args.h b/tools/args.h index 0d9605a89..d4d6c4012 100644 --- a/tools/args.h +++ b/tools/args.h @@ -73,6 +73,7 @@ arg(poll_ARG, '\0', "poll", yes_no_arg, 0) arg(poolmetadata_ARG, '\0', "poolmetadata", string_arg, 0) arg(poolmetadatasize_ARG, '\0', "poolmetadatasize", size_mb_arg, 0) arg(discards_ARG, '\0', "discards", discards_arg, 0) +arg(force_long_ARG, '\0', "force", NULL, ARG_COUNTABLE) arg(stripes_long_ARG, '\0', "stripes", int_arg, 0) arg(sysinit_ARG, '\0', "sysinit", NULL, 0) arg(thinpool_ARG, '\0', "thinpool", string_arg, 0) diff --git a/tools/commands.h b/tools/commands.h index 8d5d190f0..986539e13 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -725,6 +725,7 @@ xx(vgcfgrestore, "vgcfgrestore " "\n" "\t[-d|--debug] " "\n" "\t[-f|--file filename] " "\n" + "\t[--force]\n" "\t[-l[l]|--list [--list]]" "\n" "\t[-M|--metadatatype 1|2]" "\n" "\t[-h|--help]" "\n" @@ -733,7 +734,7 @@ xx(vgcfgrestore, "\t[--version] " "\n" "\tVolumeGroupName", - file_ARG, list_ARG, metadatatype_ARG, test_ARG) + file_ARG, force_long_ARG, list_ARG, metadatatype_ARG, test_ARG) xx(vgchange, "Change volume group attributes", diff --git a/tools/vgcfgrestore.c b/tools/vgcfgrestore.c index d62df99f7..20ca16b35 100644 --- a/tools/vgcfgrestore.c +++ b/tools/vgcfgrestore.c @@ -62,8 +62,9 @@ int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv) if (!(arg_count(cmd, file_ARG) ? backup_restore_from_file(cmd, vg_name, - arg_str_value(cmd, file_ARG, "")) : - backup_restore(cmd, vg_name))) { + arg_str_value(cmd, file_ARG, ""), + arg_count(cmd, force_long_ARG)) : + backup_restore(cmd, vg_name, arg_count(cmd, force_long_ARG)))) { unlock_vg(cmd, VG_ORPHANS); unlock_vg(cmd, vg_name); log_error("Restore failed.");