WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Added a count of the number of users of this block devic

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Added a count of the number of users of this block device, and refuse to close
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 25 Nov 2005 00:16:08 +0000
Delivery-date: Fri, 25 Nov 2005 00:16:25 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID d2b957902c6b48fb675ffbde5a46f6d8946c4372
# Parent  64d9190320012e88270a4bbbd418feecb81ede42
Added a count of the number of users of this block device, and refuse to close
down the frontend until that number becomes 0.  There are no reasonable
semantics for hot-unplugging a block device beneath a mounted filesystem, and
this solution ensures that the guest is not crashed nor the filesystem 
corruptedby the actions of the administrator.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r 64d919032001 -r d2b957902c6b 
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c      Thu Nov 24 
15:57:45 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c      Thu Nov 24 
19:53:09 2005
@@ -117,6 +117,8 @@
                info->shadow[i].req.id = i+1;
        info->shadow[BLK_RING_SIZE-1].req.id = 0x0fffffff;
 
+       info->users = 0;
+
        /* Front end dir is a number, which is used as the id. */
        info->handle = simple_strtoul(strrchr(dev->nodename,'/')+1, NULL, 0);
        dev->data = info;
@@ -265,6 +267,7 @@
                            XenbusState backend_state)
 {
        struct blkfront_info *info = dev->data;
+       struct block_device *bd;
 
        DPRINTK("blkfront:backend_changed.\n");
 
@@ -281,7 +284,18 @@
                break;
 
        case XenbusStateClosing:
-               blkfront_closing(dev);
+               bd = bdget(info->dev);
+               if (bd == NULL)
+                       xenbus_dev_fatal(dev, -ENODEV, "bdget failed");
+
+               down(&bd->bd_sem);
+               if (info->users > 0)
+                       xenbus_dev_error(dev, -EBUSY,
+                                        "Device in use; refusing to close");
+               else
+                       blkfront_closing(dev);
+               up(&bd->bd_sem);
+               bdput(bd);
                break;
        }
 }
@@ -414,12 +428,26 @@
 
 int blkif_open(struct inode *inode, struct file *filep)
 {
+       struct blkfront_info *info = inode->i_bdev->bd_disk->private_data;
+       info->users++;
        return 0;
 }
 
 
 int blkif_release(struct inode *inode, struct file *filep)
 {
+       struct blkfront_info *info = inode->i_bdev->bd_disk->private_data;
+       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;
+               XenbusState state = xenbus_read_driver_state(dev->otherend);
+
+               if (state == XenbusStateClosing)
+                       blkfront_closing(dev);
+       }
        return 0;
 }
 
diff -r 64d919032001 -r d2b957902c6b 
linux-2.6-xen-sparse/drivers/xen/blkfront/block.h
--- a/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h Thu Nov 24 15:57:45 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h Thu Nov 24 19:53:09 2005
@@ -127,6 +127,12 @@
        struct gnttab_free_callback callback;
        struct blk_shadow shadow[BLK_RING_SIZE];
        unsigned long shadow_free;
+
+       /**
+        * The number of people holding this device open.  We won't allow a
+        * hot-unplug unless this is 0.
+        */
+       int users;
 };
 
 extern spinlock_t blkif_io_lock;

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Added a count of the number of users of this block device, and refuse to close, Xen patchbot -unstable <=