diff mbox series

[RFC,v1,03/26] char-socket: fix the client mode when created through QMP

Message ID 20200415005938.23895-4-alazar@bitdefender.com
State New
Headers show
Series VM introspection | expand

Commit Message

Adalbert Lazăr April 15, 2020, 12:59 a.m. UTC
qmp_chardev_open_socket() ignores the absence of the 'server' argument
and always switches to listen/server mode.

CC: "Marc-André Lureau" <marcandre.lureau@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Adalbert Lazăr <alazar@bitdefender.com>
---
 chardev/char-socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Marc-André Lureau April 15, 2020, 10:37 a.m. UTC | #1
Hi

On Wed, Apr 15, 2020 at 3:00 AM Adalbert Lazăr <alazar@bitdefender.com> wrote:
>
> qmp_chardev_open_socket() ignores the absence of the 'server' argument
> and always switches to listen/server mode.
>
> CC: "Marc-André Lureau" <marcandre.lureau@redhat.com>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Adalbert Lazăr <alazar@bitdefender.com>
> ---
>  chardev/char-socket.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> index 9b2deb0125..fd0106ab85 100644
> --- a/chardev/char-socket.c
> +++ b/chardev/char-socket.c
> @@ -1310,7 +1310,7 @@ static void qmp_chardev_open_socket(Chardev *chr,
>      SocketChardev *s = SOCKET_CHARDEV(chr);
>      ChardevSocket *sock = backend->u.socket.data;
>      bool do_nodelay     = sock->has_nodelay ? sock->nodelay : false;
> -    bool is_listen      = sock->has_server  ? sock->server  : true;
> +    bool is_listen      = sock->has_server  ? sock->server  : false;

I don't understand what you mean. It defaults to server mode. We can't
change that.

>      bool is_telnet      = sock->has_telnet  ? sock->telnet  : false;
>      bool is_tn3270      = sock->has_tn3270  ? sock->tn3270  : false;
>      bool is_waitconnect = sock->has_wait    ? sock->wait    : false;
>
Adalbert Lazăr April 15, 2020, 11:47 a.m. UTC | #2
On Wed, 15 Apr 2020 12:37:34 +0200, Marc-André Lureau <marcandre.lureau@gmail.com> wrote:
> Hi
> 
> On Wed, Apr 15, 2020 at 3:00 AM Adalbert Lazăr <alazar@bitdefender.com> wrote:
> >
> > qmp_chardev_open_socket() ignores the absence of the 'server' argument
> > and always switches to listen/server mode.
> >
> > CC: "Marc-André Lureau" <marcandre.lureau@redhat.com>
> > CC: Paolo Bonzini <pbonzini@redhat.com>
> > Signed-off-by: Adalbert Lazăr <alazar@bitdefender.com>
> > ---
> >  chardev/char-socket.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> > index 9b2deb0125..fd0106ab85 100644
> > --- a/chardev/char-socket.c
> > +++ b/chardev/char-socket.c
> > @@ -1310,7 +1310,7 @@ static void qmp_chardev_open_socket(Chardev *chr,
> >      SocketChardev *s = SOCKET_CHARDEV(chr);
> >      ChardevSocket *sock = backend->u.socket.data;
> >      bool do_nodelay     = sock->has_nodelay ? sock->nodelay : false;
> > -    bool is_listen      = sock->has_server  ? sock->server  : true;
> > +    bool is_listen      = sock->has_server  ? sock->server  : false;
> 
> I don't understand what you mean. It defaults to server mode. We can't
> change that.

First of all, thanks for your comments.

I understand that a chardev socket is either in client mode or in server
mode.  If the 'server' parameter is not used, the socket is put in client
mode. At least this is the behavior when the socket is created by parsing
the command line. But, when created through QMP, without the 'server' parameter,
the socket is put in server mode.

Until this moment, I did not think that we can use "server=no" through QMP :))

So, yes. We may create the socket in client mode through QMP without this patch.

> 
> >      bool is_telnet      = sock->has_telnet  ? sock->telnet  : false;
> >      bool is_tn3270      = sock->has_tn3270  ? sock->tn3270  : false;
> >      bool is_waitconnect = sock->has_wait    ? sock->wait    : false;
> >
> 
> 
> -- 
> Marc-André Lureau
>
Markus Armbruster April 15, 2020, 2:11 p.m. UTC | #3
Adalbert Lazãr <alazar@bitdefender.com> writes:

