1. 20 Oct, 2014 4 commits
    • Markus Armbruster's avatar
      block: Make BlockBackend own its BlockDriverState · 9ba10c95
      Markus Armbruster authored
      On BlockBackend destruction, unref its BlockDriverState.  Replaces the
      callers' unrefs.
      
      This turns the pointer from BlockBackend to BlockDriverState into a
      strong reference, managed with bdrv_ref() / bdrv_unref().  The
      back-pointer remains weak.
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
      Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      9ba10c95
    • Markus Armbruster's avatar
      block: Connect BlockBackend to BlockDriverState · 7e7d56d9
      Markus Armbruster authored
      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: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      7e7d56d9
    • Markus Armbruster's avatar
      block: New BlockBackend · 26f54e9a
      Markus Armbruster authored
      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: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      26f54e9a
    • Markus Armbruster's avatar
      block: Split bdrv_new_root() off bdrv_new() · e4e9986b
      Markus Armbruster authored
      Creating an anonymous BDS can't fail.  Make that obvious.
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
      Reviewed-by: default avatarBenoît Canet <benoit.canet@nodalink.com>
      Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      e4e9986b
  2. 03 Oct, 2014 1 commit
  3. 25 Sep, 2014 1 commit
    • Kevin Wolf's avatar
      block: Validate node-name · 9aebf3b8
      Kevin Wolf authored
      The device_name of a BlockDriverState is currently checked because it is
      always used as a QemuOpts ID and qemu_opts_create() checks whether such
      IDs are wellformed.
      
      node-name is supposed to share the same namespace, but it isn't checked
      currently. This patch adds explicit checks both for device_name and
      node-name so that the same rules will still apply even if QemuOpts won't
      be used any more at some point.
      
      qemu-img used to use names with spaces in them, which isn't allowed any
      more. Replace them with underscores.
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      9aebf3b8
  4. 22 Sep, 2014 1 commit
    • Chrysostomos Nanakos's avatar
      async: aio_context_new(): Handle event_notifier_init failure · 2f78e491
      Chrysostomos Nanakos authored
      On a system with a low limit of open files the initialization
      of the event notifier could fail and QEMU exits without printing any
      error information to the user.
      
      The problem can be easily reproduced by enforcing a low limit of open
      files and start QEMU with enough I/O threads to hit this limit.
      
      The same problem raises, without the creation of I/O threads, while
      QEMU initializes the main event loop by enforcing an even lower limit of
      open files.
      
      This commit adds an error message on failure:
      
       # qemu [...] -object iothread,id=iothread0 -object iothread,id=iothread1
       qemu: Failed to initialize event notifier: Too many open files in system
      Signed-off-by: default avatarChrysostomos Nanakos <cnanakos@grnet.gr>
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      2f78e491
  5. 08 Sep, 2014 1 commit
  6. 29 Aug, 2014 3 commits
  7. 28 Aug, 2014 1 commit
  8. 22 Aug, 2014 2 commits
    • Max Reitz's avatar
      qemu-img: Allow cache mode specification for amend · bd39e6ed
      Max Reitz authored
      qemu-img amend may extensively modify the target image, depending on the
      options to be amended (e.g. conversion to qcow2 compat level 0.10 from
      1.1 for an image with many unallocated zero clusters). Therefore it
      makes sense to allow the user to specify the cache mode to be used.
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      bd39e6ed
    • Max Reitz's avatar
      qemu-img: Allow source cache mode specification · 40055951
      Max Reitz authored
      Many qemu-img subcommands only read the source file(s) once. For these
      use cases, a full write-back cache is unnecessary and mainly clutters
      host cache memory. Though this is generally no concern as cache memory
      is freely available and can be scaled by the host OS, it may become a
      concern with thin provisioning.
      
      For these cases, it makes sense to allow users to freely specify the
      source cache mode (e.g. use no cache at all).
      
      This commit adds a new switch (-T) for the qemu-img subcommands check,
      compare, convert and rebase to specify the cache to be used for source
      images (the backing file in case of rebase).
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      40055951
  9. 15 Aug, 2014 3 commits
  10. 08 Aug, 2014 1 commit
  11. 18 Jul, 2014 1 commit
  12. 16 Jun, 2014 2 commits
  13. 04 Jun, 2014 1 commit
  14. 02 Jun, 2014 1 commit
  15. 30 May, 2014 2 commits
  16. 19 May, 2014 1 commit
  17. 09 May, 2014 2 commits
  18. 29 Apr, 2014 1 commit
  19. 28 Apr, 2014 1 commit
  20. 25 Apr, 2014 1 commit
  21. 22 Apr, 2014 3 commits
    • Fam Zheng's avatar
      qemu-img: Improve error messages · ac1307ab
      Fam Zheng authored
      Previously, when there is a user error in argv parsing, qemu-img prints
      help text and exits.
      
      Add an error_exit function to print a helpful error message and a hint
      to run 'qemu-img --help' for more information.
      
      As a bonus, "qemu-img <cmd> --help" now has a more reasonable exit code
      0.
      
      In the future the help text should be split by sub command, and only
      print the information for the specified command.
      Signed-off-by: default avatarFam Zheng <famz@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      ac1307ab
    • Kevin Wolf's avatar
      qemu-img: Avoid duplicate block device IDs · 9ffe3332
      Kevin Wolf authored
      qemu-img used to use "image" as ID for all block devices. This means
      that e.g. img_convert() ended up with potentially multiple source images
      and one target image, all with the same ID. The next patch will catch
      this and fail to open the block device.
      
      This patch makes sure that qemu-img uses meaningful unique IDs for the
      block devices it uses.
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      9ffe3332
    • Kevin Wolf's avatar
      block: Add errp to bdrv_new() · 98522f63
      Kevin Wolf authored
      This patch adds an errp parameter to bdrv_new() and updates all its
      callers. The next patches will make use of this in order to check for
      duplicate IDs. Most of the callers know that their ID is fine, so they
      can simply assert that there is no error.
      
      Behaviour doesn't change with this patch yet as bdrv_new() doesn't
      actually assign errors to errp.
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      98522f63
  22. 01 Apr, 2014 1 commit
  23. 25 Mar, 2014 1 commit
  24. 05 Mar, 2014 1 commit
  25. 02 Mar, 2014 1 commit
  26. 21 Feb, 2014 2 commits