]> git.ipfire.org Git - thirdparty/qemu.git/log
thirdparty/qemu.git
9 years agoblock: Suppress unhelpful extra errors in bdrv_img_create()
Markus Armbruster [Thu, 12 Feb 2015 16:49:02 +0000 (17:49 +0100)] 
block: Suppress unhelpful extra errors in bdrv_img_create()

bdrv_img_create() uses qemu_opt_set(), which reports errors with
qerror_report_err().  Its error messages aren't helpful here, the
caller reports one that actually makes sense.  I don't know how to
trigger the error conditions, though.

Switch to qemu_opt_set_err() to get rid of the unwanted messages.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agoqemu-img: Suppress unhelpful extra errors in convert, resize
Markus Armbruster [Thu, 12 Feb 2015 16:43:08 +0000 (17:43 +0100)] 
qemu-img: Suppress unhelpful extra errors in convert, resize

add_old_style_options() for img_convert() and img_resize() use
qemu_opt_set(), which reports errors with qerror_report_err().  Its
error messages aren't helpful here, the caller reports one that
actually makes sense.  Reproducer:

    $ qemu-img convert -B raw in.img out.img
    qemu-img: Invalid parameter 'backing_file'
    qemu-img: Backing file not supported for file format 'raw'

Switch to qemu_opt_set_err() to get rid of the unwanted messages.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agoQemuOpts: Convert qemu_opts_set() to Error, fix its use
Markus Armbruster [Thu, 12 Feb 2015 16:07:34 +0000 (17:07 +0100)] 
QemuOpts: Convert qemu_opts_set() to Error, fix its use

Return the Error object instead of reporting it with
qerror_report_err().

Change callers that assume the function can't fail to pass
&error_abort, so that should the assumption ever break, it'll break
noisily.

Turns out all callers outside its unit test assume that.  We could
drop the Error ** argument, but that would make the interface less
regular, so don't.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agoQemuOpts: Convert qemu_opt_set_number() to Error, fix its use
Markus Armbruster [Thu, 12 Feb 2015 15:46:36 +0000 (16:46 +0100)] 
QemuOpts: Convert qemu_opt_set_number() to Error, fix its use

Return the Error object instead of reporting it with
qerror_report_err().

Change callers that assume the function can't fail to pass
&error_abort, so that should the assumption ever break, it'll break
noisily.

Turns out all callers outside its unit test assume that.  We could
drop the Error ** argument, but that would make the interface less
regular, so don't.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agoQemuOpts: Convert qemu_opt_set_bool() to Error, fix its use
Markus Armbruster [Thu, 12 Feb 2015 15:37:44 +0000 (16:37 +0100)] 
QemuOpts: Convert qemu_opt_set_bool() to Error, fix its use

Return the Error object instead of reporting it with
qerror_report_err().

Change callers that assume the function can't fail to pass
&error_abort, so that should the assumption ever break, it'll break
noisily.

Turns out all callers outside its unit test assume that.  We could
drop the Error ** argument, but that would make the interface less
regular, so don't.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agoMerge remote-tracking branch 'remotes/armbru/tags/pull-error-2015-02-18' into staging
Peter Maydell [Thu, 26 Feb 2015 07:01:08 +0000 (07:01 +0000)] 
Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2015-02-18' into staging

Clean up around error_get_pretty(), qerror_report_err()

# gpg: Signature made Wed Feb 18 10:10:07 2015 GMT using RSA key ID EB918653
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>"
# gpg:                 aka "Markus Armbruster <armbru@pond.sub.org>"

* remotes/armbru/tags/pull-error-2015-02-18:
  qemu-char: Avoid qerror_report_err() outside QMP command handlers
  qemu-img: Avoid qerror_report_err() outside QMP command handlers
  vl: Avoid qerror_report_err() outside QMP command handlers
  tpm: Avoid qerror_report_err() outside QMP command handlers
  numa: Avoid qerror_report_err() outside QMP command handlers
  net: Avoid qerror_report_err() outside QMP command handlers
  monitor: Avoid qerror_report_err() outside QMP command handlers
  monitor: Clean up around monitor_handle_fd_param()
  error: Use error_report_err() where appropriate
  error: New convenience function error_report_err()
  vhost-scsi: Improve error reporting for invalid vhostfd

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9 years agoMerge remote-tracking branch 'remotes/armbru/tags/pull-monitor-2015-02-18' into staging
Peter Maydell [Wed, 25 Feb 2015 13:14:37 +0000 (13:14 +0000)] 
Merge remote-tracking branch 'remotes/armbru/tags/pull-monitor-2015-02-18' into staging

hmp: Normalize HMP command handler names

# gpg: Signature made Wed Feb 18 10:59:44 2015 GMT using RSA key ID EB918653
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>"
# gpg:                 aka "Markus Armbruster <armbru@pond.sub.org>"

* remotes/armbru/tags/pull-monitor-2015-02-18:
  hmp: Name HMP info handler functions hmp_info_SUBCOMMAND()
  hmp: Name HMP command handler functions hmp_COMMAND()
  hmp: Clean up declarations for long-gone info handlers

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9 years agoMerge remote-tracking branch 'remotes/kraxel/tags/pull-usb-20150218-1' into staging
Peter Maydell [Wed, 25 Feb 2015 11:54:15 +0000 (11:54 +0000)] 
Merge remote-tracking branch 'remotes/kraxel/tags/pull-usb-20150218-1' into staging

usb: error handling fixes from Markus, make sysbus ehci arm-only.

# gpg: Signature made Wed Feb 18 09:54:13 2015 GMT using RSA key ID D3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>"
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>"
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>"

* remotes/kraxel/tags/pull-usb-20150218-1:
  Make sysbus EHCI devices ARM only by default
  PPC: Don't use legacy -usbdevice support for setting up board
  r2d: Don't use legacy -usbdevice support for setting up board
  usb: Change usb_create_simple() to abort on failure
  usb: Suppress bogus error when automatic usb-hub creation fails
  usb: Do not prefix error_setg() messages with "Error: "
  usb: Improve -usbdevice error reporting a bit
  usb: usb_create() can't fail, drop useless error handling

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9 years agoMerge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2015-02-16-v2-tag' into...
Peter Maydell [Wed, 25 Feb 2015 11:05:10 +0000 (11:05 +0000)] 
Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2015-02-16-v2-tag' into staging

tag for qga-pull-2015-02-16-v2

v2:

* generalized QAPI function definition for guest-memory-block-size
  to guest-memory-block-info for future extensibility (Eric)

# gpg: Signature made Tue Feb 17 22:36:08 2015 GMT using RSA key ID F108B584
# gpg: Good signature from "Michael Roth <flukshun@gmail.com>"
# gpg:                 aka "Michael Roth <mdroth@utexas.edu>"
# gpg:                 aka "Michael Roth <mdroth@linux.vnet.ibm.com>"
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: CEAC C9E1 5534 EBAB B82D  3FA0 3353 C9CE F108 B584

* remotes/mdroth/tags/qga-pull-2015-02-16-v2-tag:
  qemu-ga-win: Fail loudly on bare 'set-time'
  qga: add memory block command that unsupported
  qga: implement qmp_guest_get_memory_block_info() for Linux with sysfs
  qga: implement qmp_guest_set_memory_blocks() for Linux with sysfs
  qga: implement qmp_guest_get_memory_blocks() for Linux with sysfs
  qga: introduce three guest memory block commmands with stubs
  qga: implement file commands for Windows guest
  guest agent: guest-file-open: refactoring
  utils: drop strtok_r from envlist_parse
  qga: add guest-set-user-password command

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9 years agoMerge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
Peter Maydell [Tue, 24 Feb 2015 13:58:18 +0000 (13:58 +0000)] 
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging

- vhost-scsi: add bootindex property
- RCU: fix MemoryRegion lifetime issues in PCI; document the rules;
convert of AddressSpaceDispatch and RAMList
- KVM: add kvm_exit reasons for aarch64

