diff mbox series

[1/1] serial: Open non-block

Message ID 20180226130452.21309-1-dgilbert@redhat.com
State New
Headers show
Series [1/1] serial: Open non-block | expand

Commit Message

Dr. David Alan Gilbert Feb. 26, 2018, 1:04 p.m. UTC
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

On a real serial device, the open can block if the handshake
lines are in a particular state.  If a QEMU is passing the serial
device to the guest, the QEMU startup is blocked opening the device
(with a symptom seen as a timeout from libvirt).

Open the serial port with O_NONBLOCK.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 chardev/char-serial.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Paolo Bonzini Feb. 26, 2018, 1:57 p.m. UTC | #1
On 26/02/2018 14:04, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> On a real serial device, the open can block if the handshake
> lines are in a particular state.  If a QEMU is passing the serial
> device to the guest, the QEMU startup is blocked opening the device
> (with a symptom seen as a timeout from libvirt).
> 
> Open the serial port with O_NONBLOCK.
> 
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

Socket chardevs have "nowait" for that.  Should serial have something
similar?

Thanks,

Paolo

> ---
>  chardev/char-serial.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/chardev/char-serial.c b/chardev/char-serial.c
> index feb52e559d..97be5d4a63 100644
> --- a/chardev/char-serial.c
> +++ b/chardev/char-serial.c
> @@ -265,7 +265,8 @@ static void qmp_chardev_open_serial(Chardev *chr,
>      ChardevHostdev *serial = backend->u.serial.data;
>      int fd;
>  
> -    fd = qmp_chardev_open_file_source(serial->device, O_RDWR, errp);
> +    fd = qmp_chardev_open_file_source(serial->device, O_RDWR | O_NONBLOCK,
> +                                      errp);
>      if (fd < 0) {
>          return;
>      }
>
Dr. David Alan Gilbert Feb. 26, 2018, 3:13 p.m. UTC | #2
* Paolo Bonzini (pbonzini@redhat.com) wrote:
> On 26/02/2018 14:04, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > 
> > On a real serial device, the open can block if the handshake
> > lines are in a particular state.  If a QEMU is passing the serial
> > device to the guest, the QEMU startup is blocked opening the device
> > (with a symptom seen as a timeout from libvirt).
> > 
> > Open the serial port with O_NONBLOCK.
> > 
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> 
> Socket chardevs have "nowait" for that.  Should serial have something
> similar?

Hmm, maybe, although I think for real serial the nonblocking open should
be the default.
I've not got any more complex tests though for it.
stty -F uses the same trick of opening non-blocking.

Dave

> Thanks,
> 
> Paolo
> 
> > ---
> >  chardev/char-serial.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/chardev/char-serial.c b/chardev/char-serial.c
> > index feb52e559d..97be5d4a63 100644
> > --- a/chardev/char-serial.c
> > +++ b/chardev/char-serial.c
> > @@ -265,7 +265,8 @@ static void qmp_chardev_open_serial(Chardev *chr,
> >      ChardevHostdev *serial = backend->u.serial.data;
> >      int fd;
> >  
> > -    fd = qmp_chardev_open_file_source(serial->device, O_RDWR, errp);
> > +    fd = qmp_chardev_open_file_source(serial->device, O_RDWR | O_NONBLOCK,
> > +                                      errp);
> >      if (fd < 0) {
> >          return;
> >      }
> > 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Paolo Bonzini June 29, 2018, 2:36 p.m. UTC | #3
On 26/02/2018 14:04, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> On a real serial device, the open can block if the handshake
> lines are in a particular state.  If a QEMU is passing the serial
> device to the guest, the QEMU startup is blocked opening the device
> (with a symptom seen as a timeout from libvirt).
> 
> Open the serial port with O_NONBLOCK.
> 
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
>  chardev/char-serial.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/chardev/char-serial.c b/chardev/char-serial.c
> index feb52e559d..97be5d4a63 100644
> --- a/chardev/char-serial.c
> +++ b/chardev/char-serial.c
> @@ -265,7 +265,8 @@ static void qmp_chardev_open_serial(Chardev *chr,
>      ChardevHostdev *serial = backend->u.serial.data;
>      int fd;
>  
> -    fd = qmp_chardev_open_file_source(serial->device, O_RDWR, errp);
> +    fd = qmp_chardev_open_file_source(serial->device, O_RDWR | O_NONBLOCK,
> +                                      errp);
>      if (fd < 0) {
>          return;
>      }
> 

Queued, thanks.

Paolo
diff mbox series

Patch

diff --git a/chardev/char-serial.c b/chardev/char-serial.c
index feb52e559d..97be5d4a63 100644
--- a/chardev/char-serial.c
+++ b/chardev/char-serial.c
@@ -265,7 +265,8 @@  static void qmp_chardev_open_serial(Chardev *chr,
     ChardevHostdev *serial = backend->u.serial.data;
     int fd;
 
-    fd = qmp_chardev_open_file_source(serial->device, O_RDWR, errp);
+    fd = qmp_chardev_open_file_source(serial->device, O_RDWR | O_NONBLOCK,
+                                      errp);
     if (fd < 0) {
         return;
     }