/*
* virsh-domain.c: Commands to manage domain
*
- * Copyright (C) 2005, 2007-2013 Red Hat, Inc.
+ * Copyright (C) 2005, 2007-2014 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
const char *path = NULL;
bool quit = false;
int abort_flags = 0;
- int rv;
if (blocking) {
- if ((rv = vshCommandOptInt(cmd, "timeout", &timeout)) < 0 ||
- (rv > 0 && timeout < 1)) {
- vshError(ctl, "%s", _("invalid timeout"));
+ if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
return false;
- } else if (rv > 0) {
- /* Ensure that we can multiply by 1000 without overflowing. */
- if (timeout > INT_MAX / 1000) {
- vshError(ctl, "%s", _("timeout is too big"));
- return false;
- }
- timeout *= 1000;
- }
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
return false;
if (vshCommandOptBool(cmd, "async"))
const char *path = NULL;
bool quit = false;
int abort_flags = 0;
- int rv;
if (blocking) {
if (pivot && finish) {
vshError(ctl, "%s", _("cannot mix --pivot and --finish"));
return false;
}
- if ((rv = vshCommandOptInt(cmd, "timeout", &timeout)) < 0 ||
- (rv > 0 && timeout < 1)) {
- vshError(ctl, "%s", _("invalid timeout"));
+ if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
return false;
- } else if (rv > 0) {
- /* Ensure that we can multiply by 1000 without overflowing. */
- if (timeout > INT_MAX / 1000) {
- vshError(ctl, "%s", _("timeout is too big"));
- return false;
- }
- timeout *= 1000;
- }
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
return false;
if (vshCommandOptBool(cmd, "async"))
const char *path = NULL;
bool quit = false;
int abort_flags = 0;
- int rv;
if (blocking) {
- if ((rv = vshCommandOptInt(cmd, "timeout", &timeout)) < 0 ||
- (rv > 0 && timeout < 1)) {
- vshError(ctl, "%s", _("invalid timeout"));
+ if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
return false;
- } else if (rv > 0) {
- /* Ensure that we can multiply by 1000 without overflowing. */
- if (timeout > INT_MAX / 1000) {
- vshError(ctl, "%s", _("timeout is too big"));
- return false;
- }
- timeout *= 1000;
- }
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
return false;
if (vshCommandOptBool(cmd, "async"))
virDomainPtr dom,
bool verbose,
int pipe_fd,
- int timeout,
+ int timeout_ms,
jobWatchTimeoutFunc timeout_func,
void *opaque,
const char *label)
}
GETTIMEOFDAY(&curr);
- if (timeout && (((int)(curr.tv_sec - start.tv_sec) * 1000 +
- (int)(curr.tv_usec - start.tv_usec) / 1000) >
- timeout * 1000)) {
+ if (timeout_ms && (((int)(curr.tv_sec - start.tv_sec) * 1000 +
+ (int)(curr.tv_usec - start.tv_usec) / 1000) >
+ timeout_ms)) {
/* suspend the domain when migration timeouts. */
vshDebug(ctl, VSH_ERR_DEBUG, "%s timeout", label);
if (timeout_func)
(timeout_func)(ctl, dom, opaque);
- timeout = 0;
+ timeout_ms = 0;
}
if (verbose || !jobStarted) {
int timeout = 0;
bool live_flag = false;
vshCtrlData data;
- int rv;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
if (vshCommandOptBool(cmd, "live"))
live_flag = true;
- if ((rv = vshCommandOptInt(cmd, "timeout", &timeout)) < 0 ||
- (rv > 0 && timeout < 1)) {
- vshError(ctl, "%s", _("migrate: Invalid timeout"));
+ if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) {
+ goto cleanup;
+ } else if (timeout > 0 && !live_flag) {
+ vshError(ctl, "%s",
+ _("migrate: Unexpected timeout for offline migration"));
goto cleanup;
- } else if (rv > 0) {
- if (! live_flag) {
- vshError(ctl, "%s",
- _("migrate: Unexpected timeout for offline migration"));
- goto cleanup;
- }
-
- /* Ensure that we can multiply by 1000 without overflowing. */
- if (timeout > INT_MAX / 1000) {
- vshError(ctl, "%s", _("migrate: Timeout is too big"));
- goto cleanup;
- }
}
if (pipe(p) < 0)
/*
* virsh.c: a shell to exercise the libvirt API
*
- * Copyright (C) 2005, 2007-2013 Red Hat, Inc.
+ * Copyright (C) 2005, 2007-2014 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
return found;
}
+/* Parse an optional --timeout parameter in seconds, but store the
+ * value of the timeout in milliseconds. Return -1 on error, 0 if
+ * no timeout was requested, and 1 if timeout was set. */
+int
+vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout)
+{
+ int rv = vshCommandOptInt(cmd, "timeout", timeout);
+
+ if (rv < 0 || (rv > 0 && *timeout < 1)) {
+ vshError(ctl, "%s", _("invalid timeout"));
+ return -1;
+ }
+ if (rv > 0) {
+ /* Ensure that we can multiply by 1000 without overflowing. */
+ if (*timeout > INT_MAX / 1000) {
+ vshError(ctl, "%s", _("timeout is too big"));
+ return -1;
+ }
+ *timeout *= 1000;
+ }
+ return rv;
+}
+
+
static bool
vshConnectionUsability(vshControl *ctl, virConnectPtr conn)
{