qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v7 07/17] vfio-user: define vfio-user-server object


From: Stefan Hajnoczi
Subject: Re: [PATCH v7 07/17] vfio-user: define vfio-user-server object
Date: Tue, 29 Mar 2022 11:21:05 +0100

On Fri, Mar 25, 2022 at 03:19:36PM -0400, Jagannathan Raman wrote:
  ##
> diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h
> index 8d0fa98d33..2fcb9dada5 100644
> --- a/include/hw/remote/machine.h
> +++ b/include/hw/remote/machine.h
> @@ -26,6 +26,12 @@ struct RemoteMachineState {
>      bool vfio_user;
>  };
>  
> +struct RemoteMachineClass {
> +    MachineClass parent_class;
> +
> +    bool auto_shutdown;
> +};
> +
>  /* Used to pass to co-routine device and ioc. */
>  typedef struct RemoteCommDev {
>      PCIDevice *dev;
> @@ -33,7 +39,7 @@ typedef struct RemoteCommDev {
>  } RemoteCommDev;
>  
>  #define TYPE_REMOTE_MACHINE "x-remote-machine"
> -OBJECT_DECLARE_SIMPLE_TYPE(RemoteMachineState, REMOTE_MACHINE)
> +OBJECT_DECLARE_TYPE(RemoteMachineState, RemoteMachineClass, REMOTE_MACHINE)
>  
>  void coroutine_fn mpqemu_remote_msg_loop_co(void *data);
>  
> diff --git a/hw/remote/machine.c b/hw/remote/machine.c
> index a9a75e170f..70178b222c 100644
> --- a/hw/remote/machine.c
> +++ b/hw/remote/machine.c
> @@ -78,25 +78,48 @@ static void remote_machine_set_vfio_user(Object *obj, 
> bool value, Error **errp)
>      s->vfio_user = value;
>  }
>  
> +static bool remote_machine_get_auto_shutdown(Object *obj, Error **errp)
> +{
> +    RemoteMachineClass *rmc = REMOTE_MACHINE_GET_CLASS(obj);
> +
> +    return rmc->auto_shutdown;
> +}
> +
> +static void remote_machine_set_auto_shutdown(Object *obj, bool value,
> +                                             Error **errp)
> +{
> +    RemoteMachineClass *rmc = REMOTE_MACHINE_GET_CLASS(obj);
> +
> +    rmc->auto_shutdown = value;
> +}
> +
>  static void remote_machine_class_init(ObjectClass *oc, void *data)
>  {
>      MachineClass *mc = MACHINE_CLASS(oc);
> +    RemoteMachineClass *rmc = REMOTE_MACHINE_CLASS(oc);
>      HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
>  
>      mc->init = remote_machine_init;
>      mc->desc = "Experimental remote machine";
>  
> +    rmc->auto_shutdown = true;
> +
>      hc->unplug = qdev_simple_device_unplug_cb;
>  
>      object_class_property_add_bool(oc, "vfio-user",
>                                     remote_machine_get_vfio_user,
>                                     remote_machine_set_vfio_user);
> +
> +    object_class_property_add_bool(oc, "auto-shutdown",
> +                                   remote_machine_get_auto_shutdown,
> +                                   remote_machine_set_auto_shutdown);
>  }
>  
>  static const TypeInfo remote_machine = {
>      .name = TYPE_REMOTE_MACHINE,
>      .parent = TYPE_MACHINE,
>      .instance_size = sizeof(RemoteMachineState),
> +    .class_size = sizeof(RemoteMachineClass),

Why is ->auto_shutdown a global RemoteMachineClass field instead of a
RemoteMachineState instance field?

The getter/setter functions receive an object instance so they could
access the value in RemoteMachineState instead of RemoteMachineClass.
Moving the field to RemoteMachineState would allow multiple
RemoteMachineState instances with different ->auto_shutdown values in
case QEMU ever supports running multiple machines within a single
process.

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]