vl: Fixes for cleanups to -accel
cover vl: Fixes for cleanups to -accel
Running qemu-system-foo with no options should not generate a warning for "invalid accelerator bar".
Also, fix some mistakes made while moving the code from accel/accel.c.
r~
Richard Henderson (4):
vl: Remove unused variable in configure_accelerators
vl: Free accel_list in configure_accelerators
vl: Remove useless test in configure_accelerators
vl: Only choose enabled accelerators in configure_accelerators
vl.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/4 vl: Remove unused variable in configure_accelerators
The accel_initialised variable no longer has any setters.
--- vl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
vl.c +1 -2
@@ -2749,7 +2749,6 @@ static void configure_accelerators(const char *progname) {const char *accel;char **accel_list, **tmp; -bool accel_initialised = false;bool init_failed = false; qemu_opts_foreach(qemu_find_opts("icount"),
@@ -2776,7 +2775,7 @@ static void configure_accelerators(const char *progname) accel_list =g_strsplit (accel,":" ,0 ); -for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { +for (tmp = accel_list; tmp && *tmp; tmp++) {/* * Filter invalid accelerators here, to prevent obscenities * such as "-machine accel=tcg,,thread=single".
Signature · 1 line
2.20.1
Re: [PATCH 1/4] vl: Remove unused variable in configure_accelerators
Quoted 4 lines · Richard Henderson
The
accel_initialisedvariable no longer has any setters.Fixes 6f6e1698a68cSigned-off-by Richard Henderson <[email protected]>
Quoted 25 lines
--- vl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)vl.c +1
-2@@ -2749,7 +2749,6 @@ static void configure_accelerators(const char *progname) {const char *accel;char **accel_list, **tmp; -bool accel_initialised = false;bool init_failed = false; qemu_opts_foreach(qemu_find_opts("icount"),@@ -2776,7 +2775,7 @@ static void configure_accelerators(const char *progname) accel_list =g_strsplit (accel,":" ,0 ); -for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { +for (tmp = accel_list; tmp && *tmp; tmp++) {/* * Filter invalid accelerators here, to prevent obscenities * such as "-machine accel=tcg,,thread=single".
Signature · 1 line
Alex Bennée
Re: [PATCH 1/4] vl: Remove unused variable in configure_accelerators
In reply to Richard HendersonQuoted 9 lines · Richard Henderson
The
accel_initialisedvariable no longer has any setters.Fixes 6f6e1698a68cSigned-off-by Richard Henderson <[email protected]>--- vl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Reviewed by: Aleksandar Markovic <[email protected]>
Quoted 28 lines
vl.c +0
-1@@ -2749,7 +2749,6 @@ static void configure_accelerators(const char *progname) {const char *accel;char **accel_list, **tmp; -bool accel_initialised = false;bool init_failed = false;qemu_opts_foreach(qemu_find_opts("icount"),
vl.c +1
-1@@ -2776,7 +2775,7 @@ static void configure_accelerators(const char *progname) accel_list =g_strsplit (accel,":" ,0 ); -for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { +for (tmp = accel_list; tmp && *tmp; tmp++) {/* * Filter invalid accelerators here, to prevent obscenities * such as "-machine accel=tcg,,thread=single".
--
2.20.1
Re: [PATCH 1/4] vl: Remove unused variable in configure_accelerators
In reply to Richard HendersonQuoted 4 lines · Richard Henderson
The
accel_initialisedvariable no longer has any setters.Fixes 6f6e1698a68cSigned-off-by Richard Henderson <[email protected]>
Quoted 26 lines
--- vl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)vl.c +1
-2@@ -2749,7 +2749,6 @@ static void configure_accelerators(const char *progname) {const char *accel;char **accel_list, **tmp; -bool accel_initialised = false;bool init_failed = false; qemu_opts_foreach(qemu_find_opts("icount"),@@ -2776,7 +2775,7 @@ static void configure_accelerators(const char *progname) accel_list =g_strsplit (accel,":" ,0 ); -for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { +for (tmp = accel_list; tmp && *tmp; tmp++) {/* * Filter invalid accelerators here, to prevent obscenities * such as "-machine accel=tcg,,thread=single".
PATCH 2/4 vl: Free accel_list in configure_accelerators
In reply to Richard HendersonWe allocate the list with g_strsplit, so free it too. This freeing was lost during one of the rearrangements.
--- vl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
vl.c +3 -1
@@ -2748,7 +2748,6 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)static void configure_accelerators (const char *progname) {const char *accel; -char **accel_list, **tmp;bool init_failed = false; qemu_opts_foreach(qemu_find_opts("icount"),
@@ -2756,6 +2755,8 @@ static void configure_accelerators(const char *progname) accel =qemu_opt_get (qemu_get_machine_opts (),"accel" );if (QTAILQ_EMPTY (&qemu_accel_opts.head)) { +char **accel_list, **tmp; +if (accel ==NULL ) {/* Select the default accelerator */ if (!accel_find ("tcg" ) && !accel_find ("kvm" )) {
@@ -2787,6 +2788,7 @@ static void configure_accelerators(const char *progname)error_report ("invalid accelerator %s" , *tmp); } } +g_strfreev (accel_list); }else {if (accel !=NULL ) {error_report ("The -accel and \"-machine accel=\" options are incompatible" );
Signature · 1 line
2.20.1
Re: [PATCH 2/4] vl: Free accel_list in configure_accelerators
Quoted 32 lines · Richard Henderson
We allocate the list with
g_strsplit, so free it too. This freeing was lost during one of the rearrangements.Fixes 6f6e1698a68cSigned-off-by Richard Henderson <[email protected]>--- vl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)vl.c +2
-1@@ -2748,7 +2748,6 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)static void configure_accelerators (const char *progname) {const char *accel; -char **accel_list, **tmp;bool init_failed = false; qemu_opts_foreach(qemu_find_opts("icount"),@@ -2756,6 +2755,8 @@ static void configure_accelerators(const char *progname) accel =qemu_opt_get (qemu_get_machine_opts (),"accel" );if (QTAILQ_EMPTY (&qemu_accel_opts.head)) { +char **accel_list, **tmp; +if (accel ==NULL ) {/* Select the default accelerator */ if (!accel_find ("tcg" ) && !accel_find ("kvm" )) {
vl.c static void configure_accelerators(const char *progname) · line 2794
Quoted 7 lines
vl.c +1
-0@@ -2787,6 +2788,7 @@ static void configure_accelerators(const char *progname)error_report ("invalid accelerator %s" , *tmp); } } +g_strfreev (accel_list); }else {if (accel !=NULL ) {error_report ("The -accel and \"-machine accel=\" options are incompatible" );
FYI, a fix for this is already part of Laurent's "Trivial branch patches" PULL request from yesterday.
Thomas
Re: [PATCH 2/4] vl: Free accel_list in configure_accelerators
Quoted 35 lines · Thomas Huth
Quoted 34 lines · Richard Henderson
We allocate the list with
g_strsplit, so free it too. This freeing was lost during one of the rearrangements.Fixes 6f6e1698a68cSigned-off-by Richard Henderson <[email protected]>--- vl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)vl.c +2
-1@@ -2748,7 +2748,6 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)static void configure_accelerators (const char *progname) {const char *accel; -char **accel_list, **tmp;bool init_failed = false; qemu_opts_foreach(qemu_find_opts("icount"),@@ -2756,6 +2755,8 @@ static void configure_accelerators(const char *progname) accel =qemu_opt_get (qemu_get_machine_opts (),"accel" );if (QTAILQ_EMPTY (&qemu_accel_opts.head)) { +char **accel_list, **tmp; +if (accel ==NULL ) {/* Select the default accelerator */ if (!accel_find ("tcg" ) && !accel_find ("kvm" )) {@@ -2787,6 +2788,7 @@ static void configure_accelerators(const char *progname)error_report ("invalid accelerator %s" , *tmp); } }
Quoted 8 lines
vl.c static void configure_accelerators(const char *progname) · line 2794
Quoted 5 lines
vl.c +1
-0+g_strfreev (accel_list); }else {if (accel !=NULL ) {error_report ("The -accel and \"-machine accel=\" options are incompatible" );FYI, a fix for this is already part of Laurent's "Trivial branch patches" PULL request from yesterday.
https://patchew.org/QEMU/[email protected]/[email protected]/
Thanks,
Laurent
PATCH 2/4 vl: Free accel_list in configure_accelerators
Quoted 43 lines · Laurent Vivier
Quoted 10 lines · Thomas Huth
Quoted 9 lines · Richard Henderson
We allocate the list with
g_strsplit, so free it too. This freeing was lost during one of the rearrangements.Fixes 6f6e1698a68cSigned-off-by Richard Henderson <[email protected]>--- vl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Quoted 5 lines
vl.c static int do_configure_accelerator(void *opaque,
Quoted 5 lines
vl.c +0
-0@@ -2748,7 +2748,6 @@ static int do_configure_accelerator(void *opaque,QemuOpts *opts, Error **errp)
Quoted 8 lines
vl.c static void configure_accelerators(const char
Quoted 8 lines
vl.c +0
-1static void configure_accelerators (const char *progname) {const char *accel; -char **accel_list, **tmp;bool init_failed = false; qemu_opts_foreach(qemu_find_opts("icount"),@@ -2756,6 +2755,8 @@ static void configure_accelerators(const char*progname)
Quoted 9 lines
vl.c static void configure_accelerators(const char
Quoted 9 lines
vl.c +2
-0accel =qemu_opt_get (qemu_get_machine_opts (),"accel" );if (QTAILQ_EMPTY (&qemu_accel_opts.head)) { +char **accel_list, **tmp; +if (accel ==NULL ) {/* Select the default accelerator */ if (!accel_find ("tcg" ) && !accel_find ("kvm" )) {@@ -2787,6 +2788,7 @@ static void configure_accelerators(const char*progname)
Quoted 7 lines
vl.c static void configure_accelerators(const char *progname)
Quoted 7 lines
vl.c +1
-0error_report ("invalid accelerator %s" , *tmp); } } +g_strfreev (accel_list); }else {if (accel !=NULL ) { error_report("The -accel and \"-machine accel=\" options
Quoted 10 lines
are incompatible");
Quoted 4 lines
Quoted 1 line
FYI, a fix for this is already part of Laurent's "Trivial branch patches" PULL request from yesterday.
https://patchew.org/QEMU/20200108160233.991134-1-laurent@
vivier.eu/[email protected]/
If this (from Laurent's PR) patch is merged, Richard could transform his patch into "vl: Fix the scope of variables accel_list and tmp in configure_accelerator()" in v2.
Whatever happens:
Reviewed by: Aleksandar Markovic <[email protected]>
Quoted 5 lines
Thanks,
Laurent
Re: [PATCH 2/4] vl: Free accel_list in configure_accelerators
In reply to Richard HendersonQuoted 5 lines · Richard Henderson
We allocate the list with
g_strsplit, so free it too. This freeing was lost during one of the rearrangements.Fixes 6f6e1698a68cSigned-off-by Richard Henderson <[email protected]>
Quoted 33 lines
--- vl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)vl.c +3
-1@@ -2748,7 +2748,6 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)static void configure_accelerators (const char *progname) {const char *accel; -char **accel_list, **tmp;bool init_failed = false; qemu_opts_foreach(qemu_find_opts("icount"),@@ -2756,6 +2755,8 @@ static void configure_accelerators(const char *progname) accel =qemu_opt_get (qemu_get_machine_opts (),"accel" );if (QTAILQ_EMPTY (&qemu_accel_opts.head)) { +char **accel_list, **tmp; +if (accel ==NULL ) {/* Select the default accelerator */ if (!accel_find ("tcg" ) && !accel_find ("kvm" )) {@@ -2787,6 +2788,7 @@ static void configure_accelerators(const char *progname)error_report ("invalid accelerator %s" , *tmp); } } +g_strfreev (accel_list); }else {if (accel !=NULL ) {error_report ("The -accel and \"-machine accel=\" options are incompatible" );
Signature · 1 line
Alex Bennée
PATCH 3/4 vl: Remove useless test in configure_accelerators
In reply to Richard HendersonThe result of g_strsplit is never NULL.
--- vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
vl.c +1 -1
@@ -2776,7 +2776,7 @@ static void configure_accelerators(const char *progname) accel_list =g_strsplit (accel,":" ,0 ); -for (tmp = accel_list; tmp && *tmp; tmp++) { +for (tmp = accel_list; *tmp; tmp++) {/* * Filter invalid accelerators here, to prevent obscenities * such as "-machine accel=tcg,,thread=single".
Signature · 1 line
2.20.1
Re: [PATCH 3/4] vl: Remove useless test in configure_accelerators
Quoted 3 lines · Richard Henderson
The result of
g_strsplitis never NULL.Signed-off-by Richard Henderson <[email protected]>
Quoted 17 lines
--- vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)vl.c +1
-1@@ -2776,7 +2776,7 @@ static void configure_accelerators(const char *progname) accel_list =g_strsplit (accel,":" ,0 ); -for (tmp = accel_list; tmp && *tmp; tmp++) { +for (tmp = accel_list; *tmp; tmp++) {/* * Filter invalid accelerators here, to prevent obscenities * such as "-machine accel=tcg,,thread=single".
Signature · 1 line
Alex Bennée
Re: [PATCH 3/4] vl: Remove useless test in configure_accelerators
In reply to Richard HendersonQuoted 8 lines · Richard Henderson
The result of
g_strsplitis never NULL.Signed-off-by Richard Henderson <[email protected]>--- vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed by: Aleksandar Markovic <[email protected]>
Quoted 19 lines
vl.c +1
-1@@ -2776,7 +2776,7 @@ static void configure_accelerators(const char *progname) accel_list =g_strsplit (accel,":" ,0 ); -for (tmp = accel_list; tmp && *tmp; tmp++) { +for (tmp = accel_list; *tmp; tmp++) {/* * Filter invalid accelerators here, to prevent obscenities * such as "-machine accel=tcg,,thread=single".
--
2.20.1
Re: [PATCH 3/4] vl: Remove useless test in configure_accelerators
In reply to Richard HendersonQuoted 13 lines · Richard Henderson
The result of
g_strsplitis never NULL.Signed-off-by Richard Henderson <[email protected]>--- vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)vl.c +0
-0
vl.c static void configure_accelerators(const char *progname) · line 2782
Quoted 8 lines
vl.c +1
-1@@ -2776,7 +2776,7 @@ static void configure_accelerators(const char *progname) accel_list =g_strsplit (accel,":" ,0 ); -for (tmp = accel_list; tmp && *tmp; tmp++) { +for (tmp = accel_list; *tmp; tmp++) {/* * Filter invalid accelerators here, to prevent obscenities * such as "-machine accel=tcg,,thread=single".
PATCH 4/4 vl: Only choose enabled accelerators in configure_accelerators
In reply to Richard HendersonBy choosing "tcg:kvm" when kvm is not enabled, we generate an incorrect warning: "invalid accelerator kvm".
Presumably the inverse is also true with --disable-tcg.
--- vl.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
vl.c +12 -6
@@ -2759,11 +2759,10 @@ static void configure_accelerators(const char *progname)if (accel ==NULL ) {/* Select the default accelerator */ -if (!accel_find ("tcg" ) && !accel_find ("kvm" )) { -error_report ("No accelerator selected and" -" no default accelerator available" ); -exit (1 ); - }else { +bool have_tcg =accel_find ("tcg" ); +bool have_kvm =accel_find ("kvm" ); + +if (have_tcg && have_kvm) {int pnlen =strlen (progname);if (pnlen >=3 &&g_str_equal (&progname[pnlen -3 ],"kvm" )) {/* If the program name ends with "kvm", we prefer KVM */
@@ -2771,9 +2770,16 @@ static void configure_accelerators(const char *progname) }else { accel ="tcg:kvm" ; } + }else if (have_kvm) { + accel ="kvm" ; + }else if (have_tcg) { + accel ="tcg" ; + }else { +error_report ("No accelerator selected and" +" no default accelerator available" ); +exit (1 ); } } - accel_list =g_strsplit (accel,":" ,0 );for (tmp = accel_list; *tmp; tmp++) {
Signature · 1 line
2.20.1
Re: [PATCH 4/4] vl: Only choose enabled accelerators in configure_accelerators
Quoted 21 lines · Richard Henderson
By choosing "tcg:kvm" when kvm is not enabled, we generate an incorrect warning: "invalid accelerator kvm".
Presumably the inverse is also true with --disable-tcg.
Fixes 28a0961757fcSigned-off-by Richard Henderson <[email protected]>--- vl.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)vl.c +0
-2@@ -2759,11 +2759,10 @@ static void configure_accelerators(const char *progname)if (accel ==NULL ) {/* Select the default accelerator */ -if (!accel_find ("tcg" ) && !accel_find ("kvm" )) { - error_report("No accelerator selected and"
vl.c static void configure_accelerators(const char *progname) · line 2768
Quoted 10 lines
vl.c +4
-3- " no default accelerator available"); -exit (1 ); - }else { +bool have_tcg =accel_find ("tcg" ); +bool have_kvm =accel_find ("kvm" ); + +if (have_tcg && have_kvm) {int pnlen =strlen (progname);if (pnlen >=3 &&g_str_equal (&progname[pnlen -3 ],"kvm" )) {
I know you're not touching this bit but:
modified vl.c
@@ -2763,8 +2763,7 @@ static void configure_accelerators(const char *progname)
bool have_kvm = accel_find("kvm");
if (have_tcg && have_kvm) {
- int pnlen = strlen(progname);
- if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) {
+ if (g_str_has_suffix(progname, "kvm")) {
/* If the program name ends with "kvm", we prefer KVM */
accel = "kvm:tcg";
} else {Quoted 9 lines
/* If the program name ends with "kvm", we prefer KVM */vl.c +4
-0@@ -2771,9 +2770,16 @@ static void configure_accelerators(const char *progname) }else { accel ="tcg:kvm" ; } + }else if (have_kvm) { + accel ="kvm" ; + }else if (have_tcg) { + accel ="tcg" ;
vl.c static void configure_accelerators(const char *progname) · line 2785
Quoted 10 lines
vl.c +4
-1+ }else { +error_report ("No accelerator selected and" +" no default accelerator available" ); +exit (1 ); } } - accel_list =g_strsplit (accel,":" ,0 );for (tmp = accel_list; *tmp; tmp++) {
Anyway:
Signature · 1 line
Alex Bennée
PATCH 4/4 vl: Only choose enabled accelerators in configure_accelerators
Quoted 74 lines · Alex Bennée
vl.c static void configure_accelerators(const char
Quoted 16 lines · Richard Henderson
By choosing "tcg:kvm" when kvm is not enabled, we generate an incorrect warning: "invalid accelerator kvm".
Presumably the inverse is also true with --disable-tcg.
Fixes 28a0961757fcSigned-off-by Richard Henderson <[email protected]>--- vl.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)vl.c +0
-0@@ -2759,11 +2759,10 @@ static void configure_accelerators(const char*progname)
Quoted 5 lines
vl.c +0
-2if (accel ==NULL ) {/* Select the default accelerator */ -if (!accel_find ("tcg" ) && !accel_find ("kvm" )) { - error_report("No accelerator selected and"vl.c static void configure_accelerators(const char *progname)
Quoted 10 lines
vl.c +4
-3- " no default accelerator available"); -exit (1 ); - }else { +bool have_tcg =accel_find ("tcg" ); +bool have_kvm =accel_find ("kvm" ); + +if (have_tcg && have_kvm) {int pnlen =strlen (progname);if (pnlen >=3 &&g_str_equal (&progname[pnlen -3 ],"kvm" )) {I know you're not touching this bit but:
modified
vl.c(quoted diff) +1
-2@@ -2763,8 +2763,7 @@ static void configure_accelerators(const char *progname) bool have_kvm = accel_find("kvm"); if (have_tcg && have_kvm) { - int pnlen = strlen(progname); - if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) { + if (g_str_has_suffix(progname, "kvm")) { /* If the program name ends with "kvm", we prefer KVM*/
accel = "kvm:tcg"; } else {vl.c static void configure_accelerators(const char · line 2768
Quoted 1 line
vl.c +0
-0/* If the program name ends with "kvm", we prefer KVM */
vl.c static void configure_accelerators(const char
Quoted 1 line
vl.c +0
-0@@ -2771,9 +2770,16 @@ static void configure_accelerators(const char*progname)
Quoted 16 lines
vl.c +8
-1}else { accel ="tcg:kvm" ; } + }else if (have_kvm) { + accel ="kvm" ; + }else if (have_tcg) { + accel ="tcg" ; + }else { +error_report ("No accelerator selected and" +" no default accelerator available" ); +exit (1 ); } } - accel_list =g_strsplit (accel,":" ,0 );
Quoted 7 lines
vl.c static void configure_accelerators(const char *progname) · line 2785
Quoted 1 line
vl.c +0
-0for (tmp = accel_list; *tmp; tmp++) {Anyway:
Reviewed-by Alex Bennée <[email protected]>
With or without Alex' hint:
Reviewed by: Aleksandar Markovic <[email protected]>
Alex' hint could be a separate patch. If you decide to do it, for that patch too you can include my r-b.
Quoted 3 lines
Alex Bennée
Quoted 9 lines · Richard Henderson
Running qemu-system-foo with no options should not generate a warning for "invalid accelerator bar".
Also, fix some mistakes made while moving the code from
accel/accel.c.r~
Quoted 9 lines
Richard Henderson (4):
vl: Remove unused variable inconfigure_accelerators
vl: Freeaccel_listinconfigure_accelerators
vl: Remove useless test inconfigure_accelerators
vl: Only choose enabled accelerators inconfigure_acceleratorsvl.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
I've queued it, but feel free to beat me to sending a pull request.
Paolo