[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [linux-2.6.18-xen] blkback/blktap: Check for kthread_should_stop() in inner loop,



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1200915811 0
# Node ID 7070d34f251c3e0c411022a5d365aea9804114a7
# Parent  77f831cbb91ddca3a7539fa9197d4abc2d2bfcf9
blkback/blktap: Check for kthread_should_stop() in inner loop,
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@xxxxxxxxxx>
---
 drivers/xen/blkback/blkback.c |   10 ++++++++--
 drivers/xen/blktap/blktap.c   |   15 ++++++++++++++-
 2 files changed, 22 insertions(+), 3 deletions(-)

diff -r 77f831cbb91d -r 7070d34f251c drivers/xen/blkback/blkback.c
--- a/drivers/xen/blkback/blkback.c     Fri Jan 18 16:52:25 2008 +0000
+++ b/drivers/xen/blkback/blkback.c     Mon Jan 21 11:43:31 2008 +0000
@@ -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;
@@ -320,6 +320,11 @@ static int do_block_io_op(blkif_t *blkif
                pending_req = alloc_req();
                if (NULL == pending_req) {
                        blkif->st_oo_req++;
+                       more_to_do = 1;
+                       break;
+               }
+
+               if (kthread_should_stop()) {
                        more_to_do = 1;
                        break;
                }
@@ -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
  fail_response:
        make_response(blkif, req->id, req->operation, BLKIF_RSP_ERROR);
        free_req(pending_req);
+       msleep(1); /* back off a bit */
 } 
 
 
diff -r 77f831cbb91d -r 7070d34f251c drivers/xen/blktap/blktap.c
--- a/drivers/xen/blktap/blktap.c       Fri Jan 18 16:52:25 2008 +0000
+++ b/drivers/xen/blktap/blktap.c       Mon Jan 21 11:43:31 2008 +0000
@@ -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
  fail_response:
        make_response(blkif, req->id, req->operation, BLKIF_RSP_ERROR);
        free_req(pending_req);
-} 
+       msleep(1); /* back off a bit */
+}
 
 
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.