提交 59372413 编写于 作者: J John Ferlan

qemu: Move qemuPhysIfaceConnect to qemu_interface.c and rename

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 qemuInterfaceDirectConnect and modify callers.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 efc4080d
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "qemu_command.h" #include "qemu_command.h"
#include "qemu_hostdev.h" #include "qemu_hostdev.h"
#include "qemu_capabilities.h" #include "qemu_capabilities.h"
#include "qemu_interface.h"
#include "cpu/cpu.h" #include "cpu/cpu.h"
#include "dirname.h" #include "dirname.h"
#include "passfd.h" #include "passfd.h"
...@@ -153,60 +154,6 @@ VIR_ENUM_IMPL(qemuNumaPolicy, VIR_DOMAIN_NUMATUNE_MEM_LAST, ...@@ -153,60 +154,6 @@ VIR_ENUM_IMPL(qemuNumaPolicy, VIR_DOMAIN_NUMATUNE_MEM_LAST,
"preferred", "preferred",
"interleave"); "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: * qemuCreateInBridgePortWithHelper:
* @cfg: the configuration object in which the helper name is looked up * @cfg: the configuration object in which the helper name is looked up
...@@ -8492,7 +8439,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd, ...@@ -8492,7 +8439,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
memset(tapfd, -1, tapfdSize * sizeof(tapfd[0])); 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; goto cleanup;
} }
......
...@@ -230,13 +230,6 @@ int qemuNetworkIfaceConnect(virDomainDefPtr def, ...@@ -230,13 +230,6 @@ int qemuNetworkIfaceConnect(virDomainDefPtr def,
size_t *tapfdSize) size_t *tapfdSize)
ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(2);
int qemuPhysIfaceConnect(virDomainDefPtr def,
virQEMUDriverPtr driver,
virDomainNetDefPtr net,
int *tapfd,
size_t tapfdSize,
virNetDevVPortProfileOp vmop);
int qemuOpenVhostNet(virDomainDefPtr def, int qemuOpenVhostNet(virDomainDefPtr def,
virDomainNetDefPtr net, virDomainNetDefPtr net,
virQEMUCapsPtr qemuCaps, virQEMUCapsPtr qemuCaps,
......
...@@ -938,7 +938,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn, ...@@ -938,7 +938,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0)
goto cleanup; goto cleanup;
memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize); memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize);
if (qemuPhysIfaceConnect(vm->def, driver, net, tapfd, tapfdSize, if (qemuInterfaceDirectConnect(vm->def, driver, net,
tapfd, tapfdSize,
VIR_NETDEV_VPORT_PROFILE_OP_CREATE) < 0) VIR_NETDEV_VPORT_PROFILE_OP_CREATE) < 0)
goto cleanup; goto cleanup;
iface_connected = true; iface_connected = true;
......
/* /*
* qemu_interface.c: QEMU interface management * qemu_interface.c: QEMU interface management
* *
* Copyright (C) 2015-2016 Red Hat, Inc.
* Copyright IBM Corp. 2014 * Copyright IBM Corp. 2014
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -24,7 +25,9 @@ ...@@ -24,7 +25,9 @@
#include <config.h> #include <config.h>
#include "network_conf.h" #include "network_conf.h"
#include "domain_audit.h"
#include "qemu_interface.h" #include "qemu_interface.h"
#include "viralloc.h"
#include "virnetdev.h" #include "virnetdev.h"
#include "virnetdevtap.h" #include "virnetdevtap.h"
#include "virnetdevmacvlan.h" #include "virnetdevmacvlan.h"
...@@ -219,3 +222,57 @@ qemuInterfaceStopDevices(virDomainDefPtr def) ...@@ -219,3 +222,57 @@ qemuInterfaceStopDevices(virDomainDefPtr def)
} }
return 0; 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;
}
/* /*
* qemu_interface.h: QEMU interface management * qemu_interface.h: QEMU interface management
* *
* Copyright (C) 2014, 2016 Red Hat, Inc.
* Copyright IBM Corp. 2014 * Copyright IBM Corp. 2014
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -25,10 +26,18 @@ ...@@ -25,10 +26,18 @@
# define __QEMU_INTERFACE_H__ # define __QEMU_INTERFACE_H__
# include "domain_conf.h" # include "domain_conf.h"
# include "qemu_conf.h"
int qemuInterfaceStartDevice(virDomainNetDefPtr net); int qemuInterfaceStartDevice(virDomainNetDefPtr net);
int qemuInterfaceStartDevices(virDomainDefPtr def); int qemuInterfaceStartDevices(virDomainDefPtr def);
int qemuInterfaceStopDevice(virDomainNetDefPtr net); int qemuInterfaceStopDevice(virDomainNetDefPtr net);
int qemuInterfaceStopDevices(virDomainDefPtr def); int qemuInterfaceStopDevices(virDomainDefPtr def);
int qemuInterfaceDirectConnect(virDomainDefPtr def,
virQEMUDriverPtr driver,
virDomainNetDefPtr net,
int *tapfd,
size_t tapfdSize,
virNetDevVPortProfileOp vmop);
#endif /* __QEMU_INTERFACE_H__ */ #endif /* __QEMU_INTERFACE_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册