From 92fd2cb498e88436c201a4f2ea833265cb107885 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 2 Jul 2024 15:07:43 -0500 Subject: [PATCH] devices: isolate fake dev use for mirror checks Freeing dev-cache from dumb fake device usage. --- lib/activate/dev_manager.c | 19 ++++++++++++------- lib/device/dev-cache.c | 6 +++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index 50cfe614a..c2d857231 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -448,8 +448,9 @@ static int _ignore_blocked_mirror_devices(struct cmd_context *cmd, void *next = NULL; struct dm_task *dmt = NULL; int r = 0; - struct device *tmp_dev; - char buf[16]; + char fake_dev_name[16]; + struct device fake_dev = { 0 }; + struct dm_str_list *alias; if (!(mem = dm_pool_create("blocked_mirrors", 128))) return_0; @@ -470,16 +471,20 @@ static int _ignore_blocked_mirror_devices(struct cmd_context *cmd, dev_name(dev)); check_for_blocking = 1; } else { - - if (dm_snprintf(buf, sizeof(buf), "%u:%u", + dev_init(&fake_dev); + if (dm_snprintf(fake_dev_name, sizeof(fake_dev_name), "%u:%u", sm->logs[0].major, sm->logs[0].minor) < 0) goto_out; - if (!(tmp_dev = dev_create_file(buf, NULL, NULL, 0))) + if (!(alias = dm_pool_zalloc(mem, sizeof(*alias)))) + goto_out; + if (!(alias->str = dm_pool_strdup(mem, fake_dev_name))) goto_out; + dm_list_add(&fake_dev.aliases, &alias->list); + fake_dev.flags = DEV_REGULAR; + fake_dev.dev = MKDEV(sm->logs[0].major, sm->logs[0].minor); - tmp_dev->dev = MKDEV(sm->logs[0].major, sm->logs[0].minor); - if (dm_device_is_usable(cmd, tmp_dev, (struct dev_usable_check_params) + if (dm_device_is_usable(cmd, &fake_dev, (struct dev_usable_check_params) { .check_empty = 1, .check_blocked = 1, .check_suspended = ignore_suspended_devices(), diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index 034794c73..a36ed9775 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -78,7 +78,7 @@ static int _insert(const char *path, const struct stat *info, int rec, int check_with_udev_db); /* Setup non-zero members of passed zeroed 'struct device' */ -static void _dev_init(struct device *dev) +void dev_init(struct device *dev) { dev->fd = -1; dev->bcache_fd = -1; @@ -147,7 +147,7 @@ struct device *dev_create_file(const char *filename, struct device *dev, return NULL; } - _dev_init(dev); + dev_init(dev); dev->flags = DEV_REGULAR | ((use_malloc) ? DEV_ALLOCED : 0); dm_list_add(&dev->aliases, &alias->list); @@ -163,7 +163,7 @@ static struct device *_dev_create(dev_t d) return NULL; } - _dev_init(dev); + dev_init(dev); dev->dev = d; return dev; -- 2.43.5