diff mbox

[v2,13/17] accel: Rename 'init' method to 'init_machine'

Message ID 1409344310-5441-14-git-send-email-ehabkost@redhat.com
State New
Headers show

Commit Message

Eduardo Habkost Aug. 29, 2014, 8:31 p.m. UTC
This makes explicit the fact that the method is for machine
initialization, not just for accelerator object initialization.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c    | 8 ++++----
 include/hw/accel.h | 2 +-
 kvm-all.c          | 2 +-
 qtest.c            | 2 +-
 xen-common.c       | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

Comments

Paolo Bonzini Sept. 26, 2014, 3:09 p.m. UTC | #1
Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> This makes explicit the fact that the method is for machine
> initialization, not just for accelerator object initialization.

No, it is not for machine initialization.  It just picks defaults if
necessary from the passed machine class.

So I don't think this patch is needed.

Paolo

> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c    | 8 ++++----
>  include/hw/accel.h | 2 +-
>  kvm-all.c          | 2 +-
>  qtest.c            | 2 +-
>  xen-common.c       | 2 +-
>  5 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index 5817c3c..55378f3 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -57,11 +57,11 @@ static AccelClass *accel_find(const char *opt_name)
>      return ac;
>  }
>  
> -static int accel_init(AccelClass *acc, MachineClass *mc)
> +static int accel_init_machine(AccelClass *acc, MachineClass *mc)
>  {
>      int ret;
>      *(acc->allowed) = true;
> -    ret = acc->init(mc);
> +    ret = acc->init_machine(mc);
>      if (ret < 0) {
>          *(acc->allowed) = false;
>      }
> @@ -98,7 +98,7 @@ int configure_accelerator(MachineClass *mc)
>                     acc->name);
>              continue;
>          }
> -        ret = accel_init(acc, mc);
> +        ret = accel_init_machine(acc, mc);
>          if (ret < 0) {
>              init_failed = true;
>              fprintf(stderr, "failed to initialize %s: %s\n",
> @@ -128,7 +128,7 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)
>  {
>      AccelClass *ac = ACCEL_CLASS(oc);
>      ac->name = "tcg";
> -    ac->init = tcg_init;
> +    ac->init_machine = tcg_init;
>      ac->allowed = &tcg_allowed;
>  }
>  
> diff --git a/include/hw/accel.h b/include/hw/accel.h
> index 120ca0e..8812cda 100644
> --- a/include/hw/accel.h
> +++ b/include/hw/accel.h
> @@ -39,7 +39,7 @@ typedef struct AccelClass {
>      const char *opt_name;
>      const char *name;
>      int (*available)(void);
> -    int (*init)(MachineClass *mc);
> +    int (*init_machine)(MachineClass *mc);
>      bool *allowed;
>  } AccelClass;
>  
> diff --git a/kvm-all.c b/kvm-all.c
> index 7db966e..dd03dc4 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -2221,7 +2221,7 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data)
>  {
>      AccelClass *ac = ACCEL_CLASS(oc);
>      ac->name = "KVM";
> -    ac->init = kvm_init;
> +    ac->init_machine = kvm_init;
>      ac->allowed = &kvm_allowed;
>  }
>  
> diff --git a/qtest.c b/qtest.c
> index 829128e..4051868 100644
> --- a/qtest.c
> +++ b/qtest.c
> @@ -564,7 +564,7 @@ static void qtest_accel_class_init(ObjectClass *oc, void *data)
>      AccelClass *ac = ACCEL_CLASS(oc);
>      ac->name = "QTest";
>      ac->available = qtest_available;
> -    ac->init = qtest_init_accel;
> +    ac->init_machine = qtest_init_accel;
>      ac->allowed = &qtest_allowed;
>  }
>  
> diff --git a/xen-common.c b/xen-common.c
> index f0b34be..246d76b 100644
> --- a/xen-common.c
> +++ b/xen-common.c
> @@ -126,7 +126,7 @@ static void xen_accel_class_init(ObjectClass *oc, void *data)
>  {
>      AccelClass *ac = ACCEL_CLASS(oc);
>      ac->name = "Xen";
> -    ac->init = xen_init;
> +    ac->init_machine = xen_init;
>      ac->allowed = &xen_allowed;
>  }
>  
>
Eduardo Habkost Sept. 26, 2014, 4:42 p.m. UTC | #2
On Fri, Sep 26, 2014 at 05:09:06PM +0200, Paolo Bonzini wrote:
> Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> > This makes explicit the fact that the method is for machine
> > initialization, not just for accelerator object initialization.
> 
> No, it is not for machine initialization.  It just picks defaults if
> necessary from the passed machine class.

