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

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