mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-08 22:15:21 +00:00
qemu: stop passing in virConnectPtr for looking up networks
When setting up graphics, we sometimes need to resolve networks, requiring the caller to pass in a virConnectPtr, except sometimes they pass in NULL. Use virGetConnectNetwork() to acquire the connection to the network driver when it is needed. Reviewed-by: John Ferlan <jferlan@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
6ea0ae9619
commit
6678a44777
@ -7222,7 +7222,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
|
|||||||
net->script = script;
|
net->script = script;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(cmd = qemuProcessCreatePretendCmd(conn, driver, vm, NULL,
|
if (!(cmd = qemuProcessCreatePretendCmd(driver, vm, NULL,
|
||||||
qemuCheckFips(), true,
|
qemuCheckFips(), true,
|
||||||
VIR_QEMU_PROCESS_START_COLD)))
|
VIR_QEMU_PROCESS_START_COLD)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -2752,7 +2752,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
|
|||||||
dataFD[0])))
|
dataFD[0])))
|
||||||
goto stopjob;
|
goto stopjob;
|
||||||
|
|
||||||
if (qemuProcessPrepareDomain(dconn, driver, vm, startFlags) < 0)
|
if (qemuProcessPrepareDomain(driver, vm, startFlags) < 0)
|
||||||
goto stopjob;
|
goto stopjob;
|
||||||
|
|
||||||
if (qemuProcessPrepareHost(driver, vm, startFlags) < 0)
|
if (qemuProcessPrepareHost(driver, vm, startFlags) < 0)
|
||||||
|
@ -4327,10 +4327,10 @@ qemuProcessGraphicsAllocatePorts(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuProcessGetNetworkAddress(virConnectPtr conn,
|
qemuProcessGetNetworkAddress(const char *netname,
|
||||||
const char *netname,
|
|
||||||
char **netaddr)
|
char **netaddr)
|
||||||
{
|
{
|
||||||
|
virConnectPtr conn = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virNetworkPtr net;
|
virNetworkPtr net;
|
||||||
virNetworkDefPtr netdef = NULL;
|
virNetworkDefPtr netdef = NULL;
|
||||||
@ -4341,6 +4341,10 @@ qemuProcessGetNetworkAddress(virConnectPtr conn,
|
|||||||
char *xml = NULL;
|
char *xml = NULL;
|
||||||
|
|
||||||
*netaddr = NULL;
|
*netaddr = NULL;
|
||||||
|
|
||||||
|
if (!(conn = virGetConnectNetwork()))
|
||||||
|
return -1;
|
||||||
|
|
||||||
net = virNetworkLookupByName(conn, netname);
|
net = virNetworkLookupByName(conn, netname);
|
||||||
if (!net)
|
if (!net)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -4407,14 +4411,14 @@ qemuProcessGetNetworkAddress(virConnectPtr conn,
|
|||||||
cleanup:
|
cleanup:
|
||||||
virNetworkDefFree(netdef);
|
virNetworkDefFree(netdef);
|
||||||
virObjectUnref(net);
|
virObjectUnref(net);
|
||||||
|
virObjectUnref(conn);
|
||||||
VIR_FREE(xml);
|
VIR_FREE(xml);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuProcessGraphicsSetupNetworkAddress(virConnectPtr conn,
|
qemuProcessGraphicsSetupNetworkAddress(virDomainGraphicsListenDefPtr glisten,
|
||||||
virDomainGraphicsListenDefPtr glisten,
|
|
||||||
const char *listenAddr)
|
const char *listenAddr)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@ -4426,7 +4430,7 @@ qemuProcessGraphicsSetupNetworkAddress(virConnectPtr conn,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = qemuProcessGetNetworkAddress(conn, glisten->network, &glisten->address);
|
rc = qemuProcessGetNetworkAddress(glisten->network, &glisten->address);
|
||||||
if (rc <= -2) {
|
if (rc <= -2) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("network-based listen isn't possible, "
|
_("network-based listen isn't possible, "
|
||||||
@ -4441,8 +4445,7 @@ qemuProcessGraphicsSetupNetworkAddress(virConnectPtr conn,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuProcessGraphicsSetupListen(virConnectPtr conn,
|
qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver,
|
||||||
virQEMUDriverPtr driver,
|
|
||||||
virDomainGraphicsDefPtr graphics,
|
virDomainGraphicsDefPtr graphics,
|
||||||
virDomainObjPtr vm)
|
virDomainObjPtr vm)
|
||||||
{
|
{
|
||||||
@ -4500,8 +4503,7 @@ qemuProcessGraphicsSetupListen(virConnectPtr conn,
|
|||||||
if (glisten->address || !listenAddr)
|
if (glisten->address || !listenAddr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (qemuProcessGraphicsSetupNetworkAddress(conn,
|
if (qemuProcessGraphicsSetupNetworkAddress(glisten,
|
||||||
glisten,
|
|
||||||
listenAddr) < 0)
|
listenAddr) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
break;
|
break;
|
||||||
@ -4530,8 +4532,7 @@ qemuProcessGraphicsSetupListen(virConnectPtr conn,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuProcessSetupGraphics(virConnectPtr conn,
|
qemuProcessSetupGraphics(virQEMUDriverPtr driver,
|
||||||
virQEMUDriverPtr driver,
|
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
@ -4543,7 +4544,7 @@ qemuProcessSetupGraphics(virConnectPtr conn,
|
|||||||
for (i = 0; i < vm->def->ngraphics; i++) {
|
for (i = 0; i < vm->def->ngraphics; i++) {
|
||||||
graphics = vm->def->graphics[i];
|
graphics = vm->def->graphics[i];
|
||||||
|
|
||||||
if (qemuProcessGraphicsSetupListen(conn, driver, graphics, vm) < 0)
|
if (qemuProcessGraphicsSetupListen(driver, graphics, vm) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5625,7 +5626,6 @@ qemuProcessPrepareAllowReboot(virDomainObjPtr vm)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* qemuProcessPrepareDomain:
|
* qemuProcessPrepareDomain:
|
||||||
* @conn: connection object (for looking up storage volumes)
|
|
||||||
* @driver: qemu driver
|
* @driver: qemu driver
|
||||||
* @vm: domain object
|
* @vm: domain object
|
||||||
* @flags: qemuProcessStartFlags
|
* @flags: qemuProcessStartFlags
|
||||||
@ -5640,8 +5640,7 @@ qemuProcessPrepareAllowReboot(virDomainObjPtr vm)
|
|||||||
* TODO: move all XML modification from qemuBuildCommandLine into this function
|
* TODO: move all XML modification from qemuBuildCommandLine into this function
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
qemuProcessPrepareDomain(virConnectPtr conn,
|
qemuProcessPrepareDomain(virQEMUDriverPtr driver,
|
||||||
virQEMUDriverPtr driver,
|
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
@ -5698,7 +5697,7 @@ qemuProcessPrepareDomain(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Setting graphics devices");
|
VIR_DEBUG("Setting graphics devices");
|
||||||
if (qemuProcessSetupGraphics(conn, driver, vm, flags) < 0)
|
if (qemuProcessSetupGraphics(driver, vm, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Create domain masterKey");
|
VIR_DEBUG("Create domain masterKey");
|
||||||
@ -6329,7 +6328,7 @@ qemuProcessStart(virConnectPtr conn,
|
|||||||
goto stop;
|
goto stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuProcessPrepareDomain(conn, driver, vm, flags) < 0)
|
if (qemuProcessPrepareDomain(driver, vm, flags) < 0)
|
||||||
goto stop;
|
goto stop;
|
||||||
|
|
||||||
if (qemuProcessPrepareHost(driver, vm, flags) < 0)
|
if (qemuProcessPrepareHost(driver, vm, flags) < 0)
|
||||||
@ -6386,8 +6385,7 @@ qemuProcessStart(virConnectPtr conn,
|
|||||||
|
|
||||||
|
|
||||||
virCommandPtr
|
virCommandPtr
|
||||||
qemuProcessCreatePretendCmd(virConnectPtr conn,
|
qemuProcessCreatePretendCmd(virQEMUDriverPtr driver,
|
||||||
virQEMUDriverPtr driver,
|
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
const char *migrateURI,
|
const char *migrateURI,
|
||||||
bool enableFips,
|
bool enableFips,
|
||||||
@ -6407,7 +6405,7 @@ qemuProcessCreatePretendCmd(virConnectPtr conn,
|
|||||||
!!migrateURI, flags) < 0)
|
!!migrateURI, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuProcessPrepareDomain(conn, driver, vm, flags) < 0)
|
if (qemuProcessPrepareDomain(driver, vm, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Building emulator command line");
|
VIR_DEBUG("Building emulator command line");
|
||||||
|
@ -92,8 +92,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
virNetDevVPortProfileOp vmop,
|
virNetDevVPortProfileOp vmop,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
virCommandPtr qemuProcessCreatePretendCmd(virConnectPtr conn,
|
virCommandPtr qemuProcessCreatePretendCmd(virQEMUDriverPtr driver,
|
||||||
virQEMUDriverPtr driver,
|
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
const char *migrateURI,
|
const char *migrateURI,
|
||||||
bool enableFips,
|
bool enableFips,
|
||||||
@ -107,8 +106,7 @@ int qemuProcessInit(virQEMUDriverPtr driver,
|
|||||||
bool migration,
|
bool migration,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
int qemuProcessPrepareDomain(virConnectPtr conn,
|
int qemuProcessPrepareDomain(virQEMUDriverPtr driver,
|
||||||
virQEMUDriverPtr driver,
|
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
|
@ -498,7 +498,7 @@ testCompareXMLToArgv(const void *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(cmd = qemuProcessCreatePretendCmd(conn, &driver, vm, migrateURI,
|
if (!(cmd = qemuProcessCreatePretendCmd(&driver, vm, migrateURI,
|
||||||
(flags & FLAG_FIPS), false,
|
(flags & FLAG_FIPS), false,
|
||||||
VIR_QEMU_PROCESS_START_COLD))) {
|
VIR_QEMU_PROCESS_START_COLD))) {
|
||||||
if (flags & FLAG_EXPECT_FAILURE)
|
if (flags & FLAG_EXPECT_FAILURE)
|
||||||
|
Loading…
Reference in New Issue
Block a user