From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50014) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vnnr9-0007FD-Ur for qemu-devel@nongnu.org; Tue, 03 Dec 2013 06:09:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vnnr1-0002kJ-6u for qemu-devel@nongnu.org; Tue, 03 Dec 2013 06:09:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:27609) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vnnr0-0002iy-Uq for qemu-devel@nongnu.org; Tue, 03 Dec 2013 06:09:23 -0500 Date: Tue, 3 Dec 2013 12:09:18 +0100 From: Igor Mammedov Message-ID: <20131203120918.255b0d47@nial.usersys.redhat.com> In-Reply-To: <1386042168-20077-1-git-send-email-aik@ozlabs.ru> References: <1386042168-20077-1-git-send-email-aik@ozlabs.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v4] cpu: add suboptions support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexey Kardashevskiy Cc: qemu-devel@nongnu.org, Andreas =?ISO-8859-1?B?RuRyYmVy?= On Tue, 3 Dec 2013 14:42:48 +1100 Alexey Kardashevskiy wrote: > This adds suboptions support for -cpu. This keeps @cpu_model in order not > to break the existing architectures/machines. >=20 > Cc: Andreas F=E4rber > Signed-off-by: Alexey Kardashevskiy > --- > Changes: > v4: > * moved QemuOpts logic to qeom/cpu.c > * added cpu_opt_get() as the machine init code wants to know the CPU name > to create a CPU object > --- > include/qom/cpu.h | 41 +++++++++++++++++++++++++++++++++++++++++ > qom/cpu.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ > vl.c | 23 +++++++++++++++++++++++ > 3 files changed, 113 insertions(+) >=20 > diff --git a/include/qom/cpu.h b/include/qom/cpu.h > index 7739e00..07330e1 100644 > --- a/include/qom/cpu.h > +++ b/include/qom/cpu.h > @@ -124,6 +124,7 @@ typedef struct CPUClass { > int cpuid, void *opaque); > int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu, > void *opaque); > + void (*parse_options)(CPUState *cpu, Error **errp); > =20 > const struct VMStateDescription *vmsd; > int gdb_num_core_regs; > @@ -327,6 +328,46 @@ static inline hwaddr cpu_get_phys_page_debug(CPUStat= e *cpu, vaddr addr) > #endif > =20 > /** > + * cpu_parse_options: > + * @cpu: The CPU to set options for. > + * > + * Parses CPU options if the CPU class has a custom handler defined. > + * > + * Returns: -1 if a custom handler is defined and failed, 0 otherwise. > + */ > +static inline int cpu_parse_options(CPUState *cpu) why not pass up the stack errp, vs returning -1? And of cause, there should be a patch that demonstrates an actual user of cpu_parse_options(). > +{ > + CPUClass *cc =3D CPU_GET_CLASS(cpu); > + Error *err =3D NULL; > + > + if (cc->parse_options) { > + cc->parse_options(cpu, &err); > + if (err) { > + return -1; > + } > + } > + > + /* No callback, let arch do it the old way */ > + return 0; > +} > + > +/** > + * cpu_default_parse_options_func: > + * The default handler for CPUClass::parse_options > + * @cpu: the CPU to set option for. > + * @errp: the handling error descriptor. > + */ > +void cpu_default_parse_options_func(CPUState *cpu, Error **errp); where is it used? Maybe it should be static inside of qom/cpu.c and assigned in cpu_class_init() for TYPE_CPU. > + > +/** > + * cpu_get_opt: > + * @name: The parameter name > + * > + * Returns: a CPU parameter value. > + */ > +const char *cpu_opt_get(const char *name); > + > +/** > * cpu_reset: > * @cpu: The CPU whose state is to be reset. > */ > diff --git a/qom/cpu.c b/qom/cpu.c > index 818fb26..fb95cb4 100644 > --- a/qom/cpu.c > +++ b/qom/cpu.c > @@ -24,6 +24,8 @@ > #include "qemu/notify.h" > #include "qemu/log.h" > #include "sysemu/sysemu.h" > +#include "qapi/qmp/qerror.h" > +#include "qemu/config-file.h" > =20 > bool cpu_exists(int64_t id) > { > @@ -273,3 +275,50 @@ static void cpu_register_types(void) > } > =20 > type_init(cpu_register_types) > + > +static int cpu_set_property(const char *name, const char *value, void *o= paque) > +{ > + Error *err =3D NULL; > + > + if (strcmp(name, "type") =3D=3D 0) { > + return 0; > + } > + > + object_property_parse(opaque, value, name, &err); > + if (err !=3D NULL) { > + qerror_report_err(err); > + error_free(err); > + return -1; > + } > + > + return 0; > +} > + > +static QemuOpts *cpu_get_opts(void) > +{ > + QemuOptsList *list; > + > + list =3D qemu_find_opts("cpu"); > + assert(list); > + return qemu_opts_find(list, NULL); > +} > + > +void cpu_default_parse_options_func(CPUState *cpu, Error **errp) > +{ > + QemuOpts *opts =3D cpu_get_opts(); > + > + if (opts && qemu_opt_foreach(opts, cpu_set_property, cpu, 1)) { > + error_setg(errp, "Bad option"); > + } > +} > + > +const char *cpu_opt_get(const char *name) > +{ > + QemuOpts *opts =3D cpu_get_opts(); > + > + if (!opts) { > + return NULL; > + } > + > + return qemu_opt_get(cpu_get_opts(), name); > +} > diff --git a/vl.c b/vl.c > index 8d5d874..f7c4c0a 100644 > --- a/vl.c > +++ b/vl.c > @@ -433,6 +433,16 @@ static QemuOptsList qemu_machine_opts =3D { > }, > }; > =20 > +static QemuOptsList qemu_cpu_opts =3D { > + .name =3D "cpu", > + .implied_opt_name =3D "type", > + .merge_lists =3D true, > + .head =3D QTAILQ_HEAD_INITIALIZER(qemu_cpu_opts.head), > + .desc =3D { > + { /* End of list */ } > + }, > +}; > + > static QemuOptsList qemu_boot_opts =3D { > .name =3D "boot-opts", > .implied_opt_name =3D "order", > @@ -2880,6 +2890,7 @@ int main(int argc, char **argv, char **envp) > qemu_add_opts(&qemu_trace_opts); > qemu_add_opts(&qemu_option_rom_opts); > qemu_add_opts(&qemu_machine_opts); > + qemu_add_opts(&qemu_cpu_opts); > qemu_add_opts(&qemu_smp_opts); > qemu_add_opts(&qemu_boot_opts); > qemu_add_opts(&qemu_sandbox_opts); > @@ -2975,7 +2986,19 @@ int main(int argc, char **argv, char **envp) > } > case QEMU_OPTION_cpu: > /* hw initialization will check this */ > + > + /* Store cpu_model for old style parser */ > cpu_model =3D optarg; > + > + /* > + * Parse and save options in the cpu options list > + * for a new parser > + */ > + olist =3D qemu_find_opts("cpu"); > + opts =3D qemu_opts_parse(olist, optarg, 1); > + if (!opts) { > + exit(1); > + } > break; > case QEMU_OPTION_hda: > {