mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
device_id: more use of device_get_uuid
Use function that is caching UUID if kernel provides functionality from a single ioctl() call.
This commit is contained in:
parent
fffff2c2a2
commit
13e0222ba2
@ -25,6 +25,8 @@
|
|||||||
#include "lib/cache/lvmcache.h"
|
#include "lib/cache/lvmcache.h"
|
||||||
#include "lib/datastruct/str_list.h"
|
#include "lib/datastruct/str_list.h"
|
||||||
#include "lib/metadata/metadata-exported.h"
|
#include "lib/metadata/metadata-exported.h"
|
||||||
|
#include "lib/activate/activate.h"
|
||||||
|
#include "device_mapper/misc/dm-ioctl.h"
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -506,18 +508,19 @@ static int _dm_uuid_has_prefix(char *sysbuf, const char *prefix)
|
|||||||
/* the dm uuid uses the wwid of the underlying dev */
|
/* the dm uuid uses the wwid of the underlying dev */
|
||||||
int dev_has_mpath_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out)
|
int dev_has_mpath_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out)
|
||||||
{
|
{
|
||||||
char sysbuf[PATH_MAX] = { 0 };
|
|
||||||
|
char uuid[DM_UUID_LEN];
|
||||||
const char *idname;
|
const char *idname;
|
||||||
|
|
||||||
if (!read_sys_block(cmd, dev, "dm/uuid", sysbuf, sizeof(sysbuf)))
|
if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), uuid, sizeof(uuid)))
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
if (!_dm_uuid_has_prefix(sysbuf, "mpath-"))
|
if (!_dm_uuid_has_prefix(uuid, "mpath-"))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!idname_out)
|
if (!idname_out)
|
||||||
return 1;
|
return 1;
|
||||||
if (!(idname = strdup(sysbuf)))
|
if (!(idname = strdup(uuid)))
|
||||||
return_0;
|
return_0;
|
||||||
*idname_out = idname;
|
*idname_out = idname;
|
||||||
return 1;
|
return 1;
|
||||||
@ -525,18 +528,18 @@ int dev_has_mpath_uuid(struct cmd_context *cmd, struct device *dev, const char *
|
|||||||
|
|
||||||
static int _dev_has_crypt_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out)
|
static int _dev_has_crypt_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out)
|
||||||
{
|
{
|
||||||
char sysbuf[PATH_MAX] = { 0 };
|
char uuid[DM_UUID_LEN];
|
||||||
const char *idname;
|
const char *idname;
|
||||||
|
|
||||||
if (!read_sys_block(cmd, dev, "dm/uuid", sysbuf, sizeof(sysbuf)))
|
if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), uuid, sizeof(uuid)))
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
if (!_dm_uuid_has_prefix(sysbuf, "CRYPT-"))
|
if (!_dm_uuid_has_prefix(uuid, "CRYPT-"))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!idname_out)
|
if (!idname_out)
|
||||||
return 1;
|
return 1;
|
||||||
if (!(idname = strdup(sysbuf)))
|
if (!(idname = strdup(uuid)))
|
||||||
return_0;
|
return_0;
|
||||||
*idname_out = idname;
|
*idname_out = idname;
|
||||||
return 1;
|
return 1;
|
||||||
@ -544,18 +547,18 @@ static int _dev_has_crypt_uuid(struct cmd_context *cmd, struct device *dev, cons
|
|||||||
|
|
||||||
static int _dev_has_lvmlv_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out)
|
static int _dev_has_lvmlv_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out)
|
||||||
{
|
{
|
||||||
char sysbuf[PATH_MAX] = { 0 };
|
char uuid[DM_UUID_LEN];
|
||||||
const char *idname;
|
const char *idname;
|
||||||
|
|
||||||
if (!read_sys_block(cmd, dev, "dm/uuid", sysbuf, sizeof(sysbuf)))
|
if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), uuid, sizeof(uuid)))
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
if (!_dm_uuid_has_prefix(sysbuf, "LVM-"))
|
if (!_dm_uuid_has_prefix(uuid, UUID_PREFIX))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!idname_out)
|
if (!idname_out)
|
||||||
return 1;
|
return 1;
|
||||||
if (!(idname = strdup(sysbuf)))
|
if (!(idname = strdup(uuid)))
|
||||||
return_0;
|
return_0;
|
||||||
*idname_out = idname;
|
*idname_out = idname;
|
||||||
return 1;
|
return 1;
|
||||||
@ -773,49 +776,36 @@ const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, u
|
|||||||
struct dev_wwid *dw;
|
struct dev_wwid *dw;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
if (idtype == DEV_ID_TYPE_SYS_WWID)
|
switch (idtype) {
|
||||||
|
case DEV_ID_TYPE_SYS_WWID:
|
||||||
dev_read_sys_wwid(cmd, dev, sysbuf, sizeof(sysbuf), NULL);
|
dev_read_sys_wwid(cmd, dev, sysbuf, sizeof(sysbuf), NULL);
|
||||||
|
break;
|
||||||
else if (idtype == DEV_ID_TYPE_SYS_SERIAL)
|
case DEV_ID_TYPE_SYS_SERIAL:
|
||||||
_dev_read_sys_serial(cmd, dev, sysbuf, sizeof(sysbuf));
|
_dev_read_sys_serial(cmd, dev, sysbuf, sizeof(sysbuf));
|
||||||
|
break;
|
||||||
else if (idtype == DEV_ID_TYPE_MPATH_UUID) {
|
case DEV_ID_TYPE_MPATH_UUID:
|
||||||
read_sys_block(cmd, dev, "dm/uuid", sysbuf, sizeof(sysbuf));
|
case DEV_ID_TYPE_CRYPT_UUID:
|
||||||
/* if (strncmp(sysbuf, "mpath", 5)) sysbuf[0] = '\0'; */
|
case DEV_ID_TYPE_LVMLV_UUID:
|
||||||
}
|
(void)device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), sysbuf, sizeof(sysbuf));
|
||||||
|
break;
|
||||||
else if (idtype == DEV_ID_TYPE_CRYPT_UUID) {
|
case DEV_ID_TYPE_MD_UUID:
|
||||||
read_sys_block(cmd, dev, "dm/uuid", sysbuf, sizeof(sysbuf));
|
|
||||||
/* if (strncmp(sysbuf, "CRYPT", 5)) sysbuf[0] = '\0'; */
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (idtype == DEV_ID_TYPE_LVMLV_UUID) {
|
|
||||||
read_sys_block(cmd, dev, "dm/uuid", sysbuf, sizeof(sysbuf));
|
|
||||||
/* if (strncmp(sysbuf, "LVM", 3)) sysbuf[0] = '\0'; */
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (idtype == DEV_ID_TYPE_MD_UUID) {
|
|
||||||
read_sys_block(cmd, dev, "md/uuid", sysbuf, sizeof(sysbuf));
|
read_sys_block(cmd, dev, "md/uuid", sysbuf, sizeof(sysbuf));
|
||||||
}
|
break;
|
||||||
|
case DEV_ID_TYPE_LOOP_FILE:
|
||||||
else if (idtype == DEV_ID_TYPE_LOOP_FILE) {
|
|
||||||
read_sys_block(cmd, dev, "loop/backing_file", sysbuf, sizeof(sysbuf));
|
read_sys_block(cmd, dev, "loop/backing_file", sysbuf, sizeof(sysbuf));
|
||||||
/* if backing file is deleted, fall back to devname */
|
/* if backing file is deleted, fall back to devname */
|
||||||
if (strstr(sysbuf, "(deleted)"))
|
if (strstr(sysbuf, "(deleted)"))
|
||||||
sysbuf[0] = '\0';
|
sysbuf[0] = '\0';
|
||||||
}
|
break;
|
||||||
|
case DEV_ID_TYPE_DEVNAME:
|
||||||
else if (idtype == DEV_ID_TYPE_DEVNAME) {
|
|
||||||
if (dm_list_empty(&dev->aliases))
|
if (dm_list_empty(&dev->aliases))
|
||||||
goto_bad;
|
goto_bad;
|
||||||
if (!(idname = strdup(dev_name(dev))))
|
if (!(idname = strdup(dev_name(dev))))
|
||||||
goto_bad;
|
goto_bad;
|
||||||
return idname;
|
return idname;
|
||||||
}
|
case DEV_ID_TYPE_WWID_NAA:
|
||||||
|
case DEV_ID_TYPE_WWID_EUI:
|
||||||
else if (idtype == DEV_ID_TYPE_WWID_NAA ||
|
case DEV_ID_TYPE_WWID_T10:
|
||||||
idtype == DEV_ID_TYPE_WWID_EUI ||
|
|
||||||
idtype == DEV_ID_TYPE_WWID_T10) {
|
|
||||||
if (!(dev->flags & DEV_ADDED_VPD_WWIDS))
|
if (!(dev->flags & DEV_ADDED_VPD_WWIDS))
|
||||||
dev_read_vpd_wwids(cmd, dev);
|
dev_read_vpd_wwids(cmd, dev);
|
||||||
dm_list_iterate_items(dw, &dev->wwids) {
|
dm_list_iterate_items(dw, &dev->wwids) {
|
||||||
@ -1015,7 +1005,7 @@ static int _dev_has_stable_id(struct cmd_context *cmd, struct device *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((MAJOR(dev->dev) == cmd->dev_types->device_mapper_major)) {
|
if ((MAJOR(dev->dev) == cmd->dev_types->device_mapper_major)) {
|
||||||
if (!read_sys_block(cmd, dev, "dm/uuid", sysbuf, sizeof(sysbuf)))
|
if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), sysbuf, sizeof(sysbuf)))
|
||||||
goto_out;
|
goto_out;
|
||||||
|
|
||||||
if (_dm_uuid_has_prefix(sysbuf, "mpath-"))
|
if (_dm_uuid_has_prefix(sysbuf, "mpath-"))
|
||||||
|
Loading…
Reference in New Issue
Block a user