From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: Blue Swirl <blauwirbel@gmail.com>, patches@linaro.org
Subject: [Qemu-devel] [PATCH v3 3/7] vl.c: Fix machine registration so QEMUMachine structs can be const
Date: Tue, 29 Mar 2011 15:08:20 +0100 [thread overview]
Message-ID: <1301407704-24541-4-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1301407704-24541-1-git-send-email-peter.maydell@linaro.org>
Reimplement the list of QEMUMachine structures so that we don't keep the
'next' pointer inside the QEMUMachine struct itself. This allows us to
accept a const struct pointer in qemu_register_machine. The few places
in vl.c which were implicitly assuming that QEMUMachine structs were
writable have been updated.
We also take the opportunity to correct the return type of
qemu_register_machine from 'int' to 'void', since it can never fail
and none of its callers check the return value.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/boards.h | 5 +--
vl.c | 99 ++++++++++++++++++++++++++++++++++------------------------
2 files changed, 60 insertions(+), 44 deletions(-)
diff --git a/hw/boards.h b/hw/boards.h
index 5f41fce..731d8c7 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -29,11 +29,10 @@ typedef struct QEMUMachine {
no_sdcard:1;
int is_default;
GlobalProperty *compat_props;
- struct QEMUMachine *next;
} QEMUMachine;
-int qemu_register_machine(QEMUMachine *m);
+void qemu_register_machine(const QEMUMachine *m);
-extern QEMUMachine *current_machine;
+extern const QEMUMachine *current_machine;
#endif
diff --git a/vl.c b/vl.c
index 69cb29b..d58bbf8 100644
--- a/vl.c
+++ b/vl.c
@@ -1090,45 +1090,62 @@ int qemu_set_fd_handler(int fd,
/***********************************************************/
/* machine registration */
-static QEMUMachine *first_machine = NULL;
-QEMUMachine *current_machine = NULL;
+typedef struct QEMUMachineListEntry {
+ QTAILQ_ENTRY(QEMUMachineListEntry) entry;
+ const QEMUMachine *machine;
+} QEMUMachineListEntry;
-int qemu_register_machine(QEMUMachine *m)
+static QTAILQ_HEAD(machine_list, QEMUMachineListEntry) machine_list =
+ QTAILQ_HEAD_INITIALIZER(machine_list);
+
+const QEMUMachine *current_machine = NULL;
+
+void qemu_register_machine(const QEMUMachine *m)
{
- QEMUMachine **pm;
- pm = &first_machine;
- while (*pm != NULL)
- pm = &(*pm)->next;
- m->next = NULL;
- *pm = m;
- return 0;
+ QEMUMachineListEntry *me = qemu_mallocz(sizeof(QEMUMachineListEntry));
+ me->machine = m;
+ QTAILQ_INSERT_TAIL(&machine_list, me, entry);
}
-static QEMUMachine *find_machine(const char *name)
+static const QEMUMachine *find_machine(const char *name)
{
- QEMUMachine *m;
+ QEMUMachineListEntry *me;
- for(m = first_machine; m != NULL; m = m->next) {
- if (!strcmp(m->name, name))
- return m;
- if (m->alias && !strcmp(m->alias, name))
- return m;
+ QTAILQ_FOREACH(me, &machine_list, entry) {
+ if (!strcmp(me->machine->name, name)) {
+ return me->machine;
+ }
+ if (me->machine->alias && !strcmp(me->machine->alias, name)) {
+ return me->machine;
+ }
}
return NULL;
}
-static QEMUMachine *find_default_machine(void)
+static const QEMUMachine *find_default_machine(void)
{
- QEMUMachine *m;
-
- for(m = first_machine; m != NULL; m = m->next) {
- if (m->is_default) {
- return m;
+ QEMUMachineListEntry *me;
+ QTAILQ_FOREACH(me, &machine_list, entry) {
+ if (me->machine->is_default) {
+ return me->machine;
}
}
return NULL;
}
+static void print_machines(void)
+{
+ QEMUMachineListEntry *me;
+ QTAILQ_FOREACH(me, &machine_list, entry) {
+ const QEMUMachine *m = me->machine;
+ if (m->alias) {
+ printf("%-10s %s (alias of %s)\n", m->alias, m->desc, m->name);
+ }
+ printf("%-10s %s%s\n", m->name, m->desc,
+ m->is_default ? " (default)" : "");
+ }
+}
+
/***********************************************************/
/* main execution loop */
@@ -2050,7 +2067,7 @@ int main(int argc, char **argv, char **envp)
int optind;
const char *optarg;
const char *loadvm = NULL;
- QEMUMachine *machine;
+ const QEMUMachine *machine;
const char *cpu_model;
int tb_size;
const char *pid_file = NULL;
@@ -2146,16 +2163,8 @@ int main(int argc, char **argv, char **envp)
case QEMU_OPTION_M:
machine = find_machine(optarg);
if (!machine) {
- QEMUMachine *m;
printf("Supported machines are:\n");
- for(m = first_machine; m != NULL; m = m->next) {
- if (m->alias)
- printf("%-10s %s (alias of %s)\n",
- m->alias, m->desc, m->name);
- printf("%-10s %s%s\n",
- m->name, m->desc,
- m->is_default ? " (default)" : "");
- }
+ print_machines();
exit(*optarg != '?');
}
break;
@@ -2926,12 +2935,14 @@ int main(int argc, char **argv, char **envp)
if (!max_cpus)
max_cpus = smp_cpus;
- machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
- if (smp_cpus > machine->max_cpus) {
- fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
- "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
- machine->max_cpus);
- exit(1);
+ {
+ int machine_max_cpus = MAX(machine->max_cpus, 1);
+ if (smp_cpus > machine_max_cpus) {
+ fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max "
+ "cpus supported by machine `%s' (%d)\n",
+ smp_cpus, machine->name, machine_max_cpus);
+ exit(1);
+ }
}
qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
@@ -3073,8 +3084,14 @@ int main(int argc, char **argv, char **envp)
/* open the virtual block devices */
if (snapshot)
qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
- if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
- exit(1);
+
+ {
+ int use_scsi = machine->use_scsi;
+ if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
+ &use_scsi, 1) != 0) {
+ exit(1);
+ }
+ }
default_drive(default_cdrom, snapshot, machine->use_scsi,
IF_DEFAULT, 2, CDROM_OPTS);
--
1.7.1
next prev parent reply other threads:[~2011-03-29 14:15 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-29 14:08 [Qemu-devel] [PATCH v3 0/7] Let boards state maximum RAM limits in QEMUMachine struct Peter Maydell
2011-03-29 14:08 ` [Qemu-devel] [PATCH v3 1/7] Allow boards to specify maximum RAM size Peter Maydell
2011-03-29 14:08 ` [Qemu-devel] [PATCH v3 2/7] hw: Add maximum RAM specifications for ARM devboard models Peter Maydell
2011-03-29 14:08 ` Peter Maydell [this message]
2011-03-29 14:08 ` [Qemu-devel] [PATCH v3 4/7] hw/sun4m: Move QEMUMachine structs into sun4*_hwdef structs Peter Maydell
2011-03-29 14:08 ` [Qemu-devel] [PATCH v3 5/7] hw/sun4m: Use the QEMUMachine max_ram to implement memory limit Peter Maydell
2011-03-29 14:08 ` [Qemu-devel] [PATCH v3 6/7] hw/sun4m: Use a macro to hide the repetitive board init functions Peter Maydell
2011-03-29 14:08 ` [Qemu-devel] [PATCH v3 7/7] hw: Make QEMUMachine structure definitions const Peter Maydell
2011-03-30 7:48 ` [Qemu-devel] [PATCH v3 0/7] Let boards state maximum RAM limits in QEMUMachine struct Jes Sorensen
2011-03-30 8:09 ` Peter Maydell
2011-03-30 10:51 ` Jes Sorensen
2011-03-30 13:22 ` Peter Maydell
2011-03-30 13:55 ` Jes Sorensen
2011-03-30 13:56 ` Anthony Liguori
2011-03-30 14:07 ` Peter Maydell
2011-04-04 14:29 ` Jes Sorensen
2011-04-04 14:42 ` Peter Maydell
2011-04-04 14:53 ` Jes Sorensen
2011-04-04 16:54 ` Blue Swirl
2011-04-12 13:58 ` Jes Sorensen
2011-04-04 17:26 ` Peter Maydell
2011-04-12 13:55 ` Jes Sorensen
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=1301407704-24541-4-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=blauwirbel@gmail.com \
--cc=patches@linaro.org \
--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).