qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: Marcel Apfelbaum <marcel.a@redhat.com>, qemu-devel@nongnu.org
Cc: mst@redhat.com, aik@ozlabs.ru, lcapitulino@redhat.com,
	blauwirbel@gmail.com, jcmvbkbc@gmail.com,
	edgar.iglesias@gmail.com, gxt@mprc.pku.edu.cn,
	peter.chubb@nicta.com.au, proljc@gmail.com, agraf@suse.de,
	scottwood@freescale.com, borntraeger@de.ibm.com,
	hpoussin@reactos.org, aliguori@amazon.com, lersek@redhat.com,
	mdroth@linux.vnet.ibm.com, chouteau@adacore.com,
	jan.kiszka@web.de, stefanha@redhat.com, cornelia.huck@de.ibm.com,
	peter.crosthwaite@xilinx.com, mark.langsdorf@calxeda.com,
	armbru@redhat.com, michael@walle.cc, qemu-ppc@nongnu.org,
	pbonzini@redhat.com, aurelien@aurel32.net
Subject: Re: [Qemu-devel] [PATCH 4/4] hw/machine: qemu machine opts as properties to QemuMachineState
Date: Tue, 13 May 2014 19:54:39 +0200	[thread overview]
Message-ID: <53725C5F.7040801@suse.de> (raw)
In-Reply-To: <1399473780-20374-5-git-send-email-marcel.a@redhat.com>

Am 07.05.2014 16:43, schrieb Marcel Apfelbaum:
> Make machine's QemuOpts QOM properties of machine. The properties
> are automatically filled in. This opens the possiblity to create
> opts per machine rather than global.
> 
> Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
> ---
>  hw/core/machine.c   | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  include/hw/boards.h |   6 +-
>  vl.c                |   9 +-
>  3 files changed, 265 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index d3ffef7..fff8317 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -11,6 +11,260 @@
>   */
>  
>  #include "hw/boards.h"
> +#include "qapi/visitor.h"
> +
> +static char *machine_get_accel(Object *obj, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);

Contrary to 1/4, you here use the overly verbose "machine_state".

> +    return g_strdup(machine_state->accel);
> +}
> +
> +static void machine_set_accel(Object *obj, const char *value, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    machine_state->accel = g_strdup(value);
> +}
> +
> +static bool machine_get_kernel_irqchip(Object *obj, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    return machine_state->kernel_irqchip;
> +}
> +
> +static void machine_set_kernel_irqchip(Object *obj, bool value, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    machine_state->kernel_irqchip = value;
> +}
> +
> +static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v,
> +                                       void *opaque, const char *name,
> +                                       Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    int64_t value = machine_state->kvm_shadow_mem;
> +
> +    visit_type_int(v, &value, name, errp);
> +}
> +
> +static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
> +                                       void *opaque, const char *name,
> +                                       Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    Error *error = NULL;
> +    int64_t value;
> +
> +    visit_type_int(v, &value, name, &error);
> +    if (error) {
> +        error_propagate(errp, error);
> +        return;
> +    }
> +
> +    machine_state->kvm_shadow_mem = value;
> +}
> +
> +static char *machine_get_kernel(Object *obj, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    return g_strdup(machine_state->kernel_filename);
> +}
> +
> +static void machine_set_kernel(Object *obj, const char *value, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    machine_state->kernel_filename = g_strdup(value);
> +}
> +
> +static char *machine_get_initrd(Object *obj, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    return g_strdup(machine_state->initrd_filename);
> +}
> +
> +static void machine_set_initrd(Object *obj, const char *value, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    machine_state->initrd_filename = g_strdup(value);
> +}
> +
> +static char *machine_get_append(Object *obj, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    return g_strdup(machine_state->kernel_cmdline);
> +}
> +
> +static void machine_set_append(Object *obj, const char *value, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    machine_state->kernel_cmdline = g_strdup(value);
> +}
> +
> +static char *machine_get_dtb(Object *obj, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    return g_strdup(machine_state->dtb);
> +}
> +
> +static void machine_set_dtb(Object *obj, const char *value, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    machine_state->dtb = g_strdup(value);
> +}
> +
> +static char *machine_get_dumpdtb(Object *obj, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    return g_strdup(machine_state->dumpdtb);
> +}
> +
> +static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    machine_state->dumpdtb = g_strdup(value);
> +}
> +
> +static void machine_get_phandle_start(Object *obj, Visitor *v,
> +                                       void *opaque, const char *name,
> +                                       Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    int64_t value = machine_state->phandle_start;
> +
> +    visit_type_int(v, &value, name, errp);
> +}
> +
> +static void machine_set_phandle_start(Object *obj, Visitor *v,
> +                                       void *opaque, const char *name,
> +                                       Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    Error *error = NULL;
> +    int64_t value;
> +
> +    visit_type_int(v, &value, name, &error);
> +    if (error) {
> +        error_propagate(errp, error);
> +        return;
> +    }
> +
> +    machine_state->phandle_start = value;
> +}
> +
> +static char *machine_get_dt_compatible(Object *obj, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    return g_strdup(machine_state->dt_compatible);
> +}
> +
> +static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    machine_state->dt_compatible = g_strdup(value);
> +}
> +
> +static bool machine_get_dump_guest_core(Object *obj, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    return machine_state->dump_guest_core;
> +}
> +
> +static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    machine_state->dump_guest_core = value;
> +}
> +
> +static bool machine_get_mem_merge(Object *obj, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    return machine_state->mem_merge;
> +}
> +
> +static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    machine_state->mem_merge = value;
> +}
> +
> +static bool machine_get_usb(Object *obj, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    return machine_state->usb;
> +}
> +
> +static void machine_set_usb(Object *obj, bool value, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    machine_state->usb = value;
> +}
> +
> +static char *machine_get_firmware(Object *obj, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    return g_strdup(machine_state->firmware);
> +}
> +
> +static void machine_set_firmware(Object *obj, const char *value, Error **errp)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +    machine_state->firmware = g_strdup(value);
> +}

