Skip to content
Snippets Groups Projects
  1. Sep 20, 2023
    • Kevin Wolf's avatar
      block: Mark bdrv_parent_perms_conflict() and callers GRAPH_RDLOCK · 3804e3cf
      Kevin Wolf authored
      
      The function reads the parents list, so it needs to hold the graph lock.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarEmanuele Giuseppe Esposito <eesposit@redhat.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Message-ID: <20230911094620.45040-14-kwolf@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      3804e3cf
    • Kevin Wolf's avatar
      block: Mark bdrv_attach_child() GRAPH_WRLOCK · afdaeb9e
      Kevin Wolf authored
      
      Instead of taking the writer lock internally, require callers to already
      hold it when calling bdrv_attach_child_common(). These callers will
      typically already hold the graph lock once the locking work is
      completed, which means that they can't call functions that take it
      internally.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarEmanuele Giuseppe Esposito <eesposit@redhat.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Message-ID: <20230911094620.45040-13-kwolf@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      afdaeb9e
    • Kevin Wolf's avatar
      block: Mark bdrv_attach_child_common() GRAPH_WRLOCK · 7d4ca9d2
      Kevin Wolf authored
      
      Instead of taking the writer lock internally, require callers to already
      hold it when calling bdrv_attach_child_common(). These callers will
      typically already hold the graph lock once the locking work is
      completed, which means that they can't call functions that take it
      internally.
      
      Note that the transaction callbacks still take the lock internally, so
      tran_finalize() must be called without the lock held. This is because
      bdrv_append() also calls bdrv_replace_node_noperm(), which currently
      requires the transaction callbacks to be called unlocked. In the next
      step, both of them can be switched to locked tran_finalize() calls
      together.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Message-ID: <20230911094620.45040-11-kwolf@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      7d4ca9d2
    • Kevin Wolf's avatar
      block: Introduce bdrv_schedule_unref() · ac2ae233
      Kevin Wolf authored
      
      bdrv_unref() is called by a lot of places that need to hold the graph
      lock (it naturally happens in the context of operations that change the
      graph). However, bdrv_unref() takes the graph writer lock internally, so
      it can't actually be called while already holding a graph lock without
      causing a deadlock.
      
      bdrv_unref() also can't just become GRAPH_WRLOCK because it drains the
      node before closing it, and draining requires that the graph is
      unlocked.
      
      The solution is to defer deleting the node until we don't hold the lock
      any more and draining is possible again.
      
      Note that keeping images open for longer than necessary can create
      problems, too: You can't open an image again before it is really closed
      (if image locking didn't prevent it, it would cause corruption).
      Reopening an image immediately happens at least during bdrv_open() and
      bdrv_co_create().
      
      In order to solve this problem, make sure to run the deferred unref in
      bdrv_graph_wrunlock(), i.e. the first possible place where we can drain
      again. This is also why bdrv_schedule_unref() is marked GRAPH_WRLOCK.
      
      The output of iotest 051 is updated because the additional polling
      changes the order of HMP output, resulting in a new "(qemu)" prompt in
      the test output that was previously on a separate line and filtered out.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Message-ID: <20230911094620.45040-6-kwolf@redhat.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      ac2ae233
    • Kevin Wolf's avatar
      preallocate: Don't poll during permission updates · edcce17b
      Kevin Wolf authored
      
      When the permission related BlockDriver callbacks are called, we are in
      the middle of an operation traversing the block graph. Polling in such a
      place is a very bad idea because the graph could change in unexpected
      ways. In the future, callers will also hold the graph lock, which is
      likely to turn polling into a deadlock.
      
      So we need to get rid of calls to functions like bdrv_getlength() or
      bdrv_truncate() there as these functions poll internally. They are
      currently used so that when no parent has write/resize permissions on
      the image any more, the preallocate filter drops the extra preallocated
      area in the image file and gives up write/resize permissions itself.
      
      In order to achieve this without polling in .bdrv_check_perm, don't
      immediately truncate the image, but only schedule a BH to do so. The
      filter keeps the write/resize permissions a bit longer now until the BH
      has executed.
      
      There is one case in which delaying doesn't work: Reopening the image
      read-only. In this case, bs->file will likely be reopened read-only,
      too, so keeping write permissions a bit longer on it doesn't work. But
      we can already cover this case in preallocate_reopen_prepare() and not
      rely on the permission updates for it.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Message-ID: <20230911094620.45040-4-kwolf@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      edcce17b
    • Kevin Wolf's avatar
      preallocate: Factor out preallocate_truncate_to_real_size() · 01e28f60
      Kevin Wolf authored
      
      It's essentially the same code in preallocate_check_perm() and
      preallocate_close(), except that the latter ignores errors.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarEmanuele Giuseppe Esposito <eesposit@redhat.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Message-ID: <20230911094620.45040-3-kwolf@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      01e28f60
  2. Sep 08, 2023
  3. Sep 06, 2023
  4. Aug 30, 2023
  5. Aug 03, 2023
  6. Jul 27, 2023
  7. Jul 26, 2023
  8. Jul 25, 2023
    • Stefano Garzarella's avatar
      block/blkio: enable the completion eventfd · 9359c459
      Stefano Garzarella authored
      
      Until libblkio 1.3.0, virtio-blk drivers had completion eventfd
      notifications enabled from the start, but from the next releases
      this is no longer the case, so we have to explicitly enable them.
      
      In fact, the libblkio documentation says they could be disabled,
      so we should always enable them at the start if we want to be
      sure to get completion eventfd notifications:
      
          By default, the driver might not generate completion events for
          requests so it is necessary to explicitly enable the completion
          file descriptor before use:
      
          void blkioq_set_completion_fd_enabled(struct blkioq *q, bool enable);
      
      I discovered this while trying a development version of libblkio:
      the guest kernel hangs during boot, while probing the device.
      
      Fixes: fd66dbd4 ("blkio: add libblkio block driver")
      Signed-off-by: default avatarStefano Garzarella <sgarzare@redhat.com>
      Message-id: 20230725103744.77343-1-sgarzare@redhat.com
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      9359c459
  9. Jul 19, 2023
    • Eric Blake's avatar
      nbd/client: Simplify cookie vs. index computation · 8cb98a72
      Eric Blake authored
      
      Our code relies on a sentinel cookie value of zero for deciding when a
      packet has been handled, as well as relying on array indices between 0
      and MAX_NBD_REQUESTS-1 for dereferencing purposes.  As long as we can
      symmetrically convert between two forms, there is no reason to go with
      the odd choice of using XOR with a random pointer, when we can instead
      simplify the mappings with a mere offset of 1.
      
      Using ((uint64_t)-1) as the sentinel instead of NULL such that the two
      macros could be entirely eliminated might also be possible, but would
      require a more careful audit to find places where we currently rely on
      zero-initialization to be interpreted as the sentinel value, so I did
      not pursue that course.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-ID: <20230608135653.2918540-7-eblake@redhat.com>
      [eblake: enhance commit message]
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
      8cb98a72
Loading