Because virCond usage is connected to virMutex, this patch also converts
virCond to GCond.
An important note to make here: GMutex doesn't like when you try to
clear a lock that's still locked. So I had to hunt the few cases where
that happened and add an explicit virObjectUnlock call before unreffing
the object.
Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/conf/domain_conf.c | 27 ++-------
src/conf/domain_conf.h | 5 +-
src/libxl/libxl_domain.c | 18 ++----
src/libxl/libxl_domain.h | 2 +-
src/lxc/lxc_domain.c | 18 ++----
src/lxc/lxc_domain.h | 2 +-
src/node_device/node_device_udev.c | 22 +++----
src/qemu/qemu_agent.c | 50 +++++++---------
src/qemu/qemu_domain.c | 95 ++++++++++++++----------------
src/qemu/qemu_domain.h | 4 +-
src/qemu/qemu_hotplug.c | 28 +++------
src/qemu/qemu_hotplug.h | 2 +-
src/qemu/qemu_monitor.c | 27 ++++-----
src/rpc/virnetclient.c | 25 +++-----
src/util/virfdstream.c | 26 +++-----
src/util/virobject.c | 13 ++--
src/util/virobject.h | 2 +-
src/vz/vz_utils.c | 41 ++++---------
src/vz/vz_utils.h | 6 +-
tests/qemuhotplugmock.c | 6 +-
tests/qemuhotplugtest.c | 2 +
tests/qemumonitortestutils.c | 5 ++
tests/qemusecuritytest.c | 10 +++-
tests/qemuxml2argvtest.c | 1 +
tools/virsh-console.c | 23 ++------
25 files changed, 172 insertions(+), 288 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 639d471424..d4629a936a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3535,7 +3535,7 @@ static void virDomainObjDispose(void *obj)
virDomainObjPtr dom = obj;
VIR_DEBUG("obj=%p", dom);
- virCondDestroy(&dom->cond);
+ g_cond_clear(&dom->cond);
virDomainDefFree(dom->def);
virDomainDefFree(dom->newDef);
@@ -3557,11 +3557,7 @@ virDomainObjNew(virDomainXMLOptionPtr xmlopt)
if (!(domain = virObjectLockableNew(virDomainObjClass)))
return NULL;
- if (virCondInit(&domain->cond) < 0) {
- virReportSystemError(errno, "%s",
- _("failed to initialize domain condition"));
- goto error;
- }
+ g_cond_init(&domain->cond);
if (xmlopt->privateData.alloc) {
domain->privateData = (xmlopt->privateData.alloc)(xmlopt->config.priv);
@@ -3670,18 +3666,14 @@ virDomainObjEndAPI(virDomainObjPtr *vm)
void
virDomainObjBroadcast(virDomainObjPtr vm)
{
- virCondBroadcast(&vm->cond);
+ g_cond_broadcast(&vm->cond);
}
int
virDomainObjWait(virDomainObjPtr vm)
{
- if (virCondWait(&vm->cond, &vm->parent.lock) < 0) {
- virReportSystemError(errno, "%s",
- _("failed to wait for domain condition"));
- return -1;
- }
+ g_cond_wait(&vm->cond, &vm->parent.lock);
if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
@@ -3697,22 +3689,15 @@ virDomainObjWait(virDomainObjPtr vm)
* Waits for domain condition to be triggered for a specific period of time.
*
* Returns:
- * -1 in case of error
* 0 on success
* 1 on timeout
*/
int
virDomainObjWaitUntil(virDomainObjPtr vm,
- unsigned long long whenms)
+ gint64 whenms)
{
- if (virCondWaitUntil(&vm->cond, &vm->parent.lock, whenms) < 0) {
- if (errno != ETIMEDOUT) {
- virReportSystemError(errno, "%s",
- _("failed to wait for domain condition"));
- return -1;
- }
+ if (!g_cond_wait_until(&vm->cond, &vm->parent.lock, whenms))
return 1;
- }
return 0;
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 9310fab169..647baf40b2 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2630,7 +2630,7 @@ struct _virDomainStateReason {
struct _virDomainObj {
virObjectLockable parent;
- virCond cond;
+ GCond cond;
pid_t pid;
virDomainStateReason state;
@@ -2892,8 +2892,7 @@ bool virDomainObjTaint(virDomainObjPtr obj,
void virDomainObjBroadcast(virDomainObjPtr vm);
int virDomainObjWait(virDomainObjPtr vm);
-int virDomainObjWaitUntil(virDomainObjPtr vm,
- unsigned long long whenms);
+int virDomainObjWaitUntil(virDomainObjPtr vm, gint64 whenms);
void virDomainPanicDefFree(virDomainPanicDefPtr panic);
void virDomainResourceDefFree(virDomainResourceDefPtr resource);
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index cc53a765e1..671e49670b 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -69,8 +69,7 @@ libxlDomainObjInitJob(libxlDomainObjPrivatePtr priv)
{
memset(&priv->job, 0, sizeof(priv->job));
- if (virCondInit(&priv->job.cond) < 0)
- return -1;
+ g_cond_init(&priv->job.cond);
if (VIR_ALLOC(priv->job.current) < 0)
return -1;
@@ -90,12 +89,12 @@ libxlDomainObjResetJob(libxlDomainObjPrivatePtr priv)
static void
libxlDomainObjFreeJob(libxlDomainObjPrivatePtr priv)
{
- ignore_value(virCondDestroy(&priv->job.cond));
+ g_cond_clear(&priv->job.cond);
VIR_FREE(priv->job.current);
}
/* Give up waiting for mutex after 30 seconds */
-#define LIBXL_JOB_WAIT_TIME (1000ull * 30)
+#define LIBXL_JOB_WAIT_TIME (30 * G_TIME_SPAN_SECOND)
/*
* obj must be locked before calling, libxlDriverPrivatePtr must NOT be locked
@@ -112,17 +111,12 @@ libxlDomainObjBeginJob(libxlDriverPrivatePtr driver G_GNUC_UNUSED,
enum libxlDomainJob job)
{
libxlDomainObjPrivatePtr priv = obj->privateData;
- unsigned long long now;
- unsigned long long then;
-
- if (virTimeMillisNow(&now) < 0)
- return -1;
- then = now + LIBXL_JOB_WAIT_TIME;
+ gint64 then = g_get_monotonic_time() + LIBXL_JOB_WAIT_TIME;
while (priv->job.active) {
VIR_DEBUG("Wait normal job condition for starting job: %s",
libxlDomainJobTypeToString(job));
- if (virCondWaitUntil(&priv->job.cond, &obj->parent.lock, then) <
0)
+ if (!g_cond_wait_until(&priv->job.cond, &obj->parent.lock, then))
goto error;
}
@@ -175,7 +169,7 @@ libxlDomainObjEndJob(libxlDriverPrivatePtr driver G_GNUC_UNUSED,
libxlDomainJobTypeToString(job));
libxlDomainObjResetJob(priv);
- virCondSignal(&priv->job.cond);
+ g_cond_signal(&priv->job.cond);
}
int
diff --git a/src/libxl/libxl_domain.h b/src/libxl/libxl_domain.h
index 7e28093722..5f04f3aacb 100644
--- a/src/libxl/libxl_domain.h
+++ b/src/libxl/libxl_domain.h
@@ -47,7 +47,7 @@ VIR_ENUM_DECL(libxlDomainJob);
struct libxlDomainJobObj {
- virCond cond; /* Use to coordinate jobs */
+ GCond cond; /* Use to coordinate jobs */
enum libxlDomainJob active; /* Currently running job */
int owner; /* Thread which set current job */
unsigned long long started; /* When the job started */
diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c
index 59f803837a..a09788dd12 100644
--- a/src/lxc/lxc_domain.c
+++ b/src/lxc/lxc_domain.c
@@ -50,8 +50,7 @@ virLXCDomainObjInitJob(virLXCDomainObjPrivatePtr priv)
{
memset(&priv->job, 0, sizeof(priv->job));
- if (virCondInit(&priv->job.cond) < 0)
- return -1;
+ g_cond_init(&priv->job.cond);
return 0;
}
@@ -68,11 +67,11 @@ virLXCDomainObjResetJob(virLXCDomainObjPrivatePtr priv)
static void
virLXCDomainObjFreeJob(virLXCDomainObjPrivatePtr priv)
{
- ignore_value(virCondDestroy(&priv->job.cond));
+ g_cond_clear(&priv->job.cond);
}
/* Give up waiting for mutex after 30 seconds */
-#define LXC_JOB_WAIT_TIME (1000ull * 30)
+#define LXC_JOB_WAIT_TIME (30 * G_TIME_SPAN_SECOND)
/*
* obj must be locked before calling, virLXCDriverPtr must NOT be locked
@@ -89,17 +88,12 @@ virLXCDomainObjBeginJob(virLXCDriverPtr driver G_GNUC_UNUSED,
enum virLXCDomainJob job)
{
virLXCDomainObjPrivatePtr priv = obj->privateData;
- unsigned long long now;
- unsigned long long then;
-
- if (virTimeMillisNow(&now) < 0)
- return -1;
- then = now + LXC_JOB_WAIT_TIME;
+ gint64 then = g_get_monotonic_time() + LXC_JOB_WAIT_TIME;
while (priv->job.active) {
VIR_DEBUG("Wait normal job condition for starting job: %s",
virLXCDomainJobTypeToString(job));
- if (virCondWaitUntil(&priv->job.cond, &obj->parent.lock, then) <
0)
+ if (!g_cond_wait_until(&priv->job.cond, &obj->parent.lock, then))
goto error;
}
@@ -146,7 +140,7 @@ virLXCDomainObjEndJob(virLXCDriverPtr driver G_GNUC_UNUSED,
virLXCDomainJobTypeToString(job));
virLXCDomainObjResetJob(priv);
- virCondSignal(&priv->job.cond);
+ g_cond_signal(&priv->job.cond);
}
diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h
index 319f83338f..dfc16fae2b 100644
--- a/src/lxc/lxc_domain.h
+++ b/src/lxc/lxc_domain.h
@@ -69,7 +69,7 @@ VIR_ENUM_DECL(virLXCDomainJob);
struct virLXCDomainJobObj {
- virCond cond; /* Use to coordinate jobs */
+ GCond cond; /* Use to coordinate jobs */
enum virLXCDomainJob active; /* Currently running job */
int owner; /* Thread which set current job */
};
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 433de0aae0..22106c3f30 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -63,7 +63,7 @@ struct _udevEventData {
/* Thread data */
virThread th;
- virCond threadCond;
+ GCond threadCond;
bool threadQuit;
bool dataReady;
};
@@ -86,7 +86,7 @@ udevEventDataDispose(void *obj)
udev_monitor_unref(priv->udev_monitor);
udev_unref(udev);
- virCondDestroy(&priv->threadCond);
+ g_cond_clear(&priv->threadCond);
}
@@ -112,10 +112,7 @@ udevEventDataNew(void)
if (!(ret = virObjectLockableNew(udevEventDataClass)))
return NULL;
- if (virCondInit(&ret->threadCond) < 0) {
- virObjectUnref(ret);
- return NULL;
- }
+ g_cond_init(&ret->threadCond);
ret->watch = -1;
return ret;
@@ -1463,7 +1460,7 @@ nodeStateCleanup(void)
if (priv) {
virObjectLock(priv);
priv->threadQuit = true;
- virCondSignal(&priv->threadCond);
+ g_cond_signal(&priv->threadCond);
virObjectUnlock(priv);
virThreadJoin(&priv->th);
}
@@ -1563,12 +1560,7 @@ udevEventHandleThread(void *opaque G_GNUC_UNUSED)
while (1) {
virObjectLock(priv);
while (!priv->dataReady && !priv->threadQuit) {
- if (virCondWait(&priv->threadCond, &priv->parent.lock)) {
- virReportSystemError(errno, "%s",
- _("handler failed to wait on
condition"));
- virObjectUnlock(priv);
- return;
- }
+ g_cond_wait(&priv->threadCond, &priv->parent.lock);
}
if (priv->threadQuit) {
@@ -1635,7 +1627,7 @@ udevEventHandleCallback(int watch G_GNUC_UNUSED,
else
priv->dataReady = true;
- virCondSignal(&priv->threadCond);
+ g_cond_signal(&priv->threadCond);
virObjectUnlock(priv);
}
@@ -1757,7 +1749,7 @@ nodeStateInitializeEnumerate(void *opaque)
ignore_value(virEventRemoveHandle(priv->watch));
priv->watch = -1;
priv->threadQuit = true;
- virCondSignal(&priv->threadCond);
+ g_cond_signal(&priv->threadCond);
virObjectUnlock(priv);
}
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index d7fcc869c6..597df38752 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -99,7 +99,7 @@ struct _qemuAgentMessage {
struct _qemuAgent {
virObjectLockable parent;
- virCond notify;
+ GCond notify;
int fd;
@@ -176,7 +176,7 @@ static void qemuAgentDispose(void *obj)
VIR_DEBUG("agent=%p", agent);
if (agent->cb && agent->cb->destroy)
(agent->cb->destroy)(agent, agent->vm);
- virCondDestroy(&agent->notify);
+ g_cond_clear(&agent->notify);
VIR_FREE(agent->buffer);
g_main_context_unref(agent->context);
virResetError(&agent->lastError);
@@ -403,7 +403,7 @@ qemuAgentIOProcess(qemuAgentPtr agent)
VIR_DEBUG("Process done %zu used %d", agent->bufferOffset, len);
#endif
if (msg && msg->finished)
- virCondBroadcast(&agent->notify);
+ g_cond_broadcast(&agent->notify);
return len;
}
@@ -628,7 +628,7 @@ qemuAgentIO(GSocket *socket G_GNUC_UNUSED,
* then wakeup that waiter */
if (agent->msg && !agent->msg->finished) {
agent->msg->finished = 1;
- virCondSignal(&agent->notify);
+ g_cond_signal(&agent->notify);
}
}
@@ -643,7 +643,7 @@ qemuAgentIO(GSocket *socket G_GNUC_UNUSED,
virDomainObjPtr vm = agent->vm;
/* Make sure anyone waiting wakes up now */
- virCondSignal(&agent->notify);
+ g_cond_signal(&agent->notify);
virObjectUnlock(agent);
virObjectUnref(agent);
VIR_DEBUG("Triggering EOF callback");
@@ -654,7 +654,7 @@ qemuAgentIO(GSocket *socket G_GNUC_UNUSED,
virDomainObjPtr vm = agent->vm;
/* Make sure anyone waiting wakes up now */
- virCondSignal(&agent->notify);
+ g_cond_signal(&agent->notify);
virObjectUnlock(agent);
virObjectUnref(agent);
VIR_DEBUG("Triggering error callback");
@@ -692,12 +692,8 @@ qemuAgentOpen(virDomainObjPtr vm,
agent->timeout = QEMU_DOMAIN_PRIVATE(vm)->agentTimeout;
agent->fd = -1;
- if (virCondInit(&agent->notify) < 0) {
- virReportSystemError(errno, "%s",
- _("cannot initialize agent condition"));
- virObjectUnref(agent);
- return NULL;
- }
+ g_cond_init(&agent->notify);
+
agent->vm = vm;
agent->cb = cb;
agent->singleSync = singleSync;
@@ -752,7 +748,7 @@ qemuAgentNotifyCloseLocked(qemuAgentPtr agent)
* wake him up. No message will arrive anyway. */
if (agent->msg && !agent->msg->finished) {
agent->msg->finished = 1;
- virCondSignal(&agent->notify);
+ g_cond_signal(&agent->notify);
}
}
}
@@ -820,7 +816,7 @@ static int qemuAgentSend(qemuAgentPtr agent,
int seconds)
{
int ret = -1;
- unsigned long long then = 0;
+ gint64 then = 0;
/* Check whether qemu quit unexpectedly */
if (agent->lastError.code != VIR_ERR_OK) {
@@ -831,29 +827,23 @@ static int qemuAgentSend(qemuAgentPtr agent,
}
if (seconds > VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) {
- unsigned long long now;
- if (virTimeMillisNow(&now) < 0)
- return -1;
if (seconds == VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT)
seconds = QEMU_AGENT_WAIT_TIME;
- then = now + seconds * 1000ull;
+ then = g_get_monotonic_time() + seconds * G_TIME_SPAN_SECOND;
}
agent->msg = msg;
qemuAgentUpdateWatch(agent);
while (!agent->msg->finished) {
- if ((then && virCondWaitUntil(&agent->notify,
&agent->parent.lock, then) < 0) ||
- (!then && virCondWait(&agent->notify,
&agent->parent.lock) < 0)) {
- if (errno == ETIMEDOUT) {
- virReportError(VIR_ERR_AGENT_UNRESPONSIVE, "%s",
- _("Guest agent not available for now"));
- ret = -2;
- } else {
- virReportSystemError(errno, "%s",
- _("Unable to wait on agent socket "
- "condition"));
- }
+ if (!then) {
+ g_cond_wait(&agent->notify, &agent->parent.lock);
+ } else if (!g_cond_wait_until(&agent->notify,
+ &agent->parent.lock,
+ then)) {
+ virReportError(VIR_ERR_AGENT_UNRESPONSIVE, "%s",
+ _("Guest agent not available for now"));
+ ret = -2;
agent->inSync = false;
goto cleanup;
}
@@ -1210,7 +1200,7 @@ void qemuAgentNotifyEvent(qemuAgentPtr agent,
/* somebody waiting for this event, wake him up. */
if (agent->msg && !agent->msg->finished) {
agent->msg->finished = 1;
- virCondSignal(&agent->notify);
+ g_cond_signal(&agent->notify);
}
}
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 91e234d644..ac02f54cb8 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -334,13 +334,8 @@ qemuDomainObjInitJob(qemuDomainObjPrivatePtr priv)
{
memset(&priv->job, 0, sizeof(priv->job));
- if (virCondInit(&priv->job.cond) < 0)
- return -1;
-
- if (virCondInit(&priv->job.asyncCond) < 0) {
- virCondDestroy(&priv->job.cond);
- return -1;
- }
+ g_cond_init(&priv->job.cond);
+ g_cond_init(&priv->job.asyncCond);
return 0;
}
@@ -417,8 +412,8 @@ qemuDomainObjFreeJob(qemuDomainObjPrivatePtr priv)
qemuDomainObjResetAsyncJob(priv);
VIR_FREE(priv->job.current);
VIR_FREE(priv->job.completed);
- virCondDestroy(&priv->job.cond);
- virCondDestroy(&priv->job.asyncCond);
+ g_cond_clear(&priv->job.cond);
+ g_cond_clear(&priv->job.asyncCond);
}
static bool
@@ -6181,7 +6176,7 @@ qemuDomainObjCanSetJob(qemuDomainObjPrivatePtr priv,
}
/* Give up waiting for mutex after 30 seconds */
-#define QEMU_JOB_WAIT_TIME (1000ull * 30)
+#define QEMU_JOB_WAIT_TIME (30 * G_TIME_SPAN_SECOND)
/**
* qemuDomainObjBeginJobInternal:
@@ -6214,17 +6209,16 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
bool nowait)
{
qemuDomainObjPrivatePtr priv = obj->privateData;
- unsigned long long now;
- unsigned long long then;
+ gint64 now, then = 0;
bool nested = job == QEMU_JOB_ASYNC_NESTED;
bool async = job == QEMU_JOB_ASYNC;
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
const char *blocker = NULL;
const char *agentBlocker = NULL;
int ret = -1;
- unsigned long long duration = 0;
- unsigned long long agentDuration = 0;
- unsigned long long asyncDuration = 0;
+ gint64 duration = 0;
+ gint64 agentDuration = 0;
+ gint64 asyncDuration = 0;
VIR_DEBUG("Starting job: job=%s agentJob=%s asyncJob=%s "
"(vm=%p name=%s, current job=%s agentJob=%s async=%s)",
@@ -6236,11 +6230,8 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
qemuDomainAgentJobTypeToString(priv->job.agentActive),
qemuDomainAsyncJobTypeToString(priv->job.asyncJob));
- if (virTimeMillisNow(&now) < 0)
- return -1;
-
priv->jobs_queued++;
- then = now + QEMU_JOB_WAIT_TIME;
+ then = g_get_monotonic_time() + QEMU_JOB_WAIT_TIME;
retry:
if ((!async && job != QEMU_JOB_DESTROY) &&
@@ -6254,7 +6245,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
goto cleanup;
VIR_DEBUG("Waiting for async job (vm=%p name=%s)", obj,
obj->def->name);
- if (virCondWaitUntil(&priv->job.asyncCond, &obj->parent.lock, then)
< 0)
+ if (!g_cond_wait_until(&priv->job.asyncCond, &obj->parent.lock,
then))
goto error;
}
@@ -6263,7 +6254,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
goto cleanup;
VIR_DEBUG("Waiting for job (vm=%p name=%s)", obj,
obj->def->name);
- if (virCondWaitUntil(&priv->job.cond, &obj->parent.lock, then) <
0)
+ if (!g_cond_wait_until(&priv->job.cond, &obj->parent.lock, then))
goto error;
}
@@ -6272,7 +6263,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
if (!nested && !qemuDomainNestedJobAllowed(priv, job))
goto retry;
- ignore_value(virTimeMillisNow(&now));
+ now = g_get_monotonic_time();
if (job) {
qemuDomainObjResetJob(priv);
@@ -6322,7 +6313,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
return 0;
error:
- ignore_value(virTimeMillisNow(&now));
+ now = g_get_monotonic_time();
if (priv->job.active && priv->job.started)
duration = now - priv->job.started;
if (priv->job.agentActive && priv->job.agentStarted)
@@ -6333,7 +6324,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
VIR_WARN("Cannot start job (%s, %s, %s) for domain %s; "
"current job is (%s, %s, %s) "
"owned by (%llu %s, %llu %s, %llu %s (flags=0x%lx)) "
- "for (%llus, %llus, %llus)",
+ "for (%"G_GINT64_FORMAT"s, %"G_GINT64_FORMAT"s,
%"G_GINT64_FORMAT"s)",
qemuDomainJobTypeToString(job),
qemuDomainAgentJobTypeToString(agentJob),
qemuDomainAsyncJobTypeToString(asyncJob),
@@ -6345,7 +6336,9 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
priv->job.agentOwner, NULLSTR(priv->job.agentOwnerAPI),
priv->job.asyncOwner, NULLSTR(priv->job.asyncOwnerAPI),
priv->job.apiFlags,
- duration / 1000, agentDuration / 1000, asyncDuration / 1000);
+ duration / G_TIME_SPAN_MILLISECOND,
+ agentDuration / G_TIME_SPAN_MILLISECOND,
+ asyncDuration / G_TIME_SPAN_MILLISECOND);
if (job) {
if (nested || qemuDomainNestedJobAllowed(priv, job))
@@ -6357,29 +6350,8 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
if (agentJob)
agentBlocker = priv->job.agentOwnerAPI;
- if (errno == ETIMEDOUT) {
- if (blocker && agentBlocker) {
- virReportError(VIR_ERR_OPERATION_TIMEOUT,
- _("cannot acquire state change "
- "lock (held by monitor=%s agent=%s)"),
- blocker, agentBlocker);
- } else if (blocker) {
- virReportError(VIR_ERR_OPERATION_TIMEOUT,
- _("cannot acquire state change "
- "lock (held by monitor=%s)"),
- blocker);
- } else if (agentBlocker) {
- virReportError(VIR_ERR_OPERATION_TIMEOUT,
- _("cannot acquire state change "
- "lock (held by agent=%s)"),
- agentBlocker);
- } else {
- virReportError(VIR_ERR_OPERATION_TIMEOUT, "%s",
- _("cannot acquire state change lock"));
- }
- ret = -2;
- } else if (cfg->maxQueuedJobs &&
- priv->jobs_queued > cfg->maxQueuedJobs) {
+ if (cfg->maxQueuedJobs &&
+ priv->jobs_queued > cfg->maxQueuedJobs) {
if (blocker && agentBlocker) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("cannot acquire state change "
@@ -6405,7 +6377,26 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
}
ret = -2;
} else {
- virReportSystemError(errno, "%s", _("cannot acquire job
mutex"));
+ if (blocker && agentBlocker) {
+ virReportError(VIR_ERR_OPERATION_TIMEOUT,
+ _("cannot acquire state change "
+ "lock (held by monitor=%s agent=%s)"),
+ blocker, agentBlocker);
+ } else if (blocker) {
+ virReportError(VIR_ERR_OPERATION_TIMEOUT,
+ _("cannot acquire state change "
+ "lock (held by monitor=%s)"),
+ blocker);
+ } else if (agentBlocker) {
+ virReportError(VIR_ERR_OPERATION_TIMEOUT,
+ _("cannot acquire state change "
+ "lock (held by agent=%s)"),
+ agentBlocker);
+ } else {
+ virReportError(VIR_ERR_OPERATION_TIMEOUT, "%s",
+ _("cannot acquire state change lock"));
+ }
+ ret = -2;
}
cleanup:
@@ -6542,7 +6533,7 @@ qemuDomainObjEndJob(virQEMUDriverPtr driver, virDomainObjPtr obj)
qemuDomainObjSaveStatus(driver, obj);
/* We indeed need to wake up ALL threads waiting because
* grabbing a job requires checking more variables. */
- virCondBroadcast(&priv->job.cond);
+ g_cond_broadcast(&priv->job.cond);
}
void
@@ -6561,7 +6552,7 @@ qemuDomainObjEndAgentJob(virDomainObjPtr obj)
qemuDomainObjResetAgentJob(priv);
/* We indeed need to wake up ALL threads waiting because
* grabbing a job requires checking more variables. */
- virCondBroadcast(&priv->job.cond);
+ g_cond_broadcast(&priv->job.cond);
}
void
@@ -6577,7 +6568,7 @@ qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver, virDomainObjPtr
obj)
qemuDomainObjResetAsyncJob(priv);
qemuDomainObjSaveStatus(driver, obj);
- virCondBroadcast(&priv->job.asyncCond);
+ g_cond_broadcast(&priv->job.asyncCond);
}
void
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index cf19f4d101..0d1bafac94 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -180,7 +180,7 @@ struct _qemuDomainJobInfo {
typedef struct _qemuDomainJobObj qemuDomainJobObj;
typedef qemuDomainJobObj *qemuDomainJobObjPtr;
struct _qemuDomainJobObj {
- virCond cond; /* Use to coordinate jobs */
+ GCond cond; /* Use to coordinate jobs */
/* The following members are for QEMU_JOB_* */
qemuDomainJob active; /* Currently running job */
@@ -195,7 +195,7 @@ struct _qemuDomainJobObj {
unsigned long long agentStarted; /* When the current agent job started */
/* The following members are for QEMU_ASYNC_JOB_* */
- virCond asyncCond; /* Use to coordinate with async jobs */
+ GCond asyncCond; /* Use to coordinate with async jobs */
qemuDomainAsyncJob asyncJob; /* Currently active async job */
unsigned long long asyncOwner; /* Thread which set current async job */
const char *asyncOwnerAPI; /* The API which owns the async job */
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 14654a17d7..0e677bdce9 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -59,14 +59,14 @@
VIR_LOG_INIT("qemu.qemu_hotplug");
-#define CHANGE_MEDIA_TIMEOUT 5000
+#define CHANGE_MEDIA_TIMEOUT (5 * G_TIME_SPAN_MILLISECOND)
/* Timeout in miliseconds for device removal. PPC64 domains
* can experience a bigger delay in unplug operations during
* heavy guest activity (vcpu being the most notable case), thus
* the timeout for PPC64 is also bigger. */
-#define QEMU_UNPLUG_TIMEOUT 1000ull * 5
-#define QEMU_UNPLUG_TIMEOUT_PPC64 1000ull * 10
+#define QEMU_UNPLUG_TIMEOUT (5 * G_TIME_SPAN_MILLISECOND)
+#define QEMU_UNPLUG_TIMEOUT_PPC64 (10 * G_TIME_SPAN_MILLISECOND)
static void
@@ -201,15 +201,11 @@ static int
qemuHotplugWaitForTrayEject(virDomainObjPtr vm,
virDomainDiskDefPtr disk)
{
- unsigned long long now;
+ gint64 now = g_get_monotonic_time();
int rc;
- if (virTimeMillisNow(&now) < 0)
- return -1;
-
while (disk->tray_status != VIR_DOMAIN_DISK_TRAY_OPEN) {
- if ((rc = virDomainObjWaitUntil(vm, now + CHANGE_MEDIA_TIMEOUT)) < 0)
- return -1;
+ rc = virDomainObjWaitUntil(vm, now + CHANGE_MEDIA_TIMEOUT);
if (rc > 0) {
/* the caller called qemuMonitorEjectMedia which usually reports an
@@ -5122,7 +5118,7 @@ qemuDomainResetDeviceRemoval(virDomainObjPtr vm)
}
-unsigned long long
+gint64
qemuDomainGetUnplugTimeout(virDomainObjPtr vm)
{
if (qemuDomainIsPSeries(vm->def))
@@ -5145,22 +5141,14 @@ static int
qemuDomainWaitForDeviceRemoval(virDomainObjPtr vm)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
- unsigned long long until;
+ gint64 until;
int rc;
- if (virTimeMillisNow(&until) < 0)
- return 1;
- until += qemuDomainGetUnplugTimeout(vm);
+ until = g_get_monotonic_time() + qemuDomainGetUnplugTimeout(vm);
while (priv->unplug.alias) {
if ((rc = virDomainObjWaitUntil(vm, until)) == 1)
return 0;
-
- if (rc < 0) {
- VIR_WARN("Failed to wait on unplug condition for domain '%s'
"
- "device '%s'", vm->def->name,
priv->unplug.alias);
- return 1;
- }
}
if (priv->unplug.status == QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_GUEST_REJECTED) {
diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index 4a49e04a15..f610d7c70f 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -151,7 +151,7 @@ int qemuDomainSetVcpuInternal(virQEMUDriverPtr driver,
virBitmapPtr vcpus,
bool state);
-unsigned long long qemuDomainGetUnplugTimeout(virDomainObjPtr vm);
+gint64 qemuDomainGetUnplugTimeout(virDomainObjPtr vm);
int qemuHotplugAttachDBusVMState(virQEMUDriverPtr driver,
virDomainObjPtr vm,
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index a62fed845e..4537b3e562 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -70,7 +70,7 @@ VIR_LOG_INIT("qemu.qemu_monitor");
struct _qemuMonitor {
virObjectLockable parent;
- virCond notify;
+ GCond notify;
int fd;
@@ -228,7 +228,7 @@ qemuMonitorDispose(void *obj)
g_main_context_unref(mon->context);
virResetError(&mon->lastError);
- virCondDestroy(&mon->notify);
+ g_cond_clear(&mon->notify);
VIR_FREE(mon->buffer);
virJSONValueFree(mon->options);
VIR_FREE(mon->balloonpath);
@@ -357,7 +357,7 @@ qemuMonitorIOProcess(qemuMonitorPtr mon)
* while dealing with qemu event, mon->msg could be changed which
* means the above 'msg' may be invalid, thus we use 'mon->msg'
here */
if (mon->msg && mon->msg->finished)
- virCondBroadcast(&mon->notify);
+ g_cond_broadcast(&mon->notify);
return len;
}
@@ -618,7 +618,7 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNUSED,
* then wakeup that waiter */
if (mon->msg && !mon->msg->finished) {
mon->msg->finished = 1;
- virCondSignal(&mon->notify);
+ g_cond_signal(&mon->notify);
}
}
@@ -632,7 +632,7 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNUSED,
virDomainObjPtr vm = mon->vm;
/* Make sure anyone waiting wakes up now */
- virCondSignal(&mon->notify);
+ g_cond_signal(&mon->notify);
virObjectUnlock(mon);
VIR_DEBUG("Triggering EOF callback");
(eofNotify)(mon, vm, mon->callbackOpaque);
@@ -642,7 +642,7 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNUSED,
virDomainObjPtr vm = mon->vm;
/* Make sure anyone waiting wakes up now */
- virCondSignal(&mon->notify);
+ g_cond_signal(&mon->notify);
virObjectUnlock(mon);
VIR_DEBUG("Triggering error callback");
(errorNotify)(mon, vm, mon->callbackOpaque);
@@ -683,11 +683,8 @@ qemuMonitorOpenInternal(virDomainObjPtr vm,
if (!(mon = virObjectLockableNew(qemuMonitorClass)))
return NULL;
- if (virCondInit(&mon->notify) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("cannot initialize monitor condition"));
- goto cleanup;
- }
+ g_cond_init(&mon->notify);
+
mon->fd = fd;
mon->context = g_main_context_ref(context);
mon->vm = virObjectRef(vm);
@@ -881,7 +878,7 @@ qemuMonitorClose(qemuMonitorPtr mon)
virResetLastError();
}
mon->msg->finished = 1;
- virCondSignal(&mon->notify);
+ g_cond_signal(&mon->notify);
}
/* Propagate existing monitor error in case the current thread has no
@@ -935,11 +932,7 @@ qemuMonitorSend(qemuMonitorPtr mon,
mon, mon->msg->txBuffer, mon->msg->txFD);
while (!mon->msg->finished) {
- if (virCondWait(&mon->notify, &mon->parent.lock) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Unable to wait on monitor condition"));
- goto cleanup;
- }
+ g_cond_wait(&mon->notify, &mon->parent.lock);
}
if (mon->lastError.code != VIR_ERR_OK) {
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 1c5bef86a1..28192c7046 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -58,7 +58,7 @@ struct _virNetClientCall {
bool nonBlock;
bool haveThread;
- virCond cond;
+ GCond cond;
virNetClientCallPtr next;
};
@@ -1513,12 +1513,12 @@ static bool virNetClientIOEventLoopRemoveDone(virNetClientCallPtr
call,
*/
if (call->haveThread) {
VIR_DEBUG("Waking up sleep %p", call);
- virCondSignal(&call->cond);
+ g_cond_signal(&call->cond);
} else {
VIR_DEBUG("Removing completed call %p", call);
if (call->expectReply)
VIR_WARN("Got a call expecting a reply but without a waiting
thread");
- virCondDestroy(&call->cond);
+ g_cond_clear(&call->cond);
VIR_FREE(call->msg);
VIR_FREE(call);
}
@@ -1545,7 +1545,7 @@ virNetClientIOEventLoopRemoveAll(virNetClientCallPtr call,
return false;
VIR_DEBUG("Removing call %p", call);
- virCondDestroy(&call->cond);
+ g_cond_clear(&call->cond);
VIR_FREE(call->msg);
VIR_FREE(call);
return true;
@@ -1563,7 +1563,7 @@ virNetClientIOEventLoopPassTheBuck(virNetClientPtr client,
while (tmp) {
if (tmp != thiscall && tmp->haveThread) {
VIR_DEBUG("Passing the buck to %p", tmp);
- virCondSignal(&tmp->cond);
+ g_cond_signal(&tmp->cond);
return;
}
tmp = tmp->next;
@@ -1897,12 +1897,7 @@ static int virNetClientIO(virNetClientPtr client,
VIR_DEBUG("Going to sleep head=%p call=%p",
client->waitDispatch, thiscall);
/* Go to sleep while other thread is working... */
- if (virCondWait(&thiscall->cond, &client->parent.lock) < 0) {
- virNetClientCallRemove(&client->waitDispatch, thiscall);
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to wait on condition"));
- return -1;
- }
+ g_cond_wait(&thiscall->cond, &client->parent.lock);
VIR_DEBUG("Woken up from sleep head=%p call=%p",
client->waitDispatch, thiscall);
@@ -2042,11 +2037,7 @@ virNetClientCallNew(virNetMessagePtr msg,
if (VIR_ALLOC(call) < 0)
goto error;
- if (virCondInit(&call->cond) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("cannot initialize condition variable"));
- goto error;
- }
+ g_cond_init(&call->cond);
msg->donefds = 0;
if (msg->bufferLength)
@@ -2124,7 +2115,7 @@ static int virNetClientSendInternal(virNetClientPtr client,
if (ret == 1)
return 1;
- virCondDestroy(&call->cond);
+ g_cond_clear(&call->cond);
VIR_FREE(call);
return ret;
}
diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c
index 111e451f8c..26619472da 100644
--- a/src/util/virfdstream.c
+++ b/src/util/virfdstream.c
@@ -103,7 +103,7 @@ struct virFDStreamData {
/* Thread data */
virThreadPtr thread;
- virCond threadCond;
+ GCond threadCond;
virErrorPtr threadErr;
bool threadQuit;
bool threadAbort;
@@ -149,7 +149,7 @@ virFDStreamMsgQueuePush(virFDStreamDataPtr fdst,
tmp = &(*tmp)->next;
*tmp = msg;
- virCondSignal(&fdst->threadCond);
+ g_cond_signal(&fdst->threadCond);
if (safewrite(fd, &c, sizeof(c)) != sizeof(c)) {
virReportSystemError(errno,
@@ -175,7 +175,7 @@ virFDStreamMsgQueuePop(virFDStreamDataPtr fdst,
tmp->next = NULL;
}
- virCondSignal(&fdst->threadCond);
+ g_cond_signal(&fdst->threadCond);
if (saferead(fd, &c, sizeof(c)) != sizeof(c)) {
virReportSystemError(errno,
@@ -591,11 +591,7 @@ virFDStreamThread(void *opaque)
while (doRead == (fdst->msg != NULL) &&
!fdst->threadQuit) {
- if (virCondWait(&fdst->threadCond, &fdst->parent.lock)) {
- virReportSystemError(errno, "%s",
- _("failed to wait on condition"));
- goto error;
- }
+ g_cond_wait(&fdst->threadCond, &fdst->parent.lock);
}
if (fdst->threadQuit) {
@@ -654,7 +650,7 @@ virFDStreamJoinWorker(virFDStreamDataPtr fdst,
fdst->threadAbort = streamAbort;
fdst->threadQuit = true;
- virCondSignal(&fdst->threadCond);
+ g_cond_signal(&fdst->threadCond);
/* Give the thread a chance to lock the FD stream object. */
virObjectUnlock(fdst);
@@ -669,7 +665,7 @@ virFDStreamJoinWorker(virFDStreamDataPtr fdst,
ret = 0;
cleanup:
VIR_FREE(fdst->thread);
- virCondDestroy(&fdst->threadCond);
+ g_cond_clear(&fdst->threadCond);
return ret;
}
@@ -891,7 +887,7 @@ static int virFDStreamRead(virStreamPtr st, char *bytes, size_t
nbytes)
goto cleanup;
} else {
virObjectUnlock(fdst);
- virCondSignal(&fdst->threadCond);
+ g_cond_signal(&fdst->threadCond);
virObjectLock(fdst);
}
}
@@ -1057,7 +1053,7 @@ virFDStreamInData(virStreamPtr st,
goto cleanup;
} else {
virObjectUnlock(fdst);
- virCondSignal(&fdst->threadCond);
+ g_cond_signal(&fdst->threadCond);
virObjectLock(fdst);
}
}
@@ -1128,11 +1124,7 @@ static int virFDStreamOpenInternal(virStreamPtr st,
if (VIR_ALLOC(fdst->thread) < 0)
goto error;
- if (virCondInit(&fdst->threadCond) < 0) {
- virReportSystemError(errno, "%s",
- _("cannot initialize condition variable"));
- goto error;
- }
+ g_cond_init(&fdst->threadCond);
if (virThreadCreateFull(fdst->thread,
true,
diff --git a/src/util/virobject.c b/src/util/virobject.c
index aee1bb4af6..5bf4706f79 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -268,12 +268,7 @@ virObjectLockableNew(virClassPtr klass)
if (!(obj = virObjectNew(klass)))
return NULL;
- if (virMutexInit(&obj->lock) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Unable to initialize mutex"));
- virObjectUnref(obj);
- return NULL;
- }
+ g_mutex_init(&obj->lock);
return obj;
}
@@ -305,7 +300,7 @@ virObjectLockableDispose(void *anyobj)
{
virObjectLockablePtr obj = anyobj;
- virMutexDestroy(&obj->lock);
+ g_mutex_clear(&obj->lock);
}
@@ -424,7 +419,7 @@ virObjectLock(void *anyobj)
if (!obj)
return;
- virMutexLock(&obj->lock);
+ g_mutex_lock(&obj->lock);
}
@@ -501,7 +496,7 @@ virObjectUnlock(void *anyobj)
if (!obj)
return;
- virMutexUnlock(&obj->lock);
+ g_mutex_unlock(&obj->lock);
}
diff --git a/src/util/virobject.h b/src/util/virobject.h
index fcfe77578b..1f6f581e28 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -58,7 +58,7 @@ struct _virObject {
struct _virObjectLockable {
virObject parent;
- virMutex lock;
+ GMutex lock;
};
struct _virObjectRWLockable {
diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c
index c31ff53cfb..73dec18515 100644
--- a/src/vz/vz_utils.c
+++ b/src/vz/vz_utils.c
@@ -559,17 +559,11 @@ vzDomObjAlloc(void *opaque G_GNUC_UNUSED)
if (VIR_ALLOC(pdom) < 0)
return NULL;
- if (virCondInit(&pdom->job.cond) < 0)
- goto error;
+ g_cond_init(&pdom->job.cond);
pdom->stats = PRL_INVALID_HANDLE;
return pdom;
-
- error:
- VIR_FREE(pdom);
-
- return NULL;
}
void
@@ -582,45 +576,33 @@ vzDomObjFree(void* p)
PrlHandle_Free(pdom->sdkdom);
PrlHandle_Free(pdom->stats);
- virCondDestroy(&pdom->job.cond);
+ g_cond_clear(&pdom->job.cond);
VIR_FREE(pdom);
};
-#define VZ_JOB_WAIT_TIME (1000 * 30)
+#define VZ_JOB_WAIT_TIME (30 * G_TIME_SPAN_SECOND)
int
vzDomainObjBeginJob(virDomainObjPtr dom)
{
vzDomObjPtr pdom = dom->privateData;
- unsigned long long now;
- unsigned long long then;
-
- if (virTimeMillisNow(&now) < 0)
- return -1;
- then = now + VZ_JOB_WAIT_TIME;
+ gint64 then = g_get_monotonic_time() + VZ_JOB_WAIT_TIME;
while (pdom->job.active) {
- if (virCondWaitUntil(&pdom->job.cond, &dom->parent.lock, then) <
0)
+ if (!g_cond_wait_until(&pdom->job.cond, &dom->parent.lock, then))
goto error;
}
- if (virTimeMillisNow(&now) < 0)
- return -1;
-
pdom->job.active = true;
- pdom->job.started = now;
+ pdom->job.started = g_get_monotonic_time();
pdom->job.elapsed = 0;
pdom->job.progress = 0;
pdom->job.hasProgress = false;
return 0;
error:
- if (errno == ETIMEDOUT)
- virReportError(VIR_ERR_OPERATION_TIMEOUT,
- "%s", _("cannot acquire state change lock"));
- else
- virReportSystemError(errno,
- "%s", _("cannot acquire job mutex"));
+ virReportError(VIR_ERR_OPERATION_TIMEOUT,
+ "%s", _("cannot acquire state change lock"));
return -1;
}
@@ -631,19 +613,18 @@ vzDomainObjEndJob(virDomainObjPtr dom)
pdom->job.active = false;
pdom->job.cancelled = false;
- virCondSignal(&pdom->job.cond);
+ g_cond_signal(&pdom->job.cond);
}
int
vzDomainJobUpdateTime(vzDomainJobObjPtr job)
{
- unsigned long long now;
+ gint64 now;
if (!job->started)
return 0;
- if (virTimeMillisNow(&now) < 0)
- return -1;
+ now = g_get_monotonic_time();
if (now < job->started) {
VIR_WARN("Async job starts in the future");
diff --git a/src/vz/vz_utils.h b/src/vz/vz_utils.h
index 7ebb34bb11..6497e5530f 100644
--- a/src/vz/vz_utils.h
+++ b/src/vz/vz_utils.h
@@ -93,11 +93,11 @@ typedef struct _vzConn vzConn;
typedef struct _vzConn *vzConnPtr;
struct _vzDomainJobObj {
- virCond cond;
+ GCond cond;
bool active;
/* when the job started, zeroed on time discontinuities */
- unsigned long long started;
- unsigned long long elapsed;
+ gint64 started;
+ gint64 elapsed;
bool hasProgress;
int progress; /* percents */
PRL_HANDLE sdkJob;
diff --git a/tests/qemuhotplugmock.c b/tests/qemuhotplugmock.c
index 8e5b07788d..71fe2db88c 100644
--- a/tests/qemuhotplugmock.c
+++ b/tests/qemuhotplugmock.c
@@ -38,15 +38,15 @@ init_syms(void)
VIR_MOCK_REAL_INIT(virFileExists);
}
-unsigned long long
+gint64
qemuDomainGetUnplugTimeout(virDomainObjPtr vm G_GNUC_UNUSED)
{
/* Wait only 100ms for DEVICE_DELETED event. Give a greater
* timeout in case of PSeries guest to be consistent with the
* original logic. */
if (qemuDomainIsPSeries(vm->def))
- return 200;
- return 100;
+ return 200 * G_TIME_SPAN_MILLISECOND;
+ return 100 * G_TIME_SPAN_MILLISECOND;
}
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index d9244dca44..581a09d204 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -352,6 +352,7 @@ testQemuHotplug(const void *data)
if (keep) {
test->vm = vm;
} else {
+ virObjectUnlock(vm);
virObjectUnref(vm);
test->vm = NULL;
}
@@ -396,6 +397,7 @@ testQemuHotplugCpuDataFree(struct testQemuHotplugCpuData *data)
priv = data->vm->privateData;
priv->mon = NULL;
+ virObjectUnlock(data->vm);
virObjectUnref(data->vm);
}
diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index 78fc94e710..9c5a7249ae 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -79,6 +79,8 @@ struct _qemuMonitorTest {
virDomainObjPtr vm;
virHashTablePtr qapischema;
+
+ bool vmCreated;
};
@@ -392,6 +394,8 @@ qemuMonitorTestFree(qemuMonitorTestPtr test)
g_object_unref(test->eventThread);
+ if (test->vmCreated)
+ virObjectUnlock(test->vm);
virObjectUnref(test->vm);
if (test->started)
@@ -1062,6 +1066,7 @@ qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt,
test->vm = virDomainObjNew(xmlopt);
if (!test->vm)
goto error;
+ test->vmCreated = true;
if (!(test->vm->def = virDomainDefNew()))
goto error;
}
diff --git a/tests/qemusecuritytest.c b/tests/qemusecuritytest.c
index a1ef9d8802..65322ae29e 100644
--- a/tests/qemusecuritytest.c
+++ b/tests/qemusecuritytest.c
@@ -100,19 +100,19 @@ testDomain(const void *opaque)
if (virStorageSourceIsLocalStorage(src) && src->path &&
(src->shared || src->readonly) &&
virStringListAdd(¬Restored, src->path) < 0)
- return -1;
+ goto unlock;
for (n = src->backingStore; virStorageSourceIsBacking(n); n =
n->backingStore) {
if (virStorageSourceIsLocalStorage(n) && n->path &&
virStringListAdd(¬Restored, n->path) < 0)
- return -1;
+ goto unlock;
}
}
/* Mocking is enabled only when this env variable is set.
* See mock code for explanation. */
if (g_setenv(ENVVAR, "1", FALSE) == FALSE)
- return -1;
+ goto unlock;
if (qemuSecuritySetAllLabel(data->driver, vm, NULL, false) < 0)
goto cleanup;
@@ -124,9 +124,13 @@ testDomain(const void *opaque)
ret = 0;
cleanup:
+ virObjectUnlock(vm);
g_unsetenv(ENVVAR);
freePaths();
return ret;
+unlock:
+ virObjectUnlock(vm);
+ return -1;
}
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 405227fdf6..180201f74e 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -592,6 +592,7 @@ testCompareXMLToArgv(const void *data)
VIR_FREE(actualargv);
virDomainChrSourceDefClear(&monitor_chr);
virCommandFree(cmd);
+ virObjectUnlock(vm);
virObjectUnref(vm);
virSetConnectSecret(NULL);
virSetConnectStorage(NULL);
diff --git a/tools/virsh-console.c b/tools/virsh-console.c
index 2e498a6903..ac4d65cb0e 100644
--- a/tools/virsh-console.c
+++ b/tools/virsh-console.c
@@ -63,7 +63,7 @@ struct virConsole {
virStreamPtr st;
bool quit;
- virCond cond;
+ GCond cond;
int stdinWatch;
int stdoutWatch;
@@ -130,7 +130,7 @@ virConsoleShutdown(virConsolePtr con,
con->stdoutWatch = -1;
if (!con->quit) {
con->quit = true;
- virCondSignal(&con->cond);
+ g_cond_signal(&con->cond);
}
}
@@ -143,7 +143,7 @@ virConsoleDispose(void *obj)
if (con->st)
virStreamFree(con->st);
- virCondDestroy(&con->cond);
+ g_cond_clear(&con->cond);
virResetError(&con->error);
}
@@ -376,21 +376,12 @@ virConsoleNew(void)
if (!(con = virObjectLockableNew(virConsoleClass)))
return NULL;
- if (virCondInit(&con->cond) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("cannot initialize console condition"));
-
- goto error;
- }
+ g_cond_init(&con->cond);
con->stdinWatch = -1;
con->stdoutWatch = -1;
return con;
-
- error:
- virObjectUnref(con);
- return NULL;
}
@@ -484,11 +475,7 @@ virshRunConsole(vshControl *ctl,
}
while (!con->quit) {
- if (virCondWait(&con->cond, &con->parent.lock) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("unable to wait on console condition"));
- goto cleanup;
- }
+ g_cond_wait(&con->cond, &con->parent.lock);
}
if (con->error.code == VIR_ERR_OK)
--
2.25.2