]> sourceware.org Git - lvm2.git/commitdiff
Replace strncmp kernel version number checks with proper ones
authorAlasdair Kergon <agk@redhat.com>
Mon, 24 May 2010 23:11:34 +0000 (23:11 +0000)
committerAlasdair Kergon <agk@redhat.com>
Mon, 24 May 2010 23:11:34 +0000 (23:11 +0000)
WHATS_NEW
lib/mirror/mirrored.c
lib/misc/util.h
libdm/libdm-deptree.c

index 3b02d7dff015a8b87ca07a938784138060af436c..e1cf308cb8cda2e7393a50f872fb5aa54956a497 100644 (file)
--- 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.
index ff15b73aa3ee8c81f0b24602ca0a29aa31286fa1..eca0377637acae56edeab2f0ebf5767dc458ac37 100644 (file)
@@ -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"))
index 15d2662a9539bce68d8c2db1c233cc793577d785..fcda36911d574759ae5d20013d6ba7fd2edb4bc3 100644 (file)
@@ -27,4 +27,6 @@
 
 #define uninitialized_var(x) x = x
 
+#define KERNEL_VERSION(major, minor, release) (((major) << 16) + ((minor) << 8) + (release))
+
 #endif
index 21aa7946216606d7a22eac632fa2582bf9f13452..b75e6afae09e261f38dabc180c46d8eecc3bd2b5 100644 (file)
@@ -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;
        }
 
This page took 0.057838 seconds and 5 git commands to generate.