main - cov: clean up pvid and vgid usage
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=96b777167c63eaf2e8ef1a2e7a92dc6c66cbcd6a Commit: 96b777167c63eaf2e8ef1a2e7a92dc6c66cbcd6a Parent: 0d572d14ad14afad43a8a3f5fe033ed3996c05c6 Author: David Teigland <[email protected]> AuthorDate: Tue Aug 3 15:32:33 2021 -0500 Committer: David Teigland <[email protected]> CommitterDate: Mon Aug 16 11:31:15 2021 -0500
cov: clean up pvid and vgid usage
pvid and vgid are sometimes a null-terminated string, and other times a 'struct id', and the two types were often cast between each other. When a struct id was cast to a char pointer, the resulting string would not necessarily be null terminated. Casting a null-terminated string id to a struct id is fine, but is still avoided when possible.
A struct id is: int8_t uuid[ID_LEN] A string id is: char pvid[ID_LEN + 1]
A convention is introduced to help distinguish them:
- variables and struct fields named "pvid" or "vgid" should be null-terminated strings.
- variables and struct fields named "pv_id" or "vg_id" should be struct id's.
- examples:
char pvid[ID_LEN + 1];
char vgid[ID_LEN + 1];
struct id pv_id;
struct id vg_id;
Function names also attempt to follow this convention.
Avoid casting between the two types as much as possible, with limited exceptions when known to be safe and clearly commented.
Avoid using variations of strcpy and strcmp, and instead use memcpy/memcmp with ID_LEN (with similar limited exceptions possible.)
--- lib/activate/dev_manager.c | 2 +- lib/cache/lvmcache.c | 224 +++++++++++++++++++++++------------------- lib/cache/lvmcache.h | 7 +- lib/device/device_id.c | 4 +- lib/format_text/archiver.c | 3 +- lib/format_text/format-text.c | 57 +++++++++-- lib/format_text/import_vsn1.c | 8 +- lib/format_text/text_label.c | 10 +- lib/label/label.c | 5 +- lib/metadata/metadata.c | 46 ++++++--- lib/metadata/metadata.h | 2 +- lib/metadata/pv.c | 21 ++-- lib/metadata/pv.h | 4 +- tools/pvchange.c | 4 +- tools/pvck.c | 44 ++++----- tools/pvscan.c | 10 +- tools/toollib.c | 28 +++--- tools/vgimportdevices.c | 9 +- tools/vgrename.c | 12 ++- 19 files changed, 296 insertions(+), 204 deletions(-)
lib/activate/dev_manager.c +1 -1
@@ -2118,7 +2118,7 @@ static int _check_holder(struct dev_manager *dm, struct dm_tree *dtree,if (!strncmp (default_uuid_prefix, uuid, default_uuid_prefix_len)) uuid += default_uuid_prefix_len; -if (!strncmp (uuid, (char *)&lv->vg->id,sizeof (lv->vg->id)) && +if (!memcmp (uuid, &lv->vg->id,ID_LEN ) && !dm_tree_find_node_by_uuid (dtree, uuid)) {/* trims any UUID suffix (i.e. -cow) */ (void )dm_strncpy ((char *)&id, uuid,2 *sizeof (struct id ) +1 );
lib/cache/lvmcache.c +124 -100
549 lines not on this page · raw message
lib/cache/lvmcache.h +4 -3
@@ -47,7 +47,7 @@ struct lvmcache_vginfo;*/ struct lvmcache_vgsummary {const char *vgname; -struct id vgid; +char vgid[ID_LEN +1 ];uint64_t vgstatus;char *creation_host;const char *system_id;
@@ -96,9 +96,10 @@ struct lvmcache_vginfo *lvmcache_vginfo_from_vgname(const char *vgname, const char *vgid);struct lvmcache_vginfo *lvmcache_vginfo_from_vgid (const char *vgid);struct lvmcache_info *lvmcache_info_from_pvid (const char *pvid,struct device *dev,int valid_only); +struct lvmcache_info *lvmcache_info_from_pv_id (const struct id *pv_id,struct device *dev,int valid_only);const char *lvmcache_vgname_from_vgid (struct dm_pool *mem,const char *vgid);const char *lvmcache_vgid_from_vgname (struct cmd_context *cmd,const char *vgname); -struct device *lvmcache_device_from_pvid (struct cmd_context *cmd,const struct id *pvid,uint64_t *label_sector); +struct device *lvmcache_device_from_pv_id (struct cmd_context *cmd,const struct id *pv_id,uint64_t *label_sector);const char *lvmcache_vgname_from_info (struct lvmcache_info *info);const struct format_type *lvmcache_fmt_from_info (struct lvmcache_info *info);
@@ -181,7 +182,7 @@ int lvmcache_vg_is_foreign(struct cmd_context *cmd, const char *vgname, const chbool lvmcache_scan_mismatch (struct cmd_context *cmd,const char *vgname,const char *vgid); -int lvmcache_vginfo_has_pvid (struct lvmcache_vginfo *vginfo,char *pvid); +int lvmcache_vginfo_has_pvid (struct lvmcache_vginfo *vginfo,const char *pvid_arg);uint64_t lvmcache_max_metadata_size (void );void lvmcache_save_metadata_size (uint64_t val);
lib/device/device_id.c +2 -2
@@ -867,7 +867,7 @@ struct dev_use *get_du_for_pvid(struct cmd_context *cmd, const char *pvid) dm_list_iterate_items(du, &cmd->use_devices) {if (!du->pvid)continue ; -if (!strcmp (du->pvid, pvid)) +if (!memcmp (du->pvid, pvid,ID_LEN ))return du; }return NULL ;
@@ -1695,7 +1695,7 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,/* * A good match based on pvid. */ -if (dev->pvid[0 ] && !strcmp (dev->pvid, du->pvid)) { +if (dev->pvid[0 ] && !memcmp (dev->pvid, du->pvid,ID_LEN )) {const char *devname =dev_name (dev);if (strcmp (devname, du->idname)) {
lib/format_text/archiver.c +2 -1
@@ -413,7 +413,8 @@ int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg,return 0 ; } pv->vg_name = vg->name; - pv->vgid = vg->id; +/* both are struct id */ +memcpy (&pv->vg_id, &vg->id,sizeof (struct id ));if (!(new_pvl =dm_pool_zalloc (vg->vgmem,sizeof (*new_pvl)))) { log_error("Failed to allocate PV list item for \"%s\".",
lib/format_text/format-text.c +47 -10
147 lines not on this page · raw message
lib/format_text/import_vsn1.c +6 -2
@@ -219,7 +219,8 @@ static int _read_pv(struct cmd_context *cmd,if (!(pv->vg_name =dm_pool_strdup (mem, vg->name))) return_0; -memcpy (&pv->vgid, &vg->id,sizeof (vg->id)); +/* both are struct id */ +memcpy (&pv->vg_id, &vg->id,sizeof (struct id ));if (!_read_flag_config (pvn, &pv->status,PV_FLAGS )) {log_error ("Couldn't read status flags for physical volume." );
@@ -1302,6 +1303,7 @@ static int _read_vgsummary(const struct format_type *fmt, const struct dm_configconst struct dm_config_node *vgn;struct dm_pool *mem = fmt->cmd->mem;const char *str; +struct id id;if (!dm_config_get_str (cft->root,"creation_host" , &str)) str ="" ;
@@ -1322,11 +1324,13 @@ static int _read_vgsummary(const struct format_type *fmt, const struct dm_config vgn = vgn->child; -if (!_read_id (&vgsummary->vgid, vgn,"id" )) { +if (!_read_id (&id, vgn,"id" )) {log_error ("Couldn't read uuid for volume group %s." , vgsummary->vgname);return 0 ; } +memcpy (vgsummary->vgid, &id,ID_LEN ); +if (!_read_flag_config (vgn, &vgsummary->vgstatus,VG_FLAGS )) {log_error ("Couldn't find status flags for volume group %s." , vgsummary->vgname);
lib/format_text/text_label.c +7 -3
@@ -409,6 +409,7 @@ static int _text_read(struct cmd_context *cmd, struct labeller *labeller, struct uint64_t label_sector, int *is_duplicate) { struct lvmcache_vgsummary vgsummary; + char pvid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 };struct lvmcache_info *info;const struct format_type *fmt = labeller->fmt;struct label_header *lh = (struct label_header *) label_buf;
@@ -431,6 +432,8 @@ static int _text_read(struct cmd_context *cmd, struct labeller *labeller, struct*/ pvhdr = (struct pv_header *) ((char *) label_buf +xlate32 (lh->offset_xl)); +memcpy (pvid, &pvhdr->pv_uuid,ID_LEN ); +/* * FIXME: stop adding the device to lvmcache initially as an orphan * (and then moving it later) and instead just add it when we know the
@@ -445,7 +448,7 @@ static int _text_read(struct cmd_context *cmd, struct labeller *labeller, struct* * Other reasons for lvmcache_add to return NULL are internal errors. */ -if (!(info =lvmcache_add (cmd, labeller, (char *)pvhdr->pv_uuid, dev, label_sector, +if (!(info =lvmcache_add (cmd, labeller, pvid, dev, label_sector,FMT_TEXT_ORPHAN_VG_NAME ,FMT_TEXT_ORPHAN_VG_NAME ,0 , is_duplicate))) return_0;
@@ -495,8 +498,9 @@ static int _text_read(struct cmd_context *cmd, struct labeller *labeller, structif (!(ext_version =xlate32 (pvhdr_ext->version))) goto scan_mdas; -log_debug_metadata ("%s: PV header extension version " FMTu32" found" , -dev_name (dev), ext_version); +if (ext_version !=PV_HEADER_EXTENSION_VSN ) +log_debug_metadata ("Found pv_header_extension version " FMTu32" on %s" , + ext_version,dev_name (dev));/* Extension version */ lvmcache_set_ext_version (info,xlate32 (pvhdr_ext->version));
lib/label/label.c +2 -3
@@ -307,9 +307,8 @@ static struct labeller *_find_lvm_header(struct device *dev, dm_list_iterate_items(li, &_labellers) {if (li->l->ops->can_handle (li->l, (char *) lh, block_sector + sector)) { -log_very_verbose ("%s: %s label detected at sector %llu" , -dev_name (dev), li->name, - (unsigned long long )(block_sector + sector)); +log_debug ("Found label at sector %llu on %s" , + (unsigned long long )(block_sector + sector),dev_name (dev));if (found) { log_error("Ignoring additional label on %s at sector %llu", dev_name(dev),
lib/metadata/metadata.c +30 -16
158 lines not on this page · raw message
lib/metadata/metadata.h +1 -1
@@ -531,7 +531,7 @@ int update_pool_metadata_min_max(struct cmd_context *cmd,*/ struct id pv_id (const struct physical_volume *pv);const struct format_type *pv_format_type (const struct physical_volume *pv); -struct id pv_vgid (const struct physical_volume *pv); +struct id pv_vg_id (const struct physical_volume *pv);uint64_t find_min_mda_size (struct dm_list *mdas);char *tags_format_and_copy (struct dm_pool *mem,const struct dm_list *tagsl);
lib/metadata/pv.c +9 -12
@@ -71,9 +71,9 @@ const struct format_type *pv_format_type(const struct physical_volume *pv)return pv_field (pv, fmt); } -struct id pv_vgid (const struct physical_volume *pv) +struct id pv_vg_id (const struct physical_volume *pv) { -return pv_field (pv, vgid); +return pv_field (pv, vg_id); }struct device *pv_dev (const struct physical_volume *pv)
@@ -171,7 +171,7 @@ uint32_t pv_mda_count(const struct physical_volume *pv) {struct lvmcache_info *info; - info =lvmcache_info_from_pvid ((const char *)&pv->id.uuid, pv->dev,0 ); + info =lvmcache_info_from_pv_id (&pv->id, pv->dev,0 );return info ?lvmcache_mda_count (info) :UINT64_C (0 ); }
@@ -191,7 +191,7 @@ uint32_t pv_mda_used_count(const struct physical_volume *pv)struct lvmcache_info *info;uint32_t used_count=0 ; - info =lvmcache_info_from_pvid ((const char *)&pv->id.uuid, pv->dev,0 ); + info =lvmcache_info_from_pv_id (&pv->id, pv->dev,0 );if (!info)return 0 ;lvmcache_foreach_mda (info, _count_unignored, &used_count);
@@ -236,7 +236,7 @@ int is_used_pv(const struct physical_volume *pv)if (!(pv->fmt->features &FMT_PV_FLAGS ))return 0 ; -if (!(info =lvmcache_info_from_pvid ((const char *)&pv->id, pv->dev,0 ))) { +if (!(info =lvmcache_info_from_pv_id (&pv->id, pv->dev,0 ))) {log_error ("Failed to find cached info for PV %s." ,pv_dev_name (pv));return -1 ; }
@@ -279,10 +279,9 @@ uint64_t pv_mda_size(const struct physical_volume *pv) {struct lvmcache_info *info;uint64_t min_mda_size =0 ; -const char *pvid = (const char *)(&pv->id.uuid);/* PVs could have 2 mdas of different sizes (rounding effect) */ -if ((info =lvmcache_info_from_pvid (pvid, pv->dev,0 ))) +if ((info =lvmcache_info_from_pv_id (&pv->id, pv->dev,0 ))) min_mda_size =lvmcache_smallest_mda_size (info);return min_mda_size; }
@@ -317,10 +316,9 @@ uint64_t lvmcache_info_mda_free(struct lvmcache_info *info)uint64_t pv_mda_free (const struct physical_volume *pv) { -const char *pvid = (const char *)&pv->id.uuid;struct lvmcache_info *info; -if ((info =lvmcache_info_from_pvid (pvid, pv->dev,0 ))) +if ((info =lvmcache_info_from_pv_id (&pv->id, pv->dev,0 )))return lvmcache_info_mda_free (info);return 0 ;
@@ -373,7 +371,7 @@ unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignorstruct _pv_mda_set_ignored_baton baton;struct metadata_area *mda; -if (!(info =lvmcache_info_from_pvid ((const char *)&pv->id.uuid, pv->dev,0 ))) +if (!(info =lvmcache_info_from_pv_id (&pv->id, pv->dev,0 ))) return_0; baton.mda_ignored = mda_ignored;
@@ -418,8 +416,7 @@ unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignorstruct label *pv_label (const struct physical_volume *pv) { -struct lvmcache_info *info = -lvmcache_info_from_pvid ((const char *)&pv->id.uuid, pv->dev,0 ); +struct lvmcache_info *info =lvmcache_info_from_pv_id (&pv->id, pv->dev,0 );if (info)return lvmcache_get_label (info);
lib/metadata/pv.h +2 -2
@@ -33,11 +33,11 @@ struct physical_volume {struct format_instance *fid;/* -* vg_name and vgid are used before the parent VG struct exists. +* vg_name and vg_id are used before the parent VG struct exists. * FIXME: Investigate removal/substitution with 'vg' fields. */ const char *vg_name; -struct id vgid; +struct id vg_id;/* variables named "vgid" are char ID_LEN+1 */ /* * 'vg' is set and maintained when the PV belongs to a 'pvs'
tools/pvchange.c +3 -1
@@ -25,6 +25,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg, {struct pvchange_params *params = (struct pvchange_params *) handle->custom_handle;const char *pv_name =pv_dev_name (pv); + char pvid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 }; char uuid[64] __attribute__((aligned(8)));struct dev_use *du =NULL ;unsigned done =0 ;
@@ -187,8 +188,9 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg, }if (du) { +memcpy (pvid, &pv->id.uuid,ID_LEN );free (du->pvid); -if (!(du->pvid =strndup ((char *)&pv->id,ID_LEN ))) +if (!(du->pvid =strdup (pvid)))log_error ("Failed to set pvid for devices file." );if (!device_ids_write (cmd))log_warn ("Failed to update devices file." );
tools/pvck.c +19 -25
134 lines not on this page · raw message
tools/pvscan.c +6 -4
@@ -517,7 +517,7 @@ static int _lookup_file_contains_pvid(FILE *fp, char *pvid)static void _lookup_file_count_pvid_files (FILE *fp,const char *vgname,int *pvs_online,int *pvs_offline) { char line[64]; -char pvid[ID_LEN +1 ] = {0 }; + char pvid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 };log_debug ("checking all pvid files using lookup file for %s" , vgname);
@@ -695,13 +695,15 @@ do_lookup:static void _count_pvid_files (struct volume_group *vg,int *pvs_online,int *pvs_offline) { + char pvid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 };struct pv_list *pvl; *pvs_online =0 ; *pvs_offline =0 ; dm_list_iterate_items(pvl, &vg->pvs) { -if (_online_pvid_file_exists ((const char *)&pvl->pv->id.uuid)) +memcpy (pvid, &pvl->pv->id.uuid,ID_LEN ); +if (_online_pvid_file_exists (pvid)) (*pvs_online)++;else (*pvs_offline)++;
@@ -793,12 +795,12 @@ static int _get_devs_from_saved_vg(struct cmd_context *cmd, const char *vgname, {char path[PATH_MAX ];char file_vgname[NAME_LEN ]; + char pvid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 }; char uuidstr[64] __attribute__((aligned(8)));struct pv_list *pvl;struct device_list *devl;struct device *dev;struct volume_group *vg; -const char *pvid;const char *name1, *name2;dev_t devno;int file_major =0 , file_minor =0 ;
@@ -814,7 +816,7 @@ static int _get_devs_from_saved_vg(struct cmd_context *cmd, const char *vgname,goto_bad ; dm_list_iterate_items(pvl, &vg->pvs) { - pvid = (const char *)&pvl->pv->id.uuid; +memcpy (pvid, &pvl->pv->id.uuid,ID_LEN );memset (path,0 ,sizeof (path));snprintf (path,sizeof (path),"%s/%s" , _pvs_online_dir, pvid);
tools/toollib.c +17 -11
@@ -3845,7 +3845,7 @@ static int _get_arg_devices(struct cmd_context *cmd,int ret_max =ECMD_PROCESSED ; dm_list_iterate_items(sl, arg_pvnames) { -if (!(dil =dm_pool_alloc (cmd->mem,sizeof (*dil)))) { +if (!(dil =dm_pool_zalloc (cmd->mem,sizeof (*dil)))) {log_error ("device_id_list alloc failed." );return ECMD_FAILED ; }
@@ -3854,7 +3854,7 @@ static int _get_arg_devices(struct cmd_context *cmd,log_error ("Cannot use %s: %s" , sl->str,devname_error_reason (sl->str)); ret_max =EINIT_FAILED ; }else { -strncpy (dil->pvid, dil->dev->pvid,ID_LEN ); +memcpy (dil->pvid, dil->dev->pvid,ID_LEN );dm_list_add (arg_devices, &dil->list); } }
@@ -3883,12 +3883,12 @@ static int _get_all_devices(struct cmd_context *cmd,if (!(dev =dev_cache_get (cmd, hint->name,NULL )))continue ; -if (!(dil =dm_pool_alloc (cmd->mem,sizeof (*dil)))) { +if (!(dil =dm_pool_zalloc (cmd->mem,sizeof (*dil)))) {log_error ("device_id_list alloc failed." );return ECMD_FAILED ; } -strncpy (dil->pvid, hint->pvid,ID_LEN ); +memcpy (dil->pvid, hint->pvid,ID_LEN ); dil->dev = dev;dm_list_add (all_devices, &dil->list); }
@@ -3903,12 +3903,12 @@ static int _get_all_devices(struct cmd_context *cmd, }while ((dev =dev_iter_get (cmd, iter))) { -if (!(dil =dm_pool_alloc (cmd->mem,sizeof (*dil)))) { +if (!(dil =dm_pool_zalloc (cmd->mem,sizeof (*dil)))) {log_error ("device_id_list alloc failed." ); goto out; } -strncpy (dil->pvid, dev->pvid,ID_LEN ); +memcpy (dil->pvid, dev->pvid,ID_LEN ); dil->dev = dev;dm_list_add (all_devices, &dil->list); }
@@ -4105,6 +4105,7 @@ static int _process_pvs_in_vg(struct cmd_context *cmd, process_single_pv_fn_t process_single_pv) { log_report_t saved_log_report_state = log_get_report_state(); + char vgid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 }; char pv_uuid[64] __attribute__((aligned(8))); char vg_uuid[64] __attribute__((aligned(8)));int handle_supplied = handle !=NULL ;
@@ -4229,8 +4230,10 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,log_set_report_object_name_and_id (NULL ,NULL ); } -if (!is_orphan_vg (vg->name)) -lvmcache_get_outdated_devs (cmd, vg->name, (const char *)&vg->id, &outdated_devs); +if (!is_orphan_vg (vg->name)) { +memcpy (vgid, &vg->id,ID_LEN ); +lvmcache_get_outdated_devs (cmd, vg->name, vgid, &outdated_devs); + } dm_list_iterate_items(devl, &outdated_devs)_device_list_remove (all_devices, devl->dev);
@@ -5239,6 +5242,7 @@ int pvcreate_each_device(struct cmd_context *cmd,struct pv_list *pvl;struct pv_list *vgpvl;struct device_list *devl; + char pvid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 };const char *pv_name;unsigned int physical_block_size, logical_block_size;unsigned int prev_pbs =0 , prev_lbs =0 ;
@@ -5411,7 +5415,7 @@ int pvcreate_each_device(struct cmd_context *cmd,*/ if (!pp->is_remove && pp->uuid_str) {struct device *dev; -if ((dev =lvmcache_device_from_pvid (cmd, &pp->pva.id,NULL ))) { +if ((dev =lvmcache_device_from_pv_id (cmd, &pp->pva.id,NULL ))) { dm_list_iterate_items_safe(pd, pd2, &pp->arg_devices) {if (pd->dev != dev) {log_error ("UUID %s already in use on \"%s\"." , pp->uuid_str,dev_name (dev));
@@ -5669,7 +5673,8 @@ do_command:dm_list_add (&pp->pvs, &pvl->list);/* allow deviceidtype_ARG/deviceid_ARG ? */ -device_id_add (cmd, pd->dev, (const char *)&pvl->pv->id.uuid,NULL ,NULL ); +memcpy (pvid, &pvl->pv->id.uuid,ID_LEN ); +device_id_add (cmd, pd->dev, pvid,NULL ,NULL ); }else {log_error ("Failed to find PV %s" , pd->name);
@@ -5708,7 +5713,8 @@ do_command: }/* allow deviceidtype_ARG/deviceid_ARG ? */ -device_id_add (cmd, pd->dev, (const char *)&pv->id.uuid,NULL ,NULL ); +memcpy (pvid, &pv->id.uuid,ID_LEN ); +device_id_add (cmd, pd->dev, pvid,NULL ,NULL );log_verbose ("Set up physical volume for \"%s\" with %" PRIu64" available sectors." , pv_name,pv_size (pv));
tools/vgimportdevices.c +6 -3
@@ -26,6 +26,7 @@ static int _vgimportdevices_single(struct cmd_context *cmd, struct processing_handle *handle) { struct vgimportdevices_params *vp = (struct vgimportdevices_params *) handle->custom_handle; + char pvid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 };struct pv_list *pvl;struct physical_volume *pv;int update_vg =1 ;
@@ -34,8 +35,9 @@ static int _vgimportdevices_single(struct cmd_context *cmd, dm_list_iterate_items(pvl, &vg->pvs) {if (is_missing_pv (pvl->pv) || !pvl->pv->dev) { -log_error ("Not importing devices for VG %s with missing PV %32s." , - vg->name, (const char *)&pvl->pv->id.uuid); +memcpy (pvid, &pvl->pv->id.uuid,ID_LEN ); +log_error ("Not importing devices for VG %s with missing PV %s." , + vg->name, pvid); goto bad; } }
@@ -58,7 +60,8 @@ static int _vgimportdevices_single(struct cmd_context *cmd,if (!idtypestr && pv->device_id_type) idtypestr = pv->device_id_type; -device_id_add (cmd, pv->dev, (const char *)&pvl->pv->id.uuid, idtypestr,NULL ); +memcpy (pvid, &pvl->pv->id.uuid,ID_LEN ); +device_id_add (cmd, pv->dev, pvid, idtypestr,NULL ); vp->added_devices++;/* We could skip update if the device_id has not changed. */
tools/vgrename.c +8 -4
@@ -40,6 +40,7 @@ static int _vgrename_single(struct cmd_context *cmd, const char *vg_name,struct vgrename_params *vp = (struct vgrename_params *) handle->custom_handle;char old_path[PATH_MAX ];char new_path[PATH_MAX ]; + char vgid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 };struct id id;const char *name;char *dev_dir;
@@ -69,10 +70,13 @@ static int _vgrename_single(struct cmd_context *cmd, const char *vg_name,return ECMD_FAILED ; } -if (id_read_format_try (&id, vp->vg_name_new) && - (name =lvmcache_vgname_from_vgid (cmd->mem, (const char *)&id))) { -log_error ("New VG name \"%s\" matches the UUID of existing VG %s" , vp->vg_name_new, name); -return ECMD_FAILED ; +if (id_read_format_try (&id, vp->vg_name_new)) { +memcpy (vgid, &id,ID_LEN ); + +if ((name =lvmcache_vgname_from_vgid (cmd->mem, vgid))) { +log_error ("New VG name \"%s\" matches the UUID of existing VG %s" , vp->vg_name_new, name); +return ECMD_FAILED ; + } }/*