nbd: unlock mutex in nbd_co_send_request() error path

Cc: qemu-stable@nongnu.org
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
nbd: use TCP_CORK in nbd_co_send_request()

Use TCP_CORK to defer packet transmission until both the header and the
payload have been written.

Suggested-by: Nick Thomas <nick@bytemark.co.uk>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
nbd: set TCP_NODELAY

Disable the Nagle algorithm to reduce latency.  Note this means we must
also use TCP_CORK when sending header followed by payload to avoid
fragmenting lots of little packets.  The previous patch took care of
that.

Suggested-by: Nick Thomas <nick@bytemark.co.uk>
Tested-by: Nick Thomas <nick@bytemark.co.uk>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
scsi: avoid assertion failure on VERIFY command

A verify command is not an actual read (we do not implement
compare mode) and thus does not have an AIOCB attached.  Do
not crash in scsi_dma_complete.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
scsi: VMWare PVSCSI paravirtual device implementation

Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
Signed-off-by: Yan Vugenfirer <yan@daynix.com>
[ Rename files to vmw_pvscsi, fix setting of hostStatus in
  pvscsi_request_cancelled - Paolo ]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
vhost: Add vhost_commit callback for SeaBIOS ROM region re-mapping

This patch follows MST's recommendation to move checks for
vhost_verify_ring_mappings() -> cpu_physical_memory_map() operations
from MemoryListener->region_[add,del]() -> vhost_set_memory() into
final MemoryListener->commit() -> vhost_commit() callback.

It addresses the case where virtio-scsi vq ioport RAM re-mapping
to read-only SeaBIOS ROM triggers a cpu_physical_memory_map()
NIL MemoryRegionSection pointer failure.

Also save vhost_dev->mem_changed_[start,end]_addr values in
vhost_set_memory() for final ranges_overlap checks.  (Thanks Paolo!)

Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Asias He <asias@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
monitor: fix the wrong order of releasing keys

(qemu) sendkey ctrl_r-scroll_lock-scroll_lock

Executing this command could not let Windows guest panic, it caused by
the wrong order of releasing keys. This problem was introduced by
commit e4c8f004c55d9da3eae3e14df740238bf805b5d6.

The right release order should be starting from last item.

Signed-off-by: Amos Kong <akong@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
virtio-balloon: fix integer overflow in BALLOON_CHANGE QMP event

Because dev->actual is uint32_t, the expression 'dev->actual <<
VIRTIO_BALLOON_PFN_SHIFT' is truncated to 32 bits. This overflows when
dev->actual >= 1048576.

To reproduce:

 1. Start a VM with a QMP socket and 5G of RAM
 2. Connect to the QMP socket, negotiate capabilities and issue:

   { "execute":"balloon", "arguments": { "value": 1073741824 } }

 3. Watch for BALLOON_CHANGE QMP events, the last one will incorretly be:

   { "timestamp": { "seconds": 1366228965, "microseconds": 245466 },
     "event": "BALLOON_CHANGE", "data": { "actual": 5368709120 } }

To fix it this commit casts it to ram_addr_t, which is ram_size's type.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
virtio-scsi: create VirtIOSCSICommon

This patch refactors existing virtio-scsi code into VirtIOSCSICommon
in order to allow virtio_scsi_init_common() to be used by both internal
virtio_scsi_init() and external vhost-scsi-pci code.

Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Asias He <asias@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
virtio: simplify Makefile conditionals

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
vhost-scsi: new device supporting the tcm_vhost Linux kernel module

The WWPN specified in configfs is passed to "-device vhost-scsi-pci".
The tgpt field of the SET_ENDPOINT ioctl is obsolete now, so it is not
available from the QEMU command-line.  Instead, I hardcode it to zero.

