xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Stodden <daniel.stodden@citrix.com>
To: "Pasi Kärkkäinen" <pasik@iki.fi>
Cc: Ian Campbell <Ian.Campbell@eu.citrix.com>,
	"xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: Re: Xen guest disk online resize, xenstore/blkback/blkfront questions
Date: Thu, 7 Jan 2010 23:54:19 -0800	[thread overview]
Message-ID: <1262937259.26546.8300.camel@agari.van.xensource.com> (raw)
In-Reply-To: <20100106215735.GM25902@reaktio.net>

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

On Wed, 2010-01-06 at 16:57 -0500, Pasi Kärkkäinen wrote:

> > >   Any problems getting the new size/sectors on-the-fly in the kernel? 
> > 
> > You might need to close and reopen the block device? 
> > 
> > Idle speculation: perhaps instead of an explicit "resize" field in
> > xenstore you could just have the backend continue watching the
> > 'physical-device' node even after everything is connected the first time
> > and if it is rewritten (including to the same value) reopening the
> > physical device and setting things up again (picking up a size change as
> > a side effect).
> > 
> 
> Good idea. I'll experiment with this.

The XCP kernel has support for transparent pause/unpause. Which takes of
the queue flush in order to get the bdev closed.

Below is that patch which enables switching the physical node,
safety-checking if the VBD is paused etc. Matters not so much for
snapshotting, rather for cross-vg stuff.

It happens to work otherwise as IanC suggested.

It may be more than you're up to in order to get a resize done, e.g.
depends on whether you want to piggyback close/open into pause/unpause
or not (as a rule of thumb, it's safe to say that pause applications
want a close anyway :]). 

Didn't check for bitrot, sorry in advance.

HTH. Let me know if you're missing something or how it's going.

Cheers,
Daniel

[-- Attachment #2: blkback-device-switch.diff --]
[-- Type: text/x-patch, Size: 4501 bytes --]

diff -r e069e08b56f0 drivers/xen/blkback/xenbus.c
--- a/drivers/xen/blkback/xenbus.c	Tue Apr 14 21:22:05 2009 -0700
+++ b/drivers/xen/blkback/xenbus.c	Tue Apr 14 21:23:38 2009 -0700
@@ -37,6 +37,7 @@
 	unsigned major;
 	unsigned minor;
 	char *mode;
+	int cdrom;
 	int group_added;
 	char *nodename;
 	atomic_t refcnt;
@@ -50,6 +51,8 @@
 static int connect_ring(struct backend_info *);
 static void backend_changed(struct xenbus_watch *, const char **,
 			    unsigned int);
+static int blkback_open_bdev(struct backend_info *be);
+static void blkback_close_bdev(struct backend_info *be);
 
 static int blkback_name(blkif_t *blkif, char *buf)
 {
@@ -349,9 +352,7 @@
 
 	down(&blkback_dev_sem);
 
-	vbd_free(&blkif->vbd);
-	blkif->be->major = 0;
-	blkif->be->minor = 0;
+	blkback_close_bdev(blkif->be);
 	blkif->remove_requested = 0;
 	if (blkif->be->dev)
 		xenvbd_sysfs_delif(blkif->be->dev);
@@ -425,6 +426,10 @@
 	struct backend_info *be = blkif->be;
 
 	down(&blkback_dev_sem);
+
+	if (blkif->vbd.bdev)
+		vbd_free(&blkif->vbd);
+
 	if (be->dev) {
 		err = xenbus_write(XBT_NIL,
 				   be->dev->nodename, "pause-done", "");
@@ -471,7 +476,8 @@
 
 	} else if (xenbus_exists(XBT_NIL, dev->nodename, "pause-done")) {
 		WPRINTK("resuming %s\n", dev->nodename);
-		blkback_resume(be->blkif);
+		if (!blkback_open_bdev(be))
+			blkback_resume(be->blkif);
 	}
 }
 
@@ -555,12 +561,25 @@
 	return err;
 }
 
