Skip to content
Snippets Groups Projects
  1. May 23, 2018
  2. May 04, 2018
  3. Mar 19, 2018
  4. Mar 09, 2018
  5. Mar 02, 2018
  6. Feb 09, 2018
  7. Dec 22, 2017
    • Kevin Wolf's avatar
      block: Keep nodes drained between reopen_queue/multiple · 1a63a907
      Kevin Wolf authored
      
      The bdrv_reopen*() implementation doesn't like it if the graph is
      changed between queuing nodes for reopen and actually reopening them
      (one of the reasons is that queuing can be recursive).
      
      So instead of draining the device only in bdrv_reopen_multiple(),
      require that callers already drained all affected nodes, and assert this
      in bdrv_reopen_queue().
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarFam Zheng <famz@redhat.com>
      1a63a907
    • Kevin Wolf's avatar
      block: Allow graph changes in subtree drained section · d736f119
      Kevin Wolf authored
      
      We need to remember how many of the drain sections in which a node is
      were recursive (i.e. subtree drain rather than node drain), so that they
      can be correctly applied when children are added or removed during the
      drained section.
      
      With this change, it is safe to modify the graph even inside a
      bdrv_subtree_drained_begin/end() section.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      d736f119
    • Kevin Wolf's avatar
      block: Don't notify parents in drain call chain · 0152bf40
      Kevin Wolf authored
      
      This is in preparation for subtree drains, i.e. drained sections that
      affect not only a single node, but recursively all child nodes, too.
      
      Calling the parent callbacks for drain is pointless when we just came
      from that parent node recursively and leads to multiple increases of
      bs->quiesce_counter in a single drain call. Don't do it.
      
      In order for this to work correctly, the parent callback must be called
      for every bdrv_drain_begin/end() call, not only for the outermost one:
      
      If we have a node N with two parents A and B, recursive draining of A
      should cause the quiesce_counter of B to increase because its child N is
      drained independently of B. If now B is recursively drained, too, A must
      increase its quiesce_counter because N is drained independently of A
      only now, even if N is going from quiesce_counter 1 to 2.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      0152bf40
    • Fam Zheng's avatar
      block: Open backing image in force share mode for size probe · cc954f01
      Fam Zheng authored
      
      Management tools create overlays of running guests with qemu-img:
      
        $ qemu-img create -b /image/in/use.qcow2 -f qcow2 /overlay/image.qcow2
      
      but this doesn't work anymore due to image locking:
      
          qemu-img: /overlay/image.qcow2: Failed to get shared "write" lock
          Is another process using the image?
          Could not open backing image to determine size.
      Use the force share option to allow this use case again.
      
      Cc: qemu-stable@nongnu.org
      Signed-off-by: default avatarFam Zheng <famz@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      cc954f01
    • Kevin Wolf's avatar
      block: Formats don't need CONSISTENT_READ with NO_IO · 5fbfabd3
      Kevin Wolf authored
      
      Commit 1f4ad7d3 fixed 'qemu-img info' for raw images that are currently
      in use as a mirror target. It is not enough for image formats, though,
      as these still unconditionally request BLK_PERM_CONSISTENT_READ.
      
      As this permission is geared towards whether the guest-visible data is
      consistent, and has no impact on whether the metadata is sane, and
      'qemu-img info' does not read guest-visible data (except for the raw
      format), it makes sense to not require BLK_PERM_CONSISTENT_READ if there
      is not going to be any guest I/O performed, regardless of image format.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      5fbfabd3
  8. Dec 19, 2017
    • Paolo Bonzini's avatar
      block: avoid recursive AioContext acquire in bdrv_inactivate_all() · bd6458e4
      Paolo Bonzini authored
      
      BDRV_POLL_WHILE() does not support recursive AioContext locking.  It
      only releases the AioContext lock once regardless of how many times the
      caller has acquired it.  This results in a hang since the IOThread does
      not make progress while the AioContext is still locked.
      
      The following steps trigger the hang:
      
        $ qemu-system-x86_64 -M accel=kvm -m 1G -cpu host \
                             -object iothread,id=iothread0 \
                             -device virtio-scsi-pci,iothread=iothread0 \
                             -drive if=none,id=drive0,file=test.img,format=raw \
                             -device scsi-hd,drive=drive0 \
                             -drive if=none,id=drive1,file=test.img,format=raw \
                             -device scsi-hd,drive=drive1
        $ qemu-system-x86_64 ...same options... \
                             -incoming tcp::1234
        (qemu) migrate tcp:127.0.0.1:1234
        ...hang...
      
      Tested-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-id: 20171207201320.19284-2-stefanha@redhat.com
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      bd6458e4
  9. Nov 21, 2017
    • Alberto Garcia's avatar
      block: Close a BlockDriverState completely even when bs->drv is NULL · 50a3efb0
      Alberto Garcia authored
      
      bdrv_close() skips much of its logic when bs->drv is NULL. This is
      fine when we're closing a BlockDriverState that has just been created
      (because e.g the initialization process failed), but it's not enough
      in other cases.
      
      For example, when a valid qcow2 image is found to be corrupted then
      QEMU marks it as such in the file header and then sets bs->drv to
      NULL in order to make the BlockDriverState unusable. When that BDS is
      later closed then many of its data structures are not freed (leaking
      their memory) and none of its children are detached. This results in
      bdrv_close_all() failing to close all BDSs and making this assertion
      fail when QEMU is being shut down:
      
         bdrv_close_all: Assertion `QTAILQ_EMPTY(&all_bdrv_states)' failed.
      
      This patch makes bdrv_close() do the full uninitialization process
      in all cases. This fixes the problem with corrupted images and still
      works fine with freshly created BDSs.
      
      Signed-off-by: default avatarAlberto Garcia <berto@igalia.com>
      Message-id: 20171106145345.12038-1-berto@igalia.com
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      50a3efb0
    • Kevin Wolf's avatar
      block: Don't use BLK_PERM_CONSISTENT_READ for format probing · dacaa162
      Kevin Wolf authored
      
      For format probing, we don't really care whether all of the image
      content is consistent. The only thing we're looking at is the image
      header, and specifically the magic numbers that are expected to never
      change, no matter how inconsistent the guest visible disk content is.
      
      Therefore, don't request BLK_PERM_CONSISTENT_READ. This allows to use
      format probing, e.g. in the context of 'qemu-img info', even while the
      guest visible data in the image is inconsistent during a running block
      job.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarFam Zheng <famz@redhat.com>
      dacaa162
  10. Nov 17, 2017
    • Hanna Reitz's avatar
      block: Make bdrv_next() keep strong references · 5e003f17
      Hanna Reitz authored
      
      On one hand, it is a good idea for bdrv_next() to return a strong
      reference because ideally nearly every pointer should be refcounted.
      This fixes intermittent failure of iotest 194.
      
      On the other, it is absolutely necessary for bdrv_next() itself to keep
      a strong reference to both the BB (in its first phase) and the BDS (at
      least in the second phase) because when called the next time, it will
      dereference those objects to get a link to the next one.  Therefore, it
      needs these objects to stay around until then.  Just storing the pointer
      to the next in the iterator is not really viable because that pointer
      might become invalid as well.
      
      Both arguments taken together means we should probably just invoke
      bdrv_ref() and blk_ref() in bdrv_next().  This means we have to assert
      that bdrv_next() is always called from the main loop, but that was
      probably necessary already before this patch and judging from the
      callers, it also looks to actually be the case.
      
      Keeping these strong references means however that callers need to give
      them up if they decide to abort the iteration early.  They can do so
      through the new bdrv_next_cleanup() function.
      
      Suggested-by: default avatarKevin Wolf <kwolf@redhat.com>
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      Message-id: 20171110172545.32609-1-mreitz@redhat.com
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      5e003f17
    • Hanna Reitz's avatar
      block: Guard against NULL bs->drv · d470ad42
      Hanna Reitz authored
      
      We currently do not guard everywhere against a NULL bs->drv where we
      should be doing so.  Most of the places fixed here just do not care
      about that case at all.
      
      Some care implicitly, e.g. through a prior function call to
      bdrv_getlength() which would always fail for an ejected BDS.  Add an
      assert there to make it more obvious.
      
      Other places seem to care, but do so insufficiently: Freeing clusters in
      a qcow2 image is an error-free operation, but it may leave the image in
      an unusable state anyway.  Giving qcow2_free_clusters() an error code is
      not really viable, it is much easier to note that bs->drv may be NULL
      even after a successful driver call.  This concerns bdrv_co_flush(), and
      the way the check is added to bdrv_co_pdiscard() (in every iteration
      instead of only once).
      
      Finally, some places employ at least an assert(bs->drv); somewhere, that
      may be reasonable (such as in the reopen code), but in
      bdrv_has_zero_init(), it is definitely not.  Returning 0 there in case
      of an ejected BDS saves us much headache instead.
      
      Reported-by: default avatarR. Nageswara Sastry <nasastry@in.ibm.com>
      Buglink: https://bugs.launchpad.net/qemu/+bug/1728660
      
      
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      Message-id: 20171110203111.7666-4-mreitz@redhat.com
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      d470ad42
    • Hanna Reitz's avatar
      block: qobject_is_equal() in bdrv_reopen_prepare() · 54fd1b0d
      Hanna Reitz authored
      
      Currently, bdrv_reopen_prepare() assumes that all BDS options are
      strings. However, this is not the case if the BDS has been created
      through the json: pseudo-protocol or blockdev-add.
      
      Note that the user-invokable reopen command is an HMP command, so you
      can only specify strings there. Therefore, specifying a non-string
      option with the "same" value as it was when originally created will now
      return an error because the values are supposedly similar (and there is
      no way for the user to circumvent this but to just not specify the
      option again -- however, this is still strictly better than just
      crashing).
      
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-id: 20171114180128.17076-5-mreitz@redhat.com
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      54fd1b0d
    • Kevin Wolf's avatar
      block: Fix permissions in image activation · dafe0960
      Kevin Wolf authored
      
      Inactive images generally request less permissions for their image files
      than they would if they were active (in particular, write permissions).
      Activating the image involves extending the permissions, therefore.
      
      drv->bdrv_invalidate_cache() can already require write access to the
      image file, so we have to update the permissions earlier than that.
      The current code does it only later, so we have to move up this part.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
      dafe0960
    • Kevin Wolf's avatar
      block: Deprecate bdrv_set_read_only() and users · 398e6ad0
      Kevin Wolf authored
      
      bdrv_set_read_only() is used by some block drivers to override the
      read-only option given by the user. This is not how read-only images
      generally work in QEMU: Instead of second guessing what the user really
      meant (which currently includes making an image read-only even if the
      user didn't only use the default, but explicitly said read-only=off), we
      should error out if we can't provide what the user requested.
      
      This adds deprecation warnings to all callers of bdrv_set_read_only() so
      that the behaviour can be corrected after the usual deprecation period.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      398e6ad0
    • Kevin Wolf's avatar
      block: Fix error path in bdrv_backing_update_filename() · 64730694
      Kevin Wolf authored
      
      error_setg_errno() takes a positive errno code. Spotted by Coverity
      (CID 1381628).
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarAlberto Garcia <berto@igalia.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      64730694
Loading