mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-20 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;
|
virObjectEvent *event = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
|
g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
|
||||||
|
virConnect *autoDestroyConn = NULL;
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, -1);
|
virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, -1);
|
||||||
|
|
||||||
|
if (flags & VIR_DOMAIN_START_AUTODESTROY)
|
||||||
|
autoDestroyConn = dom->conn;
|
||||||
|
|
||||||
if (!(vm = lxcDomObjFromDomain(dom)))
|
if (!(vm = lxcDomObjFromDomain(dom)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -988,9 +992,7 @@ static int lxcDomainCreateWithFiles(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virLXCProcessStart(dom->conn, driver, vm,
|
ret = virLXCProcessStart(driver, vm, nfiles, files, autoDestroyConn,
|
||||||
nfiles, files,
|
|
||||||
(flags & VIR_DOMAIN_START_AUTODESTROY),
|
|
||||||
VIR_DOMAIN_RUNNING_BOOTED);
|
VIR_DOMAIN_RUNNING_BOOTED);
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
@ -1065,10 +1067,13 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
|
|||||||
g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
|
g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
|
||||||
g_autoptr(virCaps) caps = NULL;
|
g_autoptr(virCaps) caps = NULL;
|
||||||
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
|
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
|
||||||
|
virConnect *autoDestroyConn = NULL;
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_START_AUTODESTROY |
|
virCheckFlags(VIR_DOMAIN_START_AUTODESTROY |
|
||||||
VIR_DOMAIN_START_VALIDATE, NULL);
|
VIR_DOMAIN_START_VALIDATE, NULL);
|
||||||
|
|
||||||
|
if (flags & VIR_DOMAIN_START_AUTODESTROY)
|
||||||
|
autoDestroyConn = conn;
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_START_VALIDATE)
|
if (flags & VIR_DOMAIN_START_VALIDATE)
|
||||||
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
|
||||||
@ -1106,9 +1111,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virLXCProcessStart(conn, driver, vm,
|
if (virLXCProcessStart(driver, vm, nfiles, files, autoDestroyConn,
|
||||||
nfiles, files,
|
|
||||||
(flags & VIR_DOMAIN_START_AUTODESTROY),
|
|
||||||
VIR_DOMAIN_RUNNING_BOOTED) < 0) {
|
VIR_DOMAIN_RUNNING_BOOTED) < 0) {
|
||||||
virDomainAuditStart(vm, "booted", false);
|
virDomainAuditStart(vm, "booted", false);
|
||||||
virLXCDomainObjEndJob(driver, vm);
|
virLXCDomainObjEndJob(driver, vm);
|
||||||
|
@ -87,21 +87,15 @@ static int
|
|||||||
virLXCProcessReboot(virLXCDriver *driver,
|
virLXCProcessReboot(virLXCDriver *driver,
|
||||||
virDomainObj *vm)
|
virDomainObj *vm)
|
||||||
{
|
{
|
||||||
virConnectPtr conn = virCloseCallbacksGetConn(driver->closeCallbacks, vm);
|
g_autoptr(virConnect) autoDestroyConn = virCloseCallbacksGetConn(driver->closeCallbacks, vm);
|
||||||
int reason = vm->state.reason;
|
int reason = vm->state.reason;
|
||||||
bool autodestroy = false;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virDomainDef *savedDef;
|
virDomainDef *savedDef;
|
||||||
|
|
||||||
VIR_DEBUG("Faking reboot");
|
VIR_DEBUG("Faking reboot");
|
||||||
|
|
||||||
if (conn) {
|
if (autoDestroyConn)
|
||||||
virObjectRef(conn);
|
virObjectRef(autoDestroyConn);
|
||||||
autodestroy = true;
|
|
||||||
} else {
|
|
||||||
conn = virConnectOpen("lxc:///system");
|
|
||||||
/* Ignoring NULL conn which is mostly harmless here */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* In a reboot scenario, we need to make sure we continue
|
/* In a reboot scenario, we need to make sure we continue
|
||||||
* to use the current 'def', and not switch to 'newDef'.
|
* to use the current 'def', and not switch to 'newDef'.
|
||||||
@ -110,8 +104,7 @@ virLXCProcessReboot(virLXCDriver *driver,
|
|||||||
savedDef = g_steal_pointer(&vm->newDef);
|
savedDef = g_steal_pointer(&vm->newDef);
|
||||||
virLXCProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN, 0);
|
virLXCProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN, 0);
|
||||||
vm->newDef = savedDef;
|
vm->newDef = savedDef;
|
||||||
if (virLXCProcessStart(conn, driver, vm,
|
if (virLXCProcessStart(driver, vm, 0, NULL, autoDestroyConn, reason) < 0) {
|
||||||
0, NULL, autodestroy, reason) < 0) {
|
|
||||||
VIR_WARN("Unable to handle reboot of vm %s",
|
VIR_WARN("Unable to handle reboot of vm %s",
|
||||||
vm->def->name);
|
vm->def->name);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -120,7 +113,6 @@ virLXCProcessReboot(virLXCDriver *driver,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virObjectUnref(conn);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1146,21 +1138,19 @@ virLXCProcessEnsureRootFS(virDomainObj *vm)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* virLXCProcessStart:
|
* virLXCProcessStart:
|
||||||
* @conn: pointer to connection
|
|
||||||
* @driver: pointer to driver structure
|
* @driver: pointer to driver structure
|
||||||
* @vm: pointer to virtual machine 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
|
* @reason: reason for switching vm to running state
|
||||||
*
|
*
|
||||||
* Starts a vm
|
* Starts a vm
|
||||||
*
|
*
|
||||||
* Returns 0 on success or -1 in case of error
|
* Returns 0 on success or -1 in case of error
|
||||||
*/
|
*/
|
||||||
int virLXCProcessStart(virConnectPtr conn,
|
int virLXCProcessStart(virLXCDriver * driver,
|
||||||
virLXCDriver * driver,
|
|
||||||
virDomainObj *vm,
|
virDomainObj *vm,
|
||||||
unsigned int nfiles, int *files,
|
unsigned int nfiles, int *files,
|
||||||
bool autoDestroy,
|
virConnectPtr autoDestroyConn,
|
||||||
virDomainRunningReason reason)
|
virDomainRunningReason reason)
|
||||||
{
|
{
|
||||||
int rc = -1, r;
|
int rc = -1, r;
|
||||||
@ -1505,9 +1495,9 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autoDestroy &&
|
if (autoDestroyConn &&
|
||||||
virCloseCallbacksSet(driver->closeCallbacks, vm,
|
virCloseCallbacksSet(driver->closeCallbacks, vm,
|
||||||
conn, lxcProcessAutoDestroy) < 0)
|
autoDestroyConn, lxcProcessAutoDestroy) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* We don't need the temporary NIC names anymore, clear them */
|
/* We don't need the temporary NIC names anymore, clear them */
|
||||||
@ -1568,8 +1558,7 @@ virLXCProcessAutostartDomain(virDomainObj *vm,
|
|||||||
virObjectLock(vm);
|
virObjectLock(vm);
|
||||||
if (vm->autostart &&
|
if (vm->autostart &&
|
||||||
!virDomainObjIsActive(vm)) {
|
!virDomainObjIsActive(vm)) {
|
||||||
ret = virLXCProcessStart(data->conn, data->driver, vm,
|
ret = virLXCProcessStart(data->driver, vm, 0, NULL, NULL,
|
||||||
0, NULL, false,
|
|
||||||
VIR_DOMAIN_RUNNING_BOOTED);
|
VIR_DOMAIN_RUNNING_BOOTED);
|
||||||
virDomainAuditStart(vm, "booted", ret >= 0);
|
virDomainAuditStart(vm, "booted", ret >= 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -23,11 +23,10 @@
|
|||||||
|
|
||||||
#include "lxc_conf.h"
|
#include "lxc_conf.h"
|
||||||
|
|
||||||
int virLXCProcessStart(virConnectPtr conn,
|
int virLXCProcessStart(virLXCDriver * driver,
|
||||||
virLXCDriver * driver,
|
|
||||||
virDomainObj *vm,
|
virDomainObj *vm,
|
||||||
unsigned int nfiles, int *files,
|
unsigned int nfiles, int *files,
|
||||||
bool autoDestroy,
|
virConnectPtr autoDestroyConn,
|
||||||
virDomainRunningReason reason);
|
virDomainRunningReason reason);
|
||||||
int virLXCProcessStop(virLXCDriver *driver,
|
int virLXCProcessStop(virLXCDriver *driver,
|
||||||
virDomainObj *vm,
|
virDomainObj *vm,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user