1. 05 1月, 2015 1 次提交
    • M
      qapi: add visit_start_union and visit_end_union · 96c6cf6d
      Michael Roth 提交于
      In some cases an input visitor might bail out on filling out a
      struct for various reasons, such as missing fields when running
      in strict mode. In the case of a QAPI Union type, this may lead
      to cases where the .kind field which encodes the union type
      is uninitialized. Subsequently, other visitors, such as the
      dealloc visitor, may use this .kind value as if it were
      initialized, leading to assumptions about the union type which
      in this case may lead to segfaults. For example, freeing an
      integer value.
      
      However, we can generally rely on the fact that the always-present
      .data void * field that we generate for these union types will
      always be NULL in cases where .kind is uninitialized (at least,
      there shouldn't be a reason where we'd do this purposefully).
      
      So pass this information on to Visitor implementation via these
      optional start_union/end_union interfaces so this information
      can be used to guard against the situation above. We will make
      use of this information in a subsequent patch for the dealloc
      visitor.
      
      Cc: qemu-stable@nongnu.org
      Reported-by: NFam Zheng <famz@redhat.com>
      Suggested-by: NPaolo Bonzini <pbonzini@redhat.com>
      Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NMichael Roth <mdroth@linux.vnet.ibm.com>
      Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
      (cherry picked from commit cee2dedb)
      Signed-off-by: NMichael Roth <mdroth@linux.vnet.ibm.com>
      96c6cf6d
  2. 16 5月, 2014 3 次提交
    • M
      qapi: Replace uncommon use of the error API by the common one · 297a3646
      Markus Armbruster 提交于
      We commonly use the error API like this:
      
          err = NULL;
          foo(..., &err);
          if (err) {
              goto out;
          }
          bar(..., &err);
      
      Every error source is checked separately.  The second function is only
      called when the first one succeeds.  Both functions are free to pass
      their argument to error_set().  Because error_set() asserts no error
      has been set, this effectively means they must not be called with an
      error set.
      
      The qapi-generated code uses the error API differently:
      
          // *errp was initialized to NULL somewhere up the call chain
          frob(..., errp);
          gnat(..., errp);
      
      Errors accumulate in *errp: first error wins, subsequent errors get
      dropped.  To make this work, the second function does nothing when
      called with an error set.  Requires non-null errp, or else the second
      function can't see the first one fail.
      
      This usage has also bled into visitor tests, and two device model
      object property getters rtc_get_date() and balloon_stats_get_all().
      
      With the "accumulate" technique, you need fewer error checks in
      callers, and buy that with an error check in every callee.  Can be
      nice.
      
      However, mixing the two techniques is confusing.  You can't use the
      "accumulate" technique with functions designed for the "check
      separately" technique.  You can use the "check separately" technique
      with functions designed for the "accumulate" technique, but then
      error_set() can't catch you setting an error more than once.
      
      Standardize on the "check separately" technique for now, because it's
      overwhelmingly prevalent.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
      297a3646
    • M
      qapi: Replace start_optional()/end_optional() by optional() · e2cd0f4f
      Markus Armbruster 提交于
      Semantics of end_optional() differ subtly from the other end_FOO()
      callbacks: when start_FOO() succeeds, the matching end_FOO() gets
      called regardless of what happens in between.  end_optional() gets
      called only when everything in between succeeds as well.  Entirely
      undocumented, like all of the visitor API.
      
      The only user of Visitor Callback end_optional() never did anything,
      and was removed in commit 9f9ab465.
      
      I'm about to clean up error handling in the generated visitor code,
      and end_optional() is in my way.  No users mean no test cases, and
      making non-trivial cleanup transformations without test cases doesn't
      strike me as a good idea.
      
      Drop end_optional(), and rename start_optional() to optional().  We
      can always go back to a pair of callbacks when we have an actual need.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
      e2cd0f4f
    • M
      qapi: Remove unused Visitor callbacks start_handle(), end_handle() · cbc95538
      Markus Armbruster 提交于
      These have never been called or implemented by anything, and their
      intended use is undocumented, like all of the visitor API.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
      cbc95538
  3. 30 7月, 2013 1 次提交
  4. 27 7月, 2013 2 次提交
    • K
      qapi: Anonymous unions · 69dd62df
      Kevin Wolf 提交于
      The discriminator for anonymous unions is the data type. This allows to
      have a union type that allows both of these:
      
          { 'file': 'my_existing_block_device_id' }
          { 'file': { 'filename': '/tmp/mydisk.qcow2', 'read-only': true } }
      
      Unions like this are specified in the schema with an empty dict as
      discriminator. For this example you could take:
      
          { 'union': 'BlockRef',
            'discriminator': {},
            'data': { 'definition': 'BlockOptions',
                      'reference': 'str' } }
          { 'type': 'ExampleObject',
            'data: { 'file': 'BlockRef' } }
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      69dd62df
    • K
      qapi: Add visitor for implicit structs · 761d524d
      Kevin Wolf 提交于
      These can be used when an embedded struct is parsed and members not
      belonging to the struct may be present in the input (e.g. parsing a
      flat namespace QMP union, where fields from both the base and one
      of the alternative types are mixed in the JSON object)
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      761d524d
  5. 19 12月, 2012 3 次提交
  6. 23 7月, 2012 2 次提交
  7. 14 7月, 2012 1 次提交
  8. 08 6月, 2012 1 次提交
  9. 21 2月, 2012 1 次提交
  10. 22 7月, 2011 1 次提交
    • M
      qapi: add QAPI visitor core · 2345c77c
      Michael Roth 提交于
      Base definitions/includes for Visiter interface used by generated
      visiter/marshalling code.
      
      Includes a GenericList type. Our lists require an embedded element.
      Since these types are generated, if you want to use them in a different
      type of data structure, there's no easy way to add another embedded
      element. The solution is to have non-embedded lists and that what this is.
      Signed-off-by: NMichael Roth <mdroth@linux.vnet.ibm.com>
      Signed-off-by: NLuiz Capitulino <lcapitulino@gmail.com>
      2345c77c