From patchwork Fri May 11 22:04:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ronnie sahlberg X-Patchwork-Id: 158619 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5D86BB6F9D for ; Sat, 12 May 2012 08:15:21 +1000 (EST) Received: from localhost ([::1]:47524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSy7K-0003rk-0O for incoming@patchwork.ozlabs.org; Fri, 11 May 2012 18:15:18 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=TQ7e1U7DBGlnKIrosOwnXjSvnmsU67S4bRK0i4eDDMU=; b=FyT8HdaKvefr1ZqhLoejvhuCnLY9Co050p32x/BiR5TuzsSlkp2TErSu/Aa7CZVB6L fw/oYU7LzpMEUNabDcd55YIJ5nll03wMdW6x7a+swdur4Q6WOJLaSjYUxnMjJ/5YOTeb EsCnZ7lLsmG0Vqfgn4D8a2VFDfBa94poa8O4zMuxGkVwMM2PzZd2f5dNztJOZ8wrxcVK 6eQ7tdQRG1DHUkszUkwUwDku1mGraL7Mw/fsDx6HvIbDkYkrloJ30cYr5bVcGF9wa+IG XWoPlBtFQSLTWXM+L/PLp/zsKGhL2w1+W6wC3u7WjrwXjizMgnBkDa0OzIldPX/JEQMN BARA== Received: by 10.68.190.129 with SMTP id gq1mr24651006pbc.40.1336774497220; Fri, 11 May 2012 15:14:57 -0700 (PDT) Received: from ronniesahlberg@gmail.com ([124.184.109.242]) by mx.google.com with ESMTPS id i1sm13958128pbv.49.2012.05.11.15.14.54 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 11 May 2012 15:14:56 -0700 (PDT) Received: by ronniesahlberg@gmail.com (sSMTP sendmail emulation); Sat, 12 May 2012 08:04:48 +1000 From: Ronnie Sahlberg To: qemu-devel@nongnu.org, kwolf@redhat.com, pbonzini@redhat.com Date: Sat, 12 May 2012 08:04:37 +1000 Message-Id: <1336773877-20725-2-git-send-email-ronniesahlberg@gmail.com> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1336773877-20725-1-git-send-email-ronniesahlberg@gmail.com> References: <1336773877-20725-1-git-send-email-ronniesahlberg@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: Ronnie Sahlberg 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. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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);