# gpg: Signature made Mon Feb 16 16:32:32 2015 GMT using RSA key ID 78C7AE83
# gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>"
# gpg:                 aka "Paolo Bonzini <pbonzini@redhat.com>"
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4  E2F7 7E15 100C CD36 69B1
#      Subkey fingerprint: F133 3857 4B66 2389 866C  7682 BFFB D25F 78C7 AE83

* remotes/bonzini/tags/for-upstream: (21 commits)
  Convert ram_list to RCU
  exec: convert ram_list to QLIST
  cosmetic changes preparing for the following patches
  exec: protect mru_block with RCU
  rcu: add g_free_rcu
  rcu: introduce RCU-enabled QLIST
  exec: RCUify AddressSpaceDispatch
  exec: make iotlb RCU-friendly
  exec: introduce cpu_reload_memory_map
  docs: clarify memory region lifecycle
  pci: split shpc_cleanup and shpc_free
  pcie: remove mmconfig memory leak and wrap mmconfig update with transaction
  memory: keep the owner of the AddressSpace alive until do_address_space_destroy
  rcu: run RCU callbacks under the BQL
  rcu: do not let RCU callbacks pile up indefinitely
  vhost-scsi: set the bootable value of channel/target/lun
  vhost-scsi: add a property for booting
  vhost-scsi: expose the TYPE_FW_PATH_PROVIDER interface
  vhost-scsi: add bootindex property
  qdev: support to get a device firmware path directly
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9 years agoMerge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging
Peter Maydell [Tue, 24 Feb 2015 12:59:13 +0000 (12:59 +0000)] 
Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging

Pull request

v2:
 * Fix C11 typedef redefinitions in ahci and libqos malloc [Peter]
 * Fix lx -> PRIx64 format specifiers in ahci [Peter]

# gpg: Signature made Mon Feb 16 15:45:53 2015 GMT using RSA key ID 81AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>"
# gpg:                 aka "Stefan Hajnoczi <stefanha@gmail.com>"

* remotes/stefanha/tags/block-pull-request: (65 commits)
  block: Keep bdrv_check*_request()'s return value
  block: Remove "growable" from BDS
  block: Clamp BlockBackend requests
  qemu-io: Use BlockBackend
  qemu-io: Remove "growable" option
  qemu-io: Use blk_new_open() in openfile()
  qemu-nbd: Use blk_new_open() in main()
  qemu-img: Use BlockBackend as far as possible
  qemu-img: Use blk_new_open() in img_rebase()
  qemu-img: Use blk_new_open() in img_open()
  block/xen: Use blk_new_open() in blk_connect()
  blockdev: Use blk_new_open() in blockdev_init()
  iotests: Add test for driver=qcow2, format=qcow2
  block: Add Error parameter to bdrv_find_protocol()
  block: Add blk_new_open()
  block: Lift some BDS functions to the BlockBackend
  iotests: Add test for qemu-img convert to NBD
  qemu-img: Fix qemu-img convert -n
  qemu-iotests: Add 093 for IO throttling
  qemu-iotests: Allow caller to disable underscore convertion for qmp
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9 years agoMerge remote-tracking branch 'remotes/kraxel/tags/pull-vnc-20150216-1' into staging
Peter Maydell [Tue, 24 Feb 2015 12:07:28 +0000 (12:07 +0000)] 
Merge remote-tracking branch 'remotes/kraxel/tags/pull-vnc-20150216-1' into staging

vnc: fixup some QemuOpts conversion fallout.

# gpg: Signature made Mon Feb 16 08:13:32 2015 GMT using RSA key ID D3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>"
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>"
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>"

* remotes/kraxel/tags/pull-vnc-20150216-1:
  vnc: fix coverity warning
  ui/vnc: optimize full scanline updates
  vnc: auto assian an id when calling change vnc qmp interface
  vnc: introduce an wrapper for auto assign vnc id
  vnc: using bool type instead of int for QEMU_OPT_BOOL
  vnc: correct missing property about vnc_display
  vnc: fix qemu crash when not configure vnc option

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9 years agoMerge remote-tracking branch 'remotes/lalrae/tags/mips-20150213-2' into staging
Peter Maydell [Tue, 24 Feb 2015 11:08:40 +0000 (11:08 +0000)] 
Merge remote-tracking branch 'remotes/lalrae/tags/mips-20150213-2' into staging

MIPS patches 2015-02-13

Changes:
* bug fixes, cleanups and minor improvements

# gpg: Signature made Sat Feb 14 17:01:37 2015 GMT using RSA key ID 0B29DA6B
# gpg: Can't check signature: public key not found

* remotes/lalrae/tags/mips-20150213-2:
  linux-user: correct stat structure in MIPS N32
  target-mips: pass 0 instead of -1 as rs in microMIPS LUI instruction
  target-mips: fix broken snapshotting
  target-mips: use CP0EnLo_XI instead of magic number
  target-mips: ll and lld cause AdEL exception for unaligned address
  target-mips: fix detection of the end of the page during translation
  target-mips: Make CP0.Status.CU1 read-only for the 5Kc and 5KEc processors
  isa: remove isa_mem_base variable
  gt64xxx: remove isa_mem_base usage
  piix4: use PCI address space instead of system memory
  mips: remove isa_mem_base usage
  jazz: remove usage of isa_mem_base
  jazz: do not explode QEMUMachineInitArgs structure
  isa: add memory space parameter to isa_bus_new

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9 years agohmp: Name HMP info handler functions hmp_info_SUBCOMMAND()
Markus Armbruster [Fri, 6 Feb 2015 13:18:24 +0000 (14:18 +0100)] 
hmp: Name HMP info handler functions hmp_info_SUBCOMMAND()

Some are called do_info_SUBCOMMAND() (old ones, usually), some
hmp_info_SUBCOMMAND(), some SUBCOMMAND_info(), sometimes SUBCOMMAND
pointlessly differs in spelling.

Normalize to hmp_info_SUBCOMMAND(), where SUBCOMMAND is exactly the
subcommand name with '-' replaced by '_'.

Exceptions:

* sun4m_irq_info(), sun4m_pic_info() renamed to sun4m_hmp_info_irq(),
  sun4m_hmp_info_pic().

* lm32_irq_info(), lm32_pic_info() renamed to lm32_hmp_info_irq(),
  lm32_hmp_info_pic().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
9 years agohmp: Name HMP command handler functions hmp_COMMAND()
Markus Armbruster [Fri, 6 Feb 2015 12:55:43 +0000 (13:55 +0100)] 
hmp: Name HMP command handler functions hmp_COMMAND()

Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.

Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.

Exceptions:

* do_device_add() and client_migrate_info() *not* renamed to
  hmp_device_add(), hmp_client_migrate_info(), because they're also
  QMP handlers.  They still need to be converted to QAPI.

* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
  do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
  hmp_i(), hmp_o(), because those names are too cryptic for my taste.

* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
  because it only covers help.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
9 years agohmp: Clean up declarations for long-gone info handlers
Markus Armbruster [Fri, 6 Feb 2015 11:07:09 +0000 (12:07 +0100)] 
hmp: Clean up declarations for long-gone info handlers

Leftovers from
d1f2964 qapi: Convert query-spice
791e7c8 qapi: Convert query-migrate
0fe6a7f slirp: Drop statistic code

Signed-off-by: Markus Armbruster <armbru@redhat.com>
9 years agoMake sysbus EHCI devices ARM only by default
David Gibson [Wed, 18 Feb 2015 05:01:01 +0000 (16:01 +1100)] 
Make sysbus EHCI devices ARM only by default

A number of ARM embedded boards include EHCI USB host controllers which
appear as directly mapped devices, rather than sitting on a PCI bus.

At present code to emulate such devices is included whenever EHCI support
is included.  This patch adjusts teh config options to only include them
in builds targetting ARM by default.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
9 years agoPPC: Don't use legacy -usbdevice support for setting up board
Markus Armbruster [Wed, 4 Feb 2015 12:28:14 +0000 (13:28 +0100)] 
PPC: Don't use legacy -usbdevice support for setting up board

