Commit Graph

290 Commits

Author SHA1 Message Date
Mark McLoughlin
32db8dd75b Make qemuBuildHostNetStr() take tapfd as a string
With hotplug, we're going to want to pass a tapfd name rather than an
actual file descriptor, so prepare the way by passing a string tapfd to
qemuBuildHostNetStr().

* src/qemu_conf.h: qemuBuildHostNetStr() takes a string tapfd now

* src/qemu_conf.c: pass qemuBuildHostNetStr() a string rather than an
  actual file descriptor

* src/qemu_driver.c: update qemudDomainAttachNetDevice() for change
2009-07-27 15:31:51 +01:00
Mark McLoughlin
707302b2cf Only probe qemu for machine types when binary changes
By probing for qemu machine types, we increased the time of a
GetCapabilities call from 100us to a whopping 60ms.

This patch takes the approach of only probing for machine types
when the mtime of the emulator binary changed since the last time
the capabilities were generated.

* src/capabilities.h: cache the emulator binary mtime

* src/qemu_conf.c: add qemudGetOldMachines() to copy the machine
  types from the old caps struct if the mtime for the binary hasn't
  changed

* src/qemu_conf.h, src/qemu_driver.c: pass the old caps pointer to
  qemudCapsInit()
2009-07-27 15:30:35 +01:00
Mark McLoughlin
c14c6b083e Probe QEMU directly for machine aliases if not found in capabilties
Not all possible emulators are actually in the capabilities, so if we
don't find the supplied emulator we should probe it directly for machine
types.

* src/qemu_driver.c: add qemudCanonicalizeMachineDirect() to directly
  probe an emulator for the canonical machine type
2009-07-27 15:17:55 +01:00
Mark McLoughlin
be291b330a Canonicalize qemu machine types
In qemu-0.11 there is a 'pc-0.10' machine type which allows you to run
guests with a machine which is compatible with the pc machine in
qemu-0.10 - e.g. using the original PCI class for virtio-blk and
virtio-console and disabling MSI support in virtio-net. The idea here
is that we don't want to suprise guests by changing the hardware when
qemu is updated.

I've just posted some patches for qemu-0.11 which allows libvirt to
canonicalize the 'pc' machine alias to the latest machine version.

This patches makes us use that so that when a guest is configured to
use the 'pc' machine type, we resolve that to 'pc-0.11' machine and
save that in the guest XML.

See also:

  https://fedoraproject.org/wiki/Features/KVM_Stable_Guest_ABI

* src/qemu_conf.c: add qemudCanonicalizeMachine() to canonicalize
  the machine type according to the machine aliases in capabilities

* src/qemu_driver.c: parse aliases in qemudParseMachineTypesStr()
2009-07-27 15:17:55 +01:00
Cole Robinson
13f3d40cbf Don't allow NULL paths for BlockStats and InterfaceStats
Do the check in libvirt.c, to save drivers from the burden. This changes
behavior slightly in the qemu driver: we no longer explictly error if
passed an empty string. An error will still be thrown when the device
lookup fails.
2009-07-26 17:25:20 -04:00
Daniel P. Berrange
f4c3acdf35 Make QEMU cgroups use configurable
* qemud/libvirtd_qemu.aug, qemud/test_libvirtd_qemu.aug,
   src/qemu.conf: Add 'cgroups_controllers' and 'cgroups_device_acl'
   parameters
 * src/qemu_conf.h, src/qemu_conf.c: Load & parse configuration params
   for cgroups
 * src/qemu_driver.c: Only use cgroups controllers that are activated,
   and use configured device whitelist instead of default, if set.
2009-07-23 17:38:06 +01:00
Daniel P. Berrange
e88d638ac6 Use cgroups for block device whitelisting in QEMU guests
* src/qemu_driver.c: Set a restrictive block device whitelist for
  all QEMU guests. Update whitelist when hotplugging disks.
* src/cgroup.h, src/cgroup.c: Add some more convenience methods
  for dealing with block device whitelists.
2009-07-23 17:38:06 +01:00
Daniel P. Berrange
55bc5090b9 Implement schedular tunables API using cgroups
* src/qemu_driver.c:  Add driver methods qemuGetSchedulerType,
  qemuGetSchedulerParameters, qemuSetSchedulerParameters
* src/lxc_driver.c: Fix to use unsigned long long consistently
  for schedular parameters
* src/cgroup.h, src/cgroup.c: Fix cpu_shares to take unsigned
  long long
* src/util.c, src/util.h, src/libvirt_private.syms: Add a
  virStrToDouble helper
* src/virsh.c: Fix handling of --set arg to schedinfo command
  to honour the designated data type of each schedular tunable
  as declared by the driver
