From: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Date: Thu, 3 Nov 2016 11:10:52 +0000
CA-227162: Enable tapdisk forced shutdown mode

tap-ctl close accepts a force flag but it is not considered
by tapdisk while closing the image. With this change, tapdisk
will ignore pending I/Os on dead rings when asked to close an
image in "force shutdown" mode

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Marcus Granado <marcus.granado@citrix.com>

diff --git a/drivers/tapdisk-control.c b/drivers/tapdisk-control.c
index e5e7efd..c90d1e5 100644
--- a/drivers/tapdisk-control.c
+++ b/drivers/tapdisk-control.c
@@ -858,13 +858,19 @@ tapdisk_control_close_image(struct tapdisk_ctl_conn *conn,
     if (unlikely(err))
         goto out;
 
-    /*
-     * Wait for requests against dead rings to complete, otherwise, if we
-     * proceed with tearing down the VBD, we will free memory that will later
-     * be accessed by these requests, and this will lead to a crash.
-     */
-    while (unlikely(tapdisk_vbd_contains_dead_rings(vbd)))
+    if(request->type != TAPDISK_MESSAGE_FORCE_SHUTDOWN) {
+
+        /*
+         * Wait for requests against dead rings to complete, otherwise, if we
+         * proceed with tearing down the VBD, we will free memory that will later
+         * be accessed by these requests, and this will lead to a crash.
+         */
+        while (unlikely(tapdisk_vbd_contains_dead_rings(vbd)))
             tapdisk_server_iterate();
+    }
+    else {
+        DPRINTF("Ignoring dead rings in forced shutdown mode\n");
+    }
 
 	if (!err) {
 		do {
@@ -1253,6 +1259,10 @@ struct tapdisk_control_info message_infos[] = {
 		.handler = tapdisk_control_close_image,
 		.flags   = TAPDISK_MSG_VERBOSE,
 	},
+	[TAPDISK_MESSAGE_FORCE_SHUTDOWN] = {
+		.handler = tapdisk_control_close_image,
+		.flags   = TAPDISK_MSG_VERBOSE,
+	},
 	[TAPDISK_MESSAGE_STATS] = {
 		.handler = tapdisk_control_stats,
 		.flags   = TAPDISK_MSG_REENTER,
