[10/16] accel: pass object to accel_init_machine
diff mbox series

Message ID 1573655945-14912-11-git-send-email-pbonzini@redhat.com
State New
Headers show
Series
  • Complete the implementation of -accel
Related show

Commit Message

Paolo Bonzini Nov. 13, 2019, 2:38 p.m. UTC
We will have to set QOM properties before accel_init_machine, based on the
options provided to -accel.  Construct the object outside it so that it
will be possible to insert the iteration between object_new_with_class
and accel_init_machine.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 accel/accel.c          | 6 ++----
 include/sysemu/accel.h | 2 +-
 vl.c                   | 4 +++-
 3 files changed, 6 insertions(+), 6 deletions(-)

Comments

Marc-André Lureau Nov. 14, 2019, 10:48 a.m. UTC | #1
On Wed, Nov 13, 2019 at 6:45 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> We will have to set QOM properties before accel_init_machine, based on the
> options provided to -accel.  Construct the object outside it so that it
> will be possible to insert the iteration between object_new_with_class
> and accel_init_machine.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  accel/accel.c          | 6 ++----
>  include/sysemu/accel.h | 2 +-
>  vl.c                   | 4 +++-
>  3 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/accel/accel.c b/accel/accel.c
> index 74eda68..822e945 100644
> --- a/accel/accel.c
> +++ b/accel/accel.c
> @@ -52,11 +52,9 @@ AccelClass *accel_find(const char *opt_name)
>      return ac;
>  }
>
> -int accel_init_machine(AccelClass *acc, MachineState *ms)
> +int accel_init_machine(AccelState *accel, MachineState *ms)
>  {
> -    ObjectClass *oc = OBJECT_CLASS(acc);
> -    const char *cname = object_class_get_name(oc);
> -    AccelState *accel = ACCEL(object_new(cname));
> +    AccelClass *acc = ACCEL_GET_CLASS(accel);
>      int ret;
>      ms->accelerator = accel;
>      *(acc->allowed) = true;
> diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h
> index 90b6213..22cac0f 100644
> --- a/include/sysemu/accel.h
> +++ b/include/sysemu/accel.h
> @@ -67,7 +67,7 @@ typedef struct AccelClass {
>  extern unsigned long tcg_tb_size;
>
>  AccelClass *accel_find(const char *opt_name);
> -int accel_init_machine(AccelClass *acc, MachineState *ms);
> +int accel_init_machine(AccelState *accel, MachineState *ms);
>
>  /* Called just before os_setup_post (ie just before drop OS privs) */
>  void accel_setup_post(MachineState *ms);
> diff --git a/vl.c b/vl.c
> index 6e406d4..c8ec906 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2846,6 +2846,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)
>      bool *p_init_failed = opaque;
>      const char *acc = qemu_opt_get(opts, "accel");
>      AccelClass *ac = accel_find(acc);
> +    AccelState *accel;
>      int ret;
>
>      if (!ac) {
> @@ -2853,7 +2854,8 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)
>          error_report("invalid accelerator %s", acc);
>          return 0;
>      }
> -    ret = accel_init_machine(ac, current_machine);
> +    accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac)));
> +    ret = accel_init_machine(accel, current_machine);
>      if (ret < 0) {
>          *p_init_failed = true;
>          error_report("failed to initialize %s: %s",
> --
> 1.8.3.1
>
>
>

Patch
diff mbox series

diff --git a/accel/accel.c b/accel/accel.c
index 74eda68..822e945 100644
--- a/accel/accel.c
+++ b/accel/accel.c
@@ -52,11 +52,9 @@  AccelClass *accel_find(const char *opt_name)
     return ac;
 }
 
-int accel_init_machine(AccelClass *acc, MachineState *ms)
+int accel_init_machine(AccelState *accel, MachineState *ms)
 {
-    ObjectClass *oc = OBJECT_CLASS(acc);
-    const char *cname = object_class_get_name(oc);
-    AccelState *accel = ACCEL(object_new(cname));
+    AccelClass *acc = ACCEL_GET_CLASS(accel);
     int ret;
     ms->accelerator = accel;
     *(acc->allowed) = true;
diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h
index 90b6213..22cac0f 100644
--- a/include/sysemu/accel.h
+++ b/include/sysemu/accel.h
@@ -67,7 +67,7 @@  typedef struct AccelClass {
 extern unsigned long tcg_tb_size;
 
 AccelClass *accel_find(const char *opt_name);
-int accel_init_machine(AccelClass *acc, MachineState *ms);
+int accel_init_machine(AccelState *accel, MachineState *ms);
 
 /* Called just before os_setup_post (ie just before drop OS privs) */
 void accel_setup_post(MachineState *ms);
diff --git a/vl.c b/vl.c
index 6e406d4..c8ec906 100644
--- a/vl.c
+++ b/vl.c
@@ -2846,6 +2846,7 @@  static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)
     bool *p_init_failed = opaque;
     const char *acc = qemu_opt_get(opts, "accel");
     AccelClass *ac = accel_find(acc);
+    AccelState *accel;
     int ret;
 
     if (!ac) {
@@ -2853,7 +2854,8 @@  static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)
         error_report("invalid accelerator %s", acc);
         return 0;
     }
-    ret = accel_init_machine(ac, current_machine);
+    accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac)));
+    ret = accel_init_machine(accel, current_machine);
     if (ret < 0) {
         *p_init_failed = true;
         error_report("failed to initialize %s: %s",