sdk/emulator/qemu.git
11 years agoMerge remote-tracking branch 'kraxel/chardev.5' into staging
Anthony Liguori [Thu, 14 Mar 2013 19:54:37 +0000 (14:54 -0500)]
Merge remote-tracking branch 'kraxel/chardev.5' into staging

* kraxel/chardev.5:
  spice-qemu-char: Remove dead debugging code
  spice-qemu-char: Fix name parameter issues after qapi-ifying
  qemu-char.c: fix waiting for telnet connection message
  Revert "hmp: Disable chardev-add and chardev-remove"
  chardev: add udp support to qapi
  chardev: add memory (ringbuf) support to qapi
  chardev: add vc support to qapi
  chardev: add spice support to qapi
  chardev: add pipe support to qapi
  chardev: add console support to qapi
  chardev: switch pty init to qapi
  chardev: switch parallel init to qapi
  chardev: switch serial/tty init to qapi
  chardev: add stdio support to qapi
  chardev: switch file init to qapi
  chardev: add braille support to qapi
  chardev: add msmouse support to qapi
  chardev: switch null init to qapi
  chardev: add mux chardev support to qapi
  chardev: add support for qapi-based chardev initialization

Conflicts:
ui/console.c

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
11 years agoMerge remote-tracking branch 'afaerber/qom-cpu' into staging
Anthony Liguori [Thu, 14 Mar 2013 19:50:58 +0000 (14:50 -0500)]
Merge remote-tracking branch 'afaerber/qom-cpu' into staging

# By Andreas Färber (16) and Igor Mammedov (1)
# Via Andreas Färber
* afaerber/qom-cpu:
  target-lm32: Update VMStateDescription to LM32CPU
  target-arm: Override do_interrupt for ARMv7-M profile
  cpu: Replace do_interrupt() by CPUClass::do_interrupt method
  cpu: Pass CPUState to cpu_interrupt()
  exec: Pass CPUState to cpu_reset_interrupt()
  cpu: Move halted and interrupt_request fields to CPUState
  target-cris/helper.c: Update Coding Style
  target-i386: Update VMStateDescription to X86CPU
  cpu: Introduce cpu_class_set_vmsd()
  cpu: Register VMStateDescription through CPUState
  stubs: Add a vmstate_dummy struct for CONFIG_USER_ONLY
  vmstate: Make vmstate_register() static inline
  target-sh4: Move PVR/PRR/CVR into SuperHCPUClass
  target-sh4: Introduce SuperHCPU subclasses
  cpus: Replace open-coded CPU loop in qmp_memsave() with qemu_get_cpu()
  monitor: Use qemu_get_cpu() in monitor_set_cpu()
  cpu: Fix qemu_get_cpu() to return NULL if CPU not found

11 years agoMerge remote-tracking branch 'mdroth/qga-pull-3-11-2013' into staging
Anthony Liguori [Thu, 14 Mar 2013 19:50:30 +0000 (14:50 -0500)]
Merge remote-tracking branch 'mdroth/qga-pull-3-11-2013' into staging

# By Laszlo Ersek (3) and others
# Via Michael Roth
* mdroth/qga-pull-3-11-2013:
  qga: implement qmp_guest_set_vcpus() for Linux with sysfs
  qga: implement qmp_guest_get_vcpus() for Linux with sysfs
  qga: introduce guest-get-vcpus / guest-set-vcpus with stubs
  qga: add guest-set-time command
  qga: add guest-get-time command
  qemu-ga: use key-value store to avoid recycling fd handles after restart
  qemu-ga: make guest-sync-delimited available during fsfreeze
  qemu-ga: fix confusing GAChannelMethod comparison
  qga: cast to int for DWORD type

11 years agoMerge remote-tracking branch 'riku/linux-user-for-upstream' into staging
Anthony Liguori [Thu, 14 Mar 2013 19:50:21 +0000 (14:50 -0500)]
Merge remote-tracking branch 'riku/linux-user-for-upstream' into staging

# By Peter Maydell (5) and others
# Via Riku Voipio
* riku/linux-user-for-upstream:
  linux-user/syscall.c: Don't warn about unimplemented get_robust_list
  linux-user: Implement accept4
  linux-user: Implement sendfile and sendfile64
  linux-user: make bogus negative iovec lengths fail EINVAL
  linux-user: Fix layout of usage table to account for option text
  linux-user: Add more sparc syscall numbers
  linux-user: Support setgroups syscall with no groups
  linux-user: fix futex strace of FUTEX_CLOCK_REALTIME
  linux-user/syscall.c: handle FUTEX_WAIT_BITSET in do_futex
  linux-user: improve print_fcntl()
  linux-user: Add Alpha socket constants

11 years agospice-qemu-char: Remove dead debugging code
Hans de Goede [Wed, 13 Mar 2013 13:59:44 +0000 (14:59 +0100)]
spice-qemu-char: Remove dead debugging code

Since commit d62e5f7036a018b2ad09f17ebd481bd28953d783
"chardev: add spice support to qapi"

It is impossible to set the debug parameter, so all the dprintf calls
are essentially nops. Since we've not needed the debug parameter in ages this
is not a problem, if it later turns out we do need some more debugging options
we can add more trace-points.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agospice-qemu-char: Fix name parameter issues after qapi-ifying
Hans de Goede [Wed, 13 Mar 2013 09:41:31 +0000 (10:41 +0100)]
spice-qemu-char: Fix name parameter issues after qapi-ifying

