From 33659ebbae262228eef4e0fe990f393d1f0ed941 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 7 Aug 2010 18:17:56 +0200 Subject: block: remove wrappers for request type/flags Remove all the trivial wrappers for the cmd_type and cmd_flags fields in struct requests. This allows much easier grepping for different request types instead of unwinding through macros. Signed-off-by: Christoph Hellwig Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 82ed403..495533e 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -238,7 +238,7 @@ static int blkif_queue_request(struct request *req) ring_req->operation = rq_data_dir(req) ? BLKIF_OP_WRITE : BLKIF_OP_READ; - if (blk_barrier_rq(req)) + if (req->cmd_flags & REQ_HARDBARRIER) ring_req->operation = BLKIF_OP_WRITE_BARRIER; ring_req->nr_segments = blk_rq_map_sg(req->q, req, info->sg); @@ -309,7 +309,7 @@ static void do_blkif_request(struct request_queue *rq) blk_start_request(req); - if (!blk_fs_request(req)) { + if (req->cmd_type != REQ_TYPE_FS) { __blk_end_request_all(req, -EIO); continue; } -- cgit v1.1 From 00fff26539bfe3fad21c164fc4002d9ede056fb0 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Sat, 3 Jul 2010 17:45:40 +0900 Subject: block: remove q->prepare_flush_fn completely This removes q->prepare_flush_fn completely (changes the blk_queue_ordered API). Signed-off-by: FUJITA Tomonori Reviewed-by: Christoph Hellwig Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 495533e..76af65b 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -373,8 +373,7 @@ static int xlvbd_barrier(struct blkfront_info *info) int err; err = blk_queue_ordered(info->rq, - info->feature_barrier ? QUEUE_ORDERED_DRAIN : QUEUE_ORDERED_NONE, - NULL); + info->feature_barrier ? QUEUE_ORDERED_DRAIN : QUEUE_ORDERED_NONE); if (err) return err; -- cgit v1.1 From 8a6cfeb6deca3a8fefd639d898b0d163c0b5d368 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Thu, 8 Jul 2010 10:18:46 +0200 Subject: block: push down BKL into .locked_ioctl As a preparation for the removal of the big kernel lock in the block layer, this removes the BKL from the common ioctl handling code, moving it into every single driver still using it. Signed-off-by: Arnd Bergmann Acked-by: Christoph Hellwig Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 76af65b..9119cd3 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1045,7 +1045,7 @@ static const struct block_device_operations xlvbd_block_fops = .open = blkif_open, .release = blkif_release, .getgeo = blkif_getgeo, - .locked_ioctl = blkif_ioctl, + .ioctl = blkif_ioctl, }; -- cgit v1.1 From 6e9624b8caec290d28b4c6d9ec75749df6372b87 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Sat, 7 Aug 2010 18:25:34 +0200 Subject: block: push down BKL into .open and .release The open and release block_device_operations are currently called with the BKL held. In order to change that, we must first make sure that all drivers that currently rely on this have no regressions. This blindly pushes the BKL into all .open and .release operations for all block drivers to prepare for the next step. The drivers can subsequently replace the BKL with their own locks or remove it completely when it can be shown that it is not needed. The functions blkdev_get and blkdev_put are the only remaining users of the big kernel lock in the block layer, besides a few uses in the ioctl code, none of which need to serialize with blkdev_{get,put}. Most of these two functions is also under the protection of bdev->bd_mutex, including the actual calls to ->open and ->release, and the common code does not access any global data structures that need the BKL. Signed-off-by: Arnd Bergmann Acked-by: Christoph Hellwig Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 9119cd3..9137428 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -1018,13 +1019,18 @@ static int blkfront_is_ready(struct xenbus_device *dev) static int blkif_open(struct block_device *bdev, fmode_t mode) { struct blkfront_info *info = bdev->bd_disk->private_data; + + lock_kernel(); info->users++; + unlock_kernel(); + return 0; } static int blkif_release(struct gendisk *disk, fmode_t mode) { struct blkfront_info *info = disk->private_data; + lock_kernel(); info->users--; if (info->users == 0) { /* Check whether we have been instructed to close. We will @@ -1036,6 +1042,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode) if (state == XenbusStateClosing && info->is_ready) blkfront_closing(dev); } + unlock_kernel(); return 0; } -- cgit v1.1 From 203fd61f42fec81f43bc5abbf2d3755e04e000af Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 4 Dec 2009 15:33:54 +0000 Subject: xen: use less generic names in blkfront driver. All Xen frontend drivers have a couple of identically named functions which makes figuring out which device went wrong from a stacktrace harder than it needs to be. Rename them to something specificto the device type. Signed-off-by: Ian Campbell Cc: Jeremy Fitzhardinge --- drivers/block/xen-blkfront.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 9137428..304009e 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -651,7 +651,7 @@ fail: /* Common code used when first setting up, and when resuming. */ -static int talk_to_backend(struct xenbus_device *dev, +static int talk_to_blkback(struct xenbus_device *dev, struct blkfront_info *info) { const char *message = NULL; @@ -756,7 +756,7 @@ static int blkfront_probe(struct xenbus_device *dev, info->handle = simple_strtoul(strrchr(dev->nodename, '/')+1, NULL, 0); dev_set_drvdata(&dev->dev, info); - err = talk_to_backend(dev, info); + err = talk_to_blkback(dev, info); if (err) { kfree(info); dev_set_drvdata(&dev->dev, NULL); @@ -851,7 +851,7 @@ static int blkfront_resume(struct xenbus_device *dev) blkif_free(info, info->connected == BLKIF_STATE_CONNECTED); - err = talk_to_backend(dev, info); + err = talk_to_blkback(dev, info); if (info->connected == BLKIF_STATE_SUSPENDED && !err) err = blkif_recover(info); @@ -955,13 +955,13 @@ static void blkfront_closing(struct xenbus_device *dev) /** * Callback received when the backend's state changes. */ -static void backend_changed(struct xenbus_device *dev, +static void blkback_changed(struct xenbus_device *dev, enum xenbus_state backend_state) { struct blkfront_info *info = dev_get_drvdata(&dev->dev); struct block_device *bd; - dev_dbg(&dev->dev, "blkfront:backend_changed.\n"); + dev_dbg(&dev->dev, "blkfront:blkback_changed to state %d.\n", backend_state); switch (backend_state) { case XenbusStateInitialising: @@ -1068,7 +1068,7 @@ static struct xenbus_driver blkfront = { .probe = blkfront_probe, .remove = blkfront_remove, .resume = blkfront_resume, - .otherend_changed = backend_changed, + .otherend_changed = blkback_changed, .is_ready = blkfront_is_ready, }; -- cgit v1.1 From 0e34582699392d67910bd3919bc8fd9bedce115e Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Sat, 7 Aug 2010 18:28:55 +0200 Subject: blkfront: fixes for 'xm block-detach ... --force' Prevent prematurely freeing 'struct blkfront_info' instances (when the xenbus data structures are gone, but the Linux ones are still needed). Prevent adding a disk with the same (major, minor) [and hence the same name and sysfs entries, which leads to oopses] when the previous instance wasn't fully de-allocated yet. This still doesn't address all issues resulting from forced detach: I/O submitted after the detach still blocks forever, likely preventing subsequent un-mounting from completing. It's not clear to me (not knowing much about the block layer) how this can be avoided. Signed-off-by: Jan Beulich Signed-off-by: Jeremy Fitzhardinge Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 88 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 7 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 304009e..22091e4 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -105,6 +105,10 @@ struct blkfront_info static DEFINE_SPINLOCK(blkif_io_lock); +static unsigned int nr_minors; +static unsigned long *minors; +static DEFINE_SPINLOCK(minor_lock); + #define MAXIMUM_OUTSTANDING_BLOCK_REQS \ (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLK_RING_SIZE) #define GRANT_INVALID_REF 0 @@ -139,6 +143,55 @@ static void add_id_to_freelist(struct blkfront_info *info, info->shadow_free = id; } +static int xlbd_reserve_minors(unsigned int minor, unsigned int nr) +{ + unsigned int end = minor + nr; + int rc; + + if (end > nr_minors) { + unsigned long *bitmap, *old; + + bitmap = kzalloc(BITS_TO_LONGS(end) * sizeof(*bitmap), + GFP_KERNEL); + if (bitmap == NULL) + return -ENOMEM; + + spin_lock(&minor_lock); + if (end > nr_minors) { + old = minors; + memcpy(bitmap, minors, + BITS_TO_LONGS(nr_minors) * sizeof(*bitmap)); + minors = bitmap; + nr_minors = BITS_TO_LONGS(end) * BITS_PER_LONG; + } else + old = bitmap; + spin_unlock(&minor_lock); + kfree(old); + } + + spin_lock(&minor_lock); + if (find_next_bit(minors, end, minor) >= end) { + for (; minor < end; ++minor) + __set_bit(minor, minors); + rc = 0; + } else + rc = -EBUSY; + spin_unlock(&minor_lock); + + return rc; +} + +static void xlbd_release_minors(unsigned int minor, unsigned int nr) +{ + unsigned int end = minor + nr; + + BUG_ON(end > nr_minors); + spin_lock(&minor_lock); + for (; minor < end; ++minor) + __clear_bit(minor, minors); + spin_unlock(&minor_lock); +} + static void blkif_restart_queue_callback(void *arg) { struct blkfront_info *info = (struct blkfront_info *)arg; @@ -417,9 +470,14 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, if ((minor % nr_parts) == 0) nr_minors = nr_parts; + err = xlbd_reserve_minors(minor, nr_minors); + if (err) + goto out; + err = -ENODEV; + gd = alloc_disk(nr_minors); if (gd == NULL) - goto out; + goto release; offset = minor / nr_parts; @@ -450,7 +508,7 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, if (xlvbd_init_blk_queue(gd, sector_size)) { del_gendisk(gd); - goto out; + goto release; } info->rq = gd->queue; @@ -470,6 +528,8 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, return 0; + release: + xlbd_release_minors(minor, nr_minors); out: return err; } @@ -924,6 +984,7 @@ static void blkfront_connect(struct blkfront_info *info) static void blkfront_closing(struct xenbus_device *dev) { struct blkfront_info *info = dev_get_drvdata(&dev->dev); + unsigned int minor, nr_minors; unsigned long flags; dev_dbg(&dev->dev, "blkfront_closing: %s removed\n", dev->nodename); @@ -946,7 +1007,10 @@ static void blkfront_closing(struct xenbus_device *dev) blk_cleanup_queue(info->rq); info->rq = NULL; + minor = info->gd->first_minor; + nr_minors = info->gd->minors; del_gendisk(info->gd); + xlbd_release_minors(minor, nr_minors); out: xenbus_frontend_closed(dev); @@ -1004,7 +1068,10 @@ static int blkfront_remove(struct xenbus_device *dev) blkif_free(info, 0); - kfree(info); + if(info->users == 0) + kfree(info); + else + info->is_ready = -1; return 0; } @@ -1013,18 +1080,22 @@ static int blkfront_is_ready(struct xenbus_device *dev) { struct blkfront_info *info = dev_get_drvdata(&dev->dev); - return info->is_ready; + return info->is_ready > 0; } static int blkif_open(struct block_device *bdev, fmode_t mode) { struct blkfront_info *info = bdev->bd_disk->private_data; + int ret = 0; lock_kernel(); - info->users++; + if (info->is_ready < 0) + ret = -ENODEV; + else + info->users++; unlock_kernel(); - return 0; + return ret; } static int blkif_release(struct gendisk *disk, fmode_t mode) @@ -1039,7 +1110,10 @@ static int blkif_release(struct gendisk *disk, fmode_t mode) struct xenbus_device *dev = info->xbdev; enum xenbus_state state = xenbus_read_driver_state(dev->otherend); - if (state == XenbusStateClosing && info->is_ready) + if(info->is_ready < 0) { + blkfront_closing(dev); + kfree(info); + } else if (state == XenbusStateClosing && info->is_ready) blkfront_closing(dev); } unlock_kernel(); -- cgit v1.1 From 5d7ed20e822ef82117a4d9928b030fa0247b789d Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Sat, 7 Aug 2010 18:31:12 +0200 Subject: blkfront: don't access freed struct xenbus_device Unfortunately commit "blkfront: fixes for 'xm block-detach ... --force'" still wasn't quite right - there was a reference to freed memory left from blkfront_closing(). Signed-off-by: Jan Beulich Signed-off-by: Jeremy Fitzhardinge Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 22091e4..60006b7 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -981,13 +981,11 @@ static void blkfront_connect(struct blkfront_info *info) * the backend. Once is this done, we can switch to Closed in * acknowledgement. */ -static void blkfront_closing(struct xenbus_device *dev) +static void blkfront_closing(struct blkfront_info *info) { - struct blkfront_info *info = dev_get_drvdata(&dev->dev); unsigned int minor, nr_minors; unsigned long flags; - dev_dbg(&dev->dev, "blkfront_closing: %s removed\n", dev->nodename); if (info->rq == NULL) goto out; @@ -1013,7 +1011,8 @@ static void blkfront_closing(struct xenbus_device *dev) xlbd_release_minors(minor, nr_minors); out: - xenbus_frontend_closed(dev); + if (info->xbdev) + xenbus_frontend_closed(info->xbdev); } /** @@ -1053,7 +1052,7 @@ static void blkback_changed(struct xenbus_device *dev, xenbus_dev_error(dev, -EBUSY, "Device in use; refusing to close"); else - blkfront_closing(dev); + blkfront_closing(info); mutex_unlock(&bd->bd_mutex); bdput(bd); break; @@ -1071,7 +1070,7 @@ static int blkfront_remove(struct xenbus_device *dev) if(info->users == 0) kfree(info); else - info->is_ready = -1; + info->xbdev = NULL; return 0; } @@ -1080,22 +1079,21 @@ static int blkfront_is_ready(struct xenbus_device *dev) { struct blkfront_info *info = dev_get_drvdata(&dev->dev); - return info->is_ready > 0; + return info->is_ready && info->xbdev; } static int blkif_open(struct block_device *bdev, fmode_t mode) { struct blkfront_info *info = bdev->bd_disk->private_data; - int ret = 0; + + if (!info->xbdev) + return -ENODEV; lock_kernel(); - if (info->is_ready < 0) - ret = -ENODEV; - else - info->users++; + info->users++; unlock_kernel(); - return ret; + return 0; } static int blkif_release(struct gendisk *disk, fmode_t mode) @@ -1108,13 +1106,13 @@ static int blkif_release(struct gendisk *disk, fmode_t mode) have ignored this request initially, as the device was still mounted. */ struct xenbus_device *dev = info->xbdev; - enum xenbus_state state = xenbus_read_driver_state(dev->otherend); - if(info->is_ready < 0) { - blkfront_closing(dev); + if (!dev) { + blkfront_closing(info); kfree(info); - } else if (state == XenbusStateClosing && info->is_ready) - blkfront_closing(dev); + } else if (xenbus_read_driver_state(dev->otherend) + == XenbusStateClosing && info->is_ready) + blkfront_closing(info); } unlock_kernel(); return 0; -- cgit v1.1 From 1fa73be6be65028a7543bba8f14474b42e064a1b Mon Sep 17 00:00:00 2001 From: "K. Y. Srinivasan" Date: Thu, 11 Mar 2010 13:42:26 -0800 Subject: xen/front: Propagate changed size of VBDs Support dynamic resizing of virtual block devices. This patch supports both file backed block devices as well as physical devices that can be dynamically resized on the host side. Signed-off-by: K. Y. Srinivasan Signed-off-by: Jeremy Fitzhardinge --- drivers/block/xen-blkfront.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 60006b7..f47b096 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -930,9 +930,24 @@ static void blkfront_connect(struct blkfront_info *info) unsigned int binfo; int err; - if ((info->connected == BLKIF_STATE_CONNECTED) || - (info->connected == BLKIF_STATE_SUSPENDED) ) + switch (info->connected) { + case BLKIF_STATE_CONNECTED: + /* + * Potentially, the back-end may be signalling + * a capacity change; update the capacity. + */ + err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, + "sectors", "%Lu", §ors); + if (XENBUS_EXIST_ERR(err)) + return; + printk(KERN_INFO "Setting capacity to %Lu\n", + sectors); + set_capacity(info->gd, sectors); + + /* fall through */ + case BLKIF_STATE_SUSPENDED: return; + } dev_dbg(&info->xbdev->dev, "%s:%s.\n", __func__, info->xbdev->otherend); -- cgit v1.1 From b4dddb498c0feaff413b2a79c64e910021983775 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Thu, 11 Mar 2010 15:10:40 -0800 Subject: xen/blkfront: avoid compiler warning from missing cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix: drivers/block/xen-blkfront.c: In function ‘blkfront_connect’: drivers/block/xen-blkfront.c:933: warning: enumeration value ‘BLKIF_STATE_DISCONNECTED’ not handled in switch Signed-off-by: Jeremy Fitzhardinge --- drivers/block/xen-blkfront.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index f47b096..9b44022 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -947,6 +947,9 @@ static void blkfront_connect(struct blkfront_info *info) /* fall through */ case BLKIF_STATE_SUSPENDED: return; + + default: + break; } dev_dbg(&info->xbdev->dev, "%s:%s.\n", -- cgit v1.1 From 2def141e71d54eccac98dc2c2ba71a82c91b324e Mon Sep 17 00:00:00 2001 From: "K. Y. Srinivasan" Date: Thu, 18 Mar 2010 15:00:54 -0700 Subject: xen/blkfront: revalidate after setting capacity Signed-off-by: K. Y. Srinivasan Signed-off-by: Jeremy Fitzhardinge --- drivers/block/xen-blkfront.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 9b44022..7fa2a1d 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -943,6 +943,7 @@ static void blkfront_connect(struct blkfront_info *info) printk(KERN_INFO "Setting capacity to %Lu\n", sectors); set_capacity(info->gd, sectors); + revalidate_disk(info->gd); /* fall through */ case BLKIF_STATE_SUSPENDED: -- cgit v1.1 From 89de1669ace055b56f1de1c9f5aca26dd7f17f25 Mon Sep 17 00:00:00 2001 From: Daniel Stodden Date: Fri, 30 Apr 2010 22:01:16 +0000 Subject: blkfront: Fix backtrace in del_gendisk The call to del_gendisk follows an non-refcounted gd->queue pointer. We release the last ref in blk_cleanup_queue. Fixed by reordering releases accordingly. Signed-off-by: Daniel Stodden Signed-off-by: Jeremy Fitzhardinge --- drivers/block/xen-blkfront.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 7fa2a1d..3258ae6 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1021,14 +1021,14 @@ static void blkfront_closing(struct blkfront_info *info) /* Flush gnttab callback work. Must be done with no locks held. */ flush_scheduled_work(); - blk_cleanup_queue(info->rq); - info->rq = NULL; - minor = info->gd->first_minor; nr_minors = info->gd->minors; del_gendisk(info->gd); xlbd_release_minors(minor, nr_minors); + blk_cleanup_queue(info->rq); + info->rq = NULL; + out: if (info->xbdev) xenbus_frontend_closed(info->xbdev); -- cgit v1.1 From 9897cb532382f075b337f7933b5a50f0ffc32d35 Mon Sep 17 00:00:00 2001 From: Daniel Stodden Date: Fri, 30 Apr 2010 22:01:17 +0000 Subject: blkfront: Fix gendisk leak Signed-off-by: Daniel Stodden Signed-off-by: Jeremy Fitzhardinge --- drivers/block/xen-blkfront.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 3258ae6..62d3295 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1029,6 +1029,9 @@ static void blkfront_closing(struct blkfront_info *info) blk_cleanup_queue(info->rq); info->rq = NULL; + put_disk(info->gd); + info->gd = NULL; + out: if (info->xbdev) xenbus_frontend_closed(info->xbdev); -- cgit v1.1 From a66b5aebb7dc9e695dcb4b528906fd398b63f3d9 Mon Sep 17 00:00:00 2001 From: Daniel Stodden Date: Sat, 7 Aug 2010 18:33:17 +0200 Subject: blkfront: Clean up vbd release * Current blkfront_closing is rather a xlvbd_release_gendisk. Renamed in preparation of later patches (need the name again). * Removed the misleading comment -- this only applied to the backend switch handler, and the queue is already flushed btw. * Break out the xenbus call, callers know better when to switch frontend state. Signed-off-by: Daniel Stodden Signed-off-by: Jeremy Fitzhardinge Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 91 +++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 48 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 62d3295..d4cb7fd 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -534,6 +534,39 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, return err; } +static void xlvbd_release_gendisk(struct blkfront_info *info) +{ + unsigned int minor, nr_minors; + unsigned long flags; + + if (info->rq == NULL) + return; + + spin_lock_irqsave(&blkif_io_lock, flags); + + /* No more blkif_request(). */ + blk_stop_queue(info->rq); + + /* No more gnttab callback work. */ + gnttab_cancel_free_callback(&info->callback); + spin_unlock_irqrestore(&blkif_io_lock, flags); + + /* Flush gnttab callback work. Must be done with no locks held. */ + flush_scheduled_work(); + + del_gendisk(info->gd); + + minor = info->gd->first_minor; + nr_minors = info->gd->minors; + xlbd_release_minors(minor, nr_minors); + + blk_cleanup_queue(info->rq); + info->rq = NULL; + + put_disk(info->gd); + info->gd = NULL; +} + static void kick_pending_request_queues(struct blkfront_info *info) { if (!RING_FULL(&info->ring)) { @@ -995,49 +1028,6 @@ static void blkfront_connect(struct blkfront_info *info) } /** - * Handle the change of state of the backend to Closing. We must delete our - * device-layer structures now, to ensure that writes are flushed through to - * the backend. Once is this done, we can switch to Closed in - * acknowledgement. - */ -static void blkfront_closing(struct blkfront_info *info) -{ - unsigned int minor, nr_minors; - unsigned long flags; - - - if (info->rq == NULL) - goto out; - - spin_lock_irqsave(&blkif_io_lock, flags); - - /* No more blkif_request(). */ - blk_stop_queue(info->rq); - - /* No more gnttab callback work. */ - gnttab_cancel_free_callback(&info->callback); - spin_unlock_irqrestore(&blkif_io_lock, flags); - - /* Flush gnttab callback work. Must be done with no locks held. */ - flush_scheduled_work(); - - minor = info->gd->first_minor; - nr_minors = info->gd->minors; - del_gendisk(info->gd); - xlbd_release_minors(minor, nr_minors); - - blk_cleanup_queue(info->rq); - info->rq = NULL; - - put_disk(info->gd); - info->gd = NULL; - - out: - if (info->xbdev) - xenbus_frontend_closed(info->xbdev); -} - -/** * Callback received when the backend's state changes. */ static void blkback_changed(struct xenbus_device *dev, @@ -1073,8 +1063,11 @@ static void blkback_changed(struct xenbus_device *dev, if (info->users > 0) xenbus_dev_error(dev, -EBUSY, "Device in use; refusing to close"); - else - blkfront_closing(info); + else { + xlvbd_release_gendisk(info); + xenbus_frontend_closed(info->xbdev); + } + mutex_unlock(&bd->bd_mutex); bdput(bd); break; @@ -1130,11 +1123,13 @@ static int blkif_release(struct gendisk *disk, fmode_t mode) struct xenbus_device *dev = info->xbdev; if (!dev) { - blkfront_closing(info); + xlvbd_release_gendisk(info); kfree(info); } else if (xenbus_read_driver_state(dev->otherend) - == XenbusStateClosing && info->is_ready) - blkfront_closing(info); + == XenbusStateClosing && info->is_ready) { + xlvbd_release_gendisk(info); + xenbus_frontend_closed(dev); + } } unlock_kernel(); return 0; -- cgit v1.1 From b70f5fa043b318659c936d8c3c696250e6528944 Mon Sep 17 00:00:00 2001 From: Daniel Stodden Date: Fri, 30 Apr 2010 22:01:19 +0000 Subject: blkfront: Lock blkfront_info when closing The bdev .open/.release fops race against backend switches to Closing, handled by the XenBus thread. The original code attempted to serialize block device holders and xenbus only via bd_mutex. This is insufficient, the info->bd pointer may already be stale (or null) while xenbus tries to bump up the refcount. Protect blkfront_info with a dedicated mutex. Signed-off-by: Daniel Stodden Signed-off-by: Jeremy Fitzhardinge --- drivers/block/xen-blkfront.c | 61 +++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 21 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index d4cb7fd..1e406f0 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -79,6 +79,7 @@ static const struct block_device_operations xlvbd_block_fops; */ struct blkfront_info { + struct mutex mutex; struct xenbus_device *xbdev; struct gendisk *gd; int vdevice; @@ -804,7 +805,6 @@ again: return err; } - /** * Entry point to this code when a new device is created. Allocate the basic * structures and the ring buffer for communication with the backend, and @@ -836,6 +836,7 @@ static int blkfront_probe(struct xenbus_device *dev, return -ENOMEM; } + mutex_init(&info->mutex); info->xbdev = dev; info->vdevice = vdevice; info->connected = BLKIF_STATE_DISCONNECTED; @@ -951,6 +952,43 @@ static int blkfront_resume(struct xenbus_device *dev) return err; } +static void +blkfront_closing(struct blkfront_info *info) +{ + struct xenbus_device *xbdev = info->xbdev; + struct block_device *bdev = NULL; + + mutex_lock(&info->mutex); + + if (xbdev->state == XenbusStateClosing) { + mutex_unlock(&info->mutex); + return; + } + + if (info->gd) + bdev = bdget_disk(info->gd, 0); + + mutex_unlock(&info->mutex); + + if (!bdev) { + xenbus_frontend_closed(xbdev); + return; + } + + mutex_lock(&bdev->bd_mutex); + + if (info->users) { + xenbus_dev_error(xbdev, -EBUSY, + "Device in use; refusing to close"); + xenbus_switch_state(xbdev, XenbusStateClosing); + } else { + xlvbd_release_gendisk(info); + xenbus_frontend_closed(xbdev); + } + + mutex_unlock(&bdev->bd_mutex); + bdput(bdev); +} /* * Invoked when the backend is finally 'ready' (and has told produced @@ -1034,7 +1072,6 @@ static void blkback_changed(struct xenbus_device *dev, enum xenbus_state backend_state) { struct blkfront_info *info = dev_get_drvdata(&dev->dev); - struct block_device *bd; dev_dbg(&dev->dev, "blkfront:blkback_changed to state %d.\n", backend_state); @@ -1051,25 +1088,7 @@ static void blkback_changed(struct xenbus_device *dev, break; case XenbusStateClosing: - if (info->gd == NULL) { - xenbus_frontend_closed(dev); - break; - } - bd = bdget_disk(info->gd, 0); - if (bd == NULL) - xenbus_dev_fatal(dev, -ENODEV, "bdget failed"); - - mutex_lock(&bd->bd_mutex); - if (info->users > 0) - xenbus_dev_error(dev, -EBUSY, - "Device in use; refusing to close"); - else { - xlvbd_release_gendisk(info); - xenbus_frontend_closed(info->xbdev); - } - - mutex_unlock(&bd->bd_mutex); - bdput(bd); + blkfront_closing(info); break; } } -- cgit v1.1 From 139617437aff1f0d3b57c2d7cc60e60efc8fe6c3 Mon Sep 17 00:00:00 2001 From: Daniel Stodden Date: Sat, 7 Aug 2010 18:36:53 +0200 Subject: blkfront: Fix blkfront backend switch race (bdev open) We need not mind if users grab a late handle on a closing disk. We probably even should not. But we have to make sure it's not a dead one already Let the bdev deal with a gendisk deleted under its feet. Takes the info mutex to decide a race against backend closing. Signed-off-by: Daniel Stodden Signed-off-by: Jeremy Fitzhardinge Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 1e406f0..763a315 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1118,16 +1118,33 @@ static int blkfront_is_ready(struct xenbus_device *dev) static int blkif_open(struct block_device *bdev, fmode_t mode) { - struct blkfront_info *info = bdev->bd_disk->private_data; - - if (!info->xbdev) - return -ENODEV; + struct gendisk *disk = bdev->bd_disk; + struct blkfront_info *info; + int err = 0; lock_kernel(); - info->users++; - unlock_kernel(); - return 0; + info = disk->private_data; + if (!info) { + /* xbdev gone */ + err = -ERESTARTSYS; + goto out; + } + + mutex_lock(&info->mutex); + + if (!info->gd) + /* xbdev is closed */ + err = -ERESTARTSYS; + + mutex_unlock(&info->mutex); + + if (!err) + ++info->users; + + unlock_kernel(); +out: + return err; } static int blkif_release(struct gendisk *disk, fmode_t mode) -- cgit v1.1 From 7fd152f4b6ae4f3cf89e4b7a0383cc3c470772fc Mon Sep 17 00:00:00 2001 From: Daniel Stodden Date: Sat, 7 Aug 2010 18:45:12 +0200 Subject: blkfront: Fix blkfront backend switch race (bdev release) We cannot read backend state within bdev operations, because it risks grabbing the state change before xenbus gets to do it. Fixed by tracking deferral with a frontend switch to Closing. State exposure isn't strictly necessary, but the backends won't mind. For a 'clean' deferral this seems actually a more decent protocol than raising errors. Signed-off-by: Daniel Stodden Signed-off-by: Jeremy Fitzhardinge Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 49 +++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 763a315..4986299 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1142,31 +1142,48 @@ static int blkif_open(struct block_device *bdev, fmode_t mode) if (!err) ++info->users; - unlock_kernel(); out: + unlock_kernel(); return err; } static int blkif_release(struct gendisk *disk, fmode_t mode) { struct blkfront_info *info = disk->private_data; + struct block_device *bdev; + struct xenbus_device *xbdev; + lock_kernel(); - info->users--; - if (info->users == 0) { - /* Check whether we have been instructed to close. We will - have ignored this request initially, as the device was - still mounted. */ - struct xenbus_device *dev = info->xbdev; - - if (!dev) { - xlvbd_release_gendisk(info); - kfree(info); - } else if (xenbus_read_driver_state(dev->otherend) - == XenbusStateClosing && info->is_ready) { - xlvbd_release_gendisk(info); - xenbus_frontend_closed(dev); - } + if (--info->users) + goto out; + + bdev = bdget_disk(disk, 0); + bdput(bdev); + + /* + * Check if we have been instructed to close. We will have + * deferred this request, because the bdev was still open. + */ + + mutex_lock(&info->mutex); + xbdev = info->xbdev; + + if (xbdev && xbdev->state == XenbusStateClosing) { + /* pending switch to state closed */ + xlvbd_release_gendisk(info); + xenbus_frontend_closed(info->xbdev); + } + + mutex_unlock(&info->mutex); + + if (!xbdev) { + /* sudden device removal */ + xlvbd_release_gendisk(info); + disk->private_data = NULL; + kfree(info); } + +out: unlock_kernel(); return 0; } -- cgit v1.1 From fa1bd3591a669b92b635dbdb11d1a32a5630821b Mon Sep 17 00:00:00 2001 From: Daniel Stodden Date: Fri, 30 Apr 2010 22:01:22 +0000 Subject: blkfront: Lock blockfront_info during xbdev removal Same approach as blkfront_closing: * Grab the bdev safely, holding the info mutex. * Zap xbdev safely, holding the info mutex. * Try bdev removal safely, holding bd_mutex. Signed-off-by: Daniel Stodden Signed-off-by: Jeremy Fitzhardinge --- drivers/block/xen-blkfront.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 4986299..715de7d 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1093,18 +1093,47 @@ static void blkback_changed(struct xenbus_device *dev, } } -static int blkfront_remove(struct xenbus_device *dev) +static int blkfront_remove(struct xenbus_device *xbdev) { - struct blkfront_info *info = dev_get_drvdata(&dev->dev); + struct blkfront_info *info = dev_get_drvdata(&xbdev->dev); + struct block_device *bdev = NULL; + struct gendisk *disk; - dev_dbg(&dev->dev, "blkfront_remove: %s removed\n", dev->nodename); + dev_dbg(&xbdev->dev, "%s removed", xbdev->nodename); blkif_free(info, 0); - if(info->users == 0) + mutex_lock(&info->mutex); + + disk = info->gd; + if (disk) + bdev = bdget_disk(disk, 0); + + info->xbdev = NULL; + mutex_unlock(&info->mutex); + + if (!bdev) { + kfree(info); + return 0; + } + + /* + * The xbdev was removed before we reached the Closed + * state. See if it's safe to remove the disk. If the bdev + * isn't closed yet, we let release take care of it. + */ + + mutex_lock(&bdev->bd_mutex); + info = disk->private_data; + + if (info && !info->users) { + xlvbd_release_gendisk(info); + disk->private_data = NULL; kfree(info); - else - info->xbdev = NULL; + } + + mutex_unlock(&bdev->bd_mutex); + bdput(bdev); return 0; } -- cgit v1.1 From acfca3c622a009fb62b566604452ab9fb3a11019 Mon Sep 17 00:00:00 2001 From: Daniel Stodden Date: Sat, 7 Aug 2010 18:47:26 +0200 Subject: blkfront: Remove obsolete info->users This is just bd_openers, protected by the bd_mutex. Signed-off-by: Daniel Stodden Signed-off-by: Jeremy Fitzhardinge Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 715de7d..9c5a25a 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1168,9 +1168,6 @@ static int blkif_open(struct block_device *bdev, fmode_t mode) mutex_unlock(&info->mutex); - if (!err) - ++info->users; - out: unlock_kernel(); return err; @@ -1183,12 +1180,13 @@ static int blkif_release(struct gendisk *disk, fmode_t mode) struct xenbus_device *xbdev; lock_kernel(); - if (--info->users) - goto out; bdev = bdget_disk(disk, 0); bdput(bdev); + if (bdev->bd_openers) + goto out; + /* * Check if we have been instructed to close. We will have * deferred this request, because the bdev was still open. @@ -1212,7 +1210,6 @@ static int blkif_release(struct gendisk *disk, fmode_t mode) kfree(info); } -out: unlock_kernel(); return 0; } -- cgit v1.1 From 7b32d1044ae791a1e53a53023bf2668438d5301b Mon Sep 17 00:00:00 2001 From: Daniel Stodden Date: Fri, 30 Apr 2010 22:01:23 +0000 Subject: blkfront: Remove obsolete info->users This is just bd_openers, protected by the bd_mutex. Signed-off-by: Daniel Stodden Signed-off-by: Jeremy Fitzhardinge Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 9c5a25a..b01167b 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -96,12 +96,6 @@ struct blkfront_info unsigned long shadow_free; int feature_barrier; int is_ready; - - /** - * The number of people holding this device open. We won't allow a - * hot-unplug unless this is 0. - */ - int users; }; static DEFINE_SPINLOCK(blkif_io_lock); @@ -977,7 +971,7 @@ blkfront_closing(struct blkfront_info *info) mutex_lock(&bdev->bd_mutex); - if (info->users) { + if (bdev->bd_openers) { xenbus_dev_error(xbdev, -EBUSY, "Device in use; refusing to close"); xenbus_switch_state(xbdev, XenbusStateClosing); @@ -1126,7 +1120,7 @@ static int blkfront_remove(struct xenbus_device *xbdev) mutex_lock(&bdev->bd_mutex); info = disk->private_data; - if (info && !info->users) { + if (info && !bdev->bd_openers) { xlvbd_release_gendisk(info); disk->private_data = NULL; kfree(info); -- cgit v1.1 From d54142c71f05b608b7360d80bdab74eed0f17a98 Mon Sep 17 00:00:00 2001 From: Daniel Stodden Date: Sat, 7 Aug 2010 18:51:21 +0200 Subject: blkfront: Klog the unclean release path Signed-off-by: Daniel Stodden Signed-off-by: Jeremy Fitzhardinge Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index b01167b..c6727b5 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1120,6 +1120,10 @@ static int blkfront_remove(struct xenbus_device *xbdev) mutex_lock(&bdev->bd_mutex); info = disk->private_data; + dev_warn(disk_to_dev(disk), + "%s was hot-unplugged, %d stale handles\n", + xbdev->nodename, bdev->bd_openers); + if (info && !bdev->bd_openers) { xlvbd_release_gendisk(info); disk->private_data = NULL; @@ -1191,6 +1195,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode) if (xbdev && xbdev->state == XenbusStateClosing) { /* pending switch to state closed */ + dev_info(disk_to_dev(bdev->bd_disk), "releasing disk\n"); xlvbd_release_gendisk(info); xenbus_frontend_closed(info->xbdev); } @@ -1199,6 +1204,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode) if (!xbdev) { /* sudden device removal */ + dev_info(disk_to_dev(bdev->bd_disk), "releasing disk\n"); xlvbd_release_gendisk(info); disk->private_data = NULL; kfree(info); -- cgit v1.1 From 4dab46ff26c6003a13ec769312c50938b93c359d Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Thu, 22 Jul 2010 14:17:00 -0700 Subject: xen/blkfront: use tagged queuing for barriers When barriers are supported, then use QUEUE_ORDERED_TAG to tell the block subsystem that it doesn't need to do anything else with the barriers. Previously we used ORDERED_DRAIN which caused the block subsystem to drain all pending IO before submitting the barrier, which would be very expensive. Signed-off-by: Jeremy Fitzhardinge --- drivers/block/xen-blkfront.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index c6727b5..6d912ab 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -420,9 +420,19 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size) static int xlvbd_barrier(struct blkfront_info *info) { int err; + unsigned ordered = QUEUE_ORDERED_NONE; - err = blk_queue_ordered(info->rq, - info->feature_barrier ? QUEUE_ORDERED_DRAIN : QUEUE_ORDERED_NONE); + /* + * If we don't have barrier support, then there's really no + * way to guarantee write ordering, so we really just have to + * send writes to the backend and hope for the best. If + * barriers are supported then we can treat them as proper + * ordering tags. + */ + if (info->feature_barrier) + ordered = QUEUE_ORDERED_TAG; + + err = blk_queue_ordered(info->rq, ordered); if (err) return err; @@ -509,8 +519,7 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, info->rq = gd->queue; info->gd = gd; - if (info->feature_barrier) - xlvbd_barrier(info); + xlvbd_barrier(info); if (vdisk_info & VDISK_READONLY) set_disk_ro(gd, 1); -- cgit v1.1 From 7901d14144311c930918b1222aae7611284c63eb Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Wed, 28 Jul 2010 10:49:29 -0700 Subject: xen/blkfront: Use QUEUE_ORDERED_DRAIN for old backends If there's no feature-barrier key in xenstore, then it means its a fairly old backend which does uncached in-order writes, which means ORDERED_DRAIN is appropriate. Signed-off-by: Jeremy Fitzhardinge --- drivers/block/xen-blkfront.c | 45 ++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 6d912ab..ae5f92b 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -420,26 +420,22 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size) static int xlvbd_barrier(struct blkfront_info *info) { int err; - unsigned ordered = QUEUE_ORDERED_NONE; + const char *barrier; - /* - * If we don't have barrier support, then there's really no - * way to guarantee write ordering, so we really just have to - * send writes to the backend and hope for the best. If - * barriers are supported then we can treat them as proper - * ordering tags. - */ - if (info->feature_barrier) - ordered = QUEUE_ORDERED_TAG; + switch (info->feature_barrier) { + case QUEUE_ORDERED_DRAIN: barrier = "enabled (drain)"; break; + case QUEUE_ORDERED_TAG: barrier = "enabled (tag)"; break; + case QUEUE_ORDERED_NONE: barrier = "disabled"; break; + default: return -EINVAL; + } - err = blk_queue_ordered(info->rq, ordered); + err = blk_queue_ordered(info->rq, info->feature_barrier); if (err) return err; printk(KERN_INFO "blkfront: %s: barriers %s\n", - info->gd->disk_name, - info->feature_barrier ? "enabled" : "disabled"); + info->gd->disk_name, barrier); return 0; } @@ -665,7 +661,7 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) printk(KERN_WARNING "blkfront: %s: write barrier op failed\n", info->gd->disk_name); error = -EOPNOTSUPP; - info->feature_barrier = 0; + info->feature_barrier = QUEUE_ORDERED_NONE; xlvbd_barrier(info); } /* fall through */ @@ -1003,6 +999,7 @@ static void blkfront_connect(struct blkfront_info *info) unsigned long sector_size; unsigned int binfo; int err; + int barrier; switch (info->connected) { case BLKIF_STATE_CONNECTED: @@ -1043,10 +1040,26 @@ static void blkfront_connect(struct blkfront_info *info) } err = xenbus_gather(XBT_NIL, info->xbdev->otherend, - "feature-barrier", "%lu", &info->feature_barrier, + "feature-barrier", "%lu", &barrier, NULL); + + /* + * If there's no "feature-barrier" defined, then it means + * we're dealing with a very old backend which writes + * synchronously; draining will do what needs to get done. + * + * If there are barriers, then we can do full queued writes + * with tagged barriers. + * + * If barriers are not supported, then there's no much we can + * do, so just set ordering to NONE. + */ if (err) - info->feature_barrier = 0; + info->feature_barrier = QUEUE_ORDERED_DRAIN; + else if (barrier) + info->feature_barrier = QUEUE_ORDERED_TAG; + else + info->feature_barrier = QUEUE_ORDERED_NONE; err = xlvbd_alloc_gendisk(sectors, info, binfo, sector_size); if (err) { -- cgit v1.1 From a4cc14ec9f0ef579262a81170a2eaf760844c471 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Sun, 8 Aug 2010 21:50:05 -0400 Subject: xen-blkfront: fix missing out label Signed-off-by: Jens Axboe --- drivers/block/xen-blkfront.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/block/xen-blkfront.c') diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index ae5f92b..67d9bfa 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1232,6 +1232,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode) kfree(info); } +out: unlock_kernel(); return 0; } -- cgit v1.1