Re: [PATCH 00/18] qapi/qom: QAPIfy object-add

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02/12/20 13:51, Eduardo Habkost wrote:
I'm liking the direction this is taking.  However, I would still
like to have a clearer and feasible plan that would work for
-device, -machine, and -cpu.

-cpu is not a problem since it's generally created with a static
configuration (now done with global properties, in the future it could be a
struct).

It is a problem if it requires manually converting existing code
defining CPU properties and we don't have a transition plan.

We do not have to convert everything _if_ for some objects there are good reasons to do programmatically-generated properties. CPUs might be one of those cases (or if we decide to convert them, they might endure some more code duplication than other devices because they have so many properties).

Would a -device conversion also involve non-user-creatable
devices, or would we keep existing internal usage of QOM
properties?

Even if it's just for user-creatable devices, getting rid of QOM
property usage in devices sounds like a very ambitious goal.  I'd
like us to have a good transition plan, in addition to declaring
what's our ideal end goal.

For user-creatable objects Kevin is doing work in lockstep on all classes; but once we have the infrastructure for QAPI object configuration schemas we can proceed in the other direction and operate on one device at a time.

With some handwaving, something like (see create_unimplemented_device)

    DeviceState *dev = qdev_new(TYPE_UNIMPLEMENTED_DEVICE);

    qdev_prop_set_string(dev, "name", name);
    qdev_prop_set_uint64(dev, "size", size);
    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);

might become something like

    { 'object': 'unimplemented-device',
      'config': {
         'name': 'str',
         'size': 'size'
      },
    }

    DeviceState *dev = qapi_Unimplemented_new(&(
         (UnimplementedDeviceOptions) {
             .name = name,
             .size = size
         }, &error_fatal);
    object_unref(dev);

(i.e. all typesafe!) and the underlying code would be something like

    void (*init_properties)(Object *obj, Visitor *v, Error **errp);
    ...

    // QAPI generated constructor
    UnimplementedDevice *qapi_Unimplemented_new(
        UnimplementedDeviceOptions *opt, Error **errp)
    {
        Object *obj = object_new(TYPE_UNIMPLEMENTED_DEVICE);
        if (!qapi_Unimplemented_init_properties(obj, opt, errp)) {
            object_unref(obj);
            return NULL;
        }
        return obj;
    }

    // QAPI generated Visitor->struct adapter
    bool qapi_Unimplemented_init_properties(
        Object *obj, Visitor *v, Error **errp)
    {
        UnimplementedDeviceOptions opt;
        Error *local_err = NULL;
        visit_type_UnimplementedDeviceOptions(v, NULL,
                                              &opt, &local_err);
        if (local_err) {
            error_propagate(errp, local_err);
            return false;
        }
        unimplemented_init_properties(UNIMPLEMENTED_DEVICE(obj),
                                      &opt, &local_err);
        if (local_err) {
            error_propagate(errp, local_err);
            return false;
        }
        return true;
    }

    // Hand-written (?) initializer:
    void unimplemented_init_properties(Object *obj,
         UnimplementedDeviceOptions *opt, Error **errp)
    {
         obj->name = name;
         obj->size = size;
         device_realize(obj, errp);
    }

    // class_init code:
    oc->init_properties = qapi_Unimplemented_init_properties;

and all read-only-after-realize QOM properties could be made *really* read-only.

Paolo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux