]> xenbits.xensource.com Git - legacy/linux-2.6.18-xen.git/commitdiff
blkback/blktap: Check for kthread_should_stop() in inner loop,
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 21 Jan 2008 11:43:31 +0000 (11:43 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 21 Jan 2008 11:43:31 +0000 (11:43 +0000)
mdelaay() should be msleep(), and these changes belong in blktap as
well as blkback.
Based on comments and patches from Jan Beulich and Steven Smith.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
drivers/xen/blkback/blkback.c
drivers/xen/blktap/blktap.c

index 000cb1acd7cca9aba7c5516c5310dcadd563fcad..7e704256297f750933b583a1ee5bbd6f6ba93ddc 100644 (file)
@@ -312,7 +312,7 @@ static int do_block_io_op(blkif_t *blkif)
        rp = blk_rings->common.sring->req_prod;
        rmb(); /* Ensure we see queued requests up to 'rp'. */
 
-       while ((rc != rp)) {
+       while (rc != rp) {
 
                if (RING_REQUEST_CONS_OVERFLOW(&blk_rings->common, rc))
                        break;
@@ -324,6 +324,11 @@ static int do_block_io_op(blkif_t *blkif)
                        break;
                }
 
+               if (kthread_should_stop()) {
+                       more_to_do = 1;
+                       break;
+               }
+
                switch (blkif->blk_protocol) {
                case BLKIF_PROTOCOL_NATIVE:
                        memcpy(&req, RING_GET_REQUEST(&blk_rings->native, rc), sizeof(req));
@@ -354,7 +359,7 @@ static int do_block_io_op(blkif_t *blkif)
                default:
                        /* A good sign something is wrong: sleep for a while to
                         * avoid excessive CPU consumption by a bad guest. */
-                       mdelay(1);
+                       msleep(1);
                        DPRINTK("error: unknown block io operation [%d]\n",
                                req.operation);
                        make_response(blkif, req.id, req.operation,
@@ -517,6 +522,7 @@ static void dispatch_rw_block_io(blkif_t *blkif,
  fail_response:
        make_response(blkif, req->id, req->operation, BLKIF_RSP_ERROR);
        free_req(pending_req);
+       msleep(1); /* back off a bit */
 } 
 
 
index d618aa41f51d98152ef4eff5a69ab1aacd04912e..de8b78803a878e4b66f3afcc1f40eec8639a2248 100644 (file)
@@ -52,6 +52,7 @@
 #include <linux/major.h>
 #include <linux/gfp.h>
 #include <linux/poll.h>
+#include <linux/delay.h>
 #include <asm/tlbflush.h>
 
 #define MAX_TAP_DEV 256     /*the maximum number of tapdisk ring devices    */
@@ -1242,6 +1243,11 @@ static int do_block_io_op(blkif_t *blkif)
                        break;
                }
 
+               if (kthread_should_stop()) {
+                       more_to_do = 1;
+                       break;
+               }
+
                switch (blkif->blk_protocol) {
                case BLKIF_PROTOCOL_NATIVE:
                        memcpy(&req, RING_GET_REQUEST(&blk_rings->native, rc),
@@ -1270,6 +1276,9 @@ static int do_block_io_op(blkif_t *blkif)
                        break;
 
                default:
+                       /* A good sign something is wrong: sleep for a while to
+                        * avoid excessive CPU consumption by a bad guest. */
+                       msleep(1);
                        WPRINTK("unknown operation [%d]\n",
                                req.operation);
                        make_response(blkif, req.id, req.operation,
@@ -1277,6 +1286,9 @@ static int do_block_io_op(blkif_t *blkif)
                        free_req(pending_req);
                        break;
                }
+
+               /* Yield point for this unbounded loop. */
+               cond_resched();
        }
                
        blktap_kick_user(blkif->dev_num);
@@ -1503,7 +1515,8 @@ static void dispatch_rw_block_io(blkif_t *blkif,
  fail_response:
        make_response(blkif, req->id, req->operation, BLKIF_RSP_ERROR);
        free_req(pending_req);
-} 
+       msleep(1); /* back off a bit */
+}