commit 594b6439564a4f94c981c3cd81df200b9215e5a4
Author: Jim Meyering <meyering(a)redhat.com>
Date: Fri Sep 30 17:58:29 2011 +0200
prepare for a user-configurable RHEV-M-image-import timeout
The current timeout of 10 minutes is too short for some users,
and what they need (60 minutes) seems like it would be far too
long for most others to wait for notification of failure.
* dc-rhev-image.c (IMPORT_SLEEP_SECONDS): Define to 1, not 3.
(IMPORT_SLEEP_MULTIPLIER): Define to 2: double the length of the
sleep interval after each iteration.
(import_tpl): Use the new IMPORT_SLEEP_MULTIPLIER.
dc-rhev-image.c | 26 ++++++++++++++++++++------
1 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/dc-rhev-image.c b/dc-rhev-image.c
index 1b86c43..fb45d7d 100644
--- a/dc-rhev-image.c
+++ b/dc-rhev-image.c
@@ -61,11 +61,21 @@
#define NFSUID 36
#define NFSGID 36
+#ifndef MIN
+# define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
static const char NULID[] = "00000000-0000-0000-0000-000000000000";
enum {
- /* How long to sleep between import status queries. */
- IMPORT_SLEEP_SECONDS = 3,
+ /* Initial number of seconds to sleep while waiting for import to compete. */
+ IMPORT_SLEEP_SECONDS = 1,
+
+ /* After each report that an import is incomplete, we sleep
+ a certain number of seconds, initially IMPORT_SLEEP_SECONDS,
+ and then multiply the current number of seconds to sleep by
+ this integer factor. */
+ IMPORT_SLEEP_MULTIPLIER = 2,
/* An import times out after this many seconds. 60 is too small.
600 appears to be adequate in some real-life situations. */
@@ -2244,7 +2254,6 @@ static void import_tpl(struct config *cfg, struct api_conn
*connection,
xmlChar *ahref;
char *status;
struct timespec tm;
- unsigned int i;
/* P3 */ printf("import cluster %s\n", clustid);
/* P3 */ printf("import target %s\n", msd);
@@ -2253,7 +2262,8 @@ static void import_tpl(struct config *cfg, struct api_conn
*connection,
return;
/* P3 */ printf("import href %s\n", ahref);
- i = 0;
+ time_t n_sec = IMPORT_SLEEP_SECONDS;
+ time_t total_slept_seconds = 0;
for (;;) {
status = import_status(cfg, connection, ahref);
if (c_strcasecmp(status, "COMPLETE") == 0) {
@@ -2261,7 +2271,7 @@ static void import_tpl(struct config *cfg, struct api_conn
*connection,
}
if (c_strcasecmp(status, "PENDING") == 0 ||
c_strcasecmp(status, "IN_PROGRESS") == 0) {
- if (i++ * IMPORT_SLEEP_SECONDS
+ if (total_slept_seconds
= IMPORT_MAXIMUM_DURATION_SECONDS) {
fprintf(stderr,
"ERROR import times out, status `%s'\n",
@@ -2274,9 +2284,13 @@ static void import_tpl(struct config *cfg, struct api_conn
*connection,
exit(EXIT_FAILURE);
}
- tm.tv_sec = IMPORT_SLEEP_SECONDS;
+ tm.tv_sec = n_sec;
tm.tv_nsec = 0;
nanosleep(&tm, NULL);
+ total_slept_seconds += n_sec;
+ n_sec = MIN (n_sec * IMPORT_SLEEP_MULTIPLIER,
+ IMPORT_MAXIMUM_DURATION_SECONDS
+ - total_slept_seconds);
free(status);
}