#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"
"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
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;
}
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,
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)
/*
* 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
#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"
}
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
*
+ * Copyright (C) 2014, 2016 Red Hat, Inc.
* Copyright IBM Corp. 2014
*
* This library is free software; you can redistribute it and/or
# 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__ */