From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:46204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSy73-0003Hh-P7 for qemu-devel@nongnu.org; Fri, 11 May 2012 18:15:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSy71-00082k-Is for qemu-devel@nongnu.org; Fri, 11 May 2012 18:15:01 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:62449) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSy71-00082T-9p for qemu-devel@nongnu.org; Fri, 11 May 2012 18:14:59 -0400 Received: by pbbro12 with SMTP id ro12so5210642pbb.4 for ; Fri, 11 May 2012 15:14:57 -0700 (PDT) From: Ronnie Sahlberg Date: Sat, 12 May 2012 08:04:37 +1000 Message-Id: <1336773877-20725-2-git-send-email-ronniesahlberg@gmail.com> In-Reply-To: <1336773877-20725-1-git-send-email-ronniesahlberg@gmail.com> References: <1336773877-20725-1-git-send-email-ronniesahlberg@gmail.com> Subject: [Qemu-devel] [PATCH] ISCSI: iscsi_process_read callback for when the iscsi socket becomes readable may be invoked by qemu after the fd-is-readable event has cleared. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, kwolf@redhat.com, pbonzini@redhat.com Cc: Ronnie Sahlberg Libiscsi treats a situation such as POLLIN was invoked and the socket is readable but ioctl(...FIONREAD...) returns that there are no bytes available to read as an error and that the socket is faulty or has been closed. which may trigger a slow process of closing down the socket completely and trying to reconnect to recover. Update the iscsi fd-is-readable callback iscsi_process_read to check for this condition explicitely. If are invoked and getsockopt tells us there is a real socket problem then we pass POLLIN onto libiscsi and let it try to handle the situation and/or recover. If there is no error, but ioctl(...FIONREAD...) still indicates that there were no bytes to read, then we treat this as just a false invokation from the eventsystem and do nothing. If there are bytes available to read, then we pass POLLIN into libiscsi and let it read and process the bytes. regards ronnie sahlberg Signed-off-by: Ronnie Sahlberg --- block/iscsi.c | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index d37c4ee..694f135 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -25,6 +25,9 @@ #include "config-host.h" #include +#include +#include +#include #include "qemu-common.h" #include "qemu-error.h" #include "block_int.h" @@ -116,6 +119,35 @@ iscsi_process_read(void *arg) { IscsiLun *iscsilun = arg; struct iscsi_context *iscsi = iscsilun->iscsi; + int socket_count = 0; + int err = 0; + socklen_t err_size = sizeof(err); + + /* There are places where we might be invoked but the read-event + may not still be active. + Libiscsi treats POLLIN but socket having no bytes available to read + as a socket error. + So we have to check socket status and available bytes explicitely + before we invoke libiscsi. + */ + if (getsockopt(iscsi_get_fd(iscsi), SOL_SOCKET, SO_ERROR, &err, + &err_size) != 0 || err != 0) { + /* There is a socket error, call libicsi and let it try to handle + the error and maybe try reconnecting. + */ + iscsi_service(iscsi, POLLIN); + iscsi_set_events(iscsilun); + return; + } + + if (ioctl(iscsi_get_fd(iscsi), FIONREAD, &socket_count) == 0 + && socket_count == 0) { + /* no bytes available to read from the socket, and there was no + error, just return without calling libiscsi + */ + iscsi_set_events(iscsilun); + return; + } iscsi_service(iscsi, POLLIN); iscsi_set_events(iscsilun); -- 1.7.3.1