mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-28 11:21:44 +03:00
Use virTimeMs when appropriate
This commit is contained in:
parent
ef6e99dc24
commit
a231016b69
@ -45,8 +45,6 @@
|
||||
|
||||
#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,
|
||||
@ -492,15 +490,12 @@ void qemuDomainSetNamespaceHooks(virCapsPtr caps)
|
||||
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);
|
||||
|
||||
@ -520,7 +515,7 @@ int qemuDomainObjBeginJob(virDomainObjPtr 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;
|
||||
@ -536,15 +531,12 @@ int qemuDomainObjBeginJobWithDriver(struct qemud_driver *driver,
|
||||
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);
|
||||
@ -568,7 +560,7 @@ int qemuDomainObjBeginJobWithDriver(struct qemud_driver *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);
|
||||
|
@ -113,8 +113,6 @@
|
||||
|
||||
#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);
|
||||
@ -6841,8 +6839,6 @@ static int qemuDomainGetJobInfo(virDomainPtr dom,
|
||||
|
||||
if (virDomainObjIsActive(vm)) {
|
||||
if (priv->jobActive) {
|
||||
struct timeval now;
|
||||
|
||||
memcpy(info, &priv->jobInfo, sizeof(*info));
|
||||
|
||||
/* Refresh elapsed time again just to ensure it
|
||||
@ -6850,12 +6846,9 @@ static int qemuDomainGetJobInfo(virDomainPtr dom,
|
||||
* 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;
|
||||
|
@ -46,8 +46,6 @@
|
||||
|
||||
#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,
|
||||
@ -831,7 +829,6 @@ qemuMigrationUpdateJobStatus(struct qemud_driver *driver,
|
||||
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"),
|
||||
@ -847,18 +844,11 @@ qemuMigrationUpdateJobStatus(struct qemud_driver *driver,
|
||||
&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:
|
||||
@ -1069,18 +1059,16 @@ qemuMigrationPrepareTunnel(struct qemud_driver *driver,
|
||||
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,
|
||||
@ -1190,7 +1178,7 @@ endjob:
|
||||
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:
|
||||
@ -1229,8 +1217,9 @@ qemuMigrationPrepareDirect(struct qemud_driver *driver,
|
||||
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",
|
||||
@ -1238,11 +1227,8 @@ qemuMigrationPrepareDirect(struct qemud_driver *driver,
|
||||
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".
|
||||
*
|
||||
@ -1413,7 +1399,7 @@ endjob:
|
||||
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:
|
||||
|
@ -201,11 +201,12 @@ int virEventPollRemoveHandle(int watch) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -227,9 +228,7 @@ int virEventPollAddTimeout(int frequency,
|
||||
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;
|
||||
@ -238,8 +237,9 @@ int virEventPollAddTimeout(int frequency,
|
||||
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);
|
||||
|
||||
@ -248,7 +248,7 @@ void virEventPollUpdateTimeout(int timer, int frequency) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (gettimeofday(&tv, NULL) < 0) {
|
||||
if (virTimeMs(&now) < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -257,9 +257,7 @@ void virEventPollUpdateTimeout(int timer, int frequency) {
|
||||
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;
|
||||
}
|
||||
@ -321,18 +319,12 @@ static int virEventPollCalculateTimeout(int *timeout) {
|
||||
|
||||
/* 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 {
|
||||
@ -397,21 +389,16 @@ static struct pollfd *virEventPollMakePollFDs(int *nfds) {
|
||||
*
|
||||
* 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)
|
||||
|
Loading…
Reference in New Issue
Block a user