It's tempting, because usbdevice_create() is so simple to use.  But
there's a lot of unwanted complexity behind the simple interface.
Switch to usb_create_simple().

Cc: Alexander Graf <agraf@suse.de>
Cc: qemu-ppc@nongnu.org
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
9 years agor2d: Don't use legacy -usbdevice support for setting up board
Markus Armbruster [Wed, 4 Feb 2015 12:28:13 +0000 (13:28 +0100)] 
r2d: Don't use legacy -usbdevice support for setting up board

It's tempting, because usbdevice_create() is so simple to use.  But
there's a lot of unwanted complexity behind the simple interface.
Switch to usb_create_simple().

Cc: Magnus Damm <magnus.damm@gmail.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
9 years agousb: Change usb_create_simple() to abort on failure
Markus Armbruster [Wed, 4 Feb 2015 12:28:12 +0000 (13:28 +0100)] 
usb: Change usb_create_simple() to abort on failure

Instead of returning null pointer.  Matches pci_create_simple(),
isa_create_simple(), sysbus_create_simple().  It's unused since the
previous commit, but I'll put it to use again shortly.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
9 years agousb: Suppress bogus error when automatic usb-hub creation fails
Markus Armbruster [Wed, 4 Feb 2015 12:28:11 +0000 (13:28 +0100)] 
usb: Suppress bogus error when automatic usb-hub creation fails

USBDevice's realize method usb_qdev_realize() automatically creates a
usb-hub when only one port is left.  Creating devices in realize
methods is questionable, but works.

If usb-hub creation fails, an error is reported to stderr, but the
failure is otherwise ignored.  We then create the actual device using
the last port, which may well succeed.

Example:

    $ qemu -nodefaults -S -display none -machine usb=on -monitor stdio
    QEMU 2.2.50 monitor - type 'help' for more information
    (qemu) device_add usb-mouse
    [Repeat 36 times]
    (qemu) info usb
      Device 0.0, Port 1, Speed 12 Mb/s, Product QEMU USB Mouse
      Device 0.0, Port 2, Speed 12 Mb/s, Product QEMU USB Hub
      Device 0.0, Port 2.1, Speed 12 Mb/s, Product QEMU USB Mouse
    [More mice and hubs omitted...]
      Device 0.0, Port 2.8.8.8.8.7, Speed 12 Mb/s, Product QEMU USB Mouse
    (qemu) device_add usb-mouse
    usb hub chain too deep
    Failed to initialize USB device 'usb-hub'
    (qemu) info usb
    [...]
      Device 0.0, Port 2.8.8.8.8.7, Speed 12 Mb/s, Product QEMU USB Mouse
      Device 0.0, Port 2.8.8.8.8.8, Speed 12 Mb/s, Product QEMU USB Mouse

Despite the "Failed" message, the command actually succeeded.

In QMP, it's worse.  When adding the 37th mouse via QMP, the command
fails with

    {"error": {"class": "GenericError", "desc": "usb hub chain too deep"}}

Additionally, "Failed to initialize USB device 'usb-hub'" is reported
on stderr.  Despite the command failure, the device was created.  This
is wrong.

Fix by avoiding qdev_init() for usb-hub creation, so we can ignore
errors cleanly.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
9 years agousb: Do not prefix error_setg() messages with "Error: "
Markus Armbruster [Wed, 4 Feb 2015 12:28:10 +0000 (13:28 +0100)] 
usb: Do not prefix error_setg() messages with "Error: "

Because it produces beauties like

    (qemu) usb_add mouse
    Failed to initialize USB device 'usb-mouse': Error: tried to attach usb device QEMU USB Mouse to a bus with no free ports

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
9 years agousb: Improve -usbdevice error reporting a bit
Markus Armbruster [Wed, 4 Feb 2015 12:28:09 +0000 (13:28 +0100)] 
usb: Improve -usbdevice error reporting a bit

Most LegacyUSBFactory usbdevice_init() methods realize with
qdev_init_nofail(), even though their caller usbdevice_create() can
handle failure.  Okay if it really can't fail (I didn't check), but
somewhat brittle.

usb_msd_init() and usb_bt_init() call qdev_init().  The latter
additionally reports an error when qdev_init() fails.

Realization failure produces multiple error reports: a specific one
from qdev_init(), and generic ones from usb_bt_init(),
usb_create_simple(), usbdevice_create() and usb_parse().

Remove realization from the usbdevice_init() methods.  Realize in
usbdevice_create(), and produce exactly one error message there.  You
still get another one from usb_parse().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
9 years agousb: usb_create() can't fail, drop useless error handling
Markus Armbruster [Wed, 4 Feb 2015 12:28:08 +0000 (13:28 +0100)] 
usb: usb_create() can't fail, drop useless error handling

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
9 years agoqemu-char: Avoid qerror_report_err() outside QMP command handlers
Markus Armbruster [Tue, 10 Feb 2015 14:21:26 +0000 (15:21 +0100)] 
qemu-char: Avoid qerror_report_err() outside QMP command handlers

qerror_report_err() is a transitional interface to help with
converting existing monitor commands to QMP.  It should not be used
elsewhere.  Replace by error_report_err() in legacy chardev parser
qemu_chr_parse_compat().  Legacy chardev syntax is not to be used in
QMP.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agoqemu-img: Avoid qerror_report_err() outside QMP command handlers
Markus Armbruster [Tue, 10 Feb 2015 14:14:02 +0000 (15:14 +0100)] 
qemu-img: Avoid qerror_report_err() outside QMP command handlers

qerror_report_err() is a transitional interface to help with
converting existing monitor commands to QMP.  It should not be used
elsewhere.  Replace by error_report_err().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agovl: Avoid qerror_report_err() outside QMP command handlers
Markus Armbruster [Tue, 10 Feb 2015 14:12:59 +0000 (15:12 +0100)] 
vl: Avoid qerror_report_err() outside QMP command handlers

qerror_report_err() is a transitional interface to help with
converting existing monitor commands to QMP.  It should not be used
elsewhere.  Replace by error_report_err() in initial startup helpers
machine_set_property() and object_create().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agotpm: Avoid qerror_report_err() outside QMP command handlers
Markus Armbruster [Tue, 10 Feb 2015 14:11:17 +0000 (15:11 +0100)] 
tpm: Avoid qerror_report_err() outside QMP command handlers

qerror_report_err() is a transitional interface to help with
converting existing monitor commands to QMP.  It should not be used
elsewhere.  Replace by error_report_err() in initial startup helper
configure_tpm().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agonuma: Avoid qerror_report_err() outside QMP command handlers
Markus Armbruster [Tue, 10 Feb 2015 14:06:23 +0000 (15:06 +0100)] 
numa: Avoid qerror_report_err() outside QMP command handlers

qerror_report_err() is a transitional interface to help with
converting existing monitor commands to QMP.  It should not be used
elsewhere.  Replace by error_report_err() in initial startup helper
numa_init_func() and board setup helper
memory_region_allocate_system_memory().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agonet: Avoid qerror_report_err() outside QMP command handlers
Markus Armbruster [Tue, 10 Feb 2015 14:02:06 +0000 (15:02 +0100)] 
net: Avoid qerror_report_err() outside QMP command handlers

qerror_report_err() is a transitional interface to help with
converting existing monitor commands to QMP.  It should not be used
elsewhere.  Replace by error_report_err() in HMP command handler
hmp_host_net_add() and initial startup helpers net_init_client(),
net_init_netdev().  Keep it in QMP command handler qmp_netdev_add().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agomonitor: Avoid qerror_report_err() outside QMP command handlers
Markus Armbruster [Tue, 10 Feb 2015 14:15:43 +0000 (15:15 +0100)] 
monitor: Avoid qerror_report_err() outside QMP command handlers

