From ba61f84874c2c0b93552c69f778a6652b1f33403 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Mon, 24 May 2010 23:11:34 +0000 Subject: [PATCH] Replace strncmp kernel version number checks with proper ones --- WHATS_NEW | 1 + lib/mirror/mirrored.c | 6 ++++-- lib/misc/util.h | 2 ++ libdm/libdm-deptree.c | 9 ++++----- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 3b02d7dff..e1cf308cb 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.67 - =============================== + Replace strncmp kernel version number checks with proper ones. Avoid selecting names under /dev/block if there is an alternative. Update clustered log kernel module name to log-userspace for 2.6.31 onwards. Activate only first head of Replicator for vgchange -ay. diff --git a/lib/mirror/mirrored.c b/lib/mirror/mirrored.c index ff15b73aa..eca037763 100644 --- a/lib/mirror/mirrored.c +++ b/lib/mirror/mirrored.c @@ -474,6 +474,7 @@ static int _mirrored_target_present(struct cmd_context *cmd, unsigned maj2, min2, patchlevel2; char vsn[80]; struct utsname uts; + unsigned kmaj, kmin, krel; if (!_mirrored_checked) { _mirrored_present = target_present(cmd, "mirror", 1); @@ -511,8 +512,9 @@ static int _mirrored_target_present(struct cmd_context *cmd, * The dm-log-userspace module was added to the * 2.6.31 kernel. */ - /* FIXME Replace the broken string comparison! */ - if (!uname(&uts) && strncmp(uts.release, "2.6.31", 6) < 0) { + if (!uname(&uts) && + (sscanf(uts.release, "%u.%u.%u", &kmaj, &kmin, &krel) == 3) && + KERNEL_VERSION(kmaj, kmin, krel) < KERNEL_VERSION(2, 6, 31)) { if (module_present(cmd, "log-clustered")) _mirror_attributes |= MIRROR_LOG_CLUSTERED; } else if (module_present(cmd, "log-userspace")) diff --git a/lib/misc/util.h b/lib/misc/util.h index 15d2662a9..fcda36911 100644 --- a/lib/misc/util.h +++ b/lib/misc/util.h @@ -27,4 +27,6 @@ #define uninitialized_var(x) x = x +#define KERNEL_VERSION(major, minor, release) (((major) << 16) + ((minor) << 8) + (release)) + #endif diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c index 21aa79462..b75e6afae 100644 --- a/libdm/libdm-deptree.c +++ b/libdm/libdm-deptree.c @@ -1540,9 +1540,9 @@ static int _mirror_emit_segment_line(struct dm_task *dmt, uint32_t major, int pos = 0; char logbuf[DM_FORMAT_DEV_BUFSIZE]; const char *logtype; + unsigned kmaj, kmin, krel; - r = uname(&uts); - if (r) + if (!uname(&uts) || sscanf(uts.release, "%u.%u.%u", &kmaj, &kmin, &krel) != 3) return_0; if ((seg->flags & DM_BLOCK_ON_ERROR)) { @@ -1556,7 +1556,7 @@ static int _mirror_emit_segment_line(struct dm_task *dmt, uint32_t major, * "handle_errors" by the dm-mirror module's version * number (>= 1.12) or by the kernel version (>= 2.6.22). */ - if (strncmp(uts.release, "2.6.22", 6) >= 0) + if (KERNEL_VERSION(kmaj, kmin, krel) >= KERNEL_VERSION(2, 6, 22)) handle_errors = 1; else block_on_error = 1; @@ -1575,8 +1575,7 @@ static int _mirror_emit_segment_line(struct dm_task *dmt, uint32_t major, * The dm-log-userspace module was added to the * 2.6.31 kernel. */ - /* FIXME Replace the broken string comparison! */ - if (strncmp(uts.release, "2.6.31", 6) >= 0) + if (KERNEL_VERSION(kmaj, kmin, krel) >= KERNEL_VERSION(2, 6, 31)) dm_log_userspace = 1; } -- 2.43.5