]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Remove time APIs from src/util/util.h
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 29 Nov 2011 12:33:23 +0000 (12:33 +0000)
committerEric Blake <eblake@redhat.com>
Wed, 16 May 2012 23:06:04 +0000 (17:06 -0600)
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.

src/libvirt_private.syms
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
src/util/util.c
src/util/util.h

index b07676f9f445bd6cd27adb5231fcc808d8b7917c..b804b3476f2198e7a0922ba985ed19537db8b94a 100644 (file)
@@ -1131,8 +1131,6 @@ virStrToLong_ul;
 virStrToLong_ull;
 virStrcpy;
 virStrncpy;
-virTimeMs;
-virTimestamp;
 virTrimSpaces;
 virVasprintf;
 
index 6cf720366067ff482001cf1f6dfa32a72617a637..e7fb46d5f2f0f33fe29d554777ba89ebe2132646 100644 (file)
@@ -54,6 +54,7 @@
 #include "fdstream.h"
 #include "domain_audit.h"
 #include "domain_nwfilter.h"
+#include "virtime.h"
 
 #define VIR_FROM_THIS VIR_FROM_LXC
 
@@ -1580,7 +1581,7 @@ static int lxcVmStart(virConnectPtr conn,
         goto cleanup;
 
     /* Log timestamp */
-    if ((timestamp = virTimestamp()) == NULL) {
+    if ((timestamp = virTimeStringNow()) == NULL) {
         virReportOOMError();
         goto cleanup;
     }
index 402364818996d6bff98bb2b7a5a24661a999f687..66c0de91237d7e8004061c463bd4154a90fe1560 100644 (file)
@@ -35,6 +35,7 @@
 #include "ignore-value.h"
 #include "uuid.h"
 #include "virfile.h"
+#include "virtime.h"
 
 #include <sys/time.h>
 #include <fcntl.h>
@@ -717,7 +718,7 @@ qemuDomainObjBeginJobInternal(struct qemud_driver *driver,
 
     priv->jobs_queued++;
 
-    if (virTimeMs(&now) < 0)
+    if (virTimeMillisNow(&now) < 0)
         return -1;
     then = now + QEMU_JOB_WAIT_TIME;
 
@@ -911,7 +912,7 @@ qemuDomainObjEnterMonitorInternal(struct qemud_driver *driver,
 
     qemuMonitorLock(priv->mon);
     qemuMonitorRef(priv->mon);
-    ignore_value(virTimeMs(&priv->monStart));
+    ignore_value(virTimeMillisNow(&priv->monStart));
     virDomainObjUnlock(obj);
     if (driver_locked)
         qemuDriverUnlock(driver);
index 0d0bea2103c824f40115bd58033c6d7dc7ee81c9..09e0eaa9fb70b9b0b9e678aff9ecc855a7520372 100644 (file)
@@ -89,6 +89,7 @@
 #include "locking/lock_manager.h"
 #include "locking/domain_lock.h"
 #include "virkeycode.h"
+#include "virtime.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -2130,12 +2131,12 @@ qemuDomainGetControlInfo(virDomainPtr dom,
     } 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;
         }
@@ -8446,7 +8447,7 @@ static int qemuDomainGetJobInfo(virDomainPtr dom,
              * 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 {
index 4fd2e9f68f81acd89aef6e851ad3ce90e4ad3087..8fbf7b4a1f2247efc8d5f9a134597b6940ba6886 100644 (file)
@@ -42,6 +42,7 @@
 #include "datatypes.h"
 #include "fdstream.h"
 #include "uuid.h"
+#include "virtime.h"
 #include "locking/domain_lock.h"
 #include "rpc/virnetsocket.h"
 
@@ -790,7 +791,7 @@ qemuMigrationUpdateJobStatus(struct qemud_driver *driver,
                                         &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;
     }
@@ -1003,7 +1004,7 @@ qemuMigrationPrepareAny(struct qemud_driver *driver,
     qemuMigrationCookiePtr mig = NULL;
     bool tunnel = !!st;
 
-    if (virTimeMs(&now) < 0)
+    if (virTimeMillisNow(&now) < 0)
         return -1;
 
     if (!(def = virDomainDefParseString(driver->caps, dom_xml,
index c8f22e2d8a5e5d5690775c9edfbfe2445efb7e07..1b895f6b4a4c60a2188958eb3511f3450c526146 100644 (file)
@@ -60,6 +60,7 @@
 #include "locking/domain_lock.h"
 #include "network/bridge_driver.h"
 #include "uuid.h"
+#include "virtime.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -845,7 +846,7 @@ qemuConnectMonitor(struct qemud_driver *driver, virDomainObjPtr vm)
      * deleted while the monitor is active */
     virDomainObjRef(vm);
 
-    ignore_value(virTimeMs(&priv->monStart));
+    ignore_value(virTimeMillisNow(&priv->monStart));
     virDomainObjUnlock(vm);
     qemuDriverUnlock(driver);
 
@@ -3012,7 +3013,7 @@ int qemuProcessStart(virConnectPtr conn,
             goto cleanup;
     }
 
-    if ((timestamp = virTimestamp()) == NULL) {
+    if ((timestamp = virTimeStringNow()) == NULL) {
         virReportOOMError();
         goto cleanup;
     } else {
@@ -3290,7 +3291,7 @@ void qemuProcessStop(struct qemud_driver *driver,
         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 ||
@@ -3560,7 +3561,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
         priv->persistentAddrs = 0;
     }
 
-    if ((timestamp = virTimestamp()) == NULL) {
+    if ((timestamp = virTimeStringNow()) == NULL) {
         virReportOOMError();
         goto cleanup;
     } else {
index e8679b8e59b6971ae9349b17b92e8d137d7dca4f..97118d9ce276b23c1a845b69e1af82bb074b21ba 100644 (file)
@@ -39,6 +39,7 @@
 #include "virfile.h"
 #include "ignore-value.h"
 #include "virterror_internal.h"
+#include "virtime.h"
 
 #define EVENT_DEBUG(fmt, ...) VIR_DEBUG(fmt, __VA_ARGS__)
 
@@ -206,8 +207,9 @@ int virEventPollAddTimeout(int frequency,
 {
     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;
     }
 
@@ -249,7 +251,7 @@ void virEventPollUpdateTimeout(int timer, int frequency)
         return;
     }
 
-    if (virTimeMs(&now) < 0) {
+    if (virTimeMillisNow(&now) < 0) {
         return;
     }
 
@@ -322,7 +324,7 @@ static int virEventPollCalculateTimeout(int *timeout) {
     if (then > 0) {
         unsigned long long now;
 
-        if (virTimeMs(&now) < 0)
+        if (virTimeMillisNow(&now) < 0)
             return -1;
 
         *timeout = then - now;
@@ -398,7 +400,7 @@ static int virEventPollDispatchTimeouts(void)
     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++) {
index 1ff287d008b9ac5cec3af1ce9016feaf545d84f3..9b30f1e68dc8aa8d70140071ab28ecfd44c796cb 100644 (file)
 #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
@@ -2402,57 +2400,6 @@ int virBuildPathInternal(char **path, ...)
     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(&timestamp, "%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)
index c55e85279f26ff99f52d0f32be5e84b0af95d2d4..afa22212e95038c754697436338e23375bb6bc3b 100644 (file)
@@ -251,10 +251,6 @@ void virFileWaitForDevices(void);
 # 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,