1. 31 1月, 2020 1 次提交
  2. 06 1月, 2020 2 次提交
    • M
      block: Use bdrv_qapi_perm_to_blk_perm() · cdb1cec8
      Max Reitz 提交于
      We can save some LoC in xdbg_graph_add_edge() by using
      bdrv_qapi_perm_to_blk_perm().
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20191108123455.39445-3-mreitz@redhat.com
      Reviewed-by: NVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      cdb1cec8
    • M
      block: Add bdrv_qapi_perm_to_blk_perm() · 7b1d9c4d
      Max Reitz 提交于
      We need some way to correlate QAPI BlockPermission values with
      BLK_PERM_* flags.  We could:
      
      (1) have the same order in the QAPI definition as the the BLK_PERM_*
          flags are in LSb-first order.  However, then there is no guarantee
          that they actually match (e.g. when someone modifies the QAPI schema
          without thinking of the BLK_PERM_* definitions).
          We could add static assertions, but these would break what’s good
          about this solution, namely its simplicity.
      
      (2) define the BLK_PERM_* flags based on the BlockPermission values.
          But this way whenever someone were to modify the QAPI order
          (perfectly sensible in theory), the BLK_PERM_* values would change.
          Because these values are used for file locking, this might break
          file locking between different qemu versions.
      
      Therefore, go the slightly more cumbersome way: Add a function to
      translate from the QAPI constants to the BLK_PERM_* flags.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20191108123455.39445-2-mreitz@redhat.com
      Reviewed-by: NVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      7b1d9c4d
  3. 20 12月, 2019 1 次提交
    • K
      block: Activate recursively even for already active nodes · 7bb4941a
      Kevin Wolf 提交于
      bdrv_invalidate_cache_all() assumes that all nodes in a given subtree
      are either active or inactive when it starts. Therefore, as soon as it
      arrives at an already active node, it stops.
      
      However, this assumption is wrong. For example, it's possible to take a
      snapshot of an inactive node, which results in an active overlay over an
      inactive backing file. The active overlay is probably also the root node
      of an inactive BlockBackend (blk->disable_perm == true).
      
      In this case, bdrv_invalidate_cache_all() does not need to do anything
      to activate the overlay node, but it still needs to recurse into the
      children and the parents to make sure that after returning success,
      really everything is activated.
      
      Cc: qemu-stable@nongnu.org
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      7bb4941a
  4. 18 12月, 2019 1 次提交
  5. 19 11月, 2019 1 次提交
    • K
      block: Remove 'backing': null from bs->{explicit_,}options · ae0f57f0
      Kevin Wolf 提交于
      bs->options and bs->explicit_options shouldn't contain any options for
      child nodes. bdrv_open_inherited() takes care to remove any options that
      match a child name after opening the image and the same is done when
      reopening.
      
      However, we miss the case of 'backing': null, which is a child option,
      but results in no child being created. This means that a 'backing': null
      remains in bs->options and bs->explicit_options.
      
      A typical use for 'backing': null is in live snapshots: blockdev-add for
      the qcow2 overlay makes sure not to open the backing file (because it is
      already opened and blockdev-snapshot will attach it). After doing a
      blockdev-snapshot, bs->options and bs->explicit_options become
      inconsistent with the actual state (bs has a backing file now, but the
      options still say null). On the next occasion that the image is
      reopened, e.g. switching it from read-write to read-only when another
      snapshot is taken, the option will take effect again and the node
      incorrectly loses its backing file.
      
      Fix bdrv_open_inherited() to remove the 'backing' option from
      bs->options and bs->explicit_options even for the case where it
      specifies that no backing file is wanted.
      Reported-by: NPeter Krempa <pkrempa@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      Reviewed-by: NAlberto Garcia <berto@igalia.com>
      Tested-by: NPeter Krempa <pkrempa@redhat.com>
      ae0f57f0
  6. 26 10月, 2019 1 次提交
    • W
      core: replace getpagesize() with qemu_real_host_page_size · 038adc2f
      Wei Yang 提交于
      There are three page size in qemu:
      
        real host page size
        host page size
        target page size
      
      All of them have dedicate variable to represent. For the last two, we
      use the same form in the whole qemu project, while for the first one we
      use two forms: qemu_real_host_page_size and getpagesize().
      
      qemu_real_host_page_size is defined to be a replacement of
      getpagesize(), so let it serve the role.
      
      [Note] Not fully tested for some arch or device.
      Signed-off-by: NWei Yang <richardw.yang@linux.intel.com>
      Message-Id: <20191013021145.16011-3-richardw.yang@linux.intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      038adc2f
  7. 18 10月, 2019 5 次提交
  8. 10 10月, 2019 2 次提交
  9. 03 9月, 2019 1 次提交
  10. 19 8月, 2019 1 次提交
    • M
      block: Add bdrv_has_zero_init_truncate() · ceaca56f
      Max Reitz 提交于
      No .bdrv_has_zero_init() implementation returns 1 if growing the file
      would add non-zero areas (at least with PREALLOC_MODE_OFF), so using it
      in lieu of this new function was always safe.
      
      But on the other hand, it is possible that growing an image that is not
      zero-initialized would still add a zero-initialized area, like when
      using nonpreallocating truncation on a preallocated image.  For callers
      that care only about truncation, not about creation with potential
      preallocation, this new function is useful.
      
      Alternatively, we could have added a PreallocMode parameter to
      bdrv_has_zero_init().  But the only user would have been qemu-img
      convert, which does not have a plain PreallocMode value right now -- it
      would have to parse the creation option to obtain it.  Therefore, the
      simpler solution is to let bdrv_has_zero_init() inquire the
      preallocation status and add the new bdrv_has_zero_init_truncate() that
      presupposes PREALLOC_MODE_OFF.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20190724171239.8764-4-mreitz@redhat.com
      Reviewed-by: NMaxim Levitsky <mlevitsk@redhat.com>
      Reviewed-by: NStefano Garzarella <sgarzare@redhat.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      ceaca56f
  11. 17 8月, 2019 1 次提交
  12. 16 8月, 2019 4 次提交
    • M
      Include qemu/main-loop.h less · db725815
      Markus Armbruster 提交于
      In my "build everything" tree, changing qemu/main-loop.h triggers a
      recompile of some 5600 out of 6600 objects (not counting tests and
      objects that don't depend on qemu/osdep.h).  It includes block/aio.h,
      which in turn includes qemu/event_notifier.h, qemu/notify.h,
      qemu/processor.h, qemu/qsp.h, qemu/queue.h, qemu/thread-posix.h,
      qemu/thread.h, qemu/timer.h, and a few more.
      
      Include qemu/main-loop.h only where it's needed.  Touching it now
      recompiles only some 1700 objects.  For block/aio.h and
      qemu/event_notifier.h, these numbers drop from 5600 to 2800.  For the
      others, they shrink only slightly.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190812052359.30071-21-armbru@redhat.com>
      Reviewed-by: NAlex Bennée <alex.bennee@linaro.org>
      Reviewed-by: NPhilippe Mathieu-Daudé <philmd@redhat.com>
      Tested-by: NPhilippe Mathieu-Daudé <philmd@redhat.com>
      db725815
    • M
      block: Reduce (un)drains when replacing a child · debc2927
      Max Reitz 提交于
      Currently, bdrv_replace_child_noperm() undrains the parent until it is
      completely undrained, then re-drains it after attaching the new child
      node.
      
      This is a problem with bdrv_drop_intermediate(): We want to keep the
      whole subtree drained, including parents, while the operation is
      under way.  bdrv_replace_child_noperm() breaks this by allowing every
      parent to become unquiesced briefly, and then redraining it.
      
      In fact, there is no reason why the parent should become unquiesced and
      be allowed to submit requests to the new child node if that new node is
      supposed to be kept drained.  So if anything, we have to drain the
      parent before detaching the old child node.  Conversely, we have to
      undrain it only after attaching the new child node.
      
      Thus, change the whole drain algorithm here: Calculate the number of
      times we have to drain/undrain the parent before replacing the child
      node then drain it (if necessary), replace the child node, and then
      undrain it.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      debc2927
    • M
      block: Keep subtree drained in drop_intermediate · 637d54a5
      Max Reitz 提交于
      bdrv_drop_intermediate() calls BdrvChildRole.update_filename().  That
      may poll, thus changing the graph, which potentially breaks the
      QLIST_FOREACH_SAFE() loop.
      
      Just keep the whole subtree drained.  This is probably the right thing
      to do anyway (dropping nodes while the subtree is not drained seems
      wrong).
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NKevin Wolf <kwolf@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      637d54a5
    • K
      block: Simplify bdrv_filter_default_perms() · e444fa83
      Kevin Wolf 提交于
      The same change as commit 2b23f286 ('block/copy-on-read: Fix
      permissions for inactive node') made for the copy-on-read driver can be
      made for bdrv_filter_default_perms(): Retaining the old permissions from
      the BdrvChild if it is given complicates things unnecessarily when in
      the end this only means that the options set in the c == NULL case (i.e.
      during child creation) are retained.
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      e444fa83
  13. 23 7月, 2019 1 次提交
    • M
      block: Only the main loop can change AioContexts · 43eaaaef
      Max Reitz 提交于
      bdrv_set_aio_context_ignore() can only work in the main loop:
      bdrv_drained_begin() only works in the main loop and the node's (old)
      AioContext; and bdrv_drained_end() really only works in the main loop
      and the node's (new) AioContext (contrary to its current comment, which
      is just wrong).
      
      Consequentially, bdrv_set_aio_context_ignore() must be called from the
      main loop.  Luckily, assuming that we can make block graph changes only
      from the main loop as well, all its callers do that already.
      
      Note that changing a node's context in a sense is an operation that
      changes the block graph, so it actually makes sense to require this
      function to be called from the main loop.
      
      Also, fix bdrv_drained_end()'s description.  You can only use it from
      the main loop or the node's AioContext, and in the latter case, the
      whole subtree must be in the same context.
      
      Fixes: e037c09cSigned-off-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20190722133054.21781-3-mreitz@redhat.com
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      43eaaaef
  14. 19 7月, 2019 2 次提交
    • M
      block: Do not poll in bdrv_do_drained_end() · e037c09c
      Max Reitz 提交于
      We should never poll anywhere in bdrv_do_drained_end() (including its
      recursive callees like bdrv_drain_invoke()), because it does not cope
      well with graph changes.  In fact, it has been written based on the
      postulation that no graph changes will happen in it.
      
      Instead, the callers that want to poll must poll, i.e. all currently
      globally available wrappers: bdrv_drained_end(),
      bdrv_subtree_drained_end(), bdrv_unapply_subtree_drain(), and
      bdrv_drain_all_end().  Graph changes there do not matter.
      
      They can poll simply by passing a pointer to a drained_end_counter and
      wait until it reaches 0.
      
      This patch also adds a non-polling global wrapper for
      bdrv_do_drained_end() that takes a drained_end_counter pointer.  We need
      such a variant because now no function called anywhere from
      bdrv_do_drained_end() must poll.  This includes
      BdrvChildRole.drained_end(), which already must not poll according to
      its interface documentation, but bdrv_child_cb_drained_end() just
      violates that by invoking bdrv_drained_end() (which does poll).
      Therefore, BdrvChildRole.drained_end() must take a *drained_end_counter
      parameter, which bdrv_child_cb_drained_end() can pass on to the new
      bdrv_drained_end_no_poll() function.
      
      Note that we now have a pattern of all drained_end-related functions
      either polling or receiving a *drained_end_counter to let the caller
      poll based on that.
      
      A problem with a single poll loop is that when the drained section in
      bdrv_set_aio_context_ignore() ends, some nodes in the subgraph may be in
      the old contexts, while others are in the new context already.  To let
      the collective poll in bdrv_drained_end() work correctly, we must not
      hold a lock to the old context, so that the old context can make
      progress in case it is different from the current context.
      
      (In the process, remove the comment saying that the current context is
      always the old context, because it is wrong.)
      
      In all other places, all nodes in a subtree must be in the same context,
      so we can just poll that.  The exception of course is
      bdrv_drain_all_end(), but that always runs in the main context, so we
      can just poll NULL (like bdrv_drain_all_begin() does).
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      e037c09c
    • M
      block: Introduce BdrvChild.parent_quiesce_counter · 804db8ea
      Max Reitz 提交于
      Commit 5cb2737e laid out why
      bdrv_do_drained_end() must decrement the quiesce_counter after
      bdrv_drain_invoke().  It did not give a very good reason why it has to
      happen after bdrv_parent_drained_end(), instead only claiming symmetry
      to bdrv_do_drained_begin().
      
      It turns out that delaying it for so long is wrong.
      
      Situation: We have an active commit job (i.e. a mirror job) from top to
      base for the following graph:
      
                        filter
                          |
                        [file]
                          |
                          v
      top --[backing]--> base
      
      Now the VM is closed, which results in the job being cancelled and a
      bdrv_drain_all() happening pretty much simultaneously.
      
      Beginning the drain means the job is paused once whenever one of its
      nodes is quiesced.  This is reversed when the drain ends.
      
      With how the code currently is, after base's drain ends (which means
      that it will have unpaused the job once), its quiesce_counter remains at
      1 while it goes to undrain its parents (bdrv_parent_drained_end()).  For
      some reason or another, undraining filter causes the job to be kicked
      and enter mirror_exit_common(), where it proceeds to invoke
      block_job_remove_all_bdrv().
      
      Now base will be detached from the job.  Because its quiesce_counter is
      still 1, it will unpause the job once more.  So in total, undraining
      base will unpause the job twice.  Eventually, this will lead to the
      job's pause_count going negative -- well, it would, were there not an
      assertion against this, which crashes qemu.
      
      The general problem is that if in bdrv_parent_drained_end() we undrain
      parent A, and then undrain parent B, which then leads to A detaching the
      child, bdrv_replace_child_noperm() will undrain A as if we had not done
      so yet; that is, one time too many.
      
      It follows that we cannot decrement the quiesce_counter after invoking
      bdrv_parent_drained_end().
      
      Unfortunately, decrementing it before bdrv_parent_drained_end() would be
      wrong, too.  Imagine the above situation in reverse: Undraining A leads
      to B detaching the child.  If we had already decremented the
      quiesce_counter by that point, bdrv_replace_child_noperm() would undrain
      B one time too little; because it expects bdrv_parent_drained_end() to
      issue this undrain.  But bdrv_parent_drained_end() won't do that,
      because B is no longer a parent.
      
      Therefore, we have to do something else.  This patch opts for
      introducing a second quiesce_counter that counts how many times a
      child's parent has been quiesced (though c->role->drained_*).  With
      that, bdrv_replace_child_noperm() just has to undrain the parent exactly
      that many times when removing a child, and it will always be right.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      804db8ea
  15. 15 7月, 2019 2 次提交
    • M
      block: Deep-clear inherits_from · 3cf746b3
      Max Reitz 提交于
      BDS.inherits_from does not always point to an immediate parent node.
      When launching a block job with a filter node, for example, the node
      directly below the filter will not point to the filter, but keep its old
      pointee (above the filter).
      
      If that pointee goes away while the job is still running, the node's
      inherits_from will not be updated and thus point to garbage.  To fix
      this, bdrv_unref_child() has to check not only the parent node's
      immediate children for nodes whose inherits_from needs to be cleared,
      but its whole subtree.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20190703172813.6868-7-mreitz@redhat.com
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      3cf746b3
    • M
      block: Add BDS.never_freeze · e5182c1c
      Max Reitz 提交于
      The commit and the mirror block job must be able to drop their filter
      node at any point.  However, this will not be possible if any of the
      BdrvChild links to them is frozen.  Therefore, we need to prevent them
      from ever becoming frozen.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NAndrey Shinkevich <andrey.shinkevich@virtuozzo.com>
      Reviewed-by: NAlberto Garcia <berto@igalia.com>
      Message-id: 20190703172813.6868-2-mreitz@redhat.com
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      e5182c1c
  16. 18 6月, 2019 5 次提交
    • M
      block: Ignore loosening perm restrictions failures · 1046779e
      Max Reitz 提交于
      We generally assume that loosening permission restrictions can never
      fail.  We have seen in the past that this assumption is wrong.  This has
      led to crashes because we generally pass &error_abort when loosening
      permissions.
      
      However, a failure in such a case should actually be handled in quite
      the opposite way: It is very much not fatal, so qemu may report it, but
      still consider the operation successful.  The only realistic problem is
      that qemu may then retain permissions and thus locks on images it
      actually does not require.  But again, that is not fatal.
      
      To implement this behavior, we make all functions that change
      permissions and that pass &error_abort to the initiating function
      (bdrv_check_perm() or bdrv_child_check_perm()) evaluate the
      @loosen_restrictions value introduced in the previous patch.  If it is
      true and an error did occur, we abort the permission update, discard the
      error, and instead report success to the caller.
      
      bdrv_child_try_set_perm() itself does not pass &error_abort, but it is
      the only public function to change permissions.  As such, callers may
      pass &error_abort to it, expecting dropping permission restrictions to
      never fail.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      1046779e
    • M
      block: Add *tighten_restrictions to *check*_perm() · 9eab1544
      Max Reitz 提交于
      This patch makes three functions report whether the necessary permission
      change tightens restrictions or not.  These functions are:
      - bdrv_check_perm()
      - bdrv_check_update_perm()
      - bdrv_child_check_perm()
      
      Callers can use this result to decide whether a failure is fatal or not
      (see the next patch).
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      9eab1544
    • M
      block: Fix order in bdrv_replace_child() · 87ace5f8
      Max Reitz 提交于
      We have to start by applying the permission restrictions to new_bs
      before we can loosen them on old_bs.  See the comment for the
      explanation.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NKevin Wolf <kwolf@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      87ace5f8
    • M
      block: Add bdrv_child_refresh_perms() · c1087f12
      Max Reitz 提交于
      If a block node uses bdrv_child_try_set_perm() to change the permission
      it takes on its child, the result may be very short-lived.  If anything
      makes the block layer recalculate the permissions internally, it will
      invoke the node driver's .bdrv_child_perm() implementation.  The
      permission/shared permissions masks that returns will then override the
      values previously passed to bdrv_child_try_set_perm().
      
      If drivers want a child edge to have specific values for the
      permissions/shared permissions mask, it must return them in
      .bdrv_child_perm().  Consequentially, there is no need for them to pass
      the same values to bdrv_child_try_set_perm() then: It is better to have
      a function that invokes .bdrv_child_perm() and calls
      bdrv_child_try_set_perm() with the result.  This patch adds such a
      function under the name of bdrv_child_refresh_perms().
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NKevin Wolf <kwolf@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      c1087f12
    • V
      block: drop bs->job · b23c580c
      Vladimir Sementsov-Ogievskiy 提交于
      Drop remaining users of bs->job:
      1. assertions actually duplicated by assert(!bs->refcnt)
      2. trace-point seems not enough reason to change stream_start to return
         BlockJob pointer
      3. Restricting creation of two jobs based on same bs is bad idea, as
         3.1 Some jobs creates filters to be their main node, so, this check
         don't actually prevent creating second job on same real node (which
         will create another filter node) (but I hope it is restricted by
         other mechanisms)
         3.2 Even without bs->job we have two systems of permissions:
         op-blockers and BLK_PERM
         3.3 We may want to run several jobs on one node one day
      
      And finally, drop bs->job pointer itself. Hurrah!
      Suggested-by: NKevin Wolf <kwolf@redhat.com>
      Signed-off-by: NVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      b23c580c
  17. 04 6月, 2019 6 次提交
    • K
      block: Remove bdrv_set_aio_context() · 42a65f02
      Kevin Wolf 提交于
      All callers of bdrv_set_aio_context() are eliminated now, they have
      moved to bdrv_try_set_aio_context() and related safe functions. Remove
      bdrv_set_aio_context().
      
      With this, we can now know that the .set_aio_ctx callback must be
      present in bdrv_set_aio_context_ignore() because
      bdrv_can_set_aio_context() would have returned false previously, so
      instead of checking the condition, we can assert it.
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      42a65f02
    • K
      block: Remove wrong bdrv_set_aio_context() calls · d0ee0204
      Kevin Wolf 提交于
      The mirror and commit block jobs use bdrv_set_aio_context() to move
      their filter node into the right AioContext before hooking it up in the
      graph. Similarly, bdrv_open_backing_file() explicitly moves the backing
      file node into the right AioContext first.
      
      This isn't necessary any more, they get automatically moved into the
      right context now when attaching them.
      
      However, in the case of bdrv_open_backing_file() with a node reference,
      it's actually not only unnecessary, but even wrong: The unchecked
      bdrv_set_aio_context() changes the AioContext of the child node even if
      other parents require it to retain the old context. So this is not only
      a simplification, but a bug fix, too.
      
      Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1684342Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      d0ee0204
    • K
      block: Move node without parents to main AioContext · ad943dcb
      Kevin Wolf 提交于
      A node should only be in a non-default AioContext if a user is attached
      to it that requires this. When the last parent of a node is gone, it can
      move back to the main AioContext.
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      ad943dcb
    • K
      block: Adjust AioContexts when attaching nodes · 132ada80
      Kevin Wolf 提交于
      So far, we only made sure that updating the AioContext of a node
      affected the whole subtree. However, if a node is newly attached to a
      new parent, we also need to make sure that both the subtree of the node
      and the parent are in the same AioContext. This tries to move the new
      child node to the parent AioContext and returns an error if this isn't
      possible.
      
      BlockBackends now actually apply their AioContext to their root node.
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      132ada80
    • K
      block: Add BlockBackend.ctx · d861ab3a
      Kevin Wolf 提交于
      This adds a new parameter to blk_new() which requires its callers to
      declare from which AioContext this BlockBackend is going to be used (or
      the locks of which AioContext need to be taken anyway).
      
      The given context is only stored and kept up to date when changing
      AioContexts. Actually applying the stored AioContext to the root node
      is saved for another commit.
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      d861ab3a
    • K
      block: Drain source node in bdrv_replace_node() · f871abd6
      Kevin Wolf 提交于
      Instead of just asserting that no requests are in flight in
      bdrv_replace_node(), which is a requirement that most callers ignore, we
      can just drain the source node right there. This fixes at least starting
      a commit job while I/O is active on the backing chain, but probably
      other callers, too.
      
      Having requests in flight on the target node isn't a problem because the
      target just gets new parents, but the call path of running requests
      isn't modified. So we can just drop this assertion without a replacement.
      
      Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1711643Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      f871abd6
  18. 29 5月, 2019 2 次提交
    • A
      block: Make bdrv_root_attach_child() unref child_bs on failure · b441dc71
      Alberto Garcia 提交于
      A consequence of the previous patch is that bdrv_attach_child()
      transfers the reference to child_bs from the caller to parent_bs,
      which will drop it on bdrv_close() or when someone calls
      bdrv_unref_child().
      
      But this only happens when bdrv_attach_child() succeeds. If it fails
      then the caller is responsible for dropping the reference to child_bs.
      
      This patch makes bdrv_attach_child() take the reference also when
      there is an error, freeing the caller for having to do it.
      
      A similar situation happens with bdrv_root_attach_child(), so the
      changes on this patch affect both functions.
      Signed-off-by: NAlberto Garcia <berto@igalia.com>
      Message-id: 20dfb3d9ccec559cdd1a9690146abad5d204a186.1557754872.git.berto@igalia.com
      [mreitz: Removed now superfluous BdrvChild * variable in
               bdrv_open_child()]
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      b441dc71
    • A
      block: Use bdrv_unref_child() for all children in bdrv_close() · dd4118c7
      Alberto Garcia 提交于
      bdrv_unref_child() does the following things:
      
        - Updates the child->bs->inherits_from pointer.
        - Calls bdrv_detach_child() to remove the BdrvChild from bs->children.
        - Calls bdrv_unref() to unref the child BlockDriverState.
      
      When bdrv_unref_child() was introduced in commit 33a60407 it was not
      used in bdrv_close() because the drivers that had additional children
      (like quorum or blkverify) had already called bdrv_unref() on their
      children during their own close functions.
      
      This was changed later (in 0bd6e91a for quorum, in 3e586be0 for
      blkverify) so there's no reason not to use bdrv_unref_child() in
      bdrv_close() anymore.
      
      After this there's also no need to remove bs->backing and bs->file
      separately from the rest of the children, so bdrv_close() can be
      simplified.
      
      Now bdrv_close() unrefs all children (before this patch it was only
      bs->file and bs->backing). As a result, none of the callers of
      brvd_attach_child() should remove their reference to child_bs (because
      this function effectively steals that reference). This patch updates a
      couple of tests that were doing their own bdrv_unref().
      Signed-off-by: NAlberto Garcia <berto@igalia.com>
      Message-id: 6d1d5feaa53aa1ab127adb73d605dc4503e3abd5.1557754872.git.berto@igalia.com
      [mreitz: s/where/were/]
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      dd4118c7
  19. 20 5月, 2019 1 次提交