Skip to content
Snippets Groups Projects
  1. Dec 19, 2020
    • Markus Armbruster's avatar
      qobject: Make qobject_to_json_pretty() take a pretty argument · 6589f459
      Markus Armbruster authored
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201211171152.146877-4-armbru@redhat.com>
      6589f459
    • Markus Armbruster's avatar
      monitor: Use GString instead of QString for output buffer · 20076f4a
      Markus Armbruster authored
      
      GString has a richer set of string operations than QString.  It should
      be preferred to QString except where we need a QObject or reference
      counting.  We don't here.  Switch to GString, and put its richer
      interface to use.
      
      Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201211171152.146877-3-armbru@redhat.com>
      Reviewed-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
      20076f4a
    • Markus Armbruster's avatar
      hmp: Simplify how qmp_human_monitor_command() gets output · 436054e2
      Markus Armbruster authored
      
      Commit 48c043d0 "hmp: human-monitor-command: stop using the Memory
      chardev driver" left us "if string is non-empty, duplicate it, else
      duplicate the empty string".  Meh.  Duplicate it unconditionally.
      
      Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201211171152.146877-2-armbru@redhat.com>
      Reviewed-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
      436054e2
    • Markus Armbruster's avatar
      test-visitor-serialization: Clean up test_primitives() · 28f1c1f6
      Markus Armbruster authored
      
      test_primitives() uses union member intmax_t max to compare the
      integer members.  Unspecified behavior.  Has worked fine for many
      years, though.  Clean it up.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201210161452.2813491-11-armbru@redhat.com>
      28f1c1f6
    • Markus Armbruster's avatar
      test-visitor-serialization: Drop insufficient precision workaround · 2a02c139
      Markus Armbruster authored
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201210161452.2813491-10-armbru@redhat.com>
      2a02c139
    • Markus Armbruster's avatar
      string-output-visitor: Fix to use sufficient precision · 54addb01
      Markus Armbruster authored
      
      The string output visitor should serialize numbers so that the string
      input visitor deserializes them back to the same number.  It fails to
      do so.
      
      print_type_number() uses format %f.  This is prone to nasty rounding
      errors.  For instance, numbers between 0 and 0.0000005 get flushed to
      zero.
      
      We currently use this visitor only for HMP info migrate, info network,
      info qtree, and info memdev.  No double values occur there as far as I
      can tell.
      
      Fix anyway by formatting with %.17g.  17 decimal digits always suffice
      for IEEE double.
      
      See also recent commit "qobject: Fix qnum_to_string() to use
      sufficient precision".
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201210161452.2813491-9-armbru@redhat.com>
      54addb01
    • Markus Armbruster's avatar
      test-string-output-visitor: Cover "unround" number · 7b205a73
      Markus Armbruster authored
      
      This demonstrates rounding error due to insufficient precision: double
      3.1415926535897932 gets converted to JSON 3.141593.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201210161452.2813491-8-armbru@redhat.com>
      7b205a73
    • Markus Armbruster's avatar
      qobject: Fix qnum_to_string() to use sufficient precision · f917eed3
      Markus Armbruster authored
      
      We should serialize numbers to JSON so that they deserialize back to
      the same number.  We fail to do so.
      
      The culprit is qnum_to_string(): it uses format %f with trailing '0'
      trimmed.  Results in pretty output for "nice" numbers, but is prone to
      nasty rounding errors.  For instance, numbers between 0 and 0.0000005
      get flushed to zero.
      
      Where exactly the incorrect rounding can bite is tiresome to gauge.
      Here's my take.
      
      * In QMP output, type 'number':
      
        - query-blockstats value avg_rd_queue_depth
      
        - QMP query-migrate values mbps, cache-miss-rate, encoding-rate,
          busy-rate, compression-rate.
      
        Relatively harmless, I guess.
      
      * In tracing QMP input.  Harmless.
      
      * In qemu-ga output, type 'number': guest-get-users value login-time.
        Harmless.
      
      * In output of HMP qom-get.  Harmless.
      
      Not affected, because double values don't actually occur there (I
      think):
      
      * QMP output, type 'any':
      
        * qom-get value
      
        * qom-list, qom-list-properties value default-value
      
        * query-cpu-model-comparison, query-cpu-model-baseline,
          query-cpu-model-expansion value props.
      
      * qemu-img --output json output.
      
      * "json:" pseudo-filenames generated by bdrv_refresh_filename().
      
      * The rbd block driver's "=keyvalue-pairs" hack.
      
      * In -object help on property default values.  Aside: use of JSON
        feels inappropriate here.
      
      * Output of HMP qom-get.
      
      * Argument conversion to QemuOpts for qdev_device_add() and HMP with
        qemu_opts_from_qdict()
      
        QMP and HMP device_add, virtio-net failover primary creation,
        xen-usb "usb-host" creation, HMP netdev_add, object_add.
      
      * The uses of qobject_input_visitor_new_flat_confused()
      
        As far as I can tell, none of the visited types contain double
        values.
      
      * Dumping ImageInfoSpecific with dump_qobject()
      
      Fix by formatting with %.17g.  17 decimal digits always suffice for
      IEEE double.
      
      The change to expected test output illustrates the effect: the
      rounding errors are gone, but some seemingly "nice" numbers now get
      converted to not so nice strings, e.g. 0.42 to "0.41999999999999998".
      This is because 0.42 is not representable exactly in double.  It's
      more accurate in this example than strictly necessary, though.
      
      If ugly accuracy bothers us, we can we can try using the least number
      of digits that still converts back to the same double.  In this
      example, "0.42" would do.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201210161452.2813491-7-armbru@redhat.com>
      f917eed3
    • Markus Armbruster's avatar
      tests/check-qnum: Cover qnum_to_string() for "unround" argument · 1a907691
      Markus Armbruster authored
      
      qnum_to_string() has a FIXME comment about rounding errors due to
      insufficient precision.  Cover it: 2.718281828459045 gets converted to
      "2.718282".  The next commit will fix it.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201210161452.2813491-6-armbru@redhat.com>
      1a907691
    • Markus Armbruster's avatar
      tests/check-qjson: Replace redundant large_number() · 780df5d4
      Markus Armbruster authored
      
      Move one of large_number()'s three checks to uint_number(), and the
      other two to float_number().
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201210161452.2813491-5-armbru@redhat.com>
      780df5d4
    • Markus Armbruster's avatar
      tests/check-qjson: Cover number 2^63 · 4aea8833
      Markus Armbruster authored
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201210161452.2813491-4-armbru@redhat.com>
      4aea8833
    • Markus Armbruster's avatar
      tests/check-qjson: Examine QNum more thoroughly · 1a68eb8c
      Markus Armbruster authored
      
      simple_number() checks only qnum_get_try_int().  Also check
      qnum_get_try_uint() and qnum_get_double().
      
      float_number() checks only qnum_get_double().  Also check
      qnum_get_try_int() and qnum_get_try_uint().
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201210161452.2813491-3-armbru@redhat.com>
      1a68eb8c
    • Markus Armbruster's avatar
      tests/check-qjson: Don't skip funny QNumber to JSON conversions · 3953f826
      Markus Armbruster authored
      
      simple_number() and float_number() convert from JSON to QNumber and
      back.
      
      simple_number() tests "-0", but skips the conversion back to JSON,
      because it yields "0", not "-0".  Works as intended, so better cover
      it: don't skip, but expect the funny result.
      
      float_number() tests "-32.20e-10", but skips the conversion back to
      JSON, because it yields "-0".  This is a known bug in
      qnum_to_string(), marked FIXME there.  Cover the bug: don't skip, but
      expect the funny result.
      
      While there, switch from g_assert() to g_assert_cmpstr() & friends for
      friendlier test failures.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201210161452.2813491-2-armbru@redhat.com>
      3953f826
    • Eric Blake's avatar
      qapi: Use QAPI_LIST_PREPEND() where possible · 54aa3de7
      Eric Blake authored
      
      Anywhere we create a list of just one item or by prepending items
      (typically because order doesn't matter), we can use
      QAPI_LIST_PREPEND().  But places where we must keep the list in order
      by appending remain open-coded until later patches.
      
      Note that as a side effect, this also performs a cleanup of two minor
      issues in qga/commands-posix.c: the old code was performing
       new = g_malloc0(sizeof(*ret));
      which 1) is confusing because you have to verify whether 'new' and
      'ret' are variables with the same type, and 2) would conflict with C++
      compilation (not an actual problem for this file, but makes
      copy-and-paste harder).
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20201113011340.463563-5-eblake@redhat.com>
      Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Acked-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      [Straightforward conflicts due to commit a8aa94b5 "qga: update
      schema for guest-get-disks 'dependents' field" and commit a10b453a
      "target/mips: Move mips_cpu_add_definition() from helper.c to cpu.c"
      resolved.  Commit message tweaked.]
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      54aa3de7
    • Eric Blake's avatar
      migration: Refactor migrate_cap_add · eaedde52
      Eric Blake authored
      
      Instead of taking a list parameter and returning a new head at a
      distance, just return the new item for the caller to insert into a
      list via QAPI_LIST_PREPEND.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20201113011340.463563-4-eblake@redhat.com>
      Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      eaedde52
    • Eric Blake's avatar
      rocker: Revamp fp_port_get_info · fe4d7e33
      Eric Blake authored
      
      Instead of modifying the value member of a list element passed as a
      parameter, and open-coding the manipulation of that list, it's nicer
      to just return a freshly allocated value to be prepended to a list
      using QAPI_LIST_PREPEND.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20201113011340.463563-3-eblake@redhat.com>
      Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      fe4d7e33
  2. Dec 18, 2020
Loading