Skip to content
Snippets Groups Projects
  1. Sep 15, 2020
    • Swapnil Ingle's avatar
      block/vhdx: Support vhdx image only with 512 bytes logical sector size · 83a6a900
      Swapnil Ingle authored
      
      block/vhdx uses qemu block layer where sector size is always 512 bytes.
      This may have issues  with 4K logical sector sized vhdx image.
      
      For e.g qemu-img convert on such images fails with following assert:
      
      $qemu-img convert -f vhdx -O raw 4KTest1.vhdx test.raw
      qemu-img: util/iov.c:388: qiov_slice: Assertion `offset + len <=
      qiov->size' failed.
      Aborted
      
      This patch adds an check to return ENOTSUP for vhdx images which
      have logical sector size other than 512 bytes.
      
      Signed-off-by: default avatarSwapnil Ingle <swapnil.ingle@nutanix.com>
      Message-Id: <1596794594-44531-1-git-send-email-swapnil.ingle@nutanix.com>
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      83a6a900
  2. Jul 10, 2020
    • Markus Armbruster's avatar
      error: Avoid error_propagate() after migrate_add_blocker() · 386f6c07
      Markus Armbruster authored
      
      When migrate_add_blocker(blocker, &errp) is followed by
      error_propagate(errp, err), we can often just as well do
      migrate_add_blocker(..., errp).
      
      Do that with this Coccinelle script:
      
          @@
          expression blocker, err, errp;
          expression ret;
          @@
          -    ret = migrate_add_blocker(blocker, &err);
          -    if (err) {
          +    ret = migrate_add_blocker(blocker, errp);
          +    if (ret < 0) {
                   ... when != err;
          -        error_propagate(errp, err);
                   ...
               }
      
          @@
          expression blocker, err, errp;
          @@
          -    migrate_add_blocker(blocker, &err);
          -    if (err) {
          +    if (migrate_add_blocker(blocker, errp) < 0) {
                   ... when != err;
          -        error_propagate(errp, err);
                   ...
               }
      
      Double-check @err is not used afterwards.  Dereferencing it would be
      use after free, but checking whether it's null would be legitimate.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-43-armbru@redhat.com>
      386f6c07
    • Markus Armbruster's avatar
      qapi: Smooth another visitor error checking pattern · b11a093c
      Markus Armbruster authored
      
      Convert
      
          visit_type_FOO(v, ..., &ptr, &err);
          ...
          if (err) {
              ...
          }
      
      to
      
          visit_type_FOO(v, ..., &ptr, errp);
          ...
          if (!ptr) {
              ...
          }
      
      for functions that set @ptr to non-null / null on success / error.
      
      Eliminate error_propagate() that are now unnecessary.  Delete @err
      that are now unused.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-40-armbru@redhat.com>
      b11a093c
    • Markus Armbruster's avatar
      error: Eliminate error_propagate() with Coccinelle, part 1 · 668f62ec
      Markus Armbruster authored
      
      When all we do with an Error we receive into a local variable is
      propagating to somewhere else, we can just as well receive it there
      right away.  Convert
      
          if (!foo(..., &err)) {
              ...
              error_propagate(errp, err);
              ...
              return ...
          }
      
      to
      
          if (!foo(..., errp)) {
              ...
              ...
              return ...
          }
      
      where nothing else needs @err.  Coccinelle script:
      
          @rule1 forall@
          identifier fun, err, errp, lbl;
          expression list args, args2;
          binary operator op;
          constant c1, c2;
          symbol false;
          @@
               if (
          (
          -        fun(args, &err, args2)
          +        fun(args, errp, args2)
          |
          -        !fun(args, &err, args2)
          +        !fun(args, errp, args2)
          |
          -        fun(args, &err, args2) op c1
          +        fun(args, errp, args2) op c1
          )
                  )
               {
                   ... when != err
                       when != lbl:
                       when strict
          -        error_propagate(errp, err);
                   ... when != err
          (
                   return;
          |
                   return c2;
          |
                   return false;
          )
               }
      
          @rule2 forall@
          identifier fun, err, errp, lbl;
          expression list args, args2;
          expression var;
          binary operator op;
          constant c1, c2;
          symbol false;
          @@
          -    var = fun(args, &err, args2);
          +    var = fun(args, errp, args2);
               ... when != err
               if (
          (
                   var
          |
                   !var
          |
                   var op c1
          )
                  )
               {
                   ... when != err
                       when != lbl:
                       when strict
          -        error_propagate(errp, err);
                   ... when != err
          (
                   return;
          |
                   return c2;
          |
                   return false;
          |
                   return var;
          )
               }
      
          @depends on rule1 || rule2@
          identifier err;
          @@
          -    Error *err = NULL;
               ... when != err
      
      Not exactly elegant, I'm afraid.
      
      The "when != lbl:" is necessary to avoid transforming
      
               if (fun(args, &err)) {
                   goto out
               }
               ...
           out:
               error_propagate(errp, err);
      
      even though other paths to label out still need the error_propagate().
      For an actual example, see sclp_realize().
      
      Without the "when strict", Coccinelle transforms vfio_msix_setup(),
      incorrectly.  I don't know what exactly "when strict" does, only that
      it helps here.
      
      The match of return is narrower than what I want, but I can't figure
      out how to express "return where the operand doesn't use @err".  For
      an example where it's too narrow, see vfio_intx_enable().
      
      Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
      confused by ARMSSE being used both as typedef and function-like macro
      there.  Converted manually.
      
      Line breaks tidied up manually.  One nested declaration of @local_err
      deleted manually.  Preexisting unwanted blank line dropped in
      hw/riscv/sifive_e.c.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-35-armbru@redhat.com>
      668f62ec
  3. Jul 06, 2020
  4. May 18, 2020
  5. May 08, 2020
    • Eric Blake's avatar
      vhdx: Rework truncation logic · dbc636e7
      Eric Blake authored
      
      The vhdx driver uses truncation for image growth, with a special case
      for blocks that already read as zero but which are only being
      partially written.  But with a bit of rearranging, it's just as easy
      to defer the decision on whether truncation resulted in zeroes to the
      actual allocation attempt, reducing the number of places that still
      use bdrv_has_zero_init_truncate.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200428202905.770727-9-eblake@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      dbc636e7
  6. May 05, 2020
  7. May 04, 2020
    • Simran Singhal's avatar
      Compress lines for immediate return · b3ac2b94
      Simran Singhal authored
      
      Compress two lines into a single line if immediate return statement is found.
      
      It also remove variables progress, val, data, ret and sock
      as they are no longer needed.
      
      Remove space between function "mixer_load" and '(' to fix the
      checkpatch.pl error:-
      ERROR: space prohibited between function name and open parenthesis '('
      
      Done using following coccinelle script:
      @@
      local idexpression ret;
      expression e;
      @@
      
      -ret =
      +return
           e;
      -return ret;
      
      Signed-off-by: default avatarSimran Singhal <singhalsimran0@gmail.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Message-Id: <20200401165314.GA3213@simran-Inspiron-5558>
      [lv: in handle_aiocb_write_zeroes_unmap() move "int ret" inside the #ifdef]
      Signed-off-by: default avatarLaurent Vivier <laurent@vivier.eu>
      b3ac2b94
  8. Apr 30, 2020
  9. Apr 29, 2020
    • Philippe Mathieu-Daudé's avatar
      various: Remove suspicious '\' character outside of #define in C code · 78ee6bd0
      Philippe Mathieu-Daudé authored
      
      Fixes the following coccinelle warnings:
      
        $ spatch --sp-file --verbose-parsing  ... \
            scripts/coccinelle/remove_local_err.cocci
        ...
        SUSPICIOUS: a \ character appears outside of a #define at ./target/ppc/translate_init.inc.c:5213
        SUSPICIOUS: a \ character appears outside of a #define at ./target/ppc/translate_init.inc.c:5261
        SUSPICIOUS: a \ character appears outside of a #define at ./target/microblaze/cpu.c:166
        SUSPICIOUS: a \ character appears outside of a #define at ./target/microblaze/cpu.c:167
        SUSPICIOUS: a \ character appears outside of a #define at ./target/microblaze/cpu.c:169
        SUSPICIOUS: a \ character appears outside of a #define at ./target/microblaze/cpu.c:170
        SUSPICIOUS: a \ character appears outside of a #define at ./target/microblaze/cpu.c:171
        SUSPICIOUS: a \ character appears outside of a #define at ./target/microblaze/cpu.c:172
        SUSPICIOUS: a \ character appears outside of a #define at ./target/microblaze/cpu.c:173
        SUSPICIOUS: a \ character appears outside of a #define at ./target/i386/cpu.c:5787
        SUSPICIOUS: a \ character appears outside of a #define at ./target/i386/cpu.c:5789
        SUSPICIOUS: a \ character appears outside of a #define at ./target/i386/cpu.c:5800
        SUSPICIOUS: a \ character appears outside of a #define at ./target/i386/cpu.c:5801
        SUSPICIOUS: a \ character appears outside of a #define at ./target/i386/cpu.c:5802
        SUSPICIOUS: a \ character appears outside of a #define at ./target/i386/cpu.c:5804
        SUSPICIOUS: a \ character appears outside of a #define at ./target/i386/cpu.c:5805
        SUSPICIOUS: a \ character appears outside of a #define at ./target/i386/cpu.c:5806
        SUSPICIOUS: a \ character appears outside of a #define at ./target/i386/cpu.c:6329
        SUSPICIOUS: a \ character appears outside of a #define at ./hw/sd/sdhci.c:1133
        SUSPICIOUS: a \ character appears outside of a #define at ./hw/scsi/scsi-disk.c:3081
        SUSPICIOUS: a \ character appears outside of a #define at ./hw/net/virtio-net.c:1529
        SUSPICIOUS: a \ character appears outside of a #define at ./hw/riscv/sifive_u.c:468
        SUSPICIOUS: a \ character appears outside of a #define at ./dump/dump.c:1895
        SUSPICIOUS: a \ character appears outside of a #define at ./block/vhdx.c:2209
        SUSPICIOUS: a \ character appears outside of a #define at ./block/vhdx.c:2215
        SUSPICIOUS: a \ character appears outside of a #define at ./block/vhdx.c:2221
        SUSPICIOUS: a \ character appears outside of a #define at ./block/vhdx.c:2222
        SUSPICIOUS: a \ character appears outside of a #define at ./block/replication.c:172
        SUSPICIOUS: a \ character appears outside of a #define at ./block/replication.c:173
      
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Signed-off-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
      Message-Id: <20200412223619.11284-2-f4bug@amsat.org>
      Reviewed-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Acked-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      78ee6bd0
  10. Mar 26, 2020
  11. Oct 28, 2019
    • Hanna Reitz's avatar
      block: Add @exact parameter to bdrv_co_truncate() · c80d8b06
      Hanna Reitz authored
      
      We have two drivers (iscsi and file-posix) that (in some cases) return
      success from their .bdrv_co_truncate() implementation if the block
      device is larger than the requested offset, but cannot be shrunk.  Some
      callers do not want that behavior, so this patch adds a new parameter
      that they can use to turn off that behavior.
      
      This patch just adds the parameter and lets the block/io.c and
      block/block-backend.c functions pass it around.  All other callers
      always pass false and none of the implementations evaluate it, so that
      this patch does not change existing behavior.  Future patches take care
      of that.
      
      Suggested-by: default avatarMaxim Levitsky <mlevitsk@redhat.com>
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      Message-id: 20190918095144.955-5-mreitz@redhat.com
      Reviewed-by: default avatarMaxim Levitsky <mlevitsk@redhat.com>
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      c80d8b06
  12. Oct 14, 2019
  13. Aug 19, 2019
  14. Jun 04, 2019
    • Kevin Wolf's avatar
      block: Add BlockBackend.ctx · d861ab3a
      Kevin Wolf authored
      
      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: default avatarKevin Wolf <kwolf@redhat.com>
      d861ab3a
  15. Apr 30, 2019
  16. Nov 05, 2018
  17. Jul 23, 2018
  18. Jun 29, 2018
  19. Jun 15, 2018
    • Markus Armbruster's avatar
    • Markus Armbruster's avatar
      block: Clean up a misuse of qobject_to() in .bdrv_co_create_opts() · 92adf9db
      Markus Armbruster authored
      
      The following pattern occurs in the .bdrv_co_create_opts() methods of
      parallels, qcow, qcow2, qed, vhdx and vpc:
      
          qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
          qobject_unref(qdict);
          qdict = qobject_to(QDict, qobj);
          if (qdict == NULL) {
               ret = -EINVAL;
               goto done;
          }
      
          v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
          [...]
          ret = 0;
      done:
          qobject_unref(qdict);
          [...]
          return ret;
      
      If qobject_to() fails, we return failure without setting errp.  That's
      wrong.  As far as I can tell, it cannot fail here.  Clean it up
      anyway, by removing the useless conversion.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      92adf9db
    • Markus Armbruster's avatar
      block: Fix -blockdev for certain non-string scalars · e5af0da1
      Markus Armbruster authored
      
      Configuration flows through the block subsystem in a rather peculiar
      way.  Configuration made with -drive enters it as QemuOpts.
      Configuration made with -blockdev / blockdev-add enters it as QAPI
      type BlockdevOptions.  The block subsystem uses QDict, QemuOpts and
      QAPI types internally.  The precise flow is next to impossible to
      explain (I tried for this commit message, but gave up after wasting
      several hours).  What I can explain is a flaw in the BlockDriver
      interface that leads to this bug:
      
          $ qemu-system-x86_64 -blockdev node-name=n1,driver=nfs,server.type=inet,server.host=localhost,path=/foo/bar,user=1234
          qemu-system-x86_64: -blockdev node-name=n1,driver=nfs,server.type=inet,server.host=localhost,path=/foo/bar,user=1234: Internal error: parameter user invalid
      
      QMP blockdev-add is broken the same way.
      
      Here's what happens.  The block layer passes configuration represented
      as flat QDict (with dotted keys) to BlockDriver methods
      .bdrv_file_open().  The QDict's members are typed according to the
      QAPI schema.
      
      nfs_file_open() converts it to QAPI type BlockdevOptionsNfs, with
      qdict_crumple() and a qobject input visitor.
      
      This visitor comes in two flavors.  The plain flavor requires scalars
      to be typed according to the QAPI schema.  That's the case here.  The
      keyval flavor requires string scalars.  That's not the case here.
      nfs_file_open() uses the latter, and promptly falls apart for members
      @user, @group, @tcp-syn-count, @readahead-size, @page-cache-size,
      @debug.
      
      Switching to the plain flavor would fix -blockdev, but break -drive,
      because there the scalars arrive in nfs_file_open() as strings.
      
      The proper fix would be to replace the QDict by QAPI type
      BlockdevOptions in the BlockDriver interface.  Sadly, that's beyond my
      reach right now.
      
      Next best would be to fix the block layer to always pass correctly
      typed QDicts to the BlockDriver methods.  Also beyond my reach.
      
      What I can do is throw another hack onto the pile: have
      nfs_file_open() convert all members to string, so use of the keyval
      flavor actually works, by replacing qdict_crumple() by new function
      qdict_crumple_for_keyval_qiv().
      
      The pattern "pass result of qdict_crumple() to
      qobject_input_visitor_new_keyval()" occurs several times more:
      
      * qemu_rbd_open()
      
        Same issue as nfs_file_open(), but since BlockdevOptionsRbd has only
        string members, its only a latent bug.  Fix it anyway.
      
      * parallels_co_create_opts(), qcow_co_create_opts(),
        qcow2_co_create_opts(), bdrv_qed_co_create_opts(),
        sd_co_create_opts(), vhdx_co_create_opts(), vpc_co_create_opts()
      
        These work, because they create the QDict with
        qemu_opts_to_qdict_filtered(), which creates only string scalars.
        The function sports a TODO comment asking for better typing; that's
        going to be fun.  Use qdict_crumple_for_keyval_qiv() to be safe.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      e5af0da1
    • Hanna Reitz's avatar
      block: Add block-specific QDict header · 609f45ea
      Hanna Reitz authored
      
      There are numerous QDict functions that have been introduced for and are
      used only by the block layer.  Move their declarations into an own
      header file to reflect that.
      
      While qdict_extract_subqdict() is in fact used outside of the block
      layer (in util/qemu-config.c), it is still a function related very
      closely to how the block layer works with nested QDicts, namely by
      sometimes flattening them.  Therefore, its declaration is put into this
      header as well and util/qemu-config.c includes it with a comment stating
      exactly which function it needs.
      
      Suggested-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      Message-Id: <20180509165530.29561-7-mreitz@redhat.com>
      [Copyright note tweaked, superfluous includes dropped]
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      609f45ea
  20. May 31, 2018
  21. May 29, 2018
  22. May 15, 2018
    • Eric Blake's avatar
      block: Merge .bdrv_co_writev{,_flags} in drivers · e18a58b4
      Eric Blake authored
      
      We have too many driver callback interfaces; simplify the mess
      somewhat by merging the flags parameter of .bdrv_co_writev_flags()
      into .bdrv_co_writev().  Note that as long as a driver doesn't set
      .supported_write_flags, the flags argument will be 0 and behavior is
      identical.  Also note that the public function bdrv_co_writev() still
      lacks a flags argument; so the driver signature is thus intentionally
      slightly different.  But that's not the end of the world, nor the first
      time that the driver interface differs slightly from the public
      interface.
      
      Ideally, we should be rewriting all of these drivers to use modern
      byte-based interfaces.  But that's a more invasive patch to write
      and audit, compared to the simplification done here.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      e18a58b4
  23. May 04, 2018
  24. Mar 26, 2018
  25. Mar 19, 2018
  26. Mar 09, 2018
Loading