#include <limits.h>
#include <dirent.h>
-#include <sys/utsname.h>
#define MAX_TARGET_PARAMSIZE 50000
#define LVM_UDEV_NOSCAN_FLAG DM_SUBSYSTEM_UDEV_FLAG0
return r;
}
-/* Returns 1 for kernels >= 3.X, otherwise 0 */
-static int _check_new_kernel(void)
+/*
+ * If active LVs were activated by a version of LVM2 before 2.02.00 we must
+ * perform additional checks to find them because they do not have the LVM-
+ * prefix on their dm uuids.
+ * As of 2.02.150, we've chosen to disable this compatibility arbitrarily if
+ * we're running kernel version 3 or above.
+ */
+#define MIN_KERNEL_MAJOR 3
+
+static int _original_uuid_format_check_required(struct cmd_context *cmd)
{
- static int major = 0;
- struct utsname _uts;
+ static int _kernel_major = 0;
- if (!major) {
- if (uname(&_uts) ||
- (sscanf(_uts.release, "%d", &major) != 1))
- major = 1;
- else if (major >= 3)
- log_debug("Not checking for devices without prefix "
- UUID_PREFIX " with newer kernel.");
+ if (!_kernel_major) {
+ if ((sscanf(cmd->kernel_vsn, "%d", &_kernel_major) != 1))
+ _kernel_major = 1;
+ else if (_kernel_major >= MIN_KERNEL_MAJOR)
+ log_debug_activation("Skipping checks for old devices without " UUID_PREFIX
+ " dm uuid prefix (kernel vsn %d >= %d).", _kernel_major, MIN_KERNEL_MAJOR);
}
- return (major >= 3);
+ return (_kernel_major < MIN_KERNEL_MAJOR);
}
-static int _info(const char *dlid, int with_open_count, int with_read_ahead,
+static int _info(struct cmd_context *cmd, const char *dlid, int with_open_count, int with_read_ahead,
struct dm_info *dminfo, uint32_t *read_ahead,
struct lv_seg_status *seg_status)
{
}
}
- /* With kernels > 3.X skip checking for devices without UUID_PREFIX */
- if (_check_new_kernel())
+ /* Must we still check for the pre-2.02.00 dm uuid format? */
+ if (!_original_uuid_format_check_required(cmd))
return r;
/* Check for dlid before UUID_PREFIX was added */
return _info_run(INFO, NULL, NULL, info, NULL, 0, 0, 0, major, minor);
}
-int dev_manager_info(struct dm_pool *mem, const struct logical_volume *lv,
+int dev_manager_info(struct cmd_context *cmd, const struct logical_volume *lv,
const char *layer,
int with_open_count, int with_read_ahead,
struct dm_info *dminfo, uint32_t *read_ahead,
char *dlid, *name;
int r;
- if (!(name = dm_build_dm_name(mem, lv->vg->name, lv->name, layer)))
+ if (!(name = dm_build_dm_name(cmd->mem, lv->vg->name, lv->name, layer)))
return_0;
- if (!(dlid = build_dm_uuid(mem, lv, layer))) {
+ if (!(dlid = build_dm_uuid(cmd->mem, lv, layer))) {
r = 0;
goto_out;
}
log_debug_activation("Getting device info for %s [%s]", name, dlid);
- r = _info(dlid, with_open_count, with_read_ahead,
+ r = _info(cmd, dlid, with_open_count, with_read_ahead,
dminfo, read_ahead, seg_status);
out:
- dm_pool_free(mem, name);
+ dm_pool_free(cmd->mem, name);
return r;
}
if (_percent_run(dm, NULL, dlid, target_type, wait, lv, percent,
event_nr, fail_if_percent_unsupported))
return 1;
- else if (_percent_run(dm, NULL, dlid + sizeof(UUID_PREFIX) - 1,
+ else if (_original_uuid_format_check_required(dm->cmd) &&
+ _percent_run(dm, NULL, dlid + sizeof(UUID_PREFIX) - 1,
target_type, wait, lv, percent,
event_nr, fail_if_percent_unsupported))
return 1;
return_0;
log_debug_activation("Getting device info for %s [%s]", name, dlid);
- if (!_info(dlid, 1, 0, &info, NULL, NULL)) {
+ if (!_info(dm->cmd, dlid, 1, 0, &info, NULL, NULL)) {
log_error("Failed to get info for %s [%s].", name, dlid);
return 0;
}
log_sys_error("close", argv[args]);
if (ret == (int) DM_ARRAY_SIZE(buf)) {
- log_debug("%s skipped, detect empty disk header on %s.",
- argv[0], argv[args]);
+ log_debug_activation("%s skipped, detect empty disk header on %s.",
+ argv[0], argv[args]);
return 1;
}
}
return_NULL;
log_debug_activation("Getting device info for %s [%s]", name, dlid);
- if (!_info(dlid, 1, 0, &info, NULL, NULL)) {
+ if (!_info(dm->cmd, dlid, 1, 0, &info, NULL, NULL)) {
log_error("Failed to get info for %s [%s].", name, dlid);
return 0;
}