The strings passed in through the qapi calls are dynamic memory, since
we want to have them stick around longer then just the call to
qemu_chr_open_spice_* we need to strdup them.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agogtk: fix vc initialization
Anthony Liguori [Wed, 13 Mar 2013 17:21:04 +0000 (12:21 -0500)]
gtk: fix vc initialization

    commit 01f45d986fb0b7c2d4f0466efe3cde9708f325be
    Author: Anthony Liguori <aliguori@us.ibm.com>
    Date:   Tue Mar 5 23:21:32 2013 +0530

       qemu-char: move text console init to console.c

Broke vc initialization for GTK.  It's a simple typo.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
11 years agoqemu-char.c: fix waiting for telnet connection message
Igor Mitsyanko [Sun, 10 Mar 2013 13:58:05 +0000 (17:58 +0400)]
qemu-char.c: fix waiting for telnet connection message

Current colon position in "waiting for telnet connection" message template
produces messages like:
QEMU waiting for connection on: telnet::127.0.0.16666,server

After moving a colon to the right, we will get a correct messages like:
QEMU waiting for connection on: telnet:127.0.0.1:6666,server

Signed-off-by: Igor Mitsyanko <i.mitsyanko@gmail.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agoRevert "hmp: Disable chardev-add and chardev-remove"
Gerd Hoffmann [Thu, 28 Feb 2013 07:46:10 +0000 (08:46 +0100)]
Revert "hmp: Disable chardev-add and chardev-remove"

This reverts commit 8a14952c9d2f5fa2b3caa6dc286b62ed5d26bca7.

11 years agochardev: add udp support to qapi
Gerd Hoffmann [Wed, 27 Feb 2013 13:10:47 +0000 (14:10 +0100)]
chardev: add udp support to qapi

This patch adds 'udp' support to qapi.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: add memory (ringbuf) support to qapi
Gerd Hoffmann [Tue, 26 Feb 2013 15:21:11 +0000 (16:21 +0100)]
chardev: add memory (ringbuf) support to qapi

This patch adds 'memory' support to qapi and also switches over
the memory chardev initialization to the new qapi code path.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: add vc support to qapi
Gerd Hoffmann [Mon, 25 Feb 2013 14:52:32 +0000 (15:52 +0100)]
chardev: add vc support to qapi

This patch adds 'vc' support to qapi and also switches over the
vc chardev initialization to the new qapi code path.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: add spice support to qapi
Gerd Hoffmann [Mon, 25 Feb 2013 11:39:06 +0000 (12:39 +0100)]
chardev: add spice support to qapi

This patch adds 'spicevmc' and 'spiceport' support to qapi and also
switches over the spice chardev initialization to the new qapi code
path.

11 years agochardev: add pipe support to qapi
Gerd Hoffmann [Mon, 25 Feb 2013 10:50:55 +0000 (11:50 +0100)]
chardev: add pipe support to qapi

This patch adds 'pipe' support to qapi and also switches over the
pipe chardev initialization to the new qapi code path.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: add console support to qapi
Gerd Hoffmann [Mon, 25 Feb 2013 10:48:06 +0000 (11:48 +0100)]
chardev: add console support to qapi

This patch adds 'console' support to qapi and also switches over the
console chardev initialization to the new qapi code path.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: switch pty init to qapi
Gerd Hoffmann [Mon, 25 Feb 2013 09:16:46 +0000 (10:16 +0100)]
chardev: switch pty init to qapi

This patch switches over the pty chardev initialization
to the new qapi code path.

Bonus: Taking QemuOpts out of the loop allows some nice
cleanups along the way.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: switch parallel init to qapi
Gerd Hoffmann [Fri, 22 Feb 2013 15:17:01 +0000 (16:17 +0100)]
chardev: switch parallel init to qapi

This patch switches over the parallel chardev initialization
to the new qapi code path.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: switch serial/tty init to qapi
Gerd Hoffmann [Fri, 22 Feb 2013 14:48:05 +0000 (15:48 +0100)]
chardev: switch serial/tty init to qapi

This patch switches over the serial chardev initialization
to the new qapi code path.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: add stdio support to qapi
Gerd Hoffmann [Thu, 21 Feb 2013 11:34:58 +0000 (12:34 +0100)]
chardev: add stdio support to qapi

This patch adds 'stdio' support to qapi and also switches over the
stdio chardev initialization to the new qapi code path.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: switch file init to qapi
Gerd Hoffmann [Thu, 21 Feb 2013 11:07:14 +0000 (12:07 +0100)]
chardev: switch file init to qapi

This patch switches over the 'file' chardev initialization
to the new qapi code path.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: add braille support to qapi
Gerd Hoffmann [Thu, 21 Feb 2013 11:56:10 +0000 (12:56 +0100)]
chardev: add braille support to qapi

This patch adds 'braille' support to qapi and also switches over
the braille chardev initialization to the new qapi code path.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: add msmouse support to qapi
Gerd Hoffmann [Thu, 21 Feb 2013 10:58:44 +0000 (11:58 +0100)]
chardev: add msmouse support to qapi

This patch adds 'msmouse' support to qapi and also switches over
the msmouse chardev initialization to the new qapi code path.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: switch null init to qapi
Gerd Hoffmann [Thu, 21 Feb 2013 10:41:26 +0000 (11:41 +0100)]
chardev: switch null init to qapi

This patch switches over the 'null' chardev initialization
to the new qapi code path.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agochardev: add mux chardev support to qapi
Gerd Hoffmann [Thu, 21 Feb 2013 15:16:42 +0000 (16:16 +0100)]
chardev: add mux chardev support to qapi

This adds mux chardev support to the qapi and also makes the qapi-based
chardev creation path handle the "mux=on" option correctly.

