The function doesn't really need the connect object for anything besides
registering the autodestroy callback for it. If we merge it certain
callers can be simplified.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/lxc/lxc_driver.c | 15 +++++++++------
src/lxc/lxc_process.c | 31 ++++++++++---------------------
src/lxc/lxc_process.h | 5 ++---
3 files changed, 21 insertions(+), 30 deletions(-)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 456d2fbae9..6b2f721178 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -964,9 +964,13 @@ static int lxcDomainCreateWithFiles(virDomainPtr dom,
virObjectEvent *event = NULL;
int ret = -1;
g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
+ virConnect *autoDestroyConn = NULL;
virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, -1);
+ if (flags & VIR_DOMAIN_START_AUTODESTROY)
+ autoDestroyConn = dom->conn;
+
if (!(vm = lxcDomObjFromDomain(dom)))
goto cleanup;
@@ -988,9 +992,7 @@ static int lxcDomainCreateWithFiles(virDomainPtr dom,
goto endjob;
}
- ret = virLXCProcessStart(dom->conn, driver, vm,
- nfiles, files,
- (flags & VIR_DOMAIN_START_AUTODESTROY),
+ ret = virLXCProcessStart(driver, vm, nfiles, files, autoDestroyConn,
VIR_DOMAIN_RUNNING_BOOTED);
if (ret == 0) {
@@ -1065,10 +1067,13 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
g_autoptr(virCaps) caps = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
+ virConnect *autoDestroyConn = NULL;
virCheckFlags(VIR_DOMAIN_START_AUTODESTROY |
VIR_DOMAIN_START_VALIDATE, NULL);
+ if (flags & VIR_DOMAIN_START_AUTODESTROY)
+ autoDestroyConn = conn;
if (flags & VIR_DOMAIN_START_VALIDATE)
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
@@ -1106,9 +1111,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
goto cleanup;
}
- if (virLXCProcessStart(conn, driver, vm,
- nfiles, files,
- (flags & VIR_DOMAIN_START_AUTODESTROY),
+ if (virLXCProcessStart(driver, vm, nfiles, files, autoDestroyConn,
VIR_DOMAIN_RUNNING_BOOTED) < 0) {
virDomainAuditStart(vm, "booted", false);
virLXCDomainObjEndJob(driver, vm);
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 587ba1d3c1..4934a96e0c 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -87,21 +87,15 @@ static int
virLXCProcessReboot(virLXCDriver *driver,
virDomainObj *vm)
{
- virConnectPtr conn = virCloseCallbacksGetConn(driver->closeCallbacks, vm);
+ g_autoptr(virConnect) autoDestroyConn =
virCloseCallbacksGetConn(driver->closeCallbacks, vm);
int reason = vm->state.reason;
- bool autodestroy = false;
int ret = -1;
virDomainDef *savedDef;
VIR_DEBUG("Faking reboot");
- if (conn) {
- virObjectRef(conn);
- autodestroy = true;
- } else {
- conn = virConnectOpen("lxc:///system");
- /* Ignoring NULL conn which is mostly harmless here */
- }
+ if (autoDestroyConn)
+ virObjectRef(autoDestroyConn);
/* In a reboot scenario, we need to make sure we continue
* to use the current 'def', and not switch to 'newDef'.
@@ -110,8 +104,7 @@ virLXCProcessReboot(virLXCDriver *driver,
savedDef = g_steal_pointer(&vm->newDef);
virLXCProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN, 0);
vm->newDef = savedDef;
- if (virLXCProcessStart(conn, driver, vm,
- 0, NULL, autodestroy, reason) < 0) {
+ if (virLXCProcessStart(driver, vm, 0, NULL, autoDestroyConn, reason) < 0) {
VIR_WARN("Unable to handle reboot of vm %s",
vm->def->name);
goto cleanup;
@@ -120,7 +113,6 @@ virLXCProcessReboot(virLXCDriver *driver,
ret = 0;
cleanup:
- virObjectUnref(conn);
return ret;
}
@@ -1146,21 +1138,19 @@ virLXCProcessEnsureRootFS(virDomainObj *vm)
/**
* virLXCProcessStart:
- * @conn: pointer to connection
* @driver: pointer to driver structure
* @vm: pointer to virtual machine structure
- * @autoDestroy: mark the domain for auto destruction
+ * @autoDestroyConn: mark the domain for auto destruction for the passed connection
object
* @reason: reason for switching vm to running state
*
* Starts a vm
*
* Returns 0 on success or -1 in case of error
*/
-int virLXCProcessStart(virConnectPtr conn,
- virLXCDriver * driver,
+int virLXCProcessStart(virLXCDriver * driver,
virDomainObj *vm,
unsigned int nfiles, int *files,
- bool autoDestroy,
+ virConnectPtr autoDestroyConn,
virDomainRunningReason reason)
{
int rc = -1, r;
@@ -1505,9 +1495,9 @@ int virLXCProcessStart(virConnectPtr conn,
goto cleanup;
}
- if (autoDestroy &&
+ if (autoDestroyConn &&
virCloseCallbacksSet(driver->closeCallbacks, vm,
- conn, lxcProcessAutoDestroy) < 0)
+ autoDestroyConn, lxcProcessAutoDestroy) < 0)
goto cleanup;
/* We don't need the temporary NIC names anymore, clear them */
@@ -1568,8 +1558,7 @@ virLXCProcessAutostartDomain(virDomainObj *vm,
virObjectLock(vm);
if (vm->autostart &&
!virDomainObjIsActive(vm)) {
- ret = virLXCProcessStart(data->conn, data->driver, vm,
- 0, NULL, false,
+ ret = virLXCProcessStart(data->driver, vm, 0, NULL, NULL,
VIR_DOMAIN_RUNNING_BOOTED);
virDomainAuditStart(vm, "booted", ret >= 0);
if (ret < 0) {
diff --git a/src/lxc/lxc_process.h b/src/lxc/lxc_process.h
index 1bce57809c..4b84e31fef 100644
--- a/src/lxc/lxc_process.h
+++ b/src/lxc/lxc_process.h
@@ -23,11 +23,10 @@
#include "lxc_conf.h"
-int virLXCProcessStart(virConnectPtr conn,
- virLXCDriver * driver,
+int virLXCProcessStart(virLXCDriver * driver,
virDomainObj *vm,
unsigned int nfiles, int *files,
- bool autoDestroy,
+ virConnectPtr autoDestroyConn,
virDomainRunningReason reason);
int virLXCProcessStop(virLXCDriver *driver,
virDomainObj *vm,
--
2.36.1