Move the misplaced function from qemu_command.c to qemu_interface.c since it's closer in functionality there and had less to do with building the command line.
Rename function to qemuInterfacePhysicalConnect and modify callers. Signed-off-by: John Ferlan <jfer...@redhat.com> --- src/qemu/qemu_command.c | 58 +++-------------------------------------------- src/qemu/qemu_command.h | 7 ------ src/qemu/qemu_hotplug.c | 5 ++-- src/qemu/qemu_interface.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_interface.h | 9 ++++++++ 5 files changed, 72 insertions(+), 64 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 04bfc75..be61b21 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, "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 * @brname: the bridge name @@ -8490,7 +8437,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd, memset(tapfd, -1, tapfdSize * sizeof(tapfd[0])); - if (qemuPhysIfaceConnect(def, driver, net, tapfd, tapfdSize, vmop) < 0) + if (qemuInterfacePhysicalConnect(def, driver, net, + tapfd, tapfdSize, vmop) < 0) goto cleanup; } diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index f549aa5..2201c27 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 8771780..bfc771d 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 (qemuInterfacePhysicalConnect(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 4d55e4d..dbfdf0f 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 <config.h> #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; } + + +/** + * qemuInterfacePhysicalConnect: + * @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 +qemuInterfacePhysicalConnect(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 b4c1efc..aa2791e 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 qemuInterfacePhysicalConnect(virDomainDefPtr def, + virQEMUDriverPtr driver, + virDomainNetDefPtr net, + int *tapfd, + size_t tapfdSize, + virNetDevVPortProfileOp vmop); + #endif /* __QEMU_INTERFACE_H__ */ -- 2.5.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list