File util-linux-loop-reuse-11.patch of Package util-linux.7828

From c444a71b1ba216b39707b41ebade2e35f6a256b7 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Thu, 4 Aug 2016 10:49:46 +0200
Subject: [PATCH 11/20] lib/loopdev: cleanup sizelimit check

Signed-off-by: Karel Zak <kzak@redhat.com>
---
 include/loopdev.h              |  6 +++---
 lib/loopdev.c                  | 20 +++++++++++---------
 libmount/src/context_loopdev.c |  4 ++--
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/include/loopdev.h b/include/loopdev.h
index 706388e..ed6ef23 100644
--- a/include/loopdev.h
+++ b/include/loopdev.h
@@ -188,9 +188,9 @@ extern int loopcxt_find_by_backing_file(struct loopdev_cxt *lc,
 				const char *filename,
 				uint64_t offset, uint64_t sizelimit,
 				int flags);
-extern int loopcxt_check_conflict(struct loopdev_cxt *lc,
-				  const char *filename,
-				  uint64_t offset, uint64_t sizelimit);
+extern int loopcxt_find_overlap(struct loopdev_cxt *lc,
+				const char *filename,
+				uint64_t offset, uint64_t sizelimit);
 
 extern int loopcxt_is_used(struct loopdev_cxt *lc,
                     struct stat *st,
diff --git a/lib/loopdev.c b/lib/loopdev.c
index 4606003..cb925ae 100644
--- a/lib/loopdev.c
+++ b/lib/loopdev.c
@@ -1,3 +1,4 @@
+
 /*
  * No copyright is claimed.  This code is in the public domain; do with
  * it what you wish.
@@ -978,9 +979,9 @@ int loopcxt_is_dio(struct loopdev_cxt *lc)
  * @lc: context
  * @st: backing file stat or NULL
  * @backing_file: filename
- * @offset: offset
- * @flags: LOOPDEV_FL_OFFSET if @offset should not be ignored
- * @flags: LOOPDEV_FL_SIZELIMIT if @sizelimit should not be ignored
+ * @offset: offset (use LOOPDEV_FL_OFFSET if specified)
+ * @sizelimit: size limit (use LOOPDEV_FL_SIZELIMIT if specified)
+ * @flags: LOOPDEV_FL_{OFFSET,SIZELIMIT}
  *
  * Returns 1 if the current @lc loopdev is associated with the given backing
  * file. Note that the preferred way is to use devno and inode number rather
@@ -1040,8 +1041,7 @@ found:
 			uint64_t sz;
 
 			return loopcxt_get_sizelimit(lc, &sz) == 0 && sz == sizelimit;
-		}
-		else
+		} else
 			return rc;
 	}
 	return 1;
@@ -1566,9 +1566,9 @@ int loopcxt_find_by_backing_file(struct loopdev_cxt *lc, const char *filename,
 }
 
 /*
- * Returns: 0 = conflict, < 0 error, 1 no conflicting device
+ * Returns: 0 = success, < 0 error, 1 not found
  */
-int loopcxt_check_conflict(struct loopdev_cxt *lc, const char *filename,
+int loopcxt_find_overlap(struct loopdev_cxt *lc, const char *filename,
 			   uint64_t offset, uint64_t sizelimit)
 {
 	int rc, hasst;
@@ -1589,11 +1589,13 @@ int loopcxt_check_conflict(struct loopdev_cxt *lc, const char *filename,
 		rc = loopcxt_is_used(lc, hasst ? &st : NULL,
 				     filename, offset, sizelimit, 0);
 		if (!rc)
-			continue;
+			continue;	/* unused */
 		if (rc != 1)
-			break;
+			break;		/* error */
+
 		DBG(CXT, ul_debugobj(lc, "found %s backed by %s",
 			loopcxt_get_device(lc), filename));
+
 		rc = loopcxt_get_offset(lc, &lc_offset);
 		if (rc) {
 			DBG(CXT, ul_debugobj(lc, "failed to get offset for device %s",
diff --git a/libmount/src/context_loopdev.c b/libmount/src/context_loopdev.c
index 37e49b0..aabb2dd 100644
--- a/libmount/src/context_loopdev.c
+++ b/libmount/src/context_loopdev.c
@@ -261,8 +261,8 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt)
 		rc = loopcxt_init(&lc, 0);
 		if (rc)
 			goto done_no_deinit;
-		rc = loopcxt_check_conflict(&lc,
-			backing_file, offset, sizelimit);
+
+		rc = loopcxt_find_overlap(&lc, backing_file, offset, sizelimit);
 		if (rc < 0)
 			goto done;
 		if (rc == 0) {
-- 
2.9.2

openSUSE Build Service is sponsored by