qemu: Consolidate {Enter,Exit}Monitor{,WithDriver}

EnterMonitor and ExitMonitor methods are very similar to their
*WithDriver variants; consolidate them into EnterMonitorInternal and
ExitMonitorInternal to avoid (mainly future) code duplication.
This commit is contained in:
Jiri Denemark 2011-07-03 23:55:47 +02:00
parent cec1d280ad
commit 24f717ac22

View File

@ -622,6 +622,43 @@ int qemuDomainObjEndJob(virDomainObjPtr obj)
return virDomainObjUnref(obj);
}
static void
qemuDomainObjEnterMonitorInternal(struct qemud_driver *driver,
virDomainObjPtr obj)
{
qemuDomainObjPrivatePtr priv = obj->privateData;
qemuMonitorLock(priv->mon);
qemuMonitorRef(priv->mon);
ignore_value(virTimeMs(&priv->monStart));
virDomainObjUnlock(obj);
if (driver)
qemuDriverUnlock(driver);
}
static void
qemuDomainObjExitMonitorInternal(struct qemud_driver *driver,
virDomainObjPtr obj)
{
qemuDomainObjPrivatePtr priv = obj->privateData;
int refs;
refs = qemuMonitorUnref(priv->mon);
if (refs > 0)
qemuMonitorUnlock(priv->mon);
if (driver)
qemuDriverLock(driver);
virDomainObjLock(obj);
priv->monStart = 0;
if (refs == 0) {
priv->mon = NULL;
}
}
/*
* obj must be locked before calling, qemud_driver must be unlocked
*
@ -633,38 +670,18 @@ int qemuDomainObjEndJob(virDomainObjPtr obj)
*/
void qemuDomainObjEnterMonitor(virDomainObjPtr obj)
{
qemuDomainObjPrivatePtr priv = obj->privateData;
qemuMonitorLock(priv->mon);
qemuMonitorRef(priv->mon);
ignore_value(virTimeMs(&priv->monStart));
virDomainObjUnlock(obj);
qemuDomainObjEnterMonitorInternal(NULL, obj);
}
/* obj must NOT be locked before calling, qemud_driver must be unlocked
*
* Should be paired with an earlier qemuDomainObjEnterMonitor() call
*/
void qemuDomainObjExitMonitor(virDomainObjPtr obj)
{
qemuDomainObjPrivatePtr priv = obj->privateData;
int refs;
refs = qemuMonitorUnref(priv->mon);
if (refs > 0)
qemuMonitorUnlock(priv->mon);
virDomainObjLock(obj);
priv->monStart = 0;
if (refs == 0) {
priv->mon = NULL;
}
qemuDomainObjExitMonitorInternal(NULL, obj);
}
/*
* obj must be locked before calling, qemud_driver must be locked
*
@ -676,16 +693,9 @@ void qemuDomainObjExitMonitor(virDomainObjPtr obj)
void qemuDomainObjEnterMonitorWithDriver(struct qemud_driver *driver,
virDomainObjPtr obj)
{
qemuDomainObjPrivatePtr priv = obj->privateData;
qemuMonitorLock(priv->mon);
qemuMonitorRef(priv->mon);
ignore_value(virTimeMs(&priv->monStart));
virDomainObjUnlock(obj);
qemuDriverUnlock(driver);
qemuDomainObjEnterMonitorInternal(driver, obj);
}
/* obj must NOT be locked before calling, qemud_driver must be unlocked,
* and will be locked after returning
*
@ -694,21 +704,7 @@ void qemuDomainObjEnterMonitorWithDriver(struct qemud_driver *driver,
void qemuDomainObjExitMonitorWithDriver(struct qemud_driver *driver,
virDomainObjPtr obj)
{
qemuDomainObjPrivatePtr priv = obj->privateData;
int refs;
refs = qemuMonitorUnref(priv->mon);
if (refs > 0)
qemuMonitorUnlock(priv->mon);
qemuDriverLock(driver);
virDomainObjLock(obj);
priv->monStart = 0;
if (refs == 0) {
priv->mon = NULL;
}
qemuDomainObjExitMonitorInternal(driver, obj);
}
void qemuDomainObjEnterRemoteWithDriver(struct qemud_driver *driver,