2008-11-19 16:58:23 +00:00
|
|
|
/*
|
|
|
|
* uml_conf.c: UML driver configuration
|
|
|
|
*
|
2013-03-26 11:21:33 +00:00
|
|
|
* Copyright (C) 2006-2013 Red Hat, Inc.
|
2008-11-19 16:58:23 +00:00
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-11-19 16:58:23 +00:00
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include "uml_conf.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2012-12-12 16:35:35 +00:00
|
|
|
#include "virconf.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
make NUMA-initialization code more portable and more robust
qemudCapsInitNUMA and umlCapsInitNUMA were identical, so this change
factors them into a new function, virCapsInitNUMA, and puts it in
nodeinfo.c.
In addition to factoring out the duplicates, this change also
adjusts that function definition (along with its macros) so
that it works with Fedora 9's numactl version 1, and makes it
so the code will work even if someone builds the kernel with
CONFIG_NR_CPUS > 4096.
Finally, also perform this NUMA initialization for the lxc
and openvz drivers.
* src/nodeinfo.c: Include <stdint.h>, <numa.h> and "memory.h".
(virCapsInitNUMA): Rename from qemudCapsInitNUMA and umlCapsInitNUMA.
(NUMA_MAX_N_CPUS): Define depending on NUMA API version.
(n_bits, MASK_CPU_ISSET): Define, adjust, use uint64 rather than long.
* src/nodeinfo.h: Include "capabilities.h".
(virCapsInitNUMA): Declare it.
* examples/domain-events/events-c/Makefile.am:
* src/Makefile.am: Add $(NUMACTL_CFLAGS) and $(NUMACTL_LIBS) to various
compile/link-related variables.
* src/qemu_conf.c: Include "nodeinfo.h".
(qemudCapsInitNUMA): Remove duplicate code. Adjust caller.
* src/uml_conf.c (umlCapsInitNUMA): Likewise.
Include "nodeinfo.h".
* src/lxc_conf.c: Include "nodeinfo.h".
(lxcCapsInit): Perform NUMA initialization here, too.
* src/openvz_conf.c (openvzCapsInit): And here.
Include "nodeinfo.h".
* src/libvirt_sym.version.in: Add virCapsInitNUMA so that libvirtd
can link to this function.
2008-12-21 18:55:09 +00:00
|
|
|
#include "nodeinfo.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2010-09-07 08:19:56 +00:00
|
|
|
#include "domain_nwfilter.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2012-12-12 16:27:01 +00:00
|
|
|
#include "vircommand.h"
|
Split bridge.h into three separate files
Following the renaming of the bridge management APIs, we can now
split the source file into 3 corresponding pieces
* src/util/virnetdev.c: APIs for any type of network interface
* src/util/virnetdevbridge.c: APIs for bridge interfaces
* src/util/virnetdevtap.c: APIs for TAP interfaces
* src/util/virnetdev.c, src/util/virnetdev.h,
src/util/virnetdevbridge.c, src/util/virnetdevbridge.h,
src/util/virnetdevtap.c, src/util/virnetdevtap.h: Copied
from bridge.{c,h}
* src/util/bridge.c, src/util/bridge.h: Split into 3 pieces
* src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/openvz/openvz_driver.c, src/qemu/qemu_command.c,
src/qemu/qemu_conf.h, src/uml/uml_conf.c, src/uml/uml_conf.h,
src/uml/uml_driver.c: Update #include directives
2011-11-02 13:41:58 +00:00
|
|
|
#include "virnetdevtap.h"
|
2011-11-29 15:28:26 +00:00
|
|
|
#include "virnodesuspend.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2008-11-19 16:58:23 +00:00
|
|
|
|
2009-01-29 12:10:32 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_UML
|
2008-11-19 16:58:23 +00:00
|
|
|
|
Fix default console type setting
The default console type may vary based on the OS type. ie a Xen
paravirt guests wants a 'xen' console, while a fullvirt guests
wants a 'serial' console.
A plain integer default console type in the capabilities does
not suffice. Instead introduce a callback that is passed the
OS type.
* src/conf/capabilities.h: Use a callback for default console
type
* src/conf/domain_conf.c, src/conf/domain_conf.h: Use callback
for default console type. Add missing LXC/OpenVZ console types.
* src/esx/esx_driver.c, src/libxl/libxl_conf.c,
src/lxc/lxc_conf.c, src/openvz/openvz_conf.c,
src/phyp/phyp_driver.c, src/qemu/qemu_capabilities.c,
src/uml/uml_conf.c, src/vbox/vbox_tmpl.c,
src/vmware/vmware_conf.c, src/xen/xen_hypervisor.c,
src/xenapi/xenapi_driver.c: Set default console type callback
2011-10-20 13:56:20 +00:00
|
|
|
|
2008-11-19 16:58:23 +00:00
|
|
|
virCapsPtr umlCapsInit(void) {
|
|
|
|
virCapsPtr caps;
|
|
|
|
virCapsGuestPtr guest;
|
|
|
|
|
2012-12-10 22:28:09 +00:00
|
|
|
if ((caps = virCapabilitiesNew(virArchFromHost(),
|
2008-11-19 16:58:23 +00:00
|
|
|
0, 0)) == NULL)
|
2010-05-25 14:33:51 +00:00
|
|
|
goto error;
|
2008-11-19 16:58:23 +00:00
|
|
|
|
2009-08-13 10:56:31 +00:00
|
|
|
/* Some machines have problematic NUMA toplogy causing
|
|
|
|
* unexpected failures. We don't want to break the QEMU
|
|
|
|
* driver in this scenario, so log errors & carry on
|
|
|
|
*/
|
|
|
|
if (nodeCapsInitNUMA(caps) < 0) {
|
|
|
|
virCapabilitiesFreeNUMAInfo(caps);
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
|
2009-08-13 10:56:31 +00:00
|
|
|
}
|
2008-11-19 16:58:23 +00:00
|
|
|
|
2011-11-29 15:28:26 +00:00
|
|
|
if (virNodeSuspendGetTargetMask(&caps->host.powerMgmt) < 0)
|
|
|
|
VIR_WARN("Failed to get host power management capabilities");
|
|
|
|
|
2010-05-25 14:33:51 +00:00
|
|
|
if (virGetHostUUID(caps->host.host_uuid)) {
|
2012-07-18 12:01:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2010-05-25 14:33:51 +00:00
|
|
|
"%s", _("cannot get the host uuid"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2008-11-19 16:58:23 +00:00
|
|
|
if ((guest = virCapabilitiesAddGuest(caps,
|
|
|
|
"uml",
|
2012-12-10 22:28:09 +00:00
|
|
|
caps->host.arch,
|
2008-11-19 16:58:23 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL)) == NULL)
|
2010-05-25 14:33:51 +00:00
|
|
|
goto error;
|
2008-11-19 16:58:23 +00:00
|
|
|
|
|
|
|
if (virCapabilitiesAddGuestDomain(guest,
|
|
|
|
"uml",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL) == NULL)
|
2010-05-25 14:33:51 +00:00
|
|
|
goto error;
|
2008-11-19 16:58:23 +00:00
|
|
|
|
|
|
|
return caps;
|
|
|
|
|
2010-05-25 14:33:51 +00:00
|
|
|
error:
|
2013-02-01 12:26:18 +00:00
|
|
|
virObjectUnref(caps);
|
2008-11-19 16:58:23 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-03 11:13:33 +00:00
|
|
|
static int
|
2010-09-07 08:19:56 +00:00
|
|
|
umlConnectTapDevice(virConnectPtr conn,
|
2011-12-09 02:35:20 +00:00
|
|
|
virDomainDefPtr vm,
|
2010-09-07 08:19:56 +00:00
|
|
|
virDomainNetDefPtr net,
|
2009-06-03 11:13:33 +00:00
|
|
|
const char *bridge)
|
|
|
|
{
|
2011-07-29 15:36:17 +00:00
|
|
|
bool template_ifname = false;
|
2013-05-23 13:22:35 +00:00
|
|
|
int tapfd = -1;
|
2009-06-03 11:13:33 +00:00
|
|
|
|
2009-08-18 12:32:42 +00:00
|
|
|
if (!net->ifname ||
|
2011-07-29 15:36:17 +00:00
|
|
|
STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) ||
|
2009-08-18 12:32:42 +00:00
|
|
|
strchr(net->ifname, '%')) {
|
|
|
|
VIR_FREE(net->ifname);
|
2013-05-03 12:49:48 +00:00
|
|
|
if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_PREFIX "%d") < 0)
|
|
|
|
goto error;
|
2011-05-06 19:53:10 +00:00
|
|
|
/* avoid exposing vnet%d in getXMLDesc or error outputs */
|
2011-07-29 15:36:17 +00:00
|
|
|
template_ifname = true;
|
2009-08-18 12:32:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 12:07:59 +00:00
|
|
|
if (virNetDevTapCreateInBridgePort(bridge, &net->ifname, &net->mac,
|
2013-05-21 13:50:09 +00:00
|
|
|
vm->uuid, &tapfd, 1,
|
2012-03-01 20:35:30 +00:00
|
|
|
virDomainNetGetActualVirtPortProfile(net),
|
2012-08-30 09:14:32 +00:00
|
|
|
virDomainNetGetActualVlan(net),
|
network: fix dnsmasq/radvd binding to IPv6 on recent kernels
I hit this problem recently when trying to create a bridge with an IPv6
address on a 3.2 kernel: dnsmasq (and, further, radvd) would not bind to
the given address, waiting 20s and then giving up with -EADDRNOTAVAIL
(resp. exiting immediately with "error parsing or activating the config
file", without libvirt noticing it, BTW). This can be reproduced with (I
think) any kernel >= 2.6.39 and the following XML (to be used with
"virsh net-create"):
<network>
<name>test-bridge</name>
<bridge name='testbr0' />
<ip family='ipv6' address='fd00::1' prefix='64'>
</ip>
</network>
(it happens even when you have an IPv4, too)
The problem is that since commit [1] (which, ironically, was made to
“help IPv6 autoconfiguration”) the linux bridge code makes bridges
behave like “real” devices regarding carrier detection. This makes the
bridges created by libvirt, which are started without any up devices,
stay with the NO-CARRIER flag set, and thus prevents DAD (Duplicate
address detection) from happening, thus letting the IPv6 address flagged
as “tentative”. Such addresses cannot be bound to (see RFC 2462), so
dnsmasq fails binding to it (for radvd, it detects that "interface XXX
is not RUNNING", thus that "interface XXX does not exist, ignoring the
interface" (sic)). It seems that this behavior was enhanced somehow with
commit [2] by avoiding setting NO-CARRIER on empty bridges, but I
couldn't reproduce this behavior on my kernel. Anyway, with the “dummy
tap to set MAC address” trick, this wouldn't work.
To fix this, the idea is to get the bridge's attached device to be up so
that DAD can happen (deactivating DAD altogether is not a good idea, I
think). Currently, libvirt creates a dummy TAP device to set the MAC
address of the bridge, keeping it down. But even if we set this device
up, it is not RUNNING as soon as the tap file descriptor attached to it
is closed, thus still preventing DAD. So, we must modify the API a bit,
so that we can get the fd, keep the tap device persistent, run the
daemons, and close it after DAD has taken place. After that, the bridge
will be flagged NO-CARRIER again, but the daemons will be running, even
if not happy about the device's state (but we don't really care about
the bridge's daemons doing anything when no up interface is connected to
it).
Other solutions that I envisioned were:
* Keeping the *-nic interface up: this would waste an fd for each
bridge during all its life. May be acceptable, I don't really
know.
* Stop using the dummy tap trick, and set the MAC address directly
on the bridge: it is possible since quite some time it seems,
even if then there is the problem of the bridge not being
RUNNING when empty, contrary to what [2] says, so this will need
fixing (and this fix only happened in 3.1, so it wouldn't work
for 2.6.39)
* Using the --interface option of dnsmasq, but I saw somewhere
that it's not used by libvirt for backward compatibility. I am
not sure this would solve this problem, though, as I don't know
how dnsmasq binds itself to it with this option.
This is why this patch does what's described earlier.
This patch also makes radvd start even if the interface is
“missing” (i.e. it is not RUNNING), as it daemonizes before binding to
it, and thus sometimes does it after the interface has been brought down
by us (by closing the tap fd), and then originally stops. This also
makes it stop yelling about it in the logs when the interface is down at
a later time.
[1]
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=1faa4356a3bd89ea11fb92752d897cff3a20ec0e
[2]
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=b64b73d7d0c480f75684519c6134e79d50c1b341
2012-09-26 19:02:20 +00:00
|
|
|
VIR_NETDEV_TAP_CREATE_IFUP |
|
|
|
|
VIR_NETDEV_TAP_CREATE_PERSIST) < 0) {
|
2009-08-18 12:32:42 +00:00
|
|
|
if (template_ifname)
|
|
|
|
VIR_FREE(net->ifname);
|
2009-06-03 11:13:33 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2010-09-07 08:19:56 +00:00
|
|
|
if (net->filter) {
|
2011-12-09 02:35:20 +00:00
|
|
|
if (virDomainConfNWFilterInstantiate(conn, vm->uuid, net) < 0) {
|
2010-09-07 08:19:56 +00:00
|
|
|
if (template_ifname)
|
|
|
|
VIR_FREE(net->ifname);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-21 13:50:09 +00:00
|
|
|
VIR_FORCE_CLOSE(tapfd);
|
2009-06-03 11:13:33 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
2013-05-21 13:50:09 +00:00
|
|
|
VIR_FORCE_CLOSE(tapfd);
|
2009-06-03 11:13:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
umlBuildCommandLineNet(virConnectPtr conn,
|
2011-12-09 02:35:20 +00:00
|
|
|
virDomainDefPtr vm,
|
2009-06-03 11:13:33 +00:00
|
|
|
virDomainNetDefPtr def,
|
|
|
|
int idx)
|
|
|
|
{
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
2013-03-26 11:21:33 +00:00
|
|
|
char macaddr[VIR_MAC_STRING_BUFLEN];
|
2009-06-03 11:13:33 +00:00
|
|
|
|
|
|
|
/* General format: ethNN=type,options */
|
|
|
|
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, "eth%d=", idx);
|
2009-06-03 11:13:33 +00:00
|
|
|
|
|
|
|
switch (def->type) {
|
|
|
|
case VIR_DOMAIN_NET_TYPE_USER:
|
|
|
|
/* ethNNN=slirp,macaddr */
|
|
|
|
virBufferAddLit(&buf, "slirp");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
|
|
|
/* ethNNN=tuntap,tapname,macaddr,gateway */
|
2011-06-02 16:23:43 +00:00
|
|
|
virBufferAddLit(&buf, "tuntap,");
|
|
|
|
if (def->ifname) {
|
|
|
|
virBufferAdd(&buf, def->ifname, -1);
|
|
|
|
}
|
2009-06-03 11:13:33 +00:00
|
|
|
if (def->data.ethernet.ipaddr) {
|
2012-07-18 12:01:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2011-12-01 23:08:34 +00:00
|
|
|
_("IP address not supported for ethernet interface"));
|
2009-06-03 11:13:33 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_NET_TYPE_SERVER:
|
2012-07-18 12:01:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2009-06-03 11:13:33 +00:00
|
|
|
_("TCP server networking type not supported"));
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_NET_TYPE_CLIENT:
|
2012-07-18 12:01:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2009-06-03 11:13:33 +00:00
|
|
|
_("TCP client networking type not supported"));
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_NET_TYPE_MCAST:
|
|
|
|
/* ethNNN=tuntap,macaddr,ipaddr,port */
|
|
|
|
virBufferAddLit(&buf, "mcast");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
|
|
|
{
|
|
|
|
char *bridge;
|
|
|
|
virNetworkPtr network = virNetworkLookupByName(conn,
|
|
|
|
def->data.network.name);
|
|
|
|
if (!network) {
|
2012-07-18 12:01:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2009-06-03 11:13:33 +00:00
|
|
|
_("Network '%s' not found"),
|
|
|
|
def->data.network.name);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
bridge = virNetworkGetBridgeName(network);
|
|
|
|
virNetworkFree(network);
|
|
|
|
if (bridge == NULL) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2011-12-09 02:35:20 +00:00
|
|
|
if (umlConnectTapDevice(conn, vm, def, bridge) < 0) {
|
2009-06-03 11:13:33 +00:00
|
|
|
VIR_FREE(bridge);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ethNNN=tuntap,tapname,macaddr,gateway */
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, "tuntap,%s", def->ifname);
|
2009-06-03 11:13:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
2011-12-09 02:35:20 +00:00
|
|
|
if (umlConnectTapDevice(conn, vm, def,
|
|
|
|
def->data.bridge.brname) < 0)
|
2009-06-03 11:13:33 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* ethNNN=tuntap,tapname,macaddr,gateway */
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, "tuntap,%s", def->ifname);
|
2009-06-03 11:13:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_NET_TYPE_INTERNAL:
|
2012-07-18 12:01:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2009-06-03 11:13:33 +00:00
|
|
|
_("internal networking type not supported"));
|
|
|
|
goto error;
|
2010-03-26 16:01:35 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_NET_TYPE_DIRECT:
|
2012-07-18 12:01:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2010-03-26 16:01:35 +00:00
|
|
|
_("direct networking type not supported"));
|
|
|
|
goto error;
|
|
|
|
|
2012-02-15 17:37:15 +00:00
|
|
|
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
|
2012-07-18 12:01:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2012-02-15 17:37:15 +00:00
|
|
|
_("hostdev networking type not supported"));
|
|
|
|
goto error;
|
|
|
|
|
2010-03-26 16:01:35 +00:00
|
|
|
case VIR_DOMAIN_NET_TYPE_LAST:
|
|
|
|
break;
|
2009-06-03 11:13:33 +00:00
|
|
|
}
|
|
|
|
|
config: report error when script given for inappropriate interface type
This fixes https://bugzilla.redhat.com/show_bug.cgi?id=638633
Although scripts are not used by interfaces of type other than
"ethernet" in qemu, due to the fact that the parser stores the script
name in a union that is only valid when type is ethernet or bridge,
there is no way for anyone except the parser itself to catch the
problem of specifying an interface script for an inappropriate
interface type (by the time the parsed data gets back to the code that
called the parser, all evidence that a script was specified is
forgotten).
Since the parser itself should be agnostic to which type of interface
allows scripts (an example of why: a script specified for an interface
of type bridge is valid for xen domains, but not for qemu domains),
the solution here is to move the script out of the union(s) in the
DomainNetDef, always populate it when specified (regardless of
interface type), and let the driver decide whether or not it is
appropriate.
Currently the qemu, xen, libxml, and uml drivers recognize the script
parameter and do something with it (the uml driver only to report that
it isn't supported). Those drivers have been updated to log a
CONFIG_UNSUPPORTED error when a script is specified for an interface
type that's inappropriate for that particular hypervisor.
(NB: There was earlier discussion of solving this problem by adding a
VALIDATE flag to all libvirt APIs that accept XML, which would cause
the XML to be validated against the RNG files. One statement during
that discussion was that the RNG shouldn't contain hypervisor-specific
things, though, and a proper solution to this problem would require
that (again, because a script for an interface of type "bridge" is
accepted by xen, but not by qemu).
2012-01-06 17:59:47 +00:00
|
|
|
if (def->script) {
|
2012-07-18 12:01:08 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
config: report error when script given for inappropriate interface type
This fixes https://bugzilla.redhat.com/show_bug.cgi?id=638633
Although scripts are not used by interfaces of type other than
"ethernet" in qemu, due to the fact that the parser stores the script
name in a union that is only valid when type is ethernet or bridge,
there is no way for anyone except the parser itself to catch the
problem of specifying an interface script for an inappropriate
interface type (by the time the parsed data gets back to the code that
called the parser, all evidence that a script was specified is
forgotten).
Since the parser itself should be agnostic to which type of interface
allows scripts (an example of why: a script specified for an interface
of type bridge is valid for xen domains, but not for qemu domains),
the solution here is to move the script out of the union(s) in the
DomainNetDef, always populate it when specified (regardless of
interface type), and let the driver decide whether or not it is
appropriate.
Currently the qemu, xen, libxml, and uml drivers recognize the script
parameter and do something with it (the uml driver only to report that
it isn't supported). Those drivers have been updated to log a
CONFIG_UNSUPPORTED error when a script is specified for an interface
type that's inappropriate for that particular hypervisor.
(NB: There was earlier discussion of solving this problem by adding a
VALIDATE flag to all libvirt APIs that accept XML, which would cause
the XML to be validated against the RNG files. One statement during
that discussion was that the RNG shouldn't contain hypervisor-specific
things, though, and a proper solution to this problem would require
that (again, because a script for an interface of type "bridge" is
accepted by xen, but not by qemu).
2012-01-06 17:59:47 +00:00
|
|
|
_("interface script execution not supported by this driver"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-03-26 11:21:33 +00:00
|
|
|
virBufferAsprintf(&buf, ",%s", virMacAddrFormat(&def->mac, macaddr));
|
2009-06-03 11:13:33 +00:00
|
|
|
|
|
|
|
if (def->type == VIR_DOMAIN_NET_TYPE_MCAST) {
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, ",%s,%d",
|
2009-06-03 11:13:33 +00:00
|
|
|
def->data.socket.address,
|
|
|
|
def->data.socket.port);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virBufferError(&buf)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-06-03 11:13:33 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return virBufferContentAndReset(&buf);
|
|
|
|
|
|
|
|
error:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buf);
|
2009-06-03 11:13:33 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-11-19 16:58:23 +00:00
|
|
|
static char *
|
2010-04-03 13:33:29 +00:00
|
|
|
umlBuildCommandLineChr(virDomainChrDefPtr def,
|
2010-08-23 11:25:50 +00:00
|
|
|
const char *dev,
|
2010-05-25 13:17:48 +00:00
|
|
|
virCommandPtr cmd)
|
2008-11-19 16:58:23 +00:00
|
|
|
{
|
2009-09-03 10:05:52 +00:00
|
|
|
char *ret = NULL;
|
2008-11-19 16:58:23 +00:00
|
|
|
|
domain_conf: split source data out from ChrDef
This opens up the possibility of reusing the smaller ChrSourceDef
for both qemu monitor and a passthrough smartcard device.
* src/conf/domain_conf.h (_virDomainChrDef): Factor host
details...
(_virDomainChrSourceDef): ...into new struct.
(virDomainChrSourceDefFree): New prototype.
* src/conf/domain_conf.c (virDomainChrDefFree)
(virDomainChrDefParseXML, virDomainChrDefFormat): Split...
(virDomainChrSourceDefClear, virDomainChrSourceDefFree)
(virDomainChrSourceDefParseXML, virDomainChrSourceDefFormat):
...into new functions.
(virDomainChrDefParseTargetXML): Update clients to reflect type
split.
* src/vmx/vmx.c (virVMXParseSerial, virVMXParseParallel)
(virVMXFormatSerial, virVMXFormatParallel): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainOpenConsole): Likewise.
* src/xen/xend_internal.c (xenDaemonParseSxprChar)
(xenDaemonFormatSxprChr): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainDumpXML, vboxAttachSerial)
(vboxAttachParallel): Likewise.
* src/security/security_dac.c (virSecurityDACSetChardevLabel)
(virSecurityDACSetChardevCallback)
(virSecurityDACRestoreChardevLabel)
(virSecurityDACRestoreChardevCallback): Likewise.
* src/security/security_selinux.c (SELinuxSetSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback)
(SELinuxRestoreSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback): Likewise.
* src/security/virt-aa-helper.c (get_files): Likewise.
* src/lxc/lxc_driver.c (lxcVmStart, lxcDomainOpenConsole):
Likewise.
* src/uml/uml_conf.c (umlBuildCommandLineChr): Likewise.
* src/uml/uml_driver.c (umlIdentifyOneChrPTY, umlIdentifyChrPTY)
(umlDomainOpenConsole): Likewise.
* src/qemu/qemu_command.c (qemuBuildChrChardevStr)
(qemuBuildChrArgStr, qemuBuildCommandLine)
(qemuParseCommandLineChr): Likewise.
* src/qemu/qemu_domain.c (qemuDomainObjPrivateXMLFormat)
(qemuDomainObjPrivateXMLParse): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupChardevCgroup): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/qemu/qemu_driver.c (qemudFindCharDevicePTYsMonitor)
(qemudFindCharDevicePTYs, qemuPrepareChardevDevice)
(qemuPrepareMonitorChr, qemudShutdownVMDaemon)
(qemuDomainOpenConsole): Likewise.
* src/qemu/qemu_command.h (qemuBuildChrChardevStr)
(qemuBuildChrArgStr): Delete, now that they are static.
* src/libvirt_private.syms (domain_conf.h): New exports.
* cfg.mk (useless_free_options): Update list.
* tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Update
tests.
2011-01-07 22:45:01 +00:00
|
|
|
switch (def->source.type) {
|
2008-11-19 16:58:23 +00:00
|
|
|
case VIR_DOMAIN_CHR_TYPE_NULL:
|
2013-07-04 10:17:01 +00:00
|
|
|
if (virAsprintf(&ret, "%s%d=null", dev, def->target.port) < 0)
|
2008-11-19 16:58:23 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_PTY:
|
2013-07-04 10:17:01 +00:00
|
|
|
if (virAsprintf(&ret, "%s%d=pts", dev, def->target.port) < 0)
|
2008-11-19 16:58:23 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_DEV:
|
2009-11-05 13:19:14 +00:00
|
|
|
if (virAsprintf(&ret, "%s%d=tty:%s", dev, def->target.port,
|
2013-07-04 10:17:01 +00:00
|
|
|
def->source.data.file.path) < 0)
|
2008-11-19 16:58:23 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_STDIO:
|
2013-07-04 10:17:01 +00:00
|
|
|
if (virAsprintf(&ret, "%s%d=fd:0,fd:1", dev, def->target.port) < 0)
|
2008-11-19 16:58:23 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_TCP:
|
domain_conf: split source data out from ChrDef
This opens up the possibility of reusing the smaller ChrSourceDef
for both qemu monitor and a passthrough smartcard device.
* src/conf/domain_conf.h (_virDomainChrDef): Factor host
details...
(_virDomainChrSourceDef): ...into new struct.
(virDomainChrSourceDefFree): New prototype.
* src/conf/domain_conf.c (virDomainChrDefFree)
(virDomainChrDefParseXML, virDomainChrDefFormat): Split...
(virDomainChrSourceDefClear, virDomainChrSourceDefFree)
(virDomainChrSourceDefParseXML, virDomainChrSourceDefFormat):
...into new functions.
(virDomainChrDefParseTargetXML): Update clients to reflect type
split.
* src/vmx/vmx.c (virVMXParseSerial, virVMXParseParallel)
(virVMXFormatSerial, virVMXFormatParallel): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainOpenConsole): Likewise.
* src/xen/xend_internal.c (xenDaemonParseSxprChar)
(xenDaemonFormatSxprChr): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainDumpXML, vboxAttachSerial)
(vboxAttachParallel): Likewise.
* src/security/security_dac.c (virSecurityDACSetChardevLabel)
(virSecurityDACSetChardevCallback)
(virSecurityDACRestoreChardevLabel)
(virSecurityDACRestoreChardevCallback): Likewise.
* src/security/security_selinux.c (SELinuxSetSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback)
(SELinuxRestoreSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback): Likewise.
* src/security/virt-aa-helper.c (get_files): Likewise.
* src/lxc/lxc_driver.c (lxcVmStart, lxcDomainOpenConsole):
Likewise.
* src/uml/uml_conf.c (umlBuildCommandLineChr): Likewise.
* src/uml/uml_driver.c (umlIdentifyOneChrPTY, umlIdentifyChrPTY)
(umlDomainOpenConsole): Likewise.
* src/qemu/qemu_command.c (qemuBuildChrChardevStr)
(qemuBuildChrArgStr, qemuBuildCommandLine)
(qemuParseCommandLineChr): Likewise.
* src/qemu/qemu_domain.c (qemuDomainObjPrivateXMLFormat)
(qemuDomainObjPrivateXMLParse): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupChardevCgroup): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/qemu/qemu_driver.c (qemudFindCharDevicePTYsMonitor)
(qemudFindCharDevicePTYs, qemuPrepareChardevDevice)
(qemuPrepareMonitorChr, qemudShutdownVMDaemon)
(qemuDomainOpenConsole): Likewise.
* src/qemu/qemu_command.h (qemuBuildChrChardevStr)
(qemuBuildChrArgStr): Delete, now that they are static.
* src/libvirt_private.syms (domain_conf.h): New exports.
* cfg.mk (useless_free_options): Update list.
* tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Update
tests.
2011-01-07 22:45:01 +00:00
|
|
|
if (def->source.data.tcp.listen != 1) {
|
2012-07-18 12:01:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2010-04-03 13:33:29 +00:00
|
|
|
_("only TCP listen is supported for chr device"));
|
2008-11-19 16:58:23 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-05 13:19:14 +00:00
|
|
|
if (virAsprintf(&ret, "%s%d=port:%s", dev, def->target.port,
|
2013-07-04 10:17:01 +00:00
|
|
|
def->source.data.tcp.service) < 0)
|
2008-11-19 16:58:23 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_FILE:
|
2010-08-23 11:25:50 +00:00
|
|
|
{
|
|
|
|
int fd_out;
|
|
|
|
|
domain_conf: split source data out from ChrDef
This opens up the possibility of reusing the smaller ChrSourceDef
for both qemu monitor and a passthrough smartcard device.
* src/conf/domain_conf.h (_virDomainChrDef): Factor host
details...
(_virDomainChrSourceDef): ...into new struct.
(virDomainChrSourceDefFree): New prototype.
* src/conf/domain_conf.c (virDomainChrDefFree)
(virDomainChrDefParseXML, virDomainChrDefFormat): Split...
(virDomainChrSourceDefClear, virDomainChrSourceDefFree)
(virDomainChrSourceDefParseXML, virDomainChrSourceDefFormat):
...into new functions.
(virDomainChrDefParseTargetXML): Update clients to reflect type
split.
* src/vmx/vmx.c (virVMXParseSerial, virVMXParseParallel)
(virVMXFormatSerial, virVMXFormatParallel): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainOpenConsole): Likewise.
* src/xen/xend_internal.c (xenDaemonParseSxprChar)
(xenDaemonFormatSxprChr): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainDumpXML, vboxAttachSerial)
(vboxAttachParallel): Likewise.
* src/security/security_dac.c (virSecurityDACSetChardevLabel)
(virSecurityDACSetChardevCallback)
(virSecurityDACRestoreChardevLabel)
(virSecurityDACRestoreChardevCallback): Likewise.
* src/security/security_selinux.c (SELinuxSetSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback)
(SELinuxRestoreSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback): Likewise.
* src/security/virt-aa-helper.c (get_files): Likewise.
* src/lxc/lxc_driver.c (lxcVmStart, lxcDomainOpenConsole):
Likewise.
* src/uml/uml_conf.c (umlBuildCommandLineChr): Likewise.
* src/uml/uml_driver.c (umlIdentifyOneChrPTY, umlIdentifyChrPTY)
(umlDomainOpenConsole): Likewise.
* src/qemu/qemu_command.c (qemuBuildChrChardevStr)
(qemuBuildChrArgStr, qemuBuildCommandLine)
(qemuParseCommandLineChr): Likewise.
* src/qemu/qemu_domain.c (qemuDomainObjPrivateXMLFormat)
(qemuDomainObjPrivateXMLParse): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupChardevCgroup): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/qemu/qemu_driver.c (qemudFindCharDevicePTYsMonitor)
(qemudFindCharDevicePTYs, qemuPrepareChardevDevice)
(qemuPrepareMonitorChr, qemudShutdownVMDaemon)
(qemuDomainOpenConsole): Likewise.
* src/qemu/qemu_command.h (qemuBuildChrChardevStr)
(qemuBuildChrArgStr): Delete, now that they are static.
* src/libvirt_private.syms (domain_conf.h): New exports.
* cfg.mk (useless_free_options): Update list.
* tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Update
tests.
2011-01-07 22:45:01 +00:00
|
|
|
if ((fd_out = open(def->source.data.file.path,
|
2010-08-23 11:25:50 +00:00
|
|
|
O_WRONLY | O_APPEND | O_CREAT, 0660)) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("failed to open chardev file: %s"),
|
domain_conf: split source data out from ChrDef
This opens up the possibility of reusing the smaller ChrSourceDef
for both qemu monitor and a passthrough smartcard device.
* src/conf/domain_conf.h (_virDomainChrDef): Factor host
details...
(_virDomainChrSourceDef): ...into new struct.
(virDomainChrSourceDefFree): New prototype.
* src/conf/domain_conf.c (virDomainChrDefFree)
(virDomainChrDefParseXML, virDomainChrDefFormat): Split...
(virDomainChrSourceDefClear, virDomainChrSourceDefFree)
(virDomainChrSourceDefParseXML, virDomainChrSourceDefFormat):
...into new functions.
(virDomainChrDefParseTargetXML): Update clients to reflect type
split.
* src/vmx/vmx.c (virVMXParseSerial, virVMXParseParallel)
(virVMXFormatSerial, virVMXFormatParallel): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainOpenConsole): Likewise.
* src/xen/xend_internal.c (xenDaemonParseSxprChar)
(xenDaemonFormatSxprChr): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainDumpXML, vboxAttachSerial)
(vboxAttachParallel): Likewise.
* src/security/security_dac.c (virSecurityDACSetChardevLabel)
(virSecurityDACSetChardevCallback)
(virSecurityDACRestoreChardevLabel)
(virSecurityDACRestoreChardevCallback): Likewise.
* src/security/security_selinux.c (SELinuxSetSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback)
(SELinuxRestoreSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback): Likewise.
* src/security/virt-aa-helper.c (get_files): Likewise.
* src/lxc/lxc_driver.c (lxcVmStart, lxcDomainOpenConsole):
Likewise.
* src/uml/uml_conf.c (umlBuildCommandLineChr): Likewise.
* src/uml/uml_driver.c (umlIdentifyOneChrPTY, umlIdentifyChrPTY)
(umlDomainOpenConsole): Likewise.
* src/qemu/qemu_command.c (qemuBuildChrChardevStr)
(qemuBuildChrArgStr, qemuBuildCommandLine)
(qemuParseCommandLineChr): Likewise.
* src/qemu/qemu_domain.c (qemuDomainObjPrivateXMLFormat)
(qemuDomainObjPrivateXMLParse): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupChardevCgroup): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/qemu/qemu_driver.c (qemudFindCharDevicePTYsMonitor)
(qemudFindCharDevicePTYs, qemuPrepareChardevDevice)
(qemuPrepareMonitorChr, qemudShutdownVMDaemon)
(qemuDomainOpenConsole): Likewise.
* src/qemu/qemu_command.h (qemuBuildChrChardevStr)
(qemuBuildChrArgStr): Delete, now that they are static.
* src/libvirt_private.syms (domain_conf.h): New exports.
* cfg.mk (useless_free_options): Update list.
* tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Update
tests.
2011-01-07 22:45:01 +00:00
|
|
|
def->source.data.file.path);
|
2010-08-23 11:25:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (virAsprintf(&ret, "%s%d=null,fd:%d", dev, def->target.port, fd_out) < 0) {
|
2010-11-09 20:48:48 +00:00
|
|
|
VIR_FORCE_CLOSE(fd_out);
|
2010-08-23 11:25:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-11 10:31:56 +00:00
|
|
|
virCommandPassFD(cmd, fd_out,
|
|
|
|
VIR_COMMAND_PASS_FD_CLOSE_PARENT);
|
2010-08-23 11:25:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_PIPE:
|
|
|
|
/* XXX could open the pipe & just pass the FDs. Be wary of
|
|
|
|
* the effects of blocking I/O, though. */
|
2008-11-19 16:58:23 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_VC:
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_UDP:
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
|
|
|
default:
|
2012-07-18 12:01:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
domain_conf: split source data out from ChrDef
This opens up the possibility of reusing the smaller ChrSourceDef
for both qemu monitor and a passthrough smartcard device.
* src/conf/domain_conf.h (_virDomainChrDef): Factor host
details...
(_virDomainChrSourceDef): ...into new struct.
(virDomainChrSourceDefFree): New prototype.
* src/conf/domain_conf.c (virDomainChrDefFree)
(virDomainChrDefParseXML, virDomainChrDefFormat): Split...
(virDomainChrSourceDefClear, virDomainChrSourceDefFree)
(virDomainChrSourceDefParseXML, virDomainChrSourceDefFormat):
...into new functions.
(virDomainChrDefParseTargetXML): Update clients to reflect type
split.
* src/vmx/vmx.c (virVMXParseSerial, virVMXParseParallel)
(virVMXFormatSerial, virVMXFormatParallel): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainOpenConsole): Likewise.
* src/xen/xend_internal.c (xenDaemonParseSxprChar)
(xenDaemonFormatSxprChr): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainDumpXML, vboxAttachSerial)
(vboxAttachParallel): Likewise.
* src/security/security_dac.c (virSecurityDACSetChardevLabel)
(virSecurityDACSetChardevCallback)
(virSecurityDACRestoreChardevLabel)
(virSecurityDACRestoreChardevCallback): Likewise.
* src/security/security_selinux.c (SELinuxSetSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback)
(SELinuxRestoreSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback): Likewise.
* src/security/virt-aa-helper.c (get_files): Likewise.
* src/lxc/lxc_driver.c (lxcVmStart, lxcDomainOpenConsole):
Likewise.
* src/uml/uml_conf.c (umlBuildCommandLineChr): Likewise.
* src/uml/uml_driver.c (umlIdentifyOneChrPTY, umlIdentifyChrPTY)
(umlDomainOpenConsole): Likewise.
* src/qemu/qemu_command.c (qemuBuildChrChardevStr)
(qemuBuildChrArgStr, qemuBuildCommandLine)
(qemuParseCommandLineChr): Likewise.
* src/qemu/qemu_domain.c (qemuDomainObjPrivateXMLFormat)
(qemuDomainObjPrivateXMLParse): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupChardevCgroup): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/qemu/qemu_driver.c (qemudFindCharDevicePTYsMonitor)
(qemudFindCharDevicePTYs, qemuPrepareChardevDevice)
(qemuPrepareMonitorChr, qemudShutdownVMDaemon)
(qemuDomainOpenConsole): Likewise.
* src/qemu/qemu_command.h (qemuBuildChrChardevStr)
(qemuBuildChrArgStr): Delete, now that they are static.
* src/libvirt_private.syms (domain_conf.h): New exports.
* cfg.mk (useless_free_options): Update list.
* tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Update
tests.
2011-01-07 22:45:01 +00:00
|
|
|
_("unsupported chr device type %d"), def->source.type);
|
2008-11-19 16:58:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-07-29 14:40:49 +00:00
|
|
|
/*
|
|
|
|
* Null-terminate the current argument and return a pointer to the next.
|
|
|
|
* This should follow the same rules as the Linux kernel: arguments are
|
|
|
|
* separated by spaces; arguments can be quoted with double quotes; double
|
|
|
|
* quotes can't be escaped.
|
|
|
|
*/
|
|
|
|
static char *umlNextArg(char *args)
|
|
|
|
{
|
|
|
|
int in_quote = 0;
|
|
|
|
|
|
|
|
for (; *args; args++) {
|
|
|
|
if (*args == ' ' && !in_quote) {
|
|
|
|
*args++ = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*args == '"')
|
|
|
|
in_quote = !in_quote;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*args == ' ')
|
|
|
|
args++;
|
|
|
|
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2008-11-19 16:58:23 +00:00
|
|
|
/*
|
|
|
|
* Constructs a argv suitable for launching uml with config defined
|
|
|
|
* for a given virtual machine.
|
|
|
|
*/
|
2010-05-25 13:17:48 +00:00
|
|
|
virCommandPtr umlBuildCommandLine(virConnectPtr conn,
|
|
|
|
struct uml_driver *driver,
|
|
|
|
virDomainObjPtr vm)
|
2009-06-03 11:13:33 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/uml/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i, j;
|
2010-05-25 13:17:48 +00:00
|
|
|
virCommandPtr cmd;
|
2008-11-19 16:58:23 +00:00
|
|
|
|
2010-05-25 13:17:48 +00:00
|
|
|
cmd = virCommandNew(vm->def->os.kernel);
|
|
|
|
|
|
|
|
virCommandAddEnvPassCommon(cmd);
|
|
|
|
|
|
|
|
//virCommandAddArgPair(cmd, "con0", "fd:0,fd:1");
|
2012-03-02 20:27:39 +00:00
|
|
|
virCommandAddArgFormat(cmd, "mem=%lluK", vm->def->mem.cur_balloon);
|
2010-05-25 13:17:48 +00:00
|
|
|
virCommandAddArgPair(cmd, "umid", vm->def->name);
|
|
|
|
virCommandAddArgPair(cmd, "uml_dir", driver->monitorDir);
|
2008-11-19 16:58:23 +00:00
|
|
|
|
|
|
|
if (vm->def->os.root)
|
2010-05-25 13:17:48 +00:00
|
|
|
virCommandAddArgPair(cmd, "root", vm->def->os.root);
|
2008-11-19 16:58:23 +00:00
|
|
|
|
2013-05-21 07:21:19 +00:00
|
|
|
for (i = 0; i < vm->def->ndisks; i++) {
|
2008-11-19 16:58:23 +00:00
|
|
|
virDomainDiskDefPtr disk = vm->def->disks[i];
|
|
|
|
|
|
|
|
if (!STRPREFIX(disk->dst, "ubd")) {
|
2012-07-18 12:01:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-11-19 16:58:23 +00:00
|
|
|
_("unsupported disk type '%s'"), disk->dst);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2010-05-25 13:17:48 +00:00
|
|
|
virCommandAddArgPair(cmd, disk->dst, disk->src);
|
2008-11-19 16:58:23 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:19 +00:00
|
|
|
for (i = 0; i < vm->def->nnets; i++) {
|
2011-12-09 02:35:20 +00:00
|
|
|
char *ret = umlBuildCommandLineNet(conn, vm->def, vm->def->nets[i], i);
|
2009-06-03 11:13:33 +00:00
|
|
|
if (!ret)
|
|
|
|
goto error;
|
2010-05-25 13:17:48 +00:00
|
|
|
virCommandAddArg(cmd, ret);
|
|
|
|
VIR_FREE(ret);
|
2009-06-03 11:13:33 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:19 +00:00
|
|
|
for (i = 0; i < UML_MAX_CHAR_DEVICE; i++) {
|
Allow multiple consoles per virtual guest
While Xen only has a single paravirt console, UML, and
QEMU both support multiple paravirt consoles. The LXC
driver can also be trivially made to support multiple
consoles. This patch extends the XML to allow multiple
<console> elements in the XML. It also makes the UML
and QEMU drivers support this config.
* src/conf/domain_conf.c, src/conf/domain_conf.h: Allow
multiple <console> devices
* src/lxc/lxc_driver.c, src/xen/xen_driver.c,
src/xenxs/xen_sxpr.c, src/xenxs/xen_xm.c: Update for
internal API changes
* src/security/security_selinux.c, src/security/virt-aa-helper.c:
Only label consoles that aren't a copy of the serial device
* src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_process.c, src/uml/uml_conf.c,
src/uml/uml_driver.c: Support multiple console devices
* tests/qemuxml2xmltest.c, tests/qemuxml2argvtest.c: Extra
tests for multiple virtio consoles. Set QEMU_CAPS_CHARDEV
for all console /channel tests
* tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-auto.args,
tests/qemuxml2argvdata/qemuxml2argv-channel-virtio.args
tests/qemuxml2argvdata/qemuxml2argv-console-virtio.args: Update
for correct chardev syntax
* tests/qemuxml2argvdata/qemuxml2argv-console-virtio-many.args,
tests/qemuxml2argvdata/qemuxml2argv-console-virtio-many.xml: New
test file
2011-02-23 18:27:23 +00:00
|
|
|
virDomainChrDefPtr chr = NULL;
|
2010-08-12 13:42:34 +00:00
|
|
|
char *ret = NULL;
|
2013-05-21 07:21:19 +00:00
|
|
|
for (j = 0; j < vm->def->nconsoles; j++)
|
Allow multiple consoles per virtual guest
While Xen only has a single paravirt console, UML, and
QEMU both support multiple paravirt consoles. The LXC
driver can also be trivially made to support multiple
consoles. This patch extends the XML to allow multiple
<console> elements in the XML. It also makes the UML
and QEMU drivers support this config.
* src/conf/domain_conf.c, src/conf/domain_conf.h: Allow
multiple <console> devices
* src/lxc/lxc_driver.c, src/xen/xen_driver.c,
src/xenxs/xen_sxpr.c, src/xenxs/xen_xm.c: Update for
internal API changes
* src/security/security_selinux.c, src/security/virt-aa-helper.c:
Only label consoles that aren't a copy of the serial device
* src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_process.c, src/uml/uml_conf.c,
src/uml/uml_driver.c: Support multiple console devices
* tests/qemuxml2xmltest.c, tests/qemuxml2argvtest.c: Extra
tests for multiple virtio consoles. Set QEMU_CAPS_CHARDEV
for all console /channel tests
* tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-auto.args,
tests/qemuxml2argvdata/qemuxml2argv-channel-virtio.args
tests/qemuxml2argvdata/qemuxml2argv-console-virtio.args: Update
for correct chardev syntax
* tests/qemuxml2argvdata/qemuxml2argv-console-virtio-many.args,
tests/qemuxml2argvdata/qemuxml2argv-console-virtio-many.xml: New
test file
2011-02-23 18:27:23 +00:00
|
|
|
if (vm->def->consoles[j]->target.port == i)
|
|
|
|
chr = vm->def->consoles[j];
|
|
|
|
if (chr)
|
|
|
|
ret = umlBuildCommandLineChr(chr, "con", cmd);
|
2010-08-12 13:42:34 +00:00
|
|
|
if (!ret)
|
Convert 'int i' to 'size_t i' in src/uml/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
if (virAsprintf(&ret, "con%zu=none", i) < 0)
|
2013-07-04 10:17:01 +00:00
|
|
|
goto error;
|
2010-05-25 13:17:48 +00:00
|
|
|
virCommandAddArg(cmd, ret);
|
|
|
|
VIR_FREE(ret);
|
2008-11-19 16:58:23 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:19 +00:00
|
|
|
for (i = 0; i < UML_MAX_CHAR_DEVICE; i++) {
|
2008-11-19 16:58:23 +00:00
|
|
|
virDomainChrDefPtr chr = NULL;
|
2010-08-12 13:42:34 +00:00
|
|
|
char *ret = NULL;
|
2013-05-21 07:21:19 +00:00
|
|
|
for (j = 0; j < vm->def->nserials; j++)
|
2009-11-05 13:19:14 +00:00
|
|
|
if (vm->def->serials[j]->target.port == i)
|
2008-11-19 16:58:23 +00:00
|
|
|
chr = vm->def->serials[j];
|
|
|
|
if (chr)
|
2010-05-25 13:17:48 +00:00
|
|
|
ret = umlBuildCommandLineChr(chr, "ssl", cmd);
|
2010-08-12 13:42:34 +00:00
|
|
|
if (!ret)
|
Convert 'int i' to 'size_t i' in src/uml/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
if (virAsprintf(&ret, "ssl%zu=none", i) < 0)
|
2013-07-04 10:17:01 +00:00
|
|
|
goto error;
|
2010-05-25 13:17:48 +00:00
|
|
|
|
|
|
|
virCommandAddArg(cmd, ret);
|
|
|
|
VIR_FREE(ret);
|
2008-11-19 16:58:23 +00:00
|
|
|
}
|
|
|
|
|
2009-07-29 14:40:49 +00:00
|
|
|
if (vm->def->os.cmdline) {
|
|
|
|
char *args, *next_arg;
|
2010-05-25 13:17:48 +00:00
|
|
|
char *cmdline;
|
2013-05-03 12:49:48 +00:00
|
|
|
if (VIR_STRDUP(cmdline, vm->def->os.cmdline) < 0)
|
|
|
|
goto error;
|
2009-07-29 14:40:49 +00:00
|
|
|
|
|
|
|
args = cmdline;
|
|
|
|
while (*args == ' ')
|
|
|
|
args++;
|
|
|
|
|
|
|
|
while (*args) {
|
|
|
|
next_arg = umlNextArg(args);
|
2010-05-25 13:17:48 +00:00
|
|
|
virCommandAddArg(cmd, args);
|
2009-07-29 14:40:49 +00:00
|
|
|
args = next_arg;
|
|
|
|
}
|
2010-05-25 13:17:48 +00:00
|
|
|
VIR_FREE(cmdline);
|
2009-07-29 14:40:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-25 13:17:48 +00:00
|
|
|
return cmd;
|
2008-11-19 16:58:23 +00:00
|
|
|
|
|
|
|
error:
|
2010-05-25 13:17:48 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
return NULL;
|
2008-11-19 16:58:23 +00:00
|
|
|
}
|