[Libguestfs] [PATCH libnbd v2 5/6] api: Add nbd_aio_is_processing to test if a connection is processing.

Richard W.M. Jones rjones at redhat.com
Wed May 22 09:50:18 UTC 2019


---
 generator/generator | 14 ++++++++++++++
 lib/aio.c           | 22 ++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/generator/generator b/generator/generator
index d31f060..60dfb72 100755
--- a/generator/generator
+++ b/generator/generator
@@ -1578,6 +1578,20 @@ waiting for a reply.  In this state the handle is ready to
 issue commands.";
   };
 
+  "aio_is_processing", {
+    default_call with
+    args = []; ret = RBool;
+    shortdesc = "check if the connection is processing a command";
+    longdesc = "\
+Return true if this connection is connected to the NBD server,
+the handshake has completed, and the connection is processing
+commands (either writing out a request or reading a reply).
+
+Note the ready state (C<nbd_aio_is_ready>) is not included.
+In the ready state commands may be I<in flight> (the I<server>
+is processing them), but libnbd is not processing them.";
+  };
+
   "aio_is_dead", {
     default_call with
     args = []; ret = RBool;
diff --git a/lib/aio.c b/lib/aio.c
index 1152c9e..c7764f8 100644
--- a/lib/aio.c
+++ b/lib/aio.c
@@ -85,6 +85,28 @@ nbd_unlocked_aio_is_ready (struct nbd_connection *conn)
   return conn->state == STATE_READY;
 }
 
+static int
+is_processing_group (enum state_group group)
+{
+  switch (group) {
+  case GROUP_TOP:
+    return 0;
+  case GROUP_ISSUE_COMMAND:
+  case GROUP_REPLY:
+    return 1;
+  default:
+    return is_processing_group (nbd_internal_state_group_parent (group));
+  }
+}
+
+int
+nbd_unlocked_aio_is_processing (struct nbd_connection *conn)
+{
+  enum state_group group = nbd_internal_state_group (conn->state);
+
+  return is_processing_group (group);
+}
+
 int
 nbd_unlocked_aio_is_dead (struct nbd_connection *conn)
 {
-- 
2.21.0




More information about the Libguestfs mailing list