+static void blkback_close_bdev(struct backend_info *be)
+{
+	if (be->major || be->minor) {
+		vbd_free(&be->blkif->vbd);
+		be->major = 0;
+		be->minor = 0;
+	}
+
+	if (be->mode) {
+		kfree(be->mode);
+		be->mode = NULL;
+	}
+}
+
 static int blkback_open_bdev(struct backend_info *be)
 {
 	int err;
 	char *p;
 	long handle;
-	int cdrom = 0;
 	unsigned major;
 	unsigned minor;
 	char *device_type;
@@ -580,15 +599,16 @@
 
 	if ((be->major || be->minor) &&
 	    ((be->major != major) || (be->minor != minor))) {
-		printk(KERN_WARNING
-		       "blkback: changing physical device (from %x:%x to "
-		       "%x:%x) not supported.\n", be->major, be->minor,
-		       major, minor);
-		xenbus_dev_fatal(dev, err, "invalid physical-device change");
-		return -EINVAL;
+		printk(KERN_INFO
+		       "blkback: changing physical device (from %x:%x to %x:%x)\n",
+		       be->major, be->minor, major, minor);
 	}
 
 	if (!be->mode) {
+		/* Reopen on resume ignores the vbd info, as we're not
+		   reissuing the frontend information
+		   either. Reconnect will. */
+
 		be->mode = xenbus_read(XBT_NIL, dev->nodename, "mode", NULL);
 		if (IS_ERR(be->mode)) {
 			err = PTR_ERR(be->mode);
@@ -596,12 +616,12 @@
 			xenbus_dev_fatal(dev, err, "reading mode");
 			return err;
 		}
-	}
 
-	device_type = xenbus_read(XBT_NIL, dev->otherend, "device-type", NULL);
-	if (!IS_ERR(device_type)) {
-		cdrom = strcmp(device_type, "cdrom") == 0;
-		kfree(device_type);
+		device_type = xenbus_read(XBT_NIL, dev->otherend, "device-type", NULL);
+		if (!IS_ERR(device_type)) {
+			be->cdrom = strcmp(device_type, "cdrom") == 0;
+			kfree(device_type);
+		}
 	}
 
 	/* Front end dir is a number, which is used as the handle. */
@@ -609,9 +629,10 @@
 	handle = simple_strtoul(p, NULL, 0);
 
 	err = vbd_create(be->blkif, handle, major, minor,
-			 (NULL == strchr(be->mode, 'w')), cdrom);
+			 (NULL == strchr(be->mode, 'w')), be->cdrom);
 	if (err) {
 		xenbus_dev_fatal(dev, err, "creating vbd structure");
+		blkback_close_bdev(be);
 		return err;
 	}
 
@@ -652,24 +673,12 @@
 	}
 
 	if ((be->major || be->minor) &&
-	    ((be->major != major) || (be->minor != minor))) {
+	    ((be->major != major) || (be->minor != minor)) &&
+	    !xenbus_exists(XBT_NIL, dev->nodename, "pause-done")) {
 		printk(KERN_WARNING
-		       "blkback: changing physical device (from %x:%x to "
-		       "%x:%x) not supported.\n", be->major, be->minor,
+		       "blkback: attempt to change physical device (from %x:%x to "
+		       "%x:%x) on running blkif.\n", be->major, be->minor,
 		       major, minor);
-		return;
-	}
-
-	if (be->mode) {
-		kfree(be->mode);
-		be->mode = NULL;
-	}
-
-	be->mode = xenbus_read(XBT_NIL, dev->nodename, "mode", NULL);
-	if (IS_ERR(be->mode)) {
-		err = PTR_ERR(be->mode);
-		be->mode = NULL;
-		xenbus_dev_fatal(dev, err, "reading mode");
 		return;
 	}
 
@@ -680,8 +689,7 @@
 
 		err = xenvbd_sysfs_addif(dev);
 		if (err) {
-			vbd_free(&be->blkif->vbd);
-			be->major = be->minor = 0;
+			blkback_close_bdev(be);
 			xenbus_dev_fatal(dev, err, "creating sysfs entries");
 			return;
 		}

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

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

  reply	other threads:[~2010-01-08  7:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-06 20:26 Xen guest disk online resize, xenstore/blkback/blkfront questions Pasi Kärkkäinen
2010-01-06 20:44 ` Ian Campbell
2010-01-06 21:57   ` Pasi Kärkkäinen
2010-01-08  7:54     ` Daniel Stodden [this message]
2010-01-12 15:16       ` Pasi Kärkkäinen
2012-02-01 12:29 ` feisky
2012-02-01 15:51   ` Pasi Kärkkäinen
2012-02-02  5:31     ` feisky
2012-02-02  9:12       ` Pasi Kärkkäinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1262937259.26546.8300.camel@agari.van.xensource.com \
    --to=daniel.stodden@citrix.com \
    --cc=Ian.Campbell@eu.citrix.com \
    --cc=pasik@iki.fi \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).