xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH]: Support dynamic resizing of vbds
@ 2010-03-09 19:56 Ky Srinivasan
  2010-03-09 20:15 ` Pasi Kärkkäinen
                   ` (2 more replies)
  0 siblings, 3 replies; 49+ messages in thread
From: Ky Srinivasan @ 2010-03-09 19:56 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 119 bytes --]

The attached patch supports dynamic resizing of vbds.

Signed-off-by: K. Y. Srinivasan <ksrinivasan@novell.com>



[-- Attachment #2: xen-vbd-resize --]
[-- Type: application/octet-stream, Size: 4210 bytes --]

Subject: Propagate changed size of VBDs
References: bnc#583677
Patch-mainline: n/a

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 <ksrinivasan@novell.com>

--- sle11sp1-2010-03-05.orig/drivers/xen/blkback/blkback.c	2010-01-04 13:29:53.000000000 +0100
+++ sle11sp1-2010-03-05/drivers/xen/blkback/blkback.c	2010-03-08 10:33:18.000000000 +0100
@@ -209,6 +209,7 @@ static void print_stats(blkif_t *blkif)
 int blkif_schedule(void *arg)
 {
 	blkif_t *blkif = arg;
+	struct vbd *vbd = &blkif->vbd;
 
 	blkif_get(blkif);
 
@@ -218,6 +219,8 @@ int blkif_schedule(void *arg)
 	while (!kthread_should_stop()) {
 		if (try_to_freeze())
 			continue;
+		if (unlikely(vbd->size != vbd_size(vbd)))
+			vbd_resize(blkif);
 
 		wait_event_interruptible(
 			blkif->wq,
--- sle11sp1-2010-03-05.orig/drivers/xen/blkback/vbd.c	2009-06-09 15:50:31.000000000 +0200
+++ sle11sp1-2010-03-05/drivers/xen/blkback/vbd.c	2010-03-08 10:33:07.000000000 +0100
@@ -73,6 +73,7 @@ int vbd_create(blkif_t *blkif, blkif_vde
 	}
 
 	vbd->bdev = bdev;
+	vbd->size = vbd_size(vbd);
 
 	if (vbd->bdev->bd_disk == NULL) {
 		DPRINTK("vbd_creat: device %08x doesn't exist.\n",
@@ -120,3 +121,45 @@ int vbd_translate(struct phys_req *req, 
  out:
 	return rc;
 }
+
+void vbd_resize(blkif_t *blkif)
+{
+	struct vbd *vbd = &blkif->vbd;
+	struct xenbus_transaction xbt;
+	int err;
+	struct xenbus_device *dev = blkif->be->dev;
+	unsigned long long new_size = vbd_size(vbd);
+
+	printk(KERN_INFO "VBD Resize: new size %Lu\n", new_size);
+	vbd->size = new_size;
+again:
+	err = xenbus_transaction_start(&xbt);
+	if (err) {
+		printk(KERN_WARNING "Error starting transaction");
+		return;
+	}
+	err = xenbus_printf(xbt, dev->nodename, "sectors", "%Lu",
+			    vbd_size(vbd));
+	if (err) {
+		printk(KERN_WARNING "Error writing new size");
+		goto abort;
+	}
+	/*
+	 * Write the current state; we will use this to synchronize
+	 * the front-end. If the current state is "connected" the
+	 * front-end will get the new size information online.
+	 */
+	err = xenbus_printf(xbt, dev->nodename, "state", "%d", dev->state);
+	if (err) {
+		printk(KERN_WARNING "Error writing the state");
+		goto abort;
+	}
+
+	err = xenbus_transaction_end(xbt, 0);
+	if (err == -EAGAIN)
+		goto again;
+	if (err)
+		printk(KERN_WARNING "Error ending transaction");
+abort:
+	xenbus_transaction_end(xbt, 1);
+}
--- sle11sp1-2010-03-05.orig/drivers/xen/blkback/common.h	2010-01-04 13:22:59.000000000 +0100
+++ sle11sp1-2010-03-05/drivers/xen/blkback/common.h	2010-03-08 10:32:11.000000000 +0100
@@ -56,6 +56,7 @@ struct vbd {
 	unsigned char  type;        /* VDISK_xxx */
 	u32            pdevice;     /* phys device that this vbd maps to */
 	struct block_device *bdev;
+	sector_t       size;        /* Cached size parameter */
 };
 
 struct backend_info;
@@ -116,6 +117,7 @@ blkif_t *blkif_alloc(domid_t domid);
 void blkif_disconnect(blkif_t *blkif);
 void blkif_free(blkif_t *blkif);
 int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn);
+void vbd_resize(blkif_t *blkif);
 
 #define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
 #define blkif_put(_b)					\
--- sle11sp1-2010-03-05.orig/drivers/xen/blkfront/blkfront.c	2010-03-01 14:45:47.000000000 +0100
+++ sle11sp1-2010-03-05/drivers/xen/blkfront/blkfront.c	2010-03-08 10:36:03.000000000 +0100
@@ -330,9 +330,24 @@ static void connect(struct blkfront_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", &sectors);
+		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;
+	}
 
 	DPRINTK("blkfront.c:connect:%s.\n", info->xbdev->otherend);
 

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

^ permalink raw reply	[flat|nested] 49+ messages in thread
* [PATCH]: Support dynamic resizing of vbds
@ 2010-03-18 20:28 Ky Srinivasan
  2010-03-18 21:01 ` Jeremy Fitzhardinge
  2010-04-04  9:57 ` J. Roeleveld
  0 siblings, 2 replies; 49+ messages in thread
From: Ky Srinivasan @ 2010-03-18 20:28 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 298 bytes --]

The attached patch supports dynamic resizing of vbds. This patch fixes a bug in the previous version of this patch that was sent out. With this patch you can perform "online" resizing of  file systems that support online resizing.

Signed-off-by: K. Y. Srinivasan <ksrinivasan@novell.com>




[-- Attachment #2: xen-vbd-resize.patch --]
[-- Type: text/plain, Size: 4709 bytes --]

Subject: Propagate changed size of VBDs
References: bnc#583677
Patch-mainline: n/a

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 <ksrinivasan@novell.com>

Index: linux/drivers/xen/blkback/blkback.c
===================================================================
--- linux.orig/drivers/xen/blkback/blkback.c	2010-03-18 14:17:28.000000000 -0600
+++ linux/drivers/xen/blkback/blkback.c	2010-03-18 14:17:33.000000000 -0600
@@ -209,6 +209,7 @@ static void print_stats(blkif_t *blkif)
 int blkif_schedule(void *arg)
 {
 	blkif_t *blkif = arg;
+	struct vbd *vbd = &blkif->vbd;
 
 	blkif_get(blkif);
 
@@ -218,6 +219,8 @@ int blkif_schedule(void *arg)
 	while (!kthread_should_stop()) {
 		if (try_to_freeze())
 			continue;
+		if (unlikely(vbd->size != vbd_size(vbd)))
+			vbd_resize(blkif);
 
 		wait_event_interruptible(
 			blkif->wq,
Index: linux/drivers/xen/blkback/vbd.c
===================================================================
--- linux.orig/drivers/xen/blkback/vbd.c	2010-03-18 14:17:28.000000000 -0600
+++ linux/drivers/xen/blkback/vbd.c	2010-03-18 14:17:33.000000000 -0600
@@ -73,6 +73,7 @@ int vbd_create(blkif_t *blkif, blkif_vde
 	}
 
 	vbd->bdev = bdev;
+	vbd->size = vbd_size(vbd);
 
 	if (vbd->bdev->bd_disk == NULL) {
 		DPRINTK("vbd_creat: device %08x doesn't exist.\n",
@@ -120,3 +121,45 @@ int vbd_translate(struct phys_req *req,
  out:
 	return rc;
 }
+
+void vbd_resize(blkif_t *blkif)
+{
+	struct vbd *vbd = &blkif->vbd;
+	struct xenbus_transaction xbt;
+	int err;
+	struct xenbus_device *dev = blkif->be->dev;
+	unsigned long long new_size = vbd_size(vbd);
+
+	printk(KERN_INFO "VBD Resize: new size %Lu\n", new_size);
+	vbd->size = new_size;
+again:
+	err = xenbus_transaction_start(&xbt);
+	if (err) {
+		printk(KERN_WARNING "Error starting transaction");
+		return;
+	}
+	err = xenbus_printf(xbt, dev->nodename, "sectors", "%Lu",
+			    vbd_size(vbd));
+	if (err) {
+		printk(KERN_WARNING "Error writing new size");
+		goto abort;
+	}
+	/*
+	 * Write the current state; we will use this to synchronize
+	 * the front-end. If the current state is "connected" the
+	 * front-end will get the new size information online.
+	 */
+	err = xenbus_printf(xbt, dev->nodename, "state", "%d", dev->state);
+	if (err) {
+		printk(KERN_WARNING "Error writing the state");
+		goto abort;
+	}
+
+	err = xenbus_transaction_end(xbt, 0);
+	if (err == -EAGAIN)
+		goto again;
+	if (err)
+		printk(KERN_WARNING "Error ending transaction");
+abort:
+	xenbus_transaction_end(xbt, 1);
+}
Index: linux/drivers/xen/blkback/common.h
===================================================================
--- linux.orig/drivers/xen/blkback/common.h	2010-03-18 14:17:28.000000000 -0600
+++ linux/drivers/xen/blkback/common.h	2010-03-18 14:17:33.000000000 -0600
@@ -56,6 +56,7 @@ struct vbd {
 	unsigned char  type;        /* VDISK_xxx */
 	u32            pdevice;     /* phys device that this vbd maps to */
 	struct block_device *bdev;
+	sector_t       size;        /* Cached size parameter */
 };
 
 struct backend_info;
@@ -116,6 +117,7 @@ blkif_t *blkif_alloc(domid_t domid);
 void blkif_disconnect(blkif_t *blkif);
 void blkif_free(blkif_t *blkif);
 int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn);
+void vbd_resize(blkif_t *blkif);
 
 #define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
 #define blkif_put(_b)					\
Index: linux/drivers/xen/blkfront/blkfront.c
===================================================================
--- linux.orig/drivers/xen/blkfront/blkfront.c	2010-03-18 14:17:28.000000000 -0600
+++ linux/drivers/xen/blkfront/blkfront.c	2010-03-18 14:17:33.000000000 -0600
@@ -328,9 +328,25 @@ static void connect(struct blkfront_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", &sectors);
+		if (XENBUS_EXIST_ERR(err))
+			return;
+		printk(KERN_INFO "Setting capacity to %Lu\n",
+		       sectors);
+		set_capacity(info->gd, sectors);
+		revalidate_disk(info->gd);
+
+		/* fall through */
+	case BLKIF_STATE_SUSPENDED:
 		return;
+	}
 
 	DPRINTK("blkfront.c:connect:%s.\n", info->xbdev->otherend);
 

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

^ permalink raw reply	[flat|nested] 49+ messages in thread
* Re: [PATCH]: Support dynamic resizing of vbds
@ 2010-03-22 22:06 Ky Srinivasan
  2010-03-23  7:17 ` Pasi Kärkkäinen
  0 siblings, 1 reply; 49+ messages in thread
From: Ky Srinivasan @ 2010-03-22 22:06 UTC (permalink / raw)
  To: Jan Beulich; +Cc: jeremy, xen-devel

>>> Jan Beulich 03/22/10 2:47 AM >>>
Based on the location of the file patched, it this would seem to be 
targeted at the 2.6.18 tree, but then 2.6.18 does not have a
revalidate_disk() function (introduced only in .28). What's the deal
here? Should this perhaps be carried out by open coding in blkfront
what .28 does?

Thanks, Jan

Jan,

This patch was tested only on the 2.6.32 kernel. For kernels that don't support revalidate_disk, we may have to implement something equivalent. I will look at this later in the week.

K. Y
>>> "Ky Srinivasan"  18.03.10 22:21 >>>


>>> On 3/18/2010 at  5:01 PM, in message <4BA294A0.1010900@goop.org>, Jeremy
Fitzhardinge  wrote: 
> On 03/18/2010 01:28 PM, Ky Srinivasan wrote:
>> The attached patch supports dynamic resizing of vbds. This patch fixes a bug 
> in the previous version of this patch that was sent out. With this patch you 
> can perform "online" resizing of  file systems that support online resizing.
>>    
> 
> Please send a delta against the previous patch, since it has already 
> been applied.
I am attaching a new patch that is the delta on the previous one.

Signed-off-by: K. Y. Srinivasan 




> 
>      J

^ permalink raw reply	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2010-08-18 19:25 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-09 19:56 [PATCH]: Support dynamic resizing of vbds Ky Srinivasan
2010-03-09 20:15 ` Pasi Kärkkäinen
2010-03-09 20:31   ` Ky Srinivasan
2010-03-09 20:35     ` Pasi Kärkkäinen
2010-03-09 20:39       ` Ky Srinivasan
2010-03-11 20:15         ` Pasi Kärkkäinen
2010-03-11 21:44           ` Jeremy Fitzhardinge
2010-03-11 22:01             ` Ky Srinivasan
2010-03-11 23:13               ` Jeremy Fitzhardinge
2010-03-12  2:52                 ` Ky Srinivasan
2010-03-12 10:41 ` J. Roeleveld
2010-03-14 13:49   ` Andrew Lyon
2010-03-14 14:06     ` Pasi Kärkkäinen
2010-03-16  3:04       ` Ky Srinivasan
2010-03-16  3:05       ` Ky Srinivasan
2010-07-20 18:27         ` Pasi Kärkkäinen
2010-07-20 18:43           ` Ky Srinivasan
2010-07-20 18:50             ` Pasi Kärkkäinen
2010-07-20 18:52               ` Ky Srinivasan
2010-07-20 19:00                 ` J. Roeleveld
2010-07-20 19:06                   ` Pasi Kärkkäinen
2010-07-28 18:59                     ` Ky Srinivasan
2010-08-15 16:20                       ` [PATCH]: Support dynamic resizing of vbds / print additional information patch Pasi Kärkkäinen
2010-08-18 19:25                         ` Jeremy Fitzhardinge
2010-03-16  2:50     ` [PATCH]: Support dynamic resizing of vbds Ky Srinivasan
2010-03-16 21:24       ` J. Roeleveld
2010-03-16 21:27         ` J. Roeleveld
2010-03-16 22:04           ` J. Roeleveld
2010-03-17 15:33           ` Ky Srinivasan
2010-03-17 15:09         ` Ky Srinivasan
2010-03-16  3:03     ` Ky Srinivasan
2010-03-15  9:26 ` Jan Beulich
  -- strict thread matches above, loose matches on Subject: below --
2010-03-18 20:28 Ky Srinivasan
2010-03-18 21:01 ` Jeremy Fitzhardinge
2010-03-18 21:21   ` Ky Srinivasan
2010-03-22  8:47     ` Jan Beulich
2010-03-22  9:15       ` J. Roeleveld
2010-03-22  9:23         ` Jan Beulich
2010-03-22  9:42           ` J. Roeleveld
2010-03-22 10:40             ` Pasi Kärkkäinen
2010-07-20 17:28   ` Pasi Kärkkäinen
2010-07-20 17:37     ` Jeremy Fitzhardinge
2010-07-20 18:29       ` Pasi Kärkkäinen
2010-07-20 19:49         ` Jeremy Fitzhardinge
2010-07-24 13:43           ` Pasi Kärkkäinen
2010-04-04  9:57 ` J. Roeleveld
2010-04-05 16:45   ` Ky Srinivasan
2010-03-22 22:06 Ky Srinivasan
2010-03-23  7:17 ` Pasi Kärkkäinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).