Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 624620 - Can't write to virtio-serial when in blocking read
Can't write to virtio-serial when in blocking read
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: qemu-kvm (Show other bugs)
6.0
All Linux
low Severity medium
: rc
: ---
Assigned To: Amit Shah
Virtualization Bugs
:
Depends On:
Blocks: 580953
  Show dependency treegraph
 
Reported: 2010-08-17 05:33 EDT by Gal Hammer
Modified: 2014-01-17 07:42 EST (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-08-26 00:52:09 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Gal Hammer 2010-08-17 05:33:54 EDT
I'm trying to work with two threads. One thread is blocking on read from virtio-serial port and the second write to the port when needed. What happen is that the write doesn't return until something is read from the port.

How reproducible:

---< snip >---

#!/usr/bin/python

import os, socket, struct, platform, threading

class ListenThread(threading.Thread):
    def __init__(self, vio):
        self._vio = vio
        threading.Thread.__init__(self)

    def run(self):
        while not False:
            print "Read from vport: %s" % (self._vio.readline())

def main():
    vio = open('/dev/vport0p0', 'r+b')    
    listen = ListenThread(vio)
    listen.start()    
    input = raw_input()
    while input != 'quit':
        print "Before write()"
        vio.write(input)
        print "After write()"
        input = raw_input()    
    vio.close()

if __name__ == "__main__":
    main()

---< snip >---
Comment 2 Amit Shah 2010-08-18 03:21:51 EDT
(In reply to comment #0)
> I'm trying to work with two threads. One thread is blocking on read from
> virtio-serial port and the second write to the port when needed. What happen is
> that the write doesn't return until something is read from the port.

You're going to have to use poll and condition variables to work on the same file descriptor in two different threads.
Comment 3 Gal Hammer 2010-08-18 03:51:01 EDT
(In reply to comment #2)

> You're going to have to use poll and condition variables to work on the same
> file descriptor in two different threads.

I don't want to. This is why I open the bug.
Comment 5 Amit Shah 2010-08-23 04:44:40 EDT
I just wrote a testcase for this bug in the virtio-console test suite:

http://fedorapeople.org/gitweb?p=amitshah/public_git/test-virtserial.git

The test passes, so I guess there's a bug in the userspace app.

This is the testcase I committed:

http://fedorapeople.org/gitweb?p=amitshah/public_git/test-virtserial.git;a=commitdiff;h=e1f100f1fbe0285c7efdfc30f38bece766e59efe

It opens a port in the guest, creates a thread, blocks the thread on read, and then in the parent thread writes some stuff, host reads it and then writes something to the guest to unblock the read. This works as expected.
Comment 6 Gal Hammer 2010-08-23 05:13:15 EDT
On your test case. Does the write() exit *before* the host write something? Or in other words, does the test works if the host doesn't reply?
Comment 7 Amit Shah 2010-08-23 07:25:45 EDT
Which write are you talking about? The write in the guest does complete, it's independent of the host's reply.

I suggest you see the code yourself.
Comment 8 Amit Shah 2010-08-26 00:52:09 EDT
Since this works for me I'm closing this bug. Please re-open if you think this still needs work.

Note You need to log in before you can comment on or make changes to this bug.