mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 07:05:28 +00:00
Remove time APIs from src/util/util.h
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
This commit is contained in:
parent
32d3ec7466
commit
a8bb75a3e6
@ -1134,8 +1134,6 @@ virStrToLong_ul;
|
|||||||
virStrToLong_ull;
|
virStrToLong_ull;
|
||||||
virStrcpy;
|
virStrcpy;
|
||||||
virStrncpy;
|
virStrncpy;
|
||||||
virTimeMs;
|
|
||||||
virTimestamp;
|
|
||||||
virTrimSpaces;
|
virTrimSpaces;
|
||||||
virTypedParameterArrayClear;
|
virTypedParameterArrayClear;
|
||||||
virVasprintf;
|
virVasprintf;
|
||||||
|
@ -57,6 +57,7 @@
|
|||||||
#include "network/bridge_driver.h"
|
#include "network/bridge_driver.h"
|
||||||
#include "virnetdev.h"
|
#include "virnetdev.h"
|
||||||
#include "virnodesuspend.h"
|
#include "virnodesuspend.h"
|
||||||
|
#include "virtime.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_LXC
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
||||||
|
|
||||||
@ -1847,7 +1848,7 @@ static int lxcVmStart(virConnectPtr conn,
|
|||||||
virCommandSetErrorFD(cmd, &logfd);
|
virCommandSetErrorFD(cmd, &logfd);
|
||||||
|
|
||||||
/* Log timestamp */
|
/* Log timestamp */
|
||||||
if ((timestamp = virTimestamp()) == NULL) {
|
if ((timestamp = virTimeStringNow()) == NULL) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
#include "virfile.h"
|
#include "virfile.h"
|
||||||
#include "domain_event.h"
|
#include "domain_event.h"
|
||||||
|
#include "virtime.h"
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -728,7 +729,7 @@ qemuDomainObjBeginJobInternal(struct qemud_driver *driver,
|
|||||||
|
|
||||||
priv->jobs_queued++;
|
priv->jobs_queued++;
|
||||||
|
|
||||||
if (virTimeMs(&now) < 0)
|
if (virTimeMillisNow(&now) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
then = now + QEMU_JOB_WAIT_TIME;
|
then = now + QEMU_JOB_WAIT_TIME;
|
||||||
|
|
||||||
@ -934,7 +935,7 @@ qemuDomainObjEnterMonitorInternal(struct qemud_driver *driver,
|
|||||||
|
|
||||||
qemuMonitorLock(priv->mon);
|
qemuMonitorLock(priv->mon);
|
||||||
qemuMonitorRef(priv->mon);
|
qemuMonitorRef(priv->mon);
|
||||||
ignore_value(virTimeMs(&priv->monStart));
|
ignore_value(virTimeMillisNow(&priv->monStart));
|
||||||
virDomainObjUnlock(obj);
|
virDomainObjUnlock(obj);
|
||||||
if (driver_locked)
|
if (driver_locked)
|
||||||
qemuDriverUnlock(driver);
|
qemuDriverUnlock(driver);
|
||||||
|
@ -89,6 +89,7 @@
|
|||||||
#include "locking/domain_lock.h"
|
#include "locking/domain_lock.h"
|
||||||
#include "virkeycode.h"
|
#include "virkeycode.h"
|
||||||
#include "virnodesuspend.h"
|
#include "virnodesuspend.h"
|
||||||
|
#include "virtime.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_QEMU
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
||||||
|
|
||||||
@ -2201,12 +2202,12 @@ qemuDomainGetControlInfo(virDomainPtr dom,
|
|||||||
} else if (priv->job.active) {
|
} else if (priv->job.active) {
|
||||||
if (!priv->monStart) {
|
if (!priv->monStart) {
|
||||||
info->state = VIR_DOMAIN_CONTROL_JOB;
|
info->state = VIR_DOMAIN_CONTROL_JOB;
|
||||||
if (virTimeMs(&info->stateTime) < 0)
|
if (virTimeMillisNow(&info->stateTime) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
info->stateTime -= priv->job.start;
|
info->stateTime -= priv->job.start;
|
||||||
} else {
|
} else {
|
||||||
info->state = VIR_DOMAIN_CONTROL_OCCUPIED;
|
info->state = VIR_DOMAIN_CONTROL_OCCUPIED;
|
||||||
if (virTimeMs(&info->stateTime) < 0)
|
if (virTimeMillisNow(&info->stateTime) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
info->stateTime -= priv->monStart;
|
info->stateTime -= priv->monStart;
|
||||||
}
|
}
|
||||||
@ -8879,7 +8880,7 @@ static int qemuDomainGetJobInfo(virDomainPtr dom,
|
|||||||
* of incoming migration which we don't currently
|
* of incoming migration which we don't currently
|
||||||
* monitor actively in the background thread
|
* monitor actively in the background thread
|
||||||
*/
|
*/
|
||||||
if (virTimeMs(&info->timeElapsed) < 0)
|
if (virTimeMillisNow(&info->timeElapsed) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
info->timeElapsed -= priv->job.start;
|
info->timeElapsed -= priv->job.start;
|
||||||
} else {
|
} else {
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include "datatypes.h"
|
#include "datatypes.h"
|
||||||
#include "fdstream.h"
|
#include "fdstream.h"
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
|
#include "virtime.h"
|
||||||
#include "locking/domain_lock.h"
|
#include "locking/domain_lock.h"
|
||||||
#include "rpc/virnetsocket.h"
|
#include "rpc/virnetsocket.h"
|
||||||
|
|
||||||
@ -866,7 +867,7 @@ qemuMigrationUpdateJobStatus(struct qemud_driver *driver,
|
|||||||
&memTotal);
|
&memTotal);
|
||||||
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
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;
|
priv->job.info.type = VIR_DOMAIN_JOB_FAILED;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1098,7 +1099,7 @@ qemuMigrationPrepareAny(struct qemud_driver *driver,
|
|||||||
bool tunnel = !!st;
|
bool tunnel = !!st;
|
||||||
char *origname = NULL;
|
char *origname = NULL;
|
||||||
|
|
||||||
if (virTimeMs(&now) < 0)
|
if (virTimeMillisNow(&now) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!(def = virDomainDefParseString(driver->caps, dom_xml,
|
if (!(def = virDomainDefParseString(driver->caps, dom_xml,
|
||||||
|
@ -60,6 +60,7 @@
|
|||||||
#include "locking/domain_lock.h"
|
#include "locking/domain_lock.h"
|
||||||
#include "network/bridge_driver.h"
|
#include "network/bridge_driver.h"
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
|
#include "virtime.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_QEMU
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
||||||
|
|
||||||
@ -849,7 +850,7 @@ qemuConnectMonitor(struct qemud_driver *driver, virDomainObjPtr vm)
|
|||||||
* deleted while the monitor is active */
|
* deleted while the monitor is active */
|
||||||
virDomainObjRef(vm);
|
virDomainObjRef(vm);
|
||||||
|
|
||||||
ignore_value(virTimeMs(&priv->monStart));
|
ignore_value(virTimeMillisNow(&priv->monStart));
|
||||||
virDomainObjUnlock(vm);
|
virDomainObjUnlock(vm);
|
||||||
qemuDriverUnlock(driver);
|
qemuDriverUnlock(driver);
|
||||||
|
|
||||||
@ -3053,7 +3054,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((timestamp = virTimestamp()) == NULL) {
|
if ((timestamp = virTimeStringNow()) == NULL) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
@ -3331,7 +3332,7 @@ void qemuProcessStop(struct qemud_driver *driver,
|
|||||||
VIR_WARN("Unable to open logfile: %s",
|
VIR_WARN("Unable to open logfile: %s",
|
||||||
virStrerror(errno, ebuf, sizeof ebuf));
|
virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
} else {
|
} else {
|
||||||
if ((timestamp = virTimestamp()) == NULL) {
|
if ((timestamp = virTimeStringNow()) == NULL) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
} else {
|
} else {
|
||||||
if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 ||
|
if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 ||
|
||||||
@ -3601,7 +3602,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
priv->persistentAddrs = 0;
|
priv->persistentAddrs = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((timestamp = virTimestamp()) == NULL) {
|
if ((timestamp = virTimeStringNow()) == NULL) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "virfile.h"
|
#include "virfile.h"
|
||||||
#include "ignore-value.h"
|
#include "ignore-value.h"
|
||||||
#include "virterror_internal.h"
|
#include "virterror_internal.h"
|
||||||
|
#include "virtime.h"
|
||||||
|
|
||||||
#define EVENT_DEBUG(fmt, ...) VIR_DEBUG(fmt, __VA_ARGS__)
|
#define EVENT_DEBUG(fmt, ...) VIR_DEBUG(fmt, __VA_ARGS__)
|
||||||
|
|
||||||
@ -214,7 +215,7 @@ int virEventPollAddTimeout(int frequency,
|
|||||||
unsigned long long now;
|
unsigned long long now;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (virTimeMs(&now) < 0) {
|
if (virTimeMillisNow(&now) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +263,7 @@ void virEventPollUpdateTimeout(int timer, int frequency)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virTimeMs(&now) < 0) {
|
if (virTimeMillisNow(&now) < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +338,7 @@ static int virEventPollCalculateTimeout(int *timeout) {
|
|||||||
if (then > 0) {
|
if (then > 0) {
|
||||||
unsigned long long now;
|
unsigned long long now;
|
||||||
|
|
||||||
if (virTimeMs(&now) < 0)
|
if (virTimeMillisNow(&now) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*timeout = then - now;
|
*timeout = then - now;
|
||||||
@ -413,7 +414,7 @@ static int virEventPollDispatchTimeouts(void)
|
|||||||
int ntimeouts = eventLoop.timeoutsCount;
|
int ntimeouts = eventLoop.timeoutsCount;
|
||||||
VIR_DEBUG("Dispatch %d", ntimeouts);
|
VIR_DEBUG("Dispatch %d", ntimeouts);
|
||||||
|
|
||||||
if (virTimeMs(&now) < 0)
|
if (virTimeMillisNow(&now) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (i = 0 ; i < ntimeouts ; i++) {
|
for (i = 0 ; i < ntimeouts ; i++) {
|
||||||
|
@ -33,12 +33,10 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <time.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/time.h>
|
|
||||||
#if HAVE_MMAP
|
#if HAVE_MMAP
|
||||||
# include <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
@ -2498,57 +2496,6 @@ int virBuildPathInternal(char **path, ...)
|
|||||||
return ret;
|
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
|
#if HAVE_LIBDEVMAPPER_H
|
||||||
bool
|
bool
|
||||||
virIsDevMapperDevice(const char *dev_name)
|
virIsDevMapperDevice(const char *dev_name)
|
||||||
|
@ -249,10 +249,6 @@ void virFileWaitForDevices(void);
|
|||||||
# define virBuildPath(path, ...) virBuildPathInternal(path, __VA_ARGS__, NULL)
|
# define virBuildPath(path, ...) virBuildPathInternal(path, __VA_ARGS__, NULL)
|
||||||
int virBuildPathInternal(char **path, ...) ATTRIBUTE_SENTINEL;
|
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);
|
bool virIsDevMapperDevice(const char *dev_name) ATTRIBUTE_NONNULL(1);
|
||||||
|
|
||||||
int virEmitXMLWarning(int fd,
|
int virEmitXMLWarning(int fd,
|
||||||
|
Loading…
Reference in New Issue
Block a user