> On Wed, 15 Apr 2020 12:37:34 +0200, Marc-André Lureau <marcandre.lureau@gmail.com> wrote:
>> Hi
>> 
>> On Wed, Apr 15, 2020 at 3:00 AM Adalbert Lazăr <alazar@bitdefender.com> wrote:
>> >
>> > qmp_chardev_open_socket() ignores the absence of the 'server' argument
>> > and always switches to listen/server mode.
>> >
>> > CC: "Marc-André Lureau" <marcandre.lureau@redhat.com>
>> > CC: Paolo Bonzini <pbonzini@redhat.com>
>> > Signed-off-by: Adalbert Lazăr <alazar@bitdefender.com>
>> > ---
>> >  chardev/char-socket.c | 2 +-
>> >  1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/chardev/char-socket.c b/chardev/char-socket.c
>> > index 9b2deb0125..fd0106ab85 100644
>> > --- a/chardev/char-socket.c
>> > +++ b/chardev/char-socket.c
>> > @@ -1310,7 +1310,7 @@ static void qmp_chardev_open_socket(Chardev *chr,
>> >      SocketChardev *s = SOCKET_CHARDEV(chr);
>> >      ChardevSocket *sock = backend->u.socket.data;
>> >      bool do_nodelay     = sock->has_nodelay ? sock->nodelay : false;
>> > -    bool is_listen      = sock->has_server  ? sock->server  : true;
>> > +    bool is_listen      = sock->has_server  ? sock->server  : false;
>> 
>> I don't understand what you mean. It defaults to server mode. We can't
>> change that.
>
> First of all, thanks for your comments.
>
> I understand that a chardev socket is either in client mode or in server
> mode.  If the 'server' parameter is not used, the socket is put in client
> mode. At least this is the behavior when the socket is created by parsing
> the command line. But, when created through QMP, without the 'server' parameter,
> the socket is put in server mode.
>
> Until this moment, I did not think that we can use "server=no" through QMP :))

Start here:

    $ socat "READLINE,history=$HOME/.qmp_history,prompt=QMP>" UNIX-CONNECT:$HOME/work/images/test-qmp 
    {"QMP": {"version": {"qemu": {"micro": 92, "minor": 2, "major": 4}, "package": "v5.0.0-rc2-30-g25b0509e28"}, "capabilities": ["oob"]}}
    QMP>{"execute": "qmp_capabilities"}
    {"return": {}}
    QMP>{"execute":"chardev-add", "arguments": {"id":"foo", "backend": {"type": "socket", "data": {"addr": {"type": "inet", "data": {"host": "0.0.0.0", "port": "2445"}}, "server": false}}}}
    {"error": {"class": "GenericError", "desc": "Failed to connect socket: Connection refused"}}

