mirror of https://gitee.com/openkylin/libvirt.git
qemu: report TAP device indexes to systemd
Record the index of each TAP device created and report them to systemd, so they show up in machinectl status for the VM.
This commit is contained in:
parent
d0ab79e9cd
commit
f7afeddce9
|
@ -727,7 +727,9 @@ qemuSetupCpuCgroup(virQEMUDriverPtr driver,
|
|||
|
||||
static int
|
||||
qemuInitCgroup(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm)
|
||||
virDomainObjPtr vm,
|
||||
size_t nnicindexes,
|
||||
int *nicindexes)
|
||||
{
|
||||
int ret = -1;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
|
@ -769,7 +771,7 @@ qemuInitCgroup(virQEMUDriverPtr driver,
|
|||
NULL,
|
||||
vm->pid,
|
||||
false,
|
||||
0, NULL,
|
||||
nnicindexes, nicindexes,
|
||||
vm->def->resource->partition,
|
||||
cfg->cgroupControllers,
|
||||
&priv->cgroup) < 0) {
|
||||
|
@ -855,7 +857,9 @@ qemuConnectCgroup(virQEMUDriverPtr driver,
|
|||
|
||||
int
|
||||
qemuSetupCgroup(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm)
|
||||
virDomainObjPtr vm,
|
||||
size_t nnicindexes,
|
||||
int *nicindexes)
|
||||
{
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
virCapsPtr caps = NULL;
|
||||
|
@ -867,7 +871,7 @@ qemuSetupCgroup(virQEMUDriverPtr driver,
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (qemuInitCgroup(driver, vm) < 0)
|
||||
if (qemuInitCgroup(driver, vm, nnicindexes, nicindexes) < 0)
|
||||
return -1;
|
||||
|
||||
if (!priv->cgroup)
|
||||
|
@ -1023,7 +1027,6 @@ qemuSetupCgroupForVcpu(virDomainObjPtr vm)
|
|||
/* If we don't know VCPU<->PID mapping or all vcpu runs in the same
|
||||
* thread, we cannot control each vcpu.
|
||||
*/
|
||||
VIR_WARN("Unable to get vcpus' pids.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,9 @@ int qemuTeardownHostdevCgroup(virDomainObjPtr vm,
|
|||
int qemuConnectCgroup(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm);
|
||||
int qemuSetupCgroup(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm);
|
||||
virDomainObjPtr vm,
|
||||
size_t nnicindexes,
|
||||
int *nicindexes);
|
||||
int qemuSetupCpusetMems(virDomainObjPtr vm);
|
||||
int qemuSetupCgroupVcpuBW(virCgroupPtr cgroup,
|
||||
unsigned long long period,
|
||||
|
|
|
@ -289,7 +289,8 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
|
|||
virDomainNetDefPtr net,
|
||||
virQEMUCapsPtr qemuCaps,
|
||||
int *tapfd,
|
||||
size_t *tapfdSize)
|
||||
size_t *tapfdSize,
|
||||
int *nicindex)
|
||||
{
|
||||
const char *brname;
|
||||
int ret = -1;
|
||||
|
@ -330,6 +331,8 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
|
|||
virDomainAuditNetDevice(def, net, tunpath, false);
|
||||
goto cleanup;
|
||||
}
|
||||
if (virNetDevGetIndex(net->ifname, nicindex) < 0)
|
||||
goto cleanup;
|
||||
if (virDomainNetGetActualBridgeMACTableManager(net)
|
||||
== VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_LIBVIRT) {
|
||||
/* libvirt is managing the FDB of the bridge this device
|
||||
|
@ -7425,7 +7428,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
|
|||
int vlan,
|
||||
int bootindex,
|
||||
virNetDevVPortProfileOp vmop,
|
||||
bool standalone)
|
||||
bool standalone,
|
||||
int *nicindex)
|
||||
{
|
||||
int ret = -1;
|
||||
char *nic = NULL, *host = NULL;
|
||||
|
@ -7439,6 +7443,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
|
|||
virNetDevBandwidthPtr actualBandwidth;
|
||||
size_t i;
|
||||
|
||||
*nicindex = -1;
|
||||
|
||||
if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER)
|
||||
return qemuBuildVhostuserCommandLine(cmd, def, net, qemuCaps);
|
||||
|
||||
|
@ -7475,7 +7481,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
|
|||
memset(tapfd, -1, tapfdSize * sizeof(tapfd[0]));
|
||||
|
||||
if (qemuNetworkIfaceConnect(def, driver, net,
|
||||
qemuCaps, tapfd, &tapfdSize) < 0)
|
||||
qemuCaps, tapfd,
|
||||
&tapfdSize, nicindex) < 0)
|
||||
goto cleanup;
|
||||
} else if (actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
if (VIR_ALLOC(tapfd) < 0 || VIR_ALLOC(tapfdName) < 0)
|
||||
|
@ -7830,7 +7837,9 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||
qemuBuildCommandLineCallbacksPtr callbacks,
|
||||
bool standalone,
|
||||
bool enableFips,
|
||||
virBitmapPtr nodeset)
|
||||
virBitmapPtr nodeset,
|
||||
size_t *nnicindexes,
|
||||
int **nicindexes)
|
||||
{
|
||||
virErrorPtr originalError = NULL;
|
||||
size_t i, j;
|
||||
|
@ -7875,6 +7884,9 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||
|
||||
virUUIDFormat(def->uuid, uuid);
|
||||
|
||||
*nnicindexes = 0;
|
||||
*nicindexes = NULL;
|
||||
|
||||
emulator = def->emulator;
|
||||
|
||||
if (!cfg->privileged) {
|
||||
|
@ -8931,10 +8943,15 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||
else
|
||||
vlan = i;
|
||||
|
||||
if (VIR_EXPAND_N(*nicindexes, *nnicindexes, 1) < 0)
|
||||
goto error;
|
||||
|
||||
if (qemuBuildInterfaceCommandLine(cmd, driver, def, net,
|
||||
qemuCaps, vlan, bootNet, vmop,
|
||||
standalone) < 0)
|
||||
standalone,
|
||||
&((*nicindexes)[*nnicindexes - 1])) < 0)
|
||||
goto error;
|
||||
|
||||
last_good_net = i;
|
||||
bootNet = 0;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,9 @@ virCommandPtr qemuBuildCommandLine(virConnectPtr conn,
|
|||
qemuBuildCommandLineCallbacksPtr callbacks,
|
||||
bool forXMLToArgv,
|
||||
bool enableFips,
|
||||
virBitmapPtr nodeset)
|
||||
virBitmapPtr nodeset,
|
||||
size_t *nnicindexes,
|
||||
int **nicindexes)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(11);
|
||||
|
||||
/* Generate '-device' string for chardev device */
|
||||
|
@ -194,7 +196,8 @@ int qemuNetworkIfaceConnect(virDomainDefPtr def,
|
|||
virDomainNetDefPtr net,
|
||||
virQEMUCapsPtr qemuCaps,
|
||||
int *tapfd,
|
||||
size_t *tapfdSize)
|
||||
size_t *tapfdSize,
|
||||
int *nicindex)
|
||||
ATTRIBUTE_NONNULL(2);
|
||||
|
||||
int qemuPhysIfaceConnect(virDomainDefPtr def,
|
||||
|
|
|
@ -6335,6 +6335,8 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
|
|||
size_t i;
|
||||
virQEMUDriverConfigPtr cfg;
|
||||
virCapsPtr caps = NULL;
|
||||
size_t nnicindexes = 0;
|
||||
int *nicindexes = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
|
@ -6520,13 +6522,14 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
|
|||
&buildCommandLineCallbacks,
|
||||
true,
|
||||
qemuCheckFips(),
|
||||
NULL)))
|
||||
NULL,
|
||||
&nnicindexes, &nicindexes)))
|
||||
goto cleanup;
|
||||
|
||||
ret = virCommandToString(cmd);
|
||||
|
||||
cleanup:
|
||||
|
||||
VIR_FREE(nicindexes);
|
||||
virObjectUnref(qemuCaps);
|
||||
virCommandFree(cmd);
|
||||
virDomainDefFree(def);
|
||||
|
|
|
@ -846,6 +846,7 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
|
|||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
char **tapfdName = NULL;
|
||||
int *tapfd = NULL;
|
||||
int nicindex = -1;
|
||||
size_t tapfdSize = 0;
|
||||
char **vhostfdName = NULL;
|
||||
int *vhostfd = NULL;
|
||||
|
@ -915,7 +916,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
|
|||
goto cleanup;
|
||||
memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize);
|
||||
if (qemuNetworkIfaceConnect(vm->def, driver, net,
|
||||
priv->qemuCaps, tapfd, &tapfdSize) < 0)
|
||||
priv->qemuCaps, tapfd, &tapfdSize,
|
||||
&nicindex) < 0)
|
||||
goto cleanup;
|
||||
iface_connected = true;
|
||||
if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, vhostfd, &vhostfdSize) < 0)
|
||||
|
|
|
@ -4278,6 +4278,8 @@ int qemuProcessStart(virConnectPtr conn,
|
|||
virQEMUDriverConfigPtr cfg;
|
||||
virCapsPtr caps = NULL;
|
||||
unsigned int hostdev_flags = 0;
|
||||
size_t nnicindexes = 0;
|
||||
int *nicindexes = NULL;
|
||||
|
||||
VIR_DEBUG("vm=%p name=%s id=%d pid=%llu",
|
||||
vm, vm->def->name, vm->def->id,
|
||||
|
@ -4597,7 +4599,8 @@ int qemuProcessStart(virConnectPtr conn,
|
|||
migrateFrom, stdin_fd, snapshot, vmop,
|
||||
&buildCommandLineCallbacks, false,
|
||||
qemuCheckFips(),
|
||||
nodemask)))
|
||||
nodemask,
|
||||
&nnicindexes, &nicindexes)))
|
||||
goto cleanup;
|
||||
|
||||
/* now that we know it is about to start call the hook if present */
|
||||
|
@ -4734,7 +4737,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||
}
|
||||
|
||||
VIR_DEBUG("Setting up domain cgroup (if required)");
|
||||
if (qemuSetupCgroup(driver, vm) < 0)
|
||||
if (qemuSetupCgroup(driver, vm, nnicindexes, nicindexes) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* This must be done after cgroup placement to avoid resetting CPU
|
||||
|
@ -4947,6 +4950,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||
VIR_FORCE_CLOSE(logfile);
|
||||
virObjectUnref(cfg);
|
||||
virObjectUnref(caps);
|
||||
VIR_FREE(nicindexes);
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -4962,6 +4966,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||
qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED, stop_flags);
|
||||
virObjectUnref(cfg);
|
||||
virObjectUnref(caps);
|
||||
VIR_FREE(nicindexes);
|
||||
|
||||
return -1;
|
||||
|
||||
|
|
|
@ -262,6 +262,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
|||
char *log = NULL;
|
||||
virCommandPtr cmd = NULL;
|
||||
size_t i;
|
||||
size_t nnicindexes = 0;
|
||||
int *nicindexes = NULL;
|
||||
|
||||
if (!(conn = virGetConnect()))
|
||||
goto out;
|
||||
|
@ -346,7 +348,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
|||
VIR_NETDEV_VPORT_PROFILE_OP_NO_OP,
|
||||
&testCallbacks, false,
|
||||
(flags & FLAG_FIPS),
|
||||
NULL))) {
|
||||
NULL, &nnicindexes, &nicindexes))) {
|
||||
if (!virtTestOOMActive() &&
|
||||
(flags & FLAG_EXPECT_FAILURE)) {
|
||||
ret = 0;
|
||||
|
@ -393,6 +395,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
|||
ret = 0;
|
||||
|
||||
out:
|
||||
VIR_FREE(nicindexes);
|
||||
VIR_FREE(log);
|
||||
VIR_FREE(expectargv);
|
||||
VIR_FREE(actualargv);
|
||||
|
|
|
@ -44,6 +44,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
|||
char *log = NULL;
|
||||
char *emulator = NULL;
|
||||
virCommandPtr cmd = NULL;
|
||||
size_t nnicindexes = 0;
|
||||
int *nicindexes = NULL;
|
||||
|
||||
if (!(conn = virGetConnect()))
|
||||
goto fail;
|
||||
|
@ -119,7 +121,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
|||
vmdef, &monitor_chr, json, extraFlags,
|
||||
migrateFrom, migrateFd, NULL,
|
||||
VIR_NETDEV_VPORT_PROFILE_OP_NO_OP,
|
||||
&testCallbacks, false, false, NULL)))
|
||||
&testCallbacks, false, false, NULL,
|
||||
&nnicindexes, &nicindexes)))
|
||||
goto fail;
|
||||
|
||||
if (!virtTestOOMActive()) {
|
||||
|
@ -155,6 +158,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
|||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(nicindexes);
|
||||
VIR_FREE(log);
|
||||
VIR_FREE(emulator);
|
||||
VIR_FREE(expectargv);
|
||||
|
|
Loading…
Reference in New Issue