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

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