mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Do not reset position in metadata ring buffer on vgrename and vgcfgrestore.
We should write metadata into next position in the ring buffer while calling vgrename and vgcfgrestore. At this code level (_vg_write_raw), we were not able to determine if this is a rename or not. If yes, then accompanying VG structure passed here has a new name set, not the old one. When looking for a location where to put metadata next, we were given a NULL value because of failed VG name comparison (in _find_vg_rlocn) between the name in existing metadata and metadata we're just about to write. This resets the position in the ring buffer, overwriting any existing metadata (and also incorrectly updates the cache to "orphan" afterwards). This patch just adds old_name item in struct volume_group that we can check and use if necessary and detect renames at lower layers as well. The same applies for vgcfgrestore, but here we're using a special value of old_name, an empty string, to disable the check with existing metadata totally.
This commit is contained in:
parent
c6469d46dd
commit
1e696b0c15
@ -1,5 +1,6 @@
|
||||
Version 2.02.63 -
|
||||
================================
|
||||
Do not reset position in metadata ring buffer on vgrename and vgcfgrestore.
|
||||
Allow VGs with active LVs to be renamed.
|
||||
Use UUIDs instead of names while processing event handlers.
|
||||
Only pass visible LVs to tools in cmdline VG name/tag expansions without -a.
|
||||
|
@ -306,6 +306,12 @@ int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Setting vg->old_name to a blank value will explicitly
|
||||
* disable any attempt to check VG name in existing metadata.
|
||||
*/
|
||||
vg->old_name = dm_pool_strdup(vg->vgmem, "");
|
||||
|
||||
/* Add any metadata areas on the PVs */
|
||||
dm_list_iterate_items(pvl, &vg->pvs) {
|
||||
pv = pvl->pv;
|
||||
|
@ -380,6 +380,17 @@ static struct raw_locn *_find_vg_rlocn(struct device_area *dev_area,
|
||||
} else
|
||||
*precommitted = 0;
|
||||
|
||||
/* Do not check non-existent metadata. */
|
||||
if (!rlocn->offset && !rlocn->size)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Don't try to check existing metadata
|
||||
* if given vgname is an empty string.
|
||||
*/
|
||||
if (!*vgname)
|
||||
return rlocn;
|
||||
|
||||
/* FIXME Loop through rlocns two-at-a-time. List null-terminated. */
|
||||
/* FIXME Ignore if checksum incorrect!!! */
|
||||
if (!dev_read(dev_area->dev, dev_area->start + rlocn->offset,
|
||||
@ -387,9 +398,11 @@ static struct raw_locn *_find_vg_rlocn(struct device_area *dev_area,
|
||||
goto_bad;
|
||||
|
||||
if (!strncmp(vgnamebuf, vgname, len = strlen(vgname)) &&
|
||||
(isspace(vgnamebuf[len]) || vgnamebuf[len] == '{')) {
|
||||
(isspace(vgnamebuf[len]) || vgnamebuf[len] == '{'))
|
||||
return rlocn;
|
||||
}
|
||||
else
|
||||
log_debug("Volume group name found in metadata does "
|
||||
"not match expected name %s.", vgname);
|
||||
|
||||
bad:
|
||||
if ((info = info_from_pvid(dev_area->dev->pvid, 0)))
|
||||
@ -542,7 +555,8 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg,
|
||||
if (!(mdah = _raw_read_mda_header(fid->fmt, &mdac->area)))
|
||||
goto_out;
|
||||
|
||||
rlocn = _find_vg_rlocn(&mdac->area, mdah, vg->name, &noprecommit);
|
||||
rlocn = _find_vg_rlocn(&mdac->area, mdah,
|
||||
vg->old_name ? vg->old_name : vg->name, &noprecommit);
|
||||
mdac->rlocn.offset = _next_rlocn_offset(rlocn, mdah);
|
||||
|
||||
if (!fidtc->raw_metadata_buf &&
|
||||
@ -647,7 +661,9 @@ static int _vg_commit_raw_rlocn(struct format_instance *fid,
|
||||
if (!(mdah = _raw_read_mda_header(fid->fmt, &mdac->area)))
|
||||
goto_out;
|
||||
|
||||
if (!(rlocn = _find_vg_rlocn(&mdac->area, mdah, vg->name, &noprecommit))) {
|
||||
if (!(rlocn = _find_vg_rlocn(&mdac->area, mdah,
|
||||
vg->old_name ? vg->old_name : vg->name,
|
||||
&noprecommit))) {
|
||||
mdah->raw_locns[0].offset = 0;
|
||||
mdah->raw_locns[0].size = 0;
|
||||
mdah->raw_locns[0].checksum = 0;
|
||||
|
@ -227,6 +227,7 @@ struct volume_group {
|
||||
|
||||
struct id id;
|
||||
char *name;
|
||||
char *old_name; /* Set during vgrename and vgcfgrestore */
|
||||
char *system_id;
|
||||
|
||||
uint32_t extent_size;
|
||||
|
@ -457,6 +457,8 @@ int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
|
||||
struct dm_pool *mem = vg->vgmem;
|
||||
struct pv_list *pvl;
|
||||
|
||||
vg->old_name = vg->name;
|
||||
|
||||
if (!(vg->name = dm_pool_strdup(mem, new_name))) {
|
||||
log_error("vg->name allocation failed for '%s'", new_name);
|
||||
return 0;
|
||||
@ -2428,11 +2430,15 @@ int vg_commit(struct volume_group *vg)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Instruct remote nodes to upgrade cached metadata.
|
||||
*/
|
||||
if (cache_updated)
|
||||
if (cache_updated) {
|
||||
/* Instruct remote nodes to upgrade cached metadata. */
|
||||
remote_commit_cached_metadata(vg);
|
||||
/*
|
||||
* We need to clear old_name after a successful commit.
|
||||
* The volume_group structure could be reused later.
|
||||
*/
|
||||
vg->old_name = NULL;
|
||||
}
|
||||
|
||||
/* If update failed, remove any cached precommitted metadata. */
|
||||
if (!cache_updated && !drop_cached_metadata(vg))
|
||||
|
Loading…
Reference in New Issue
Block a user