From: Ronnie Sahlberg <ronniesahlberg@gmail.com>
To: qemu-devel@nongnu.org, kwolf@redhat.com, pbonzini@redhat.com
Cc: Ronnie Sahlberg <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.
Date: Sat, 12 May 2012 08:04:37 +1000 [thread overview]
Message-ID: <1336773877-20725-2-git-send-email-ronniesahlberg@gmail.com> (raw)
In-Reply-To: <1336773877-20725-1-git-send-email-ronniesahlberg@gmail.com>
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 <ronniesahlberg@gmail.com>
---
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 <poll.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
#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
next prev parent reply other threads:[~2012-05-11 22:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-11 22:04 [Qemu-devel] [PATCH 0/1] ISCSI: Dont call libiscsi for POLLIN if there are no bytes readable from the socket Ronnie Sahlberg
2012-05-11 22:04 ` Ronnie Sahlberg [this message]
2012-05-14 15:30 ` [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 Paolo Bonzini
2012-05-15 10:44 ` ronnie sahlberg
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=1336773877-20725-2-git-send-email-ronniesahlberg@gmail.com \
--to=ronniesahlberg@gmail.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).