[Spice-devel] [PATCH 00/21] RFCv2: add Spice block device

Marc-André Lureau marcandre.lureau at gmail.com
Mon Nov 18 04:25:10 PST 2013


Hi,

The following patch series implement a Spice block device, which
allows the client to redirect a block device using the NBD protocol,
which greatly simplifies the Spice code by reusing an existing
protocol, and allows sharing existing qemu NBD implementation.

The backend only support read-only device atm (although it shouldn't
be hard to add write support if necessary)

Usage with a CDROM drive:
 -device ide-cd,drive=cd -drive if=none,id=cd,readonly,file=spicebd:

The associated server and client bits are:
http://lists.freedesktop.org/archives/spice-devel/2013-June/013608.html
http://lists.freedesktop.org/archives/spice-devel/2013-November/015452.html
http://lists.freedesktop.org/archives/spice-devel/2013-November/015431.html

Caveats: This block device driver is a bit special, since it is
successfully initialized with size 0, and once the client is connected
(or want to change block device) it re-opens itself. For this to work,
we allow a block driver to be open with an existing opaque data. We
also save the associate device name in the block drivers.

During migration, the source needs to be able to flush pending
operations, so the Spice channel context must be in a running loop. A
modification to the Spice server API allows to associate a particular
channel with the AIO loop, and may be used in the future to associate
channels with different context or athreads. However, the AIO context
doesn't have timers yet. Since they aren't really needed for the NBD
channel, it's not a problem. I have been told timers in AIO are on
their way, so this could be updated later.

Since the block driver state is not migrated, the destination needs to
wait until the block driver is initialized before the VM can run. This
is done with a simple hold count. It is also necessary to avoid extra
media changed notifications, which is easily done by checking
migration state.


Marc-André Lureau (21):
  vscclient: do not add a socket watch if there is not data to send
  spice-char: remove unused field
  qmp_change_blockdev() remove unused has_format
  include: add missing config-host.h include
  char: add qemu_chr_fe_event()
  Split nbd block client code
  nbd: don't change socket block during negotiate
  nbd: pass export name as init argument
  nbd: make session_close() idempotent
  nbd: finish any pending coroutine
  nbd: avoid uninitialized warnings
  block: save the associated child name in BlockDriverState
  blockdev: add qmp_change_blockdev_int()
  block: extract make_snapshot() from bdrv_open()
  block: add "snapshot.size" option to avoid extra bdrv_open()
  block: learn to open a driver with a given opaque
  block: allow to call bdrv_open() with an opaque
  block: do not notify change during migration
  sysemu: add vm_start_hold/release
  spice-core: allow an interface to be in AIO context
  block: add spice block device backend

 block.c                   | 225 ++++++++++++-------
 block/Makefile.objs       |   3 +-
 block/nbd-client.c        | 384 +++++++++++++++++++++++++++++++++
 block/nbd-client.h        |  50 +++++
 block/nbd.c               | 380 +++-----------------------------
 block/spicebd.c           | 536 ++++++++++++++++++++++++++++++++++++++++++++++
 blockdev.c                |  24 ++-
 hw/block/fdc.c            |   8 +-
 hw/ide/core.c             |  12 +-
 hw/scsi/scsi-disk.c       |  11 +-
 hw/sd/sd.c                |   6 +-
 include/block/block.h     |   2 +-
 include/block/block_int.h |   1 +
 include/sysemu/blockdev.h |   5 +-
 include/sysemu/char.h     |  10 +
 include/sysemu/sysemu.h   |   2 +
 include/ui/qemu-spice.h   |   4 +-
 libcacard/vscclient.c     |  10 +-
 nbd.c                     |   1 -
 qemu-char.c               |   9 +-
 qmp.c                     |   2 +-
 spice-qemu-char.c         |  20 +-
 stubs/vm-stop.c           |   5 +
 ui/spice-core.c           |  62 +++++-
 vl.c                      |  17 ++
 25 files changed, 1320 insertions(+), 469 deletions(-)
 create mode 100644 block/nbd-client.c
 create mode 100644 block/nbd-client.h
 create mode 100644 block/spicebd.c

-- 
1.8.3.1



More information about the Spice-devel mailing list