From patchwork Tue Mar 25 13:46:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 3890461 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 92D2A9F2B6 for ; Tue, 25 Mar 2014 20:16:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 817FB201F9 for ; Tue, 25 Mar 2014 20:16:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2408B201BC for ; Tue, 25 Mar 2014 20:16:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754947AbaCYUQf (ORCPT ); Tue, 25 Mar 2014 16:16:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44171 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754488AbaCYUQe (ORCPT ); Tue, 25 Mar 2014 16:16:34 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2PDkdrI026806 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 25 Mar 2014 09:46:41 -0400 Received: from localhost.tlv.redhat.com (dhcp-4-195.tlv.redhat.com [10.35.4.195]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s2PDkR4P012878; Tue, 25 Mar 2014 09:46:35 -0400 From: Marcel Apfelbaum To: qemu-devel@nongnu.org Cc: mst@redhat.com, afaerber@suse.de, peter.maydell@linaro.org, pbonzini@redhat.com, agraf@suse.de, lcapitulino@redhat.com, aliguori@amazon.com, stefano.stabellini@eu.citrix.com, armbru@redhat.com, stefanha@redhat.com, alex@alex.org.uk, rth@twiddle.net, famz@redhat.com, qemu-ppc@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 2/5] machine: remove QEMUMachine indirection from MachineClass Date: Tue, 25 Mar 2014 15:46:51 +0200 Message-Id: <1395755214-8957-3-git-send-email-marcel.a@redhat.com> In-Reply-To: <1395755214-8957-1-git-send-email-marcel.a@redhat.com> References: <1395755214-8957-1-git-send-email-marcel.a@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP No need to go through qemu_machine field. Use MachineClass fields directly. Signed-off-by: Marcel Apfelbaum --- device-hotplug.c | 2 +- qmp.c | 4 +-- vl.c | 103 ++++++++++++++++++++++++++++++++----------------------- 3 files changed, 63 insertions(+), 46 deletions(-) diff --git a/device-hotplug.c b/device-hotplug.c index ebfa6b1..eecb08e 100644 --- a/device-hotplug.c +++ b/device-hotplug.c @@ -40,7 +40,7 @@ DriveInfo *add_init_drive(const char *optstr) return NULL; mc = MACHINE_GET_CLASS(current_machine); - dinfo = drive_init(opts, mc->qemu_machine->block_default_type); + dinfo = drive_init(opts, mc->block_default_type); if (!dinfo) { qemu_opts_del(opts); return NULL; diff --git a/qmp.c b/qmp.c index 87a28f7..26eb589 100644 --- a/qmp.c +++ b/qmp.c @@ -117,8 +117,8 @@ void qmp_cpu_add(int64_t id, Error **errp) MachineClass *mc; mc = MACHINE_GET_CLASS(current_machine); - if (mc->qemu_machine->hot_add_cpu) { - mc->qemu_machine->hot_add_cpu(id, errp); + if (mc->hot_add_cpu) { + mc->hot_add_cpu(id, errp); } else { error_setg(errp, "Not supported"); } diff --git a/vl.c b/vl.c index 02bf8ec..62c630a 100644 --- a/vl.c +++ b/vl.c @@ -1583,8 +1583,29 @@ MachineState *current_machine; static void machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); - - mc->qemu_machine = data; + QEMUMachine *qm = data; + + mc->name = qm->name; + mc->alias = qm->alias; + mc->desc = qm->desc; + mc->init = qm->init; + mc->reset = qm->reset; + mc->hot_add_cpu = qm->hot_add_cpu; + mc->kvm_type = qm->kvm_type; + mc->block_default_type = qm->block_default_type; + mc->max_cpus = qm->max_cpus; + mc->no_serial = qm->no_serial; + mc->no_parallel = qm->no_parallel; + mc->use_virtcon = qm->use_virtcon; + mc->use_sclp = qm->use_sclp; + mc->no_floppy = qm->no_floppy; + mc->no_cdrom = qm->no_cdrom; + mc->no_sdcard = qm->no_sdcard; + mc->is_default = qm->is_default; + mc->default_machine_opts = qm->default_machine_opts; + mc->default_boot_order = qm->default_boot_order; + mc->compat_props = qm->compat_props; + mc->hw_version = qm->hw_version; } int qemu_register_machine(QEMUMachine *m) @@ -1611,12 +1632,12 @@ static MachineClass *find_machine(const char *name) for (el = machines; el; el = el->next) { MachineClass *temp = el->data; - if (!strcmp(temp->qemu_machine->name, name)) { + if (!strcmp(temp->name, name)) { mc = temp; break; } - if (temp->qemu_machine->alias && - !strcmp(temp->qemu_machine->alias, name)) { + if (temp->alias && + !strcmp(temp->alias, name)) { mc = temp; break; } @@ -1634,7 +1655,7 @@ MachineClass *find_default_machine(void) for (el = machines; el; el = el->next) { MachineClass *temp = el->data; - if (temp->qemu_machine->is_default) { + if (temp->is_default) { mc = temp; break; } @@ -1648,27 +1669,25 @@ MachineInfoList *qmp_query_machines(Error **errp) { GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false); MachineInfoList *mach_list = NULL; - QEMUMachine *m; for (el = machines; el; el = el->next) { MachineClass *mc = el->data; MachineInfoList *entry; MachineInfo *info; - m = mc->qemu_machine; info = g_malloc0(sizeof(*info)); - if (m->is_default) { + if (mc->is_default) { info->has_is_default = true; info->is_default = true; } - if (m->alias) { + if (mc->alias) { info->has_alias = true; - info->alias = g_strdup(m->alias); + info->alias = g_strdup(mc->alias); } - info->name = g_strdup(m->name); - info->cpu_max = !m->max_cpus ? 1 : m->max_cpus; + info->name = g_strdup(mc->name); + info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus; entry = g_malloc0(sizeof(*entry)); entry->value = info; @@ -1874,8 +1893,8 @@ void qemu_system_reset(bool report) mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL; - if (mc && mc->qemu_machine->reset) { - mc->qemu_machine->reset(); + if (mc && mc->reset) { + mc->reset(); } else { qemu_devices_reset(); } @@ -2684,12 +2703,11 @@ static MachineClass *machine_parse(const char *name) printf("Supported machines are:\n"); for (el = machines; el; el = el->next) { MachineClass *mc = el->data; - QEMUMachine *m = mc->qemu_machine; - if (m->alias) { - printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name); + if (mc->alias) { + printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name); } - printf("%-20s %s%s\n", m->name, m->desc, - m->is_default ? " (default)" : ""); + printf("%-20s %s%s\n", mc->name, mc->desc, + mc->is_default ? " (default)" : ""); } } @@ -2943,7 +2961,7 @@ int main(int argc, char **argv, char **envp) const char *optarg; const char *loadvm = NULL; MachineClass *machine_class; - QEMUMachine *machine; + QEMUMachine *machine = NULL; const char *cpu_model; const char *vga_model = NULL; const char *qtest_chrdev = NULL; @@ -3946,9 +3964,8 @@ int main(int argc, char **argv, char **envp) object_property_add_child(object_get_root(), "machine", OBJECT(current_machine), &error_abort); - machine = machine_class->qemu_machine; - if (machine->hw_version) { - qemu_set_version(machine->hw_version); + if (machine_class->hw_version) { + qemu_set_version(machine_class->hw_version); } if (qemu_opts_foreach(qemu_find_opts("object"), @@ -4008,11 +4025,11 @@ int main(int argc, char **argv, char **envp) smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL)); - machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */ - if (smp_cpus > machine->max_cpus) { + machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */ + if (smp_cpus > machine_class->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); + "supported by machine `%s' (%d)\n", smp_cpus, + machine_class->name, machine_class->max_cpus); exit(1); } @@ -4020,9 +4037,9 @@ int main(int argc, char **argv, char **envp) * Get the default machine options from the machine if it is not already * specified either by the configuration file or by the command line. */ - if (machine->default_machine_opts) { + if (machine_class->default_machine_opts) { qemu_opts_set_defaults(qemu_find_opts("machine"), - machine->default_machine_opts, 0); + machine_class->default_machine_opts, 0); } qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0); @@ -4031,25 +4048,25 @@ int main(int argc, char **argv, char **envp) if (!vga_model && !default_vga) { vga_interface_type = VGA_DEVICE; } - if (!has_defaults || machine->no_serial) { + if (!has_defaults || machine_class->no_serial) { default_serial = 0; } - if (!has_defaults || machine->no_parallel) { + if (!has_defaults || machine_class->no_parallel) { default_parallel = 0; } - if (!has_defaults || !machine->use_virtcon) { + if (!has_defaults || !machine_class->use_virtcon) { default_virtcon = 0; } - if (!has_defaults || !machine->use_sclp) { + if (!has_defaults || !machine_class->use_sclp) { default_sclp = 0; } - if (!has_defaults || machine->no_floppy) { + if (!has_defaults || machine_class->no_floppy) { default_floppy = 0; } - if (!has_defaults || machine->no_cdrom) { + if (!has_defaults || machine_class->no_cdrom) { default_cdrom = 0; } - if (!has_defaults || machine->no_sdcard) { + if (!has_defaults || machine_class->no_sdcard) { default_sdcard = 0; } if (!has_defaults) { @@ -4189,7 +4206,7 @@ int main(int argc, char **argv, char **envp) kernel_cmdline = qemu_opt_get(machine_opts, "append"); bios_name = qemu_opt_get(machine_opts, "firmware"); - boot_order = machine->default_boot_order; + boot_order = machine_class->default_boot_order; opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL); if (opts) { char *normal_boot_order; @@ -4283,11 +4300,11 @@ int main(int argc, char **argv, char **envp) 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->block_default_type, 1) != 0) { + &machine_class->block_default_type, 1) != 0) { exit(1); } - default_drive(default_cdrom, snapshot, machine->block_default_type, 2, + default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2, CDROM_OPTS); default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS); default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS); @@ -4371,8 +4388,8 @@ int main(int argc, char **argv, char **envp) exit (i == 1 ? 1 : 0); } - if (machine->compat_props) { - qdev_prop_register_global_list(machine->compat_props); + if (machine_class->compat_props) { + qdev_prop_register_global_list(machine_class->compat_props); } qemu_add_globals(); @@ -4387,7 +4404,7 @@ int main(int argc, char **argv, char **envp) .cpu_model = cpu_model }; current_machine->init_args = args; - machine->init(¤t_machine->init_args); + machine_class->init(¤t_machine->init_args); audio_init();