qerror_report_err() is a transitional interface to help with
converting existing monitor commands to QMP.  It should not be used
elsewhere.  Replace by error_report_err() in HMP command handler
hmp_trace_event().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agomonitor: Clean up around monitor_handle_fd_param()
Markus Armbruster [Mon, 9 Feb 2015 13:03:19 +0000 (14:03 +0100)] 
monitor: Clean up around monitor_handle_fd_param()

monitor_handle_fd_param() is a wrapper around
monitor_handle_fd_param2() that feeds errors to qerror_report_err()
instead of returning them.  qerror_report_err() is inappropriate in
many contexts.  monitor_handle_fd_param() looks simpler than
monitor_handle_fd_param2(), which tempts use.  Remove the temptation:
drop the wrapper and open-code the (trivial) error handling instead.

Replace the open-coded qerror_report_err() by error_report_err() in
places that already use error_report().  Turns out that's everywhere.

While there, rename monitor_handle_fd_param2() to monitor_fd_param().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agoerror: Use error_report_err() where appropriate
Markus Armbruster [Thu, 12 Feb 2015 12:55:05 +0000 (13:55 +0100)] 
error: Use error_report_err() where appropriate

Coccinelle semantic patch:

    @@
    expression E;
    @@
    -    error_report("%s", error_get_pretty(E));
    -    error_free(E);
    +    error_report_err(E);
    @@
    expression E, S;
    @@
    -    error_report("%s", error_get_pretty(E));
    +    error_report_err(E);
    (
         exit(S);
    |
         abort();
    )

Trivial manual touch-ups in block/sheepdog.c.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agoerror: New convenience function error_report_err()
Markus Armbruster [Fri, 6 Feb 2015 14:27:19 +0000 (15:27 +0100)] 
error: New convenience function error_report_err()

I've typed error_report("%s", error_get_pretty(ERR)) too many times
already, and I've fixed too many instances of qerror_report_err(ERR)
to error_report("%s", error_get_pretty(ERR)) as well.  Capture the
pattern in a convenience function.

Since it's almost invariably followed by error_free(), stuff that into
the convenience function as well.

The next patch will put it to use.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
9 years agovhost-scsi: Improve error reporting for invalid vhostfd
Markus Armbruster [Mon, 9 Feb 2015 10:49:08 +0000 (11:49 +0100)] 
vhost-scsi: Improve error reporting for invalid vhostfd

We get two error messages: one from monitor_handle_fd_param2(), and
another one from vhost_scsi_realize().  The second one gets suppressed
in QMP context.

That's because monitor_handle_fd_param() calls qerror_report_err().
Calling qerror_report_err() is always inappropriate in realize
methods, because it doesn't return the Error object.  It either
reports the error to stderr or the human monitor, or it stores it in
the QMP monitor, where it makes the QMP command fail even when the
realize method ignores the error and succeeds.  Fortunately,
vhost_scsi_realize() doesn't do that.

Fix by switching to monitor_handle_fd_param2().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agoqemu-ga-win: Fail loudly on bare 'set-time'
Michal Privoznik [Wed, 21 Jan 2015 11:09:50 +0000 (12:09 +0100)] 
qemu-ga-win: Fail loudly on bare 'set-time'

The command is not implemented correctly yet. The documentation allows
to not pass any value to set, in which case the time is re-read from
RTC. However, reading CMOS on Windows is not trivial to implement. So
instead of pretending we've set the correct time, fail explicitly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
9 years agoqga: add memory block command that unsupported
zhanghailiang [Thu, 22 Jan 2015 02:40:06 +0000 (10:40 +0800)] 
qga: add memory block command that unsupported

For memory block command, we only support for linux with sysfs.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
9 years agoqga: implement qmp_guest_get_memory_block_info() for Linux with sysfs
zhanghailiang [Thu, 22 Jan 2015 02:40:05 +0000 (10:40 +0800)] 
qga: implement qmp_guest_get_memory_block_info() for Linux with sysfs

This conveys general information about guest memory blocks. Currently,
just the memory block size.

The size of a memory block is architecture dependent, it represents the logical
unit upon which memory online/offline operations are to be performed.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
*generalized guest-get-memory-block-size to get-get-memory-block-info
 for future extensibility

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
9 years agoqga: implement qmp_guest_set_memory_blocks() for Linux with sysfs
zhanghailiang [Thu, 22 Jan 2015 02:40:04 +0000 (10:40 +0800)] 
qga: implement qmp_guest_set_memory_blocks() for Linux with sysfs

We can change guest's online/offline state of memory blocks, by using
command 'guest-set-memory-blocks'.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
9 years agoqga: implement qmp_guest_get_memory_blocks() for Linux with sysfs
zhanghailiang [Thu, 22 Jan 2015 02:40:03 +0000 (10:40 +0800)] 
qga: implement qmp_guest_get_memory_blocks() for Linux with sysfs

We can get guest's memory block information by using command
"guest-get-memory-blocks", the returned value contains a list of memory block
info, such as phys-index, online state, can-offline info.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
*replaced guest-triggerable assertion with an error msg

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
9 years agoqga: introduce three guest memory block commmands with stubs
zhanghailiang [Thu, 22 Jan 2015 02:40:02 +0000 (10:40 +0800)] 
qga: introduce three guest memory block commmands with stubs

Introduce three new guest commands:
guest-get-memory-blocks, guest-set-memory-blocks, guest-get-memory-block-size.

With these three commands, we can support online/offline guest's memory block
(logical memory hotplug/unplug) as required from host.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
*generalized guest-get-memory-block-size to get-get-memory-block-info
 for future extensibility

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
9 years agoqga: implement file commands for Windows guest
Olga Krishtal [Fri, 6 Feb 2015 17:59:55 +0000 (20:59 +0300)] 
qga: implement file commands for Windows guest

The following commands are implemented:
- guest_file_open
- guest_file_close
- guest_file_write
- guest_file_read
- guest_file_seek
- guest_file_flush

Motivation is quite simple: Windows guests should be supported with the
same set of features as Linux one. Also this patch is a prerequisite for
Windows guest-exec command support.

Signed-off-by: Olga Krishtal <okrishtal@parallels.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
9 years agoguest agent: guest-file-open: refactoring
Simon Zolin [Fri, 6 Feb 2015 17:59:54 +0000 (20:59 +0300)] 
guest agent: guest-file-open: refactoring

Moved the code that sets non-blocking flag on fd into a separate function.

Signed-off-by: Simon Zolin <szolin@parallels.com>
Reviewed-by: Roman Kagan <rkagan@parallels.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Michael Roth <mdroth@linux.vnet.ibm.com>
CC: Eric Blake <eblake@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
9 years agoutils: drop strtok_r from envlist_parse
Olga Krishtal [Fri, 6 Feb 2015 17:59:53 +0000 (20:59 +0300)] 
utils: drop strtok_r from envlist_parse

The problem is that mingw 4.9.1 fails to compile the code with the
following warning:

/mingw/include/string.h:88:9: note: previous declaration of 'strtok_r'
was here
   char *strtok_r(char * __restrict__ _Str,
                  const char * __restrict__ _Delim,
                  char ** __restrict__ __last);
/include/sysemu/os-win32.h:83:7: warning: redundant redeclaration of
   'strtok_r' [-Wredundant-decls]
   char *strtok_r(char *str, const char *delim, char **saveptr);

The problem is that compiles just fine on previous versions of mingw.
Compiler version check here is not a good idea. Though fortunately
strtok_r is used only once in the code and we could simply rewrite
the code without it.

Signed-off-by: Olga Krishtal <okrishtal@parallels.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Eric Blake <eblake@redhat.com>
CC: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
9 years agoqga: add guest-set-user-password command
Daniel P. Berrange [Wed, 11 Feb 2015 11:26:12 +0000 (11:26 +0000)] 
qga: add guest-set-user-password command

