Blame SOURCES/ledmon-nvme.patch

725b5c
commit 868a01e894f6abd33a98457a7ee4c1aa7e1eb2fe
725b5c
Author: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
725b5c
Date:   Tue May 9 11:21:25 2017 +0200
725b5c
725b5c
    Don't rely on searching for "/block" in sysfs path for detecting partitions
725b5c
    
725b5c
    It is simpler and more reliable to check for a "partition" file in the
725b5c
    device's directory (supported since kernel 2.6.28). The previous
725b5c
    approach would fail for nvme devices because their device path looks
725b5c
    like this:
725b5c
    /sys/devices/pci0000:00/0000:00:0c.0/nvme/nvme0/nvme0n1
725b5c
    
725b5c
    Fixes: b30173ec8c05 ("* fix off-normal-failure block dev status loop * remove unused raid->slave_list member * support md raid on block device partitions")
725b5c
725b5c
diff --git a/src/slave.c b/src/slave.c
725b5c
index 9843ffd..436ed4a 100644
725b5c
--- a/src/slave.c
725b5c
+++ b/src/slave.c
725b5c
@@ -22,6 +22,8 @@
725b5c
 #include <string.h>
725b5c
 #include <stdlib.h>
725b5c
 #include <stdint.h>
725b5c
+#include <stdio.h>
725b5c
+#include <sys/stat.h>
725b5c
 
725b5c
 #if _HAVE_DMALLOC_H
725b5c
 #include <dmalloc.h>
725b5c
@@ -100,27 +102,26 @@ static struct block_device *_get_block(const char *path, void *block_list)
725b5c
 {
725b5c
 	char temp[PATH_MAX];
725b5c
 	char link[PATH_MAX];
725b5c
-	char *ptr;
725b5c
-	struct block_device *device = NULL;
725b5c
 
725b5c
 	str_cpy(temp, path, PATH_MAX);
725b5c
 	str_cat(temp, "/block", PATH_MAX);
725b5c
 
725b5c
-	if (realpath(temp, link)) {
725b5c
-		ptr = strrchr(link, '/');
725b5c
-		if (ptr && link < ptr - strlen("/block")) {
725b5c
-			/* translate partition to master block dev */
725b5c
-			if(strncmp(
725b5c
-				ptr - strlen("/block"),
725b5c
-				"/block",
725b5c
-				strlen("/block"))) {
725b5c
+	if (!realpath(temp, link))
725b5c
+		return NULL;
725b5c
 
725b5c
+	/* translate partition to master block dev */
725b5c
+	if (snprintf(temp, PATH_MAX, "%s/partition", link) > 0) {
725b5c
+		struct stat sb;
725b5c
+		char *ptr;
725b5c
+
725b5c
+		if (stat(temp, &sb) == 0 && S_ISREG(sb.st_mode)) {
725b5c
+			ptr = strrchr(link, '/');
725b5c
+			if (ptr)
725b5c
 				*ptr = '\0';
725b5c
-			}
725b5c
-			device = list_first_that(block_list, _compare, link);
725b5c
 		}
725b5c
 	}
725b5c
-	return device;
725b5c
+
725b5c
+	return list_first_that(block_list, _compare, link);
725b5c
 }
725b5c
 
725b5c
 /**