2009-07-23 17:38:06 +01:00
Daniel P. Berrange
38f6f47be9 Place every QEMU guest in a private cgroup
* src/qemu_driver.c: Place guest in cgroup upon startup. Remove
  cgroup upon shutdown
2009-07-23 17:38:06 +01:00
Laine Stump
165ed4a00e Add bare format string to printf-derivatives troubles
* src/datatypes.c src/domain_conf.c src/interface_conf.c
  src/lxc_driver.c src/qemu_driver.c src/storage_backend.c src/virsh.c:
  add bare %s format string to printf-derivatives called with no format
  string
2009-07-23 18:27:47 +02:00
Nguyen Anh Quynh
e4c48e02b4 Add support for physical memory access for QEmu
* include/libvirt/libvirt.h include/libvirt/libvirt.h.in: adds the new
  flag VIR_MEMORY_PHYSICAL for virDomainMemoryPeek
* src/libvirt.c: update the front-end checking
* src/qemu_driver.c: extend the QEmu driver
2009-07-22 16:29:38 +02:00
Mark McLoughlin
c2709cdaaa Add support for network device detach
qemu network devices are hot-unplugged in two stages - first the PCI NIC
is removed using 'pci_del <pci_addr>' and then the backend is removed
using 'host_net_remove <vlan> <name>'.

In order to perform these operations we need to have retained the
PCI address, backend name and vlan number.

* src/qemu_driver.c: add qemudDomainDetachNetDevice()
2009-07-22 11:34:07 +01:00
Mark McLoughlin
4e21a95afe Retain PCI address from NIC attach
When we pci_add a NIC, we need to retain the PCI address assigned by
qemu for using during detach.

* src/qemu_driver.c: use qemudParsePciAddReply() to pull the PCI
  address from the pci_add reply

* src/domain_conf.c: handle storing and parsing the PCI address in the
  domain state XML file
2009-07-22 11:34:07 +01:00
Mark McLoughlin
ffec099e75 Re-factor pci_add reply parsing and parse domain/bus numbers
The current code for parsing pci_add replies ignores the the domain and
bus numbers. Re-write the code to rectify that.

Also, since pci_add is used for NIC hotplug as well ask disk hotplug,
re-factor the code into a separate function.

* src/qemu_driver.c: add qemudParsePciAddReply() function which can
  handle parsing domain and bus numbers
2009-07-22 11:34:07 +01:00
Mark McLoughlin
d06f261cb1 Remove the network backend if NIC hotplug fails
If we fail to pci_add a NIC, we should remove the network backend and
leave things the way we found them. To do that, we pre-allocate a
host_net_remove monitor command and issue that if the pci_add fails.
If the remove fails, we just log a warning.

We can only do this if we have a name for the network backend and
we know the vlan number its associated with.

* src/qemu_driver.c: host_net_remove the network backend if the
  pci_add fails
2009-07-22 11:34:07 +01:00
Mark McLoughlin
35153940e3 Basic qemu NIC hotplug support
Implement basic NIC hotplug support using the 'host_net_add' and
'pci_add' qemu monitor commands.

For now, we don't support 'bridge' or 'network' types.

Also, if pci_add fails, we currently fail to remove the backend
which we added.

Finally, NIC hot-unplug support is missing.

* src/qemu_driver.c: add qemudDomainAttachNetDevice()

* src/qemu_conf.[ch]: export qemuBuildNicStr(), qemuBuildHostNetStr()
  and qemuAssignNames()

* src/libvirt_private.syms: export virDomainNetTypeToString()
2009-07-22 11:34:06 +01:00
Mark McLoughlin
423af1977f Make qemuCmdFlags available in qemudDomainAttachDevice()
qemudDomainChangeEjectableMedia() currently extracts the qemu command
line flags, but other device attaching code might need it, so move
the qemudExtractVersionInfo() call up a frame.

* src/qemu_driver.c: move the qemudExtractVersionInfo() call from
  qemudDomainChangeEjectableMedia() to qemudDomainAttachDevice()
2009-07-22 11:34:06 +01:00
Mark McLoughlin
0165410712 Retain disk PCI address across libvirtd restarts
When we hot-plug a disk device into a qemu guest, we need to retain its
PCI address so that it can be removed again later. Currently, we do
retain the slot number, but not across libvirtd restarts.

Add <state devaddr="xxxx:xx:xx"/> to the disk device XML config when the
VIR_DOMAIN_XML_INTERNAL_STATUS flag is used. We still don't parse the
domain and bus number, but the format allows us to do that in future.

* src/domain_conf.h: replace slotnum with pci_addr struct, add helper
  for testing whether the address is valid

* src/domain_conf.c: handle formatting and parsing the address

* src/qemu_driver.c: store the parsed slot number as a full PCI address,
  and use this address with the pci_del monitor command

* src/vbox/vbox_tmpl.c: we're debug printing slotnum here even though
  it can never be set, just delete it
