mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-22 17:35:59 +03:00
Fix vgsplit for lvm1 format (set and validate VG name in PVs metadata).
Split metadata areas in vgsplit properly.
This commit is contained in:
parent
0d93f89f5c
commit
66f28e193a
@ -1,5 +1,7 @@
|
||||
Version 2.02.25 -
|
||||
=================================
|
||||
Fix vgsplit for lvm1 format (set and validate VG name in PVs metadata).
|
||||
Split metadata areas in vgsplit properly.
|
||||
|
||||
Version 2.02.24 - 19th March 2007
|
||||
=================================
|
||||
|
@ -80,6 +80,22 @@ static int _text_vg_setup(struct format_instance *fid __attribute((unused)),
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if metadata area belongs to vg
|
||||
*/
|
||||
static int _mda_in_vg_raw(struct format_instance *fid __attribute((unused)),
|
||||
struct volume_group *vg, struct metadata_area *mda)
|
||||
{
|
||||
struct mda_context *mdac = (struct mda_context *) mda->metadata_locn;
|
||||
struct pv_list *pvl;
|
||||
|
||||
list_iterate_items(pvl, &vg->pvs)
|
||||
if (pvl->pv->dev == mdac->area.dev)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _text_lv_setup(struct format_instance *fid __attribute((unused)),
|
||||
struct logical_volume *lv)
|
||||
{
|
||||
@ -1395,7 +1411,8 @@ static struct metadata_area_ops _metadata_text_raw_ops = {
|
||||
.vg_remove = _vg_remove_raw,
|
||||
.vg_precommit = _vg_precommit_raw,
|
||||
.vg_commit = _vg_commit_raw,
|
||||
.vg_revert = _vg_revert_raw
|
||||
.vg_revert = _vg_revert_raw,
|
||||
.mda_in_vg = _mda_in_vg_raw,
|
||||
};
|
||||
|
||||
/* pvmetadatasize in sectors */
|
||||
|
@ -505,6 +505,34 @@ int vg_change_pesize(struct cmd_context *cmd, struct volume_group *vg,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int vg_split_mdas(struct cmd_context *cmd, struct volume_group *vg_from,
|
||||
struct volume_group *vg_to)
|
||||
{
|
||||
struct metadata_area *mda, *mda2;
|
||||
struct list *mdas_from, *mdas_to;
|
||||
int common_mda = 0;
|
||||
|
||||
mdas_from = &vg_from->fid->metadata_areas;
|
||||
mdas_to = &vg_to->fid->metadata_areas;
|
||||
|
||||
list_iterate_items_safe(mda, mda2, mdas_from) {
|
||||
if (!mda->ops->mda_in_vg) {
|
||||
common_mda = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!mda->ops->mda_in_vg(vg_from->fid, vg_from, mda)) {
|
||||
list_del(&mda->list);
|
||||
list_add(mdas_to, &mda->list);
|
||||
}
|
||||
}
|
||||
|
||||
if (list_empty(mdas_from) || list_empty(mdas_to))
|
||||
return common_mda;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Sizes in sectors */
|
||||
struct physical_volume *pv_create(const struct format_type *fmt,
|
||||
struct device *dev,
|
||||
@ -759,6 +787,12 @@ int vg_validate(struct volume_group *vg)
|
||||
r = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(pvl->pv->vg_name, vg->name)) {
|
||||
log_error("Internal error: VG name for PV %s is corrupted",
|
||||
dev_name(pvl->pv->dev));
|
||||
r = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!check_pv_segments(vg)) {
|
||||
|
@ -178,6 +178,11 @@ struct metadata_area_ops {
|
||||
struct volume_group * vg, struct metadata_area * mda);
|
||||
int (*vg_remove) (struct format_instance * fi, struct volume_group * vg,
|
||||
struct metadata_area * mda);
|
||||
/*
|
||||
* Check if metadata area belongs to vg
|
||||
*/
|
||||
int (*mda_in_vg) (struct format_instance * fi,
|
||||
struct volume_group * vg, struct metadata_area *mda);
|
||||
};
|
||||
|
||||
struct metadata_area {
|
||||
@ -450,6 +455,8 @@ int vg_extend(struct format_instance *fi, struct volume_group *vg,
|
||||
int pv_count, char **pv_names);
|
||||
int vg_change_pesize(struct cmd_context *cmd, struct volume_group *vg,
|
||||
uint32_t new_extent_size);
|
||||
int vg_split_mdas(struct cmd_context *cmd, struct volume_group *vg_from,
|
||||
struct volume_group *vg_to);
|
||||
|
||||
/* Manipulate LVs */
|
||||
struct logical_volume *lv_create_empty(struct format_instance *fi,
|
||||
|
@ -299,6 +299,10 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Set metadata format of original VG */
|
||||
/* FIXME: need some common logic */
|
||||
cmd->fmt = vg_from->fid->fmt;
|
||||
|
||||
/* Create new VG structure */
|
||||
if (!(vg_to = vg_create(cmd, vg_name_to, vg_from->extent_size,
|
||||
vg_from->max_pv, vg_from->max_lv,
|
||||
@ -330,11 +334,15 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
|
||||
if (!(_move_mirrors(vg_from, vg_to)))
|
||||
goto error;
|
||||
|
||||
/* FIXME Split mdas properly somehow too! */
|
||||
/* Currently we cheat by sharing the format instance and relying on
|
||||
* vg_write to ignore mdas outside the VG! Done this way, with text
|
||||
* format, vg_from disappears for a short time. */
|
||||
vg_to->fid = vg_from->fid;
|
||||
/* Split metadata areas and check if both vgs have at least one area */
|
||||
if (!(vg_split_mdas(cmd, vg_from, vg_to))) {
|
||||
log_error("Cannot split: Nowhere to store metadata for new Volume Group");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Set proper name for all PVs in new VG */
|
||||
if (!vg_rename(cmd, vg_to, vg_name_to))
|
||||
goto error;
|
||||
|
||||
/* store it on disks */
|
||||
log_verbose("Writing out updated volume groups");
|
||||
|
Loading…
Reference in New Issue
Block a user