Add a new 'guest-set-user-password' command for changing the password
of guest OS user accounts. This command is needed to enable OpenStack
to support its API for changing the admin password of guests running
on KVM/QEMU. It is not practical to provide a command at the QEMU
level explicitly targetting administrator account password change
only, since different guest OS have different names for the admin
account. While UNIX systems use 'root', Windows systems typically
use 'Administrator' and even that can be renamed. Higher level apps
like OpenStack have the ability to figure out the correct admin
account name since they have info that QEMU/libvirt do not.

The command accepts either the clear text password string, encoded
in base64 to make it 8-bit safe in JSON:

$ echo -n "123456" | base64
MTIzNDU2
$ virsh -c qemu:///system  qemu-agent-command f21x86_64 \
   '{ "execute": "guest-set-user-password",
      "arguments": { "crypted": false,
                     "username": "root",
                     "password": "MTIzNDU2" } }'
  {"return":{}}

Or a password that has already been run though a crypt(3) like
algorithm appropriate for the guest, again then base64 encoded:

$ echo -n '$6$n01A2Tau$e...snip...DfMOP7of9AJ1I8q0' | base64
JDYkb...snip...YT2Ey
$ virsh -c qemu:///system  qemu-agent-command f21x86_64 \
   '{ "execute": "guest-set-user-password",
      "arguments": { "crypted": true,
                     "username": "root",
                     "password": "JDYkb...snip...YT2Ey" } }'

NB windows support is desirable, but not implemented in this
patch.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
9 years agoConvert ram_list to RCU
Mike Day [Thu, 5 Sep 2013 18:41:35 +0000 (14:41 -0400)] 
Convert ram_list to RCU

Allow "unlocked" reads of the ram_list by using an RCU-enabled QLIST.

The ramlist mutex is kept.  call_rcu callbacks are run with the iothread
lock taken, but that may change in the future.  Writers still take the
ramlist mutex, but they no longer need to assume that the iothread lock
is taken.

Readers of the list, instead, no longer require either the iothread
or ramlist mutex, but they need to use rcu_read_lock() and
rcu_read_unlock().

One place in arch_init.c was downgrading from write side to read side
like this:

    qemu_mutex_lock_iothread()
    qemu_mutex_lock_ramlist()
    ...
    qemu_mutex_unlock_iothread()
    ...
    qemu_mutex_unlock_ramlist()

and the equivalent idiom is:

    qemu_mutex_lock_ramlist()
    rcu_read_lock()
    ...
    qemu_mutex_unlock_ramlist()
    ...
    rcu_read_unlock()

Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Mike Day <ncmike@ncultra.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agoexec: convert ram_list to QLIST
Mike Day [Wed, 21 Jan 2015 12:45:24 +0000 (13:45 +0100)] 
exec: convert ram_list to QLIST

QLIST has RCU-friendly primitives, so switch to it.

Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Mike Day <ncmike@ncultra.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agocosmetic changes preparing for the following patches
Mike Day [Thu, 5 Sep 2013 18:41:35 +0000 (14:41 -0400)] 
cosmetic changes preparing for the following patches

Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Mike Day <ncmike@ncultra.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agoexec: protect mru_block with RCU
Paolo Bonzini [Mon, 9 Sep 2013 15:58:40 +0000 (17:58 +0200)] 
exec: protect mru_block with RCU

Hence, freeing a RAMBlock has to be switched to call_rcu.

Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agorcu: add g_free_rcu
Paolo Bonzini [Wed, 11 Feb 2015 14:00:12 +0000 (15:00 +0100)] 
rcu: add g_free_rcu

This simplifies calling g_free from an RCU callback.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agorcu: introduce RCU-enabled QLIST
Mike Day [Tue, 27 Aug 2013 15:38:45 +0000 (11:38 -0400)] 
rcu: introduce RCU-enabled QLIST

Add RCU-enabled variants on the existing bsd DQ facility. Each
operation has the same interface as the existing (non-RCU)
version. Also, each operation is implemented as macro.

Using the RCU-enabled QLIST, existing QLIST users will be able to
convert to RCU without using a different list interface.

Signed-off-by: Mike Day <ncmike@ncultra.org>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agoexec: RCUify AddressSpaceDispatch
Paolo Bonzini [Wed, 21 Jan 2015 11:09:14 +0000 (12:09 +0100)] 
exec: RCUify AddressSpaceDispatch

Note that even after this patch, most callers of address_space_*
functions must still be under the big QEMU lock, otherwise the memory
region returned by address_space_translate can disappear as soon as
address_space_translate returns.  This will be fixed in the next part
of this series.

Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agoexec: make iotlb RCU-friendly
Paolo Bonzini [Fri, 16 Aug 2013 06:26:30 +0000 (08:26 +0200)] 
exec: make iotlb RCU-friendly

After the previous patch, TLBs will be flushed on every change to
the memory mapping.  This patch augments that with synchronization
of the MemoryRegionSections referred to in the iotlb array.

With this change, it is guaranteed that iotlb_to_region will access
the correct memory map, even once the TLB will be accessed outside
the BQL.

Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agoexec: introduce cpu_reload_memory_map
Paolo Bonzini [Thu, 15 Jan 2015 11:46:47 +0000 (12:46 +0100)] 
exec: introduce cpu_reload_memory_map

This for now is a simple TLB flush.  This can change later for two
reasons:

1) an AddressSpaceDispatch will be cached in the CPUState object

2) it will not be possible to do tlb_flush once the TCG-generated code
runs outside the BQL.

Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agodocs: clarify memory region lifecycle
Paolo Bonzini [Fri, 13 Feb 2015 12:42:03 +0000 (13:42 +0100)] 
docs: clarify memory region lifecycle

Now that objects actually obey the rules, document them.

Reviewed-by: Matthew Rosato <mjrosato@linux.vnet.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agopci: split shpc_cleanup and shpc_free
Paolo Bonzini [Thu, 12 Feb 2015 20:39:20 +0000 (21:39 +0100)] 
pci: split shpc_cleanup and shpc_free

object_unparent should not be called until the parent device is going to be
destroyed.  Only remove the capability and do memory_region_del_subregion
at unrealize time.  Freeing the data structures is left in shpc_free, to
be called from the instance_finalize callback.

Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.vnet.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agopcie: remove mmconfig memory leak and wrap mmconfig update with transaction
Paolo Bonzini [Wed, 28 Jan 2015 10:18:58 +0000 (11:18 +0100)] 
pcie: remove mmconfig memory leak and wrap mmconfig update with transaction

This memory leak was introduced inadvertently by omitting object_unparent.
A better fix is to use the new memory_region_set_size instead of destroying
and recreating the MMIO region on the fly.

Also, ensure that unmapping and remapping the region is done atomically.

Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9 years agoblock: Keep bdrv_check*_request()'s return value
Max Reitz [Thu, 5 Feb 2015 18:58:25 +0000 (13:58 -0500)] 
block: Keep bdrv_check*_request()'s return value

Do not throw away the value returned by bdrv_check_request() and
bdrv_check_byte_request().

Fix up some coding style issues in the proximity of the affected hunks.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-id: 1423162705-32065-17-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoblock: Remove "growable" from BDS
Max Reitz [Thu, 5 Feb 2015 18:58:24 +0000 (13:58 -0500)] 
block: Remove "growable" from BDS

Now that request clamping is done in the BlockBackend, the "growable"
field can be removed from the BlockDriverState. All BDSs are now treated
as being "growable" (that is, they are allowed to grow; they are not
necessarily actually able to).

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423162705-32065-16-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoblock: Clamp BlockBackend requests
Max Reitz [Thu, 5 Feb 2015 18:58:23 +0000 (13:58 -0500)] 
block: Clamp BlockBackend requests

BlockBackend is used as the interface between the block layer and guest
devices. It should therefore assure that all requests are clamped to the
image size.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-id: 1423162705-32065-15-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqemu-io: Use BlockBackend
Max Reitz [Thu, 5 Feb 2015 18:58:22 +0000 (13:58 -0500)] 
qemu-io: Use BlockBackend

