1. 19 5月, 2020 8 次提交
  2. 08 5月, 2020 1 次提交
    • E
      block: Drop unused .bdrv_has_zero_init_truncate · 47e0b38a
      Eric Blake 提交于
      Now that there are no clients of bdrv_has_zero_init_truncate, none of
      the drivers need to worry about providing it.
      
      What's more, this eliminates a source of some confusion: a literal
      reading of the documentation as written in ceaca56f and implemented in
      commit 1dcaf527 claims that a driver which returns 0 for
      bdrv_has_zero_init_truncate() must not return 1 for
      bdrv_has_zero_init(); this condition was violated for parallels, qcow,
      and sometimes for vdi, although in practice it did not matter since
      those drivers also lacked .bdrv_co_truncate.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20200428202905.770727-10-eblake@redhat.com>
      Acked-by: NRichard W.M. Jones <rjones@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      47e0b38a
  3. 04 5月, 2020 1 次提交
  4. 30 4月, 2020 2 次提交
  5. 27 3月, 2020 1 次提交
  6. 26 3月, 2020 2 次提交
  7. 24 3月, 2020 2 次提交
    • V
      block: bdrv_set_backing_bs: fix use-after-free · 6e57963a
      Vladimir Sementsov-Ogievskiy 提交于
      There is a use-after-free possible: bdrv_unref_child() leaves
      bs->backing freed but not NULL. bdrv_attach_child may produce nested
      polling loop due to drain, than access of freed pointer is possible.
      
      I've produced the following crash on 30 iotest with modified code. It
      does not reproduce on master, but still seems possible:
      
          #0  __strcmp_avx2 () at /lib64/libc.so.6
          #1  bdrv_backing_overridden (bs=0x55c9d3cc2060) at block.c:6350
          #2  bdrv_refresh_filename (bs=0x55c9d3cc2060) at block.c:6404
          #3  bdrv_backing_attach (c=0x55c9d48e5520) at block.c:1063
          #4  bdrv_replace_child_noperm
              (child=child@entry=0x55c9d48e5520,
              new_bs=new_bs@entry=0x55c9d3cc2060) at block.c:2290
          #5  bdrv_replace_child
              (child=child@entry=0x55c9d48e5520,
              new_bs=new_bs@entry=0x55c9d3cc2060) at block.c:2320
          #6  bdrv_root_attach_child
              (child_bs=child_bs@entry=0x55c9d3cc2060,
              child_name=child_name@entry=0x55c9d241d478 "backing",
              child_role=child_role@entry=0x55c9d26ecee0 <child_backing>,
              ctx=<optimized out>, perm=<optimized out>, shared_perm=21,
              opaque=0x55c9d3c5a3d0, errp=0x7ffd117108e0) at block.c:2424
          #7  bdrv_attach_child
              (parent_bs=parent_bs@entry=0x55c9d3c5a3d0,
              child_bs=child_bs@entry=0x55c9d3cc2060,
              child_name=child_name@entry=0x55c9d241d478 "backing",
              child_role=child_role@entry=0x55c9d26ecee0 <child_backing>,
              errp=errp@entry=0x7ffd117108e0) at block.c:5876
          #8  in bdrv_set_backing_hd
              (bs=bs@entry=0x55c9d3c5a3d0,
              backing_hd=backing_hd@entry=0x55c9d3cc2060,
              errp=errp@entry=0x7ffd117108e0)
              at block.c:2576
          #9  stream_prepare (job=0x55c9d49d84a0) at block/stream.c:150
          #10 job_prepare (job=0x55c9d49d84a0) at job.c:761
          #11 job_txn_apply (txn=<optimized out>, fn=<optimized out>) at
              job.c:145
          #12 job_do_finalize (job=0x55c9d49d84a0) at job.c:778
          #13 job_completed_txn_success (job=0x55c9d49d84a0) at job.c:832
          #14 job_completed (job=0x55c9d49d84a0) at job.c:845
          #15 job_completed (job=0x55c9d49d84a0) at job.c:836
          #16 job_exit (opaque=0x55c9d49d84a0) at job.c:864
          #17 aio_bh_call (bh=0x55c9d471a160) at util/async.c:117
          #18 aio_bh_poll (ctx=ctx@entry=0x55c9d3c46720) at util/async.c:117
          #19 aio_poll (ctx=ctx@entry=0x55c9d3c46720,
              blocking=blocking@entry=true)
              at util/aio-posix.c:728
          #20 bdrv_parent_drained_begin_single (poll=true, c=0x55c9d3d558f0)
              at block/io.c:121
          #21 bdrv_parent_drained_begin_single (c=c@entry=0x55c9d3d558f0,
              poll=poll@entry=true)
              at block/io.c:114
          #22 bdrv_replace_child_noperm
              (child=child@entry=0x55c9d3d558f0,
              new_bs=new_bs@entry=0x55c9d3d27300) at block.c:2258
          #23 bdrv_replace_child
              (child=child@entry=0x55c9d3d558f0,
              new_bs=new_bs@entry=0x55c9d3d27300) at block.c:2320
          #24 bdrv_root_attach_child
              (child_bs=child_bs@entry=0x55c9d3d27300,
              child_name=child_name@entry=0x55c9d241d478 "backing",
              child_role=child_role@entry=0x55c9d26ecee0 <child_backing>,
              ctx=<optimized out>, perm=<optimized out>, shared_perm=21,
              opaque=0x55c9d3cc2060, errp=0x7ffd11710c60) at block.c:2424
          #25 bdrv_attach_child
              (parent_bs=parent_bs@entry=0x55c9d3cc2060,
              child_bs=child_bs@entry=0x55c9d3d27300,
              child_name=child_name@entry=0x55c9d241d478 "backing",
              child_role=child_role@entry=0x55c9d26ecee0 <child_backing>,
              errp=errp@entry=0x7ffd11710c60) at block.c:5876
          #26 bdrv_set_backing_hd
              (bs=bs@entry=0x55c9d3cc2060,
              backing_hd=backing_hd@entry=0x55c9d3d27300,
              errp=errp@entry=0x7ffd11710c60)
              at block.c:2576
          #27 stream_prepare (job=0x55c9d495ead0) at block/stream.c:150
          ...
      Signed-off-by: NVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200316060631.30052-2-vsementsov@virtuozzo.com>
      Reviewed-by: NPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: NJohn Snow <jsnow@redhat.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      6e57963a
    • P
      block: Assert BlockDriver::format_name is not NULL · a15f08dc
      Philippe Mathieu-Daudé 提交于
      bdrv_do_find_format() calls strcmp() using BlockDriver::format_name
      as argument, which must not be NULL. Assert this field is not null
      when we register a block driver in bdrv_register().
      Reported-by: NMansour Ahmadi <ManSoSec@gmail.com>
      Signed-off-by: NPhilippe Mathieu-Daudé <philmd@redhat.com>
      Message-Id: <20200318222235.23856-1-philmd@redhat.com>
      Reviewed-by: NAlberto Garcia <berto@igalia.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      a15f08dc
  8. 11 3月, 2020 3 次提交
  9. 07 3月, 2020 3 次提交
  10. 22 2月, 2020 1 次提交
  11. 20 2月, 2020 2 次提交
  12. 18 2月, 2020 5 次提交
  13. 06 2月, 2020 2 次提交
    • P
      block: fix memleaks in bdrv_refresh_filename · cb895614
      Pan Nengyuan 提交于
      If we call the qmp 'query-block' while qemu is working on
      'block-commit', it will cause memleaks, the memory leak stack is as
      follow:
      
      Indirect leak of 12360 byte(s) in 3 object(s) allocated from:
          #0 0x7f80f0b6d970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970)
          #1 0x7f80ee86049d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d)
          #2 0x55ea95b5bb67 in qdict_new /mnt/sdb/qemu-4.2.0-rc0/qobject/qdict.c:29
          #3 0x55ea956cd043 in bdrv_refresh_filename /mnt/sdb/qemu-4.2.0-rc0/block.c:6427
          #4 0x55ea956cc950 in bdrv_refresh_filename /mnt/sdb/qemu-4.2.0-rc0/block.c:6399
          #5 0x55ea956cc950 in bdrv_refresh_filename /mnt/sdb/qemu-4.2.0-rc0/block.c:6399
          #6 0x55ea956cc950 in bdrv_refresh_filename /mnt/sdb/qemu-4.2.0-rc0/block.c:6399
          #7 0x55ea958818ea in bdrv_block_device_info /mnt/sdb/qemu-4.2.0-rc0/block/qapi.c:56
          #8 0x55ea958879de in bdrv_query_info /mnt/sdb/qemu-4.2.0-rc0/block/qapi.c:392
          #9 0x55ea9588b58f in qmp_query_block /mnt/sdb/qemu-4.2.0-rc0/block/qapi.c:578
          #10 0x55ea95567392 in qmp_marshal_query_block qapi/qapi-commands-block-core.c:95
      
      Indirect leak of 4120 byte(s) in 1 object(s) allocated from:
          #0 0x7f80f0b6d970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970)
          #1 0x7f80ee86049d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d)
          #2 0x55ea95b5bb67 in qdict_new /mnt/sdb/qemu-4.2.0-rc0/qobject/qdict.c:29
          #3 0x55ea956cd043 in bdrv_refresh_filename /mnt/sdb/qemu-4.2.0-rc0/block.c:6427
          #4 0x55ea956cc950 in bdrv_refresh_filename /mnt/sdb/qemu-4.2.0-rc0/block.c:6399
          #5 0x55ea956cc950 in bdrv_refresh_filename /mnt/sdb/qemu-4.2.0-rc0/block.c:6399
          #6 0x55ea9569f301 in bdrv_backing_attach /mnt/sdb/qemu-4.2.0-rc0/block.c:1064
          #7 0x55ea956a99dd in bdrv_replace_child_noperm /mnt/sdb/qemu-4.2.0-rc0/block.c:2283
          #8 0x55ea956b9b53 in bdrv_replace_node /mnt/sdb/qemu-4.2.0-rc0/block.c:4196
          #9 0x55ea956b9e49 in bdrv_append /mnt/sdb/qemu-4.2.0-rc0/block.c:4236
          #10 0x55ea958c3472 in commit_start /mnt/sdb/qemu-4.2.0-rc0/block/commit.c:306
          #11 0x55ea94b68ab0 in qmp_block_commit /mnt/sdb/qemu-4.2.0-rc0/blockdev.c:3459
          #12 0x55ea9556a7a7 in qmp_marshal_block_commit qapi/qapi-commands-block-core.c:407
      
      Fixes: bb808d5fReported-by: NEuler Robot <euler.robot@huawei.com>
      Signed-off-by: NPan Nengyuan <pannengyuan@huawei.com>
      Message-id: 20200116085600.24056-1-pannengyuan@huawei.com
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      cb895614
    • A
      block: Use a GString in bdrv_perm_names() · e2a7423a
      Alberto Garcia 提交于
      This is a bit more efficient than having to allocate and free memory
      for each new permission.
      
      The default size (30) is enough for "consistent read, write, resize".
      Signed-off-by: NAlberto Garcia <berto@igalia.com>
      Message-id: 20200110171518.22168-1-berto@igalia.com
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      e2a7423a
  14. 31 1月, 2020 1 次提交
  15. 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
  16. 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
  17. 18 12月, 2019 1 次提交
  18. 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
  19. 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