Naming aside, this all looks good up to here.

> +
> +static void machine_initfn(Object *obj)
> +{
> +    object_property_add_str(obj, "accel",
> +                            machine_get_accel, machine_set_accel, NULL);
> +    object_property_add_bool(obj, "kernel_irqchip",

"kernel-irqchip"

> +                             machine_get_kernel_irqchip,
> +                             machine_set_kernel_irqchip,
> +                             NULL);
> +    object_property_add(obj, "kvm_shadow_mem", "int",

"kvm-shadow-mem"

> +                        machine_get_kvm_shadow_mem,
> +                        machine_set_kvm_shadow_mem,
> +                        NULL, NULL, NULL);
> +    object_property_add_str(obj, "kernel",
> +                            machine_get_kernel, machine_set_kernel, NULL);
> +    object_property_add_str(obj, "initrd",
> +                            machine_get_initrd, machine_set_initrd, NULL);
> +    object_property_add_str(obj, "append",
> +                            machine_get_append, machine_set_append, NULL);
> +    object_property_add_str(obj, "dtb",
> +                            machine_get_dtb, machine_set_dtb, NULL);
> +    object_property_add_str(obj, "dumpdtb",
> +                            machine_get_dumpdtb, machine_set_dumpdtb, NULL);
> +    object_property_add(obj, "phandle_start", "int",

"phandle-start"

> +                        machine_get_phandle_start,
> +                        machine_set_phandle_start,
> +                        NULL, NULL, NULL);
> +    object_property_add_str(obj, "dt_compatible",

"dt-compatible"

QOM conventions require dashes rather than underscores. We faced the
same issue with -cpu legacy options, and the safest solution probably is
to replace patch 3/4 and its usage below with a machine-specific
function that converts from underscore to dash before setting the property.

> +                            machine_get_dt_compatible,
> +                            machine_set_dt_compatible,
> +                            NULL);
> +    object_property_add_bool(obj, "dump-guest-core",
> +                             machine_get_dump_guest_core,
> +                             machine_set_dump_guest_core,
> +                             NULL);
> +    object_property_add_bool(obj, "mem-merge",
> +                             machine_get_mem_merge, machine_set_mem_merge, NULL);
> +    object_property_add_bool(obj, "usb", machine_get_usb, machine_set_usb, NULL);
> +    object_property_add_str(obj, "firmware",
> +                            machine_get_firmware, machine_set_firmware, NULL);
> +}
> +
> +static void qemu_machine_finalize(Object *obj)
> +{
> +    MachineState *machine_state = MACHINE(obj);
> +
> +    g_free(machine_state->accel);
> +    g_free(machine_state->kernel_filename);
> +    g_free(machine_state->initrd_filename);
> +    g_free(machine_state->kernel_cmdline);
> +    g_free(machine_state->dtb);
> +    g_free(machine_state->dumpdtb);
> +    g_free(machine_state->dt_compatible);
> +    g_free(machine_state->firmware);
> +}
>  
>  static const TypeInfo machine_info = {
>      .name = TYPE_MACHINE,
> @@ -18,6 +272,8 @@ static const TypeInfo machine_info = {
>      .abstract = true,
>      .class_size = sizeof(MachineClass),
>      .instance_size = sizeof(MachineState),
> +    .instance_init = machine_initfn,
> +    .instance_finalize = qemu_machine_finalize,

Do we need an .instance_post_init to apply -global property defaults?

>  };
>  
>  static void machine_register_types(void)
> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index eba0574..69664a5 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -114,9 +114,9 @@ struct MachineState {
>      const MachineClass *machine;
>      ram_addr_t ram_size;
>      const char *boot_order;
> -    const char *kernel_filename;
> -    const char *kernel_cmdline;
> -    const char *initrd_filename;
> +    char *kernel_filename;
> +    char *kernel_cmdline;
> +    char *initrd_filename;
>      const char *cpu_model;
>  };
>  
> diff --git a/vl.c b/vl.c
> index 6ec6c1a..e92871c 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -4216,6 +4216,12 @@ int main(int argc, char **argv, char **envp)
>          exit(0);
>      }
>  
> +    machine_opts = qemu_get_machine_opts();
> +    if (qemu_opt_foreach(machine_opts, object_set_property, current_machine, 1) < 0) {
> +        object_unref(OBJECT(current_machine));
> +        exit(1);
> +    }
> +
>      configure_accelerator(machine_class);
>  
>      if (qtest_chrdev) {
> @@ -4426,9 +4432,6 @@ int main(int argc, char **argv, char **envp)
>      current_machine->machine = machine_class;
>      current_machine->ram_size = ram_size;
>      current_machine->boot_order = boot_order;
> -    current_machine->kernel_filename = kernel_filename;
> -    current_machine->kernel_cmdline = kernel_cmdline;
> -    current_machine->initrd_filename = initrd_filename;

So these three are the only fields set from -machine itself?

>      current_machine->cpu_model = cpu_model;
>  
>      machine_class->init(current_machine);

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

  reply	other threads:[~2014-05-13 17:55 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-07 14:42 [Qemu-devel] [Qemu-detvel] [PATCH 0/4] machine: QemuOpts per machine Marcel Apfelbaum
2014-05-07 14:42 ` [Qemu-devel] [PATCH 1/4] machine: conversion of QEMUMachineInitArgs to MachineState Marcel Apfelbaum
2014-05-12 16:00   ` Laszlo Ersek
2014-05-13 13:25   ` Cornelia Huck
2014-05-13 15:44   ` Michael S. Tsirkin
2014-05-13 17:34   ` Andreas Färber
2014-05-15 15:04   ` Markus Armbruster
2014-05-18  8:37     ` Marcel Apfelbaum
2014-05-16 14:39   ` Igor Mammedov
2014-05-16 18:33     ` Andreas Färber
2014-05-18  8:51       ` Marcel Apfelbaum
2014-05-16 16:20   ` Igor Mammedov
2014-05-16 18:38     ` Andreas Färber
2014-05-18  8:48       ` Marcel Apfelbaum
2014-05-07 14:42 ` [Qemu-devel] [PATCH 2/4] qapi: output visitor crashes qemu if it encounters a NULL value Marcel Apfelbaum
2014-05-13 17:36   ` Andreas Färber
2014-05-13 19:08     ` Eric Blake
2014-05-14 17:00       ` Andreas Färber
2014-05-14 17:29         ` Marcel Apfelbaum
2014-05-14 18:25           ` Luiz Capitulino
2014-05-14 19:51             ` Markus Armbruster
2014-05-14 20:38             ` Michael Roth
2014-05-18  8:42               ` Marcel Apfelbaum
2014-05-14 20:26           ` Andreas Färber
2014-05-15 16:13   ` Markus Armbruster
2014-05-15 16:27     ` Michael Roth
2014-05-15 17:19       ` Markus Armbruster
2014-05-15 17:55         ` Michael Roth
2014-05-07 14:42 ` [Qemu-devel] [PATCH 3/4] vl.c: do not set 'type' property in obj_set_property Marcel Apfelbaum
2014-05-13 17:39   ` Andreas Färber
2014-05-15 16:15   ` Markus Armbruster
2014-05-15 16:38     ` Andreas Färber
2014-05-15 17:13       ` Paolo Bonzini
2014-05-07 14:43 ` [Qemu-devel] [PATCH 4/4] hw/machine: qemu machine opts as properties to QemuMachineState Marcel Apfelbaum
2014-05-13 17:54   ` Andreas Färber [this message]
2014-05-13 13:13 ` [Qemu-devel] [Qemu-detvel] [PATCH 0/4] machine: QemuOpts per machine Marcel Apfelbaum

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=53725C5F.7040801@suse.de \
    --to=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=aik@ozlabs.ru \
    --cc=aliguori@amazon.com \
    --cc=armbru@redhat.com \
    --cc=aurelien@aurel32.net \
    --cc=blauwirbel@gmail.com \
    --cc=borntraeger@de.ibm.com \
    --cc=chouteau@adacore.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=gxt@mprc.pku.edu.cn \
    --cc=hpoussin@reactos.org \
    --cc=jan.kiszka@web.de \
    --cc=jcmvbkbc@gmail.com \
    --cc=lcapitulino@redhat.com \
    --cc=lersek@redhat.com \
    --cc=marcel.a@redhat.com \
    --cc=mark.langsdorf@calxeda.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=michael@walle.cc \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.chubb@nicta.com.au \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=proljc@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=scottwood@freescale.com \
    --cc=stefanha@redhat.com \
    /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).