diff --git a/WHATS_NEW b/WHATS_NEW index 5bc776860..2aba0ae2b 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,7 @@ Version 2.02.62 - ==================================== + Run device info query device by uuid only. + Don't touch /dev in vgmknodes if activation is disabled. Update lvm2app.h Doxygen comments and add lvm2app Doxygen config file. Update nightly tests and lvm2app unit tests to cover tags. Add lvm2app functions lvm_{vg|lv}_{get|add|remove}_tag() functions. diff --git a/lib/activate/activate.c b/lib/activate/activate.c index 433c8cced..f53b94e3b 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -440,28 +440,18 @@ int target_present(struct cmd_context *cmd, const char *target_name, /* * Returns 1 if info structure populated, else 0 on failure. */ -static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv, int with_mknodes, - struct lvinfo *info, int with_open_count, int with_read_ahead, unsigned by_uuid_only) +int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, + struct lvinfo *info, int with_open_count, int with_read_ahead) { 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))) + if (!dev_manager_info(lv->vg->cmd->mem, lv, with_open_count, + with_read_ahead, &dminfo, &info->read_ahead)) return_0; - log_debug("Getting device info for %s", name); - if (!dev_manager_info(lv->vg->cmd->mem, name, lv, with_mknodes, - with_open_count, with_read_ahead, &dminfo, - &info->read_ahead)) { - if (name) - dm_pool_free(cmd->mem, name); - return_0; - } - info->exists = dminfo.exists; info->suspended = dminfo.suspended; info->open_count = dminfo.open_count; @@ -471,18 +461,9 @@ 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); -} - int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s, struct lvinfo *info, int with_open_count, int with_read_ahead) { @@ -492,7 +473,7 @@ int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s, if (!(lv = lv_from_lvid(cmd, lvid_s, 0))) return 0; - r = _lv_info(cmd, lv, 0, info, with_open_count, with_read_ahead, 1); + r = lv_info(cmd, lv, info, with_open_count, with_read_ahead); vg_release(lv->vg); return r; @@ -558,12 +539,11 @@ int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv, return r; } -static int _lv_active(struct cmd_context *cmd, struct logical_volume *lv, - unsigned by_uuid_only) +static int _lv_active(struct cmd_context *cmd, struct logical_volume *lv) { struct lvinfo info; - if (!_lv_info(cmd, lv, 0, &info, 0, 0, by_uuid_only)) { + if (!lv_info(cmd, lv, &info, 0, 0)) { stack; return -1; } @@ -657,7 +637,7 @@ static int _lvs_in_vg_activated(struct volume_group *vg, unsigned by_uuid_only) dm_list_iterate_items(lvl, &vg->lvs) { if (lv_is_visible(lvl->lv)) - count += (_lv_active(vg->cmd, lvl->lv, by_uuid_only) == 1); + count += (_lv_active(vg->cmd, lvl->lv) == 1); } return count; @@ -700,7 +680,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)) return 1; if (!vg_is_clustered(lv->vg)) @@ -1182,7 +1162,6 @@ int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s, int exc int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv) { - struct lvinfo info; int r = 1; if (!lv) { @@ -1191,14 +1170,10 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv) return r; } - if (!_lv_info(cmd, lv, 1, &info, 0, 0, 0)) - return_0; + if (!activation()) + return 1; - if (info.exists) { - if (lv_is_visible(lv)) - r = dev_manager_lv_mknodes(lv); - } else - r = dev_manager_lv_rmnodes(lv); + r = dev_manager_mknodes(lv); fs_unlock(); diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index bbf95a367..5c5bc440f 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -127,7 +127,7 @@ static int _info_run(const char *name, const char *dlid, struct dm_info *info, dmtask = mknodes ? DM_DEVICE_MKNODES : DM_DEVICE_INFO; - if (!(dmt = _setup_task(name, dlid, 0, dmtask, major, minor))) + if (!(dmt = _setup_task(mknodes ? name : NULL, dlid, 0, dmtask, major, minor))) return_0; if (!with_open_count) @@ -205,27 +205,18 @@ int device_is_usable(dev_t dev) return r; } -static int _info(const char *name, const char *dlid, int mknodes, - int with_open_count, int with_read_ahead, +static int _info(const char *dlid, int with_open_count, int with_read_ahead, struct dm_info *info, uint32_t *read_ahead) { int r = 0; - if (!mknodes && dlid && *dlid) { - if ((r = _info_run(NULL, dlid, info, read_ahead, 0, with_open_count, - with_read_ahead, 0, 0)) && - info->exists) - return 1; - else if ((r = _info_run(NULL, dlid + sizeof(UUID_PREFIX) - 1, info, - read_ahead, 0, with_open_count, - with_read_ahead, 0, 0)) && - info->exists) - return 1; - } - - if (name) - return _info_run(name, NULL, info, read_ahead, mknodes, - with_open_count, with_read_ahead, 0, 0); + if ((r = _info_run(NULL, dlid, info, read_ahead, 0, with_open_count, + with_read_ahead, 0, 0)) && info->exists) + return 1; + else if ((r = _info_run(NULL, dlid + sizeof(UUID_PREFIX) - 1, info, + read_ahead, 0, with_open_count, + with_read_ahead, 0, 0)) && info->exists) + return 1; return r; } @@ -235,20 +226,28 @@ 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 dev_manager_info(struct dm_pool *mem, const struct logical_volume *lv, int with_open_count, int with_read_ahead, struct dm_info *info, uint32_t *read_ahead) { - 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 [%s]", name, dlid); + r = _info(dlid, 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, @@ -744,7 +743,7 @@ static int _belong_to_vg(const char *vgname, const char *name) /* NEW CODE STARTS HERE */ /*************************/ -int dev_manager_lv_mknodes(const struct logical_volume *lv) +static int _dev_manager_lv_mknodes(const struct logical_volume *lv) { char *name; @@ -755,11 +754,32 @@ int dev_manager_lv_mknodes(const struct logical_volume *lv) return fs_add_lv(lv, name); } -int dev_manager_lv_rmnodes(const struct logical_volume *lv) +static int _dev_manager_lv_rmnodes(const struct logical_volume *lv) { return fs_del_lv(lv); } +int dev_manager_mknodes(const struct logical_volume *lv) +{ + struct dm_info dminfo; + const char *name; + int r = 0; + + if (!(name = build_dm_name(lv->vg->cmd->mem, lv->vg->name, lv->name, NULL))) + return_0; + + if ((r = _info_run(name, NULL, &dminfo, NULL, 1, 0, 0, 0, 0))) { + if (dminfo.exists) { + if (lv_is_visible(lv)) + r = _dev_manager_lv_mknodes(lv); + } else + r = _dev_manager_lv_rmnodes(lv); + } + + dm_pool_free(lv->vg->cmd->mem, (char*)name); + return r; +} + static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree, struct logical_volume *lv, const char *layer) { @@ -774,7 +794,7 @@ static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree, return_0; log_debug("Getting device info for %s [%s]", name, dlid); - if (!_info(name, dlid, 0, 1, 0, &info, NULL)) { + if (!_info(dlid, 1, 0, &info, NULL)) { log_error("Failed to get info for %s [%s].", name, dlid); return 0; } @@ -1309,11 +1329,11 @@ static int _create_lv_symlinks(struct dev_manager *dm, struct dm_tree_node *root continue; } if (lv_is_visible(lvlayer->lv)) { - if (!dev_manager_lv_mknodes(lvlayer->lv)) + if (!_dev_manager_lv_mknodes(lvlayer->lv)) r = 0; continue; } - if (!dev_manager_lv_rmnodes(lvlayer->lv)) + if (!_dev_manager_lv_rmnodes(lvlayer->lv)) r = 0; } diff --git a/lib/activate/dev_manager.h b/lib/activate/dev_manager.h index 5333544e2..e946aafb8 100644 --- a/lib/activate/dev_manager.h +++ b/lib/activate/dev_manager.h @@ -40,9 +40,8 @@ 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 mknodes, int with_open_count, int with_read_ahead, +int dev_manager_info(struct dm_pool *mem, const struct logical_volume *lv, + int with_open_count, int with_read_ahead, struct dm_info *info, uint32_t *read_ahead); int dev_manager_snapshot_percent(struct dev_manager *dm, const struct logical_volume *lv, @@ -59,8 +58,7 @@ int dev_manager_preload(struct dev_manager *dm, struct logical_volume *lv, int *flush_required); int dev_manager_deactivate(struct dev_manager *dm, struct logical_volume *lv); -int dev_manager_lv_mknodes(const struct logical_volume *lv); -int dev_manager_lv_rmnodes(const struct logical_volume *lv); +int dev_manager_mknodes(const struct logical_volume *lv); /* * Put the desired changes into effect.