--- src/lxc/lxc_native.c | 44 +++++++++++++++++++--- .../lxcconf2xmldata/lxcconf2xml-physnetwork.config | 6 +++ tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml | 26 +++++++++++++ tests/lxcconf2xmltest.c | 1 + 4 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-physnetwork.config create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index c4238a8..ad33845 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -360,6 +360,26 @@ error: 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 lxcAddNetworkDefinition(virDomainDefPtr def, const char *type, @@ -368,22 +388,36 @@ lxcAddNetworkDefinition(virDomainDefPtr def, const char *flag) { virDomainNetDefPtr net = NULL; + virDomainHostdevDefPtr hostdev = NULL; if ((type == NULL) || STREQ(type, "empty") || STREQ(type, "") || STREQ(type, "none")) return 0; - if (!(net = lxcCreateNetDef(type, link, mac, flag))) - goto error; + if (type != NULL && STREQ(type, "phys")) { + 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) - goto error; - def->nets[def->nnets - 1] = net; + if (VIR_EXPAND_N(def->hostdevs, def->nhostdevs, 1) < 0) + goto error; + 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; error: virDomainNetDefFree(net); + virDomainHostdevDefFree(hostdev); return -1; } diff --git a/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.config b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.config new file mode 100644 index 0000000..63a4aa1 --- /dev/null +++ b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.config @@ -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 diff --git a/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml new file mode 100644 index 0000000..35a2a96 --- /dev/null +++ b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml @@ -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> diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c index 50041a5..c888b42 100644 --- a/tests/lxcconf2xmltest.c +++ b/tests/lxcconf2xmltest.c @@ -106,6 +106,7 @@ mymain(void) DO_TEST("fstab", true); DO_TEST("nonetwork", false); DO_TEST("nonenetwork", false); + DO_TEST("physnetwork", false); return ret; } -- 1.8.5.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list