Skip to contentSkip to conversation

serial: Open non-block

PATCH Applied Dr. David Alan Gilbert (git) 2 participants 4 messages Feb 26, 2018 – Jun 29, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: Open non-block

From: "Dr. David Alan Gilbert" <[email protected]>

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.

---
 chardev/char-serial.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
chardev/char-serial.c +2 -1
index feb52e559d..97be5d4a63 100644
@@ -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;
     }
Signature · 1 line
2.14.3
#1 lore raw
Quoted 10 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

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.

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

Thanks,

Paolo

Quoted 19 lines
---
 chardev/char-serial.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
chardev/char-serial.c +2 -1
index feb52e559d..97be5d4a63 100644
@@ -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;
     }
#2 lore raw
Quoted 8 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 7 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

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).

Quoted 6 lines
Quoted 3 lines

Open the serial port with O_NONBLOCK.

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

Quoted 16 lines

Thanks,

Paolo

Quoted 12 lines
---
 chardev/char-serial.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
chardev/char-serial.c +0 -0
index feb52e559d..97be5d4a63 100644
@@ -265,7 +265,8 @@ static void qmp_chardev_open_serial(Chardev *chr,
     ChardevHostdev *serial = backend->u.serial.data;
     int fd;
 
Quoted 8 lines

chardev/char-serial.c static void qmp_chardev_open_serial(Chardev *chr, · line 272

Quoted 7 lines
chardev/char-serial.c +2 -1
-    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 / [email protected] / Manchester, UK

#3 lore raw
In reply to Dr. David Alan Gilbert (git)
Quoted 20 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

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.

---
 chardev/char-serial.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
chardev/char-serial.c +0 -0
index feb52e559d..97be5d4a63 100644

chardev/char-serial.c static void qmp_chardev_open_serial(Chardev *chr, · line 272

Quoted 9 lines
chardev/char-serial.c +2 -1
@@ -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