Patchwork [16/22] machine: move default machine out of machine definitions

login
register
mail settings
Submitter Anthony Liguori
Date June 7, 2010, 11:52 p.m.
Message ID <1275954730-8196-17-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/54913/
State New
Headers show

Comments

Anthony Liguori - June 7, 2010, 11:52 p.m.
There can only be one default machine so instead of setting in each machine
whether it's the default, simply declare what the name of the default machine
is.  A nice characteristic of this is that we technically don't need to
describe the default machine in QEMU anymore.  Instead, it could be described
in a config file but this patch doesn't do that.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Patch

diff --git a/hw/boards.h b/hw/boards.h
index 5176e95..b99dc68 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -14,13 +14,13 @@  struct QEMUMachine {
     const char *alias;
     const char *desc;
     QEMUMachineInitFunc *init;
-    int is_default;
     QemuOptDesc *opts_desc;
     QemuOptValue *opts_default;
     struct QEMUMachine *next;
 };
 
 int qemu_register_machine(QEMUMachine *m);
+void machine_set_default(const char *name);
 
 extern QEMUMachine *current_machine;
 
diff --git a/hw/etraxfs.c b/hw/etraxfs.c
index 1cb6052..e41d1ce 100644
--- a/hw/etraxfs.c
+++ b/hw/etraxfs.c
@@ -176,12 +176,12 @@  static QEMUMachine bareetraxfs_machine = {
     .name = "bareetraxfs",
     .desc = "Bare ETRAX FS board",
     .init = bareetraxfs_init,
-    .is_default = 1,
 };
 
 static void bareetraxfs_machine_init(void)
 {
     qemu_register_machine(&bareetraxfs_machine);
+    machine_set_default("bareetraxfs");
 }
 
 machine_init(bareetraxfs_machine_init);
diff --git a/hw/integratorcp.c b/hw/integratorcp.c
index 36ebaf0..b505773 100644
--- a/hw/integratorcp.c
+++ b/hw/integratorcp.c
@@ -515,12 +515,12 @@  static QEMUMachine integratorcp_machine = {
     .name = "integratorcp",
     .desc = "ARM Integrator/CP (ARM926EJ-S)",
     .init = integratorcp_init,
-    .is_default = 1,
 };
 
 static void integratorcp_machine_init(void)
 {
     qemu_register_machine(&integratorcp_machine);
+    machine_set_default("integratorcp");
 }
 
 machine_init(integratorcp_machine_init);
diff --git a/hw/mcf5208.c b/hw/mcf5208.c
index b6eb94d..1ed8871 100644
--- a/hw/mcf5208.c
+++ b/hw/mcf5208.c
@@ -293,12 +293,12 @@  static QEMUMachine mcf5208evb_machine = {
     .name = "mcf5208evb",
     .desc = "MCF5206EVB",
     .init = mcf5208evb_init,
-    .is_default = 1,
 };
 
 static void mcf5208evb_machine_init(void)
 {
     qemu_register_machine(&mcf5208evb_machine);
+    machine_set_default("mcf5208evb");
 }
 
 machine_init(mcf5208evb_machine_init);
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index 0ef0090..f89be6d 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -993,12 +993,12 @@  static QEMUMachine mips_malta_machine = {
     .name = "malta",
     .desc = "MIPS Malta Core LV",
     .init = mips_malta_init,
-    .is_default = 1,
 };
 
 static void mips_malta_machine_init(void)
 {
     qemu_register_machine(&mips_malta_machine);
+    machine_set_default("malta");
 }
 
 machine_init(mips_malta_machine_init);
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index d02bf20..1bb6bee 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -186,7 +186,6 @@  static QEMUMachine pc_machine = {
     .alias = "pc",
     .desc = "Standard PC",
     .init = pc_init,
-    .is_default = 1,
     .opts_desc = pc_opts_desc,
     .opts_default = (QemuOptValue[]) {
         QOPT_VALUE("acpi", "on"),
@@ -277,6 +276,7 @@  static void pc_machine_init(void)
     qemu_register_machine(&pc_machine_v0_11);
     qemu_register_machine(&pc_machine_v0_10);
     qemu_register_machine(&isapc_machine);
+    machine_set_default("pc");
 }
 
 machine_init(pc_machine_init);
diff --git a/hw/petalogix_s3adsp1800_mmu.c b/hw/petalogix_s3adsp1800_mmu.c
index 5cc5787..5528960 100644
--- a/hw/petalogix_s3adsp1800_mmu.c
+++ b/hw/petalogix_s3adsp1800_mmu.c
@@ -201,12 +201,12 @@  static QEMUMachine petalogix_s3adsp1800_machine = {
     .name = "petalogix-s3adsp1800",
     .desc = "Petalogix linux refdesign for xilinx Spartan 3ADSP1800",
     .init = petalogix_s3adsp1800_init,
-    .is_default = 1
 };
 
 static void petalogix_s3adsp1800_machine_init(void)
 {
     qemu_register_machine(&petalogix_s3adsp1800_machine);
+    machine_set_default("petalogix-s3adsp1800");
 }
 
 machine_init(petalogix_s3adsp1800_machine_init);
diff --git a/hw/ppc_newworld.c b/hw/ppc_newworld.c
index 3be0c2d..acc320a 100644
--- a/hw/ppc_newworld.c
+++ b/hw/ppc_newworld.c
@@ -446,14 +446,14 @@  static QEMUMachine core99_machine = {
         QOPT_VALUE("max_cpus", stringify(MAX_CPUS)),
         { /* end of list */ }
     },
-#ifdef TARGET_PPC64
-    .is_default = 1,
-#endif
 };
 
 static void core99_machine_init(void)
 {
     qemu_register_machine(&core99_machine);
+#ifdef TARGET_PPC64
+    machine_set_default("mac99");
+#endif
 }
 
 machine_init(core99_machine_init);
diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c
index 7fab893..365a2b6 100644
--- a/hw/ppc_oldworld.c
+++ b/hw/ppc_oldworld.c
@@ -418,14 +418,14 @@  static QEMUMachine heathrow_machine = {
         QOPT_VALUE("max_cpus", stringify(MAX_CPUS)),
         { /* end of list */ }
     },
-#ifndef TARGET_PPC64
-    .is_default = 1,
-#endif
 };
 
 static void heathrow_machine_init(void)
 {
     qemu_register_machine(&heathrow_machine);
+#ifndef TARGET_PPC64
+    machine_set_default("g3beige");
+#endif
 }
 
 machine_init(heathrow_machine_init);
diff --git a/hw/s390-virtio.c b/hw/s390-virtio.c
index a769ba0..6c0f400 100644
--- a/hw/s390-virtio.c
+++ b/hw/s390-virtio.c
@@ -281,12 +281,12 @@  static QEMUMachine s390_machine = {
         QOPT_VALUE("max_cpus", "255"),
         { /* end of list */ }
     },
-    .is_default = 1,
 };
 
 static void s390_machine_init(void)
 {
     qemu_register_machine(&s390_machine);
+    machine_set_default("s390-virtio");
 }
 
 machine_init(s390_machine_init);
diff --git a/hw/shix.c b/hw/shix.c
index da5716e..8648c41 100644
--- a/hw/shix.c
+++ b/hw/shix.c
@@ -91,12 +91,12 @@  static QEMUMachine shix_machine = {
     .name = "shix",
     .desc = "shix card",
     .init = shix_init,
-    .is_default = 1,
 };
 
 static void shix_machine_init(void)
 {
     qemu_register_machine(&shix_machine);
+    machine_set_default("shix");
 }
 
 machine_init(shix_machine_init);
diff --git a/hw/sun4m.c b/hw/sun4m.c
index 7d24873..8098cef 100644
--- a/hw/sun4m.c
+++ b/hw/sun4m.c
@@ -1324,7 +1324,6 @@  static QEMUMachine ss5_machine = {
         QOPT_VALUE("default_drive", "scsi"),
         { /* end of list */ }
     },
-    .is_default = 1,
 };
 
 static QEMUMachine ss10_machine = {
@@ -1838,6 +1837,7 @@  static void ss2_machine_init(void)
     qemu_register_machine(&ss1000_machine);
     qemu_register_machine(&ss2000_machine);
     qemu_register_machine(&ss2_machine);
+    machine_set_default("SS-5");
 }
 
 machine_init(ss2_machine_init);
diff --git a/hw/sun4u.c b/hw/sun4u.c
index 8b112be..13e7219 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -923,7 +923,6 @@  static QEMUMachine sun4u_machine = {
     .name = "sun4u",
     .desc = "Sun4u platform",
     .init = sun4u_init,
-    .is_default = 1,
 };
 
 static QEMUMachine sun4v_machine = {
@@ -943,6 +942,7 @@  static void sun4u_machine_init(void)
     qemu_register_machine(&sun4u_machine);
     qemu_register_machine(&sun4v_machine);
     qemu_register_machine(&niagara_machine);
+    machine_set_default("sun4u");
 }
 
 machine_init(sun4u_machine_init);
diff --git a/vl.c b/vl.c
index 34e48f8..3d49ba7 100644
--- a/vl.c
+++ b/vl.c
@@ -1591,6 +1591,7 @@  void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
 /* machine registration */
 
 static QEMUMachine *first_machine = NULL;
+static const char *default_machine = NULL;
 
 int qemu_register_machine(QEMUMachine *m)
 {
@@ -1603,6 +1604,11 @@  int qemu_register_machine(QEMUMachine *m)
     return 0;
 }
 
+void machine_set_default(const char *name)
+{
+    default_machine = name;
+}
+
 static QEMUMachine *find_machine(const char *name)
 {
     QEMUMachine *m;
@@ -1618,14 +1624,7 @@  static QEMUMachine *find_machine(const char *name)
 
 static QEMUMachine *find_default_machine(void)
 {
-    QEMUMachine *m;
-
-    for(m = first_machine; m != NULL; m = m->next) {
-        if (m->is_default) {
-            return m;
-        }
-    }
-    return NULL;
+    return find_machine(default_machine);
 }
 
 /***********************************************************/
@@ -2764,7 +2763,9 @@  int main(int argc, char **argv, char **envp)
                                    m->alias, m->desc, m->name);
                         printf("%-10s %s%s\n",
                                m->name, m->desc,
-                               m->is_default ? " (default)" : "");
+                               (!strcmp(m->name, default_machine) ||
+                                !strcmp(m->alias, default_machine)) ? 
+                               " (default)" : "");
                     }
                     exit(0);
                 }