1. 19 5月, 2020 13 次提交
    • M
      block: Distinguish paths in *_format_default_perms · 33f2663b
      Max Reitz 提交于
      bdrv_format_default_perms() has one code path for backing files, and one
      for storage files.  We want to pull them out into their own functions,
      so make sure they are completely distinct before so the next patches
      will be a bit cleaner.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20200513110544.176672-16-mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      33f2663b
    • M
      block: Add child_of_bds · 43483550
      Max Reitz 提交于
      Any current user of child_file, child_format, and child_backing can and
      should use this generic BdrvChildClass instead, as it can handle all of
      these cases.  However, to be able to do so, the users must pass the
      appropriate BdrvChildRole when the child is created/attached.  (The
      following commits will take care of that.)
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-Id: <20200513110544.176672-15-mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      43483550
    • M
      block: Unify bdrv_child_cb_detach() · 48e08288
      Max Reitz 提交于
      Make bdrv_child_cb_detach() call bdrv_backing_detach() for children with
      a COW role (and drop the reverse call from bdrv_backing_detach()), so it
      can be used for any child (with a proper role set).
      
      Because so far no child has a proper role set, we need a temporary new
      callback for child_backing.detach that ensures bdrv_backing_detach() is
      called for all COW children that do not have their role set yet.
      
      (Also, move bdrv_child_cb_detach() down to group it with
      bdrv_inherited_options() and bdrv_child_cb_attach().)
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-Id: <20200513110544.176672-14-mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      48e08288
    • M
      block: Unify bdrv_child_cb_attach() · ca2f1234
      Max Reitz 提交于
      Make bdrv_child_cb_attach() call bdrv_backing_attach() for children with
      a COW role (and drop the reverse call from bdrv_backing_attach()), so it
      can be used for any child (with a proper role set).
      
      Because so far no child has a proper role set, we need a temporary new
      callback for child_backing.attach that ensures bdrv_backing_attach() is
      called for all COW children that do not have their role set yet.
      
      (Also, move bdrv_child_cb_attach() down to group it with
      bdrv_inherited_options().)
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-Id: <20200513110544.176672-13-mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      ca2f1234
    • M
      block: Use bdrv_inherited_options() · 00ff7ffd
      Max Reitz 提交于
      Let child_file's, child_format's, and child_backing's .inherit_options()
      implementations fall back to bdrv_inherited_options() to show that it
      would really work for all of these cases, if only the parents passed the
      appropriate BdrvChildRole and parent_is_format values.
      
      (Also, make bdrv_open_inherit(), the only place to explicitly call
      bdrv_backing_options(), call bdrv_inherited_options() instead.)
      
      This patch should incur only two visible changes, both for child_format
      children, both of which are effectively bug fixes:
      
      First, they no longer have discard=unmap set by default.  This reason it
      was set is because bdrv_inherited_fmt_options() fell through to
      bdrv_protocol_options(), and that set it because "format drivers take
      care to send flushes and respect unmap policy".  None of the drivers
      that use child_format for their children (quorum and blkverify) are
      format drivers, though, so this reasoning does not apply here.
      
      Second, they no longer have BDRV_O_NO_IO force-cleared.  child_format
      was used solely for children that do not store any metadata and as such
      will not be accessed by their parents as long as those parents do not
      receive I/O themselves.  Thus, such children should inherit
      BDRV_O_NO_IO.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-Id: <20200513110544.176672-12-mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      00ff7ffd
    • M
      block: Add generic bdrv_inherited_options() · fae8bd39
      Max Reitz 提交于
      After the series this patch belongs to, we want to have a common
      BdrvChildClass that encompasses all of child_file, child_format, and
      child_backing.  Such a single class needs a single .inherit_options()
      implementation, and this patch introduces it.
      
      The next patch will show how the existing implementations can fall back
      to it just by passing appropriate BdrvChildRole and parent_is_format
      values.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-Id: <20200513110544.176672-11-mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      fae8bd39
    • M
      block: Rename bdrv_inherited_options() · b054ff73
      Max Reitz 提交于
      The other two .inherit_options implementations specify exactly for what
      case they are used in their name, so do it for this one as well.
      
      (The actual intention behind this patch is to follow it up with a
      generic bdrv_inherited_options() that works for all three cases.)
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20200513110544.176672-10-mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      b054ff73
    • M
      block: Pass parent_is_format to .inherit_options() · 3cdc69d3
      Max Reitz 提交于
      We plan to unify the generic .inherit_options() functions.  The
      resulting common function will need to decide whether to force-enable
      format probing, force-disable it, or leave it as-is.  To make this
      decision, it will need to know whether the parent node is a format node
      or not (because we never want format probing if the parent is a format
      node already (except for the backing chain)).
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20200513110544.176672-9-mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      3cdc69d3
    • M
      block: Pass BdrvChildRole to .inherit_options() · 272c02ea
      Max Reitz 提交于
      For now, all callers (effectively) pass 0 and no callee evaluates thie
      value.  Later patches will change both.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20200513110544.176672-8-mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      272c02ea
    • M
      block: Pass BdrvChildRole to bdrv_child_perm() · bf8e925e
      Max Reitz 提交于
      For now, all callers pass 0 and no callee evaluates this value.  Later
      patches will change both.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20200513110544.176672-7-mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      bf8e925e
    • M
      block: Add BdrvChildRole to BdrvChild · 258b7765
      Max Reitz 提交于
      For now, it is always set to 0.  Later patches in this series will
      ensure that all callers pass an appropriate combination of flags.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20200513110544.176672-6-mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      258b7765
    • M
      block: Rename BdrvChildRole to BdrvChildClass · bd86fb99
      Max Reitz 提交于
      This structure nearly only contains parent callbacks for child state
      changes.  It cannot really reflect a child's role, because different
      roles may overlap (as we will see when real roles are introduced), and
      because parents can have custom callbacks even when the child fulfills a
      standard role.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NAlberto Garcia <berto@igalia.com>
      Message-Id: <20200513110544.176672-4-mreitz@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      bd86fb99
    • M
      block: Add bdrv_make_empty() · 6f7a3b53
      Max Reitz 提交于
      Right now, all users of bdrv_make_empty() call the BlockDriver method
      directly.  That is not only bad style, it is also wrong, unless the
      caller has a BdrvChild with a WRITE or WRITE_UNCHANGED permission.
      (WRITE_UNCHANGED suffices, because callers generally use this function
      to clear a node with a backing file after a commit operation.)
      
      Introduce bdrv_make_empty() that verifies that it does.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-Id: <20200429141126.85159-2-mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      6f7a3b53
  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 1 次提交