mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
virLXCProcessStart: Pass in virConnect object only when registering autodestroy
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@redhat.com> Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
This commit is contained in:
parent
e44a5f43cb
commit
ed0507b58a
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user