Skip to content
Snippets Groups Projects
  1. Jun 02, 2023
    • Eric Blake's avatar
      test-cutils: Prepare for upcoming semantic change in qemu_strtosz · edafce69
      Eric Blake authored
      
      A quick search for 'qemu_strtosz' in the code base shows that outside
      of the testsuite, the ONLY place that passes a non-NULL pointer to
      @endptr of any variant of a size parser is in hmp.c (the 'o' parser of
      monitor_parse_arguments), and that particular caller warns of
      "extraneous characters at the end of line" unless the trailing bytes
      are purely whitespace.  Thus, it makes no semantic difference at the
      high level whether we parse "1.5e1k" as "1" + ".5e1" + "k" (an attempt
      to use scientific notation in strtod with a scaling suffix of 'k' with
      no trailing junk, but which qemu_strtosz says should fail with
      EINVAL), or as "1.5e" + "1k" (a valid size with scaling suffix of 'e'
      for exabytes, followed by two junk bytes) - either way, any user
      passing such a string will get an error message about a parse failure.
      
      However, an upcoming patch to qemu_strtosz will fix other corner case
      bugs in handling the fractional portion of a size, and in doing so, it
      is easier to declare that qemu_strtosz() itself stops parsing at the
      first 'e' rather than blindly consuming whatever strtod() will
      recognize.  Once that is fixed, the difference will be visible at the
      low level (getting a valid parse with trailing garbage when @endptr is
      non-NULL, while continuing to get -EINVAL when @endptr is NULL); this
      is easier to demonstrate by moving the affected strings from
      test_qemu_strtosz_invalid() (which declares them as always -EINVAL) to
      test_qemu_strtosz_trailing() (where @endptr affects behavior, for now
      with FIXME comments).
      
      Note that a similar argument could be made for having "0x1.5" or
      "0x1M" parse as 0x1 with ".5" or "M" as trailing junk, instead of
      blindly treating it as -EINVAL; however, as these cases do not suffer
      from the same problems as floating point, they are not worth changing
      at this time.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarHanna Czenczek <hreitz@redhat.com>
      Message-Id: <20230522190441.64278-11-eblake@redhat.com>
      edafce69
    • Eric Blake's avatar
      test-cutils: Add coverage of qemu_strtod · 759573d0
      Eric Blake authored
      
      It's hard to tweak code for consistency if I can't prove what will or
      won't break from those tweaks.  Time to add unit tests for
      qemu_strtod() and qemu_strtod_finite().
      
      Among other things, I wrote a check whether we have C99 semantics for
      strtod("0x1") (which MUST parse hex numbers) rather than C89 (which
      must stop parsing at 'x').  These days, I suspect that is okay; but if
      it fails CI checks, knowing the difference will help us decide what we
      want to do about it.  Note that C2x, while not final at the time of
      this patch, has been considering whether to make strtol("0b1") parse
      as 1 with no slop instead of the C17 parse of 0 with slop "b1"; that
      decision may also bleed over to strtod().  But for now, I didn't think
      it worth adding unit tests on that front (to strtol or strtod) as
      things may still change.
      
      Likewise, there are plenty more corner cases of strtod proper that I
      don't explicitly test here, but there are enough unit tests added here
      that it covers all the branches reached in our wrappers.  In
      particular, it demonstrates the difference on when *value is left
      uninitialized, which an upcoming patch will normalize.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarHanna Czenczek <hreitz@redhat.com>
      Message-Id: <20230522190441.64278-10-eblake@redhat.com>
      759573d0
    • Eric Blake's avatar
      cutils: Allow NULL endptr in parse_uint() · 52d606aa
      Eric Blake authored
      
      All the qemu_strto*() functions permit a NULL endptr, just like their
      libc counterparts, leaving parse_uint() as the oddball that caused
      SEGFAULT on NULL and required the user to call parse_uint_full()
      instead.  Relax things for consistency, even though the testsuite is
      the only impacted caller.  Add one more unit test to ensure even
      parse_uint_full(NULL, 0, &value) works.  This also fixes our code to
      uniformly favor EINVAL over ERANGE when both apply.
      
      Also fixes a doc mismatch @v vs. a parameter named value.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarHanna Czenczek <hreitz@redhat.com>
      Message-Id: <20230522190441.64278-9-eblake@redhat.com>
      52d606aa
    • Eric Blake's avatar
      cutils: Adjust signature of parse_uint[_full] · bd1386cc
      Eric Blake authored
      
      It's already confusing that we have two very similar functions for
      wrapping the parse of a 64-bit unsigned value, differing mainly on
      whether they permit leading '-'.  Adjust the signature of parse_uint()
      and parse_uint_full() to be like all of qemu_strto*(): put the result
      parameter last, use the same types (uint64_t and unsigned long long
      have the same width, but are not always the same type), and mark
      endptr const (this latter change only affects the rare caller of
      parse_uint).  Adjust all callers in the tree.
      
      While at it, note that since cutils.c already includes:
      
          QEMU_BUILD_BUG_ON(sizeof(int64_t) != sizeof(long long));
      
      we are guaranteed that the result of parse_uint* cannot exceed
      UINT64_MAX (or the build would have failed), so we can drop
      pre-existing dead comparisons in opts-visitor.c that were never false.
      
      Reviewed-by: default avatarHanna Czenczek <hreitz@redhat.com>
      Message-Id: <20230522190441.64278-8-eblake@redhat.com>
      [eblake: Drop dead code spotted by Markus]
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      bd1386cc
    • Eric Blake's avatar
      cutils: Document differences between parse_uint and qemu_strtou64 · 84760bbc
      Eric Blake authored
      
      These two functions are subtly different, and not just because of
      swapped parameter order.  It took me adding better unit tests to
      figure out why.  Document the differences to make it more obvious to
      developers trying to pick which one to use, as well as to aid in
      upcoming semantic changes.
      
      While touching the documentation, adjust a mis-statement: parse_uint
      does not return -EINVAL on invalid base, but assert()s, like all the
      other qemu_strto* functions that take a base argument.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarHanna Czenczek <hreitz@redhat.com>
      Message-Id: <20230522190441.64278-7-eblake@redhat.com>
      84760bbc
    • Eric Blake's avatar
      cutils: Fix wraparound parsing in qemu_strtoui · 56ddafde
      Eric Blake authored
      
      While we were matching 32-bit strtol in qemu_strtoi, our use of a
      64-bit parse was leaking through for some inaccurate answers in
      qemu_strtoui in comparison to a 32-bit strtoul (see the unit test for
      examples).  The comment for that function even described what we have
      to do for a correct parse, but didn't implement it correctly: since
      strtoull checks for overflow against the wrong values and then
      negates, we have to temporarily undo negation before checking for
      overflow against our desired value.
      
      Our int wrappers would be a lot easier to write if libc had a
      guaranteed 32-bit parser even on platforms with 64-bit long.
      
      Whether we parse C2x binary strings like "0b1000" is currently up to
      what libc does; our unit tests intentionally don't cover that at the
      moment, though.
      
      Fixes: 473a2a33 ("cutils: add qemu_strtoi & qemu_strtoui parsers for int/unsigned int types", v2.12.0)
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      CC: qemu-stable@nongnu.org
      Message-Id: <20230522190441.64278-6-eblake@redhat.com>
      Reviewed-by: default avatarHanna Czenczek <hreitz@redhat.com>
      56ddafde
    • Eric Blake's avatar
      test-cutils: Test more integer corner cases · 3069522b
      Eric Blake authored
      We have quite a few undertested and underdocumented integer parsing
      corner cases.  To ensure that any changes we make in the code are
      intentional rather than accidental semantic changes, it is time to add
      more unit tests of existing behavior.
      
      In particular, this demonstrates that parse_uint() and qemu_strtou64()
      behave differently.  For "-0", it's hard to argue why parse_uint needs
      to reject it (it's not a negative integer), but the documentation sort
      of mentions it; but it is intentional that all other negative values
      are treated as ERANGE with value 0 (compared to qemu_strtou64()
      treating "-2" as success and UINT64_MAX-1, for example).
      
      Also, when mixing overflow/underflow with a check for no trailing
      junk, parse_uint_full favors ERANGE over EINVAL, while qemu_strto[iu]*
      favor EINVAL.  This behavior is outside the C standard, so we can pick
      whatever we want, but it would be nice to be consistent.
      
      Note that C requires that "9223372036854775808" fail strtoll() with
      ERANGE/INT64_MAX, but "-9223372036854775808" pass with INT64_MIN; we
      weren't testing this.  For strtol(), the behavior depends on whether
      long is 32- or 64-bits (the cutoff point either being the same as
      strtoll() or at "-2147483648").  Meanwhile, C is clear that
      "-18446744073709551615" pass stroull() (but not strtoll) with value 1,
      even though we want it to fail parse_uint().  And although
      qemu_strtoui() has no C counterpart, it makes more sense if we design
      it like 32-bit strtoul() (that is, where "-4294967296" be an alternate
      acceptable spelling for "1", but "-0xffffffff00000001" should be
      treated as overflow and return 0xffffffff rather than 1).  We aren't
      there yet, so some of the tests added in this patch have FIXME
      comments.
      
      However, note that C2x will (likely) be adding a SILENT semantic
      change, where C17 strtol("0b1", &ep, 2) returns 0 with ep="b1", but
      C2x will have it return 1 with ep="".  I did not feel like adding
      testing for those corner cases, in part because the next version of C
      is not standard and libc support for binary parsing is not yet
      wide-spread (as of this patch, glibc.git still misparses bare "0b":
      https://sourceware.org/bugzilla/show_bug.cgi?id=30371
      
      ).
      
      Message-Id: <20230522190441.64278-5-eblake@redhat.com>
      [eblake: fix a few typos spotted by Hanna]
      Reviewed-by: default avatarHanna Czenczek <hreitz@redhat.com>
      [eblake: fix typo on platforms with 32-bit long]
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      3069522b
    • Eric Blake's avatar
      test-cutils: Test integral qemu_strto* value on failures · d326d03b
      Eric Blake authored
      
      We are inconsistent on the contents of *value after a strto* parse
      failure.  I found the following behaviors:
      
      - parse_uint() and parse_uint_full(), which document that *value is
        slammed to 0 on all EINVAL failures and 0 or UINT_MAX on ERANGE
        failures, and has unit tests for that (note that parse_uint requires
        non-NULL endptr, and does not fail with EINVAL for trailing junk)
      
      - qemu_strtosz(), which leaves *value untouched on all failures (both
        EINVAL and ERANGE), and has unit tests but not documentation for
        that
      
      - qemu_strtoi() and other integral friends, which document *value on
        ERANGE failures but is unspecified on EINVAL (other than implicitly
        by comparison to libc strto*); there, *value is untouched for NULL
        string, slammed to 0 on no conversion, and left at the prefix value
        on NULL endptr; unit tests do not consistently check the value
      
      - qemu_strtod(), which documents *value on ERANGE failures but is
        unspecified on EINVAL; there, *value is untouched for NULL string,
        slammed to 0.0 for no conversion, and left at the prefix value on
        NULL endptr; there are no unit tests (other than indirectly through
        qemu_strtosz)
      
      - qemu_strtod_finite(), which documents *value on ERANGE failures but
        is unspecified on EINVAL; there, *value is left at the prefix for
        'inf' or 'nan' and untouched in all other cases; there are no unit
        tests (other than indirectly through qemu_strtosz)
      
      Upcoming patches will change behaviors for consistency, but it's best
      to first have more unit test coverage to see the impact of those
      changes.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarHanna Czenczek <hreitz@redhat.com>
      Message-Id: <20230522190441.64278-4-eblake@redhat.com>
      d326d03b
    • Eric Blake's avatar
      test-cutils: Use g_assert_cmpuint where appropriate · 3b4790d4
      Eric Blake authored
      When debugging test failures, seeing unsigned values as large positive
      values rather than negative values matters (assuming glib 2.78+; given
      that I just fixed a bug in glib 2.76 [1] where g_assert_cmpuint
      displays signed instead of unsigned values).  No impact when the test
      is passing, but using a consistent style will matter more in upcoming
      test additions.  Also, some tests are better with cmphex.
      
      While at it, fix some spacing and minor typing issues spotted nearby.
      
      [1] https://gitlab.gnome.org/GNOME/glib/-/issues/2997
      
      
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarHanna Czenczek <hreitz@redhat.com>
      Message-Id: <20230522190441.64278-3-eblake@redhat.com>
      3b4790d4
    • Eric Blake's avatar
      test-cutils: Avoid g_assert in unit tests · 3a592592
      Eric Blake authored
      glib documentation[1] is clear: g_assert() should be avoided in unit
      tests because it is ineffective if G_DISABLE_ASSERT is defined; unit
      tests should stick to constructs based on g_assert_true() instead.
      Note that since commit 262a69f4, we intentionally state that you
      cannot define G_DISABLE_ASSERT while building qemu; but our code can
      be copied to other projects without that restriction, so we should be
      consistent.
      
      For most of the replacements in this patch, using g_assert_cmpstr()
      would be a regression in quality - although it would helpfully display
      the string contents of both pointers on test failure, here, we really
      do care about pointer equality, not just string content equality.  But
      when a NULL pointer is expected, g_assert_null works fine.
      
      [1] https://libsoup.org/glib/glib-Testing.html#g-assert
      
      
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarHanna Czenczek <hreitz@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@linaro.org>
      Message-Id: <20230522190441.64278-2-eblake@redhat.com>
      3a592592
    • Eric Blake's avatar
      qcow2: Explicit mention of padding bytes · 5cf899e2
      Eric Blake authored
      
      Although we already covered the need for padding bytes with our
      changes in commit 3ae3fcfa, commit 66fcbca5 (both v5.0.0) added one
      byte and relied on the rest of the text for implicitly covering 7
      padding bytes.  For consistency with other parts of the header (such
      as the header extension format listing padding from n - m, or the
      snapshot table entry listing variable padding), we might as well call
      out the remaining 7 bytes as padding until such time (as any) as they
      gain another meaning.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      CC: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
      Message-Id: <20230522184631.47211-1-eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
      5cf899e2
    • Eric Blake's avatar
      iotests: Fix test 104 under NBD · 43074635
      Eric Blake authored
      
      In the past, commit a231cb27 ("iotests: Fix 104 for NBD", v2.3.0)
      added an additional filter to _filter_img_info to rewrite NBD URIs
      into the expected output form.  This recently broke when we tweaked
      tests to run in a per-format directory, which did not match the regex,
      because _img_info itself is now already changing
      SOCK_DIR=/tmp/tmpphjfbphd/raw-nbd-104 into
      /tmp/tmpphjfbphd/IMGFMT-nbd-104 prior to _img_info_filter getting a
      chance to further filter things.
      
      While diagnosing the problem, I also noticed some filter lines
      rendered completely useless by a typo when we switched from TCP to
      Unix sockets for NBD (in shell, '\\+' is different from "\\+" (one
      gives two backslash to the regex, matching the literal 2-byte sequence
      <\+> after a single digit; the other gives one backslash to the regex,
      as the metacharacter \+ to match one or more of <[0-9]>); since the
      literal string <nbd://127.0.0.1:0\+> is not a valid URI, that regex
      hasn't been matching anything for years so it is fine to just drop it
      rather than fix the typo.
      
      Fixes: f3923a72 ("iotests: Switch nbd tests to use Unix rather than TCP", v4.2.0)
      Fixes: 5ba7db09 ("iotests: always use a unique sub-directory per test", v8.0.0)
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20230519150216.2599189-1-eblake@redhat.com>
      Reviewed-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      43074635
    • Richard Henderson's avatar
      Merge tag 'migration-20230601-pull-request' of https://gitlab.com/juan.quintela/qemu into staging · a86d7b9e
      Richard Henderson authored
      Migration Pull request (20230601)
      
      Hi
      
      In this series:
      - improve background migration (fiona)
      - improve vmstate failure states (vladimir)
      - dropped all the RDMA cleanups
      
      Please, apply.
      
      # -----BEGIN PGP SIGNATURE-----
      #
      # iQIzBAABCAAdFiEEGJn/jt6/WMzuA0uC9IfvGFhy1yMFAmR5LAoACgkQ9IfvGFhy
      # 1yPOuxAA5QzUfswCIWehrkY8FApDjsecPDq5R6hS1p5pDZkHTF5y6j49J93I65o2
      # E4qr4l0+DJvBvnxTW29JQ1i0RPqJHnJBFC9Ib4o0NaA/7iRP1sTwYxIN4wWZz6H/
      # pqG3oQC0WPPqgj9tHSgDW4TNkFjETYaezTN8nddNmyiaO9UxNuR5ZKbeYMroVlfp
      # KbnAYfXV6CyXKUZFT32BYcajYBDZAqBCO6y3gEn77KPlT1/TqnucoYEVuNudq5SE
      # jeCamTzoAQ6SIRFM/eY+aASxdsSryqDS/WLqBFsleXs1kkJ6mkDnNels4HqS+xs9
      # p2Vhv/59ktoC57XsRgTgzEklAaSHunZivcQkc5szyGVE5TZyKtWg8WhA6rvlqbjK
      # lb3kKpvtVi73+pAWU0hhKFdnCrB6ieCHI70CJ5mpiIu3MzLUyrNJOK4FoKNoJDOD
      # Dp45DK+W/EMg51pXyHJZZqHM1p0GGj0fmhv5T05nJ590fIWV4iqDdHFxsMZ9vEPN
      # iEvAB7/pXz+yECznDFrp2e047rshOGaKKNSW3zl3/7D32Ds2FKur76dL4BoymztW
      # HHLxmRWn8HmHMoKYLoawWVmCBsDqy8BFct+rHbA6h/0nSCPYIUCmMrSYVqajUbXD
      # Ulkh4KNQGoBCzp5Toa0dYEXVc891wVOw4k8PTARwf2OYskSkT88=
      # =Km5X
      # -----END PGP SIGNATURE-----
      # gpg: Signature made Thu 01 Jun 2023 04:38:50 PM PDT
      # gpg:                using RSA key 1899FF8EDEBF58CCEE034B82F487EF185872D723
      # gpg: Good signature from "Juan Quintela <quintela@redhat.com>" [unknown]
      # gpg:                 aka "Juan Quintela <quintela@trasno.org>" [unknown]
      # gpg: WARNING: This key is not certified with a trusted signature!
      # gpg:          There is no indication that the signature belongs to the owner.
      # Primary key fingerprint: 1899 FF8E DEBF 58CC EE03  4B82 F487 EF18 5872 D723
      
      * tag 'migration-20230601-pull-request' of https://gitlab.com/juan.quintela/qemu
      
      :
        migration: stop tracking ram writes when cancelling background migration
        migration: restore vmstate on migration failure
        migration: switch from .vm_was_running to .vm_old_state
        runstate: drop unused runstate_store()
        migration: never fail in global_state_store()
        runstate: add runstate_get()
      
      Signed-off-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      a86d7b9e
  2. Jun 01, 2023
Loading