mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 2 years ago
Clone
Blob Blame History Raw
commit a7864d8f81e29dd7228c16f35314843e2f0c7b86
Author: Peter Rajnoha <prajnoha@redhat.com>
Date:   Wed Mar 26 09:09:33 2014 +0100

    0
---
 lib/cache/lvmetad.c              | 16 +++++++++++-----
 libdaemon/client/daemon-client.h |  2 +-
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index 38d9042..c019250 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -143,6 +143,7 @@ static daemon_reply _lvmetad_send(const char *id, ...)
 	daemon_reply repl;
 	daemon_request req;
 	int try = 0;
+	int time = 0, wait, sleep = 1;
 
 retry:
 	req = daemon_request_make(id);
@@ -159,7 +160,7 @@ retry:
 	daemon_request_destroy(req);
 
 	if (!repl.error && !strcmp(daemon_reply_str(repl, "response", ""), "token_mismatch") &&
-	    try < 60 && !test_mode()) {
+	    try < 10 && time < 80000000 && !test_mode()) {
 		/*
 		 * If another process is trying to scan, they might have the
 		 * same future token id and it's better to wait and avoid doing
@@ -172,12 +173,17 @@ retry:
 		 * the update, we back off for a short while (0.2-2 seconds) and
 		 * try again.
 		 */
-		if (!strcmp(daemon_reply_str(repl, "expected", ""), "update in progress") || try % 5)
-			usleep( 50000 + random() % 450000 ); /* 0.05 - 0.5s */
-		else
+		if (!strcmp(daemon_reply_str(repl, "expected", ""), "update in progress") || sleep) {
+			wait = 50000 + random() % 450000; /* 0.05 - 0.5s */
+			time += wait;
+			usleep( wait );
+			-- sleep;
+		} else {
 			/* If the re-scan fails here, we try again later. */
 			lvmetad_pvscan_all_devs(_lvmetad_cmd, NULL);
-		++ try;
+			++ try;
+			sleep = 5;
+		}
 		daemon_reply_destroy(repl);
 		goto retry;
 	}
diff --git a/libdaemon/client/daemon-client.h b/libdaemon/client/daemon-client.h
index 6ba65e6..8a44f8b 100644
--- a/libdaemon/client/daemon-client.h
+++ b/libdaemon/client/daemon-client.h
@@ -102,7 +102,7 @@ static inline int64_t daemon_reply_int(daemon_reply r, const char *path, int64_t
 }
 
 static inline const char *daemon_reply_str(daemon_reply r, const char *path, const char *def) {
-	return dm_config_find_str(r.cft->root, path, def);
+	return dm_config_find_str_allow_empty(r.cft->root, path, def);
 }