1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-28 03:27:58 +03:00

Read PV metadata information from cache if pv_setup called with pv->fid == vg->fid.

If the PV is already part of the VG (so the pv->fid == vg->fid), it makes no
sense to attach the mdas information from PV to a VG. Instead, we read new
PV metadata information from cache and attach it to the VG fid.
This commit is contained in:
Peter Rajnoha 2011-02-25 13:59:47 +00:00
parent ea4a41e961
commit 38b0564cab
3 changed files with 33 additions and 24 deletions

View File

@ -294,8 +294,6 @@ struct volume_group *backup_read_vg(struct cmd_context *cmd,
int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg) int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg)
{ {
struct pv_list *pvl; struct pv_list *pvl;
struct physical_volume *pv;
struct lvmcache_info *info;
struct format_instance *fid; struct format_instance *fid;
struct format_instance_ctx fic; struct format_instance_ctx fic;
@ -305,7 +303,7 @@ int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg)
*/ */
/* Attempt to write out using currently active format */ /* Attempt to write out using currently active format */
fic.type = FMT_INSTANCE_VG | FMT_INSTANCE_MDAS | FMT_INSTANCE_AUX_MDAS; fic.type = FMT_INSTANCE_VG | FMT_INSTANCE_AUX_MDAS;
fic.context.vg_ref.vg_name = vg->name; fic.context.vg_ref.vg_name = vg->name;
fic.context.vg_ref.vg_id = NULL; fic.context.vg_ref.vg_id = NULL;
if (!(fid = cmd->fmt->ops->create_instance(cmd->fmt, &fic))) { if (!(fid = cmd->fmt->ops->create_instance(cmd->fmt, &fic))) {
@ -322,20 +320,9 @@ int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg)
/* Add any metadata areas on the PVs */ /* Add any metadata areas on the PVs */
dm_list_iterate_items(pvl, &vg->pvs) { dm_list_iterate_items(pvl, &vg->pvs) {
pv = pvl->pv; if (!vg->fid->fmt->ops->pv_setup(vg->fid->fmt, pvl->pv, vg)) {
if (!(info = info_from_pvid(pv->dev->pvid, 0))) {
log_error("PV %s missing from cache",
pv_dev_name(pv));
return 0;
}
if (cmd->fmt != info->fmt) {
log_error("PV %s is a different format (seqno %s)",
pv_dev_name(pv), info->fmt->name);
return 0;
}
if (!vg->fid->fmt->ops->pv_setup(vg->fid->fmt, pv, vg)) {
log_error("Format-specific setup for %s failed", log_error("Format-specific setup for %s failed",
pv_dev_name(pv)); pv_dev_name(pvl->pv));
return 0; return 0;
} }
} }

View File

@ -1645,20 +1645,42 @@ static int _text_pv_setup(const struct format_type *fmt,
{ {
struct format_instance *fid = pv->fid; struct format_instance *fid = pv->fid;
const char *pvid = (const char *) (*pv->old_id.uuid ? &pv->old_id : &pv->id); const char *pvid = (const char *) (*pv->old_id.uuid ? &pv->old_id : &pv->id);
struct lvmcache_info *info;
unsigned mda_index; unsigned mda_index;
struct metadata_area *pv_mda; struct metadata_area *pv_mda;
struct mda_context *pv_mdac; struct mda_context *pv_mdac;
uint64_t pe_count; uint64_t pe_count;
uint64_t size_reduction = 0; uint64_t size_reduction = 0;
/* Add any further mdas on this PV to VG's format instance. */ /* If PV has its own format instance, add mdas from pv->fid to vg->fid. */
for (mda_index = 0; mda_index < FMT_TEXT_MAX_MDAS_PER_PV; mda_index++) { if (pv->fid != vg->fid) {
if (!(pv_mda = fid_get_mda_indexed(fid, pvid, ID_LEN, mda_index))) for (mda_index = 0; mda_index < FMT_TEXT_MAX_MDAS_PER_PV; mda_index++) {
continue; if (!(pv_mda = fid_get_mda_indexed(fid, pvid, ID_LEN, mda_index)))
continue;
/* Be sure it's not already in VG's format instance! */ /* Be sure it's not already in VG's format instance! */
if (!fid_get_mda_indexed(vg->fid, pvid, ID_LEN, mda_index)) if (!fid_get_mda_indexed(vg->fid, pvid, ID_LEN, mda_index))
fid_add_mda(vg->fid, pv_mda, pvid, ID_LEN, mda_index); fid_add_mda(vg->fid, pv_mda, pvid, ID_LEN, mda_index);
}
}
/*
* Otherwise, if the PV is already a part of the VG (pv->fid == vg->fid),
* reread PV mda information from the cache and add it to vg->fid.
*/
else {
if (!(info = info_from_pvid(pv->dev->pvid, 0))) {
log_error("PV %s missing from cache", pv_dev_name(pv));
return 0;
}
if (fmt != info->fmt) {
log_error("PV %s is a different format (seqno %s)",
pv_dev_name(pv), info->fmt->name);
return 0;
}
if (!fid_add_mdas(vg->fid, &info->mdas, pvid, ID_LEN))
return_0;
} }
/* If there's the 2nd mda, we need to reduce /* If there's the 2nd mda, we need to reduce

View File

@ -4105,7 +4105,7 @@ int fid_add_mdas(struct format_instance *fid, struct dm_list *mdas,
mda_new = mda_copy(fid->fmt->cmd->mem, mda); mda_new = mda_copy(fid->fmt->cmd->mem, mda);
if (!mda_new) if (!mda_new)
return_0; return_0;
fid_remove_mda(fid, NULL, key, key_len, mda_index);
fid_add_mda(fid, mda_new, key, key_len, mda_index); fid_add_mda(fid, mda_new, key, key_len, mda_index);
mda_index++; mda_index++;
} }