> So, yes. We may create the socket in client mode through QMP without this patch.
>
>> 
>> >      bool is_telnet      = sock->has_telnet  ? sock->telnet  : false;
>> >      bool is_tn3270      = sock->has_tn3270  ? sock->tn3270  : false;
>> >      bool is_waitconnect = sock->has_wait    ? sock->wait    : false;
>> >
>> 
>> 
>> -- 
>> Marc-André Lureau
>>
Adalbert Lazăr April 15, 2020, 5:53 p.m. UTC | #4
On Wed, 15 Apr 2020 16:11:14 +0200, Markus Armbruster <armbru@redhat.com> wrote:
> Adalbert Lazãr <alazar@bitdefender.com> writes:
> 
> > On Wed, 15 Apr 2020 12:37:34 +0200, Marc-André Lureau <marcandre.lureau@gmail.com> wrote:
> >> Hi
> >> 
> >> On Wed, Apr 15, 2020 at 3:00 AM Adalbert Lazăr <alazar@bitdefender.com> wrote:
> >> >
> >> > qmp_chardev_open_socket() ignores the absence of the 'server' argument
> >> > and always switches to listen/server mode.
> >> >
> >> > CC: "Marc-André Lureau" <marcandre.lureau@redhat.com>
> >> > CC: Paolo Bonzini <pbonzini@redhat.com>
> >> > Signed-off-by: Adalbert Lazăr <alazar@bitdefender.com>
> >> > ---
> >> >  chardev/char-socket.c | 2 +-
> >> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >> >
> >> > diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> >> > index 9b2deb0125..fd0106ab85 100644
> >> > --- a/chardev/char-socket.c
> >> > +++ b/chardev/char-socket.c
> >> > @@ -1310,7 +1310,7 @@ static void qmp_chardev_open_socket(Chardev *chr,
> >> >      SocketChardev *s = SOCKET_CHARDEV(chr);
> >> >      ChardevSocket *sock = backend->u.socket.data;
> >> >      bool do_nodelay     = sock->has_nodelay ? sock->nodelay : false;
> >> > -    bool is_listen      = sock->has_server  ? sock->server  : true;
> >> > +    bool is_listen      = sock->has_server  ? sock->server  : false;
> >> 
> >> I don't understand what you mean. It defaults to server mode. We can't
> >> change that.
> >
> > First of all, thanks for your comments.
> >
> > I understand that a chardev socket is either in client mode or in server
> > mode.  If the 'server' parameter is not used, the socket is put in client
> > mode. At least this is the behavior when the socket is created by parsing
> > the command line. But, when created through QMP, without the 'server' parameter,
> > the socket is put in server mode.
> >
> > Until this moment, I did not think that we can use "server=no" through QMP :))
> 
> Start here:
> 
>     $ socat "READLINE,history=$HOME/.qmp_history,prompt=QMP>" UNIX-CONNECT:$HOME/work/images/test-qmp 
>     {"QMP": {"version": {"qemu": {"micro": 92, "minor": 2, "major": 4}, "package": "v5.0.0-rc2-30-g25b0509e28"}, "capabilities": ["oob"]}}
>     QMP>{"execute": "qmp_capabilities"}
>     {"return": {}}
>     QMP>{"execute":"chardev-add", "arguments": {"id":"foo", "backend": {"type": "socket", "data": {"addr": {"type": "inet", "data": {"host": "0.0.0.0", "port": "2445"}}, "server": false}}}}
>     {"error": {"class": "GenericError", "desc": "Failed to connect socket: Connection refused"}}
> 

Thank you, Markus.

I wanted to say that while I was writing the reply, I had an aha! moment and I was
amused that I have not thought to use server=no/false and I used the wrong verb tense.
Markus Armbruster April 16, 2020, 6:03 a.m. UTC | #5
Adalbert Lazãr <alazar@bitdefender.com> writes:

> On Wed, 15 Apr 2020 16:11:14 +0200, Markus Armbruster <armbru@redhat.com> wrote:
>> Adalbert Lazãr <alazar@bitdefender.com> writes:
[...]
>> > Until this moment, I did not think that we can use "server=no" through QMP :))
>> 
>> Start here:
>> 
>>     $ socat "READLINE,history=$HOME/.qmp_history,prompt=QMP>" UNIX-CONNECT:$HOME/work/images/test-qmp 
>>     {"QMP": {"version": {"qemu": {"micro": 92, "minor": 2, "major": 4}, "package": "v5.0.0-rc2-30-g25b0509e28"}, "capabilities": ["oob"]}}
>>     QMP>{"execute": "qmp_capabilities"}
>>     {"return": {}}
>>     QMP>{"execute":"chardev-add", "arguments": {"id":"foo", "backend": {"type": "socket", "data": {"addr": {"type": "inet", "data": {"host": "0.0.0.0", "port": "2445"}}, "server": false}}}}
>>     {"error": {"class": "GenericError", "desc": "Failed to connect socket: Connection refused"}}
>> 
>
> Thank you, Markus.
>
> I wanted to say that while I was writing the reply, I had an aha! moment and I was
> amused that I have not thought to use server=no/false and I used the wrong verb tense.

Happy to help!  Enjoy :)
diff mbox series

Patch

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 9b2deb0125..fd0106ab85 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -1310,7 +1310,7 @@  static void qmp_chardev_open_socket(Chardev *chr,
     SocketChardev *s = SOCKET_CHARDEV(chr);
     ChardevSocket *sock = backend->u.socket.data;
     bool do_nodelay     = sock->has_nodelay ? sock->nodelay : false;
-    bool is_listen      = sock->has_server  ? sock->server  : true;
+    bool is_listen      = sock->has_server  ? sock->server  : false;
     bool is_telnet      = sock->has_telnet  ? sock->telnet  : false;
     bool is_tn3270      = sock->has_tn3270  ? sock->tn3270  : false;
     bool is_waitconnect = sock->has_wait    ? sock->wait    : false;