]> sourceware.org Git - lvm2.git/commitdiff
metadata: include description with command in metadata areas
authorDavid Teigland <teigland@redhat.com>
Tue, 18 Jun 2019 21:10:06 +0000 (16:10 -0500)
committerDavid Teigland <teigland@redhat.com>
Thu, 20 Jun 2019 21:09:05 +0000 (16:09 -0500)
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.

lib/format_text/export.c
lib/format_text/format-text.c
lib/metadata/metadata.h
lib/metadata/vg.h
test/shell/metadata.sh

index 841e06db9eecd70390849c2e023553d8b1d88f6f..2a3f8442662340e1c5c213508c6f185309c2ffea 100644 (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;
        }
index 13b2c664f6e99438348c7a02f4bf0f1dbe286634..6873f1963aef56f019566503327db08ebb8cd7e9 100644 (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) {
index 63ee4a619bce2c6045d12969d33c3175d2c83034..2fc0015ca5bb41130f966f557af68af1a754da3d 100644 (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);
index 6e89b3375ff53539a90e3537fdb3db14e3ec28a6..2e214616961777bd3d7f95d2d7b73ecf9ced7312 100644 (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
index a86bc0bcfe5967d114b3ff6ca4d25e61e92da04e..f5d64834b798753169cc143e7dd9ed58cdb1cc38 100644 (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
This page took 0.0427 seconds and 5 git commands to generate.