You need to sign in or sign up before continuing.
  1. 16 2月, 2015 2 次提交
    • M
      block: Add blk_new_open() · ca49a4fd
      Max Reitz 提交于
      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: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NKevin Wolf <kwolf@redhat.com>
      Message-id: 1423162705-32065-3-git-send-email-mreitz@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      ca49a4fd
    • M
      block: Lift some BDS functions to the BlockBackend · 1ef01253
      Max Reitz 提交于
      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: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-id: 1423162705-32065-2-git-send-email-mreitz@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      1ef01253
  2. 07 2月, 2015 1 次提交
  3. 10 12月, 2014 3 次提交
  4. 20 10月, 2014 4 次提交
    • M
      block: Lift device model API into BlockBackend · a7f53e26
      Markus Armbruster 提交于
      Move device model attachment / detachment and the BlockDevOps device
      model callbacks and their wrappers from BlockDriverState to
      BlockBackend.
      
      Wrapper calls in block.c change from
      
          bdrv_dev_FOO_cb(bs, ...)
      
      to
      
          if (bs->blk) {
              bdrv_dev_FOO_cb(bs->blk, ...);
          }
      
      No change, because both bdrv_dev_change_media_cb() and
      bdrv_dev_resize_cb() do nothing when no device model is attached, and
      a device model can be attached only when bs->blk.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NKevin Wolf <kwolf@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      a7f53e26
    • M
      hw: Convert from BlockDriverState to BlockBackend, mostly · 4be74634
      Markus Armbruster 提交于
      Device models should access their block backends only through the
      block-backend.h API.  Convert them, and drop direct includes of
      inappropriate headers.
      
      Just four uses of BlockDriverState are left:
      
      * The Xen paravirtual block device backend (xen_disk.c) opens images
        itself when set up via xenbus, bypassing blockdev.c.  I figure it
        should go through qmp_blockdev_add() instead.
      
      * Device model "usb-storage" prompts for keys.  No other device model
        does, and this one probably shouldn't do it, either.
      
      * ide_issue_trim_cb() uses bdrv_aio_discard() instead of
        blk_aio_discard() because it fishes its backend out of a BlockAIOCB,
        which has only the BlockDriverState.
      
      * PC87312State has an unused BlockDriverState[] member.
      
      The next two commits take care of the latter two.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      4be74634
    • M
      block: Connect BlockBackend to BlockDriverState · 7e7d56d9
      Markus Armbruster 提交于
      Convenience function blk_new_with_bs() creates a BlockBackend with its
      BlockDriverState.  Callers have to unref both.  The commit after next
      will relieve them of the need to unref the BlockDriverState.
      
      Complication: due to the silly way drive_del works, we need a way to
      hide a BlockBackend, just like bdrv_make_anon().  To emphasize its
      "special" status, give the function a suitably off-putting name:
      blk_hide_on_behalf_of_do_drive_del().  Unfortunately, hiding turns the
      BlockBackend's name into the empty string.  Can't avoid that without
      breaking the blk->bs->device_name equals blk->name invariant.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      7e7d56d9
    • M
      block: New BlockBackend · 26f54e9a
      Markus Armbruster 提交于
      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
      48f364dd "blockdev: Refuse to drive_del something added with
      blockdev-add" and commit 2d246f01 "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: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      26f54e9a