Turn virDomainObjPtr into a virObjectPtr

Switch virDomainObjPtr to use the virObject APIs for reference
counting. The main change is that virObjectUnref does not return
the reference count, merely a bool indicating whether the object
still has any refs left. Checking the return value is also not
mandatory.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-07-11 14:35:46 +01:00
parent 46ec5f85c8
commit 31cb030ab6
13 changed files with 93 additions and 126 deletions

View File

@ -660,6 +660,21 @@ VIR_ENUM_IMPL(virDomainNumatuneMemPlacementMode,
#define VIR_DOMAIN_XML_WRITE_FLAGS VIR_DOMAIN_XML_SECURE
#define VIR_DOMAIN_XML_READ_FLAGS VIR_DOMAIN_XML_INACTIVE
static virClassPtr virDomainObjClass;
static void virDomainObjDispose(void *obj);
static int virDomainObjOnceInit(void)
{
if (!(virDomainObjClass = virClassNew("virDomainObj",
sizeof(virDomainObj),
virDomainObjDispose)))
return -1;
return 0;
}
VIR_ONCE_GLOBAL_INIT(virDomainObj)
void
virBlkioDeviceWeightArrayClear(virBlkioDeviceWeightPtr deviceWeights,
int ndevices)
@ -725,7 +740,7 @@ virDomainObjListDataFree(void *payload, const void *name ATTRIBUTE_UNUSED)
{
virDomainObjPtr obj = payload;
virDomainObjLock(obj);
if (virDomainObjUnref(obj) > 0)
if (virObjectUnref(obj))
virDomainObjUnlock(obj);
}
@ -1639,10 +1654,10 @@ void virDomainDefFree(virDomainDefPtr def)
}
static void virDomainSnapshotObjListDeinit(virDomainSnapshotObjListPtr snapshots);
static void virDomainObjFree(virDomainObjPtr dom)
static void virDomainObjDispose(void *obj)
{
if (!dom)
return;
virDomainObjPtr dom = obj;
VIR_DEBUG("obj=%p", dom);
virDomainDefFree(dom->def);
@ -1654,37 +1669,18 @@ static void virDomainObjFree(virDomainObjPtr dom)
virMutexDestroy(&dom->lock);
virDomainSnapshotObjListDeinit(&dom->snapshots);
VIR_FREE(dom);
}
void virDomainObjRef(virDomainObjPtr dom)
{
dom->refs++;
VIR_DEBUG("obj=%p refs=%d", dom, dom->refs);
}
int virDomainObjUnref(virDomainObjPtr dom)
{
dom->refs--;
VIR_DEBUG("obj=%p refs=%d", dom, dom->refs);
if (dom->refs == 0) {
virDomainObjUnlock(dom);
virDomainObjFree(dom);
return 0;
}
return dom->refs;
}
static virDomainObjPtr virDomainObjNew(virCapsPtr caps)
virDomainObjPtr virDomainObjNew(virCapsPtr caps)
{
virDomainObjPtr domain;
if (VIR_ALLOC(domain) < 0) {
virReportOOMError();
if (virDomainObjInitialize() < 0)
return NULL;
if (!(domain = virObjectNew(virDomainObjClass)))
return NULL;
}
if (caps->privateDataAllocFunc &&
!(domain->privateData = (caps->privateDataAllocFunc)())) {
@ -1706,7 +1702,6 @@ static virDomainObjPtr virDomainObjNew(virCapsPtr caps)
virDomainObjLock(domain);
virDomainObjSetState(domain, VIR_DOMAIN_SHUTOFF,
VIR_DOMAIN_SHUTOFF_UNKNOWN);
domain->refs = 1;
virDomainSnapshotObjListInit(&domain->snapshots);
@ -9417,8 +9412,7 @@ static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
return obj;
error:
/* obj was never shared, so unref should return 0 */
ignore_value(virDomainObjUnref(obj));
virObjectUnref(obj);
VIR_FREE(nodes);
return NULL;
}
@ -13527,9 +13521,7 @@ static virDomainObjPtr virDomainLoadStatus(virCapsPtr caps,
return obj;
error:
/* obj was never shared, so unref should return 0 */
if (obj)
ignore_value(virDomainObjUnref(obj));
virObjectUnref(obj);
VIR_FREE(statusFile);
return NULL;
}

View File

@ -43,6 +43,7 @@
# include "virnetdevvportprofile.h"
# include "virnetdevopenvswitch.h"
# include "virnetdevbandwidth.h"
# include "virobject.h"
/* forward declarations of all device types, required by
* virDomainDeviceDef
@ -1809,8 +1810,9 @@ struct _virDomainStateReason {
typedef struct _virDomainObj virDomainObj;
typedef virDomainObj *virDomainObjPtr;
struct _virDomainObj {
virObject object;
virMutex lock;
int refs;
pid_t pid;
virDomainStateReason state;
@ -1847,6 +1849,7 @@ virDomainObjIsActive(virDomainObjPtr dom)
return dom->def->id != -1;
}
virDomainObjPtr virDomainObjNew(virCapsPtr caps);
int virDomainObjListInit(virDomainObjListPtr objs);
void virDomainObjListDeinit(virDomainObjListPtr objs);
@ -1909,9 +1912,6 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def,
void *opaque);
void virDomainDefFree(virDomainDefPtr vm);
void virDomainObjRef(virDomainObjPtr vm);
/* Returns 1 if the object was freed, 0 if more refs exist */
int virDomainObjUnref(virDomainObjPtr vm) ATTRIBUTE_RETURN_CHECK;
virDomainChrDefPtr virDomainChrDefNew(void);

View File

@ -428,12 +428,11 @@ virDomainObjListGetInactiveNames;
virDomainObjListInit;
virDomainObjListNumOfDomains;
virDomainObjLock;
virDomainObjRef;
virDomainObjNew;
virDomainObjSetDefTransient;
virDomainObjSetState;
virDomainObjTaint;
virDomainObjUnlock;
virDomainObjUnref;
virDomainPausedReasonTypeFromString;
virDomainPausedReasonTypeToString;
virDomainPciRombarModeTypeFromString;

View File

@ -134,7 +134,7 @@ libxlDomainObjUnref(void *data)
{
virDomainObjPtr vm = data;
ignore_value(virDomainObjUnref(vm));
virObjectUnref(vm);
}
static void
@ -484,13 +484,13 @@ libxlCreateDomEvents(virDomainObjPtr vm)
/* Add a reference to the domain object while it is injected in
* the event loop.
*/
virDomainObjRef(vm);
virObjectRef(vm);
if ((priv->eventHdl = virEventAddHandle(
fd,
VIR_EVENT_HANDLE_READABLE | VIR_EVENT_HANDLE_ERROR,
libxlEventHandler,
vm, libxlDomainObjUnref)) < 0) {
ignore_value(virDomainObjUnref(vm));
virObjectUnref(vm);
goto error;
}

View File

@ -565,7 +565,7 @@ static void virLXCProcessMonitorDestroy(virLXCMonitorPtr mon,
priv = vm->privateData;
if (priv->monitor == mon)
priv->monitor = NULL;
if (virDomainObjUnref(vm) > 0)
if (virObjectUnref(vm))
virDomainObjUnlock(vm);
}
@ -666,12 +666,12 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver,
/* Hold an extra reference because we can't allow 'vm' to be
* deleted while the monitor is active */
virDomainObjRef(vm);
virObjectRef(vm);
monitor = virLXCMonitorNew(vm, driver->stateDir, &monitorCallbacks);
if (monitor == NULL)
ignore_value(virDomainObjUnref(vm));
virObjectUnref(vm);
if (virSecurityManagerClearSocketLabel(driver->securityManager, vm->def) < 0) {
if (monitor) {

View File

@ -598,17 +598,8 @@ int openvzLoadDomains(struct openvz_driver *driver) {
}
*line++ = '\0';
if (VIR_ALLOC(dom) < 0)
goto no_memory;
if (virMutexInit(&dom->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot initialize mutex"));
VIR_FREE(dom);
goto cleanup;
}
virDomainObjLock(dom);
if (!(dom = virDomainObjNew(driver->caps)))
goto cleanup;
if (VIR_ALLOC(dom->def) < 0)
goto no_memory;
@ -623,7 +614,6 @@ int openvzLoadDomains(struct openvz_driver *driver) {
VIR_DOMAIN_RUNNING_UNKNOWN);
}
dom->refs = 1;
dom->pid = veid;
if (virDomainObjGetState(dom, NULL) == VIR_DOMAIN_SHUTOFF)
dom->def->id = -1;
@ -683,7 +673,6 @@ int openvzLoadDomains(struct openvz_driver *driver) {
goto cleanup;
}
virDomainObjUnlock(dom);
dom = NULL;
}
@ -700,9 +689,7 @@ int openvzLoadDomains(struct openvz_driver *driver) {
virCommandFree(cmd);
VIR_FREE(temp);
VIR_FREE(outbuf);
/* dom hasn't been shared yet, so unref should return 0 */
if (dom)
ignore_value(virDomainObjUnref(dom));
virObjectUnref(dom);
return -1;
}

View File

@ -774,7 +774,7 @@ qemuDomainObjBeginJobInternal(struct qemud_driver *driver,
return -1;
then = now + QEMU_JOB_WAIT_TIME;
virDomainObjRef(obj);
virObjectRef(obj);
if (driver_locked)
qemuDriverUnlock(driver);
@ -854,8 +854,7 @@ error:
qemuDriverLock(driver);
virDomainObjLock(obj);
}
/* Safe to ignore value since ref count was incremented above */
ignore_value(virDomainObjUnref(obj));
virObjectUnref(obj);
return -1;
}
@ -922,10 +921,10 @@ int qemuDomainObjBeginAsyncJobWithDriver(struct qemud_driver *driver,
* To be called after completing the work associated with the
* earlier qemuDomainBeginJob() call
*
* Returns remaining refcount on 'obj', maybe 0 to indicated it
* was deleted
* Returns true if @obj was still referenced, false if it was
* disposed of.
*/
int qemuDomainObjEndJob(struct qemud_driver *driver, virDomainObjPtr obj)
bool qemuDomainObjEndJob(struct qemud_driver *driver, virDomainObjPtr obj)
{
qemuDomainObjPrivatePtr priv = obj->privateData;
enum qemuDomainJob job = priv->job.active;
@ -941,10 +940,10 @@ int qemuDomainObjEndJob(struct qemud_driver *driver, virDomainObjPtr obj)
qemuDomainObjSaveJob(driver, obj);
virCondSignal(&priv->job.cond);
return virDomainObjUnref(obj);
return virObjectUnref(obj);
}
int
bool
qemuDomainObjEndAsyncJob(struct qemud_driver *driver, virDomainObjPtr obj)
{
qemuDomainObjPrivatePtr priv = obj->privateData;
@ -958,7 +957,7 @@ qemuDomainObjEndAsyncJob(struct qemud_driver *driver, virDomainObjPtr obj)
qemuDomainObjSaveJob(driver, obj);
virCondBroadcast(&priv->job.asyncCond);
return virDomainObjUnref(obj);
return virObjectUnref(obj);
}
static int
@ -1031,9 +1030,7 @@ qemuDomainObjExitMonitorInternal(struct qemud_driver *driver,
qemuDomainObjSaveJob(driver, obj);
virCondSignal(&priv->job.cond);
/* safe to ignore since the surrounding async job increased
* the reference counter as well */
ignore_value(virDomainObjUnref(obj));
virObjectUnref(obj);
}
}
@ -1207,7 +1204,7 @@ void qemuDomainObjExitAgentWithDriver(struct qemud_driver *driver,
void qemuDomainObjEnterRemoteWithDriver(struct qemud_driver *driver,
virDomainObjPtr obj)
{
virDomainObjRef(obj);
virObjectRef(obj);
virDomainObjUnlock(obj);
qemuDriverUnlock(driver);
}
@ -1217,9 +1214,7 @@ void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver,
{
qemuDriverLock(driver);
virDomainObjLock(obj);
/* Safe to ignore value, since we incremented ref in
* qemuDomainObjEnterRemoteWithDriver */
ignore_value(virDomainObjUnref(obj));
virObjectUnref(obj);
}

View File

@ -193,11 +193,11 @@ int qemuDomainObjBeginAsyncJobWithDriver(struct qemud_driver *driver,
enum qemuDomainAsyncJob asyncJob)
ATTRIBUTE_RETURN_CHECK;
int qemuDomainObjEndJob(struct qemud_driver *driver,
virDomainObjPtr obj)
bool qemuDomainObjEndJob(struct qemud_driver *driver,
virDomainObjPtr obj)
ATTRIBUTE_RETURN_CHECK;
int qemuDomainObjEndAsyncJob(struct qemud_driver *driver,
virDomainObjPtr obj)
bool qemuDomainObjEndAsyncJob(struct qemud_driver *driver,
virDomainObjPtr obj)
ATTRIBUTE_RETURN_CHECK;
void qemuDomainObjSetJobPhase(struct qemud_driver *driver,
virDomainObjPtr obj,

View File

@ -3402,7 +3402,7 @@ endjob:
ignore_value(qemuDomainObjEndAsyncJob(driver, wdEvent->vm));
unlock:
if (virDomainObjUnref(wdEvent->vm) > 0)
if (virObjectUnref(wdEvent->vm))
virDomainObjUnlock(wdEvent->vm);
qemuDriverUnlock(driver);
VIR_FREE(wdEvent);

View File

@ -1369,7 +1369,7 @@ qemuMigrationPrepareAny(struct qemud_driver *driver,
* This prevents any other APIs being invoked while incoming
* migration is taking place.
*/
if (qemuMigrationJobContinue(vm) == 0) {
if (!qemuMigrationJobContinue(vm)) {
vm = NULL;
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("domain disappeared"));
@ -1396,7 +1396,7 @@ cleanup:
return ret;
endjob:
if (qemuMigrationJobFinish(driver, vm) == 0) {
if (!qemuMigrationJobFinish(driver, vm)) {
vm = NULL;
}
goto cleanup;
@ -2680,7 +2680,7 @@ endjob:
VIR_DOMAIN_EVENT_RESUMED_MIGRATED);
}
if (qemuMigrationJobFinish(driver, vm) == 0) {
if (!qemuMigrationJobFinish(driver, vm)) {
vm = NULL;
} else if (!virDomainObjIsActive(vm) &&
(!vm->persistent ||
@ -2722,7 +2722,7 @@ qemuMigrationPerformPhase(struct qemud_driver *driver,
virDomainEventPtr event = NULL;
int ret = -1;
bool resume;
int refs;
bool hasrefs;
/* If we didn't start the job in the begin phase, start it now. */
if (!(flags & VIR_MIGRATE_CHANGE_PROTECTION)) {
@ -2770,10 +2770,10 @@ qemuMigrationPerformPhase(struct qemud_driver *driver,
endjob:
if (ret < 0)
refs = qemuMigrationJobFinish(driver, vm);
hasrefs = qemuMigrationJobFinish(driver, vm);
else
refs = qemuMigrationJobContinue(vm);
if (refs == 0) {
hasrefs = qemuMigrationJobContinue(vm);
if (!hasrefs) {
vm = NULL;
} else if (!virDomainObjIsActive(vm) && !vm->persistent) {
qemuDomainRemoveInactive(driver, vm);
@ -3374,15 +3374,15 @@ qemuMigrationJobStartPhase(struct qemud_driver *driver,
virDomainObjPtr vm,
enum qemuMigrationJobPhase phase)
{
virDomainObjRef(vm);
virObjectRef(vm);
qemuMigrationJobSetPhase(driver, vm, phase);
}
int
bool
qemuMigrationJobContinue(virDomainObjPtr vm)
{
qemuDomainObjReleaseAsyncJob(vm);
return virDomainObjUnref(vm);
return virObjectUnref(vm);
}
bool
@ -3405,7 +3405,7 @@ qemuMigrationJobIsActive(virDomainObjPtr vm,
return true;
}
int
bool
qemuMigrationJobFinish(struct qemud_driver *driver, virDomainObjPtr vm)
{
return qemuDomainObjEndAsyncJob(driver, vm);

View File

@ -66,12 +66,12 @@ void qemuMigrationJobStartPhase(struct qemud_driver *driver,
virDomainObjPtr vm,
enum qemuMigrationJobPhase phase)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int qemuMigrationJobContinue(virDomainObjPtr obj)
bool qemuMigrationJobContinue(virDomainObjPtr obj)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
bool qemuMigrationJobIsActive(virDomainObjPtr vm,
enum qemuDomainAsyncJob job)
ATTRIBUTE_NONNULL(1);
int qemuMigrationJobFinish(struct qemud_driver *driver, virDomainObjPtr obj)
bool qemuMigrationJobFinish(struct qemud_driver *driver, virDomainObjPtr obj)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
int qemuMigrationSetOffline(struct qemud_driver *driver,

View File

@ -173,7 +173,7 @@ static void qemuProcessHandleAgentDestroy(qemuAgentPtr agent,
priv = vm->privateData;
if (priv->agent == agent)
priv->agent = NULL;
if (virDomainObjUnref(vm) > 0)
if (virObjectUnref(vm))
virDomainObjUnlock(vm);
}
@ -225,7 +225,7 @@ qemuConnectAgent(struct qemud_driver *driver, virDomainObjPtr vm)
/* Hold an extra reference because we can't allow 'vm' to be
* deleted while the agent is active */
virDomainObjRef(vm);
virObjectRef(vm);
ignore_value(virTimeMillisNow(&priv->agentStart));
virDomainObjUnlock(vm);
@ -246,9 +246,8 @@ qemuConnectAgent(struct qemud_driver *driver, virDomainObjPtr vm)
goto cleanup;
}
/* Safe to ignore value since ref count was incremented above */
if (agent == NULL)
ignore_value(virDomainObjUnref(vm));
virObjectUnref(vm);
if (!virDomainObjIsActive(vm)) {
qemuAgentClose(agent);
@ -584,7 +583,7 @@ qemuProcessFakeReboot(void *opaque)
ret = 0;
endjob:
if (qemuDomainObjEndJob(driver, vm) == 0)
if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@ -593,7 +592,7 @@ cleanup:
ignore_value(qemuProcessKill(driver, vm,
VIR_QEMU_PROCESS_KILL_FORCE));
}
if (virDomainObjUnref(vm) > 0)
if (virObjectUnref(vm))
virDomainObjUnlock(vm);
}
if (event)
@ -610,7 +609,7 @@ qemuProcessShutdownOrReboot(struct qemud_driver *driver,
if (priv->fakeReboot) {
qemuDomainSetFakeReboot(driver, vm, false);
virDomainObjRef(vm);
virObjectRef(vm);
virThread th;
if (virThreadCreate(&th,
false,
@ -619,8 +618,7 @@ qemuProcessShutdownOrReboot(struct qemud_driver *driver,
VIR_ERROR(_("Failed to create reboot thread, killing domain"));
ignore_value(qemuProcessKill(driver, vm,
VIR_QEMU_PROCESS_KILL_NOWAIT));
/* Safe to ignore value since ref count was incremented above */
ignore_value(virDomainObjUnref(vm));
virObjectUnref(vm);
}
} else {
ignore_value(qemuProcessKill(driver, vm, VIR_QEMU_PROCESS_KILL_NOWAIT));
@ -801,9 +799,9 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
/* Hold an extra reference because we can't allow 'vm' to be
* deleted before handling watchdog event is finished.
*/
virDomainObjRef(vm);
virObjectRef(vm);
if (virThreadPoolSendJob(driver->workerPool, 0, wdEvent) < 0) {
if (virDomainObjUnref(vm) == 0)
if (!virObjectUnref(vm))
vm = NULL;
VIR_FREE(wdEvent);
}
@ -1022,7 +1020,7 @@ static void qemuProcessHandleMonitorDestroy(qemuMonitorPtr mon,
priv = vm->privateData;
if (priv->mon == mon)
priv->mon = NULL;
if (virDomainObjUnref(vm) > 0)
if (virObjectUnref(vm))
virDomainObjUnlock(vm);
}
@ -1213,7 +1211,7 @@ qemuConnectMonitor(struct qemud_driver *driver, virDomainObjPtr vm)
/* Hold an extra reference because we can't allow 'vm' to be
* deleted while the monitor is active */
virDomainObjRef(vm);
virObjectRef(vm);
ignore_value(virTimeMillisNow(&priv->monStart));
virDomainObjUnlock(vm);
@ -1228,9 +1226,8 @@ qemuConnectMonitor(struct qemud_driver *driver, virDomainObjPtr vm)
virDomainObjLock(vm);
priv->monStart = 0;
/* Safe to ignore value since ref count was incremented above */
if (mon == NULL)
ignore_value(virDomainObjUnref(vm));
virObjectUnref(vm);
if (!virDomainObjIsActive(vm)) {
qemuMonitorClose(mon);
@ -3068,7 +3065,7 @@ qemuProcessReconnect(void *opaque)
/* Hold an extra reference because we can't allow 'vm' to be
* deleted if qemuConnectMonitor() failed */
virDomainObjRef(obj);
virObjectRef(obj);
/* XXX check PID liveliness & EXE path */
if (qemuConnectMonitor(driver, obj) < 0)
@ -3165,10 +3162,10 @@ qemuProcessReconnect(void *opaque)
driver->nextvmid = obj->def->id + 1;
endjob:
if (qemuDomainObjEndJob(driver, obj) == 0)
if (!qemuDomainObjEndJob(driver, obj))
obj = NULL;
if (obj && virDomainObjUnref(obj) > 0)
if (obj && virObjectUnref(obj))
virDomainObjUnlock(obj);
qemuDriverUnlock(driver);
@ -3178,18 +3175,18 @@ endjob:
return;
error:
if (qemuDomainObjEndJob(driver, obj) == 0)
if (!qemuDomainObjEndJob(driver, obj))
obj = NULL;
if (obj) {
if (!virDomainObjIsActive(obj)) {
if (virDomainObjUnref(obj) > 0)
if (virObjectUnref(obj))
virDomainObjUnlock(obj);
qemuDriverUnlock(driver);
return;
}
if (virDomainObjUnref(obj) > 0) {
if (virObjectUnref(obj)) {
/* We can't get the monitor back, so must kill the VM
* to remove danger of it ending up running twice if
* user tries to start it again later
@ -3277,9 +3274,9 @@ qemuProcessReconnectHelper(void *payload,
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not create thread. QEMU initialization "
"might be incomplete"));
if (qemuDomainObjEndJob(src->driver, obj) == 0) {
if (!qemuDomainObjEndJob(src->driver, obj)) {
obj = NULL;
} else if (virDomainObjUnref(obj) > 0) {
} else if (virObjectUnref(obj)) {
/* We can't spawn a thread and thus connect to monitor.
* Kill qemu */
qemuProcessStop(src->driver, obj, VIR_DOMAIN_SHUTOFF_FAILED, 0);
@ -3950,12 +3947,11 @@ cleanup:
* a case, but there are too many to maintain certainty, so we
* will do this as a precaution).
*/
virDomainObjRef(vm);
virObjectRef(vm);
virDomainObjUnlock(vm);
qemuDriverLock(driver);
virDomainObjLock(vm);
/* Safe to ignore value since ref count was incremented above */
ignore_value(virDomainObjUnref(vm));
virObjectUnref(vm);
}
return ret;
}
@ -4407,7 +4403,7 @@ qemuProcessAutoDestroy(struct qemud_driver *driver,
VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
if (qemuDomainObjEndJob(driver, dom) == 0)
if (!qemuDomainObjEndJob(driver, dom))
dom = NULL;
if (dom && !dom->persistent)
qemuDomainRemoveInactive(driver, dom);

View File

@ -213,9 +213,7 @@ cleanup:
VIR_FREE(directoryName);
VIR_FREE(fileName);
VIR_FREE(vmx);
/* any non-NULL vm here has not been shared, so unref will return 0 */
if (vm)
ignore_value(virDomainObjUnref(vm));
virObjectUnref(vm);
return ret;
}