Skip to content
Snippets Groups Projects
  1. Oct 15, 2021
  2. Jul 06, 2021
  3. Apr 01, 2021
  4. Mar 19, 2021
  5. Mar 06, 2021
    • Kevin Wolf's avatar
      qom: Check for wellformed id in user_creatable_add_type() · 0bd5a2eb
      Kevin Wolf authored
      
      Most code paths for creating a user creatable object go through
      QemuOpts, which ensures that the provided 'id' option is actually a
      valid identifier.
      
      However, there are some code paths that don't go through QemuOpts:
      qemu-storage-daemon --object (since commit 8db1efd3) and QMP object-add
      (since it was first introduced in commit cff8b2c6). We need to have the
      same validity check for those, too.
      
      This adds the check and makes it print the same error message as
      QemuOpts on failure.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Message-Id: <20210302171623.49709-1-kwolf@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      0bd5a2eb
  6. Dec 19, 2020
    • Markus Armbruster's avatar
      qobject: Change qobject_to_json()'s value to GString · eab3a467
      Markus Armbruster authored
      
      qobject_to_json() and qobject_to_json_pretty() build a GString, then
      covert it to QString.  Just one of the callers actually needs a
      QString: qemu_rbd_parse_filename().  A few others need a string they
      can modify: qmp_send_response(), qga's send_response(), to_json_str(),
      and qmp_fd_vsend_fds().  The remainder just need a string.
      
      Change qobject_to_json() and qobject_to_json_pretty() to return the
      GString.
      
      qemu_rbd_parse_filename() now has to convert to QString.  All others
      save a QString temporary.  to_json_str() actually becomes a bit
      simpler, because GString provides more convenient modification
      functions.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201211171152.146877-6-armbru@redhat.com>
      eab3a467
  7. Oct 15, 2020
  8. Jul 10, 2020
    • Eric Auger's avatar
      qom: Introduce object_property_try_add_child() · db57fef1
      Eric Auger authored
      
      object_property_add() does not allow object_property_try_add()
      to gracefully fail as &error_abort is passed as an error handle.
      
      However such failure can easily be triggered from the QMP shell when,
      for instance, one attempts to create an object with an id that already
      exists. This is achieved from the following call path:
      
      qmp_object_add -> user_creatable_add_dict -> user_creatable_add_type ->
      object_property_add_child -> object_property_add
      
      For instance, from the qmp-shell, call twice:
      object-add qom-type=memory-backend-ram id=mem1 props.size=1073741824
      and QEMU aborts.
      
      This behavior is undesired as a user/management application mistake
      in reusing a property ID shouldn't result in loss of the VM and live
      data within.
      
      This patch introduces a new function, object_property_try_add_child()
      which takes an error handle and turn object_property_try_add() into
      a non-static one.
      
      Now the call path becomes:
      
      user_creatable_add_type -> object_property_try_add_child ->
      object_property_try_add
      
      and the error is returned gracefully to the QMP client.
      
      (QEMU) object-add qom-type=memory-backend-ram id=mem2  props.size=4294967296
      {"return": {}}
      (QEMU) object-add qom-type=memory-backend-ram id=mem2  props.size=4294967296
      {"error": {"class": "GenericError", "desc": "attempt to add duplicate property
      'mem2' to object (type 'container')"}}
      
      Signed-off-by: default avatarEric Auger <eric.auger@redhat.com>
      Fixes: d2623129 ("qom: Drop parameter @errp of object_property_add() & friends")
      Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
      
      Reviewed-by: default avatarGreg Kurz <groug@kaod.org>
      Tested-by: default avatarGreg Kurz <groug@kaod.org>
      Message-Id: <20200629193424.30280-2-eric.auger@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      db57fef1
    • Markus Armbruster's avatar
      qom: Use returned bool to check for failure, Coccinelle part · 778a2dc5
      Markus Armbruster authored
      
      The previous commit enables conversion of
      
          foo(..., &err);
          if (err) {
              ...
          }
      
      to
      
          if (!foo(..., errp)) {
              ...
          }
      
      for QOM functions that now return true / false on success / error.
      Coccinelle script:
      
          @@
          identifier fun = {
              object_apply_global_props, object_initialize_child_with_props,
              object_initialize_child_with_propsv, object_property_get,
              object_property_get_bool, object_property_parse, object_property_set,
              object_property_set_bool, object_property_set_int,
              object_property_set_link, object_property_set_qobject,
              object_property_set_str, object_property_set_uint, object_set_props,
              object_set_propv, user_creatable_add_dict,
              user_creatable_complete, user_creatable_del
          };
          expression list args, args2;
          typedef Error;
          Error *err;
          @@
          -    fun(args, &err, args2);
          -    if (err)
          +    if (!fun(args, &err, args2))
               {
                   ...
               }
      
      Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
      ARMSSE being used both as typedef and function-like macro there.
      Convert manually.
      
      Line breaks tidied up manually.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-29-armbru@redhat.com>
      778a2dc5
    • Markus Armbruster's avatar
      qom: Make functions taking Error ** return bool, not void · 6fd5bef1
      Markus Armbruster authored
      
      See recent commit "error: Document Error API usage rules" for
      rationale.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-28-armbru@redhat.com>
      6fd5bef1
    • Markus Armbruster's avatar
      qom: Put name parameter before value / visitor parameter · 5325cc34
      Markus Armbruster authored
      
      The object_property_set_FOO() setters take property name and value in
      an unusual order:
      
          void object_property_set_FOO(Object *obj, FOO_TYPE value,
                                       const char *name, Error **errp)
      
      Having to pass value before name feels grating.  Swap them.
      
      Same for object_property_set(), object_property_get(), and
      object_property_parse().
      
      Convert callers with this Coccinelle script:
      
          @@
          identifier fun = {
              object_property_get, object_property_parse, object_property_set_str,
              object_property_set_link, object_property_set_bool,
              object_property_set_int, object_property_set_uint, object_property_set,
              object_property_set_qobject
          };
          expression obj, v, name, errp;
          @@
          -    fun(obj, v, name, errp)
          +    fun(obj, name, v, errp)
      
      Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
      message "no position information".  Convert that one manually.
      
      Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
      ARMSSE being used both as typedef and function-like macro there.
      Convert manually.
      
      Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
      by RXCPU being used both as typedef and function-like macro there.
      Convert manually.  The other files using RXCPU that way don't need
      conversion.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-27-armbru@redhat.com>
      [Straightforwad conflict with commit 2336172d "audio: set default
      value for pcspk.iobase property" resolved]
      5325cc34
    • Markus Armbruster's avatar
      qapi: Use returned bool to check for failure, Coccinelle part · 62a35aaa
      Markus Armbruster authored
      
      The previous commit enables conversion of
      
          visit_foo(..., &err);
          if (err) {
              ...
          }
      
      to
      
          if (!visit_foo(..., errp)) {
              ...
          }
      
      for visitor functions that now return true / false on success / error.
      Coccinelle script:
      
          @@
          identifier fun =~ "check_list|input_type_enum|lv_start_struct|lv_type_bool|lv_type_int64|lv_type_str|lv_type_uint64|output_type_enum|parse_type_bool|parse_type_int64|parse_type_null|parse_type_number|parse_type_size|parse_type_str|parse_type_uint64|print_type_bool|print_type_int64|print_type_null|print_type_number|print_type_size|print_type_str|print_type_uint64|qapi_clone_start_alternate|qapi_clone_start_list|qapi_clone_start_struct|qapi_clone_type_bool|qapi_clone_type_int64|qapi_clone_type_null|qapi_clone_type_number|qapi_clone_type_str|qapi_clone_type_uint64|qapi_dealloc_start_list|qapi_dealloc_start_struct|qapi_dealloc_type_anything|qapi_dealloc_type_bool|qapi_dealloc_type_int64|qapi_dealloc_type_null|qapi_dealloc_type_number|qapi_dealloc_type_str|qapi_dealloc_type_uint64|qobject_input_check_list|qobject_input_check_struct|qobject_input_start_alternate|qobject_input_start_list|qobject_input_start_struct|qobject_input_type_any|qobject_input_type_bool|qobject_input_type_bool_keyval|qobject_input_type_int64|qobject_input_type_int64_keyval|qobject_input_type_null|qobject_input_type_number|qobject_input_type_number_keyval|qobject_input_type_size_keyval|qobject_input_type_str|qobject_input_type_str_keyval|qobject_input_type_uint64|qobject_input_type_uint64_keyval|qobject_output_start_list|qobject_output_start_struct|qobject_output_type_any|qobject_output_type_bool|qobject_output_type_int64|qobject_output_type_null|qobject_output_type_number|qobject_output_type_str|qobject_output_type_uint64|start_list|visit_check_list|visit_check_struct|visit_start_alternate|visit_start_list|visit_start_struct|visit_type_.*";
          expression list args;
          typedef Error;
          Error *err;
          @@
          -    fun(args, &err);
          -    if (err)
          +    if (!fun(args, &err))
               {
                   ...
               }
      
      A few line breaks tidied up manually.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-19-armbru@redhat.com>
      62a35aaa
  9. May 15, 2020
    • Markus Armbruster's avatar
      qom: Drop @errp parameter of object_property_del() · df4fe0b2
      Markus Armbruster authored
      
      Same story as for object_property_add(): the only way
      object_property_del() can fail is when the property with this name
      does not exist.  Since our property names are all hardcoded, failure
      is a programming error, and the appropriate way to handle it is
      passing &error_abort.  Most callers do that, the commit before
      previous fixed one that didn't (and got the error handling wrong), and
      the two remaining exceptions ignore errors.
      
      Drop the @errp parameter.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <20200505152926.18877-19-armbru@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      df4fe0b2
    • Markus Armbruster's avatar
      qom: Drop parameter @errp of object_property_add() & friends · d2623129
      Markus Armbruster authored
      
      The only way object_property_add() can fail is when a property with
      the same name already exists.  Since our property names are all
      hardcoded, failure is a programming error, and the appropriate way to
      handle it is passing &error_abort.
      
      Same for its variants, except for object_property_add_child(), which
      additionally fails when the child already has a parent.  Parentage is
      also under program control, so this is a programming error, too.
      
      We have a bit over 500 callers.  Almost half of them pass
      &error_abort, slightly fewer ignore errors, one test case handles
      errors, and the remaining few callers pass them to their own callers.
      
      The previous few commits demonstrated once again that ignoring
      programming errors is a bad idea.
      
      Of the few ones that pass on errors, several violate the Error API.
      The Error ** argument must be NULL, &error_abort, &error_fatal, or a
      pointer to a variable containing NULL.  Passing an argument of the
      latter kind twice without clearing it in between is wrong: if the
      first call sets an error, it no longer points to NULL for the second
      call.  ich9_pm_add_properties(), sparc32_ledma_realize(),
      sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
      are wrong that way.
      
      When the one appropriate choice of argument is &error_abort, letting
      users pick the argument is a bad idea.
      
      Drop parameter @errp and assert the preconditions instead.
      
      There's one exception to "duplicate property name is a programming
      error": the way object_property_add() implements the magic (and
      undocumented) "automatic arrayification".  Don't drop @errp there.
      Instead, rename object_property_add() to object_property_try_add(),
      and add the obvious wrapper object_property_add().
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <20200505152926.18877-15-armbru@redhat.com>
      [Two semantic rebase conflicts resolved]
      d2623129
  10. Apr 30, 2020
    • Kevin Wolf's avatar
      qemu-storage-daemon: Fix non-string --object properties · eaae29ef
      Kevin Wolf authored
      
      After processing the option string with the keyval parser, we get a
      QDict that contains only strings. This QDict must be fed to a keyval
      visitor which converts the strings into the right data types.
      
      qmp_object_add(), however, uses the normal QObject input visitor, which
      expects a QDict where all properties already have the QType that matches
      the data type required by the QOM object type.
      
      Change the --object implementation in qemu-storage-daemon so that it
      doesn't call qmp_object_add(), but calls user_creatable_add_dict()
      directly instead and pass it a new keyval boolean that decides which
      visitor must be used.
      
      Reported-by: default avatarCoiby Xu <coiby.xu@gmail.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      eaae29ef
    • Kevin Wolf's avatar
      qom: Factor out user_creatable_add_dict() · d6a5beeb
      Kevin Wolf authored
      
      The QMP handler qmp_object_add() and the implementation of --object in
      qemu-storage-daemon can share most of the code. Currently,
      qemu-storage-daemon calls qmp_object_add(), but this is not correct
      because different visitors need to be used.
      
      As a first step towards a fix, make qmp_object_add() a wrapper around a
      new function user_creatable_add_dict() that can get an additional
      parameter. The handling of "props" is only required for compatibility
      and not required for the qemu-storage-daemon command line, so it stays
      in qmp_object_add().
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      d6a5beeb
  11. Jan 24, 2020
  12. Oct 14, 2019
  13. Feb 26, 2019
  14. Dec 11, 2018
  15. Oct 19, 2018
  16. Oct 05, 2018
    • Marc-André Lureau's avatar
      vl: list user creatable properties when 'help' is argument · 1195fa2b
      Marc-André Lureau authored
      
      Iterate over the writable class properties, sort and print them out
      with the description if available.
      
      Ex: qemu -object memory-backend-file,help
      memory-backend-file.align=int
      memory-backend-file.discard-data=bool
      memory-backend-file.dump=bool - Set to 'off' to exclude from core dump
      memory-backend-file.host-nodes=int - Binds memory to the list of NUMA host nodes
      memory-backend-file.mem-path=string
      memory-backend-file.merge=bool - Mark memory as mergeable
      memory-backend-file.pmem=bool
      memory-backend-file.policy=HostMemPolicy - Set the NUMA policy
      memory-backend-file.prealloc=bool - Preallocate memory
      memory-backend-file.share=bool - Mark the memory as private to QEMU or shared
      memory-backend-file.size=int - Size of the memory region (ex: 500M)
      
      Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      1195fa2b
  17. May 08, 2018
  18. May 04, 2018
  19. Mar 02, 2018
  20. Feb 09, 2018
  21. Sep 19, 2017
Loading