Skip to contentSkip to conversation

Modify qemu_opt_rename to realize renaming all items in opts

PATCH Superseded Jun Li 2 participants 3 messages Sep 23, 2014 – Sep 24, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jun Li

author
#0 lore raw

PATCH 1/1 Modify qemu_opt_rename to realize renaming all items in opts

Add realization of rename all items in opts for qemu_opt_rename. e.g:
When add bps twice in command line, need to rename all bps to throttling.bps-total.

---
This patch solved following bug:
Bug 1145586 - qemu-kvm will give strange hint when add bps twice for a drive ref:https://bugzilla.redhat.com/show_bug.cgi?id=1145586

---
 blockdev.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
blockdev.c +9 -4
index b361fbb..7c39a06 100644
@@ -536,10 +536,15 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to)
 {
     const char *value;
 
-    value = qemu_opt_get(opts, from);
-    if (value) {
-        qemu_opt_set(opts, to, value);
-        qemu_opt_unset(opts, from);
+    /* rename all items */
+    while (1) {
+        value = qemu_opt_get(opts, from);
+        if (value) {
+            qemu_opt_set(opts, to, value);
+            qemu_opt_unset(opts, from);
+        } else {
+            break;
+        }
     }
 }
 
Signature · 1 line
1.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jun Li

Add realization of rename all items in opts for qemu_opt_rename. e.g:
When add bps twice in command line, need to rename all bps to throttling.bps-total.

---
This patch solved following bug:
Bug 1145586 - qemu-kvm will give strange hint when add bps twice for a drive ref:https://bugzilla.redhat.com/show_bug.cgi?id=1145586

Including that bug link in the commit message might be nice for someone visiting this patch a year from now.

Quoted 9 lines
---
 blockdev.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
blockdev.c +0 -0
index b361fbb..7c39a06 100644

blockdev.c static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to) · line 541

Quoted 10 lines
blockdev.c +3 -4
@@ -536,10 +536,15 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to)
 {
     const char *value;
 
-    value = qemu_opt_get(opts, from);
-    if (value) {
-        qemu_opt_set(opts, to, value);
-        qemu_opt_unset(opts, from);
+    /* rename all items */
+    while (1) {
+        value = qemu_opt_get(opts, from);

Can't this just be written as:

while ((value = qemu_opt_get(opts, from))) {

blockdev.c static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to) · line 547

Quoted 6 lines
blockdev.c +6 -0
+        if (value) {
+            qemu_opt_set(opts, to, value);
+            qemu_opt_unset(opts, from);
+        } else {
+            break;
+        }

and lose the if/else and break? But that's style, not functional, so:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#2 lore raw
Quoted 6 lines · Eric Blake
Quoted 5 lines · Jun Li

Add realization of rename all items in opts for qemu_opt_rename. e.g:
When add bps twice in command line, need to rename all bps to throttling.bps-total.

Quoted 8 lines
Quoted 5 lines

---
This patch solved following bug:
Bug 1145586 - qemu-kvm will give strange hint when add bps twice for a drive ref:https://bugzilla.redhat.com/show_bug.cgi?id=1145586

Including that bug link in the commit message might be nice for someone visiting this patch a year from now.

ok, got it.

Quoted 32 lines
Quoted 10 lines
---
 blockdev.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
blockdev.c +0 -0
index b361fbb..7c39a06 100644

blockdev.c static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to) · line 541

Quoted 10 lines
blockdev.c +3 -4
@@ -536,10 +536,15 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to)
 {
     const char *value;
 
-    value = qemu_opt_get(opts, from);
-    if (value) {
-        qemu_opt_set(opts, to, value);
-        qemu_opt_unset(opts, from);
+    /* rename all items */
+    while (1) {
+        value = qemu_opt_get(opts, from);

Can't this just be written as:

while ((value = qemu_opt_get(opts, from))) {

blockdev.c static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to) · line 547

Quoted 6 lines
blockdev.c +6 -0
+        if (value) {
+            qemu_opt_set(opts, to, value);
+            qemu_opt_unset(opts, from);
+        } else {
+            break;
+        }
Quoted 3 lines

and lose the if/else and break? But that's style, not functional, so:

Thanks. I will submit a new version.

Best Regards,
Jun Li