2009-07-22 11:34:05 +01:00
Jun Koi
b2fd033cd5 Fix an uninitialized variable in Unix socket open
* src/qemu_driver.c: qemudOpenMonitorUnix() had an uninitialized loop
  counter
2009-07-21 11:57:54 +02:00
Cole Robinson
3b5417687d qemu: Try multiple times to open unix monitor socket
Unlike the pty monitor (which we know exists since we scrape its path from
stdout), we have no way of knowing that the unix monitor socket should exist/
be initialized. As a result, some of my KVM guests randomly fail to start on
F10 host.

Try to open the unix socket in a 3 second timeout loop. Ignore EACCES (path
does not exist if a first time run) and ECONNREFUSED (leftover socket from
a previous run hasn't been removed yet). Fixes things for me.
2009-07-16 12:52:53 -04:00
Daniel P. Berrange
0714b2ba4c Run QEMU guests as an unprivileged user
* configure.in: Add --with-qemu-user and --with-qemu-group args
* libvirt.spec.in: use 'qemu' for user/group for Fedora >= 12
* qemud/libvirtd_qemu.arg, qemud/test_libvirtd_qemu.aug,
  src/qemu.conf: Add 'user' and 'group' args for configuration
* src/Makefile.am: Create %localstatedir/cache/libvirt/qemu
* src/qemu_conf.c, src/qemu_conf.h: Load user/group from config
* src/qemu_driver.c: Change user ID/group ID when launching QEMU
  guests. Change user/group ownership on disks/usb/pci devs.
  Put memory dumps in %localstatedir/cache/libvirt/qemu
* src/util.c, src/util.h: Add convenient APIs for converting
  username/groupname to user ID / group ID
2009-07-16 17:06:55 +01:00
Paolo Bonzini
e1abc44814 Implement qemu dump capabilities
* src/qemu_driver.c (qemudDomainCoreDump): New
  (qemuDriver): Add core dump function. The behaviour is similar
  as the current Xen dump
2009-07-16 16:50:23 +02:00
Daniel P. Berrange
1795bfe4a1 Fix SELinux denial during hotplug
* src/qemu_driver.c: Relabel disk images *before* running QEMU
hotplug monitor commands
2009-07-16 11:32:09 +01:00
Daniel P. Berrange
326ecb7814 Fix PCI device hotplug/unplug with newer QEMU
* src/qemu_driver.c: Try new monitor syntax for hotplug first. If
  that fails fallback to old KVM specific syntax
2009-07-16 11:32:09 +01:00
Daniel P. Berrange
2d1f2e706c Fix problem with QEMU monitor welcome prompt confusing libvirt
after a libvirtd daemon restart with active guests

* src/qemu_driver: Read and dicard pending monitor data
  before issuing new monitor commands.
2009-07-16 11:32:03 +01:00
Cole Robinson
fe7cb869a8 qemu: Check driver is initialized up front, to avoid segfault.
If the qemu_driver was not initialized (possibly due to an error on driver
startup), we can segfault if attempting to connect to the URI.
2009-07-10 19:29:31 -04:00
Mark McLoughlin
62455ed872 Switch to using a unix socket for the qemu monitor
We keep support for the pty based monitor so that we can re-connect
to VMs started by older versions of libvirtd.

* src/domain_conf.c: handle formatting and parsing unix monitors

* src/qemu_driver.c: add qemudOpenMonitorUnix(), remove the monitor
  pty path searching from qemudFindCharDevicePTYs(), switch
  qemudStartVMDaemon() and qemuDomainXMLToNative() to using a unix
  monitor

* tests/qemuxml2argvtest.c: switch to using a unix monitor

* tests/qemuxml2argvdata/qemuxml2argv-*.args: update test data
2009-07-09 20:04:09 +01:00
Mark McLoughlin
05d377bdd2 Add the monitor type to the domain state XML
There are no functional changes in this patch apart from adding the
monitor type to the state XML.

The patch mostly consists of switching to use virDomainChrDef every
where to describe the monitor.

* src/domain_conf.h: replace monitorpath with monitor_chr

* src/domain_conf.c: handle parsing the monitor type and initializing
  monitor chr

* src/qemu_conf.[ch]: make qemudBuildCommandLine take a
  virDomainChrDefPtr and use that to build the -monitor parameter

* src/qemu_driver.c: split pty specific and common code from
  qemudOpenMonitor, have qemudStartVMDaemon() initialize monitor_chr

* tests/qemuxml2argvtest.c: update for qemudBuildCommandLine() change
2009-07-09 20:04:07 +01:00
Mark McLoughlin
1f4ec305f0 Minor qemu monitor coding style fixes
* src/qemu_driver.c: use a consistent coding style for function
  definitions
2009-07-09 19:31:01 +01:00
Mark McLoughlin
8a52daa2d4 Don't leak vm->monitorpath on re-connect
* src/qemu_driver.c: vm->monitorpath is already initialized in the case
  of re-connect, so move the initialization for the normal startup case
  out of the common code
2009-07-09 19:31:01 +01:00
Daniel P. Berrange
96619805cb Use libcap-ng to clear capabilities for many child processes 2009-06-29 17:00:52 +00:00
Daniel P. Berrange
39c7e7a6b7 Fix crash in QEMU driver with bad capabilities data 2009-06-29 10:41:56 +00:00
Daniel Veillard
d45242c616 Fix a couple of state problems
* src/qemu_driver.c: fix a domain state problem after
  migration, patch  by Federico Simoncelli, fixes #507537
* src/domain_conf.c:  fix a transcient domain state problem after
  destroy, patch  by Federico Simoncelli, fixes #507304
* AUTHORS: add Federico Simoncelli and Javier Fontan
daniel
2009-06-25 13:55:58 +00:00
Daniel P. Berrange
73f34b31f5 Fix broken dominfo command when no security driver is implemented 2009-06-25 09:37:22 +00:00
Cole Robinson
387935345c Fix memory reporting for inactive domains in the qemu driver.
Currently, 'info' will always report that mem = max mem. Make sure we
actually return the correct mem value.
2009-06-22 16:35:03 +00:00
Cole Robinson
53603043c7 Set default emulator in domain_conf.*, rather than the driver.
Rather than numerous instances of:

emulator = vm->def->emulator;
if (!emulator)
    emulator = virDomainDefDefaultEmulator(conn, vm->def, driver->caps);
if (!emulator)
    return -1;

Set this value at XML parse time in the domain config, so we can depend on
it for all future emulator accesses. There were unchecked accesses in the
qemu driver that were tripping up on this if no emulator was specified in
the XML, see:

http://www.redhat.com/archives/libvir-list/2008-October/msg00602.html
2009-06-16 15:42:46 +00:00
Daniel P. Berrange
0420a03240 Remove use of getuid()==0 for privilege checks 2009-06-12 13:20:13 +00:00
Daniel P. Berrange
d2c9fe850b Improve error reporting for virConnectOpen URIs 2009-06-12 12:06:15 +00:00
Daniel P. Berrange
56a46886ad Fix re-detection of transient VMs after libvirtd restart 2009-06-12 11:38:50 +00:00
Daniel P. Berrange
b0b968efd5 Generic shared impls of all NUMA apis 2009-06-03 13:28:02 +00:00
Daniel Veillard
81d0ffbc3b NPIV implementation for node device create and destroy
* src/Makefile.am src/node_device.[ch] src/node_device_conf.[ch]
  src/node_device_hal.[ch] src/node_device_hal_linux.c
  src/qemu_driver.c src/remote_internal.c src/storage_backend.c
  src/virsh.c src/xen_unified.c tests/nodedevxml2xmltest.c
  po/POTFILES.in: implementation for node device create and destroy
  in NPIV support, patch by David Allan
Daniel
2009-06-02 15:12:53 +00:00
Cole Robinson
34497fdb37 qemu_driver: Fix another domain startup error reporting race.
Parse the command line output a bit earlier so we have a better chance
of reporting the full error output on failure.

I hit this when QEMU would try to boot an invalid kernel (virtinst bug).
2009-05-29 14:12:50 +00:00
Cole Robinson
4ff19ced3a qemuDomainLookupByUUID: print correct UUID string on failed lookup.
Currently we print the raw UUID which isn't very useful in ascii format.
2009-05-29 14:01:55 +00:00
Daniel P. Berrange
c31300e69f Fix misc bugs in ARGV -> XML convertor 2009-05-28 13:21:19 +00:00
Daniel P. Berrange
3d4a0ccbc6 QEMU domain XML conversion from QEMU argv 2009-05-21 14:16:55 +00:00
Daniel P. Berrange
d8dbd61107 Basic domain XML conversions for Xen/QEMU drivers 2009-05-21 14:14:01 +00:00
Daniel P. Berrange
4d5383fd36 public API for domain XML conversions 2009-05-21 13:46:35 +00:00
Daniel P. Berrange
de658ab4e4 Fix misc locking bugs identified by lock checker 2009-05-19 11:06:25 +00:00
Daniel Veillard
cd223d93da generic support for RDP and desktop graphic extensions
* docs/schemas/domain.rng src/domain_conf.[ch] src/qemu_driver.c:
  extend the generic code for the RDP and desktop extensions of
  the graphic tag needed for vbox, patch by Pritesh Kothari
Daniel
2009-05-15 09:43:51 +00:00
Daniel P. Berrange
426f9772b8 Fix QEMU ARGV detection with kvm >= 85 2009-05-11 15:14:24 +00:00