Linux/pvops blktap + blkfront updates.
Subsystems (3)
PATCH 1/1 Linux/pvops blktap + blkfront updates.
First 4 stop blktap barfing once and blkfront twice during shutdown, plus a memory leak.
16 A fix-double-free.diff: blktap: Fix tap kobj double unref in sysfs_destroy. 17 A fix-blk-cleanup.diff: blkfront: Fix backtrace in blk_cleanup_queue. 18 A fix-gendisk-leak.diff: blkfront: Stop leaking the gendisk struct. 19 A fix-bd-oops.diff: blkfront: Fix an unlikely xenbus crasher.
The rest is decoration.
20 A blkfront-close.diff: blkfront: Clean up closing transition.
21 A xs-write-unlocked.diff: blkfront: Move xenstore accesses off the device release path. 22 A xlvbd-release-gendisk.diff: blkfront: Clean up blkfront_closing.
23 A debug-common.diff: blkfront: Clean up debug statements.
Cheers,
Daniel
PATCH 1/1 blktap: Fix tap kobj double unref in sysfs_destroy
It's that final put_device in device_unregister which is supposed to clear the caller's reference. Subtle indeed, because refcount went 2->3 when after sysfs_destroy:
+1 for our own ring->dev
+1 for the open sysfs ./remove attribute
+1 for the callback scheduled
Drops to 1 in device_unregister and 0 only after leaving callbacks.
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1267197951 28800
# Node ID 3ea95de27eaed11b87a5c608629f5089b0b33a73 # Parent 6cee7e3206311d4556e5bb75ceb522e4e293d4d1
blktap: Fix tap kobj double unref in sysfs_destroy.
It's that final put_device in device_unregister which is supposed to clear the caller's reference. Subtle indeed, because refcount went 2->3 when after sysfs_destroy:
+1 for our own ring->dev
+1 for the open sysfs ./remove attribute
+1 for the callback scheduled
Drops to 1 in device_unregister and 0 only after leaving callbacks.
drivers/xen/blktap/sysfs.c +0 -1
@@ -360,7 +360,6 @@ !atomic_read(&tap->ring.sysfs_refcnt)))return -EAGAIN ; -put_device (dev);device_schedule_callback (dev, device_unregister);return 0 ;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blkfront: Fix backtrace in blk_cleanup_queue
In reply to Daniel Stodden# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1267197952 28800
# Node ID 93086816e211834e57d2d0d425b9eb00d3140a8c # Parent 3ea95de27eaed11b87a5c608629f5089b0b33a73
blkfront: Fix backtrace in blk_cleanup_queue.
drivers/block/xen-blkfront.c +2 -2
@@ -942,11 +942,11 @@/* Flush gnttab callback work. Must be done with no locks held. */ flush_scheduled_work (); +del_gendisk (info->gd); +blk_cleanup_queue (info->rq); info->rq =NULL ; -del_gendisk (info->gd); - out:xenbus_frontend_closed (dev); }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blkfront: Stop leaking the gendisk struct
In reply to Daniel Stodden# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1267197953 28800
# Node ID 3b7ebe4ce587d81361bf9afb5825420fa3d4c9d7 # Parent 93086816e211834e57d2d0d425b9eb00d3140a8c
blkfront: Stop leaking the gendisk struct.
drivers/block/xen-blkfront.c +3 -0
@@ -947,6 +947,9 @@blk_cleanup_queue (info->rq); info->rq =NULL ; +put_disk (info->gd); + info->gd =NULL ; + out:xenbus_frontend_closed (dev); }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blkfront: Fix an unlikely xenbus crasher
In reply to Daniel StoddenGetting partition 0 should not fail, but if it does we won't continue.
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1267197954 28800
# Node ID fcefa69c0dbf52a86a9037ad14f81d3252f387ff # Parent 3b7ebe4ce587d81361bf9afb5825420fa3d4c9d7
blkfront: Fix an unlikely xenbus crasher.
Getting partition 0 should not fail, but if it does we won't continue.
drivers/block/xen-blkfront.c +3 -1
@@ -985,8 +985,10 @@break ; } bd =bdget_disk (info->gd,0 ); -if (bd ==NULL ) +if (bd ==NULL ) {xenbus_dev_fatal (dev, -ENODEV ,"bdget failed" ); +break ; + }mutex_lock (&bd->bd_mutex);if (info->users >0 )
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blkfront: Clean up closing transition
In reply to Daniel StoddenJust gained enough locals to justify a proper subroutine.
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1267198064 28800
# Node ID 96525ab0393ab7cab181de757a495f57284ccd01 # Parent fcefa69c0dbf52a86a9037ad14f81d3252f387ff
blkfront: Clean up closing transition.
Just gained enough locals to justify a proper subroutine.
drivers/block/xen-blkfront.c +30 -19
@@ -954,6 +954,35 @@xenbus_frontend_closed (dev); } +static void blkfront_close (struct blkfront_info *info) +{ +struct xenbus_device *dev = info->xbdev; +struct gendisk *gd = info->gd; +struct block_device *bd; + +if (!gd) { +xenbus_frontend_closed (dev); +return ; + } + + bd =bdget_disk (gd,0 ); +if (!bd) { +xenbus_dev_fatal (dev, -ENODEV ,"bdget failed" ); +return ; + } + +mutex_lock (&bd->bd_mutex); + +if (info->users >0 ) +xenbus_dev_error (dev, -EBUSY , +"Device in use; refusing to close" ); +else +blkfront_closing (dev); + +mutex_unlock (&bd->bd_mutex); +bdput (bd); +} +/** * Callback received when the backend's state changes. */
@@ -961,7 +990,6 @@ 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);
@@ -980,24 +1008,7 @@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" ); -break ; - } - -mutex_lock (&bd->bd_mutex); -if (info->users >0 ) -xenbus_dev_error (dev, -EBUSY , -"Device in use; refusing to close" ); -else -blkfront_closing (dev); -mutex_unlock (&bd->bd_mutex); -bdput (bd); +blkfront_close (info);break ; } }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blkfront: Move xenstore accesses off the device release path
In reply to Daniel StoddenNot holding the bdev mutex should be slightly more robust. Also helps getting blkfront_closing to complement xlvbd_alloc_gendisk.
# HG changeset patch
# User Daniel Stodden <[email protected]>
# Date 1267200019 28800
# Node ID 183cbdaef8d14d863465c18bc06cbc7849c30bbc # Parent 96525ab0393ab7cab181de757a495f57284ccd01
blkfront: Move xenstore accesses off the device release path.
Not holding the bdev mutex should be slightly more robust. Also helps getting blkfront_closing to complement xlvbd_alloc_gendisk.
drivers/block/xen-blkfront.c +14 -10
@@ -927,8 +927,8 @@dev_dbg (&dev->dev,"blkfront_closing: %s removed\n" , dev->nodename); -if (info->rq ==NULL ) - goto out; +if (!info->gd) +return ;spin_lock_irqsave (&blkif_io_lock, flags);
@@ -949,9 +949,6 @@put_disk (info->gd); info->gd =NULL ; - - out: -xenbus_frontend_closed (dev); }static void blkfront_close (struct blkfront_info *info)
@@ -959,6 +956,7 @@struct xenbus_device *dev = info->xbdev;struct gendisk *gd = info->gd;struct block_device *bd; +int inuse;if (!gd) {xenbus_frontend_closed (dev);
@@ -973,14 +971,18 @@mutex_lock (&bd->bd_mutex); -if (info->users >0 ) -xenbus_dev_error (dev, -EBUSY , -"Device in use; refusing to close" ); -else + inuse = !!info->users; +if (!inuse)blkfront_closing (dev);mutex_unlock (&bd->bd_mutex);bdput (bd); + +if (inuse) +xenbus_dev_error (dev, -EBUSY , +"Device in use; refusing to close" ); +else +xenbus_frontend_closed (dev); }/**
@@ -1051,8 +1053,10 @@struct xenbus_device *dev = info->xbdev;enum xenbus_state state =xenbus_read_driver_state (dev->otherend); -if (state == XenbusStateClosing && info->is_ready) +if (state == XenbusStateClosing && info->is_ready) {blkfront_closing (dev); +xenbus_frontend_closed (dev); + } }return 0 ; }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blkfront: Clean up blkfront_closing
In reply to Daniel Stodden* Call blkfront_closing the xlvbd_release_gendisk it is.
* Fix comments regarding device disconnects.
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1267200152 28800
# Node ID 03ff587d68cd4146470e874c587250d9bc7a2492 # Parent 183cbdaef8d14d863465c18bc06cbc7849c30bbc
blkfront: Clean up blkfront_closing.
* Call blkfront_closing the xlvbd_release_gendisk it is.
* Fix comments regarding device disconnects.
drivers/block/xen-blkfront.c +36 -37
@@ -473,6 +473,37 @@return err; } +static void xlvbd_release_gendisk (struct blkfront_info *info) +{ +struct xenbus_device *dev = info->xbdev; +unsigned long flags; + +dev_dbg (&dev->dev,"%s: %s removed\n" , __func__, dev->nodename); + +if (!info->gd) +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); + +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)) {
@@ -915,42 +946,10 @@ }/** -* 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. +* Handle the change of state of the backend to Closing. Refuse to +* disconnect while the device is still in use. This also ensures that +* writes are flushed through to the backend. */ -static void blkfront_closing (struct xenbus_device *dev) -{ -struct blkfront_info *info =dev_get_drvdata (&dev->dev); -unsigned long flags; - -dev_dbg (&dev->dev,"blkfront_closing: %s removed\n" , dev->nodename); - -if (!info->gd) -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); - -blk_cleanup_queue (info->rq); - info->rq =NULL ; - -put_disk (info->gd); - info->gd =NULL ; -} -static void blkfront_close (struct blkfront_info *info) {struct xenbus_device *dev = info->xbdev;
@@ -973,7 +972,7 @@ inuse = !!info->users;if (!inuse) -blkfront_closing (dev); +xlvbd_release_gendisk (info);mutex_unlock (&bd->bd_mutex);bdput (bd);
@@ -1054,7 +1053,7 @@enum xenbus_state state =xenbus_read_driver_state (dev->otherend);if (state == XenbusStateClosing && info->is_ready) { -blkfront_closing (dev); +xlvbd_release_gendisk (info);xenbus_frontend_closed (dev); } }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blkfront: Clean up debug statements
In reply to Daniel Stodden* Use dev_dbg everywhere.
* Fix excess line withs.
* Wrap dev_dbg to take a blkfront_info handle.
* Separate datapath debug statements (DEV_QDBG), conditionally.
* Verbose disk remove/release dbg_info statements.
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1267200155 28800
# Node ID 03b5c624c6186447675e996b62747e6aa87671a4 # Parent 03ff587d68cd4146470e874c587250d9bc7a2492
blkfront: Clean up debug statements.
* Use dev_dbg everywhere.
* Fix excess line withs.
* Wrap dev_dbg to take a blkfront_info handle.
* Separate datapath debug statements (DEV_QDBG), conditionally.
* Verbose disk remove/release dbg_info statements.
drivers/block/xen-blkfront.c +51 -33
@@ -35,6 +35,8 @@* IN THE SOFTWARE. */ +/* #define DEBUG 1 */ +#include <linux/interrupt.h> #include <linux/blkdev.h> #include <linux/hdreg.h>
@@ -100,6 +102,19 @@int users; }; +#define DEV_DBG(_info, _fmt, _args ...) \ + dev_dbg(&(_info)->xbdev->dev, "%s: "_fmt, __func__, ##_args) +#define DEV_WARN(_info, _fmt, _args ...) \ + dev_warn(&(_info)->xbdev->dev, _fmt, ##_args) +#define DEV_INFO(_info, _fmt, _args ...) \ + dev_warn(&(_info)->xbdev->dev, _fmt, ##_args) + +#if defined(DEBUG ) &&DEBUG >=2 +#define DEV_QDBG(_info, _fmt, _args ...) DEV_DBG(_info, _fmt, ##_args) +#else +#define DEV_QDBG(_info, _fmt, _args ...) do {} while (0) +#endif +static DEFINE_SPINLOCK (blkif_io_lock);#define MAXIMUM_OUTSTANDING_BLOCK_REQS \
@@ -164,12 +179,11 @@struct blkfront_info *info = bdev->bd_disk->private_data;int i; -dev_dbg (&info->xbdev->dev,"command: 0x%x, argument: 0x%lx\n" , - command, (long )argument); +DEV_DBG (info,"command: 0x%x, argument: 0x%lx\n" , command, (long )argument);switch (command) {case CDROMMULTISESSION : -dev_dbg (&info->xbdev->dev,"FIXME: support multisession CDs later\n" ); +DEV_DBG (info,"FIXME: support multisession CDs later\n" );for (i =0 ; i <sizeof (struct cdrom_multisession ); i++)if (put_user (0 , (char __user *)(argument + i)))return -EFAULT ;
@@ -183,8 +197,7 @@ }default : -/*printk(KERN_ALERT "ioctl %08x not supported by Xen blkdev\n", -command);*/ +/* DEV_WARN(info, "ioctl %08x not supported\n", command); */ return -EINVAL ;/* same return as native Linux */ }
@@ -291,16 +304,15 @@*/ static void do_blkif_request (struct request_queue *rq) { -struct blkfront_info *info =NULL ; +struct blkfront_info *info = rq->queuedata;struct request *req;int queued; -pr_debug ("Entered do_blkif_request\n" ); +DEV_QDBG (info,"\n" ); queued =0 ;while ((req =blk_peek_request (rq)) !=NULL ) { - info = req->rq_disk->private_data;if (RING_FULL (&info->ring)) goto wait;
@@ -312,8 +324,8 @@continue ; } -pr_debug ("do_blk_req %p: cmd %p, sec %lx, " -"(%u/%u) buffer:%p [%s]\n" , +DEV_QDBG (info, +"%p: cmd %p, sec %lx, (%u/%u) buffer:%p [%s]\n" , req, req->cmd, (unsigned long )blk_rq_pos (req),blk_rq_cur_sectors (req),blk_rq_sectors (req), req->buffer,rq_data_dir (req) ?"write" :"read" );
@@ -378,9 +390,6 @@if (err)return err; -printk (KERN_INFO "blkfront: %s: barriers %s\n" , - info->gd->disk_name, - info->feature_barrier ?"enabled" :"disabled" );return 0 ; }
@@ -401,7 +410,8 @@if ((info->vdevice>>EXT_SHIFT ) >1 ) {/* this is above the extended range; something is wrong */ -printk (KERN_WARNING "blkfront: vdevice 0x%x is above the extended range; ignoring\n" , info->vdevice); +DEV_WARN (info,"vdevice %#x is above %#x; ignoring\n" , + info->vdevice,1U <<EXT_SHIFT );return -ENODEV ; }
@@ -452,8 +462,9 @@ goto out; } + info->gd = gd; info->rq = gd->queue; - info->gd = gd; + info->rq->queuedata = info;if (info->feature_barrier)xlvbd_barrier (info);
@@ -475,11 +486,8 @@static void xlvbd_release_gendisk (struct blkfront_info *info) { -struct xenbus_device *dev = info->xbdev;unsigned long flags; -dev_dbg (&dev->dev,"%s: %s removed\n" , __func__, dev->nodename); -if (!info->gd)return ;
@@ -595,8 +603,7 @@switch (bret->operation) {case BLKIF_OP_WRITE_BARRIER :if (unlikely (bret->status ==BLKIF_RSP_EOPNOTSUPP )) { -printk (KERN_WARNING "blkfront: %s: write barrier op failed\n" , - info->gd->disk_name); +DEV_WARN (info,"write barrier op failed\n" ); error = -EOPNOTSUPP ; info->feature_barrier =0 ;xlvbd_barrier (info);
@@ -605,8 +612,9 @@case BLKIF_OP_READ :case BLKIF_OP_WRITE :if (unlikely (bret->status !=BLKIF_RSP_OKAY )) -dev_dbg (&info->xbdev->dev,"Bad return from blkdev data " -"request: %x\n" , bret->status); +DEV_QDBG (info, +"Bad return from blkdev data " +"request: %x\n" , bret->status);__blk_end_request_all (req, error);break ;
@@ -877,7 +885,7 @@struct blkfront_info *info =dev_get_drvdata (&dev->dev);int err; -dev_dbg (&dev->dev,"blkfront_resume: %s\n" , dev->nodename); +DEV_DBG (info,"connected=%d\n" , info->connected);blkif_free (info, info->connected ==BLKIF_STATE_CONNECTED );
@@ -904,8 +912,7 @@ (info->connected == BLKIF_STATE_SUSPENDED) ) return; -dev_dbg (&info->xbdev->dev,"%s:%s.\n" , - __func__, info->xbdev->otherend); +DEV_DBG (info,"connecting to %s\n" , info->xbdev->otherend); err = xenbus_gather(XBT_NIL, info->xbdev->otherend, "sectors", "%llu", §ors,
@@ -940,6 +947,9 @@kick_pending_request_queues (info);spin_unlock_irq (&blkif_io_lock); +DEV_INFO (info,"%s: %llu MiB, %luB sectors, barriers %s\n" , + info->gd->disk_name, (sectors * sector_size) >>20 , + sector_size, info->feature_barrier ?"enabled" :"disabled" );add_disk (info->gd); info->is_ready =1 ;
@@ -971,8 +981,10 @@mutex_lock (&bd->bd_mutex); inuse = !!info->users; -if (!inuse) +if (!inuse) { +get_disk (gd);xlvbd_release_gendisk (info); + }mutex_unlock (&bd->bd_mutex);bdput (bd);
@@ -980,8 +992,11 @@if (inuse)xenbus_dev_error (dev, -EBUSY ,"Device in use; refusing to close" ); -else +else { +DEV_INFO (info,"%s removed\n" , gd->disk_name); +put_disk (gd);xenbus_frontend_closed (dev); + } }/**
@@ -992,7 +1007,7 @@ {struct blkfront_info *info =dev_get_drvdata (&dev->dev); -dev_dbg (&dev->dev,"blkfront:blkback_changed to state %d.\n" , backend_state); +DEV_DBG (info,"state %d\n" , backend_state);switch (backend_state) {case XenbusStateInitialising:
@@ -1018,7 +1033,7 @@ {struct blkfront_info *info =dev_get_drvdata (&dev->dev); -dev_dbg (&dev->dev,"blkfront_remove: %s removed\n" , dev->nodename); +DEV_DBG (info,"\n" );blkif_free (info,0 );
@@ -1088,13 +1103,16 @@static int __init xlblk_init (void ) { +int err; +if (!xen_domain ())return -ENODEV ; -if (register_blkdev (XENVBD_MAJOR ,DEV_NAME )) { -printk (KERN_WARNING "xen_blk: can't get major %d with name %s\n" , -XENVBD_MAJOR ,DEV_NAME ); -return -ENODEV ; + err =register_blkdev (XENVBD_MAJOR ,DEV_NAME ); +if (err) { +printk (KERN_WARNING "%s: can't get major %d with name %s: %d\n" , +KBUILD_MODNAME ,XENVBD_MAJOR ,DEV_NAME , err); +return err; }return xenbus_register_frontend (&blkfront);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel