The virTimestamp and virTimeMs functions in src/util/util.h
duplicate functionality from virtime.h, in a non-async signal
safe manner. Remove them, and convert all code over to the new
APIs.
* src/util/util.c, src/util/util.h: Delete virTimeMs and virTimestamp
* src/lxc/lxc_driver.c, src/qemu/qemu_domain.c,
src/qemu/qemu_driver.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c, src/util/event_poll.c: Convert to use
virtime APIs
(cherry picked from commit
a8bb75a3e65f0ae866f3b3fd60c57b2aa2050017)
Conflicts:
src/lxc/lxc_driver.c
src/qemu/qemu_domain.c
src/qemu/qemu_driver.c
* the patches contained context with extra include files not
yet introduced on the branch.
src/util/event_poll.c
* the branch had context with a call to EVENT_DEBUG that
was no longer existing in the original patch.
virStrToLong_ull;
virStrcpy;
virStrncpy;
-virTimeMs;
-virTimestamp;
virTrimSpaces;
virVasprintf;
#include "fdstream.h"
#include "domain_audit.h"
#include "domain_nwfilter.h"
+#include "virtime.h"
#define VIR_FROM_THIS VIR_FROM_LXC
goto cleanup;
/* Log timestamp */
- if ((timestamp = virTimestamp()) == NULL) {
+ if ((timestamp = virTimeStringNow()) == NULL) {
virReportOOMError();
goto cleanup;
}
#include "ignore-value.h"
#include "uuid.h"
#include "virfile.h"
+#include "virtime.h"
#include <sys/time.h>
#include <fcntl.h>
priv->jobs_queued++;
- if (virTimeMs(&now) < 0)
+ if (virTimeMillisNow(&now) < 0)
return -1;
then = now + QEMU_JOB_WAIT_TIME;
qemuMonitorLock(priv->mon);
qemuMonitorRef(priv->mon);
- ignore_value(virTimeMs(&priv->monStart));
+ ignore_value(virTimeMillisNow(&priv->monStart));
virDomainObjUnlock(obj);
if (driver_locked)
qemuDriverUnlock(driver);
#include "locking/lock_manager.h"
#include "locking/domain_lock.h"
#include "virkeycode.h"
+#include "virtime.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
} else if (priv->job.active) {
if (!priv->monStart) {
info->state = VIR_DOMAIN_CONTROL_JOB;
- if (virTimeMs(&info->stateTime) < 0)
+ if (virTimeMillisNow(&info->stateTime) < 0)
goto cleanup;
info->stateTime -= priv->job.start;
} else {
info->state = VIR_DOMAIN_CONTROL_OCCUPIED;
- if (virTimeMs(&info->stateTime) < 0)
+ if (virTimeMillisNow(&info->stateTime) < 0)
goto cleanup;
info->stateTime -= priv->monStart;
}
* of incoming migration which we don't currently
* monitor actively in the background thread
*/
- if (virTimeMs(&info->timeElapsed) < 0)
+ if (virTimeMillisNow(&info->timeElapsed) < 0)
goto cleanup;
info->timeElapsed -= priv->job.start;
} else {
#include "datatypes.h"
#include "fdstream.h"
#include "uuid.h"
+#include "virtime.h"
#include "locking/domain_lock.h"
#include "rpc/virnetsocket.h"
&memTotal);
qemuDomainObjExitMonitorWithDriver(driver, vm);
- if (ret < 0 || virTimeMs(&priv->job.info.timeElapsed) < 0) {
+ if (ret < 0 || virTimeMillisNow(&priv->job.info.timeElapsed) < 0) {
priv->job.info.type = VIR_DOMAIN_JOB_FAILED;
return -1;
}
qemuMigrationCookiePtr mig = NULL;
bool tunnel = !!st;
- if (virTimeMs(&now) < 0)
+ if (virTimeMillisNow(&now) < 0)
return -1;
if (!(def = virDomainDefParseString(driver->caps, dom_xml,
#include "locking/domain_lock.h"
#include "network/bridge_driver.h"
#include "uuid.h"
+#include "virtime.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
* deleted while the monitor is active */
virDomainObjRef(vm);
- ignore_value(virTimeMs(&priv->monStart));
+ ignore_value(virTimeMillisNow(&priv->monStart));
virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
goto cleanup;
}
- if ((timestamp = virTimestamp()) == NULL) {
+ if ((timestamp = virTimeStringNow()) == NULL) {
virReportOOMError();
goto cleanup;
} else {
VIR_WARN("Unable to open logfile: %s",
virStrerror(errno, ebuf, sizeof ebuf));
} else {
- if ((timestamp = virTimestamp()) == NULL) {
+ if ((timestamp = virTimeStringNow()) == NULL) {
virReportOOMError();
} else {
if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 ||
priv->persistentAddrs = 0;
}
- if ((timestamp = virTimestamp()) == NULL) {
+ if ((timestamp = virTimeStringNow()) == NULL) {
virReportOOMError();
goto cleanup;
} else {
#include "virfile.h"
#include "ignore-value.h"
#include "virterror_internal.h"
+#include "virtime.h"
#define EVENT_DEBUG(fmt, ...) VIR_DEBUG(fmt, __VA_ARGS__)
{
unsigned long long now;
int ret;
+
EVENT_DEBUG("Adding timer %d with %d ms freq", nextTimer, frequency);
- if (virTimeMs(&now) < 0) {
+ if (virTimeMillisNow(&now) < 0) {
return -1;
}
return;
}
- if (virTimeMs(&now) < 0) {
+ if (virTimeMillisNow(&now) < 0) {
return;
}
if (then > 0) {
unsigned long long now;
- if (virTimeMs(&now) < 0)
+ if (virTimeMillisNow(&now) < 0)
return -1;
*timeout = then - now;
int ntimeouts = eventLoop.timeoutsCount;
VIR_DEBUG("Dispatch %d", ntimeouts);
- if (virTimeMs(&now) < 0)
+ if (virTimeMillisNow(&now) < 0)
return -1;
for (i = 0 ; i < ntimeouts ; i++) {
#include <fcntl.h>
#include <errno.h>
#include <poll.h>
-#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
-#include <sys/time.h>
#if HAVE_MMAP
# include <sys/mman.h>
#endif
return ret;
}
-/**
- * virTimestamp:
- *
- * Return an allocated string containing the current date and time,
- * followed by ": ". Return NULL on allocation failure.
- */
-char *
-virTimestamp(void)
-{
- struct timeval cur_time;
- struct tm time_info;
- char timestr[100];
- char *timestamp;
-
- gettimeofday(&cur_time, NULL);
- localtime_r(&cur_time.tv_sec, &time_info);
-
- strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", &time_info);
-
- if (virAsprintf(×tamp, "%s.%03d",
- timestr, (int) cur_time.tv_usec / 1000) < 0) {
- return NULL;
- }
-
- return timestamp;
-}
-
-#define timeval_to_ms(tv) (((tv).tv_sec * 1000ull) + ((tv).tv_usec / 1000))
-
-/**
- * virTimeMs:
- *
- * Get current time in milliseconds.
- *
- * Returns 0 on success, -1 on failure.
- */
-int
-virTimeMs(unsigned long long *ms)
-{
- struct timeval now;
-
- if (gettimeofday(&now, NULL) < 0) {
- virReportSystemError(errno, "%s",
- _("cannot get time of day"));
- return -1;
- }
-
- *ms = timeval_to_ms(now);
- return 0;
-}
-
#if HAVE_LIBDEVMAPPER_H
bool
virIsDevMapperDevice(const char *dev_name)
# define virBuildPath(path, ...) virBuildPathInternal(path, __VA_ARGS__, NULL)
int virBuildPathInternal(char **path, ...) ATTRIBUTE_SENTINEL;
-char *virTimestamp(void);
-
-int virTimeMs(unsigned long long *ms) ATTRIBUTE_NONNULL(1);
-
bool virIsDevMapperDevice(const char *dev_name) ATTRIBUTE_NONNULL(1);
int virEmitXMLWarning(int fd,