#define QEMU_NAMESPACE_HREF "http://libvirt.org/schemas/domain/qemu/1.0"
-#define timeval_to_ms(tv) (((tv).tv_sec * 1000ull) + ((tv).tv_usec / 1000))
-
static void qemuDomainEventDispatchFunc(virConnectPtr conn,
virDomainEventPtr event,
int qemuDomainObjBeginJob(virDomainObjPtr obj)
{
qemuDomainObjPrivatePtr priv = obj->privateData;
- struct timeval now;
+ unsigned long long now;
unsigned long long then;
- if (gettimeofday(&now, NULL) < 0) {
- virReportSystemError(errno, "%s",
- _("cannot get time of day"));
+ if (virTimeMs(&now) < 0)
return -1;
- }
- then = timeval_to_ms(now) + QEMU_JOB_WAIT_TIME;
+ then = now + QEMU_JOB_WAIT_TIME;
virDomainObjRef(obj);
priv->jobActive = QEMU_JOB_UNSPECIFIED;
priv->jobSignals = 0;
memset(&priv->jobSignalsData, 0, sizeof(priv->jobSignalsData));
- priv->jobStart = timeval_to_ms(now);
+ priv->jobStart = now;
memset(&priv->jobInfo, 0, sizeof(priv->jobInfo));
return 0;
virDomainObjPtr obj)
{
qemuDomainObjPrivatePtr priv = obj->privateData;
- struct timeval now;
+ unsigned long long now;
unsigned long long then;
- if (gettimeofday(&now, NULL) < 0) {
- virReportSystemError(errno, "%s",
- _("cannot get time of day"));
+ if (virTimeMs(&now) < 0)
return -1;
- }
- then = timeval_to_ms(now) + QEMU_JOB_WAIT_TIME;
+ then = now + QEMU_JOB_WAIT_TIME;
virDomainObjRef(obj);
qemuDriverUnlock(driver);
priv->jobActive = QEMU_JOB_UNSPECIFIED;
priv->jobSignals = 0;
memset(&priv->jobSignalsData, 0, sizeof(priv->jobSignalsData));
- priv->jobStart = timeval_to_ms(now);
+ priv->jobStart = now;
memset(&priv->jobInfo, 0, sizeof(priv->jobInfo));
virDomainObjUnlock(obj);
#define QEMU_NB_BLKIO_PARAM 1
-#define timeval_to_ms(tv) (((tv).tv_sec * 1000ull) + ((tv).tv_usec / 1000))
-
static void processWatchdogEvent(void *data, void *opaque);
static int qemudShutdown(void);
if (virDomainObjIsActive(vm)) {
if (priv->jobActive) {
- struct timeval now;
-
memcpy(info, &priv->jobInfo, sizeof(*info));
/* Refresh elapsed time again just to ensure it
* of incoming migration which we don't currently
* monitor actively in the background thread
*/
- if (gettimeofday(&now, NULL) < 0) {
- virReportSystemError(errno, "%s",
- _("cannot get time of day"));
+ if (virTimeMs(&info->timeElapsed) < 0)
goto cleanup;
- }
- info->timeElapsed = timeval_to_ms(now) - priv->jobStart;
+ info->timeElapsed -= priv->jobStart;
} else {
memset(info, 0, sizeof(*info));
info->type = VIR_DOMAIN_JOB_NONE;
#define VIR_FROM_THIS VIR_FROM_QEMU
-#define timeval_to_ms(tv) (((tv).tv_sec * 1000ull) + ((tv).tv_usec / 1000))
-
enum qemuMigrationCookieFlags {
QEMU_MIGRATION_COOKIE_FLAG_GRAPHICS,
QEMU_MIGRATION_COOKIE_FLAG_LOCKSTATE,
unsigned long long memProcessed;
unsigned long long memRemaining;
unsigned long long memTotal;
- struct timeval now;
if (!virDomainObjIsActive(vm)) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, _("%s: %s"),
&memTotal);
qemuDomainObjExitMonitorWithDriver(driver, vm);
- if (ret < 0) {
+ if (ret < 0 || virTimeMs(&priv->jobInfo.timeElapsed) < 0) {
priv->jobInfo.type = VIR_DOMAIN_JOB_FAILED;
return -1;
}
-
- if (gettimeofday(&now, NULL) < 0) {
- priv->jobInfo.type = VIR_DOMAIN_JOB_FAILED;
- virReportSystemError(errno, "%s",
- _("cannot get time of day"));
- return -1;
- }
- priv->jobInfo.timeElapsed = timeval_to_ms(now) - priv->jobStart;
+ priv->jobInfo.timeElapsed -= priv->jobStart;
switch (status) {
case QEMU_MONITOR_MIGRATION_STATUS_INACTIVE:
int internalret;
int dataFD[2] = { -1, -1 };
qemuDomainObjPrivatePtr priv = NULL;
- struct timeval now;
+ unsigned long long now;
qemuMigrationCookiePtr mig = NULL;
+
VIR_DEBUG("driver=%p, dconn=%p, cookiein=%s, cookieinlen=%d, "
"cookieout=%p, cookieoutlen=%p, st=%p, dname=%s, dom_xml=%s",
driver, dconn, NULLSTR(cookiein), cookieinlen,
cookieout, cookieoutlen, st, NULLSTR(dname), dom_xml);
- if (gettimeofday(&now, NULL) < 0) {
- virReportSystemError(errno, "%s",
- _("cannot get time of day"));
+ if (virTimeMs(&now) < 0)
return -1;
- }
/* Parse the domain XML. */
if (!(def = virDomainDefParseString(driver->caps, dom_xml,
virDomainObjIsActive(vm)) {
priv->jobActive = QEMU_JOB_MIGRATION_IN;
priv->jobInfo.type = VIR_DOMAIN_JOB_UNBOUNDED;
- priv->jobStart = timeval_to_ms(now);
+ priv->jobStart = now;
}
cleanup:
int ret = -1;
int internalret;
qemuDomainObjPrivatePtr priv = NULL;
- struct timeval now;
+ unsigned long long now;
qemuMigrationCookiePtr mig = NULL;
+
VIR_DEBUG("driver=%p, dconn=%p, cookiein=%s, cookieinlen=%d, "
"cookieout=%p, cookieoutlen=%p, uri_in=%s, uri_out=%p, "
"dname=%s, dom_xml=%s",
cookieout, cookieoutlen, NULLSTR(uri_in), uri_out,
NULLSTR(dname), dom_xml);
- if (gettimeofday(&now, NULL) < 0) {
- virReportSystemError(errno, "%s",
- _("cannot get time of day"));
+ if (virTimeMs(&now) < 0)
return -1;
- }
/* The URI passed in may be NULL or a string "tcp://somehostname:port".
*
virDomainObjIsActive(vm)) {
priv->jobActive = QEMU_JOB_MIGRATION_IN;
priv->jobInfo.type = VIR_DOMAIN_JOB_UNBOUNDED;
- priv->jobStart = timeval_to_ms(now);
+ priv->jobStart = now;
}
cleanup:
int virEventPollAddTimeout(int frequency,
virEventTimeoutCallback cb,
void *opaque,
- virFreeCallback ff) {
- struct timeval now;
+ virFreeCallback ff)
+{
+ unsigned long long now;
int ret;
EVENT_DEBUG("Adding timer %d with %d ms freq", nextTimer, frequency);
- if (gettimeofday(&now, NULL) < 0) {
+ if (virTimeMs(&now) < 0) {
return -1;
}
eventLoop.timeouts[eventLoop.timeoutsCount].opaque = opaque;
eventLoop.timeouts[eventLoop.timeoutsCount].deleted = 0;
eventLoop.timeouts[eventLoop.timeoutsCount].expiresAt =
- frequency >= 0 ? frequency +
- (((unsigned long long)now.tv_sec)*1000) +
- (((unsigned long long)now.tv_usec)/1000) : 0;
+ frequency >= 0 ? frequency + now : 0;
eventLoop.timeoutsCount++;
ret = nextTimer-1;
return ret;
}
-void virEventPollUpdateTimeout(int timer, int frequency) {
- struct timeval tv;
+void virEventPollUpdateTimeout(int timer, int frequency)
+{
+ unsigned long long now;
int i;
EVENT_DEBUG("Updating timer %d timeout with %d ms freq", timer, frequency);
return;
}
- if (gettimeofday(&tv, NULL) < 0) {
+ if (virTimeMs(&now) < 0) {
return;
}
if (eventLoop.timeouts[i].timer == timer) {
eventLoop.timeouts[i].frequency = frequency;
eventLoop.timeouts[i].expiresAt =
- frequency >= 0 ? frequency +
- (((unsigned long long)tv.tv_sec)*1000) +
- (((unsigned long long)tv.tv_usec)/1000) : 0;
+ frequency >= 0 ? frequency + now : 0;
virEventPollInterruptLocked();
break;
}
/* Calculate how long we should wait for a timeout if needed */
if (then > 0) {
- struct timeval tv;
+ unsigned long long now;
- if (gettimeofday(&tv, NULL) < 0) {
- virReportSystemError(errno, "%s",
- _("Unable to get current time"));
+ if (virTimeMs(&now) < 0)
return -1;
- }
-
- *timeout = then -
- ((((unsigned long long)tv.tv_sec)*1000) +
- (((unsigned long long)tv.tv_usec)/1000));
+ *timeout = then - now;
if (*timeout < 0)
*timeout = 0;
} else {
*
* Returns 0 upon success, -1 if an error occurred
*/
-static int virEventPollDispatchTimeouts(void) {
- struct timeval tv;
+static int virEventPollDispatchTimeouts(void)
+{
unsigned long long now;
int i;
/* Save this now - it may be changed during dispatch */
int ntimeouts = eventLoop.timeoutsCount;
VIR_DEBUG("Dispatch %d", ntimeouts);
- if (gettimeofday(&tv, NULL) < 0) {
- virReportSystemError(errno, "%s",
- _("Unable to get current time"));
+ if (virTimeMs(&now) < 0)
return -1;
- }
- now = (((unsigned long long)tv.tv_sec)*1000) +
- (((unsigned long long)tv.tv_usec)/1000);
for (i = 0 ; i < ntimeouts ; i++) {
if (eventLoop.timeouts[i].deleted || eventLoop.timeouts[i].frequency < 0)