Skip to contentSkip to conversation

fix monitor

PATCH Applied Gerd Hoffmann 7 participants 10 messages Mar 19, 2013 – Apr 4, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix monitor

chardev flow control broke monitor, fix it by adding watch support.

---
v2: fix tyops

---
 monitor.c |   23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
monitor.c +21 -2
index 112e920..74807f9 100644
@@ -261,11 +261,30 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
     }
 }
 
+static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond,
+                                  void *opaque)
+{
+    monitor_flush(opaque);
+    return FALSE;
+}
+
 void monitor_flush(Monitor *mon)
 {
+    int rc;
+
     if (mon && mon->outbuf_index != 0 && !mon->mux_out) {
-        qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index);
-        mon->outbuf_index = 0;
+        rc = qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index);
+        if (rc == mon->outbuf_index) {
+            /* all flushed */
+            mon->outbuf_index = 0;
+            return;
+        }
+        if (rc > 0) {
+            /* partial write */
+            memmove(mon->outbuf, mon->outbuf + rc, mon->outbuf_index - rc);
+            mon->outbuf_index -= rc;
+        }
+        qemu_chr_fe_add_watch(mon->chr, G_IO_OUT, monitor_unblocked, mon);
     }
 }
 
Signature · 1 line
1.7.9.7
#1 lore raw
Quoted 5 lines · Gerd Hoffmann

chardev flow control broke monitor, fix it by adding watch support.

---
v2: fix tyops

Well played, Sir :)

Quoted 32 lines
---
 monitor.c |   23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
monitor.c +14 -2
index 112e920..74807f9 100644
@@ -261,11 +261,30 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
     }
 }
 
+static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond,
+                                  void *opaque)
+{
+    monitor_flush(opaque);
+    return FALSE;
+}
+
 void monitor_flush(Monitor *mon)
 {
+    int rc;
+
     if (mon && mon->outbuf_index != 0 && !mon->mux_out) {
-        qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index);
-        mon->outbuf_index = 0;
+        rc = qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index);
+        if (rc == mon->outbuf_index) {
+            /* all flushed */
+            mon->outbuf_index = 0;
+            return;

monitor.c int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, · line 290

Quoted 10 lines
monitor.c +7 -0
+        }
+        if (rc > 0) {
+            /* partial write */
+            memmove(mon->outbuf, mon->outbuf + rc, mon->outbuf_index - rc);
+            mon->outbuf_index -= rc;
+        }
+        qemu_chr_fe_add_watch(mon->chr, G_IO_OUT, monitor_unblocked, mon);
     }
 }
 

Looks good to me.

Should we maybe forego (re)installing the (new) watch when rc<0? (Especially because on a persistent error the fd might immediately report writability.)

Laszlo

#2 lore raw
Quoted 54 lines · Laszlo Ersek
Quoted 5 lines · Gerd Hoffmann

chardev flow control broke monitor, fix it by adding watch support.

---
v2: fix tyops

Well played, Sir :)

Quoted 32 lines
---
 monitor.c |   23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
monitor.c +14 -2
index 112e920..74807f9 100644
@@ -261,11 +261,30 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
     }
 }
 
+static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond,
+                                  void *opaque)
+{
+    monitor_flush(opaque);
+    return FALSE;
+}
+
 void monitor_flush(Monitor *mon)
 {
+    int rc;
+
     if (mon && mon->outbuf_index != 0 && !mon->mux_out) {
-        qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index);
-        mon->outbuf_index = 0;
+        rc = qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index);
+        if (rc == mon->outbuf_index) {
+            /* all flushed */
+            mon->outbuf_index = 0;
+            return;

monitor.c int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, · line 290

Quoted 10 lines
monitor.c +7 -0
+        }
+        if (rc > 0) {
+            /* partial write */
+            memmove(mon->outbuf, mon->outbuf + rc, mon->outbuf_index - rc);
+            mon->outbuf_index -= rc;
+        }
+        qemu_chr_fe_add_watch(mon->chr, G_IO_OUT, monitor_unblocked, mon);
     }
 }
 

Looks good to me.

Quoted 3 lines

Should we maybe forego (re)installing the (new) watch when rc<0? (Especially because on a persistent error the fd might immediately report writability.)

Yes, it is probably wise to check for errno == EAGAIN (assuming qemu_chr_fe_write makes sure errno it set to something sensible on error).

