提交 442d6a05 编写于 作者: B Bogdan Purcareata 提交者: Daniel P. Berrange

Implement support for <hostdev caps=net>

This allows a container-type domain to have exclusive access to one of
the host's NICs.

Wire <hostdev caps=net> with the lxc_controller - when moving the newly
created veth devices into a new namespace, also look for any hostdev
devices that should be moved. Note: once the container domain has been
destroyed, there is no code that moves the interfaces back to the
original namespace. This does happen, though, probably due to default
cleanup on namespace destruction.
Signed-off-by: NBogdan Purcareata <bogdan.purcareata@freescale.com>
上级 4aafa1ff
...@@ -1551,7 +1551,6 @@ cleanup: ...@@ -1551,7 +1551,6 @@ cleanup:
return ret; return ret;
} }
static int lxcContainerSetupHostdevSubsys(virDomainDefPtr vmDef, static int lxcContainerSetupHostdevSubsys(virDomainDefPtr vmDef,
virDomainHostdevDefPtr def, virDomainHostdevDefPtr def,
const char *dstprefix, const char *dstprefix,
...@@ -1582,6 +1581,9 @@ static int lxcContainerSetupHostdevCaps(virDomainDefPtr vmDef, ...@@ -1582,6 +1581,9 @@ static int lxcContainerSetupHostdevCaps(virDomainDefPtr vmDef,
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
return lxcContainerSetupHostdevCapsMisc(vmDef, def, dstprefix, securityDriver); return lxcContainerSetupHostdevCapsMisc(vmDef, def, dstprefix, securityDriver);
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
return 0; // case is handled in virLXCControllerMoveInterfaces
default: default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported host device mode %s"), _("Unsupported host device mode %s"),
...@@ -2286,6 +2288,22 @@ virArch lxcContainerGetAlt32bitArch(virArch arch) ...@@ -2286,6 +2288,22 @@ virArch lxcContainerGetAlt32bitArch(virArch arch)
} }
static bool
lxcNeedNetworkNamespace(virDomainDefPtr def)
{
size_t i;
if (def->nets != NULL)
return true;
if (def->features & (1 << VIR_DOMAIN_FEATURE_PRIVNET))
return true;
for (i = 0 ; i < def->nhostdevs ; i++) {
if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES &&
def->hostdevs[i]->source.caps.type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET)
return true;
}
return false;
}
/** /**
* lxcContainerStart: * lxcContainerStart:
* @def: pointer to virtual machine structure * @def: pointer to virtual machine structure
...@@ -2329,8 +2347,7 @@ int lxcContainerStart(virDomainDefPtr def, ...@@ -2329,8 +2347,7 @@ int lxcContainerStart(virDomainDefPtr def,
cflags |= CLONE_NEWUSER; cflags |= CLONE_NEWUSER;
} }
if (def->nets != NULL || if (lxcNeedNetworkNamespace(def)) {
(def->features & (1 << VIR_DOMAIN_FEATURE_PRIVNET))) {
VIR_DEBUG("Enable network namespaces"); VIR_DEBUG("Enable network namespaces");
cflags |= CLONE_NEWNET; cflags |= CLONE_NEWNET;
} }
......
...@@ -1050,12 +1050,28 @@ cleanup2: ...@@ -1050,12 +1050,28 @@ cleanup2:
static int virLXCControllerMoveInterfaces(virLXCControllerPtr ctrl) static int virLXCControllerMoveInterfaces(virLXCControllerPtr ctrl)
{ {
size_t i; size_t i;
virDomainDefPtr def = ctrl->def;
for (i = 0 ; i < ctrl->nveths ; i++) { for (i = 0 ; i < ctrl->nveths ; i++) {
if (virNetDevSetNamespace(ctrl->veths[i], ctrl->initpid) < 0) if (virNetDevSetNamespace(ctrl->veths[i], ctrl->initpid) < 0)
return -1; return -1;
} }
for (i = 0; i < def->nhostdevs; i ++) {
virDomainHostdevDefPtr hdev = def->hostdevs[i];
if (hdev->mode != VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES)
continue;
virDomainHostdevCaps hdcaps = hdev->source.caps;
if (hdcaps.type != VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET)
continue;
if (virNetDevSetNamespace(hdcaps.u.net.iface, ctrl->initpid) < 0)
return -1;
}
return 0; return 0;
} }
......
...@@ -307,6 +307,7 @@ int virLXCPrepareHostDevices(virLXCDriverPtr driver, ...@@ -307,6 +307,7 @@ int virLXCPrepareHostDevices(virLXCDriverPtr driver,
switch (dev->source.subsys.type) { switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE:
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
break; break;
default: default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
......
...@@ -31,5 +31,10 @@ ...@@ -31,5 +31,10 @@
<char>/dev/tty0</char> <char>/dev/tty0</char>
</source> </source>
</hostdev> </hostdev>
<hostdev mode='capabilities' type='net'>
<source>
<interface>eth0</interface>
</source>
</hostdev>
</devices> </devices>
</domain> </domain>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册