1. 23 6月, 2015 7 次提交
    • M
      vl: Avoid qerror_report() outside QMP command handlers · 1459407e
      Markus Armbruster 提交于
      qerror_report() is a transitional interface to help with converting
      existing monitor commands to QMP.  It should not be used elsewhere.
      Replace by error_report() in initial startup helpers parse_sandbox()
      and parse_add_fd().
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NLuiz Capitulino <lcapitulino@redhat.com>
      1459407e
    • M
      QemuOpts: Wean off qerror_report_err() · 70b94331
      Markus Armbruster 提交于
      qerror_report_err() is a transitional interface to help with
      converting existing monitor commands to QMP.  It should not be used
      elsewhere.
      
      The only remaining user in qemu-option.c is qemu_opts_parse().  Is it
      used in QMP context?  If not, we can simply replace
      qerror_report_err() by error_report_err().
      
      The uses in qemu-img.c, qemu-io.c, qemu-nbd.c and under tests/ are
      clearly not in QMP context.
      
      The uses in vl.c aren't either, because the only QMP command handlers
      there are qmp_query_status() and qmp_query_machines(), and they don't
      call it.
      
      Remaining uses:
      
      * drive_def(): Command line -drive and such, HMP drive_add and pci_add
      
      * hmp_chardev_add(): HMP chardev-add
      
      * monitor_parse_command(): HMP core
      
      * tmp_config_parse(): Command line -tpmdev
      
      * net_host_device_add(): HMP host_net_add
      
      * net_client_parse(): Command line -net and -netdev
      
      * qemu_global_option(): Command line -global
      
      * vnc_parse_func(): Command line -display, -vnc, default display, HMP
        change, QMP change.  Bummer.
      
      * qemu_pci_hot_add_nic(): HMP pci_add
      
      * usb_net_init(): Command line -usbdevice, HMP usb_add
      
      Propagate errors through qemu_opts_parse().  Create a convenience
      function qemu_opts_parse_noisily() that passes errors to
      error_report_err().  Switch all non-QMP users outside tests to it.
      
      That leaves vnc_parse_func().  Propagate errors through it.  Since I'm
      touching it anyway, rename it to vnc_parse().
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: NLuiz Capitulino <lcapitulino@redhat.com>
      70b94331
    • M
      qdev-monitor: Propagate errors through qdev_device_add() · f006cf7f
      Markus Armbruster 提交于
      Also polish an error message while I'm touching the line anyway,
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NAndreas Färber <afaerber@suse.de>
      f006cf7f
    • M
    • M
      qdev-monitor: Convert qbus_find() to Error · d2828429
      Markus Armbruster 提交于
      As usual, the conversion breaks printing explanatory messages after
      the error: actual printing of the error gets delayed, so the
      explanations precede rather than follow it.
      
      Pity.  Disable them for now.  See also commit 7216ae3d.
      
      While there, eliminate QERR_BUS_NOT_FOUND, and clean up unusual
      spelling in the error message.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      d2828429
    • M
      qdev-monitor: Fix check for full bus · ed238ba2
      Markus Armbruster 提交于
      Property bus has always been too screwed up to be really usable for
      values other than plain bus IDs.  This just fixes a bug that crept in
      in commit 1395af6f "qdev: add a maximum device allowed field for the
      bus."
      
      It doesn't always fail when it should:
      
          $ qemu-system-x86_64 -nodefaults -device virtio-serial-pci -device virtio-rng-device,bus=pci.0/virtio-serial-pci/virtio-bus
      
      Happily plugs the virtio-rng-device into the virtio-bus provided by
      virtio-serial-pci, even though its only slot is already occupied by a
      virtio-serial-device.
      
      And sometimes fails when it shouldn't:
      
          $ qemu-system-x86_64 -nodefaults -device virtio-serial-pci -device virtserialport,bus=virtio-bus/virtio-serial-device
      
      Yes, the virtio-bus is full, but the virtio-serial-bus provided by
      virtio-serial-device isn't, and that's the one we're trying to use.
      
      Root cause: we check "bus full" when we resolve the first element of
      the path.  That's the correct one only when it's also the last one.
      
      Fix by moving the "bus full" check to right before we return a bus.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      ed238ba2
    • M
      qdev-monitor: Stop error avalanche in qbus_find_recursive() · a5ec494e
      Markus Armbruster 提交于
      Reproducer:
      
          $ qemu-system-x86_64 -nodefaults -device virtio-rng-pci -device virtio-rng-pci -device virtio-rng-device,bus=virtio-bus
          qemu-system-x86_64: -device virtio-rng-device,bus=virtio-bus: Bus 'virtio-bus' is full
          qemu-system-x86_64: -device virtio-rng-device,bus=virtio-bus: Bus 'virtio-bus' is full
          qemu-system-x86_64: -device virtio-rng-device,bus=virtio-bus: Bus 'virtio-bus' not found
      
      qbus_find_recursive() reports the "is full" error itself, and leaves
      reporting "not found" to its caller.  The result is confusion.  Write
      it a function contract that permits leaving all error reporting to the
      caller, and implement it.  Update callers to detect and report "is
      full".
      
      Screwed up when commit 1395af6f added the max_dev limit and the "is
      full" error condition to enforce it.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      a5ec494e
  2. 22 6月, 2015 10 次提交
  3. 21 6月, 2015 16 次提交
  4. 20 6月, 2015 7 次提交
    • M
      qdev: Un-deprecate qdev_init_nofail() · daeba969
      Markus Armbruster 提交于
      It's a perfectly sensible helper function.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NAndreas Färber <afaerber@suse.de>
      daeba969
    • M
      qdev: Deprecated qdev_init() is finally unused, drop · 0210afe6
      Markus Armbruster 提交于
      qdev_init() is a wrapper around setting property "realized" to true,
      plus error handling that passes errors to qerror_report_err().
      qerror_report_err() is a transitional interface to help with
      converting existing monitor commands to QMP.  It should not be used
      elsewhere.
      
      All code has been modernized to avoid qdev_init() and its
      inappropriate error handling.  We can finally drop it.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NAndreas Färber <afaerber@suse.de>
      0210afe6
    • D
      qom: Don't pass string table to object_get_enum() function · a3590dac
      Daniel P. Berrange 提交于
      Now that properties can be explicitly registered as an enum
      type, there is no need to pass the string table to the
      object_get_enum() function. The object property registration
      already has a pointer to the string table.
      
      In changing this method signature, the hostmem backend object
      has to be converted to use the new enum property registration
      code, which simplifies it somewhat.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NAndreas Färber <afaerber@suse.de>
      a3590dac
    • D
      qom: Add an object_property_add_enum() helper function · a8e3fbed
      Daniel P. Berrange 提交于
      A QOM property can be parsed as enum using the visit_type_enum()
      helper function, but this forces callers to use the more complex
      generic object_property_add() method when registering it. It
      also requires that users of that object have access to the
      string map when they want to read the property value.
      
      This patch introduces a specialized object_property_add_enum()
      method which simplifies the use of enum properties, so the
      setters/getters directly get passed the int value.
      
        typedef enum {
           MYDEV_TYPE_FROG,
           MYDEV_TYPE_ALLIGATOR,
           MYDEV_TYPE_PLATYPUS,
      
           MYDEV_TYPE_LAST
        } MyDevType;
      
      Then provide a table of enum <-> string mappings
      
        static const char *const mydevtypemap[MYDEV_TYPE_LAST + 1] = {
           [MYDEV_TYPE_FROG] = "frog",
           [MYDEV_TYPE_ALLIGATOR] = "alligator",
           [MYDEV_TYPE_PLATYPUS] = "platypus",
           [MYDEV_TYPE_LAST] = NULL,
        };
      
      Assuming an object struct of
      
         typedef struct {
            Object parent_obj;
            MyDevType devtype;
            ...other fields...
         } MyDev;
      
      The property can then be registered as follows:
      
         static int mydev_prop_get_devtype(Object *obj,
                                           Error **errp G_GNUC_UNUSED)
         {
             MyDev *dev = MYDEV(obj);
      
             return dev->devtype;
         }
      
         static void mydev_prop_set_devtype(Object *obj,
                                            int value,
                                            Error **errp G_GNUC_UNUSED)
         {
             MyDev *dev = MYDEV(obj);
      
             dev->devtype = value;
         }
      
         object_property_add_enum(obj, "devtype",
                                  mydevtypemap, "MyDevType",
                                  mydev_prop_get_devtype,
                                  mydev_prop_set_devtype,
                                  NULL);
      
      Note there is no need to check the range of 'value' in
      the setter, because the string->enum conversion code will
      have already done that and reported an error as required.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NAndreas Färber <afaerber@suse.de>
      a8e3fbed
    • D
      qom: Make enum string tables const-correct · 2e4450ff
      Daniel P. Berrange 提交于
      The enum string table parameters in various QOM/QAPI methods
      are declared 'const char *strings[]'. This results in const
      warnings if passed a variable that was declared as
      
         static const char * const strings[] = { .... };
      
      Add the extra const annotation to the parameters, since
      neither the string elements, nor the array itself should
      ever be modified.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NAndreas Färber <afaerber@suse.de>
      2e4450ff
    • D
      qom: Add object_new_with_props() / object_new_withpropv() helpers · a31bdae5
      Daniel P. Berrange 提交于
      It is reasonably common to want to create an object, set a
      number of properties, register it in the hierarchy and then
      mark it as complete (if a user creatable type). This requires
      quite a lot of error prone, verbose, boilerplate code to achieve.
      
      First a pair of functions object_set_props() / object_set_propv()
      are added which allow for a list of objects to be set in
      one single API call.
      
      Then object_new_with_props() / object_new_with_propv() constructors
      are added which simplify the sequence of calls to create an
      object, populate properties, register in the object composition
      tree and mark the object complete, into a single method call.
      
      Usage would be:
      
         Error *err = NULL;
         Object *obj;
         obj = object_new_with_propv(TYPE_MEMORY_BACKEND_FILE,
                                     object_get_objects_root(),
                                     "hostmem0",
                                     &err,
                                     "share", "yes",
                                     "mem-path", "/dev/shm/somefile",
                                     "prealloc", "yes",
                                     "size", "1048576",
                                     NULL);
      
      Note all property values are passed in string form and will
      be parsed into their required data types, using normal QOM
      semantics for parsing from string format.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NAndreas Färber <afaerber@suse.de>
      a31bdae5
    • D
      qom: Add helper function for getting user objects root · bc2256c4
      Daniel P. Berrange 提交于
      Add object_get_objects_root() function which is a convenience for
      obtaining the Object * located at /objects in the object
      composition tree. Convert existing code over to use the new
      API where appropriate.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NAndreas Färber <afaerber@suse.de>
      bc2256c4