mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-07-06 09:55:46 +00:00
LXC from native: convert phys network types to net hostdev devices
This commit is contained in:
parent
b73c029d83
commit
69fc236243
@ -369,6 +369,26 @@ error:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static virDomainHostdevDefPtr
|
||||||
|
lxcCreateHostdevDef(int mode, int type, const char *data)
|
||||||
|
{
|
||||||
|
virDomainHostdevDefPtr hostdev = virDomainHostdevDefAlloc();
|
||||||
|
|
||||||
|
if (!hostdev)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
hostdev->mode = mode;
|
||||||
|
hostdev->source.caps.type = type;
|
||||||
|
|
||||||
|
if (type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET &&
|
||||||
|
VIR_STRDUP(hostdev->source.caps.u.net.iface, data) < 0) {
|
||||||
|
virDomainHostdevDefFree(hostdev);
|
||||||
|
hostdev = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hostdev;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
lxcAddNetworkDefinition(virDomainDefPtr def,
|
lxcAddNetworkDefinition(virDomainDefPtr def,
|
||||||
const char *type,
|
const char *type,
|
||||||
@ -377,22 +397,36 @@ lxcAddNetworkDefinition(virDomainDefPtr def,
|
|||||||
const char *flag)
|
const char *flag)
|
||||||
{
|
{
|
||||||
virDomainNetDefPtr net = NULL;
|
virDomainNetDefPtr net = NULL;
|
||||||
|
virDomainHostdevDefPtr hostdev = NULL;
|
||||||
|
|
||||||
if ((type == NULL) || STREQ(type, "empty") || STREQ(type, "") ||
|
if ((type == NULL) || STREQ(type, "empty") || STREQ(type, "") ||
|
||||||
STREQ(type, "none"))
|
STREQ(type, "none"))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(net = lxcCreateNetDef(type, link, mac, flag)))
|
if (type != NULL && STREQ(type, "phys")) {
|
||||||
goto error;
|
if (!link ||
|
||||||
|
!(hostdev = lxcCreateHostdevDef(VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES,
|
||||||
|
VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET,
|
||||||
|
link)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0)
|
if (VIR_EXPAND_N(def->hostdevs, def->nhostdevs, 1) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
def->nets[def->nnets - 1] = net;
|
def->hostdevs[def->nhostdevs - 1] = hostdev;
|
||||||
|
} else {
|
||||||
|
if (!(net = lxcCreateNetDef(type, link, mac, flag)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0)
|
||||||
|
goto error;
|
||||||
|
def->nets[def->nnets - 1] = net;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virDomainNetDefFree(net);
|
virDomainNetDefFree(net);
|
||||||
|
virDomainHostdevDefFree(hostdev);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
tests/lxcconf2xmldata/lxcconf2xml-physnetwork.config
Normal file
6
tests/lxcconf2xmldata/lxcconf2xml-physnetwork.config
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
lxc.network.type = phys
|
||||||
|
lxc.network.link = eth0
|
||||||
|
|
||||||
|
lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
|
||||||
|
lxc.utsname = migrate_test
|
||||||
|
lxc.autodev=1
|
26
tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml
Normal file
26
tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<domain type='lxc'>
|
||||||
|
<name>migrate_test</name>
|
||||||
|
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||||
|
<memory unit='KiB'>65536</memory>
|
||||||
|
<currentMemory unit='KiB'>0</currentMemory>
|
||||||
|
<vcpu placement='static' current='0'>1</vcpu>
|
||||||
|
<os>
|
||||||
|
<type>exe</type>
|
||||||
|
<init>/sbin/init</init>
|
||||||
|
</os>
|
||||||
|
<clock offset='utc'/>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<filesystem type='mount' accessmode='passthrough'>
|
||||||
|
<source dir='/var/lib/lxc/migrate_test/rootfs'/>
|
||||||
|
<target dir='/'/>
|
||||||
|
</filesystem>
|
||||||
|
<hostdev mode='capabilities' type='net'>
|
||||||
|
<source>
|
||||||
|
<interface>eth0</interface>
|
||||||
|
</source>
|
||||||
|
</hostdev>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
@ -106,6 +106,7 @@ mymain(void)
|
|||||||
DO_TEST("fstab", true);
|
DO_TEST("fstab", true);
|
||||||
DO_TEST("nonetwork", false);
|
DO_TEST("nonetwork", false);
|
||||||
DO_TEST("nonenetwork", false);
|
DO_TEST("nonenetwork", false);
|
||||||
|
DO_TEST("physnetwork", false);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user