]> sourceware.org Git - lvm2.git/commitdiff
devices: isolate fake dev use for mirror checks
authorDavid Teigland <teigland@redhat.com>
Tue, 2 Jul 2024 20:07:43 +0000 (15:07 -0500)
committerDavid Teigland <teigland@redhat.com>
Tue, 2 Jul 2024 20:07:43 +0000 (15:07 -0500)
Freeing dev-cache from dumb fake device usage.

lib/activate/dev_manager.c
lib/device/dev-cache.c

index 50cfe614a569660929909366def670be157b2b0c..c2d857231f90eda00bdf36d4ab532861b2340702 100644 (file)
@@ -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(),
index 034794c7311ec5f01b4032e3356f22ce5e1588a0..a36ed9775d6a9c77bbef222784d306fef64582be 100644 (file)
@@ -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;
This page took 0.039444 seconds and 5 git commands to generate.