Skip to content
Snippets Groups Projects
  1. Dec 19, 2020
    • Markus Armbruster's avatar
      qobject: Factor JSON writer out of qobject_to_json() · 998da0b1
      Markus Armbruster authored
      
      We have two JSON writers written in C: qobject/qjson.c provides
      qobject_to_json(), and migration/qjson.c provides a more low level
      imperative interface.  They don't share code.  The latter tacitly
      limits numbers to int64_t, and strings contents to characters that
      don't need escaping.
      
      Factor out qobject_to_json()'s JSON writer as qobject/json-writer.c.
      Straightforward, except for numbers: since the writer is to be
      independent of QObject, it can't use qnum_to_string().  Open-code it
      instead.  This is actually an improvement of sorts, because it
      liberates qnum_to_string() from JSON's needs: its JSON-related FIXMEs
      move to the JSON writer, where they belong.
      
      The next commit will replace migration/qjson.c.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201211171152.146877-16-armbru@redhat.com>
      998da0b1
    • Markus Armbruster's avatar
      qobject: Move internals to qobject-internal.h · 80d71121
      Markus Armbruster authored
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201211171152.146877-9-armbru@redhat.com>
      80d71121
    • 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
  2. Aug 24, 2018
  3. Mar 19, 2018
  4. Feb 09, 2018
  5. Nov 17, 2017
  6. Jun 20, 2017
Loading