tests for -m option
cover tests for -m option
Series adds properties to machine class for its ram_size, ram_slots, maxram_size fields making them available via QMP interface so that management tools and unit tests could query values.
The last patch provides rudimentary -m option testing and basis for memory hotplug tests that will be added later.
git repo for testing:
https://github.com/imammedo/qemu/commits/memory-hotplug-tests-v1
Igor Mammedov (4):
switch RAM_ADDR_FMT format specifier to print decimal vl.c: use single local_err throughout main()
machine: convert ram_size, maxram_size, ram_slots to properties test -m option parameters
arch_init.c | 14 ++-- exec.c | 4 +- hw/core/machine.c | 181 +++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc.c | 4 +- hw/ppc/ppc405_boards.c | 2 +- include/exec/cpu-common.h | 6 +- include/hw/boards.h | 5 + numa.c | 2 +- tests/Makefile | 2 + tests/memhp-test.c | 145 ++++++++++++++++++++++++++++++++++++ vl.c | 127 ++++++++++++++------------------ xen-hvm.c | 11 +-- 12 files changed, 410 insertions(+), 93 deletions(-) create mode 100644 tests/memhp-test.c
PATCH 1/4 switch RAM_ADDR_FMT format specifier to print decimal
... and add RAM_ADDR_FMTX for hex format. In addition fix places to print sizes/lengths as decimal and addresses as hex.
Also drop "%" from RAM_ADDR_FMT macro and use it like other PRIfoo format placeholders specifying "%" explicitly.
--- arch_init.c | 14 +++++++------- exec.c | 4 ++-- hw/i386/pc.c | 4 ++-- hw/ppc/ppc405_boards.c | 2 +- include/exec/cpu-common.h | 6 ++++-- numa.c | 2 +- vl.c | 6 +++--- xen-hvm.c | 11 +++++------ 8 files changed, 25 insertions(+), 24 deletions(-)
arch_init.c +7 -7
@@ -1072,8 +1072,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) QTAILQ_FOREACH(block, &ram_list.blocks, next) {if (!strncmp (id, block->idstr,sizeof (id))) {if (block->length != length) { -error_report ("Length mismatch: %s: " RAM_ADDR_FMT -" in != " RAM_ADDR_FMT , id, length, +error_report ("Length mismatch: %s: %" RAM_ADDR_FMT +" in != %" RAM_ADDR_FMT , id, length, block->length); ret = -EINVAL ; }
@@ -1098,7 +1098,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) host =host_from_stream_offset (f, addr, flags);if (!host) { -error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); +error_report ("Illegal RAM offset %" RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }
@@ -1110,7 +1110,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) host =host_from_stream_offset (f, addr, flags);if (!host) { -error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); +error_report ("Illegal RAM offset %" RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }
@@ -1119,14 +1119,14 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) }else if (flags &RAM_SAVE_FLAG_XBZRLE ) {void *host =host_from_stream_offset (f, addr, flags);if (!host) { -error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); +error_report ("Illegal RAM offset %" RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }if (load_xbzrle (f, addr, host) <0 ) { -error_report ("Failed to decompress XBZRLE page at " -RAM_ADDR_FMT , addr); +error_report ("Failed to decompress XBZRLE page at %" +RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }
exec.c +2 -2
@@ -1435,8 +1435,8 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) flags, -1, 0); }if (area != vaddr) { -fprintf (stderr,"Could not remap addr: " -RAM_ADDR_FMT "@" RAM_ADDR_FMT "\n" , +fprintf (stderr,"Could not remap addr: %" +RAM_ADDR_FMTX "@%" RAM_ADDR_FMTX "\n" , length, addr);exit (1 ); }
hw/i386/pc.c +2 -2
@@ -1257,8 +1257,8 @@ FWCfgState *pc_memory_init(MachineState *machine,if ((pcms->hotplug_memory_base + hotplug_mem_size) < hotplug_mem_size) { -error_report ("unsupported amount of maximum memory: " RAM_ADDR_FMT , - machine->maxram_size); +error_report ("unsupported amount of maximum memory: %" +RAM_ADDR_FMT , machine->maxram_size);exit (EXIT_FAILURE ); }
hw/ppc/ppc405_boards.c +1 -1
@@ -358,7 +358,7 @@ static void ref405ep_init(MachineState *machine) bdloc =0 ; }#ifdef DEBUG_BOARD_INIT -printf ("bdloc " RAM_ADDR_FMT "\n" , bdloc); +printf ("bdloc %" RAM_ADDR_FMTX "\n" , bdloc);printf ("%s: Done\n" , __func__);#endif }
include/exec/cpu-common.h +4 -2
@@ -38,11 +38,13 @@ enum device_endian {#if defined(CONFIG_XEN_BACKEND )typedef uint64_t ram_addr_t ;# define RAM_ADDR_MAX UINT64_MAX -# define RAM_ADDR_FMT "%" PRIx64 +# define RAM_ADDR_FMTX PRIx64 +# define RAM_ADDR_FMT PRIu64#else typedef uintptr_t ram_addr_t ;# define RAM_ADDR_MAX UINTPTR_MAX -# define RAM_ADDR_FMT "%" PRIxPTR +# define RAM_ADDR_FMTX PRIxPTR +# define RAM_ADDR_FMT PRIuPTR#endif extern ram_addr_t ram_size;
numa.c +1 -1
@@ -189,7 +189,7 @@ void set_numa_nodes(void) }if (numa_total != ram_size) {error_report ("total memory for NUMA nodes (%" PRIu64")" -" should equal RAM size (" RAM_ADDR_FMT ")" , +" should equal RAM size (%" RAM_ADDR_FMT ")" , numa_total, ram_size);exit (1 ); }
vl.c +3 -3
@@ -3319,7 +3319,7 @@ int main(int argc, char **argv, char **envp) sz =qemu_opt_get_size (opts,"maxmem" ,0 );if (sz < ram_size) {fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") <= initial memory (" +"(%" PRIu64") <= initial memory (%" RAM_ADDR_FMT ")\n" , sz, ram_size);exit (EXIT_FAILURE ); }
@@ -3327,7 +3327,7 @@ int main(int argc, char **argv, char **envp) slots =qemu_opt_get_number (opts,"slots" ,0 );if ((sz > ram_size) && !slots) {fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") more than initial memory (" +"(%" PRIu64") more than initial memory (%" RAM_ADDR_FMT ") but no hotplug slots where " "specified\n" , sz, ram_size);exit (EXIT_FAILURE );
@@ -3336,7 +3336,7 @@ int main(int argc, char **argv, char **envp)if ((sz <= ram_size) && slots) {fprintf (stderr,"qemu: invalid -m option value: %" PRIu64" hotplug slots where specified but " -"maxmem (%" PRIu64") <= initial memory (" +"maxmem (%" PRIu64") <= initial memory (%" RAM_ADDR_FMT ")\n" , slots, sz, ram_size);exit (EXIT_FAILURE ); }
xen-hvm.c +5 -6
@@ -221,8 +221,8 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr)if (runstate_check (RUN_STATE_INMIGRATE )) {/* RAM already populated in Xen */ -fprintf (stderr,"%s: do not alloc " RAM_ADDR_FMT -" bytes of ram at " RAM_ADDR_FMT " when runstate is INMIGRATE\n" , +fprintf (stderr,"%s: do not alloc %" RAM_ADDR_FMT " bytes" +" of ram at %" RAM_ADDR_FMTX " when runstate is INMIGRATE\n" , __func__, size, ram_addr);return ; }
@@ -241,7 +241,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr) }if (xc_domain_populate_physmap_exact (xen_xc, xen_domid, nr_pfn,0 ,0 , pfn_list)) { -hw_error ("xen: failed to populate ram at " RAM_ADDR_FMT , ram_addr); +hw_error ("xen: failed to populate ram at %" RAM_ADDR_FMTX , ram_addr); }g_free (pfn_list);
@@ -1127,9 +1127,8 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length) - start_pfn; rc =xc_hvm_modified_memory (xen_xc, xen_domid, start_pfn, nb_pages);if (rc) { -fprintf (stderr, -"%s failed for " RAM_ADDR_FMT " (" RAM_ADDR_FMT "): %i, %s\n" , - __func__, start, nb_pages, rc,strerror (-rc)); +fprintf (stderr,"%s failed for %" RAM_ADDR_FMTX " (%" RAM_ADDR_FMT "):" +" %i, %s\n" , __func__, start, nb_pages, rc,strerror (-rc)); } } }
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 1/4] switch RAM_ADDR_FMT format specifier to print decimal
Quoted 2 lines · Igor Mammedov
... and add
RAM_ADDR_FMTXfor hex format. In addition fix places to print sizes/lengths as decimal and addresses as hex.
ugh.
maybe both - though I really think most people will find it easier to parse he hex variant.
Quoted 20 lines
Also drop "%" from
RAM_ADDR_FMTmacro and use it like other PRIfoo format placeholders specifying "%" explicitly.Signed-off-by Igor Mammedov <[email protected]>--- arch_init.c | 14 +++++++------- exec.c | 4 ++-- hw/i386/pc.c | 4 ++-- hw/ppc/ppc405_boards.c | 2 +- include/exec/cpu-common.h | 6 ++++-- numa.c | 2 +- vl.c | 6 +++--- xen-hvm.c | 11 +++++------ 8 files changed, 25 insertions(+), 24 deletions(-)arch_init.c +0
-0
arch_init.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 1077
Quoted 8 lines
arch_init.c +2
-2@@ -1072,8 +1072,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) QTAILQ_FOREACH(block, &ram_list.blocks, next) {if (!strncmp (id, block->idstr,sizeof (id))) {if (block->length != length) { -error_report ("Length mismatch: %s: " RAM_ADDR_FMT -" in != " RAM_ADDR_FMT , id, length, +error_report ("Length mismatch: %s: %" RAM_ADDR_FMT +" in != %" RAM_ADDR_FMT , id, length, block->length);
Not sure I like this.
length values are often powers of two.
Parsing them in decimal is hard.
Quoted 183 lines
arch_init.c +5
-5ret = -EINVAL ; }@@ -1098,7 +1098,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) host =host_from_stream_offset (f, addr, flags);if (!host) { -error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); +error_report ("Illegal RAM offset %" RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }@@ -1110,7 +1110,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) host =host_from_stream_offset (f, addr, flags);if (!host) { -error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); +error_report ("Illegal RAM offset %" RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }@@ -1119,14 +1119,14 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) }else if (flags &RAM_SAVE_FLAG_XBZRLE ) {void *host =host_from_stream_offset (f, addr, flags);if (!host) { -error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); +error_report ("Illegal RAM offset %" RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }if (load_xbzrle (f, addr, host) <0 ) { -error_report ("Failed to decompress XBZRLE page at " -RAM_ADDR_FMT , addr); +error_report ("Failed to decompress XBZRLE page at %" +RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }exec.c +2
-2@@ -1435,8 +1435,8 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) flags, -1, 0); }if (area != vaddr) { -fprintf (stderr,"Could not remap addr: " -RAM_ADDR_FMT "@" RAM_ADDR_FMT "\n" , +fprintf (stderr,"Could not remap addr: %" +RAM_ADDR_FMTX "@%" RAM_ADDR_FMTX "\n" , length, addr);exit (1 ); }hw/i386/pc.c +2
-2@@ -1257,8 +1257,8 @@ FWCfgState *pc_memory_init(MachineState *machine,if ((pcms->hotplug_memory_base + hotplug_mem_size) < hotplug_mem_size) { -error_report ("unsupported amount of maximum memory: " RAM_ADDR_FMT , - machine->maxram_size); +error_report ("unsupported amount of maximum memory: %" +RAM_ADDR_FMT , machine->maxram_size);exit (EXIT_FAILURE ); }hw/ppc/ppc405_boards.c +1
-1@@ -358,7 +358,7 @@ static void ref405ep_init(MachineState *machine) bdloc =0 ; }#ifdef DEBUG_BOARD_INIT -printf ("bdloc " RAM_ADDR_FMT "\n" , bdloc); +printf ("bdloc %" RAM_ADDR_FMTX "\n" , bdloc);printf ("%s: Done\n" , __func__);#endif }include/exec/cpu-common.h +4
-2@@ -38,11 +38,13 @@ enum device_endian {#if defined(CONFIG_XEN_BACKEND )typedef uint64_t ram_addr_t ;# define RAM_ADDR_MAX UINT64_MAX -# define RAM_ADDR_FMT "%" PRIx64 +# define RAM_ADDR_FMTX PRIx64 +# define RAM_ADDR_FMT PRIu64#else typedef uintptr_t ram_addr_t ;# define RAM_ADDR_MAX UINTPTR_MAX -# define RAM_ADDR_FMT "%" PRIxPTR +# define RAM_ADDR_FMTX PRIxPTR +# define RAM_ADDR_FMT PRIuPTR#endif extern ram_addr_t ram_size;numa.c +1
-1@@ -189,7 +189,7 @@ void set_numa_nodes(void) }if (numa_total != ram_size) {error_report ("total memory for NUMA nodes (%" PRIu64")" -" should equal RAM size (" RAM_ADDR_FMT ")" , +" should equal RAM size (%" RAM_ADDR_FMT ")" , numa_total, ram_size);exit (1 ); }vl.c +3
-3@@ -3319,7 +3319,7 @@ int main(int argc, char **argv, char **envp) sz =qemu_opt_get_size (opts,"maxmem" ,0 );if (sz < ram_size) {fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") <= initial memory (" +"(%" PRIu64") <= initial memory (%" RAM_ADDR_FMT ")\n" , sz, ram_size);exit (EXIT_FAILURE ); }@@ -3327,7 +3327,7 @@ int main(int argc, char **argv, char **envp) slots =qemu_opt_get_number (opts,"slots" ,0 );if ((sz > ram_size) && !slots) {fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") more than initial memory (" +"(%" PRIu64") more than initial memory (%" RAM_ADDR_FMT ") but no hotplug slots where " "specified\n" , sz, ram_size);exit (EXIT_FAILURE );@@ -3336,7 +3336,7 @@ int main(int argc, char **argv, char **envp)if ((sz <= ram_size) && slots) {fprintf (stderr,"qemu: invalid -m option value: %" PRIu64" hotplug slots where specified but " -"maxmem (%" PRIu64") <= initial memory (" +"maxmem (%" PRIu64") <= initial memory (%" RAM_ADDR_FMT ")\n" , slots, sz, ram_size);exit (EXIT_FAILURE ); }xen-hvm.c +5
-6@@ -221,8 +221,8 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr)if (runstate_check (RUN_STATE_INMIGRATE )) {/* RAM already populated in Xen */ -fprintf (stderr,"%s: do not alloc " RAM_ADDR_FMT -" bytes of ram at " RAM_ADDR_FMT " when runstate is INMIGRATE\n" , +fprintf (stderr,"%s: do not alloc %" RAM_ADDR_FMT " bytes" +" of ram at %" RAM_ADDR_FMTX " when runstate is INMIGRATE\n" , __func__, size, ram_addr);return ; }@@ -241,7 +241,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr) }if (xc_domain_populate_physmap_exact (xen_xc, xen_domid, nr_pfn,0 ,0 , pfn_list)) { -hw_error ("xen: failed to populate ram at " RAM_ADDR_FMT , ram_addr); +hw_error ("xen: failed to populate ram at %" RAM_ADDR_FMTX , ram_addr); }g_free (pfn_list);@@ -1127,9 +1127,8 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length) - start_pfn; rc =xc_hvm_modified_memory (xen_xc, xen_domid, start_pfn, nb_pages);if (rc) { -fprintf (stderr, -"%s failed for " RAM_ADDR_FMT " (" RAM_ADDR_FMT "): %i, %s\n" , - __func__, start, nb_pages, rc,strerror (-rc)); +fprintf (stderr,"%s failed for %" RAM_ADDR_FMTX " (%" RAM_ADDR_FMT "):" +" %i, %s\n" , __func__, start, nb_pages, rc,strerror (-rc)); } } }Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 1/4] switch RAM_ADDR_FMT format specifier to print decimal
Quoted 32 lines · On Wed, 25 Jun 2014 14:51:15 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov
... and add
RAM_ADDR_FMTXfor hex format. In addition fix places to print sizes/lengths as decimal and addresses as hex.ugh.
maybe both - though I really think most people will find it easier to parse he hex variant.Quoted 24 lines
Also drop "%" from
RAM_ADDR_FMTmacro and use it like other PRIfoo format placeholders specifying "%" explicitly.Signed-off-by Igor Mammedov <[email protected]>--- arch_init.c | 14 +++++++------- exec.c | 4 ++-- hw/i386/pc.c | 4 ++-- hw/ppc/ppc405_boards.c | 2 +- include/exec/cpu-common.h | 6 ++++-- numa.c | 2 +- vl.c | 6 +++--- xen-hvm.c | 11 +++++------ 8 files changed, 25 insertions(+), 24 deletions(-)arch_init.c +0
-1@@ -1072,8 +1072,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) QTAILQ_FOREACH(block, &ram_list.blocks, next) {if (!strncmp (id, block->idstr,sizeof (id))) {if (block->length != length) { - error_report("Length mismatch: %s: " RAM_ADDR_FMT
Quoted 8 lines
arch_init.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 1077
Quoted 4 lines
arch_init.c +2
-1-" in != " RAM_ADDR_FMT , id, length, +error_report ("Length mismatch: %s: %" RAM_ADDR_FMT +" in != %" RAM_ADDR_FMT , id, length, block->length);Not sure I like this.
length values are often powers of two.
Parsing them in decimal is hard.
Problem is that when user specifies on CLI size in decimal and then sees error message where it's hex or mix of decimal and/or hex values.
But I don't care much about it, we can drop this patch
Quoted 184 lines
Quoted 184 lines
arch_init.c +5
-5ret = -EINVAL ; }@@ -1098,7 +1098,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) host =host_from_stream_offset (f, addr, flags);if (!host) { -error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); +error_report ("Illegal RAM offset %" RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }@@ -1110,7 +1110,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) host =host_from_stream_offset (f, addr, flags);if (!host) { -error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); +error_report ("Illegal RAM offset %" RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }@@ -1119,14 +1119,14 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) }else if (flags &RAM_SAVE_FLAG_XBZRLE ) {void *host =host_from_stream_offset (f, addr, flags);if (!host) { -error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); +error_report ("Illegal RAM offset %" RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }if (load_xbzrle (f, addr, host) <0 ) { -error_report ("Failed to decompress XBZRLE page at " -RAM_ADDR_FMT , addr); +error_report ("Failed to decompress XBZRLE page at %" +RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }exec.c +2
-2@@ -1435,8 +1435,8 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) flags, -1, 0); }if (area != vaddr) { -fprintf (stderr,"Could not remap addr: " -RAM_ADDR_FMT "@" RAM_ADDR_FMT "\n" , +fprintf (stderr,"Could not remap addr: %" +RAM_ADDR_FMTX "@%" RAM_ADDR_FMTX "\n" , length, addr);exit (1 ); }hw/i386/pc.c +2
-2@@ -1257,8 +1257,8 @@ FWCfgState *pc_memory_init(MachineState *machine,if ((pcms->hotplug_memory_base + hotplug_mem_size) < hotplug_mem_size) { -error_report ("unsupported amount of maximum memory: " RAM_ADDR_FMT , - machine->maxram_size); +error_report ("unsupported amount of maximum memory: %" +RAM_ADDR_FMT , machine->maxram_size);exit (EXIT_FAILURE ); }hw/ppc/ppc405_boards.c +1
-1@@ -358,7 +358,7 @@ static void ref405ep_init(MachineState *machine) bdloc =0 ; }#ifdef DEBUG_BOARD_INIT -printf ("bdloc " RAM_ADDR_FMT "\n" , bdloc); +printf ("bdloc %" RAM_ADDR_FMTX "\n" , bdloc);printf ("%s: Done\n" , __func__);#endif }include/exec/cpu-common.h +4
-2@@ -38,11 +38,13 @@ enum device_endian {#if defined(CONFIG_XEN_BACKEND )typedef uint64_t ram_addr_t ;# define RAM_ADDR_MAX UINT64_MAX -# define RAM_ADDR_FMT "%" PRIx64 +# define RAM_ADDR_FMTX PRIx64 +# define RAM_ADDR_FMT PRIu64#else typedef uintptr_t ram_addr_t ;# define RAM_ADDR_MAX UINTPTR_MAX -# define RAM_ADDR_FMT "%" PRIxPTR +# define RAM_ADDR_FMTX PRIxPTR +# define RAM_ADDR_FMT PRIuPTR#endif extern ram_addr_t ram_size;numa.c +1
-1@@ -189,7 +189,7 @@ void set_numa_nodes(void) }if (numa_total != ram_size) {error_report ("total memory for NUMA nodes (%" PRIu64")" -" should equal RAM size (" RAM_ADDR_FMT ")" , +" should equal RAM size (%" RAM_ADDR_FMT ")" , numa_total, ram_size);exit (1 ); }vl.c +3
-3@@ -3319,7 +3319,7 @@ int main(int argc, char **argv, char **envp) sz =qemu_opt_get_size (opts,"maxmem" ,0 );if (sz < ram_size) {fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") <= initial memory (" +"(%" PRIu64") <= initial memory (%" RAM_ADDR_FMT ")\n" , sz, ram_size);exit (EXIT_FAILURE ); }@@ -3327,7 +3327,7 @@ int main(int argc, char **argv, char **envp) slots =qemu_opt_get_number (opts,"slots" ,0 );if ((sz > ram_size) && !slots) {fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") more than initial memory (" +"(%" PRIu64") more than initial memory (%" RAM_ADDR_FMT ") but no hotplug slots where " "specified\n" , sz, ram_size);exit (EXIT_FAILURE );@@ -3336,7 +3336,7 @@ int main(int argc, char **argv, char **envp)if ((sz <= ram_size) && slots) {fprintf (stderr,"qemu: invalid -m option value: %" PRIu64" hotplug slots where specified but " -"maxmem (%" PRIu64") <= initial memory (" +"maxmem (%" PRIu64") <= initial memory (%" RAM_ADDR_FMT ")\n" , slots, sz, ram_size);exit (EXIT_FAILURE ); }xen-hvm.c +5
-6@@ -221,8 +221,8 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr)if (runstate_check (RUN_STATE_INMIGRATE )) {/* RAM already populated in Xen */ -fprintf (stderr,"%s: do not alloc " RAM_ADDR_FMT -" bytes of ram at " RAM_ADDR_FMT " when runstate is INMIGRATE\n" , +fprintf (stderr,"%s: do not alloc %" RAM_ADDR_FMT " bytes" +" of ram at %" RAM_ADDR_FMTX " when runstate is INMIGRATE\n" , __func__, size, ram_addr);return ; }@@ -241,7 +241,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr) }if (xc_domain_populate_physmap_exact (xen_xc, xen_domid, nr_pfn,0 ,0 , pfn_list)) { -hw_error ("xen: failed to populate ram at " RAM_ADDR_FMT , ram_addr); +hw_error ("xen: failed to populate ram at %" RAM_ADDR_FMTX , ram_addr); }g_free (pfn_list);@@ -1127,9 +1127,8 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length) - start_pfn; rc =xc_hvm_modified_memory (xen_xc, xen_domid, start_pfn, nb_pages);if (rc) { -fprintf (stderr, -"%s failed for " RAM_ADDR_FMT " (" RAM_ADDR_FMT "): %i, %s\n" , - __func__, start, nb_pages, rc,strerror (-rc)); +fprintf (stderr,"%s failed for %" RAM_ADDR_FMTX " (%" RAM_ADDR_FMT "):" +" %i, %s\n" , __func__, start, nb_pages, rc,strerror (-rc)); } } }Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 1/4] switch RAM_ADDR_FMT format specifier to print decimal
Quoted 43 lines · Igor Mammedov
Quoted 32 lines · On Wed, 25 Jun 2014 14:51:15 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov
... and add
RAM_ADDR_FMTXfor hex format. In addition fix places to print sizes/lengths as decimal and addresses as hex.ugh.
maybe both - though I really think most people will find it easier to parse he hex variant.Quoted 24 lines
Also drop "%" from
RAM_ADDR_FMTmacro and use it like other PRIfoo format placeholders specifying "%" explicitly.Signed-off-by Igor Mammedov <[email protected]>--- arch_init.c | 14 +++++++------- exec.c | 4 ++-- hw/i386/pc.c | 4 ++-- hw/ppc/ppc405_boards.c | 2 +- include/exec/cpu-common.h | 6 ++++-- numa.c | 2 +- vl.c | 6 +++--- xen-hvm.c | 11 +++++------ 8 files changed, 25 insertions(+), 24 deletions(-)arch_init.c +0
-1@@ -1072,8 +1072,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) QTAILQ_FOREACH(block, &ram_list.blocks, next) {if (!strncmp (id, block->idstr,sizeof (id))) {if (block->length != length) { - error_report("Length mismatch: %s: " RAM_ADDR_FMTQuoted 8 lines
arch_init.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 1077
Quoted 4 lines
arch_init.c +2
-1-" in != " RAM_ADDR_FMT , id, length, +error_report ("Length mismatch: %s: %" RAM_ADDR_FMT +" in != %" RAM_ADDR_FMT , id, length, block->length);Not sure I like this.
length values are often powers of two.
Parsing them in decimal is hard.
Quoted 4 lines
Problem is that when user specifies on CLI size in decimal and then sees error message where it's hex or mix of decimal and/or hex values.
But I don't care much about it, we can drop this patch
User likely does something like 5G.
Seeing size in decimal bytes is unlikely to be helpful.
Quoted 184 lines
Quoted 184 lines
Quoted 184 lines
arch_init.c +5
-5ret = -EINVAL ; }@@ -1098,7 +1098,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) host =host_from_stream_offset (f, addr, flags);if (!host) { -error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); +error_report ("Illegal RAM offset %" RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }@@ -1110,7 +1110,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) host =host_from_stream_offset (f, addr, flags);if (!host) { -error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); +error_report ("Illegal RAM offset %" RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }@@ -1119,14 +1119,14 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) }else if (flags &RAM_SAVE_FLAG_XBZRLE ) {void *host =host_from_stream_offset (f, addr, flags);if (!host) { -error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); +error_report ("Illegal RAM offset %" RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }if (load_xbzrle (f, addr, host) <0 ) { -error_report ("Failed to decompress XBZRLE page at " -RAM_ADDR_FMT , addr); +error_report ("Failed to decompress XBZRLE page at %" +RAM_ADDR_FMTX , addr); ret = -EINVAL ;break ; }exec.c +2
-2@@ -1435,8 +1435,8 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) flags, -1, 0); }if (area != vaddr) { -fprintf (stderr,"Could not remap addr: " -RAM_ADDR_FMT "@" RAM_ADDR_FMT "\n" , +fprintf (stderr,"Could not remap addr: %" +RAM_ADDR_FMTX "@%" RAM_ADDR_FMTX "\n" , length, addr);exit (1 ); }hw/i386/pc.c +2
-2@@ -1257,8 +1257,8 @@ FWCfgState *pc_memory_init(MachineState *machine,if ((pcms->hotplug_memory_base + hotplug_mem_size) < hotplug_mem_size) { -error_report ("unsupported amount of maximum memory: " RAM_ADDR_FMT , - machine->maxram_size); +error_report ("unsupported amount of maximum memory: %" +RAM_ADDR_FMT , machine->maxram_size);exit (EXIT_FAILURE ); }hw/ppc/ppc405_boards.c +1
-1@@ -358,7 +358,7 @@ static void ref405ep_init(MachineState *machine) bdloc =0 ; }#ifdef DEBUG_BOARD_INIT -printf ("bdloc " RAM_ADDR_FMT "\n" , bdloc); +printf ("bdloc %" RAM_ADDR_FMTX "\n" , bdloc);printf ("%s: Done\n" , __func__);#endif }include/exec/cpu-common.h +4
-2@@ -38,11 +38,13 @@ enum device_endian {#if defined(CONFIG_XEN_BACKEND )typedef uint64_t ram_addr_t ;# define RAM_ADDR_MAX UINT64_MAX -# define RAM_ADDR_FMT "%" PRIx64 +# define RAM_ADDR_FMTX PRIx64 +# define RAM_ADDR_FMT PRIu64#else typedef uintptr_t ram_addr_t ;# define RAM_ADDR_MAX UINTPTR_MAX -# define RAM_ADDR_FMT "%" PRIxPTR +# define RAM_ADDR_FMTX PRIxPTR +# define RAM_ADDR_FMT PRIuPTR#endif extern ram_addr_t ram_size;numa.c +1
-1@@ -189,7 +189,7 @@ void set_numa_nodes(void) }if (numa_total != ram_size) {error_report ("total memory for NUMA nodes (%" PRIu64")" -" should equal RAM size (" RAM_ADDR_FMT ")" , +" should equal RAM size (%" RAM_ADDR_FMT ")" , numa_total, ram_size);exit (1 ); }vl.c +3
-3@@ -3319,7 +3319,7 @@ int main(int argc, char **argv, char **envp) sz =qemu_opt_get_size (opts,"maxmem" ,0 );if (sz < ram_size) {fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") <= initial memory (" +"(%" PRIu64") <= initial memory (%" RAM_ADDR_FMT ")\n" , sz, ram_size);exit (EXIT_FAILURE ); }@@ -3327,7 +3327,7 @@ int main(int argc, char **argv, char **envp) slots =qemu_opt_get_number (opts,"slots" ,0 );if ((sz > ram_size) && !slots) {fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") more than initial memory (" +"(%" PRIu64") more than initial memory (%" RAM_ADDR_FMT ") but no hotplug slots where " "specified\n" , sz, ram_size);exit (EXIT_FAILURE );@@ -3336,7 +3336,7 @@ int main(int argc, char **argv, char **envp)if ((sz <= ram_size) && slots) {fprintf (stderr,"qemu: invalid -m option value: %" PRIu64" hotplug slots where specified but " -"maxmem (%" PRIu64") <= initial memory (" +"maxmem (%" PRIu64") <= initial memory (%" RAM_ADDR_FMT ")\n" , slots, sz, ram_size);exit (EXIT_FAILURE ); }xen-hvm.c +5
-6@@ -221,8 +221,8 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr)if (runstate_check (RUN_STATE_INMIGRATE )) {/* RAM already populated in Xen */ -fprintf (stderr,"%s: do not alloc " RAM_ADDR_FMT -" bytes of ram at " RAM_ADDR_FMT " when runstate is INMIGRATE\n" , +fprintf (stderr,"%s: do not alloc %" RAM_ADDR_FMT " bytes" +" of ram at %" RAM_ADDR_FMTX " when runstate is INMIGRATE\n" , __func__, size, ram_addr);return ; }@@ -241,7 +241,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr) }if (xc_domain_populate_physmap_exact (xen_xc, xen_domid, nr_pfn,0 ,0 , pfn_list)) { -hw_error ("xen: failed to populate ram at " RAM_ADDR_FMT , ram_addr); +hw_error ("xen: failed to populate ram at %" RAM_ADDR_FMTX , ram_addr); }g_free (pfn_list);@@ -1127,9 +1127,8 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length) - start_pfn; rc =xc_hvm_modified_memory (xen_xc, xen_domid, start_pfn, nb_pages);if (rc) { -fprintf (stderr, -"%s failed for " RAM_ADDR_FMT " (" RAM_ADDR_FMT "): %i, %s\n" , - __func__, start, nb_pages, rc,strerror (-rc)); +fprintf (stderr,"%s failed for %" RAM_ADDR_FMTX " (%" RAM_ADDR_FMT "):" +" %i, %s\n" , __func__, start, nb_pages, rc,strerror (-rc)); } } }Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 1/4] switch RAM_ADDR_FMT format specifier to print decimal
In reply to Igor MammedovOn 25 June 2014 12:42, Igor Mammedov <[email protected]> wrote
Quoted 2 lines
... and add
RAM_ADDR_FMTXfor hex format. In addition fix places to print sizes/lengths as decimal and addresses as hex.
Please can you make the 'body' part of your commit messages stand on its own? It's kind of hard to understand when half of the sentence is off wherever the mail client displays its Subject line and only half is in the email body.
Quoted 2 lines
Also drop "%" from
RAM_ADDR_FMTmacro and use it like other PRIfoo format placeholders specifying "%" explicitly.
[If you find yourself writing "And... Also..." in a commit message it's often a sign that you probably want to split it into more than one patch.]
If you're going to do this you should just create a set of RAMADDR_PRI[diouxX] like we have for HWADDR, rather than leaving the non-standard RAM_ADDR_FMT name.
Please don't change the default meaning of RAM_ADDR_FMT in the same commit as making a lot of boilerplate no-effect changes to move % characters around; if there are cases that would be better done as decimal then those behavioural changes should be done in their own patches so it's clear which things have been changed.
thanks
-- PMM
PATCH 2/4 vl.c: use single local_err throughout main()
In reply to Igor Mammedov--- vl.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
vl.c +1 -3
@@ -2927,6 +2927,7 @@ int main(int argc, char **argv, char **envp) };const char *trace_events =NULL ;const char *trace_file =NULL ; +Error *local_err =NULL ;const ram_addr_t default_ram_size = (ram_addr_t )DEFAULT_RAM_SIZE *1024 *1024 ;ram_addr_t maxram_size = default_ram_size;
@@ -4220,7 +4221,6 @@ int main(int argc, char **argv, char **envp)configure_accelerator (machine_class);if (qtest_chrdev) { -Error *local_err =NULL ;qtest_init (qtest_chrdev, qtest_log, &local_err);if (local_err) {error_report ("%s" ,error_get_pretty (local_err));
@@ -4448,7 +4448,6 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_VNC /* init remote displays */ if (vnc_display) { -Error *local_err =NULL ;vnc_display_init (ds);vnc_display_open (ds, vnc_display, &local_err);if (local_err !=NULL ) {
@@ -4503,7 +4502,6 @@ int main(int argc, char **argv, char **envp) }if (incoming) { -Error *local_err =NULL ;qemu_start_incoming_migration (incoming, &local_err);if (local_err) { error_report("-incoming %s: %s", incoming,
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 2/4] vl.c: use single local_err throughout main()
Quoted 1 line · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>
Fixes any bugs?
Quoted 42 lines
--- vl.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)vl.c +1
-3@@ -2927,6 +2927,7 @@ int main(int argc, char **argv, char **envp) };const char *trace_events =NULL ;const char *trace_file =NULL ; +Error *local_err =NULL ;const ram_addr_t default_ram_size = (ram_addr_t )DEFAULT_RAM_SIZE *1024 *1024 ;ram_addr_t maxram_size = default_ram_size;@@ -4220,7 +4221,6 @@ int main(int argc, char **argv, char **envp)configure_accelerator (machine_class);if (qtest_chrdev) { -Error *local_err =NULL ;qtest_init (qtest_chrdev, qtest_log, &local_err);if (local_err) {error_report ("%s" ,error_get_pretty (local_err));@@ -4448,7 +4448,6 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_VNC /* init remote displays */ if (vnc_display) { -Error *local_err =NULL ;vnc_display_init (ds);vnc_display_open (ds, vnc_display, &local_err);if (local_err !=NULL ) {@@ -4503,7 +4502,6 @@ int main(int argc, char **argv, char **envp) }if (incoming) { -Error *local_err =NULL ;qemu_start_incoming_migration (incoming, &local_err);if (local_err) { error_report("-incoming %s: %s", incoming,Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 2/4] vl.c: use single local_err throughout main()
Quoted 4 lines · On Wed, 25 Jun 2014 14:51:52 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 1 line · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>Fixes any bugs?
Nope, it's to reduce code duplication, which would be increased in following patch.
Quoted 44 lines
Quoted 43 lines
--- vl.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)vl.c +1
-3@@ -2927,6 +2927,7 @@ int main(int argc, char **argv, char **envp) };const char *trace_events =NULL ;const char *trace_file =NULL ; +Error *local_err =NULL ;const ram_addr_t default_ram_size = (ram_addr_t )DEFAULT_RAM_SIZE *1024 *1024 ;ram_addr_t maxram_size = default_ram_size;@@ -4220,7 +4221,6 @@ int main(int argc, char **argv, char **envp)configure_accelerator (machine_class);if (qtest_chrdev) { -Error *local_err =NULL ;qtest_init (qtest_chrdev, qtest_log, &local_err);if (local_err) {error_report ("%s" ,error_get_pretty (local_err));@@ -4448,7 +4448,6 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_VNC /* init remote displays */ if (vnc_display) { -Error *local_err =NULL ;vnc_display_init (ds);vnc_display_open (ds, vnc_display, &local_err);if (local_err !=NULL ) {@@ -4503,7 +4502,6 @@ int main(int argc, char **argv, char **envp) }if (incoming) { -Error *local_err =NULL ;qemu_start_incoming_migration (incoming, &local_err);if (local_err) { error_report("-incoming %s: %s", incoming,Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 2/4] vl.c: use single local_err throughout main()
Quoted 9 lines · Igor Mammedov
Quoted 4 lines · On Wed, 25 Jun 2014 14:51:52 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 1 line · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>Fixes any bugs?
Nope, it's to reduce code duplication, which would be increased in following patch.
Guys we need to get 2.1 out of the door.
So hold off on new non bugfix patches until after 2.2, or if you feel you want early feedback, tag them as RFC.
This is just adding to a pile of mail I have to wade through and discard, and you will have to repost or ping me again after the release anyway.
Quoted 44 lines
Quoted 44 lines
Quoted 43 lines
--- vl.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)vl.c +1
-3@@ -2927,6 +2927,7 @@ int main(int argc, char **argv, char **envp) };const char *trace_events =NULL ;const char *trace_file =NULL ; +Error *local_err =NULL ;const ram_addr_t default_ram_size = (ram_addr_t )DEFAULT_RAM_SIZE *1024 *1024 ;ram_addr_t maxram_size = default_ram_size;@@ -4220,7 +4221,6 @@ int main(int argc, char **argv, char **envp)configure_accelerator (machine_class);if (qtest_chrdev) { -Error *local_err =NULL ;qtest_init (qtest_chrdev, qtest_log, &local_err);if (local_err) {error_report ("%s" ,error_get_pretty (local_err));@@ -4448,7 +4448,6 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_VNC /* init remote displays */ if (vnc_display) { -Error *local_err =NULL ;vnc_display_init (ds);vnc_display_open (ds, vnc_display, &local_err);if (local_err !=NULL ) {@@ -4503,7 +4502,6 @@ int main(int argc, char **argv, char **envp) }if (incoming) { -Error *local_err =NULL ;qemu_start_incoming_migration (incoming, &local_err);if (local_err) { error_report("-incoming %s: %s", incoming,Signature · 1 line
1.7.1
PATCH 3/4 machine: convert ram_size, maxram_size, ram_slots to properties
In reply to Igor Mammedov... short term it will help writing unit tests accessing these values via QMP. And down the road it will allow to drop global variable ram_size.
--- hw/core/machine.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 5 ++ vl.c | 123 +++++++++++++++------------------- 3 files changed, 240 insertions(+), 69 deletions(-)
hw/core/machine.c +181 -0
@@ -12,6 +12,10 @@#include "hw/boards.h" #include "qapi/visitor.h" +#include "qemu/error-report.h" +#include "hw/xen/xen.h" + +static const ram_addr_t default_ram_size =128 *1024 *1024 ;static char *machine_get_accel (Object *obj,Error **errp) {
@@ -235,8 +239,118 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp) ms->firmware =g_strdup (value); } +static void machine_get_ram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +int64_t value = ms->ram_size; + +visit_type_int (v, &value, name, errp); +} + +static void machine_set_ram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, &value, name, &error); +if (error) { + goto out; + } + + value =QEMU_ALIGN_UP (value,8192 ); + ms->ram_size = value; +if (ms->ram_size != value) { +error_setg (&error,"ram size too large" ); + goto out; + } + +if (!ms->ram_size) { +error_setg (&error,"ram size can't be 0" ); + } +out: +if (error) { +error_propagate (errp, error); + } +} + +static void machine_get_maxram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +int64_t value = ms->maxram_size; + +visit_type_int (v, &value, name, errp); +} + +static void machine_set_maxram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, &value, name, &error); +if (error) { + goto out; + } + + ms->maxram_size = value; +if (ms->maxram_size != value) { +error_setg (&error,"maxmem is too large" ); + goto out; + } + +if (!ms->maxram_size) { +error_setg (&error,"maxmem can't be 0" ); + } +out: +if (error) { +error_propagate (errp, error); + } +} + +static void machine_get_ram_slots (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +int64_t value = ms->ram_slots; + +visit_type_int (v, &value, name, errp); +} + +static void machine_set_ram_slots (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, &value, name, &error); +if (error) { + goto out; + } + + ms->ram_slots = value; + +out: +if (error) { +error_propagate (errp, error); + } +} +static void machine_initfn (Object *obj) { +MachineState *ms =MACHINE (obj); +object_property_add_str (obj,"accel" , machine_get_accel, machine_set_accel,NULL ); object_property_add_bool(obj, "kernel_irqchip",
@@ -274,6 +388,20 @@ static void machine_initfn(Object *obj)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 ); + + ms->ram_size = default_ram_size; +object_property_add (obj,MACHINE_MEMORY_SIZE_OPT ,"int" , + machine_get_ram_size, + machine_set_ram_size, +NULL ,NULL ,NULL ); +object_property_add (obj,MACHINE_MAXMEMORY_SIZE_OPT ,"int" , + machine_get_maxram_size, + machine_set_maxram_size, +NULL ,NULL ,NULL ); +object_property_add (obj,MACHINE_MEMORY_SLOTS_OPT ,"int" , + machine_get_ram_slots, + machine_set_ram_slots, +NULL ,NULL ,NULL ); }static void machine_finalize (Object *obj)
@@ -290,11 +418,64 @@ static void machine_finalize(Object *obj)g_free (ms->firmware); } +static void machine_pre_init (MachineState *ms,Error **errp) +{ +Error *error =NULL ; + +if ((ms->ram_size > ms->maxram_size) && ms->maxram_size) { +error_setg (&error,"invalid \"maxmem\" value (%" RAM_ADDR_FMT +") < initial memory (%" RAM_ADDR_FMT ")" , + ms->maxram_size, ms->ram_size); + goto out; + } + +if ((ms->ram_size < ms->maxram_size) && !ms->ram_slots) { +error_setg (&error,"invalid \"maxmem\" value (%" RAM_ADDR_FMT ") " +"more than initial memory (%" PRIu64") but " +"no hotplug slots where specified" , + ms->maxram_size, ms->ram_size); + goto out; + } + +if ((ms->ram_size == ms->maxram_size) && ms->ram_slots) { +error_setg (&error,"invalid \"maxmem\" value (%" RAM_ADDR_FMT ") " +"it must be more than initial memory if hotplug slots > 0" , + ms->maxram_size); + goto out; + } + +if (!ms->maxram_size && !ms->ram_slots) { + ms->maxram_size = ms->ram_size; + } + +if (!xen_enabled ()) { +/* On 32-bit hosts, QEMU is limited by virtual address space */ +if (HOST_LONG_BITS ==32 && ((ms->ram_size > (2047 <<20 )) || + (ms->maxram_size > (2047 <<20 )))) { +error_setg (&error,"at most 2047 MB RAM can be simulated\n" ); + goto out; + } + } + +out: +if (error) { +error_propagate (errp, error); + } +} + +static void machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->instance_pre_init = machine_pre_init; +} +static const TypeInfo machine_info = { .name =TYPE_MACHINE , .parent =TYPE_OBJECT , .abstract = true, .class_size =sizeof (MachineClass), + .class_init = machine_class_init, .instance_size =sizeof (MachineState), .instance_init = machine_initfn, .instance_finalize = machine_finalize,
include/hw/boards.h +5 -0
@@ -81,6 +81,7 @@ struct MachineClass {const char *desc;void (*init)(MachineState *state); +void (*instance_pre_init)(MachineState *state,Error **errp);void (*reset)(void );void (*hot_add_cpu)(const int64_t id,Error **errp);int (*kvm_type)(const char *arg);
@@ -134,4 +135,8 @@ struct MachineState { const char *cpu_model; }; +#define MACHINE_MEMORY_SIZE_OPT "memory-size" +#define MACHINE_MEMORY_SLOTS_OPT "memory-slots" +#define MACHINE_MAXMEMORY_SIZE_OPT "maxmem" +#endif
vl.c +54 -69
193 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 3/4] machine: convert ram_size, maxram_size, ram_slots to properties
Quoted 128 lines · Igor Mammedov
... short term it will help writing unit tests accessing these values via QMP. And down the road it will allow to drop global variable
ram_size.Signed-off-by Igor Mammedov <[email protected]>--- hw/core/machine.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 5 ++ vl.c | 123 +++++++++++++++------------------- 3 files changed, 240 insertions(+), 69 deletions(-)hw/core/machine.c +102
-0@@ -12,6 +12,10 @@#include "hw/boards.h" #include "qapi/visitor.h" +#include "qemu/error-report.h" +#include "hw/xen/xen.h" + +static const ram_addr_t default_ram_size =128 *1024 *1024 ;static char *machine_get_accel (Object *obj,Error **errp) {@@ -235,8 +239,118 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp) ms->firmware =g_strdup (value); } +static void machine_get_ram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +int64_t value = ms->ram_size; + +visit_type_int (v, &value, name, errp); +} + +static void machine_set_ram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, &value, name, &error); +if (error) { + goto out; + } + + value =QEMU_ALIGN_UP (value,8192 ); + ms->ram_size = value; +if (ms->ram_size != value) { +error_setg (&error,"ram size too large" ); + goto out; + } + +if (!ms->ram_size) { +error_setg (&error,"ram size can't be 0" ); + } +out: +if (error) { +error_propagate (errp, error); + } +} + +static void machine_get_maxram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +int64_t value = ms->maxram_size; + +visit_type_int (v, &value, name, errp); +} + +static void machine_set_maxram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, &value, name, &error); +if (error) { + goto out; + } + + ms->maxram_size = value; +if (ms->maxram_size != value) { +error_setg (&error,"maxmem is too large" ); + goto out; + } + +if (!ms->maxram_size) { +error_setg (&error,"maxmem can't be 0" ); + } +out: +if (error) { +error_propagate (errp, error); + } +} + +static void machine_get_ram_slots (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +int64_t value = ms->ram_slots; + +visit_type_int (v, &value, name, errp); +} + +static void machine_set_ram_slots (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, &value, name, &error); +if (error) { + goto out;
hw/core/machine.c static void machine_set_firmware(Object *obj, const char *value, Error **errp) · line 349
Quoted 10 lines
hw/core/machine.c +9
-0+ } + + ms->ram_slots = value; + +out: +if (error) { +error_propagate (errp, error); + } +}
Really that's too much boiler plate code for each value. Can't we support a "validate" callback from standard integer values, to be called after parsing?
Quoted 42 lines
hw/core/machine.c +26
-0static void machine_initfn (Object *obj) { +MachineState *ms =MACHINE (obj); +object_property_add_str (obj,"accel" , machine_get_accel, machine_set_accel,NULL ); object_property_add_bool(obj, "kernel_irqchip",@@ -274,6 +388,20 @@ static void machine_initfn(Object *obj)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 ); + + ms->ram_size = default_ram_size; +object_property_add (obj,MACHINE_MEMORY_SIZE_OPT ,"int" , + machine_get_ram_size, + machine_set_ram_size, +NULL ,NULL ,NULL ); +object_property_add (obj,MACHINE_MAXMEMORY_SIZE_OPT ,"int" , + machine_get_maxram_size, + machine_set_maxram_size, +NULL ,NULL ,NULL ); +object_property_add (obj,MACHINE_MEMORY_SLOTS_OPT ,"int" , + machine_get_ram_slots, + machine_set_ram_slots, +NULL ,NULL ,NULL ); }static void machine_finalize (Object *obj)@@ -290,11 +418,64 @@ static void machine_finalize(Object *obj)g_free (ms->firmware); } +static void machine_pre_init (MachineState *ms,Error **errp) +{ +Error *error =NULL ; + +if ((ms->ram_size > ms->maxram_size) && ms->maxram_size) { +error_setg (&error,"invalid \"maxmem\" value (%" RAM_ADDR_FMT +") < initial memory (%" RAM_ADDR_FMT ")" , + ms->maxram_size, ms->ram_size); + goto out; + }
hw/core/machine.c static void machine_finalize(Object *obj) · line 440
Quoted 10 lines
hw/core/machine.c +10
-0+ +if ((ms->ram_size < ms->maxram_size) && !ms->ram_slots) { +error_setg (&error,"invalid \"maxmem\" value (%" RAM_ADDR_FMT ") " +"more than initial memory (%" PRIu64") but " +"no hotplug slots where specified" , + ms->maxram_size, ms->ram_size); + goto out; + } + +if ((ms->ram_size == ms->maxram_size) && ms->ram_slots) {
ugly () within conditions, not really needed.
Quoted 271 lines
hw/core/machine.c +33
-0+error_setg (&error,"invalid \"maxmem\" value (%" RAM_ADDR_FMT ") " +"it must be more than initial memory if hotplug slots > 0" , + ms->maxram_size); + goto out; + } + +if (!ms->maxram_size && !ms->ram_slots) { + ms->maxram_size = ms->ram_size; + } + +if (!xen_enabled ()) { +/* On 32-bit hosts, QEMU is limited by virtual address space */ +if (HOST_LONG_BITS ==32 && ((ms->ram_size > (2047 <<20 )) || + (ms->maxram_size > (2047 <<20 )))) { +error_setg (&error,"at most 2047 MB RAM can be simulated\n" ); + goto out; + } + } + +out: +if (error) { +error_propagate (errp, error); + } +} + +static void machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->instance_pre_init = machine_pre_init; +} +static const TypeInfo machine_info = { .name =TYPE_MACHINE , .parent =TYPE_OBJECT , .abstract = true, .class_size =sizeof (MachineClass), + .class_init = machine_class_init, .instance_size =sizeof (MachineState), .instance_init = machine_initfn, .instance_finalize = machine_finalize,include/hw/boards.h +5
-0@@ -81,6 +81,7 @@ struct MachineClass {const char *desc;void (*init)(MachineState *state); +void (*instance_pre_init)(MachineState *state,Error **errp);void (*reset)(void );void (*hot_add_cpu)(const int64_t id,Error **errp);int (*kvm_type)(const char *arg);@@ -134,4 +135,8 @@ struct MachineState { const char *cpu_model; }; +#define MACHINE_MEMORY_SIZE_OPT "memory-size" +#define MACHINE_MEMORY_SLOTS_OPT "memory-slots" +#define MACHINE_MAXMEMORY_SIZE_OPT "maxmem" +#endif vl.c +54
-69@@ -119,8 +119,6 @@ int main(int argc, char **argv)#include "qom/object_interfaces.h" #include "qapi-event.h" -#define DEFAULT_RAM_SIZE 128 -#define MAX_VIRTIO_CONSOLES 1#define MAX_SCLP_CONSOLES 1@@ -2928,10 +2926,8 @@ int main(int argc, char **argv, char **envp)const char *trace_events =NULL ;const char *trace_file =NULL ;Error *local_err =NULL ; -const ram_addr_t default_ram_size = (ram_addr_t )DEFAULT_RAM_SIZE * -1024 *1024 ; -ram_addr_t maxram_size = default_ram_size; -uint64_t ram_slots =0 ; +const char *maxram_size_str =NULL ; +const char *ram_slots_str =NULL ;FILE *vmstate_dump_file =NULL ;atexit (qemu_run_exit_notifiers);@@ -2978,7 +2974,7 @@ int main(int argc, char **argv, char **envp)module_call_init (MODULE_INIT_MACHINE ); machine_class =find_default_machine (); cpu_model =NULL ; - ram_size = default_ram_size; + ram_size =0 ; snapshot =0 ; cyls = heads = secs =0 ; translation =BIOS_ATA_TRANSLATION_AUTO ;@@ -3269,7 +3265,6 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_m: {uint64_t sz;const char *mem_str; -const char *maxmem_str, *slots_str; opts =qemu_opts_parse (qemu_find_opts ("memory" ), optarg,1 );@@ -3287,7 +3282,7 @@ int main(int argc, char **argv, char **envp)exit (EXIT_FAILURE ); } - sz =qemu_opt_get_size (opts,"size" , ram_size); + sz =qemu_opt_get_size (opts,"size" ,0 );/* Fix up legacy suffix-less format */ if (g_ascii_isdigit (mem_str[strlen (mem_str) -1 ])) {@@ -3301,54 +3296,12 @@ int main(int argc, char **argv, char **envp) }/* backward compatibility behaviour for case "-m 0" */ -if (sz ==0 ) { - sz = default_ram_size; - } - - sz =QEMU_ALIGN_UP (sz,8192 ); - ram_size = sz; -if (ram_size != sz) { -error_report ("ram size too large" ); -exit (EXIT_FAILURE ); +if (sz !=0 ) { + ram_size = sz; } - maxmem_str =qemu_opt_get (opts,"maxmem" ); - slots_str =qemu_opt_get (opts,"slots" ); -if (maxmem_str && slots_str) { -uint64_t slots; - - sz =qemu_opt_get_size (opts,"maxmem" ,0 ); -if (sz < ram_size) { -fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") <= initial memory (%" -RAM_ADDR_FMT ")\n" , sz, ram_size); -exit (EXIT_FAILURE ); - } - - slots =qemu_opt_get_number (opts,"slots" ,0 ); -if ((sz > ram_size) && !slots) { -fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") more than initial memory (%" -RAM_ADDR_FMT ") but no hotplug slots where " -"specified\n" , sz, ram_size); -exit (EXIT_FAILURE ); - } - -if ((sz <= ram_size) && slots) { -fprintf (stderr,"qemu: invalid -m option value: %" - PRIu64" hotplug slots where specified but " -"maxmem (%" PRIu64") <= initial memory (%" -RAM_ADDR_FMT ")\n" , slots, sz, ram_size); -exit (EXIT_FAILURE ); - } - maxram_size = sz; - ram_slots = slots; - }else if ((!maxmem_str && slots_str) || - (maxmem_str && !slots_str)) { -fprintf (stderr,"qemu: invalid -m option value: missing " -"'%s' option\n" , slots_str ?"maxmem" :"slots" ); -exit (EXIT_FAILURE ); - } + maxram_size_str =qemu_opt_get (opts,"maxmem" ); + ram_slots_str =qemu_opt_get (opts,"slots" );break ; }#ifdef CONFIG_TPM @@ -4203,14 +4156,48 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -/* store value for the future use */ -qemu_opt_set_number (qemu_find_opts_singleton ("memory" ),"size" , ram_size); -if (qemu_opts_foreach (qemu_find_opts ("device" ), device_help_func,NULL ,0 ) !=0 ) {exit (0 ); } +if (ram_size) { +object_property_set_int (OBJECT (current_machine), ram_size, +MACHINE_MEMORY_SIZE_OPT , &local_err); +if (local_err) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } + } + +if (maxram_size_str) { +uint64_t sz =qemu_opt_get_size (qemu_find_opts_singleton ("memory" ), +"maxmem" ,0 ); + +parse_option_size ("maxmem" , maxram_size_str, &sz, &local_err); +if (local_err) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } +object_property_set_int (OBJECT (current_machine), sz, +MACHINE_MAXMEMORY_SIZE_OPT , &local_err); +if (local_err) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } + } + +if (ram_slots_str) { +if (object_set_property (MACHINE_MEMORY_SLOTS_OPT , ram_slots_str, + current_machine)) { +exit (EXIT_FAILURE ); + } + } + + machine_opts =qemu_get_machine_opts ();if (qemu_opt_foreach (machine_opts, object_set_property, current_machine,1 ) <0 ) {@@ -4229,6 +4216,9 @@ int main(int argc, char **argv, char **envp) } } + ram_size =object_property_get_int (OBJECT (current_machine), +MACHINE_MEMORY_SIZE_OPT , + &error_abort); machine_opts =qemu_get_machine_opts (); kernel_filename =qemu_opt_get (machine_opts,"kernel" ); initrd_filename =qemu_opt_get (machine_opts,"initrd" );@@ -4314,14 +4304,6 @@ int main(int argc, char **argv, char **envp)if (foreach_device_config (DEV_BT , bt_parse))exit (1 ); -if (!xen_enabled ()) { -/* On 32-bit hosts, QEMU is limited by virtual address space */ -if (ram_size > (2047 <<20 ) &&HOST_LONG_BITS ==32 ) { -fprintf (stderr,"qemu: at most 2047 MB RAM can be simulated\n" ); -exit (1 ); - } - } -blk_mig_init ();ram_mig_init ();@@ -4386,12 +4368,15 @@ int main(int argc, char **argv, char **envp)qdev_machine_init (); - current_machine->ram_size = ram_size; - current_machine->maxram_size = maxram_size; - current_machine->ram_slots = ram_slots; current_machine->boot_order = boot_order; current_machine->cpu_model = cpu_model; + machine_class->instance_pre_init (current_machine, &local_err); +if (local_err !=NULL ) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } machine_class->init (current_machine);audio_init ();Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 3/4] machine: convert ram_size, maxram_size, ram_slots to properties
Quoted 135 lines · On Wed, 25 Jun 2014 14:54:47 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 134 lines · Igor Mammedov
... short term it will help writing unit tests accessing these values via QMP. And down the road it will allow to drop global variable
ram_size.Signed-off-by Igor Mammedov <[email protected]>--- hw/core/machine.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 5 ++ vl.c | 123 +++++++++++++++------------------- 3 files changed, 240 insertions(+), 69 deletions(-)hw/core/machine.c +108
-0@@ -12,6 +12,10 @@#include "hw/boards.h" #include "qapi/visitor.h" +#include "qemu/error-report.h" +#include "hw/xen/xen.h" + +static const ram_addr_t default_ram_size =128 *1024 *1024 ;static char *machine_get_accel (Object *obj,Error **errp) {@@ -235,8 +239,118 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp) ms->firmware =g_strdup (value); } +static void machine_get_ram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +int64_t value = ms->ram_size; + +visit_type_int (v, &value, name, errp); +} + +static void machine_set_ram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, &value, name, &error); +if (error) { + goto out; + } + + value =QEMU_ALIGN_UP (value,8192 ); + ms->ram_size = value; +if (ms->ram_size != value) { +error_setg (&error,"ram size too large" ); + goto out; + } + +if (!ms->ram_size) { +error_setg (&error,"ram size can't be 0" ); + } +out: +if (error) { +error_propagate (errp, error); + } +} + +static void machine_get_maxram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +int64_t value = ms->maxram_size; + +visit_type_int (v, &value, name, errp); +} + +static void machine_set_maxram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, &value, name, &error); +if (error) { + goto out; + } + + ms->maxram_size = value; +if (ms->maxram_size != value) { +error_setg (&error,"maxmem is too large" ); + goto out; + } + +if (!ms->maxram_size) { +error_setg (&error,"maxmem can't be 0" ); + } +out: +if (error) { +error_propagate (errp, error); + } +} + +static void machine_get_ram_slots (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +int64_t value = ms->ram_slots; + +visit_type_int (v, &value, name, errp); +} + +static void machine_set_ram_slots (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, &value, name, &error); +if (error) { + goto out; + } + + ms->ram_slots = value; + +out: +if (error) {
Quoted 8 lines
hw/core/machine.c static void machine_set_firmware(Object *obj, const char *value, Error **errp)
Quoted 4 lines
hw/core/machine.c +3
-0+error_propagate (errp, error); + } +}Really that's too much boiler plate code for each value. Can't we support a "validate" callback from standard integer values, to be called after parsing?
machine_set_ram_slots() could be reduced to:
+static void machine_set_ram_slots(Object *obj, Visitor *v,
+ void *opaque, const char *name,
+ Error **errp)
+{
+ MachineState *ms = MACHINE(obj);
+
+ visit_type_int(v, &value, name, errp);
+}
maxram_size/ram_size setters could be reduced ~11 LOC moving common parts to a helper.
But generic property validator is probably out of scope for this series and it won't help much in this case.
Quoted 329 lines
Quoted 44 lines
hw/core/machine.c +26
-0static void machine_initfn (Object *obj) { +MachineState *ms =MACHINE (obj); +object_property_add_str (obj,"accel" , machine_get_accel, machine_set_accel,NULL ); object_property_add_bool(obj, "kernel_irqchip",@@ -274,6 +388,20 @@ static void machine_initfn(Object *obj)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 ); + + ms->ram_size = default_ram_size; +object_property_add (obj,MACHINE_MEMORY_SIZE_OPT ,"int" , + machine_get_ram_size, + machine_set_ram_size, +NULL ,NULL ,NULL ); +object_property_add (obj,MACHINE_MAXMEMORY_SIZE_OPT ,"int" , + machine_get_maxram_size, + machine_set_maxram_size, +NULL ,NULL ,NULL ); +object_property_add (obj,MACHINE_MEMORY_SLOTS_OPT ,"int" , + machine_get_ram_slots, + machine_set_ram_slots, +NULL ,NULL ,NULL ); }static void machine_finalize (Object *obj)@@ -290,11 +418,64 @@ static void machine_finalize(Object *obj)g_free (ms->firmware); } +static void machine_pre_init (MachineState *ms,Error **errp) +{ +Error *error =NULL ; + +if ((ms->ram_size > ms->maxram_size) && ms->maxram_size) { +error_setg (&error,"invalid \"maxmem\" value (%" RAM_ADDR_FMT +") < initial memory (%" RAM_ADDR_FMT ")" , + ms->maxram_size, ms->ram_size); + goto out; + }hw/core/machine.c static void machine_finalize(Object *obj) · line 440
Quoted 10 lines
hw/core/machine.c +10
-0+ +if ((ms->ram_size < ms->maxram_size) && !ms->ram_slots) { +error_setg (&error,"invalid \"maxmem\" value (%" RAM_ADDR_FMT ") " +"more than initial memory (%" PRIu64") but " +"no hotplug slots where specified" , + ms->maxram_size, ms->ram_size); + goto out; + } + +if ((ms->ram_size == ms->maxram_size) && ms->ram_slots) {ugly () within conditions, not really needed.
Quoted 271 lines
hw/core/machine.c +33
-0+error_setg (&error,"invalid \"maxmem\" value (%" RAM_ADDR_FMT ") " +"it must be more than initial memory if hotplug slots > 0" , + ms->maxram_size); + goto out; + } + +if (!ms->maxram_size && !ms->ram_slots) { + ms->maxram_size = ms->ram_size; + } + +if (!xen_enabled ()) { +/* On 32-bit hosts, QEMU is limited by virtual address space */ +if (HOST_LONG_BITS ==32 && ((ms->ram_size > (2047 <<20 )) || + (ms->maxram_size > (2047 <<20 )))) { +error_setg (&error,"at most 2047 MB RAM can be simulated\n" ); + goto out; + } + } + +out: +if (error) { +error_propagate (errp, error); + } +} + +static void machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->instance_pre_init = machine_pre_init; +} +static const TypeInfo machine_info = { .name =TYPE_MACHINE , .parent =TYPE_OBJECT , .abstract = true, .class_size =sizeof (MachineClass), + .class_init = machine_class_init, .instance_size =sizeof (MachineState), .instance_init = machine_initfn, .instance_finalize = machine_finalize,include/hw/boards.h +5
-0@@ -81,6 +81,7 @@ struct MachineClass {const char *desc;void (*init)(MachineState *state); +void (*instance_pre_init)(MachineState *state,Error **errp);void (*reset)(void );void (*hot_add_cpu)(const int64_t id,Error **errp);int (*kvm_type)(const char *arg);@@ -134,4 +135,8 @@ struct MachineState { const char *cpu_model; }; +#define MACHINE_MEMORY_SIZE_OPT "memory-size" +#define MACHINE_MEMORY_SLOTS_OPT "memory-slots" +#define MACHINE_MAXMEMORY_SIZE_OPT "maxmem" +#endif vl.c +54
-69@@ -119,8 +119,6 @@ int main(int argc, char **argv)#include "qom/object_interfaces.h" #include "qapi-event.h" -#define DEFAULT_RAM_SIZE 128 -#define MAX_VIRTIO_CONSOLES 1#define MAX_SCLP_CONSOLES 1@@ -2928,10 +2926,8 @@ int main(int argc, char **argv, char **envp)const char *trace_events =NULL ;const char *trace_file =NULL ;Error *local_err =NULL ; -const ram_addr_t default_ram_size = (ram_addr_t )DEFAULT_RAM_SIZE * -1024 *1024 ; -ram_addr_t maxram_size = default_ram_size; -uint64_t ram_slots =0 ; +const char *maxram_size_str =NULL ; +const char *ram_slots_str =NULL ;FILE *vmstate_dump_file =NULL ;atexit (qemu_run_exit_notifiers);@@ -2978,7 +2974,7 @@ int main(int argc, char **argv, char **envp)module_call_init (MODULE_INIT_MACHINE ); machine_class =find_default_machine (); cpu_model =NULL ; - ram_size = default_ram_size; + ram_size =0 ; snapshot =0 ; cyls = heads = secs =0 ; translation =BIOS_ATA_TRANSLATION_AUTO ;@@ -3269,7 +3265,6 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_m: {uint64_t sz;const char *mem_str; -const char *maxmem_str, *slots_str; opts =qemu_opts_parse (qemu_find_opts ("memory" ), optarg,1 );@@ -3287,7 +3282,7 @@ int main(int argc, char **argv, char **envp)exit (EXIT_FAILURE ); } - sz =qemu_opt_get_size (opts,"size" , ram_size); + sz =qemu_opt_get_size (opts,"size" ,0 );/* Fix up legacy suffix-less format */ if (g_ascii_isdigit (mem_str[strlen (mem_str) -1 ])) {@@ -3301,54 +3296,12 @@ int main(int argc, char **argv, char **envp) }/* backward compatibility behaviour for case "-m 0" */ -if (sz ==0 ) { - sz = default_ram_size; - } - - sz =QEMU_ALIGN_UP (sz,8192 ); - ram_size = sz; -if (ram_size != sz) { -error_report ("ram size too large" ); -exit (EXIT_FAILURE ); +if (sz !=0 ) { + ram_size = sz; } - maxmem_str =qemu_opt_get (opts,"maxmem" ); - slots_str =qemu_opt_get (opts,"slots" ); -if (maxmem_str && slots_str) { -uint64_t slots; - - sz =qemu_opt_get_size (opts,"maxmem" ,0 ); -if (sz < ram_size) { -fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") <= initial memory (%" -RAM_ADDR_FMT ")\n" , sz, ram_size); -exit (EXIT_FAILURE ); - } - - slots =qemu_opt_get_number (opts,"slots" ,0 ); -if ((sz > ram_size) && !slots) { -fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") more than initial memory (%" -RAM_ADDR_FMT ") but no hotplug slots where " -"specified\n" , sz, ram_size); -exit (EXIT_FAILURE ); - } - -if ((sz <= ram_size) && slots) { -fprintf (stderr,"qemu: invalid -m option value: %" - PRIu64" hotplug slots where specified but " -"maxmem (%" PRIu64") <= initial memory (%" -RAM_ADDR_FMT ")\n" , slots, sz, ram_size); -exit (EXIT_FAILURE ); - } - maxram_size = sz; - ram_slots = slots; - }else if ((!maxmem_str && slots_str) || - (maxmem_str && !slots_str)) { -fprintf (stderr,"qemu: invalid -m option value: missing " -"'%s' option\n" , slots_str ?"maxmem" :"slots" ); -exit (EXIT_FAILURE ); - } + maxram_size_str =qemu_opt_get (opts,"maxmem" ); + ram_slots_str =qemu_opt_get (opts,"slots" );break ; }#ifdef CONFIG_TPM @@ -4203,14 +4156,48 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -/* store value for the future use */ -qemu_opt_set_number (qemu_find_opts_singleton ("memory" ),"size" , ram_size); -if (qemu_opts_foreach (qemu_find_opts ("device" ), device_help_func,NULL ,0 ) !=0 ) {exit (0 ); } +if (ram_size) { +object_property_set_int (OBJECT (current_machine), ram_size, +MACHINE_MEMORY_SIZE_OPT , &local_err); +if (local_err) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } + } + +if (maxram_size_str) { +uint64_t sz =qemu_opt_get_size (qemu_find_opts_singleton ("memory" ), +"maxmem" ,0 ); + +parse_option_size ("maxmem" , maxram_size_str, &sz, &local_err); +if (local_err) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } +object_property_set_int (OBJECT (current_machine), sz, +MACHINE_MAXMEMORY_SIZE_OPT , &local_err); +if (local_err) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } + } + +if (ram_slots_str) { +if (object_set_property (MACHINE_MEMORY_SLOTS_OPT , ram_slots_str, + current_machine)) { +exit (EXIT_FAILURE ); + } + } + + machine_opts =qemu_get_machine_opts ();if (qemu_opt_foreach (machine_opts, object_set_property, current_machine,1 ) <0 ) {@@ -4229,6 +4216,9 @@ int main(int argc, char **argv, char **envp) } } + ram_size =object_property_get_int (OBJECT (current_machine), +MACHINE_MEMORY_SIZE_OPT , + &error_abort); machine_opts =qemu_get_machine_opts (); kernel_filename =qemu_opt_get (machine_opts,"kernel" ); initrd_filename =qemu_opt_get (machine_opts,"initrd" );@@ -4314,14 +4304,6 @@ int main(int argc, char **argv, char **envp)if (foreach_device_config (DEV_BT , bt_parse))exit (1 ); -if (!xen_enabled ()) { -/* On 32-bit hosts, QEMU is limited by virtual address space */ -if (ram_size > (2047 <<20 ) &&HOST_LONG_BITS ==32 ) { -fprintf (stderr,"qemu: at most 2047 MB RAM can be simulated\n" ); -exit (1 ); - } - } -blk_mig_init ();ram_mig_init ();@@ -4386,12 +4368,15 @@ int main(int argc, char **argv, char **envp)qdev_machine_init (); - current_machine->ram_size = ram_size; - current_machine->maxram_size = maxram_size; - current_machine->ram_slots = ram_slots; current_machine->boot_order = boot_order; current_machine->cpu_model = cpu_model; + machine_class->instance_pre_init (current_machine, &local_err); +if (local_err !=NULL ) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } machine_class->init (current_machine);audio_init ();Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 3/4] machine: convert ram_size, maxram_size, ram_slots to properties
Quoted 149 lines · Igor Mammedov
Quoted 135 lines · On Wed, 25 Jun 2014 14:54:47 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 134 lines · Igor Mammedov
... short term it will help writing unit tests accessing these values via QMP. And down the road it will allow to drop global variable
ram_size.Signed-off-by Igor Mammedov <[email protected]>--- hw/core/machine.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 5 ++ vl.c | 123 +++++++++++++++------------------- 3 files changed, 240 insertions(+), 69 deletions(-)hw/core/machine.c +108
-0@@ -12,6 +12,10 @@#include "hw/boards.h" #include "qapi/visitor.h" +#include "qemu/error-report.h" +#include "hw/xen/xen.h" + +static const ram_addr_t default_ram_size =128 *1024 *1024 ;static char *machine_get_accel (Object *obj,Error **errp) {@@ -235,8 +239,118 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp) ms->firmware =g_strdup (value); } +static void machine_get_ram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +int64_t value = ms->ram_size; + +visit_type_int (v, &value, name, errp); +} + +static void machine_set_ram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, &value, name, &error); +if (error) { + goto out; + } + + value =QEMU_ALIGN_UP (value,8192 ); + ms->ram_size = value; +if (ms->ram_size != value) { +error_setg (&error,"ram size too large" ); + goto out; + } + +if (!ms->ram_size) { +error_setg (&error,"ram size can't be 0" ); + } +out: +if (error) { +error_propagate (errp, error); + } +} + +static void machine_get_maxram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +int64_t value = ms->maxram_size; + +visit_type_int (v, &value, name, errp); +} + +static void machine_set_maxram_size (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, &value, name, &error); +if (error) { + goto out; + } + + ms->maxram_size = value; +if (ms->maxram_size != value) { +error_setg (&error,"maxmem is too large" ); + goto out; + } + +if (!ms->maxram_size) { +error_setg (&error,"maxmem can't be 0" ); + } +out: +if (error) { +error_propagate (errp, error); + } +} + +static void machine_get_ram_slots (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +int64_t value = ms->ram_slots; + +visit_type_int (v, &value, name, errp); +} + +static void machine_set_ram_slots (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, &value, name, &error); +if (error) { + goto out; + } + + ms->ram_slots = value; + +out: +if (error) {Quoted 8 lines
hw/core/machine.c static void machine_set_firmware(Object *obj, const char *value, Error **errp)
Quoted 4 lines
hw/core/machine.c +3
-0+error_propagate (errp, error); + } +}Really that's too much boiler plate code for each value. Can't we support a "validate" callback from standard integer values, to be called after parsing?
machine_set_ram_slots()could be reduced to:
hw/core/machine.c static void machine_set_firmware(Object *obj, const char *value, Error **errp) · line 340
Quoted 8 lines
hw/core/machine.c +8
-0+static void machine_set_ram_slots (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +MachineState *ms =MACHINE (obj); + +visit_type_int (v, &value, name, errp); +}
Still too much for a single property, sorry.
Quoted 5 lines
maxram_size/ram_size setters could be reduced ~11 LOC moving common parts to a helper.
But generic property validator is probably out of scope for this series
We have time to do it right, we are past development freeze so this is 2.2 material.
In fact, FYI I'm not queueing 2.2 patches anyway, it would help me if you tagged them as RFC explicitly.
Quoted 1 line
and it won't help much in this case.
Done right, it should help.
Basically we have a ton of integer properties
where the only tricky thing is that
value is validated before it is saved.
So what I want is a variant of DEFINE_PROP
which invokes a callback on the value
before saving it, and checks the return code.
Along the lines of:
DEFINE_PROP_UINT32_VALIDATE("foo", type, field, default, validate),
Quoted 329 lines
Quoted 329 lines
Quoted 44 lines
hw/core/machine.c +26
-0static void machine_initfn (Object *obj) { +MachineState *ms =MACHINE (obj); +object_property_add_str (obj,"accel" , machine_get_accel, machine_set_accel,NULL ); object_property_add_bool(obj, "kernel_irqchip",@@ -274,6 +388,20 @@ static void machine_initfn(Object *obj)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 ); + + ms->ram_size = default_ram_size; +object_property_add (obj,MACHINE_MEMORY_SIZE_OPT ,"int" , + machine_get_ram_size, + machine_set_ram_size, +NULL ,NULL ,NULL ); +object_property_add (obj,MACHINE_MAXMEMORY_SIZE_OPT ,"int" , + machine_get_maxram_size, + machine_set_maxram_size, +NULL ,NULL ,NULL ); +object_property_add (obj,MACHINE_MEMORY_SLOTS_OPT ,"int" , + machine_get_ram_slots, + machine_set_ram_slots, +NULL ,NULL ,NULL ); }static void machine_finalize (Object *obj)@@ -290,11 +418,64 @@ static void machine_finalize(Object *obj)g_free (ms->firmware); } +static void machine_pre_init (MachineState *ms,Error **errp) +{ +Error *error =NULL ; + +if ((ms->ram_size > ms->maxram_size) && ms->maxram_size) { +error_setg (&error,"invalid \"maxmem\" value (%" RAM_ADDR_FMT +") < initial memory (%" RAM_ADDR_FMT ")" , + ms->maxram_size, ms->ram_size); + goto out; + }hw/core/machine.c static void machine_finalize(Object *obj) · line 440
Quoted 10 lines
hw/core/machine.c +10
-0+ +if ((ms->ram_size < ms->maxram_size) && !ms->ram_slots) { +error_setg (&error,"invalid \"maxmem\" value (%" RAM_ADDR_FMT ") " +"more than initial memory (%" PRIu64") but " +"no hotplug slots where specified" , + ms->maxram_size, ms->ram_size); + goto out; + } + +if ((ms->ram_size == ms->maxram_size) && ms->ram_slots) {ugly () within conditions, not really needed.
Quoted 271 lines
hw/core/machine.c +33
-0+error_setg (&error,"invalid \"maxmem\" value (%" RAM_ADDR_FMT ") " +"it must be more than initial memory if hotplug slots > 0" , + ms->maxram_size); + goto out; + } + +if (!ms->maxram_size && !ms->ram_slots) { + ms->maxram_size = ms->ram_size; + } + +if (!xen_enabled ()) { +/* On 32-bit hosts, QEMU is limited by virtual address space */ +if (HOST_LONG_BITS ==32 && ((ms->ram_size > (2047 <<20 )) || + (ms->maxram_size > (2047 <<20 )))) { +error_setg (&error,"at most 2047 MB RAM can be simulated\n" ); + goto out; + } + } + +out: +if (error) { +error_propagate (errp, error); + } +} + +static void machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->instance_pre_init = machine_pre_init; +} +static const TypeInfo machine_info = { .name =TYPE_MACHINE , .parent =TYPE_OBJECT , .abstract = true, .class_size =sizeof (MachineClass), + .class_init = machine_class_init, .instance_size =sizeof (MachineState), .instance_init = machine_initfn, .instance_finalize = machine_finalize,include/hw/boards.h +5
-0@@ -81,6 +81,7 @@ struct MachineClass {const char *desc;void (*init)(MachineState *state); +void (*instance_pre_init)(MachineState *state,Error **errp);void (*reset)(void );void (*hot_add_cpu)(const int64_t id,Error **errp);int (*kvm_type)(const char *arg);@@ -134,4 +135,8 @@ struct MachineState { const char *cpu_model; }; +#define MACHINE_MEMORY_SIZE_OPT "memory-size" +#define MACHINE_MEMORY_SLOTS_OPT "memory-slots" +#define MACHINE_MAXMEMORY_SIZE_OPT "maxmem" +#endif vl.c +54
-69@@ -119,8 +119,6 @@ int main(int argc, char **argv)#include "qom/object_interfaces.h" #include "qapi-event.h" -#define DEFAULT_RAM_SIZE 128 -#define MAX_VIRTIO_CONSOLES 1#define MAX_SCLP_CONSOLES 1@@ -2928,10 +2926,8 @@ int main(int argc, char **argv, char **envp)const char *trace_events =NULL ;const char *trace_file =NULL ;Error *local_err =NULL ; -const ram_addr_t default_ram_size = (ram_addr_t )DEFAULT_RAM_SIZE * -1024 *1024 ; -ram_addr_t maxram_size = default_ram_size; -uint64_t ram_slots =0 ; +const char *maxram_size_str =NULL ; +const char *ram_slots_str =NULL ;FILE *vmstate_dump_file =NULL ;atexit (qemu_run_exit_notifiers);@@ -2978,7 +2974,7 @@ int main(int argc, char **argv, char **envp)module_call_init (MODULE_INIT_MACHINE ); machine_class =find_default_machine (); cpu_model =NULL ; - ram_size = default_ram_size; + ram_size =0 ; snapshot =0 ; cyls = heads = secs =0 ; translation =BIOS_ATA_TRANSLATION_AUTO ;@@ -3269,7 +3265,6 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_m: {uint64_t sz;const char *mem_str; -const char *maxmem_str, *slots_str; opts =qemu_opts_parse (qemu_find_opts ("memory" ), optarg,1 );@@ -3287,7 +3282,7 @@ int main(int argc, char **argv, char **envp)exit (EXIT_FAILURE ); } - sz =qemu_opt_get_size (opts,"size" , ram_size); + sz =qemu_opt_get_size (opts,"size" ,0 );/* Fix up legacy suffix-less format */ if (g_ascii_isdigit (mem_str[strlen (mem_str) -1 ])) {@@ -3301,54 +3296,12 @@ int main(int argc, char **argv, char **envp) }/* backward compatibility behaviour for case "-m 0" */ -if (sz ==0 ) { - sz = default_ram_size; - } - - sz =QEMU_ALIGN_UP (sz,8192 ); - ram_size = sz; -if (ram_size != sz) { -error_report ("ram size too large" ); -exit (EXIT_FAILURE ); +if (sz !=0 ) { + ram_size = sz; } - maxmem_str =qemu_opt_get (opts,"maxmem" ); - slots_str =qemu_opt_get (opts,"slots" ); -if (maxmem_str && slots_str) { -uint64_t slots; - - sz =qemu_opt_get_size (opts,"maxmem" ,0 ); -if (sz < ram_size) { -fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") <= initial memory (%" -RAM_ADDR_FMT ")\n" , sz, ram_size); -exit (EXIT_FAILURE ); - } - - slots =qemu_opt_get_number (opts,"slots" ,0 ); -if ((sz > ram_size) && !slots) { -fprintf (stderr,"qemu: invalid -m option value: maxmem " -"(%" PRIu64") more than initial memory (%" -RAM_ADDR_FMT ") but no hotplug slots where " -"specified\n" , sz, ram_size); -exit (EXIT_FAILURE ); - } - -if ((sz <= ram_size) && slots) { -fprintf (stderr,"qemu: invalid -m option value: %" - PRIu64" hotplug slots where specified but " -"maxmem (%" PRIu64") <= initial memory (%" -RAM_ADDR_FMT ")\n" , slots, sz, ram_size); -exit (EXIT_FAILURE ); - } - maxram_size = sz; - ram_slots = slots; - }else if ((!maxmem_str && slots_str) || - (maxmem_str && !slots_str)) { -fprintf (stderr,"qemu: invalid -m option value: missing " -"'%s' option\n" , slots_str ?"maxmem" :"slots" ); -exit (EXIT_FAILURE ); - } + maxram_size_str =qemu_opt_get (opts,"maxmem" ); + ram_slots_str =qemu_opt_get (opts,"slots" );break ; }#ifdef CONFIG_TPM @@ -4203,14 +4156,48 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -/* store value for the future use */ -qemu_opt_set_number (qemu_find_opts_singleton ("memory" ),"size" , ram_size); -if (qemu_opts_foreach (qemu_find_opts ("device" ), device_help_func,NULL ,0 ) !=0 ) {exit (0 ); } +if (ram_size) { +object_property_set_int (OBJECT (current_machine), ram_size, +MACHINE_MEMORY_SIZE_OPT , &local_err); +if (local_err) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } + } + +if (maxram_size_str) { +uint64_t sz =qemu_opt_get_size (qemu_find_opts_singleton ("memory" ), +"maxmem" ,0 ); + +parse_option_size ("maxmem" , maxram_size_str, &sz, &local_err); +if (local_err) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } +object_property_set_int (OBJECT (current_machine), sz, +MACHINE_MAXMEMORY_SIZE_OPT , &local_err); +if (local_err) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } + } + +if (ram_slots_str) { +if (object_set_property (MACHINE_MEMORY_SLOTS_OPT , ram_slots_str, + current_machine)) { +exit (EXIT_FAILURE ); + } + } + + machine_opts =qemu_get_machine_opts ();if (qemu_opt_foreach (machine_opts, object_set_property, current_machine,1 ) <0 ) {@@ -4229,6 +4216,9 @@ int main(int argc, char **argv, char **envp) } } + ram_size =object_property_get_int (OBJECT (current_machine), +MACHINE_MEMORY_SIZE_OPT , + &error_abort); machine_opts =qemu_get_machine_opts (); kernel_filename =qemu_opt_get (machine_opts,"kernel" ); initrd_filename =qemu_opt_get (machine_opts,"initrd" );@@ -4314,14 +4304,6 @@ int main(int argc, char **argv, char **envp)if (foreach_device_config (DEV_BT , bt_parse))exit (1 ); -if (!xen_enabled ()) { -/* On 32-bit hosts, QEMU is limited by virtual address space */ -if (ram_size > (2047 <<20 ) &&HOST_LONG_BITS ==32 ) { -fprintf (stderr,"qemu: at most 2047 MB RAM can be simulated\n" ); -exit (1 ); - } - } -blk_mig_init ();ram_mig_init ();@@ -4386,12 +4368,15 @@ int main(int argc, char **argv, char **envp)qdev_machine_init (); - current_machine->ram_size = ram_size; - current_machine->maxram_size = maxram_size; - current_machine->ram_slots = ram_slots; current_machine->boot_order = boot_order; current_machine->cpu_model = cpu_model; + machine_class->instance_pre_init (current_machine, &local_err); +if (local_err !=NULL ) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } machine_class->init (current_machine);audio_init ();Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 3/4] machine: convert ram_size, maxram_size, ram_slots to properties
In reply to Igor Mammedovvl.c int main(int argc, char **argv, char **envp) · line 4172
Quoted 10 lines · Igor Mammedov
vl.c +9
-0+if (ram_size) { +object_property_set_int (OBJECT (current_machine), ram_size, +MACHINE_MEMORY_SIZE_OPT , &local_err); +if (local_err) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } + }
You can use &error_abort (global variable) instead of &local_err and let error_set handle the rest. Like this:
if (ram_size) {
object_property_set_int(OBJECT(current_machine), ram_size,
MACHINE_MEMORY_SIZE_OPT, &error_abort);
}Signature · 1 line
Kirill
Re: [Qemu-devel] [PATCH 3/4] machine: convert ram_size, maxram_size, ram_slots to properties
Quoted 13 lines · On Wed, 25 Jun 2014 18:09:52 +0400 (MSK) Kirill Batuzov <[email protected]>…
vl.c int main(int argc, char **argv, char **envp) · line 4172
Quoted 10 lines · Igor Mammedov
vl.c +9
-0+if (ram_size) { +object_property_set_int (OBJECT (current_machine), ram_size, +MACHINE_MEMORY_SIZE_OPT , &local_err); +if (local_err) { +error_report ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +exit (EXIT_FAILURE ); + } + }
Quoted 8 lines
You can use
&error_abort(global variable) instead of&local_errand leterror_sethandle the rest. Like this:if (ram_size) { object_property_set_int(OBJECT(current_machine), ram_size, MACHINE_MEMORY_SIZE_OPT, &error_abort); }
thanks, I'll use error_abort.
PATCH 4/4 test -m option parameters
In reply to Igor Mammedovadds a base for memory hotplug tests, starting with checking that -m option accepts expected options.
--- tests/Makefile | 2 + tests/memhp-test.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 0 deletions(-) create mode 100644 tests/memhp-test.c
tests/Makefile +2 -0
@@ -154,6 +154,7 @@ gcov-files-i386-y += hw/pci-bridge/i82801b11.c check-qtest-i386-y += tests/ioh3420-test$(EXESUF) gcov-files-i386-y += hw/pci-bridge/ioh3420.c check-qtest-i386-y += tests/usb-hcd-ehci-test$(EXESUF) +check-qtest-i386-y += tests/memhp-test$(EXESUF) gcov-files-i386-y += hw/usb/hcd-ehci.c gcov-files-i386-y += hw/usb/hcd-uhci.c gcov-files-i386-y += hw/usb/dev-hid.c
@@ -293,6 +294,7 @@ libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o libqos-pc-obj-y += tests/libqos/malloc-pc.o libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o +tests/memhp-test$(EXESUF): tests/memhp-test.o $(libqos-obj-y) tests/rtc-test$(EXESUF): tests/rtc-test.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o tests/endianness-test$(EXESUF): tests/endianness-test.o
tests/memhp-test.c new file +145 -0
145 lines not on this page · raw message
Signature · 1 line
1.7.1