mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-04-26 15:14:42 +00:00
lxc: report veth device indexes to systemd
Record the index of each host-side veth device created and report them to systemd, so they show up in machinectl status for the VM. lxc-shell(95449419f969d649d9962566ec42af7d) Since: Fri 2015-01-16 16:53:37 GMT; 3s ago Leader: 28085 (sh) Service: libvirt-lxc; class container Iface: vnet0 Address: fe80::216:3eff:fe00:c317%124 OS: Fedora 21 (Twenty One) Unit: machine-lxc\x2dshell.scope └─28085 /bin/sh
This commit is contained in:
parent
e4fc4f0c99
commit
a2bdfa5261
@ -463,7 +463,9 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
|
|||||||
|
|
||||||
|
|
||||||
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def,
|
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def,
|
||||||
pid_t initpid)
|
pid_t initpid,
|
||||||
|
size_t nnicindexes,
|
||||||
|
int *nicindexes)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
virCgroupPtr cgroup = NULL;
|
||||||
|
|
||||||
@ -481,7 +483,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def,
|
|||||||
NULL,
|
NULL,
|
||||||
initpid,
|
initpid,
|
||||||
true,
|
true,
|
||||||
0, NULL,
|
nnicindexes, nicindexes,
|
||||||
def->resource->partition,
|
def->resource->partition,
|
||||||
-1,
|
-1,
|
||||||
&cgroup) < 0)
|
&cgroup) < 0)
|
||||||
|
@ -28,7 +28,9 @@
|
|||||||
# include "virusb.h"
|
# include "virusb.h"
|
||||||
|
|
||||||
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def,
|
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def,
|
||||||
pid_t initpid);
|
pid_t initpid,
|
||||||
|
size_t nnicindexes,
|
||||||
|
int *nicindexes);
|
||||||
virCgroupPtr virLXCCgroupJoin(virDomainDefPtr def);
|
virCgroupPtr virLXCCgroupJoin(virDomainDefPtr def);
|
||||||
int virLXCCgroupSetup(virDomainDefPtr def,
|
int virLXCCgroupSetup(virDomainDefPtr def,
|
||||||
virCgroupPtr cgroup,
|
virCgroupPtr cgroup,
|
||||||
|
@ -110,6 +110,9 @@ struct _virLXCController {
|
|||||||
size_t nveths;
|
size_t nveths;
|
||||||
char **veths;
|
char **veths;
|
||||||
|
|
||||||
|
size_t nnicindexes;
|
||||||
|
int *nicindexes;
|
||||||
|
|
||||||
size_t npassFDs;
|
size_t npassFDs;
|
||||||
int *passFDs;
|
int *passFDs;
|
||||||
|
|
||||||
@ -260,6 +263,7 @@ static void virLXCControllerFree(virLXCControllerPtr ctrl)
|
|||||||
for (i = 0; i < ctrl->nveths; i++)
|
for (i = 0; i < ctrl->nveths; i++)
|
||||||
VIR_FREE(ctrl->veths[i]);
|
VIR_FREE(ctrl->veths[i]);
|
||||||
VIR_FREE(ctrl->veths);
|
VIR_FREE(ctrl->veths);
|
||||||
|
VIR_FREE(ctrl->nicindexes);
|
||||||
|
|
||||||
for (i = 0; i < ctrl->npassFDs; i++)
|
for (i = 0; i < ctrl->npassFDs; i++)
|
||||||
VIR_FORCE_CLOSE(ctrl->passFDs[i]);
|
VIR_FORCE_CLOSE(ctrl->passFDs[i]);
|
||||||
@ -344,6 +348,51 @@ static int virLXCControllerValidateNICs(virLXCControllerPtr ctrl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int virLXCControllerGetNICIndexes(virLXCControllerPtr ctrl)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
VIR_DEBUG("Getting nic indexes");
|
||||||
|
for (i = 0; i < ctrl->def->nnets; i++) {
|
||||||
|
int nicindex = -1;
|
||||||
|
switch (ctrl->def->nets[i]->type) {
|
||||||
|
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
||||||
|
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
||||||
|
if (ctrl->def->nets[i]->ifname == NULL)
|
||||||
|
continue;
|
||||||
|
if (virNetDevGetIndex(ctrl->def->nets[i]->ifname,
|
||||||
|
&nicindex) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
if (VIR_EXPAND_N(ctrl->nicindexes,
|
||||||
|
ctrl->nnicindexes,
|
||||||
|
1) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
VIR_DEBUG("Index %d for %s", nicindex,
|
||||||
|
ctrl->def->nets[i]->ifname);
|
||||||
|
ctrl->nicindexes[ctrl->nnicindexes-1] = nicindex;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIR_DOMAIN_NET_TYPE_USER:
|
||||||
|
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
||||||
|
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
||||||
|
case VIR_DOMAIN_NET_TYPE_SERVER:
|
||||||
|
case VIR_DOMAIN_NET_TYPE_CLIENT:
|
||||||
|
case VIR_DOMAIN_NET_TYPE_MCAST:
|
||||||
|
case VIR_DOMAIN_NET_TYPE_INTERNAL:
|
||||||
|
case VIR_DOMAIN_NET_TYPE_DIRECT:
|
||||||
|
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int virLXCControllerValidateConsoles(virLXCControllerPtr ctrl)
|
static int virLXCControllerValidateConsoles(virLXCControllerPtr ctrl)
|
||||||
{
|
{
|
||||||
if (ctrl->def->nconsoles != ctrl->nconsoles) {
|
if (ctrl->def->nconsoles != ctrl->nconsoles) {
|
||||||
@ -732,7 +781,9 @@ static int virLXCControllerSetupCgroupLimits(virLXCControllerPtr ctrl)
|
|||||||
nodeset = virDomainNumatuneGetNodeset(ctrl->def->numatune, auto_nodeset, -1);
|
nodeset = virDomainNumatuneGetNodeset(ctrl->def->numatune, auto_nodeset, -1);
|
||||||
|
|
||||||
if (!(ctrl->cgroup = virLXCCgroupCreate(ctrl->def,
|
if (!(ctrl->cgroup = virLXCCgroupCreate(ctrl->def,
|
||||||
ctrl->initpid)))
|
ctrl->initpid,
|
||||||
|
ctrl->nnicindexes,
|
||||||
|
ctrl->nicindexes)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virCgroupAddTask(ctrl->cgroup, getpid()) < 0)
|
if (virCgroupAddTask(ctrl->cgroup, getpid()) < 0)
|
||||||
@ -2494,6 +2545,9 @@ int main(int argc, char *argv[])
|
|||||||
if (virLXCControllerValidateNICs(ctrl) < 0)
|
if (virLXCControllerValidateNICs(ctrl) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virLXCControllerGetNICIndexes(ctrl) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCControllerValidateConsoles(ctrl) < 0)
|
if (virLXCControllerValidateConsoles(ctrl) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user