From 51aed1992f3c7836ef7016d1815d2fad9f0ec874 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Mon, 21 Feb 2011 12:31:28 +0000 Subject: [PATCH] Add old_uuid field to struct physical_volume so we can still reference a PV with its old UUID when we're changig it (the cache as well as metadata area index has the old uuid that we need to use to access the information!) --- lib/format_text/format-text.c | 10 +++++----- lib/metadata/pv.h | 1 + tools/pvchange.c | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index 4d387e31f..c5f58301a 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -1260,6 +1260,7 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume { struct text_fid_pv_context *fid_pv_tc; struct format_instance *fid = pv->fid; + const char *pvid = (const char *) (*pv->old_id.uuid ? &pv->old_id : &pv->id); struct label *label; int64_t label_sector; struct lvmcache_info *info; @@ -1303,8 +1304,7 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume * just pass the right format_instance in. */ for (mda_index = 0; mda_index < FMT_TEXT_MAX_MDAS_PER_PV; mda_index++) { - if (!(mda = fid_get_mda_indexed(fid, (const char *) &pv->id, - ID_LEN, mda_index))) + if (!(mda = fid_get_mda_indexed(fid, pvid, ID_LEN, mda_index))) continue; mdac = (struct mda_context *) mda->metadata_locn; @@ -1644,7 +1644,7 @@ static int _text_pv_setup(const struct format_type *fmt, struct volume_group *vg) { struct format_instance *fid = pv->fid; - const char *pvid = (const char *) &pv->id; + const char *pvid = (const char *) (*pv->old_id.uuid ? &pv->old_id : &pv->id); unsigned mda_index; struct metadata_area *pv_mda; struct mda_context *pv_mdac; @@ -1879,7 +1879,7 @@ static int _text_pv_add_metadata_area(const struct format_type *fmt, unsigned mda_ignored) { struct format_instance *fid = pv->fid; - const char *pvid = (char *) &pv->id; + const char *pvid = (const char *) (*pv->old_id.uuid ? &pv->old_id : &pv->id); uint64_t pe_start, pe_end; uint64_t alignment, alignment_offset; uint64_t disk_size; @@ -2099,7 +2099,7 @@ static int _text_pv_resize(const struct format_type *fmt, uint64_t size) { struct format_instance *fid = pv->fid; - const char *pvid = (const char *) &pv->id; + const char *pvid = (const char *) (*pv->old_id.uuid ? &pv->old_id : &pv->id); struct metadata_area *mda; struct mda_context *mdac; uint64_t size_reduction; diff --git a/lib/metadata/pv.h b/lib/metadata/pv.h index a9efcfe10..af6361034 100644 --- a/lib/metadata/pv.h +++ b/lib/metadata/pv.h @@ -22,6 +22,7 @@ struct volume_group; struct physical_volume { struct id id; + struct id old_id; /* Set during pvchange -u. */ struct device *dev; const struct format_type *fmt; struct format_instance *fid; diff --git a/tools/pvchange.c b/tools/pvchange.c index 0ffe7df43..254cf9132 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -120,6 +120,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg, if (arg_count(cmd, uuid_ARG)) { /* --uuid: Change PV ID randomly */ + memcpy(&pv->old_id, &pv->id, sizeof(pv->id)); if (!id_create(&pv->id)) { log_error("Failed to generate new random UUID for %s.", pv_name); -- 2.43.5