On (Wed) May 05 2010 [08:16:37], Anthony Liguori wrote: > On 05/04/2010 04:39 PM, Amit Shah wrote: >> For char devices whose backing files are open in non-blocking mode, >> non-blocking writes can now be made using qemu_chr_write_nb(). >> >> For non-blocking chardevs, we can return -EAGAIN to callers of >> qemu_chr_write_nb(). When the backend is ready to accept more data, >> we can let the caller know via a callback. >> >> -EAGAIN is returned only when the backend's file is non-blocking >> and a callback is registered by the caller when invoking >> qemu_chr_add_handlers(). >> >> In case a backend doesn't support non-blocking writes, >> qemu_chr_write_nb() invokes qemu_chr_write(). >> >> Individual callers can update their code to add a callback handler, >> call qemu_chr_write_nb() instead of qemu_chr_write() if they wish to >> receive -EAGAIN notifications. >> >> No backend currently supports non-blocking writes. >> >> Signed-off-by: Amit Shah<amit.s...@redhat.com> >> >> +ssize_t qemu_chr_write_nb(CharDriverState *s, const uint8_t *buf, size_t >> len) >> +{ >> + if (!s->nonblock) { >> + /* Fallback to blocking write if no callback registered */ >> + return qemu_chr_write(s, buf, len); >> + } >> + >> + return s->chr_write_nb(s, buf, len); >> +} >> > > I really dislike the idea of adding another function for this.
This suggestion came from Gerd to separate out a write() that blocks and a write_nb() that doesn't block on -EAGAIN. > Can you > explain why you need this functionality for virtio-console and why this > functionality isn't needed for everything else? I don't know about everything else; but for virtio-console, a fast guest could swamp a host chardev with data and while the host chardev blocks to flush out all the data, a notification to ask the guest to stop is needed so that we don't lose any data. (virtio-console asks virtio-serial to throttle any more data, and virtio-serial doesn't send any more data to this port till it signals otherwise. The guest, in the meantime, keeps filling its queue till the queue is full. Once that happens, writes in guests return with -EAGAIN.) Amit