From: Max Vozeler <max@vozeler.com>
To: "Németh Márton" <nm127@freemail.hu>
Cc: gregkh <gregkh@suse.de>,
devel@driverdev.osuosl.org, LKML <linux-kernel@vger.kernel.org>,
usbip-devel@lists.sourceforge.net
Subject: Re: usbip: somtimes stalls at kernel_recvmsg()
Date: Thu, 16 Dec 2010 23:50:27 +0100 [thread overview]
Message-ID: <4D0A97B3.2090701@vozeler.com> (raw)
In-Reply-To: <4D09C056.5020305@freemail.hu>
Hi Németh,
On 16.12.2010 08:31, Németh Márton wrote:
> Németh Márton wrote:
>> I'm working with usbip and I sometimes see a stall when I run
>> the "lsusb" command from the userspace.
Does it eventually recover?
>> I added some debug messages
>> and it seems that the kernel_recvmsg() in
>> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=drivers/staging/usbip/usbip_common.c;h=210ef16bab8d271a52e5d36cd1994aad57ad99e1;hb=HEAD
>>
>> This is the only place I could find where the TCP messages are arriving in
>> the usbip code.
>>
>> What happens if a message does not arrive? Does it stall forever?
Yes, it will block until detached or until a TCP
timeout or error closes the connection.
The TCP timeout can take several minutes.
>> yes, how can the kernel_recvmsg() call changed to handle some timeout?
>
> I found that the userspace manpage of recvmsg(2) ("man recvmsg") contains description
> of the "flags" parameter. I suppose the parameters and behaviour of the userspace
> recvmsg() is the same as the kernelspace kernel_recvmsg().
I recently faced this problem, too.
The solution I arrived at was to set SO_RCVTIMEO
and SO_SNDTIMEO socket opts in the tools together
with the patch below.
The patch works around a lack of heart-beat in
the usbip protocol which would otherwise make idle
connections time out.
(It wont apply cleanly but hopefully conveys the idea.).
Extending the protocol for a heart-beat message
doesn't seem to be possible without breaking the
compatibility at the same time.
I was planning to submit it on the weekend along
with the tool changes to set the timeouts.
Max
---
From: Max Vozeler <max@vozeler.com>
Date: Mon, 13 Dec 2010 00:39:14 +0100
Subject: [PATCH 1/3] vhci: allow SO_RCVTIMEO on the socket
In case of unanswered replies, a receive timeout is
considered a connection error and the device will be
shut down and removed.
This is a workaround for the lack of heart-beat
messages in the USBIP protocol. It allows userspace
to set a maximum latency for the connection.
---
vhci_rx.c | 21 ++++++++++++++++++++-
1 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/vhci_rx.c b/vhci_rx.c
index bc16dc4..9a1fe80 100644
--- a/vhci_rx.c
+++ b/vhci_rx.c
@@ -197,6 +197,19 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,
return;
}
+static int vhci_priv_tx_empty(struct vhci_device *vdev)
+{
+ int empty = 0;
+
+ spin_lock(&vdev->priv_lock);
+
+ empty = list_empty(&vdev->priv_rx);
+
+ spin_unlock(&vdev->priv_lock);
+
+ return empty;
+}
+
/* recv a pdu */
static void vhci_rx_pdu(struct usbip_device *ud)
{
@@ -216,8 +229,14 @@ static void vhci_rx_pdu(struct usbip_device *ud)
usbip_uinfo("connection reset by peer\n");
else if (ret == -ETIMEDOUT)
usbip_uinfo("connection timed out\n");
- else if (ret != -ERESTARTSYS)
+ else if (ret == -EAGAIN) {
+ /* connection was idle? */
+ if (vhci_priv_tx_empty(vdev))
+ return;
+ usbip_uinfo("connection timed out with pending urbs\n");
+ } else if (ret != -ERESTARTSYS)
usbip_uinfo("xmit failed %d\n", ret);
+
usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
return;
}
--
1.7.2.3
next prev parent reply other threads:[~2010-12-16 22:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-13 22:36 usbip: somtimes stalls at kernel_recvmsg() Németh Márton
2010-12-16 7:31 ` Németh Márton
2010-12-16 22:50 ` Max Vozeler [this message]
2010-12-17 5:45 ` usbip: sometimes " Németh Márton
2010-12-20 22:22 ` Max Vozeler
2010-12-21 8:03 ` Németh Márton
2010-12-22 19:49 ` Németh Márton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D0A97B3.2090701@vozeler.com \
--to=max@vozeler.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=nm127@freemail.hu \
--cc=usbip-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).