commit d1c95d665c76f4d83f51929a1181fd4b71a78e2c
Author: Jim Meyering <meyering(a)redhat.com>
Date: Mon Aug 22 11:06:39 2011 +0200
maint: give names to import-related sleep/timeout constants
* dc-rhev-image.c (IMPORT_SLEEP_SECONDS): Define.
(IMPORT_SLEEP_SECONDS): Define.
(import_tpl): Use those rather than hard-coded constants.
* NEWS (Bug fixes): Mention it.
NEWS | 3 +++
dc-rhev-image.c | 15 ++++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/NEWS b/NEWS
index e122bcf..b859a8b 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ iwhd NEWS -*- outline -*-
** Bug fixes
+ dc-rhev-image now allows a RHEV-M import to take 10 minutes.
+ Before, it would timeout after just 1 minute, which was often inadequate.
+
object deletion now succeeds for an object whose FS-backed file has been
removed behind iwhd's back.
diff --git a/dc-rhev-image.c b/dc-rhev-image.c
index 20a1d13..6b74f35 100644
--- a/dc-rhev-image.c
+++ b/dc-rhev-image.c
@@ -63,6 +63,15 @@
static const char NULID[] = "00000000-0000-0000-0000-000000000000";
+enum {
+ /* How long to sleep between import status queries. */
+ IMPORT_SLEEP_SECONDS = 3,
+
+ /* An import times out after this many seconds. 60 is too small.
+ 600 appears to be adequate in some real-life situations. */
+ IMPORT_MAXIMUM_DURATION_SECONDS = 600
+};
+
struct config {
char *image;
char *apiurl;
@@ -2238,8 +2247,8 @@ static void import_tpl(struct config *cfg, struct api_conn *connection,
}
if (c_strcasecmp(status, "PENDING") == 0 ||
c_strcasecmp(status, "IN_PROGRESS") == 0) {
- /* Yes, 10 minutes may be needed, 1 is way too small. */
- if (++i >= 200) {
+ if (i++ * IMPORT_SLEEP_SECONDS
+ >= IMPORT_MAXIMUM_DURATION_SECONDS) {
fprintf(stderr,
"ERROR import times out, status `%s'\n",
status);
@@ -2251,7 +2260,7 @@ static void import_tpl(struct config *cfg, struct api_conn *connection,
exit(EXIT_FAILURE);
}
- tm.tv_sec = 3;
+ tm.tv_sec = IMPORT_SLEEP_SECONDS;
tm.tv_nsec = 0;
nanosleep(&tm, NULL);