qemu-io should behave like a guest, therefore it should use BlockBackend
to access the block layer.

There are a couple of places where that is infeasible: First, the
bdrv_debug_* functions could theoretically be mirrored in the
BlockBackend, but since these are functions internal to the block layer,
they should not be visible externally (qemu-io as a test tool is exempt
from this).

Second, bdrv_get_info() and bdrv_get_specific_info() work on a single
BDS alone, therefore they should stay BDS-specific.

Third, bdrv_is_allocated() mainly works on a single BDS as well. Some
data may be passed through from the BDS's file (if sectors which are
apparently allocated in the file are not really allocated there but just
zero).

[Fixed conflicts around block_acct_start() usage from Fam Zheng's
"qemu-io: Account IO by aio_read and aio_write" commit.  Use
BlockBackend and blk_get_stats() instead of BlockDriverState.
--Stefan]

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423162705-32065-14-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqemu-io: Remove "growable" option
Max Reitz [Thu, 5 Feb 2015 18:58:21 +0000 (13:58 -0500)] 
qemu-io: Remove "growable" option

Remove "growable" option from the "open" command and from the qemu-io
command line. qemu-io is about to be converted to BlockBackend which
will make sure that no request exceeds the image size, so the only way
to keep "growable" would be to use BlockBackend if it is not given and
to directly access the BDS if it is.

qemu-io is a debugging tool, therefore removing a rarely used option
will have only a very small impact, if any. There was only one
qemu-iotest which used the option; since it is not critical, this patch
just removes it.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423162705-32065-13-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqemu-io: Use blk_new_open() in openfile()
Max Reitz [Thu, 5 Feb 2015 18:58:20 +0000 (13:58 -0500)] 
qemu-io: Use blk_new_open() in openfile()

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423162705-32065-12-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqemu-nbd: Use blk_new_open() in main()
Max Reitz [Thu, 5 Feb 2015 18:58:19 +0000 (13:58 -0500)] 
qemu-nbd: Use blk_new_open() in main()

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-id: 1423162705-32065-11-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqemu-img: Use BlockBackend as far as possible
Max Reitz [Thu, 5 Feb 2015 18:58:18 +0000 (13:58 -0500)] 
qemu-img: Use BlockBackend as far as possible

Although qemu-img already creates BlockBackends, it does not do accesses
to the images through them. This patch converts all of the bdrv_* calls
for which this is currently possible to blk_* calls. Most of the
remaining calls will probably stay bdrv_* calls because they really do
operate on the BDS level instead of the BB level.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423162705-32065-10-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqemu-img: Use blk_new_open() in img_rebase()
Max Reitz [Thu, 5 Feb 2015 18:58:17 +0000 (13:58 -0500)] 
qemu-img: Use blk_new_open() in img_rebase()

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423162705-32065-9-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqemu-img: Use blk_new_open() in img_open()
Max Reitz [Thu, 5 Feb 2015 18:58:16 +0000 (13:58 -0500)] 
qemu-img: Use blk_new_open() in img_open()

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423162705-32065-8-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoblock/xen: Use blk_new_open() in blk_connect()
Max Reitz [Thu, 5 Feb 2015 18:58:15 +0000 (13:58 -0500)] 
block/xen: Use blk_new_open() in blk_connect()

As part of the required changes, this fixes a bug where specifying an
invalid driver would result in the block layer probing the image format;
now it will result in an error, unless "<unset>" is specified as the
driver name. Fixing this would require further work on the xen_disk code
which does not seem worth it (at this point and for this patch).

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423162705-32065-7-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoblockdev: Use blk_new_open() in blockdev_init()
Max Reitz [Thu, 5 Feb 2015 18:58:14 +0000 (13:58 -0500)] 
blockdev: Use blk_new_open() in blockdev_init()

Due to different error propagation, this breaks tests 051 and 087; fix
their output.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423162705-32065-6-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoiotests: Add test for driver=qcow2, format=qcow2
Max Reitz [Thu, 5 Feb 2015 18:58:13 +0000 (13:58 -0500)] 
iotests: Add test for driver=qcow2, format=qcow2

While specifying a different driver and format is obviously invalid,
specifying the same driver once through driver and once through format
is invalid as well. Add a test for it.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423162705-32065-5-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoblock: Add Error parameter to bdrv_find_protocol()
Max Reitz [Thu, 5 Feb 2015 18:58:12 +0000 (13:58 -0500)] 
block: Add Error parameter to bdrv_find_protocol()

The argument given to bdrv_find_protocol() is just a file name, which
makes it difficult for the caller to reconstruct what protocol
bdrv_find_protocol() was hoping to find. This patch adds an Error
parameter to that function to solve this issue.

Suggested-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423162705-32065-4-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoblock: Add blk_new_open()
Max Reitz [Thu, 5 Feb 2015 18:58:11 +0000 (13:58 -0500)] 
block: Add blk_new_open()

blk_new_with_bs() creates a BlockBackend with an empty BlockDriverState
attached to it. Empty BDSs are not nice, therefore add an alternative
function which combines blk_new_with_bs() with bdrv_open().

Note: In contrast to bdrv_open() which takes a BlockDriver parameter,
blk_new_open() does not take such a parameter. This is because
bdrv_open() opens a BlockDriverState, therefore it is natural to be able
to set the BlockDriver for that BDS. The fact that bdrv_open() can open
more than a single BDS is merely some form of a byproduct.

blk_new_open() on the other hand is intended to be used to create a
whole tree of BlockDriverStates. Therefore, setting a single BlockDriver
does not make much sense. Instead, the drivers to be used for each of
the nodes must be configured through the "options" QDict; including the
driver of the root BDS.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-id: 1423162705-32065-3-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoblock: Lift some BDS functions to the BlockBackend
Max Reitz [Thu, 5 Feb 2015 18:58:10 +0000 (13:58 -0500)] 
block: Lift some BDS functions to the BlockBackend

Create the blk_* counterparts for the following bdrv_* functions (which
make sense to call on the BlockBackend level):
- bdrv_co_write_zeroes()
- bdrv_write_compressed()
- bdrv_truncate()
- bdrv_nb_sectors()
- bdrv_discard()
- bdrv_load_vmstate()
- bdrv_save_vmstate()

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423162705-32065-2-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoiotests: Add test for qemu-img convert to NBD
Max Reitz [Wed, 11 Feb 2015 14:58:47 +0000 (09:58 -0500)] 
iotests: Add test for qemu-img convert to NBD

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423666727-20777-3-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqemu-img: Fix qemu-img convert -n
Max Reitz [Wed, 11 Feb 2015 14:58:46 +0000 (09:58 -0500)] 
qemu-img: Fix qemu-img convert -n

If -n is specified, it does not matter whether the output format and
protocol support image creation; building the creation options should
simply be skipped.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423666727-20777-2-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqemu-iotests: Add 093 for IO throttling
Fam Zheng [Fri, 30 Jan 2015 02:49:46 +0000 (10:49 +0800)] 
qemu-iotests: Add 093 for IO throttling

This case utilizes qemu-io command "aio_{read,write} -q" to verify the
effectiveness of IO throttling options.

It's implemented by driving the vm timer from qtest protocol, so the
throttling timers are signaled with determinied time duration. Then we
verify the completed IO requests are within 10% error of bps and iops
limits.

"null" protocol is used as the disk backend so that no actual disk IO is
performed on host, this will make the blockstats much more
deterministic. Both "null-aio" and "null-co" are covered, which is also
a simple cross validation test for the driver code.

Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 1422586186-9925-6-git-send-email-famz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqemu-iotests: Allow caller to disable underscore convertion for qmp
Fam Zheng [Fri, 30 Jan 2015 02:49:45 +0000 (10:49 +0800)] 
qemu-iotests: Allow caller to disable underscore convertion for qmp

QMP command "block_set_io_throttle" expects underscores in parameters
instead of dashes: {iops,bps}_{rd,wr,max}.

