Skip to content
Snippets Groups Projects
  1. Dec 18, 2020
  2. Oct 02, 2020
    • Dr. David Alan Gilbert's avatar
      qemu-io-cmds: Simplify help_oneline · da16f4b8
      Dr. David Alan Gilbert authored
      help_oneline is declared and starts as:
      
        static void help_oneline(const char *cmd, const cmdinfo_t *ct)
        {
            if (cmd) {
                printf("%s ", cmd);
            } else {
                printf("%s ", ct->name);
                if (ct->altname) {
                    printf("(or %s) ", ct->altname);
                }
            }
      
      However, there are only two routes to help_oneline being called:
      
         help_f -> help_all -> help_oneline(ct->name, ct)
      
         help_f -> help_onecmd(argv[1], ct)
      
      In the first case, 'cmd' and 'ct->name' are the same thing,
      so it's impossible for the if (cmd) to be false and then validly
      print ct->name - this is upsetting gcc
      ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96739
      
       )
      
      In the second case, cmd is argv[1] and we know we've got argv[1]
      so again (cmd) is non-NULL.
      
      Simplify help_oneline by just printing cmd.
      (Also strengthen argc check just to be pedantic)
      
      Signed-off-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
      Message-Id: <20200824102914.105619-1-dgilbert@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      da16f4b8
  3. Jul 28, 2020
  4. Apr 30, 2020
  5. Oct 28, 2019
  6. Sep 13, 2019
  7. Sep 03, 2019
  8. Jun 12, 2019
    • Alex Bennée's avatar
      qemu-io-cmds: use clock_gettime for benchmarking · 50290c00
      Alex Bennée authored
      
      The previous use of gettimeofday() ran into undefined behaviour when
      we ended up doing a div 0 for a very short operation. This is because
      gettimeofday only works at the microsecond level as well as being
      prone to discontinuous jumps in system time. Using clock_gettime with
      CLOCK_MONOTONIC gives greater precision and alleviates some of the
      potential problems with time jumping around.
      
      We could use CLOCK_MONOTONIC_RAW to avoid being tripped up by NTP and
      adjtime but that is Linux specific so I decided it would do for now.
      
      Signed-off-by: default avatarAlex Bennée <alex.bennee@linaro.org>
      50290c00
  9. May 20, 2019
  10. Apr 18, 2019
  11. Mar 26, 2019
  12. Mar 12, 2019
  13. Feb 11, 2019
  14. Jan 30, 2019
    • Richard W.M. Jones's avatar
      qemu-io: Add generic function for reinitializing optind. · d339d766
      Richard W.M. Jones authored
      
      On FreeBSD 11.2:
      
        $ nbdkit memory size=1M --run './qemu-io -f raw -c "aio_write 0 512" $nbd'
        Parsing error: non-numeric argument, or extraneous/unrecognized suffix -- aio_write
      
      After main option parsing, we reinitialize optind so we can parse each
      command.  However reinitializing optind to 0 does not work on FreeBSD.
      What happens when you do this is optind remains 0 after the option
      parsing loop, and the result is we try to parse argv[optind] ==
      argv[0] == "aio_write" as if it was the first parameter.
      
      The FreeBSD manual page says:
      
        In order to use getopt() to evaluate multiple sets of arguments, or to
        evaluate a single set of arguments multiple times, the variable optreset
        must be set to 1 before the second and each additional set of calls to
        getopt(), and the variable optind must be reinitialized.
      
      (From the rest of the man page it is clear that optind must be
      reinitialized to 1).
      
      The glibc man page says:
      
        A program that scans multiple argument vectors,  or  rescans  the  same
        vector  more than once, and wants to make use of GNU extensions such as
        '+' and '-' at  the  start  of  optstring,  or  changes  the  value  of
        POSIXLY_CORRECT  between scans, must reinitialize getopt() by resetting
        optind to 0, rather than the traditional value of 1.  (Resetting  to  0
        forces  the  invocation  of  an  internal  initialization  routine that
        rechecks POSIXLY_CORRECT and checks for GNU extensions in optstring.)
      
      This commit introduces an OS-portability function called
      qemu_reset_optind which provides a way of resetting optind that works
      on FreeBSD and platforms that use optreset, while keeping it the same
      as now on other platforms.
      
      Note that the qemu codebase sets optind in many other places, but in
      those other places it's setting a local variable and not using getopt.
      This change is only needed in places where we are using getopt and the
      associated global variable optind.
      
      Signed-off-by: default avatarRichard W.M. Jones <rjones@redhat.com>
      Message-id: 20190118101114.11759-2-rjones@redhat.com
      Reviewed-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      d339d766
  15. Dec 14, 2018
  16. Nov 05, 2018
  17. Oct 01, 2018
  18. Jun 11, 2018
  19. Feb 09, 2018
  20. Dec 22, 2017
  21. Oct 26, 2017
    • Eric Blake's avatar
      qemu-io: Relax 'alloc' now that block-status doesn't assert · f0a9c18f
      Eric Blake authored
      
      Previously, the alloc command required that input parameters be
      sector-aligned and clamped to 32 bits, because the underlying
      bdrv_is_allocated used a 32-bit parameter and asserted aligned
      inputs.  But now that we have fixed block status to report a
      64-bit bytes value, and to properly round requests on behalf of
      guests, we can pass any values, and can use qemu-io to add
      coverage that our rounding is correct regardless of the guest
      alignment constraints.
      
      Update iotest 177 to intentionally probe block status at
      unaligned boundaries as well as with a bytes value that does not
      map to 32-bit sectors, which also required tweaking the image
      prep to leave an unallocated portion to the image under test.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      f0a9c18f
  22. Sep 26, 2017
    • Kevin Wolf's avatar
      qemu-io: Drop write permissions before read-only reopen · f3adefb2
      Kevin Wolf authored
      
      qemu-io provides a 'reopen' command that allows switching from writable
      to read-only access. We need to make sure that we don't try to keep
      write permissions to a BlockBackend that becomes read-only, otherwise
      things are going to fail.
      
      This requires a bdrv_drain() call because otherwise in-flight AIO
      write requests could issue new internal requests while the permission
      has already gone away, which would cause assertion failures. Draining
      the queue doesn't break AIO requests in any new way, bdrv_reopen() would
      drain it anyway only a few lines later.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarFam Zheng <famz@redhat.com>
      f3adefb2
  23. Aug 08, 2017
  24. Jul 11, 2017
  25. Jul 10, 2017
    • Eric Blake's avatar
      block: Make bdrv_is_allocated() byte-based · d6a644bb
      Eric Blake authored
      
      We are gradually moving away from sector-based interfaces, towards
      byte-based.  In the common case, allocation is unlikely to ever use
      values that are not naturally sector-aligned, but it is possible
      that byte-based values will let us be more precise about allocation
      at the end of an unaligned file that can do byte-based access.
      
      Changing the signature of the function to use int64_t *pnum ensures
      that the compiler enforces that all callers are updated.  For now,
      the io.c layer still assert()s that all callers are sector-aligned
      on input and that *pnum is sector-aligned on return to the caller,
      but that can be relaxed when a later patch implements byte-based
      block status.  Therefore, this code adds usages like
      DIV_ROUND_UP(,BDRV_SECTOR_SIZE) to callers that still want aligned
      values, where the call might reasonbly give non-aligned results
      in the future; on the other hand, no rounding is needed for callers
      that should just continue to work with byte alignment.
      
      For the most part this patch is just the addition of scaling at the
      callers followed by inverse scaling at bdrv_is_allocated().  But
      some code, particularly bdrv_commit(), gets a lot simpler because it
      no longer has to mess with sectors; also, it is now possible to pass
      NULL if the caller does not care how much of the image is allocated
      beyond the initial offset.  Leave comments where we can further
      simplify once a later patch eliminates the need for sector-aligned
      requests through bdrv_is_allocated().
      
      For ease of review, bdrv_is_allocated_above() will be tackled
      separately.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      d6a644bb
  26. Jun 26, 2017
  27. May 11, 2017
  28. Apr 28, 2017
  29. Apr 11, 2017
  30. Apr 03, 2017
    • Peter Maydell's avatar
      qemu-io-cmds: Assert that global and nofile commands don't use ct->perms · 6aabeb58
      Peter Maydell authored
      
      It would be a bug for a command with the CMD_NOFILE_OK or
      CMD_FLAG_GLOBAL flags set to also set the ct->perms field,
      because the former says "OK for a file not to be open"
      but the latter is a check on a file.
      
      Add an assertion in qemuio_add_command() so we can catch that
      sort of buggy command definition immediately rather than it
      being a bug that only manifests when a particular set of
      command line options is used.
      
      (Coverity gets confused about this (CID 1371723) and reports
      that we might dereference a NULL blk pointer in this case,
      because it can't tell that that code path never happens with
      the cmdinfo_t that we have. This commit won't help unconfuse
      it, but it does fix the underlying issue.)
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Message-id: 1490967529-4767-1-git-send-email-peter.maydell@linaro.org
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      6aabeb58
  31. Feb 28, 2017
  32. Feb 23, 2017
Loading