Patchwork [FOR,0.12] monitor: Accept input only byte-wise

login
register
mail settings
Submitter Jan Kiszka
Date Dec. 4, 2009, 1:05 p.m.
Message ID <4B190919.9040602@siemens.com>
Download mbox | patch
Permalink /patch/40328/
State New
Headers show

Comments

Jan Kiszka - Dec. 4, 2009, 1:05 p.m.
This allows to suspend command interpretation and execution
synchronously, e.g. during migration.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

 monitor.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Daniel P. Berrange - April 16, 2010, 11 a.m.
On Fri, Dec 04, 2009 at 02:05:29PM +0100, Jan Kiszka wrote:
> This allows to suspend command interpretation and execution
> synchronously, e.g. during migration.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
> 
>  monitor.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/monitor.c b/monitor.c
> index 3286ba2..a3be1c8 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -3418,7 +3418,7 @@ static int monitor_can_read(void *opaque)
>  {
>      Monitor *mon = opaque;
>  
> -    return (mon->suspend_cnt == 0) ? 128 : 0;
> +    return (mon->suspend_cnt == 0) ? 1 : 0;
>  }
>  
>  static void monitor_read(void *opaque, const uint8_t *buf, int size)

FYI, this change seems to have broken the 'getfd' command in the monitor. 
Any attempt to use this command (in both text + json modes) is currently 
returning

  "No file descriptor supplied via SCM_RIGHTS"

Reverting this change makes getfd work again for me.

Strace of libvirtd shows it sending the command + FD in one message:

 sendmsg(18, {msg_name(0)=NULL, msg_iov(1)=[{"getfd fd-net2\r", 14}],
  msg_controllen=24, {cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS,
 {16}}, msg_flags=0}, 0) = 14

Strace of qemu shows that it receives the FD ok, but immediately closes it
before finishing reading the actual monitor command with which it is associated:

[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"g", 1}], msg_controllen=24, {cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, {17}}, msg_flags=0}, 0) = 1
[pid 31941] close(17)                   = 0
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"e", 1}], msg_controllen=0, msg_flags=0}, 0) = 1
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"t", 1}], msg_controllen=0, msg_flags=0}, 0) = 1
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"f", 1}], msg_controllen=0, msg_flags=0}, 0) = 1
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"d", 1}], msg_controllen=0, msg_flags=0}, 0) = 1
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{" ", 1}], msg_controllen=0, msg_flags=0}, 0) = 1
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"f", 1}], msg_controllen=0, msg_flags=0}, 0) = 1
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"d", 1}], msg_controllen=0, msg_flags=0}, 0) = 1
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"-", 1}], msg_controllen=0, msg_flags=0}, 0) = 1
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"n", 1}], msg_controllen=0, msg_flags=0}, 0) = 1
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"e", 1}], msg_controllen=0, msg_flags=0}, 0) = 1
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"t", 1}], msg_controllen=0, msg_flags=0}, 0) = 1
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"2", 1}], msg_controllen=0, msg_flags=0}, 0) = 1
[pid 31941] recvmsg(16, {msg_name(0)=NULL, msg_iov(1)=[{"\r", 1}], msg_controllen=0, msg_flags=0}, 0) = 1

The QEMU code appears to be written to assume that it will recvmsg() a
complete monitor command in one go + process that, because it closes the
FD the moment the data from any recvmsg() is dealt with.

Regards,
Daniel

Patch

diff --git a/monitor.c b/monitor.c
index 3286ba2..a3be1c8 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3418,7 +3418,7 @@  static int monitor_can_read(void *opaque)
 {
     Monitor *mon = opaque;
 
-    return (mon->suspend_cnt == 0) ? 128 : 0;
+    return (mon->suspend_cnt == 0) ? 1 : 0;
 }
 
 static void monitor_read(void *opaque, const uint8_t *buf, int size)