11 years agochardev: add support for qapi-based chardev initialization
Gerd Hoffmann [Thu, 21 Feb 2013 10:39:12 +0000 (11:39 +0100)]
chardev: add support for qapi-based chardev initialization

This patch add support for a new way to initialize chardev devices.
Instead of calling a initialization function with a QemuOpts we will
now create a (qapi) ChardevBackend, optionally call a function to
fill ChardevBackend from QemuOpts, then go create the chardev using
the new qapi code path which is also used by chardev-add.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
11 years agoexec: make -mem-path filenames deterministic
Peter Feiner [Mon, 4 Mar 2013 18:54:25 +0000 (13:54 -0500)]
exec: make -mem-path filenames deterministic

Adds ramblocks' names to their backing files when using -mem-path.  Eases
introspection and debugging.

Signed-off-by: Peter Feiner <peter@gridcentric.ca>
Message-id: 1362423265-15855-1-git-send-email-peter@gridcentric.ca
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
11 years agoAdd search path support for qemu data files.
Gerd Hoffmann [Fri, 8 Mar 2013 10:42:24 +0000 (11:42 +0100)]
Add search path support for qemu data files.

This patch allows to specify multiple directories where qemu should look
for data files.  To implement that the behavior of the -L switch is
slightly different now:  Instead of replacing the data directory the
path specified will be appended to the data directory list.  So when
specifiying -L multiple times all directories specified will be checked,
in the order they are specified on the command line, instead of just the
last one.

Additionally the default paths are always appended to the directory
data list.  This allows to specify a incomplete directory (such as the
seabios out/ directory) via -L.  Anything not found there will be loaded
from the default paths, so you don't have to create a symlink farm for
all the rom blobs.

For trouble-shooting a tracepoint has been added, logging which blob
has been loaded from which location.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 1362739344-8068-1-git-send-email-kraxel@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
11 years agoBuild TPM passthrough for i386 and x86_64 targets
Stefan Berger [Wed, 27 Feb 2013 17:47:55 +0000 (12:47 -0500)]
Build TPM passthrough for i386 and x86_64 targets

Build the TPM passthrough driver only for i386 and x86_64 targets
using the default-configs files for those targets with softmmu.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Message-id: 1361987275-26289-8-git-send-email-stefanb@linux.vnet.ibm.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
11 years agoAdd support for cancelling of a TPM command
Stefan Berger [Wed, 27 Feb 2013 17:47:54 +0000 (12:47 -0500)]
Add support for cancelling of a TPM command

This patch adds support for cancelling an executing TPM command.
In Linux for example a user can cancel a command through the TPM's
sysfs 'cancel' entry using

echo "1" > /sysfs/class/misc/tpm0/device/cancel

This patch propagates the cancellation of a command inside a VM
to the host TPM's sysfs entry.
It also uses the possibility to cancel the command before QEMU VM
shutdown or reboot, which helps in preventing QEMU from hanging while
waiting for the completion of the command.
To relieve higher layers or users from having to determine the TPM's
cancel sysfs entry, the driver searches for the entry in well known
locations.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Message-id: 1361987275-26289-7-git-send-email-stefanb@linux.vnet.ibm.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
11 years agoAdd a TPM Passthrough backend driver implementation
Stefan Berger [Wed, 27 Feb 2013 17:47:53 +0000 (12:47 -0500)]
Add a TPM Passthrough backend driver implementation

This patch is based of off version 9 of Stefan Berger's patch series
  "QEMU Trusted Platform Module (TPM) integration"
and adds a new backend driver for it.

This patch adds a passthrough backend driver for passing commands sent to the
emulated TPM device directly to a TPM device opened on the host machine.
Thus it is possible to use a hardware TPM device in a system running on QEMU,
providing the ability to access a TPM in a special state (e.g. after a Trusted
Boot).

This functionality is being used in the acTvSM Trusted Virtualization Platform
which is available on [1].

Usage example:
  qemu-system-x86_64 -tpmdev passthrough,id=tpm0,path=/dev/tpm0 \
                     -device tpm-tis,tpmdev=tpm0 \
                     -cdrom test.iso -boot d

Some notes about the host TPM:
The TPM needs to be enabled and activated. If that's not the case one
has to go through the BIOS/UEFI and enable and activate that TPM for TPM
commands to work as expected.
It may be necessary to boot the kernel using tpm_tis.force=1 in the boot
command line or 'modprobe tpm_tis force=1' in case of using it as a module.

Regards,
Andreas Niederl, Stefan Berger

[1] http://trustedjava.sourceforge.net/

Signed-off-by: Andreas Niederl <andreas.niederl@iaik.tugraz.at>
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Message-id: 1361987275-26289-6-git-send-email-stefanb@linux.vnet.ibm.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
11 years agoBuild the TPM frontend code
Stefan Berger [Wed, 27 Feb 2013 17:47:52 +0000 (12:47 -0500)]
Build the TPM frontend code

Build the TPM frontend code that has been added so far.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Message-id: 1361987275-26289-5-git-send-email-stefanb@linux.vnet.ibm.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
11 years agoAdd a debug register
Stefan Berger [Wed, 27 Feb 2013 17:47:51 +0000 (12:47 -0500)]
Add a debug register

