diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 17baf76d0197b4322de8e3d50c5f957b461dfeea..4b461f2197682359b34f14afd688a310317b51c1 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -26,6 +26,7 @@ #include "qemu_command.h" #include "qemu_hostdev.h" #include "qemu_capabilities.h" +#include "qemu_interface.h" #include "cpu/cpu.h" #include "dirname.h" #include "passfd.h" @@ -153,60 +154,6 @@ VIR_ENUM_IMPL(qemuNumaPolicy, VIR_DOMAIN_NUMATUNE_MEM_LAST, "preferred", "interleave"); -/** - * qemuPhysIfaceConnect: - * @def: the definition of the VM (needed by 802.1Qbh and audit) - * @driver: pointer to the driver instance - * @net: pointer to the VM's interface description with direct device type - * @tapfd: array of file descriptor return value for the new device - * @tapfdSize: number of file descriptors in @tapfd - * @vmop: VM operation type - * - * Returns 0 on success or -1 in case of error. - */ -int -qemuPhysIfaceConnect(virDomainDefPtr def, - virQEMUDriverPtr driver, - virDomainNetDefPtr net, - int *tapfd, - size_t tapfdSize, - virNetDevVPortProfileOp vmop) -{ - int ret = -1; - char *res_ifname = NULL; - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP; - - if (net->model && STREQ(net->model, "virtio")) - macvlan_create_flags |= VIR_NETDEV_MACVLAN_VNET_HDR; - - if (virNetDevMacVLanCreateWithVPortProfile(net->ifname, - &net->mac, - virDomainNetGetActualDirectDev(net), - virDomainNetGetActualDirectMode(net), - def->uuid, - virDomainNetGetActualVirtPortProfile(net), - &res_ifname, - vmop, cfg->stateDir, - tapfd, tapfdSize, - macvlan_create_flags) < 0) - goto cleanup; - - virDomainAuditNetDevice(def, net, res_ifname, true); - VIR_FREE(net->ifname); - net->ifname = res_ifname; - ret = 0; - - cleanup: - if (ret < 0) { - while (tapfdSize--) - VIR_FORCE_CLOSE(tapfd[tapfdSize]); - } - virObjectUnref(cfg); - return ret; -} - - /** * qemuCreateInBridgePortWithHelper: * @cfg: the configuration object in which the helper name is looked up @@ -8492,7 +8439,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd, memset(tapfd, -1, tapfdSize * sizeof(tapfd[0])); - if (qemuPhysIfaceConnect(def, driver, net, tapfd, tapfdSize, vmop) < 0) + if (qemuInterfaceDirectConnect(def, driver, net, + tapfd, tapfdSize, vmop) < 0) goto cleanup; } diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index f549aa5390ce82da7e38af3afe63ca68cbc72334..2201c279cbd0515ef71e3e4ec3418f82cfbf42ca 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -230,13 +230,6 @@ int qemuNetworkIfaceConnect(virDomainDefPtr def, size_t *tapfdSize) ATTRIBUTE_NONNULL(2); -int qemuPhysIfaceConnect(virDomainDefPtr def, - virQEMUDriverPtr driver, - virDomainNetDefPtr net, - int *tapfd, - size_t tapfdSize, - virNetDevVPortProfileOp vmop); - int qemuOpenVhostNet(virDomainDefPtr def, virDomainNetDefPtr net, virQEMUCapsPtr qemuCaps, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index afa99f125d5f4806cc00b7cf55ae502deb97d317..84421552416dcb97a7c633c09e4a0b654e16bba3 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -938,8 +938,9 @@ int qemuDomainAttachNetDevice(virConnectPtr conn, if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) goto cleanup; memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize); - if (qemuPhysIfaceConnect(vm->def, driver, net, tapfd, tapfdSize, - VIR_NETDEV_VPORT_PROFILE_OP_CREATE) < 0) + if (qemuInterfaceDirectConnect(vm->def, driver, net, + tapfd, tapfdSize, + VIR_NETDEV_VPORT_PROFILE_OP_CREATE) < 0) goto cleanup; iface_connected = true; if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, vhostfd, &vhostfdSize) < 0) diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index 4d55e4dfd7b3364958b299399da4b2db027d785a..d3a1abc5781a06e028ecae5a6af2ef253879f0f3 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -1,6 +1,7 @@ /* * qemu_interface.c: QEMU interface management * + * Copyright (C) 2015-2016 Red Hat, Inc. * Copyright IBM Corp. 2014 * * This library is free software; you can redistribute it and/or @@ -24,7 +25,9 @@ #include #include "network_conf.h" +#include "domain_audit.h" #include "qemu_interface.h" +#include "viralloc.h" #include "virnetdev.h" #include "virnetdevtap.h" #include "virnetdevmacvlan.h" @@ -219,3 +222,57 @@ qemuInterfaceStopDevices(virDomainDefPtr def) } return 0; } + + +/** + * qemuInterfaceDirectConnect: + * @def: the definition of the VM (needed by 802.1Qbh and audit) + * @driver: pointer to the driver instance + * @net: pointer to the VM's interface description with direct device type + * @tapfd: array of file descriptor return value for the new device + * @tapfdSize: number of file descriptors in @tapfd + * @vmop: VM operation type + * + * Returns 0 on success or -1 in case of error. + */ +int +qemuInterfaceDirectConnect(virDomainDefPtr def, + virQEMUDriverPtr driver, + virDomainNetDefPtr net, + int *tapfd, + size_t tapfdSize, + virNetDevVPortProfileOp vmop) +{ + int ret = -1; + char *res_ifname = NULL; + virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP; + + if (net->model && STREQ(net->model, "virtio")) + macvlan_create_flags |= VIR_NETDEV_MACVLAN_VNET_HDR; + + if (virNetDevMacVLanCreateWithVPortProfile(net->ifname, + &net->mac, + virDomainNetGetActualDirectDev(net), + virDomainNetGetActualDirectMode(net), + def->uuid, + virDomainNetGetActualVirtPortProfile(net), + &res_ifname, + vmop, cfg->stateDir, + tapfd, tapfdSize, + macvlan_create_flags) < 0) + goto cleanup; + + virDomainAuditNetDevice(def, net, res_ifname, true); + VIR_FREE(net->ifname); + net->ifname = res_ifname; + ret = 0; + + cleanup: + if (ret < 0) { + while (tapfdSize--) + VIR_FORCE_CLOSE(tapfd[tapfdSize]); + } + virObjectUnref(cfg); + return ret; +} diff --git a/src/qemu/qemu_interface.h b/src/qemu/qemu_interface.h index b4c1efcb084c50643e51742aa1283fb49d291899..48a8e96bde231cbd0716554cc2eb9fed1984d937 100644 --- a/src/qemu/qemu_interface.h +++ b/src/qemu/qemu_interface.h @@ -1,6 +1,7 @@ /* * qemu_interface.h: QEMU interface management * + * Copyright (C) 2014, 2016 Red Hat, Inc. * Copyright IBM Corp. 2014 * * This library is free software; you can redistribute it and/or @@ -25,10 +26,18 @@ # define __QEMU_INTERFACE_H__ # include "domain_conf.h" +# include "qemu_conf.h" int qemuInterfaceStartDevice(virDomainNetDefPtr net); int qemuInterfaceStartDevices(virDomainDefPtr def); int qemuInterfaceStopDevice(virDomainNetDefPtr net); int qemuInterfaceStopDevices(virDomainDefPtr def); +int qemuInterfaceDirectConnect(virDomainDefPtr def, + virQEMUDriverPtr driver, + virDomainNetDefPtr net, + int *tapfd, + size_t tapfdSize, + virNetDevVPortProfileOp vmop); + #endif /* __QEMU_INTERFACE_H__ */