mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-30 17:18:21 +03:00
device: use device_get_uuid
Replace call to get_dm_uuid_from_sysfs() with use of device_get_uuid() which gets the same information, but instead of several syscalls it need either 1 or even 0 when the information is cached with newer kernels.
This commit is contained in:
parent
b63e54d0ed
commit
01e014a246
@ -21,6 +21,7 @@
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/commands/toolcontext.h"
|
||||
#include "device_mapper/misc/dm-ioctl.h"
|
||||
#include "lib/activate/activate.h"
|
||||
#include "lib/misc/lvm-string.h"
|
||||
|
||||
#ifdef UDEV_SYNC_SUPPORT
|
||||
@ -453,18 +454,6 @@ out:
|
||||
return r;
|
||||
}
|
||||
|
||||
int get_dm_uuid_from_sysfs(char *buf, size_t buf_size, int major, int minor)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
|
||||
if (dm_snprintf(path, sizeof(path), "%sdev/block/%d:%d/dm/uuid", dm_sysfs_dir(), major, minor) < 0) {
|
||||
log_error("%d:%d: dm_snprintf failed for path to sysfs dm directory.", major, minor);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_sysfs_value(path, buf, buf_size, 0);
|
||||
}
|
||||
|
||||
static struct dm_list *_get_or_add_list_by_index_key(struct dm_hash_table *idx, const char *key)
|
||||
{
|
||||
struct dm_list *list;
|
||||
@ -574,7 +563,7 @@ static int _get_vgid_and_lvid_for_dev(struct cmd_context *cmd, struct device *de
|
||||
char uuid[DM_UUID_LEN];
|
||||
size_t uuid_len;
|
||||
|
||||
if (!get_dm_uuid_from_sysfs(uuid, sizeof(uuid), (int) MAJOR(dev->dev), (int) MINOR(dev->dev)))
|
||||
if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), uuid, sizeof(uuid)))
|
||||
return_0;
|
||||
|
||||
uuid_len = strlen(uuid);
|
||||
|
@ -76,7 +76,6 @@ bool dev_cache_has_md_with_end_superblock(struct dev_types *dt);
|
||||
|
||||
int get_sysfs_value(const char *path, char *buf, size_t buf_size, int error_if_no_value);
|
||||
int get_sysfs_binary(const char *path, char *buf, size_t buf_size, int *retlen);
|
||||
int get_dm_uuid_from_sysfs(char *buf, size_t buf_size, int major, int minor);
|
||||
|
||||
int setup_devices_file(struct cmd_context *cmd);
|
||||
int setup_devices(struct cmd_context *cmd);
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "lib/device/bcache.h"
|
||||
#include "lib/label/label.h"
|
||||
#include "lib/commands/toolcontext.h"
|
||||
#include "lib/activate/activate.h"
|
||||
#include "device_mapper/misc/dm-ioctl.h"
|
||||
|
||||
#ifdef BLKID_WIPING_SUPPORT
|
||||
@ -52,31 +53,14 @@ int dev_is_nvme(struct dev_types *dt, struct device *dev)
|
||||
|
||||
int dev_is_lv(struct cmd_context *cmd, struct device *dev)
|
||||
{
|
||||
FILE *fp;
|
||||
char path[PATH_MAX];
|
||||
char buffer[64];
|
||||
int ret = 0;
|
||||
char buffer[128];
|
||||
|
||||
if (dm_snprintf(path, sizeof(path), "%sdev/block/%d:%d/dm/uuid",
|
||||
dm_sysfs_dir(),
|
||||
(int) MAJOR(dev->dev),
|
||||
(int) MINOR(dev->dev)) < 0) {
|
||||
log_warn("Sysfs dm uuid path for %s is too long.", dev_name(dev));
|
||||
return 0;
|
||||
}
|
||||
if (device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev),
|
||||
buffer, sizeof(buffer)) &&
|
||||
!strncmp(buffer, UUID_PREFIX, sizeof(UUID_PREFIX) - 1))
|
||||
return 1;
|
||||
|
||||
if (!(fp = fopen(path, "r")))
|
||||
return 0;
|
||||
|
||||
if (!fgets(buffer, sizeof(buffer), fp))
|
||||
log_debug("Failed to read %s.", path);
|
||||
else if (!strncmp(buffer, "LVM-", 4))
|
||||
ret = 1;
|
||||
|
||||
if (fclose(fp))
|
||||
log_sys_debug("fclose", path);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dev_is_used_by_active_lv(struct cmd_context *cmd, struct device *dev, int *used_by_lv_count,
|
||||
@ -140,14 +124,10 @@ int dev_is_used_by_active_lv(struct cmd_context *cmd, struct device *dev, int *u
|
||||
|
||||
/*
|
||||
* if "dm-1" is a dm device, then check if it's an LVM LV
|
||||
* by reading /sys/block/<holder_name>/dm/uuid and seeing
|
||||
* if the uuid begins with LVM-
|
||||
* UUID_PREFIX is "LVM-"
|
||||
* by reading DM status and seeing if the uuid begins
|
||||
* with UUID_PREFIX ("LVM-")
|
||||
*/
|
||||
|
||||
dm_uuid[0] = '\0';
|
||||
|
||||
if (!get_dm_uuid_from_sysfs(dm_uuid, sizeof(dm_uuid), dm_dev_major, dm_dev_minor))
|
||||
if (!device_get_uuid(cmd, dm_dev_major, dm_dev_minor, dm_uuid, sizeof(dm_uuid)))
|
||||
continue;
|
||||
|
||||
if (!strncmp(dm_uuid, UUID_PREFIX, 4))
|
||||
|
@ -869,7 +869,7 @@ static void _get_rootvg_dev(struct cmd_context *cmd, char **dm_uuid_out)
|
||||
if (stat(me->mnt_dir, &info) < 0)
|
||||
return;
|
||||
|
||||
if (!get_dm_uuid_from_sysfs(dm_uuid, sizeof(dm_uuid), (int)MAJOR(info.st_dev), (int)MINOR(info.st_dev)))
|
||||
if (!device_get_uuid(cmd, MAJOR(info.st_dev), MINOR(info.st_dev), dm_uuid, sizeof(dm_uuid)))
|
||||
return;
|
||||
|
||||
log_debug("Found root dm_uuid %s", dm_uuid);
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "lib/cache/lvmcache.h"
|
||||
#include "lib/device/device_id.h"
|
||||
#include "device_mapper/misc/dm-ioctl.h"
|
||||
#include "lib/activate/activate.h"
|
||||
/* coverity[unnecessary_header] needed for MuslC */
|
||||
#include <sys/file.h>
|
||||
#include <mntent.h>
|
||||
@ -151,14 +152,14 @@ static int _get_rootvg_dev(struct cmd_context *cmd, char **dm_uuid_out, int *ski
|
||||
if (stat(me->mnt_dir, &info) < 0)
|
||||
return_0;
|
||||
|
||||
if (!get_dm_uuid_from_sysfs(dm_uuid, sizeof(dm_uuid), (int)MAJOR(info.st_dev), (int)MINOR(info.st_dev)))
|
||||
if (!device_get_uuid(cmd, MAJOR(info.st_dev), MINOR(info.st_dev), dm_uuid, sizeof(dm_uuid)))
|
||||
return_0;
|
||||
|
||||
/* UUID_PREFIX = "LVM-" */
|
||||
if (strncmp(dm_uuid, UUID_PREFIX, 4))
|
||||
if (strncmp(dm_uuid, UUID_PREFIX, sizeof(UUID_PREFIX) - 1))
|
||||
return_0;
|
||||
|
||||
if (strlen(dm_uuid) < 4 + ID_LEN)
|
||||
if (strlen(dm_uuid) < sizeof(UUID_PREFIX) - 1 + ID_LEN)
|
||||
return_0;
|
||||
|
||||
*dm_uuid_out = dm_pool_strdup(cmd->mem, dm_uuid);
|
||||
|
Loading…
Reference in New Issue
Block a user