The problem is that lots of the accelerator initialization code changes
global state or machine state. But I want to be able to create
accelerator objects usable for probing without affecting any
global/machine state. The use case I have in mind is to return
accelerator-specific runnable/features information when listing CPU
model information.

My plan here is to split accelerator initialization into:

* instance_init(), which won't affect any machine/global state, and can
  be safely run multiple times;
* machine_init(), which may affect machine/global state.

In a perfect world, machine_init() wouldn't even exist because
accelerators would never affect machine/global state, but we are a long
way from that.
diff mbox

Patch

diff --git a/hw/core/accel.c b/hw/core/accel.c
index 5817c3c..55378f3 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -57,11 +57,11 @@  static AccelClass *accel_find(const char *opt_name)
     return ac;
 }
 
-static int accel_init(AccelClass *acc, MachineClass *mc)
+static int accel_init_machine(AccelClass *acc, MachineClass *mc)
 {
     int ret;
     *(acc->allowed) = true;
-    ret = acc->init(mc);
+    ret = acc->init_machine(mc);
     if (ret < 0) {
         *(acc->allowed) = false;
     }
@@ -98,7 +98,7 @@  int configure_accelerator(MachineClass *mc)
                    acc->name);
             continue;
         }
-        ret = accel_init(acc, mc);
+        ret = accel_init_machine(acc, mc);
         if (ret < 0) {
             init_failed = true;
             fprintf(stderr, "failed to initialize %s: %s\n",
@@ -128,7 +128,7 @@  static void tcg_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "tcg";
-    ac->init = tcg_init;
+    ac->init_machine = tcg_init;
     ac->allowed = &tcg_allowed;
 }
 
diff --git a/include/hw/accel.h b/include/hw/accel.h
index 120ca0e..8812cda 100644
--- a/include/hw/accel.h
+++ b/include/hw/accel.h
@@ -39,7 +39,7 @@  typedef struct AccelClass {
     const char *opt_name;
     const char *name;
     int (*available)(void);
-    int (*init)(MachineClass *mc);
+    int (*init_machine)(MachineClass *mc);
     bool *allowed;
 } AccelClass;
 
diff --git a/kvm-all.c b/kvm-all.c
index 7db966e..dd03dc4 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -2221,7 +2221,7 @@  static void kvm_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "KVM";
-    ac->init = kvm_init;
+    ac->init_machine = kvm_init;
     ac->allowed = &kvm_allowed;
 }
 
diff --git a/qtest.c b/qtest.c
index 829128e..4051868 100644
--- a/qtest.c
+++ b/qtest.c
@@ -564,7 +564,7 @@  static void qtest_accel_class_init(ObjectClass *oc, void *data)
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "QTest";
     ac->available = qtest_available;
-    ac->init = qtest_init_accel;
+    ac->init_machine = qtest_init_accel;
     ac->allowed = &qtest_allowed;
 }
 
diff --git a/xen-common.c b/xen-common.c
index f0b34be..246d76b 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -126,7 +126,7 @@  static void xen_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "Xen";
-    ac->init = xen_init;
+    ac->init_machine = xen_init;
     ac->allowed = &xen_allowed;
 }