qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Igor Mammedov" <imammedo@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [RFC 9/9] target-i386: Unify CPU object creation on x86_cpu_create_from_name()
Date: Fri, 28 Dec 2012 18:34:06 -0200	[thread overview]
Message-ID: <1356726846-10637-10-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1356726846-10637-1-git-send-email-ehabkost@redhat.com>

To keep the kvm_enabled() check for "host" working, a 'kvm_required'
field was added to X86CPUClass.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu-qom.h |  1 +
 target-i386/cpu.c     | 32 ++++++++++++++++++++------------
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index 332916a..fc58f83 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -49,6 +49,7 @@ typedef struct X86CPUClass {
     /*< public >*/
 
     void (*parent_reset)(CPUState *cpu);
+    bool kvm_required;
 } X86CPUClass;
 
 /**
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index fa7fab0..7beacdf 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1605,23 +1605,24 @@ static X86CPU *x86_cpu_create_from_name(const char *name, Error **errp)
 {
     Error *error = NULL;
     X86CPU *cpu = NULL;
+    ObjectClass *oc;
+    X86CPUClass *cc;
     char *class_name = g_strdup_printf(CPU_CLASS_NAME("%s"), name);
 
+    oc = object_class_by_name(class_name);
+    if (!oc) {
+        error_setg(&error, "Unable to find CPU definition: %s", name);
+        goto out;
+    }
 
-    if (kvm_enabled() && name && strcmp(name, "host") == 0) {
-#ifdef CONFIG_KVM
-        cpu = X86_CPU(object_new(TYPE_X86_HOST_CPU));
-#endif
-    } else {
-
-        if (!object_class_by_name(class_name)) {
-            error_setg(&error, "Unable to find CPU definition: %s", name);
-            goto out;
-        }
-
-        cpu = X86_CPU(object_new(class_name));
+    cc = X86_CPU_CLASS(oc);
+    if (cc->kvm_required && !kvm_enabled()) {
+        error_setg(&error, "CPU model '%s' requires KVM", name);
+        goto out;
     }
 
+    cpu = X86_CPU(object_new(class_name));
+
 out:
     g_free(class_name);
     if (error) {
@@ -2499,6 +2500,12 @@ static void x86_host_cpu_initfn(Object *obj)
     }
 }
 
+static void x86_host_cpu_class_init(ObjectClass *oc, void *data)
+{
+    X86CPUClass *cc = X86_CPU_CLASS(oc);
+    cc->kvm_required = true;
+}
+
 static const TypeInfo x86_host_cpu_type_info = {
     .name = TYPE_X86_HOST_CPU,
     .parent = TYPE_X86_CPU,
@@ -2506,6 +2513,7 @@ static const TypeInfo x86_host_cpu_type_info = {
     .instance_init = x86_host_cpu_initfn,
     .abstract = false,
     .class_size = sizeof(X86CPUClass),
+    .class_init = x86_host_cpu_class_init,
 };
 
 #endif /* CONFIG_KVM */
-- 
1.7.11.7

      parent reply	other threads:[~2012-12-28 20:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-28 20:33 [Qemu-devel] [PATCH 0/9] x86 CPU subclasses Eduardo Habkost
2012-12-28 20:33 ` [Qemu-devel] [PATCH 1/9] target-i386: Move CPU object creation to cpu.c Eduardo Habkost
2012-12-28 20:33 ` [Qemu-devel] [PATCH 2/9] target-i386: Make cpu_x86_create() get Error argument Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [PATCH 3/9] target-i386: Simplify cpu_x86_find_by_name() logic Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 4/9] target-i386: Set feature string parsing results directly on CPU object Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 5/9] target-i386: Move kvm_features/hypervisor initialization to cpu_x86_find_by_name() Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 6/9] target-i386: Move CPU creation code to model name lookup function Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 7/9] target-i386: CPU subclass for -cpu "host" Eduardo Habkost
2013-01-02 19:00   ` Igor Mammedov
2013-01-02 20:07     ` Igor Mammedov
2013-01-02 20:20       ` Eduardo Habkost
2013-01-02 20:16     ` Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 8/9] target-i386: CPU subclasses for predefined CPU models Eduardo Habkost
2012-12-28 20:34 ` Eduardo Habkost [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1356726846-10637-10-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=afaerber@suse.de \
    --cc=imammedo@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).