From c29b9a2aae92c0843e7e23171c81eb0d3e740788 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Thu, 3 Feb 2011 19:08:16 +1100 Subject: [PATCH] Add a new "iscsi_queue_length()" which will tell us how many commands are in flight at the moment. Aside from commands, we also consider the "has not yet connected completely" as being an i/o. When this command returns 0 it means we are connected ant the iscsi connection is idle, with no commands in flight. KVM needs a function to detect idleness like this for its block layer io_flush function. --- include/iscsi.h | 4 ++++ lib/socket.c | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/iscsi.h b/include/iscsi.h index a3cbf54..11e014c 100644 --- a/include/iscsi.h +++ b/include/iscsi.h @@ -47,6 +47,10 @@ int iscsi_which_events(struct iscsi_context *iscsi); * file descriptor. */ int iscsi_service(struct iscsi_context *iscsi, int revents); +/* + * How many commands are in flight. + */ +int iscsi_queue_length(struct iscsi_context *iscsi); diff --git a/lib/socket.c b/lib/socket.c index e6df382..4ed6e97 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -188,6 +188,25 @@ iscsi_which_events(struct iscsi_context *iscsi) return events; } +int +iscsi_queue_length(struct iscsi_context *iscsi) +{ + int i = 0; + struct iscsi_pdu *pdu; + + for (pdu = iscsi->outqueue; pdu; pdu = pdu->next) { + i++; + } + for (pdu = iscsi->waitpdu; pdu; pdu = pdu->next) { + i++; + } + if (iscsi->is_connected == 0) { + i++; + } + + return i; +} + static int iscsi_read_from_socket(struct iscsi_context *iscsi) {