1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

metadata: include description with command in metadata areas

Previously the VG metadata description field (which contains
the command line) was only included in backup/archive copies
of the metadata.  Now also include it in the metadata written
to the metadata areas.
This commit is contained in:
David Teigland 2019-06-18 16:10:06 -05:00
parent 82b137ef2f
commit 8fecd9c14e
5 changed files with 33 additions and 4 deletions

View File

@ -1086,7 +1086,7 @@ size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
return r;
}
size_t export_vg_to_buffer(struct volume_group *vg, char **buf)
static size_t _export_vg_to_buffer(struct volume_group *vg, char **buf)
{
return text_vg_export_raw(vg, "", buf);
}
@ -1096,7 +1096,7 @@ struct dm_config_tree *export_vg_to_config_tree(struct volume_group *vg)
char *buf = NULL;
struct dm_config_tree *vg_cft;
if (!export_vg_to_buffer(vg, &buf)) {
if (!_export_vg_to_buffer(vg, &buf)) {
log_error("Could not format metadata for VG %s.", vg->name);
return NULL;
}

View File

@ -493,6 +493,29 @@ static struct volume_group *_vg_read_precommit_raw(struct format_instance *fid,
return vg;
}
#define MAX_DESC_LEN 2048
static char *_build_desc_write(struct cmd_context *cmd, struct volume_group *vg)
{
size_t len = strlen(cmd->cmd_line) + 32;
char *desc;
if (len > MAX_DESC_LEN)
len = MAX_DESC_LEN;
if (!(desc = zalloc(len)))
return_NULL;
vg->write_count++;
if (vg->write_count == 1)
dm_snprintf(desc, len, "Write from %s.", cmd->cmd_line);
else
dm_snprintf(desc, len, "Write[%u] from %s.", vg->write_count, cmd->cmd_line);
return desc;
}
/*
* VG metadata updates:
*
@ -576,9 +599,11 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg,
new_buf = fidtc->raw_metadata_buf;
new_size = fidtc->raw_metadata_buf_size;
} else {
new_size = text_vg_export_raw(vg, "", &new_buf);
char *desc = _build_desc_write(fid->fmt->cmd, vg);
new_size = text_vg_export_raw(vg, desc, &new_buf);
fidtc->raw_metadata_buf = new_buf;
fidtc->raw_metadata_buf_size = new_size;
free(desc);
}
if (!new_size || !new_buf) {

View File

@ -473,7 +473,6 @@ void lv_calculate_readahead(const struct logical_volume *lv, uint32_t *read_ahea
/*
* For internal metadata caching.
*/
size_t export_vg_to_buffer(struct volume_group *vg, char **buf);
struct dm_config_tree *export_vg_to_config_tree(struct volume_group *vg);
struct volume_group *import_vg_from_config_tree(const struct dm_config_tree *cft,
struct format_instance *fid);

View File

@ -42,6 +42,7 @@ struct volume_group {
struct lvmcache_vginfo *vginfo;
uint32_t seqno; /* Metadata sequence number */
unsigned skip_validate_lock_args : 1;
uint32_t write_count; /* count the number of vg_write calls */
/*
* The parsed committed (on-disk) copy of this VG; is NULL if this VG is committed

View File

@ -26,6 +26,10 @@ pvcreate --metadatacopies 0 "$dev5"
vgcreate $SHARED "$vg" "${DEVICES[@]}"
lvcreate -n $lv -l 1 -i5 -I256 $vg
pvck --dump metadata "$dev1" > meta1
grep "description = " meta1 > desc1
grep "Write from lvcreate" desc1
pvchange -x n "$dev1"
pvchange -x y "$dev1"
vgchange -a n $vg