This patch uses the possibility to add a vendor-specific register and
adds a debug register useful for dumping the TIS's internal state. This
register is only active in a debug build (#define DEBUG_TIS).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Message-id: 1361987275-26289-4-git-send-email-stefanb@linux.vnet.ibm.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
11 years agoAdd TPM (frontend) hardware interface (TPM TIS) to QEMU
Stefan Berger [Wed, 27 Feb 2013 17:47:50 +0000 (12:47 -0500)]
Add TPM (frontend) hardware interface (TPM TIS) to QEMU

This patch adds the main code of the TPM frontend driver, the TPM TIS
interface, to QEMU. The code is largely based on the previous implementation
for Xen but has been significantly extended to meet the standard's
requirements, such as the support for changing of localities and all the
functionality of the available flags.

Communication with the backend (i.e., for Xen or the libtpms-based one)
is cleanly separated through an interface which the backend driver needs
to implement.

Whenever the frontend has collected a complete packet, it will submit
a task to the backend, which then starts processing the command. Once
the result has been returned, the backend invokes a callback function
(tpm_tis_receive_cb()).

Testing the proper functioning of the different flags and localities
cannot be done from user space when running in Linux for example, since
access to the address space of the TPM TIS interface is not possible. Also
the Linux driver itself does not exercise all functionality. So, for
testing there is a fairly extensive test suite as part of the SeaBIOS patches
since from within the BIOS one can have full access to all the TPM's registers.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Message-id: 1361987275-26289-3-git-send-email-stefanb@linux.vnet.ibm.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
11 years agoSupport for TPM command line options
Stefan Berger [Wed, 27 Feb 2013 17:47:49 +0000 (12:47 -0500)]
Support for TPM command line options

This patch adds support for TPM command line options.
The command line options supported here are

./qemu-... -tpmdev passthrough,path=<path to TPM device>,id=<id>
           -device tpm-tis,tpmdev=<id>,id=<other id>

and

./qemu-... -tpmdev help

where the latter works similar to -soundhw help and shows a list of
available TPM backends (for example 'passthrough').

Using the type parameter, the backend is chosen, i.e., 'passthrough' for the
passthrough driver. The interpretation of the other parameters along
with determining whether enough parameters were provided is pushed into
the backend driver, which needs to implement the interface function
'create' and return a TPMDriverOpts structure if the VM can be started or
'NULL' if not enough or bad parameters were provided.

Monitor support for 'info tpm' has been added. It for example prints the
following:

(qemu) info tpm
TPM devices:
 tpm0: model=tpm-tis
  \ tpm0: type=passthrough,path=/dev/tpm0,cancel-path=/sys/devices/pnp0/00:09/cancel

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Message-id: 1361987275-26289-2-git-send-email-stefanb@linux.vnet.ibm.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
11 years agotarget-lm32: Update VMStateDescription to LM32CPU
Andreas Färber [Sat, 2 Feb 2013 12:45:29 +0000 (13:45 +0100)]
target-lm32: Update VMStateDescription to LM32CPU

Add a vmstate_lm32_cpu referencing the previous VMStateDescription as a
sub-struct and hook it up to CPUClass::vmsd. Drop cpu_{save,load}().

Acked-by: Michael Walle <michael@walle.cc>
Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agotarget-arm: Override do_interrupt for ARMv7-M profile
Andreas Färber [Sat, 2 Feb 2013 11:33:14 +0000 (12:33 +0100)]
target-arm: Override do_interrupt for ARMv7-M profile

Enable ARMCPUInfo to specify a custom class_init functions.
Introduce arm_v7m_class_init() and use it for "cortex-m3" model.

Instead of forwarding from arm_cpu_do_interrupt() to do_interrupt_v7m(),
override CPUClass::do_interrupt with arm_v7m_cpu_do_interrupt()
in arm_v7m_class_init().

Acked-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agocpu: Replace do_interrupt() by CPUClass::do_interrupt method
Andreas Färber [Sat, 2 Feb 2013 09:57:51 +0000 (10:57 +0100)]
cpu: Replace do_interrupt() by CPUClass::do_interrupt method

This removes a global per-target function and thus takes us one step
closer to compiling multiple targets into one executable.

It will also allow to override the interrupt handling for certain CPU
families.

Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agocpu: Pass CPUState to cpu_interrupt()
Andreas Färber [Fri, 18 Jan 2013 14:03:43 +0000 (15:03 +0100)]
cpu: Pass CPUState to cpu_interrupt()

Move it to qom/cpu.h to avoid issues with include order.

Change pc_acpi_smi_interrupt() opaque to X86CPU.

Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agoexec: Pass CPUState to cpu_reset_interrupt()
Andreas Färber [Thu, 17 Jan 2013 21:30:20 +0000 (22:30 +0100)]
exec: Pass CPUState to cpu_reset_interrupt()

Move it to qom/cpu.c to avoid build failures depending on include order
of cpu-qom.h and exec/cpu-all.h.

Change opaques of various ..._irq_handler() functions to the
appropriate CPU type to facilitate using cpu_reset_interrupt().

Fix Coding Style issues while at it (missing braces, indentation).

Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agocpu: Move halted and interrupt_request fields to CPUState
Andreas Färber [Thu, 17 Jan 2013 17:51:17 +0000 (18:51 +0100)]
cpu: Move halted and interrupt_request fields to CPUState

Both fields are used in VMState, thus need to be moved together.
Explicitly zero them on reset since they were located before
breakpoints.

Pass PowerPCCPU to kvmppc_handle_halt().

Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agotarget-cris/helper.c: Update Coding Style
Andreas Färber [Fri, 25 Jan 2013 16:37:28 +0000 (17:37 +0100)]
target-cris/helper.c: Update Coding Style

Reindent, add missing braces and drop/adjust whitespace.

Prepares for CPUArchState-to-CPUState field movements in
cpu_cris_handle_mmu_fault(), do_interruptv10() and do_interrupt().
The remaining functions were so minor that they can be fixed in one go.

Acked-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agotarget-i386: Update VMStateDescription to X86CPU
Andreas Färber [Sat, 2 Feb 2013 12:38:08 +0000 (13:38 +0100)]
target-i386: Update VMStateDescription to X86CPU

Expose vmstate_cpu as vmstate_x86_cpu and hook it up to CPUClass::vmsd.
Adapt opaques and VMState fields to X86CPU. Drop cpu_{save,load}().

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agocpu: Introduce cpu_class_set_vmsd()
Andreas Färber [Fri, 22 Feb 2013 20:50:10 +0000 (21:50 +0100)]
cpu: Introduce cpu_class_set_vmsd()

This setter avoids redefining each VMStateDescription value to
vmstate_dummy by not referencing the value for CONFIG_USER_ONLY.

Suggested-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agocpu: Register VMStateDescription through CPUState
Andreas Färber [Sun, 20 Jan 2013 19:23:22 +0000 (20:23 +0100)]
cpu: Register VMStateDescription through CPUState

In comparison to DeviceClass::vmsd, CPU VMState is split in two,
"cpu_common" and "cpu", and uses cpu_index as instance_id instead of -1.
Therefore add a CPU-specific CPUClass::vmsd field.

Unlike the legacy CPUArchState registration, rather register CPUState.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
11 years agostubs: Add a vmstate_dummy struct for CONFIG_USER_ONLY
Andreas Färber [Mon, 18 Feb 2013 16:56:20 +0000 (17:56 +0100)]
stubs: Add a vmstate_dummy struct for CONFIG_USER_ONLY

Reviewed-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agovmstate: Make vmstate_register() static inline
Andreas Färber [Mon, 18 Feb 2013 20:41:59 +0000 (21:41 +0100)]
vmstate: Make vmstate_register() static inline

This avoids adding a duplicate stub for CONFIG_USER_ONLY.

Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agotarget-sh4: Move PVR/PRR/CVR into SuperHCPUClass
Andreas Färber [Tue, 20 Nov 2012 15:15:47 +0000 (16:15 +0100)]
target-sh4: Move PVR/PRR/CVR into SuperHCPUClass

They are never changed once initialized, and moving them to the class
will allow to inspect them before instantiating.

Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agotarget-sh4: Introduce SuperHCPU subclasses
Andreas Färber [Mon, 19 Nov 2012 01:42:18 +0000 (02:42 +0100)]
target-sh4: Introduce SuperHCPU subclasses

Store legacy name in SuperHCPUClass for -cpu ? and for case-insensitive
class lookup.

List CPUs by iterating over TYPE_SUPERH_CPU subclasses.

Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agocpus: Replace open-coded CPU loop in qmp_memsave() with qemu_get_cpu()
Andreas Färber [Fri, 15 Feb 2013 14:41:49 +0000 (15:41 +0100)]
cpus: Replace open-coded CPU loop in qmp_memsave() with qemu_get_cpu()

No functional change, just less usages of first_cpu and next_cpu fields.

env is passed to cpu_memory_rw_debug(), which in turn passes it to
target-specific cpu_get_phys_page_debug(). Changing both would be a
larger refactoring, so defer that by using env_ptr for now.

Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agomonitor: Use qemu_get_cpu() in monitor_set_cpu()
Andreas Färber [Fri, 15 Feb 2013 16:01:09 +0000 (17:01 +0100)]
monitor: Use qemu_get_cpu() in monitor_set_cpu()

No functional change, just a reduction of CPU loops.

The mon_cpu field is left untouched for now since changing that requires
a number of larger prerequisites, including cpu_synchronize_state() and
mon_get_cpu().

Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agocpu: Fix qemu_get_cpu() to return NULL if CPU not found
Igor Mammedov [Thu, 7 Mar 2013 18:12:43 +0000 (19:12 +0100)]
cpu: Fix qemu_get_cpu() to return NULL if CPU not found

Commit 55e5c2850 breaks CPU not found return value, and returns
CPU corresponding to the last non NULL env.
Fix it by returning CPU only if env is not NULL, otherwise CPU is
not found and function should return NULL.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
11 years agoqga: implement qmp_guest_set_vcpus() for Linux with sysfs
Laszlo Ersek [Wed, 6 Mar 2013 21:59:31 +0000 (22:59 +0100)]
qga: implement qmp_guest_set_vcpus() for Linux with sysfs

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
11 years agoqga: implement qmp_guest_get_vcpus() for Linux with sysfs
Laszlo Ersek [Wed, 6 Mar 2013 21:59:30 +0000 (22:59 +0100)]
qga: implement qmp_guest_get_vcpus() for Linux with sysfs

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
11 years agoqga: introduce guest-get-vcpus / guest-set-vcpus with stubs
Laszlo Ersek [Wed, 6 Mar 2013 21:59:29 +0000 (22:59 +0100)]
qga: introduce guest-get-vcpus / guest-set-vcpus with stubs

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
11 years agoqga: add guest-set-time command
Lei Li [Tue, 5 Mar 2013 09:39:12 +0000 (17:39 +0800)]
qga: add guest-set-time command

Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
*added stub for w32

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
11 years agoqga: add guest-get-time command
Lei Li [Tue, 5 Mar 2013 09:39:11 +0000 (17:39 +0800)]
qga: add guest-get-time command

Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
*added stub for w32

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
11 years agoqemu-ga: use key-value store to avoid recycling fd handles after restart
Michael Roth [Fri, 1 Mar 2013 17:40:27 +0000 (11:40 -0600)]
qemu-ga: use key-value store to avoid recycling fd handles after restart

Hosts hold on to handles provided by guest-file-open for periods that can
span beyond the life of the qemu-ga process that issued them. Since these
are issued starting from 0 on every restart, we run the risk of issuing
duplicate handles after restarts/reboots.

As a result, users with a stale copy of these handles may end up
reading/writing corrupted data due to their existing handles effectively
being re-assigned to an unexpected file or offset.

We unfortunately do not issue handles as strings, but as integers, so a
solution such as using UUIDs can't be implemented without introducing a
new interface.

As a workaround, we fix this by implementing a persistent key-value store
that will be used to track the value of the last handle that was issued
across restarts/reboots to avoid issuing duplicates.

The store is automatically written to the same directory we currently
set via --statedir to track fsfreeze state, and so should be applicable
for stable releases where this flag is supported.

A follow-up can use this same store for handling fsfreeze state, but
that change is cosmetic and left out for now.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Cc: qemu-stable@nongnu.org
* fixed guest_file_handle_add() return value from uint64_t to int64_t

11 years agoqemu-ga: make guest-sync-delimited available during fsfreeze
Michael Roth [Fri, 1 Mar 2013 17:49:38 +0000 (11:49 -0600)]
qemu-ga: make guest-sync-delimited available during fsfreeze

We currently maintain a whitelist of commands that are safe during
fsfreeze. During fsfreeze, we disable all commands that aren't part of
that whitelist.

guest-sync-delimited meets the criteria for being whitelisted, and is
also required for qemu-ga clients that rely on guest-sync-delimited for
re-syncing the channel after a timeout.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Cc: qemu-stable@nongnu.org
Reviewed-by: Eric Blake <eblake@redhat.com>
11 years agoqemu-ga: fix confusing GAChannelMethod comparison
Stefan Hajnoczi [Tue, 19 Feb 2013 14:12:34 +0000 (15:12 +0100)]
qemu-ga: fix confusing GAChannelMethod comparison

In commit 7868e26e5930f49ca942311885776b938dcf3b77
("qemu-ga: add initial win32 support") support was added for qemu-ga on
Windows using virtio-serial.  Other channel methods (ISA serial and UNIX
domain socket) are not supported on Windows.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
11 years agoqga: cast to int for DWORD type
Lei Li [Mon, 28 Jan 2013 04:49:09 +0000 (12:49 +0800)]
qga: cast to int for DWORD type

This patch fixes a compiler warning when cross-build:

qga/service-win32.c: In function 'printf_win_error':
qga/service-win32.c:32:5: warning: format '%d' expects argument of type 'int',
                          but argument 3 has type 'DWORD' [-Wformat]

Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
11 years agoMerge remote-tracking branch 'quintela/migration.next' into staging
Anthony Liguori [Mon, 11 Mar 2013 13:30:34 +0000 (08:30 -0500)]
Merge remote-tracking branch 'quintela/migration.next' into staging

# By Paolo Bonzini (40) and others
# Via Juan Quintela
* quintela/migration.next: (46 commits)
  page_cache: dup memory on insert
  page_cache: fix memory leak
  Fix cache_resize to keep old entry age
  Fix page_cache leak in cache_resize
  migration: inline migrate_fd_close
  migration: eliminate s->migration_file
  migration: move contents of migration_close to migrate_fd_cleanup
  migration: move rate limiting to QEMUFile
  migration: small changes around rate-limiting
  migration: use qemu_ftell to compute bandwidth
  migration: use QEMUFile for writing outgoing migration data
  migration: use QEMUFile for migration channel lifetime
  qemu-file: simplify and export qemu_ftell
  qemu-file: add writable socket QEMUFile
  qemu-file: check exit status when closing a pipe QEMUFile
  qemu-file: fsync a writable stdio QEMUFile
  migration: merge qemu_popen_cmd with qemu_popen
  migration: use qemu_file_rate_limit consistently
  migration: remove useless qemu_file_get_error check
  migration: detect error before sleeping
  ...

11 years agoarm: fix compilation with CONFIG_FDT
Paolo Bonzini [Mon, 11 Mar 2013 10:31:26 +0000 (11:31 +0100)]
arm: fix compilation with CONFIG_FDT

A conflict was resolved the wrong way when merging commit 320ba5f (build:
always link device_tree.o into emulators if libfdt available, 2013-02-05).
This causes a build failure for the arm-softmmu target due to multiply
defined symbol.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1362997886-9470-1-git-send-email-pbonzini@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
11 years agolinux-user/syscall.c: Don't warn about unimplemented get_robust_list
Peter Maydell [Fri, 8 Feb 2013 04:34:54 +0000 (04:34 +0000)]
linux-user/syscall.c: Don't warn about unimplemented get_robust_list

The nature of the kernel ABI for the get_robust_list and set_robust_list
syscalls means we cannot implement them in QEMU. Make get_robust_list
silently return ENOSYS rather than using the default "print message and
then fail ENOSYS" code path, in the same way we already do for
set_robust_list, and add a comment documenting why we do this.

This silences warnings which were being produced for emulating
even trivial programs like 'ls' in x86-64-on-x86-64.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
11 years agolinux-user: Implement accept4
Peter Maydell [Fri, 8 Feb 2013 04:35:04 +0000 (04:35 +0000)]
linux-user: Implement accept4

Implement the accept4 syscall (which is identical to accept
but has an additional flags argument).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
11 years agolinux-user: Implement sendfile and sendfile64
Peter Maydell [Fri, 8 Feb 2013 07:31:55 +0000 (07:31 +0000)]
linux-user: Implement sendfile and sendfile64

Implement the sendfile and sendfile64 syscalls. This implementation
passes all the LTP test cases for these syscalls.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
11 years agolinux-user: make bogus negative iovec lengths fail EINVAL
Peter Maydell [Fri, 8 Feb 2013 07:58:41 +0000 (07:58 +0000)]
linux-user: make bogus negative iovec lengths fail EINVAL

If the guest passes us a bogus negative length for an iovec, fail
EINVAL rather than proceeding blindly forward. This fixes some of
the error cases tests for readv and writev in the LTP.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
11 years agolinux-user: Fix layout of usage table to account for option text
Peter Maydell [Thu, 14 Feb 2013 08:46:43 +0000 (08:46 +0000)]
linux-user: Fix layout of usage table to account for option text

The linux-user usage message attempts to line up the columns in
its table by calculating the maximum width of any item in them.
However for the 'Argument' column it was only accounting for the
length of the option switch (eg "-d"), not the additional example
text (eg "item[,...]"). This currently has no adverse effects
because the widest item in the column happens to be the argumentless
"-singlestep" option, but improving the "-d" option help to read
"-d item[,...]" exceeds that limit.

Fix this by correctly calculating maxarglen as the width of the
first column text including a possible option argument, and
adjusting its uses to match.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
11 years agopage_cache: dup memory on insert
Peter Lieven [Mon, 25 Feb 2013 17:12:04 +0000 (19:12 +0200)]
page_cache: dup memory on insert

The page cache frees all data on finish, on resize and
if there is collision on insert. So it should be the caches
responsibility to dup the data that is stored in the cache.

Signed-off-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agopage_cache: fix memory leak
Peter Lieven [Mon, 25 Feb 2013 17:12:03 +0000 (19:12 +0200)]
page_cache: fix memory leak

XBZRLE encoded migration introduced a MRU page cache
meachnism. Unfortunately, cached items where never freed in
case of a collision in the page cache on cache_insert().

This lead to out of memory conditions during XBZRLE migration
if the page cache was small and there where a lot of collisions
in the cache.

Signed-off-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agoFix cache_resize to keep old entry age
Orit Wasserman [Mon, 25 Feb 2013 17:12:02 +0000 (19:12 +0200)]
Fix cache_resize to keep old entry age

Instead of using cache_insert do the update itself

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agoFix page_cache leak in cache_resize
Orit Wasserman [Mon, 25 Feb 2013 17:12:01 +0000 (19:12 +0200)]
Fix page_cache leak in cache_resize

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: inline migrate_fd_close
Paolo Bonzini [Fri, 22 Feb 2013 16:36:48 +0000 (17:36 +0100)]
migration: inline migrate_fd_close

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: eliminate s->migration_file
Paolo Bonzini [Fri, 22 Feb 2013 16:36:47 +0000 (17:36 +0100)]
migration: eliminate s->migration_file

The indirection is useless now.  Backends can open s->file directly.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: move contents of migration_close to migrate_fd_cleanup
Paolo Bonzini [Fri, 22 Feb 2013 16:36:46 +0000 (17:36 +0100)]
migration: move contents of migration_close to migrate_fd_cleanup

With this patch, the migration_file is not needed anymore.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: move rate limiting to QEMUFile
Paolo Bonzini [Fri, 22 Feb 2013 16:36:45 +0000 (17:36 +0100)]
migration: move rate limiting to QEMUFile

Rate limiting is now simply a byte counter; client call
qemu_file_rate_limit() manually to determine if they have to exit.
So it is possible and simple to move the functionality to QEMUFile.

This makes the remaining functionality of s->file redundant;
in the next patch we can remove it and write directly to s->migration_file.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: small changes around rate-limiting
Paolo Bonzini [Fri, 22 Feb 2013 16:36:44 +0000 (17:36 +0100)]
migration: small changes around rate-limiting

This patch extracts a few small changes from the next patch, which
are unrelated to adding generic rate-limiting functionality to
QEMUFile.  Make migration_set_rate_limit a simple accessor, and
use qemu_file_set_rate_limit consistently.  Also fix a typo where
INT_MAX should have been SIZE_MAX.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: use qemu_ftell to compute bandwidth
Paolo Bonzini [Fri, 22 Feb 2013 16:36:43 +0000 (17:36 +0100)]
migration: use qemu_ftell to compute bandwidth

Prepare for when s->bytes_xfer will be removed.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: use QEMUFile for writing outgoing migration data
Paolo Bonzini [Fri, 22 Feb 2013 16:36:42 +0000 (17:36 +0100)]
migration: use QEMUFile for writing outgoing migration data

Second, drop the file descriptor indirection, and write directly to the
QEMUFile.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: use QEMUFile for migration channel lifetime
Paolo Bonzini [Fri, 22 Feb 2013 16:36:41 +0000 (17:36 +0100)]
migration: use QEMUFile for migration channel lifetime

As a start, use QEMUFile to store the destination and close it.
qemu_get_fd gets a file descriptor that will be used by the write
callbacks.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agoqemu-file: simplify and export qemu_ftell
Paolo Bonzini [Fri, 22 Feb 2013 16:36:40 +0000 (17:36 +0100)]
qemu-file: simplify and export qemu_ftell

Force a flush when qemu_ftell is called.  This simplifies the buffer magic
(it also breaks qemu_ftell for input QEMUFiles, but we never use it).

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agoqemu-file: add writable socket QEMUFile
Paolo Bonzini [Fri, 22 Feb 2013 16:36:39 +0000 (17:36 +0100)]
qemu-file: add writable socket QEMUFile

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agoqemu-file: check exit status when closing a pipe QEMUFile
Paolo Bonzini [Fri, 22 Feb 2013 16:36:38 +0000 (17:36 +0100)]
qemu-file: check exit status when closing a pipe QEMUFile

This is what exec_close does.  Move this to the underlying QEMUFile.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agoqemu-file: fsync a writable stdio QEMUFile
Paolo Bonzini [Fri, 22 Feb 2013 16:36:37 +0000 (17:36 +0100)]
qemu-file: fsync a writable stdio QEMUFile

This is what fd_close does.  Prepare for switching to a QEMUFile.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: merge qemu_popen_cmd with qemu_popen
Paolo Bonzini [Fri, 22 Feb 2013 16:36:36 +0000 (17:36 +0100)]
migration: merge qemu_popen_cmd with qemu_popen

There is no reason for outgoing exec migration to do popen manually
anymore (the reason used to be that we needed the FILE* to make it
non-blocking).  Use qemu_popen_cmd.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: use qemu_file_rate_limit consistently
Paolo Bonzini [Fri, 22 Feb 2013 16:36:35 +0000 (17:36 +0100)]
migration: use qemu_file_rate_limit consistently

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: remove useless qemu_file_get_error check
Paolo Bonzini [Fri, 22 Feb 2013 16:36:34 +0000 (17:36 +0100)]
migration: remove useless qemu_file_get_error check

migration_put_buffer is never called if there has been an error.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: detect error before sleeping
Paolo Bonzini [Fri, 22 Feb 2013 16:36:33 +0000 (17:36 +0100)]
migration: detect error before sleeping

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: eliminate last_round
Paolo Bonzini [Fri, 22 Feb 2013 16:36:32 +0000 (17:36 +0100)]
migration: eliminate last_round

We will go around the loop exactly once after setting last_round.
Eliminate the variable altogether.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agoqemu-file: make qemu_fflush and qemu_file_set_error private again
Paolo Bonzini [Fri, 22 Feb 2013 16:36:31 +0000 (17:36 +0100)]
qemu-file: make qemu_fflush and qemu_file_set_error private again

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agoRename buffered_ to migration_
Juan Quintela [Fri, 22 Feb 2013 16:36:30 +0000 (17:36 +0100)]
Rename buffered_ to migration_

This is consistent once that we have moved everything to migration.c

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: yay, buffering is gone
Paolo Bonzini [Fri, 22 Feb 2013 16:36:29 +0000 (17:36 +0100)]
migration: yay, buffering is gone

Buffering was needed because blocking writes could take a long time
and starve other threads seeking to grab the big QEMU mutex.

Now that all writes (except within _complete callbacks) are done
outside the big QEMU mutex, we do not need buffering at all.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: run setup callbacks out of big lock
Paolo Bonzini [Fri, 22 Feb 2013 16:36:28 +0000 (17:36 +0100)]
migration: run setup callbacks out of big lock

Only the migration_bitmap_sync() call needs the iothread lock.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: run pending/iterate callbacks out of big lock
Paolo Bonzini [Fri, 22 Feb 2013 16:36:27 +0000 (17:36 +0100)]
migration: run pending/iterate callbacks out of big lock

This makes it possible to do blocking writes directly to the socket,
with no buffer in the middle.  For RAM, only the migration_bitmap_sync()
call needs the iothread lock.  For block migration, it is needed by
the block layer (including bdrv_drain_all and dirty bitmap access),
but because some code is shared between iterate and complete, all of
mig_save_device_dirty is run with the lock taken.

In the savevm case, the iterate callback runs within the big lock.
This is annoying because it complicates the rules.  Luckily we do not
need to do anything about it: the RAM iterate callback does not need
the iothread lock, and block migration never runs during savevm.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: reorder SaveVMHandlers members
Paolo Bonzini [Fri, 22 Feb 2013 16:36:26 +0000 (17:36 +0100)]
migration: reorder SaveVMHandlers members

This groups together the callbacks that later will have similar
locking rules.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agoblock-migration: add lock
Paolo Bonzini [Fri, 22 Feb 2013 16:36:25 +0000 (17:36 +0100)]
block-migration: add lock

Some state is shared between the block migration code and its AIO
callbacks.  Once block migration will run outside the iothread,
the block migration code and the AIO callbacks will be able to
run concurrently.  Protect the critical sections with a separate
lock.  Do the same for completed_sectors, which can be used from
the monitor.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agoblock-migration: document usage of state across threads
Paolo Bonzini [Fri, 22 Feb 2013 16:36:24 +0000 (17:36 +0100)]
block-migration: document usage of state across threads

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agoblock-migration: small preparatory changes for locking
Paolo Bonzini [Fri, 22 Feb 2013 16:36:23 +0000 (17:36 +0100)]
block-migration: small preparatory changes for locking

Some small changes that will simplify the positioning of lock/unlock
primitives.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agoblock-migration: remove variables that are never read
Paolo Bonzini [Fri, 22 Feb 2013 16:36:22 +0000 (17:36 +0100)]
block-migration: remove variables that are never read

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: cleanup migration (including thread) in the iothread
Paolo Bonzini [Fri, 22 Feb 2013 16:36:21 +0000 (17:36 +0100)]
migration: cleanup migration (including thread) in the iothread

Perform final cleanup in a bottom half, and add joining the thread to
the series of cleanup actions.

migrate_fd_error remains for connection error, but it doesn't need
to cleanup anything anymore.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
11 years agomigration: prepare to access s->state outside critical sections
Paolo Bonzini [Fri, 22 Feb 2013 16:36:20 +0000 (17:36 +0100)]
migration: prepare to access s->state outside critical sections

Accessing s->state outside the big QEMU lock will simplify a bit the
locking/unlocking of the iothread lock.

We need to keep the lock in migrate_fd_error and migrate_fd_completed,
however, because they call migrate_fd_cleanup.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>