Add optional argument conv_keys (defaults to True, backward compatible),
it will be used in IO throttling test case.

Reviewed-by: Benoit Canet <benoit@irqsave.net>
Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 1422586186-9925-5-git-send-email-famz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqemu-iotests: Add VM method qtest() to iotests.py
Fam Zheng [Fri, 30 Jan 2015 02:49:44 +0000 (10:49 +0800)] 
qemu-iotests: Add VM method qtest() to iotests.py

This will allow test cases to run command in qtest protocol. It's
write-only for now.

Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 1422586186-9925-4-git-send-email-famz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqtest: Add scripts/qtest.py
Fam Zheng [Fri, 30 Jan 2015 02:49:43 +0000 (10:49 +0800)] 
qtest: Add scripts/qtest.py

This adds scripts/qtest.py as a python library for qtest protocol.

This is a skeleton with a basic "cmd" method to execute a command,
reading and parsing of qtest output could be added later on demand.

Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 1422586186-9925-3-git-send-email-famz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqemu-io: Account IO by aio_read and aio_write
Fam Zheng [Fri, 30 Jan 2015 02:49:42 +0000 (10:49 +0800)] 
qemu-io: Account IO by aio_read and aio_write

This will enable accounting of aio requests issued from qemu-io aio
read/write commands.

Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 1422586186-9925-2-git-send-email-famz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqtest: Fix deadloop by running main loop AIO context's timers
Fam Zheng [Mon, 19 Jan 2015 09:51:43 +0000 (17:51 +0800)] 
qtest: Fix deadloop by running main loop AIO context's timers

qemu_clock_run_timers() only takes care of main_loop_tlg, we shouldn't
forget aio timer list groups.

Currently, the qemu_clock_deadline_ns_all (a few lines above) counts all
the timergroups of this clock type, including aio tlg, but we don't fire
them, so they are never cleared, which makes a dead loop.

For example, this function hangs when trying to drive throttled block
request queue with qtest clock_step.

Signed-off-by: Fam Zheng <famz@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1421661103-29153-1-git-send-email-famz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoblock: vmdk - fixed sizeof() error
Jeff Cody [Tue, 10 Feb 2015 18:22:56 +0000 (13:22 -0500)] 
block: vmdk - fixed sizeof() error

The size compared should be PATH_MAX, rather than sizeof(char *).

Reported-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jeff Cody <jcody@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 46d873261433f4527e88885582f96942d61758d6.1423592487.git.jcody@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agosavevm: Improve error message for blocked migration
Kevin Wolf [Tue, 10 Feb 2015 13:25:02 +0000 (14:25 +0100)] 
savevm: Improve error message for blocked migration

If an internal snapshot can't be saved because migration is blocked
(most commonly probably because of AHCI), we had a really bad error
message:

$ echo -e "savevm foo\nquit" | qemu -M q35 /tmp/test.qcow2 -monitor stdio
QEMU 2.2.50 monitor - type 'help' for more information
(qemu) savevm foo
Error -22 while writing VM
(qemu) quit

This patch converts qemu_savevm_state() to the Error infrastructure so
that a useful error pointing to the problematic device is produced now:

$ echo -e "savevm foo\nquit" | qemu -M q35 /tmp/test.qcow2 -monitor stdio
QEMU 2.2.50 monitor - type 'help' for more information
(qemu) savevm foo
State blocked by non-migratable device '0000:00:1f.2/ich9_ahci'
(qemu) quit

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1423574702-23072-1-git-send-email-kwolf@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agonbd: fix the co_queue multi-adding bug
Bin Wu [Tue, 10 Feb 2015 07:20:46 +0000 (15:20 +0800)] 
nbd: fix the co_queue multi-adding bug

When we tested the VM migartion between different hosts with NBD
devices, we found if we sent a cancel command after the drive_mirror
was just started, a coroutine re-enter error would occur. The stack
was as follow:

(gdb) bt
00)  0x00007fdfc744d885 in raise () from /lib64/libc.so.6
01)  0x00007fdfc744ee61 in abort () from /lib64/libc.so.6
02)  0x00007fdfca467cc5 in qemu_coroutine_enter (co=0x7fdfcaedb400, opaque=0x0)
at qemu-coroutine.c:118
03)  0x00007fdfca467f6c in qemu_co_queue_run_restart (co=0x7fdfcaedb400) at
qemu-coroutine-lock.c:59
04)  0x00007fdfca467be5 in coroutine_swap (from=0x7fdfcaf3c4e8,
to=0x7fdfcaedb400) at qemu-coroutine.c:96
05)  0x00007fdfca467cea in qemu_coroutine_enter (co=0x7fdfcaedb400, opaque=0x0)
at qemu-coroutine.c:123
06)  0x00007fdfca467f6c in qemu_co_queue_run_restart (co=0x7fdfcaedbdc0) at
qemu-coroutine-lock.c:59
07)  0x00007fdfca467be5 in coroutine_swap (from=0x7fdfcaf3c4e8,
to=0x7fdfcaedbdc0) at qemu-coroutine.c:96
08)  0x00007fdfca467cea in qemu_coroutine_enter (co=0x7fdfcaedbdc0, opaque=0x0)
at qemu-coroutine.c:123
09)  0x00007fdfca4a1fa4 in nbd_recv_coroutines_enter_all (s=0x7fdfcaef7dd0) at
block/nbd-client.c:41
10) 0x00007fdfca4a1ff9 in nbd_teardown_connection (client=0x7fdfcaef7dd0) at
block/nbd-client.c:50
11) 0x00007fdfca4a20f0 in nbd_reply_ready (opaque=0x7fdfcaef7dd0) at
block/nbd-client.c:92
12) 0x00007fdfca45ed80 in aio_dispatch (ctx=0x7fdfcae15e90) at aio-posix.c:144
13) 0x00007fdfca45ef1b in aio_poll (ctx=0x7fdfcae15e90, blocking=false) at
aio-posix.c:222
14) 0x00007fdfca448c34 in aio_ctx_dispatch (source=0x7fdfcae15e90, callback=0x0,
user_data=0x0) at async.c:212
15) 0x00007fdfc8f2f69a in g_main_context_dispatch () from
/usr/lib64/libglib-2.0.so.0
16) 0x00007fdfca45c391 in glib_pollfds_poll () at main-loop.c:190
17) 0x00007fdfca45c489 in os_host_main_loop_wait (timeout=1483677098) at
main-loop.c:235
18) 0x00007fdfca45c57b in main_loop_wait (nonblocking=0) at main-loop.c:484
19) 0x00007fdfca25f403 in main_loop () at vl.c:2249
20) 0x00007fdfca266fc2 in main (argc=42, argv=0x7ffff517d638,
envp=0x7ffff517d790) at vl.c:4814

We find the nbd_recv_coroutines_enter_all function (triggered by a cancel
command or a network connection breaking down) will enter a coroutine which
is waiting for the sending lock. If the lock is still held by another coroutine,
the entering coroutine will be added into the co_queue again. Latter, when the
lock is released, a coroutine re-enter error will occur.

This bug can be fixed simply by delaying the setting of recv_coroutine as
suggested by paolo. After applying this patch, we have tested the cancel
operation in mirror phase looply for more than 5 hous and everything is fine.
Without this patch, a coroutine re-enter error will occur in 5 minutes.

Signed-off-by: Bn Wu <wu.wubin@huawei.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1423552846-3896-1-git-send-email-wu.wubin@huawei.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqtest/ahci: Adding simple dma read-write test
John Snow [Thu, 5 Feb 2015 17:41:30 +0000 (12:41 -0500)] 
qtest/ahci: Adding simple dma read-write test

Adds a test case for AHCI wherein we write a 4K
block of a changing pattern to sector 0, then
read back that 4K and compare the transmit and
receive buffers.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 1423158090-25580-20-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqtest/ahci: Assert sector size in identify test
John Snow [Thu, 5 Feb 2015 17:41:29 +0000 (12:41 -0500)] 
qtest/ahci: Assert sector size in identify test

