Blame SOURCES/0072-RHBZ-1039199-check-loop-control.patch

e41771
---
e41771
 kpartx/lopart.c |   18 ++++++++++++++++--
e41771
 1 file changed, 16 insertions(+), 2 deletions(-)
e41771
e41771
Index: multipath-tools-130222/kpartx/lopart.c
e41771
===================================================================
e41771
--- multipath-tools-130222.orig/kpartx/lopart.c
e41771
+++ multipath-tools-130222/kpartx/lopart.c
e41771
@@ -32,6 +32,10 @@
e41771
 #include "lopart.h"
e41771
 #include "xstrncpy.h"
e41771
 
e41771
+#ifndef LOOP_CTL_GET_FREE
e41771
+#define LOOP_CTL_GET_FREE       0x4C82
e41771
+#endif
e41771
+
e41771
 #if !defined (__alpha__) && !defined (__ia64__) && !defined (__x86_64__) \
e41771
         && !defined (__s390x__)
e41771
 #define int2ptr(x)	((void *) ((int) x))
e41771
@@ -140,14 +144,24 @@ find_unused_loop_device (void)
e41771
 
e41771
 	char dev[20];
e41771
 	char *loop_formats[] = { "/dev/loop%d", "/dev/loop/%d" };
e41771
-	int i, j, fd, somedev = 0, someloop = 0, loop_known = 0;
e41771
+	int i, j, fd, first = 0, somedev = 0, someloop = 0, loop_known = 0;
e41771
 	struct stat statbuf;
e41771
 	struct loop_info loopinfo;
e41771
 	FILE *procdev;
e41771
 
e41771
+	if (stat("/dev/loop-control", &statbuf) == 0 &&
e41771
+	    S_ISCHR(statbuf.st_mode)) {
e41771
+		fd = open("/dev/loop-control", O_RDWR);
e41771
+		if (fd >= 0) {
e41771
+			first = ioctl(fd, LOOP_CTL_GET_FREE);
e41771
+			close(fd);
e41771
+		}
e41771
+		if (first < 0)
e41771
+			first = 0;
e41771
+	}
e41771
 	for (j = 0; j < SIZE(loop_formats); j++) {
e41771
 
e41771
-	    for(i = 0; i < 256; i++) {
e41771
+	    for(i = first; i < 256; i++) {
e41771
 		sprintf(dev, loop_formats[j], i);
e41771
 
e41771
 		if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {