mirror_qemu/include/qemu
Markus Armbruster 26f54e9a3c block: New BlockBackend
A block device consists of a frontend device model and a backend.

A block backend has a tree of block drivers doing the actual work.
The tree is managed by the block layer.

We currently use a single abstraction BlockDriverState both for tree
nodes and the backend as a whole.  Drawbacks:

* Its API includes both stuff that makes sense only at the block
  backend level (root of the tree) and stuff that's only for use
  within the block layer.  This makes the API bigger and more complex
  than necessary.  Moreover, it's not obvious which interfaces are
  meant for device models, and which really aren't.

* Since device models keep a reference to their backend, the backend
  object can't just be destroyed.  But for media change, we need to
  replace the tree.  Our solution is to make the BlockDriverState
  generic, with actual driver state in a separate object, pointed to
  by member opaque.  That lets us replace the tree by deinitializing
  and reinitializing its root.  This special need of the root makes
  the data structure awkward everywhere in the tree.

The general plan is to separate the APIs into "block backend", for use
by device models, monitor and whatever other code dealing with block
backends, and "block driver", for use by the block layer and whatever
other code (if any) dealing with trees and tree nodes.

Code dealing with block backends, device models in particular, should
become completely oblivious of BlockDriverState.  This should let us
clean up both APIs, and the tree data structures.

This commit is a first step.  It creates a minimal "block backend"
API: type BlockBackend and functions to create, destroy and find them.

BlockBackend objects are created and destroyed exactly when root
BlockDriverState objects are created and destroyed.  "Root" in the
sense of "in bdrv_states".  They're not yet used for anything; that'll
come shortly.

A root BlockDriverState is created with bdrv_new_root(), so where to
create a BlockBackend is obvious.  Where these roots get destroyed
isn't always as obvious.

It is obvious in qemu-img.c, qemu-io.c and qemu-nbd.c, and in error
paths of blockdev_init(), blk_connect().  That leaves destruction of
objects successfully created by blockdev_init() and blk_connect().

blockdev_init() is used only by drive_new() and qmp_blockdev_add().
Objects created by the latter are currently indestructible (see commit
48f364d "blockdev: Refuse to drive_del something added with
blockdev-add" and commit 2d246f0 "blockdev: Introduce
DriveInfo.enable_auto_del").  Objects created by the former get
destroyed by drive_del().

Objects created by blk_connect() get destroyed by blk_disconnect().

BlockBackend is reference-counted.  Its reference count never exceeds
one so far, but that's going to change.

In drive_del(), the BB's reference count is surely one now.  The BDS's
reference count is greater than one when something else is holding a
reference, such as a block job.  In this case, the BB is destroyed
right away, but the BDS lives on until all extra references get
dropped.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2014-10-20 13:41:26 +02:00
..
acl.h misc: move include files to include/qemu/ 2012-12-19 08:32:39 +01:00
aes.h include/qemu/aes.h: Avoid conflicts with FreeBSD AES functions 2014-06-19 16:13:38 +01:00
atomic.h atomic.h: Fix build with clang 2013-11-21 08:01:06 -08:00
bitmap.h util: introduce bitmap_try_new 2014-09-30 13:30:51 +02:00
bitops.h bitops: provide an inline implementation of find_first_bit 2014-06-18 18:10:47 +02:00
bswap.h bswap.h: Rename ldl_p, stl_p, etc to ldl_he_p, stl_he_p, etc 2014-05-24 00:07:29 +04:00
compatfd.h misc: move include files to include/qemu/ 2012-12-19 08:32:39 +01:00
compiler.h qemu/compiler: Define QEMU_ARTIFICIAL 2014-09-29 14:55:28 -04:00
config-file.h qemu-option: introduce qemu_find_opts_singleton 2014-04-27 13:04:18 +04:00
crc32c.h include/qemu/crc32c.h: Rename include guards to match filename 2014-02-26 17:20:07 +00:00
envlist.h misc: move include files to include/qemu/ 2012-12-19 08:32:39 +01:00
error-report.h qemu-error: Add error_vreport() 2014-10-09 15:36:15 +02:00
event_notifier.h misc: move include files to include/qemu/ 2012-12-19 08:32:39 +01:00
fifo8.h util/fifo8: implement push/pop of multiple bytes 2014-02-08 14:50:48 +00:00
hbitmap.h hbitmap: Use non-bitops ctzl 2013-02-16 11:11:34 +00:00
host-utils.h target-ppc: Add ISA2.06 divde[o] Instructions 2014-03-05 03:06:39 +01:00
int128.h int128: Add int128_exts64() 2014-05-30 13:00:28 -06:00
iov.h iov: add iov_discard_front/back() to remove data 2013-01-02 15:58:05 +01:00
log.h log: Change log_cpu_state[_mask]() argument to CPUState 2013-07-09 21:33:04 +02:00
main-loop.h async: aio_context_new(): Handle event_notifier_init failure 2014-09-22 11:39:48 +01:00
module.h module: implement module loading 2014-02-20 13:14:18 +01:00
notify.h notify: add NotiferWithReturn so notifier list can abort 2013-06-28 09:20:26 +02:00
option.h util: Emancipate id_wellformed() from QemuOpts 2014-10-03 10:30:33 +01:00
option_int.h QemuOpts: change opt->name|str from (const char *) to (char *) 2014-06-16 17:23:20 +08:00
osdep.h util: Move general qemu_getauxval to util/getauxval.c 2014-09-09 13:13:05 +02:00
queue.h misc: move include files to include/qemu/ 2012-12-19 08:32:39 +01:00
range.h Introduce signed range. 2014-06-19 18:44:19 +03:00
ratelimit.h aio / timers: Switch entire codebase to the new timer API 2013-08-22 19:14:24 +02:00
readline.h readline: Add missing GCC_FMT_ATTR 2014-02-01 13:46:06 +04:00
rfifolock.h rfifolock: add recursive FIFO lock 2014-03-13 14:42:21 +01:00
seqlock.h seqlock: introduce read-write seqlock 2013-10-17 17:24:15 +02:00
sockets.h qemu-sockets: Add error to non-blocking connect handler 2014-10-09 15:36:15 +02:00
thread-posix.h qemu-thread: add QemuEvent 2013-10-17 17:30:55 +02:00
thread-win32.h qemu-thread: add QemuEvent 2013-10-17 17:30:55 +02:00
thread.h Add a 'name' parameter to qemu_thread_create 2014-03-09 21:09:38 +02:00
throttle.h throttle: add throttle_detach/attach_aio_context() 2014-06-04 09:56:12 +02:00
timer.h cpu-exec: Add sleeping algorithm 2014-08-06 17:53:07 +02:00
tls.h misc: move include files to include/qemu/ 2012-12-19 08:32:39 +01:00
typedefs.h block: New BlockBackend 2014-10-20 13:41:26 +02:00
uri.h misc: move include files to include/qemu/ 2012-12-19 08:32:39 +01:00
xattr.h misc: move include files to include/qemu/ 2012-12-19 08:32:39 +01:00