diff --git a/lib/display/display.c b/lib/display/display.c index b511b8e39..cf3c7f64f 100644 --- a/lib/display/display.c +++ b/lib/display/display.c @@ -695,7 +695,7 @@ void vgdisplay_full(const struct volume_group *vg) log_print("--- Volume group ---"); log_print("VG Name %s", vg->name); - log_print("System ID %s", vg->system_id); + log_print("System ID %s", (vg->system_id && *vg->system_id) ? vg->system_id : vg->lvm1_system_id ? : ""); log_print("Format %s", vg->fid->fmt->name); if (vg->fid->fmt->features & FMT_MDAS) { log_print("Metadata Areas %d", diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c index 8155b0437..9b387e2a1 100644 --- a/lib/format1/import-export.c +++ b/lib/format1/import-export.c @@ -156,8 +156,10 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem __attribute__((unused } /* Preserve existing system_id if it exists */ - if (vg && *vg->lvm1_system_id) + if (vg && vg->lvm1_system_id && *vg->lvm1_system_id) strncpy((char *)pvd->system_id, vg->lvm1_system_id, sizeof(pvd->system_id)); + else if (vg && vg->system_id && *vg->system_id) + strncpy((char *)pvd->system_id, vg->system_id, sizeof(pvd->system_id)); /* Is VG already exported or being exported? */ if (vg && vg_is_exported(vg)) { diff --git a/lib/format_text/export.c b/lib/format_text/export.c index ddaaebb54..8232e2f45 100644 --- a/lib/format_text/export.c +++ b/lib/format_text/export.c @@ -414,9 +414,11 @@ static int _print_vg(struct formatter *f, struct volume_group *vg) if (!_out_tags(f, &vg->tags)) return_0; - + if (vg->system_id && *vg->system_id) outf(f, "system_id = \"%s\"", vg->system_id); + else if (vg->lvm1_system_id && *vg->lvm1_system_id) + outf(f, "system_id = \"%s\"", vg->lvm1_system_id); outsize(f, (uint64_t) vg->extent_size, "extent_size = %u", vg->extent_size); diff --git a/lib/format_text/import_vsn1.c b/lib/format_text/import_vsn1.c index 366e61cfa..64c08a0bd 100644 --- a/lib/format_text/import_vsn1.c +++ b/lib/format_text/import_vsn1.c @@ -883,8 +883,6 @@ static struct volume_group *_read_vg(struct format_instance *fid, dm_hash_destroy(pv_hash); dm_hash_destroy(lv_hash); - /* FIXME Determine format type from file contents */ - /* eg Set to instance of fmt1 here if reading a format1 backup? */ vg_set_fid(vg, fid); /* diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c index 2bed1ad59..404cc6fa6 100644 --- a/lib/metadata/vg.c +++ b/lib/metadata/vg.c @@ -47,6 +47,8 @@ struct volume_group *alloc_vg(const char *pool_name, struct cmd_context *cmd, return NULL; } + vg->system_id = ""; + vg->cmd = cmd; vg->vgmem = vgmem; vg->alloc = ALLOC_NORMAL; @@ -627,6 +629,9 @@ int vg_set_system_id(struct volume_group *vg, const char *system_id) return 0; } + if (vg->lvm1_system_id) + *vg->lvm1_system_id = '\0'; + return 1; } diff --git a/lib/report/report.c b/lib/report/report.c index b5418e55b..75928c026 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -989,7 +989,7 @@ static int _vgsystemid_disp(struct dm_report *rh, struct dm_pool *mem, const void *data, void *private) { const struct volume_group *vg = (const struct volume_group *) data; - const char *repstr = vg->system_id ? : vg->lvm1_system_id ? : ""; + const char *repstr = (vg->system_id && *vg->system_id) ? vg->system_id : vg->lvm1_system_id ? : ""; return _string_disp(rh, mem, field, &repstr, private); } diff --git a/tools/toollib.c b/tools/toollib.c index 19c23fed8..12fe1e249 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -200,8 +200,9 @@ static int _ignore_vg(struct volume_group *vg, const char *vg_name, */ if (read_error & FAILED_SYSTEMID) { if (arg_vgnames && str_list_match_item(arg_vgnames, vg->name)) { - log_error("Cannot access VG %s with system ID %s with local system ID %s.", - vg->name, vg->system_id, vg->cmd->system_id); + log_error("Cannot access VG %s with system ID %s with %slocal system ID%s%s.", + vg->name, vg->system_id, vg->cmd->system_id ? "" : "unknown ", + vg->cmd->system_id ? " " : "", vg->cmd->system_id ? vg->cmd->system_id : ""); return 1; } else { read_error &= ~FAILED_SYSTEMID; /* Check for other errors */ diff --git a/tools/vgchange.c b/tools/vgchange.c index 3f9772288..36b44a9ad 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -575,6 +575,9 @@ static int _vgchange_system_id(struct cmd_context *cmd, struct volume_group *vg) vg->name, vg->system_id, system_id); vg->system_id = system_id; + + if (vg->lvm1_system_id) + *vg->lvm1_system_id = '\0'; return 1; }