Changes in Patch-v2:
   - Add vhost_scsi_get_features() in order to determine feature bits
     supports by host kernel (mst + nab)
   - Re-enable usage of DEFINE_VIRTIO_COMMON_FEATURES, and allow
     EVENT_IDX to be disabled by host in vhost_scsi_get_features()
   - Drop unused hotplug bit in DEFINE_VHOST_SCSI_PROPERTIES

Changes in Patch-v1:
   - Set event_idx=off by default (nab, thanks asias)
   - Disable hotplug feature bit for v3.9 tcm_vhost kernel code, need to
     re-enable in v3.10 (nab)
   - Update to latest qemu.git/master HEAD

Changes in WIP-V3:
   - Drop ioeventfd vhost_scsi_properties (asias, thanks stefanha)
   - Add CONFIG_VHOST_SCSI (asias, thanks stefanha)
   - Add hotplug feature bit

Changes in WIP-V2:
   - Add backend guest masking support (nab)
   - Bump ABI_VERSION to 1 (nab)
   - Set up set_guest_notifiers (asias)
   - Set up vs->dev.vq_index (asias)
   - Drop vs->vs.vdev.{set,clear}_vhost_endpoint (asias)
   - Drop VIRTIO_CONFIG_S_DRIVER check in vhost_scsi_set_status (asias)

Howto:
   Use the latest seabios, at least commit b44a7be17b
   git clone git://git.seabios.org/seabios.git
   make
   cp out/bios.bin /usr/share/qemu/bios.bin
   qemu -device vhost-scsi-pci,wwpn=naa.6001405bd4e8476d,event_idx=off
...

Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: Asias He <asias@redhat.com>
[ Rebase on top of VirtIOSCSICommon patch, fix bugs in feature
  negotiation and irqfd masking - Paolo ]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
vhost-scsi-pci: new device supporting the tcm_vhost Linux kernel module

Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: Asias He <asias@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
vhost-scsi-ccw: new device supporting the tcm_vhost Linux kernel module

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
vhost-scsi-s390: new device supporting the tcm_vhost Linux kernel module

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Asias He <asias@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qcow2: allow sub-cluster compressed write to last cluster

Compression in qcow2 requires image length to be a multiple of the
cluster size.  Lift this requirement by zero-padding the final cluster
when necessary.  The virtual disk size is still not cluster-aligned, so
the guest cannot access the zero sectors.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qcow: allow sub-cluster compressed write to last cluster

Compression in qcow requires image length to be a multiple of the
cluster size.  Lift this requirement by zero-padding the final cluster
when necessary.  The virtual disk size is still not cluster-aligned, so
the guest cannot access the zero sectors.

Note that this is almost identical to the qcow2 version of this code.
qcow2's compression code is drawn from qcow.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qemu-img: do not zero-pad the compressed write buffer

bdrv_write_compressed() does not allow requests that span the end of the
device.  Therefore it is useless to zero-pad the last cluster and
thereby exceed the end of the device.

Let image formats handle zero-padding the final compressed cluster, if
necessary.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qemu-iotests: Fix _filter_qemu

$QEMU_PROG happens to be 'qemu' in my setup, so this sed command
replaces a bit too much. Restrict it to the start of the line and to
when it's followed by a colon, i.e. the form used by error messages.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
block: Fail gracefully when using a format driver on protocol level

Specifying the wrong driver could fail an assertion:

$ qemu-system-x86_64 -drive file.driver=qcow2,file=x
qemu-system-x86_64: block.c:721: bdrv_open_common: Assertion `file !=
((void *)0)' failed.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: Add driver-specific options for backing files

Options starting in "backing." are passed to the backing file now. If
you don't need to specify the filename for the backing file, you can add
it on the command line instead of in the image file:

$ qemu-nbd -t /tmp/test.img
$ qemu-img create -f qcow2 empty.qcow2 1G
$ qemu-system-x86_64 -drive file=empty.qcow2,backing.file.driver=nbd,\
    backing.file.host=localhost

Note that this doesn't override the backing filename from the image. If
the image has one, this will fail because NBD doesn't want the options
and a filename at the same time.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>