aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/lguest/lguest.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c
index 20f8253881b3..64110797044a 100644
--- a/Documentation/lguest/lguest.c
+++ b/Documentation/lguest/lguest.c
@@ -769,6 +769,16 @@ static void net_output(struct virtqueue *vq)
769 add_used(vq, head, 0); 769 add_used(vq, head, 0);
770} 770}
771 771
772/* Will reading from this file descriptor block? */
773static bool will_block(int fd)
774{
775 fd_set fdset;
776 struct timeval zero = { 0, 0 };
777 FD_ZERO(&fdset);
778 FD_SET(fd, &fdset);
779 return select(fd+1, &fdset, NULL, NULL, &zero) != 1;
780}
781
772/* This is where we handle packets coming in from the tun device to our 782/* This is where we handle packets coming in from the tun device to our
773 * Guest. */ 783 * Guest. */
774static void net_input(struct virtqueue *vq) 784static void net_input(struct virtqueue *vq)
@@ -781,10 +791,15 @@ static void net_input(struct virtqueue *vq)
781 head = wait_for_vq_desc(vq, iov, &out, &in); 791 head = wait_for_vq_desc(vq, iov, &out, &in);
782 if (out) 792 if (out)
783 errx(1, "Output buffers in net input queue?"); 793 errx(1, "Output buffers in net input queue?");
794
795 /* Deliver interrupt now, since we're about to sleep. */
796 if (vq->pending_used && will_block(net_info->tunfd))
797 trigger_irq(vq);
798
784 len = readv(net_info->tunfd, iov, in); 799 len = readv(net_info->tunfd, iov, in);
785 if (len <= 0) 800 if (len <= 0)
786 err(1, "Failed to read from tun."); 801 err(1, "Failed to read from tun.");
787 add_used_and_trigger(vq, head, len); 802 add_used(vq, head, len);
788} 803}
789 804
790/* This is the helper to create threads. */ 805/* This is the helper to create threads. */