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

lvmdevices: use deviceidtype option strictly

Only use the device id type specified by --deviceidtype,
and fail if that type is not available for the device.
This commit is contained in:
David Teigland 2022-09-15 09:45:21 -05:00
parent c4e6d675de
commit 13c63f0cfa
6 changed files with 20 additions and 11 deletions

View File

@ -1140,7 +1140,7 @@ struct dev_use *get_du_for_device_id(struct cmd_context *cmd, uint16_t idtype, c
* . add or update entry in cmd->use_devices
*/
int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_arg,
const char *idtype_arg, const char *id_arg)
const char *idtype_arg, const char *id_arg, int use_idtype_only)
{
char pvid[ID_LEN+1] = { 0 };
uint16_t idtype = 0;
@ -1194,9 +1194,13 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
*/
if (idtype_arg) {
if (!(idtype = idtype_from_str(idtype_arg)))
if (!(idtype = idtype_from_str(idtype_arg))) {
if (use_idtype_only) {
log_error("The specified --deviceidtype %s is unknown.", idtype_arg);
return 0;
}
log_warn("WARNING: ignoring unknown device_id type %s.", idtype_arg);
else {
} else {
if (id_arg) {
if ((idname = strdup(id_arg)))
goto id_done;
@ -1206,6 +1210,11 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
if ((idname = device_id_system_read(cmd, dev, idtype)))
goto id_done;
if (use_idtype_only) {
log_error("The specified --deviceidtype %s is not available for %s.", idtype_arg, dev_name(dev));
return 0;
}
log_warn("WARNING: ignoring deviceidtype %s which is not available for device.", idtype_arg);
idtype = 0;
}

View File

@ -28,7 +28,7 @@ int device_ids_use_devname(struct cmd_context *cmd);
int device_ids_read(struct cmd_context *cmd);
int device_ids_write(struct cmd_context *cmd);
int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid,
const char *idtype_arg, const char *id_arg);
const char *idtype_arg, const char *id_arg, int use_idtype_only);
void device_id_pvremove(struct cmd_context *cmd, struct device *dev);
void device_ids_match(struct cmd_context *cmd);
int device_ids_match_dev(struct cmd_context *cmd, struct device *dev);

View File

@ -264,7 +264,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
if (update_set) {
log_print("Adding multipath device %s for multipath component %s.",
dev_name(mpath_dev), dev_name(du->dev));
if (!device_id_add(cmd, mpath_dev, dev->pvid, NULL, NULL))
if (!device_id_add(cmd, mpath_dev, dev->pvid, NULL, NULL, 0))
stack;
} else {
log_print("Missing multipath device %s for multipath component %s.",
@ -360,7 +360,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
/* also allow deviceid_ARG ? */
deviceidtype = arg_str_value(cmd, deviceidtype_ARG, NULL);
if (!device_id_add(cmd, dev, dev->pvid, deviceidtype, NULL))
if (!device_id_add(cmd, dev, dev->pvid, deviceidtype, NULL, 1))
goto_bad;
if (!device_ids_write(cmd))
goto_bad;
@ -408,7 +408,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
}
dm_list_iterate_items(devl, &found_devs) {
deviceidtype = arg_str_value(cmd, deviceidtype_ARG, NULL);
if (!device_id_add(cmd, devl->dev, devl->dev->pvid, deviceidtype, NULL))
if (!device_id_add(cmd, devl->dev, devl->dev->pvid, deviceidtype, NULL, 1))
goto_bad;
}
if (!device_ids_write(cmd))

View File

@ -5833,7 +5833,7 @@ do_command:
/* allow deviceidtype_ARG/deviceid_ARG ? */
memcpy(pvid, &pvl->pv->id.uuid, ID_LEN);
device_id_add(cmd, pd->dev, pvid, NULL, NULL);
device_id_add(cmd, pd->dev, pvid, NULL, NULL, 0);
} else {
log_error("Failed to find PV %s", pd->name);
@ -5873,7 +5873,7 @@ do_command:
/* allow deviceidtype_ARG/deviceid_ARG ? */
memcpy(pvid, &pv->id.uuid, ID_LEN);
device_id_add(cmd, pd->dev, pvid, NULL, NULL);
device_id_add(cmd, pd->dev, pvid, NULL, NULL, 0);
log_verbose("Set up physical volume for \"%s\" with %" PRIu64
" available sectors.", pv_name, pv_size(pv));

View File

@ -162,7 +162,7 @@ static int _update_vg(struct cmd_context *cmd, struct volume_group *vg,
*/
if (vp->import_devices || cmd->enable_devices_file) {
dm_list_iterate_items(devl, &vp->new_devs) {
if (!device_id_add(cmd, devl->dev, devl->dev->pvid, NULL, NULL)) {
if (!device_id_add(cmd, devl->dev, devl->dev->pvid, NULL, NULL, 0)) {
log_error("Failed to add device id for %s.", dev_name(devl->dev));
goto bad;
}

View File

@ -60,7 +60,7 @@ static int _vgimportdevices_single(struct cmd_context *cmd,
idtypestr = pv->device_id_type;
memcpy(pvid, &pvl->pv->id.uuid, ID_LEN);
device_id_add(cmd, pv->dev, pvid, idtypestr, NULL);
device_id_add(cmd, pv->dev, pvid, idtypestr, NULL, 0);
vp->added_devices++;
/* We could skip update if the device_id has not changed. */