A minor sanity check to assert that the sector size is 512.
The current block layer code deeply assumes that the IDE
sector size will be 512 bytes, so we carry forward that assumption
here.

This is useful for the DMA tests, which currently assume that
a sector will always be 512 bytes.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1423158090-25580-19-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agolibqos/ahci: Add ahci_clean_mem
John Snow [Thu, 5 Feb 2015 17:41:28 +0000 (12:41 -0500)] 
libqos/ahci: Add ahci_clean_mem

Clean up guest memory being used in ahci_clean_mem, to be
called during ahci_shutdown. With all guest memory leaks removed,
add an option to the allocator to throw an assertion if a leak
occurs.

This test adds some sanity to both the AHCI library and the
allocator.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1423158090-25580-18-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agolibqos/ahci: add ahci_io
John Snow [Thu, 5 Feb 2015 17:41:27 +0000 (12:41 -0500)] 
libqos/ahci: add ahci_io

ahci_io is a wrapper around ahci_guest_io that takes a pointer to host
memory instead, and will create a guest memory buffer and copy the data
to/from as needed and as appropriate for a read/write command, such that
after a read, the guest data will be in a host buffer, and for a write,
the data will be transmitted to guest memory prior to the block operation.

Now that we have all the syntactic sugar functions in place for AHCI,
we can convert the identify test to be very, very short.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1423158090-25580-17-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agolibqos/ahci: Add ahci_guest_io
John Snow [Thu, 5 Feb 2015 17:41:26 +0000 (12:41 -0500)] 
libqos/ahci: Add ahci_guest_io

ahci_guest_io is a shorthand function that will, in one shot,
execute a data command on the guest to the specified guest buffer
location, in the requested amount.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1423158090-25580-16-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agolibqos/ahci: add ahci command size setters
John Snow [Thu, 5 Feb 2015 17:41:25 +0000 (12:41 -0500)] 
libqos/ahci: add ahci command size setters

Adds setters for size, prd_size and both via set_sizes.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 1423158090-25580-15-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agolibqos/ahci: add ahci command verify
John Snow [Thu, 5 Feb 2015 17:41:24 +0000 (12:41 -0500)] 
libqos/ahci: add ahci command verify

Helps to verify that a command completed successfully.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1423158090-25580-14-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agolibqos/ahci: add ahci command functions
John Snow [Thu, 5 Feb 2015 17:41:23 +0000 (12:41 -0500)] 
libqos/ahci: add ahci command functions

This patch adds the AHCICommand structure, and a set of functions to
operate on the structure.

ahci_command_create - Initialize and create a new AHCICommand in memory
ahci_command_free - Destroy this object.
ahci_command_set_buffer - Set where the guest memory DMA buffer is.
ahci_command_commit - Write this command to the AHCI HBA.
ahci_command_issue - Issue the committed command synchronously.
ahci_command_issue_async - Issue the committed command asynchronously.
ahci_command_wait - Wait for an asynchronous command to finish.
ahci_command_slot - Get the number of the command slot we committed to.

Helpers:
size_to_prdtl       - Calculate the required minimum PRDTL size from
                      a buffer size.
ahci_command_find   - Given an ATA command mnemonic, look it up in the
                      properties table to obtain info about the command.
command_header_init - Initialize the command header with sane values.
command_table_init  - Initialize the command table with sane values.

[Peter Maydell <peter.maydell@linaro.org> reported the following clang
warning:

  tests/libqos/ahci.c:598:3: warning: redefinition
  of typedef 'AHCICommand' is a C11 feature
      [-Wtypedef-redefinition]
  } AHCICommand;

I have replaced typedef struct ... AHCICommand; with struct ... ;
--Stefan]

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 1423158090-25580-13-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agolibqos/ahci: Add ide cmd properties
John Snow [Thu, 5 Feb 2015 17:41:22 +0000 (12:41 -0500)] 
libqos/ahci: Add ide cmd properties

Add a structure that defines some properties of various IDE commands.
These will be used to simplify the interface to the libqos AHCI calls,
lessening the redundancy of specifying and respecifying properties of
commands to various helper functions.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 1423158090-25580-12-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqtest/ahci: add ahci_write_fis
John Snow [Thu, 5 Feb 2015 17:41:21 +0000 (12:41 -0500)] 
qtest/ahci: add ahci_write_fis

Similar to ahci_set_command_header, add a helper that takes an
in-memory representation of a command FIS and writes it to guest
memory, handling endianness as-needed.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 1423158090-25580-11-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agoqtest/ahci: Demagic ahci tests.
John Snow [Thu, 5 Feb 2015 17:41:20 +0000 (12:41 -0500)] 
qtest/ahci: Demagic ahci tests.

Add human-readable command names and other miscellaneous #defines
to help make the code more readable.

Some of these definitions are not yet used in this current series,
but for convenience and sanity they have been lumped together here,
as it's more trouble than it is worth in a test suite to hand-pick,
one-by-one, which preprocessor definitions are useful per-each test.

These definitions include:

ATA Command Mnemonics
Current expected AHCI sector size
FIS magic bytes
REG_H2D_FIS flags
Command Header flags

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 1423158090-25580-10-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agolibqos/ahci: Add cmd response sanity check helpers
John Snow [Thu, 5 Feb 2015 17:41:19 +0000 (12:41 -0500)] 
libqos/ahci: Add cmd response sanity check helpers

This patch adds a few helpers to help sanity-check the response of the
AHCI device after a command.

ahci_d2h_check_sanity inspects the D2H Register FIS,
ahci_pio_check_sanity inspects the PIO Setup FIS, and
ahci_cmd_check_sanity inspects the command header.

To support the PIO sanity check, a new structure is added for the
PIO Setup FIS type. Existing FIS types (H2D and D2H) have had their
members renamed slightly to condense reserved members into fewer
fields; and LBA fields are now represented by arrays of 8 byte chunks
instead of independent variables.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1423158090-25580-9-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agolibqos/ahci: Add port_check_nonbusy helper
John Snow [Thu, 5 Feb 2015 17:41:18 +0000 (12:41 -0500)] 
libqos/ahci: Add port_check_nonbusy helper

A simple helper that asserts a given port is not busy processing any
commands via the TFD, Command Issue and SACT registers.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1423158090-25580-8-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agolibqos/ahci: Add ahci_port_check_interrupts helper
John Snow [Thu, 5 Feb 2015 17:41:17 +0000 (12:41 -0500)] 
libqos/ahci: Add ahci_port_check_interrupts helper

A helper that compares a given port's current interrupts and checks them
against a supplied list of expected interrupt bits, and throws an error
if they do not match.

The helper then resets the requested interrupts on this port, and asserts
that the interrupt register is now empty.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1423158090-25580-7-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agolibqos/ahci: Add ahci_port_check_error helper
John Snow [Thu, 5 Feb 2015 17:41:16 +0000 (12:41 -0500)] 
libqos/ahci: Add ahci_port_check_error helper

ahci_port_check_error checks a given port's error registers and asserts
that everything from the port-level view is still OK.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1423158090-25580-6-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agolibqos/ahci: Add command header helpers
John Snow [Thu, 5 Feb 2015 17:41:15 +0000 (12:41 -0500)] 
libqos/ahci: Add command header helpers

Adds command header helper functions:
-ahci_command_header_set
-ahci_command_header_get,
-ahci_command_destroy, and
-ahci_cmd_pick

These helpers help to quickly manage the command header information in
the AHCI device.

ahci_command_header_set and get will store or retrieve an AHCI command
header, respectively.

ahci_cmd_pick chooses the first available but least recently used
command slot to allow us to cycle through the available command slots.

ahci_command_destroy obliterates all information contained within a
given slot's command header, and frees its associated command table,
but not its DMA buffer!

Lastly, the command table pointer fields (dba and dbau) are merged into
a single 64bit value to make managing 64bit tests simpler.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 1423158090-25580-5-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>