cheers,
Gerd

#4 lore raw
Quoted 11 lines · Markus Armbruster
Quoted 6 lines · Gerd Hoffmann

chardev flow control broke monitor, fix it by adding watch support.

---
v2: fix tyops
---

Subject lacks v2. Anthony, holler if you want a respin to unconfuse your tools.

I already processed this patch--specifically this copy of it. Newest mail always wins when there's a conflict but please don't rely on that :-)

Regards,

Anthony Liguori

#6 lore raw
In reply to Gerd Hoffmann

Hi Gerd,

I today saw this assert when live migrating a VM. Is this related? The below patch was already applied.

qemu-1.4.5: /usr/src/qemu-1.4.5/monitor.c:297: monitor_puts: Assertion `mon->outbuf_index < sizeof(mon->outbuf) - 1' failed.

Peter

Quoted 54 lines · Gerd Hoffmann

chardev flow control broke monitor, fix it by adding watch support.

---
v2: fix tyops

---
 monitor.c |   23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
monitor.c +21 -2
index 112e920..74807f9 100644
@@ -261,11 +261,30 @@ int monitor_read_password(Monitor *mon, ReadLineFunc
 *readline_func,
     }
 }
 
+static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond,
+                                  void *opaque)
+{
+    monitor_flush(opaque);
+    return FALSE;
+}
+
 void monitor_flush(Monitor *mon)
 {
+    int rc;
+
     if (mon && mon->outbuf_index != 0 && !mon->mux_out) {
-        qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index);
-        mon->outbuf_index = 0;
+        rc = qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index);
+        if (rc == mon->outbuf_index) {
+            /* all flushed */
+            mon->outbuf_index = 0;
+            return;
+        }
+        if (rc > 0) {
+            /* partial write */
+            memmove(mon->outbuf, mon->outbuf + rc, mon->outbuf_index -
 rc);
+            mon->outbuf_index -= rc;
+        }
+        qemu_chr_fe_add_watch(mon->chr, G_IO_OUT, monitor_unblocked,
 mon);
     }

}

--
1.7.9.7

#7 lore raw
Quoted 7 lines · Peter Lieven

Hi Gerd,

I today saw this assert when live migrating a VM. Is this related? The below patch was already applied.

qemu-1.4.5: /usr/src/qemu-1.4.5/monitor.c:297: monitor_puts: Assertion `mon->outbuf_index < sizeof(mon->outbuf) - 1' failed.

Probably, patches (from luiz) are on the list to make the monitor buffer size dynamic, they should fix it.

cheers,
Gerd

#8 lore raw
Quoted 11 lines · On Wed, 03 Apr 2013 14:35:46 +0200 Gerd Hoffmann <[email protected]> wrote:
Quoted 7 lines · Peter Lieven

Hi Gerd,

I today saw this assert when live migrating a VM. Is this related? The below patch was already applied.

qemu-1.4.5: /usr/src/qemu-1.4.5/monitor.c:297: monitor_puts: Assertion `mon->outbuf_index < sizeof(mon->outbuf) - 1' failed.

Probably, patches (from luiz) are on the list to make the monitor buffer size dynamic, they should fix it.

Yes.

Peter, can you please try my series and report if it really fixes the assertion for you?

http://lists.gnu.org/archive/html/qemu-devel/2013-04/msg00369.html

#9 lore raw
Quoted 11 lines · Luiz Capitulino
Quoted 8 lines · On Wed, 03 Apr 2013 14:35:46 +0200 Gerd Hoffmann <[email protected]> wrote:
Quoted 7 lines · Peter Lieven

Hi Gerd,

I today saw this assert when live migrating a VM. Is this related? The below patch was already applied.

qemu-1.4.5: /usr/src/qemu-1.4.5/monitor.c:297: monitor_puts: Assertion `mon->outbuf_index < sizeof(mon->outbuf) - 1' failed.

Quoted 9 lines
Quoted 2 lines

Probably, patches (from luiz) are on the list to make the monitor buffer size dynamic, they should fix it.

Yes.

Peter, can you please try my series and report if it really fixes the assertion for you?

http://lists.gnu.org/archive/html/qemu-devel/2013-04/msg00369.html

I will do, but the assertion was not as easy triggerable for me as typing '?'. We run some tests today with the patches applied and I will let you know if there where any further assertions.

Peter