[RFC] Always query device by uuid only in activation calls. lvm2 devices have always UUID set even if imported from lvm1 metadata. Why not use query by UUID only always? --- lib/activate/activate.c | 20 +++------------- lib/activate/dev_manager.c | 51 ++++++++++++++++++++++++++++++++----------- lib/activate/dev_manager.h | 6 ++-- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/lib/activate/activate.c b/lib/activate/activate.c index 433c8cc..c37b036 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -444,23 +444,14 @@ static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv, in struct lvinfo *info, int with_open_count, int with_read_ahead, unsigned by_uuid_only) { struct dm_info dminfo; - char *name = NULL; if (!activation()) return 0; - if (!by_uuid_only && - !(name = build_dm_name(cmd->mem, lv->vg->name, lv->name, NULL))) - return_0; - - log_debug("Getting device info for %s", name); - if (!dev_manager_info(lv->vg->cmd->mem, name, lv, with_mknodes, + if (!dev_manager_info(lv->vg->cmd->mem, lv, with_mknodes, with_open_count, with_read_ahead, &dminfo, - &info->read_ahead)) { - if (name) - dm_pool_free(cmd->mem, name); + &info->read_ahead, by_uuid_only)) return_0; - } info->exists = dminfo.exists; info->suspended = dminfo.suspended; @@ -471,16 +462,13 @@ static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv, in info->live_table = dminfo.live_table; info->inactive_table = dminfo.inactive_table; - if (name) - dm_pool_free(cmd->mem, name); - return 1; } int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, struct lvinfo *info, int with_open_count, int with_read_ahead) { - return _lv_info(cmd, lv, 0, info, with_open_count, with_read_ahead, 0); + return _lv_info(cmd, lv, 0, info, with_open_count, with_read_ahead, 1); } int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s, @@ -700,7 +688,7 @@ int lv_is_active(struct logical_volume *lv) { int ret; - if (_lv_active(lv->vg->cmd, lv, 0)) + if (_lv_active(lv->vg->cmd, lv, 1)) return 1; if (!vg_is_clustered(lv->vg)) diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index 23cea2e..ae39953 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -122,13 +122,16 @@ static int _info_run(const char *name, const char *dlid, struct dm_info *info, int with_read_ahead, uint32_t major, uint32_t minor) { int r = 0; + const char *dmname; struct dm_task *dmt; - int dmtask; - dmtask = mknodes ? DM_DEVICE_MKNODES : DM_DEVICE_INFO; - - if (!(dmt = _setup_task(name, dlid, 0, dmtask, major, minor))) - return_0; + if (mknodes) { + if (!(dmt = _setup_task(name, dlid, 0, DM_DEVICE_MKNODES, major, minor))) + return_0; + } else { + if (!(dmt = _setup_task(NULL, dlid, 0, DM_DEVICE_INFO, major, minor))) + return_0; + } if (!with_open_count) if (!dm_task_no_open_count(dmt)) @@ -148,7 +151,13 @@ static int _info_run(const char *name, const char *dlid, struct dm_info *info, r = 1; - out: + if (!mknodes && name && info->exists && + (dmname = dm_task_get_name(dmt)) && strcmp(dmname, name)) { + log_error("Internal error: Device with UUID %s should have name %s but in-kernel is set %s.", + dlid, name, dmname); + //r = 0; + } +out: dm_task_destroy(dmt); return r; } @@ -235,20 +244,36 @@ static int _info_by_dev(uint32_t major, uint32_t minor, struct dm_info *info) return _info_run(NULL, NULL, info, NULL, 0, 0, 0, major, minor); } -int dev_manager_info(struct dm_pool *mem, const char *name, - const struct logical_volume *lv, int with_mknodes, - int with_open_count, int with_read_ahead, - struct dm_info *info, uint32_t *read_ahead) +int dev_manager_info(struct dm_pool *mem, const struct logical_volume *lv, + int with_mknodes, int with_open_count, int with_read_ahead, + struct dm_info *info, uint32_t *read_ahead, + int by_uuid_only) { - const char *dlid; + const char *dlid, *name; + int r; + + if (!(name = build_dm_name(mem, lv->vg->name, lv->name, NULL))) { + log_error("name build failed for %s", lv->name); + return 0; + } if (!(dlid = _build_dlid(mem, lv->lvid.s, NULL))) { log_error("dlid build failed for %s", lv->name); return 0; } - return _info(name, dlid, with_mknodes, with_open_count, with_read_ahead, - info, read_ahead); + log_debug("Getting device info for %s", name); + if (by_uuid_only) + r = _info(NULL, dlid, with_mknodes, with_open_count, + with_read_ahead, info, read_ahead); + else { + log_error("QUERY BY NAME %s", name); + r = _info(name, dlid, with_mknodes, with_open_count, + with_read_ahead, info, read_ahead); + } + + dm_pool_free(mem, (char*)name); + return r; } static const struct dm_info *_cached_info(struct dm_pool *mem, diff --git a/lib/activate/dev_manager.h b/lib/activate/dev_manager.h index 5333544..5e04425 100644 --- a/lib/activate/dev_manager.h +++ b/lib/activate/dev_manager.h @@ -40,10 +40,10 @@ void dev_manager_exit(void); * (eg, an origin is created before its snapshot, but is not * unsuspended until the snapshot is also created.) */ -int dev_manager_info(struct dm_pool *mem, const char *name, - const struct logical_volume *lv, +int dev_manager_info(struct dm_pool *mem, const struct logical_volume *lv, int mknodes, int with_open_count, int with_read_ahead, - struct dm_info *info, uint32_t *read_ahead); + struct dm_info *info, uint32_t *read_ahead, + int by_uuid_only); int dev_manager_snapshot_percent(struct dev_manager *dm, const struct logical_volume *lv, float *percent,