From mboxrd@z Thu Jan 1 00:00:00 1970 From: Shriram Rajagopalan Subject: Re: [PATCH] make qemu handle drbd properly Date: Sat, 25 Jun 2011 12:47:09 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1449860737==" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: James Harper Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============1449860737== Content-Type: multipart/alternative; boundary=000325554fbe11917404a68c1457 --000325554fbe11917404a68c1457 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jan 26, 2011 at 11:43 PM, James Harper < james.harper@bendigoit.com.au> wrote: > This attached patch allows qemu to accept a drbd: prefix and interpret > it as a drbd resource. It then searches for it in /dev/drbd/by-res/ > (which must be mapped via udev). It's against 4.0-testing. > > Also, the block scripts make the drbd resource primary but don't want > for it to actually become available. A secondary drbd resource returns > EMEDIUMTYPE so if we get that result, wait half a second and retry, up > to a total of 5 retries. Fixing this in the block scripts might be > better but I can't see how to do it cleanly. > > James > > > diff --git a/xenstore.c b/xenstore.c > index 13b8d57..f6e2170 100644 > --- a/xenstore.c > +++ b/xenstore.c > @@ -413,6 +413,9 @@ void xenstore_parse_domain_config(int hvm_domid) > char *danger_buf = NULL; > char *danger_type = NULL; > > + int retries = 1; /* number of attempts to open the block device - > drbd can take a second to become available */ > + int status; > + > for(i = 0; i < MAX_DRIVES + 1; i++) > media_filename[i] = NULL; > > @@ -519,6 +522,14 @@ void xenstore_parse_domain_config(int hvm_domid) > format = &bdrv_raw; > } > > + if (!strcmp(drv, "drbd")) { > + char *newparams = malloc(17 + strlen(params) + 1); > + sprintf(newparams, "/dev/drbd/by-res/%s", params); > + free(params); > + params = newparams; > + format = &bdrv_raw; > + retries = 5; > + } > #if 0 > /* Phantom VBDs are disabled because the use of paths > * from guest-controlled areas in xenstore is unsafe. > @@ -617,7 +628,14 @@ void xenstore_parse_domain_config(int hvm_domid) > > fprintf(stderr, "Using file %s in read-%s mode\n", > bs->filename, is_readonly ? "only" : "write"); > > - if (bdrv_open2(bs, params, flags, format) < 0) > + do { > + int status = bdrv_open2(bs, params, flags, format); > + if (status != -EMEDIUMTYPE) > + break; > + usleep(500000); /* 500ms */ > + retries--; > + } while (retries); > + if (status < 0) > fprintf(stderr, "qemu: could not open vbd '%s' or hard > disk image '%s' (drv '%s' format '%s')\n", buf, params, drv ? drv : "?", > format ? format->format_name : " > } > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel > Sorry to dig up an old thread. This patch doesnt seem to be in any of the qemu-xen-*, xen-*-testing or xen-unstable trees. Any reason why? shriram --000325554fbe11917404a68c1457 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Wed, Jan 26, 2011 at 11:43 PM, James Harper <= span dir=3D"ltr"><james= .harper@bendigoit.com.au> wrote:
This attached patch allows qemu to accept a drbd: prefix and interpret
it as a drbd resource. It then searches for it in /dev/drbd/by-res/
(which must be mapped via udev). It's against 4.0-testing.

Also, the block scripts make the drbd resource primary but don't want for it to actually become available. A secondary drbd resource returns
EMEDIUMTYPE so if we get that result, wait half a second and retry, up
to a total of 5 retries. Fixing this in the block scripts might be
better but I can't see how to do it cleanly.

James


diff --git a/xenstore.c b/xenstore.c
index 13b8d57..f6e2170 100644
--- a/xenstore.c
+++ b/xenstore.c
@@ -413,6 +413,9 @@ void xenstore_parse_domain_config(int hvm_domid)
=A0 =A0 char *danger_buf =3D NULL;
=A0 =A0 char *danger_type =3D NULL;

+ =A0 =A0int retries =3D 1; /* number of attempts to open the block device = -
drbd can take a second to become available */
+ =A0 =A0int status;
+
=A0 =A0 for(i =3D 0; i < MAX_DRIVES + 1; i++)
=A0 =A0 =A0 =A0 media_filename[i] =3D NULL;

@@ -519,6 +522,14 @@ void xenstore_parse_domain_config(int hvm_domid)
=A0 =A0 =A0 =A0 =A0 =A0format =3D &bdrv_raw;
=A0 =A0 =A0 =A0 }

+ =A0 =A0 =A0 =A0if (!strcmp(drv, "drbd")) {
+ =A0 =A0 =A0 =A0 =A0 =A0char *newparams =3D malloc(17 + strlen(params) + 1= );
+ =A0 =A0 =A0 =A0 =A0 =A0sprintf(newparams, "/dev/drbd/by-res/%s"= , params);
+ =A0 =A0 =A0 =A0 =A0 =A0free(params);
+ =A0 =A0 =A0 =A0 =A0 =A0params =3D newparams;
+ =A0 =A0 =A0 =A0 =A0 format =3D &bdrv_raw;
+ =A0 =A0 =A0 =A0 =A0 =A0retries =3D 5;
+ =A0 =A0 =A0 =A0}
=A0#if 0
=A0 =A0 =A0 =A0/* Phantom VBDs are disabled because the use of paths
=A0 =A0 =A0 =A0 * from guest-controlled areas in xenstore is unsafe.
@@ -617,7 +628,14 @@ void xenstore_parse_domain_config(int hvm_domid)

=A0 =A0 =A0 =A0 =A0 =A0 fprintf(stderr, "Using file %s in read-%s mod= e\n",
bs->filename, is_readonly ? "only" : "write");

- =A0 =A0 =A0 =A0 =A0 =A0if (bdrv_open2(bs, params, flags, format) < 0)<= br> + =A0 =A0 =A0 =A0 =A0 =A0do {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int status =3D bdrv_open2(bs, params, flag= s, format);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (status !=3D -EMEDIUMTYPE)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0usleep(500000); /* 500ms */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0retries--;
+ =A0 =A0 =A0 =A0 =A0 =A0} while (retries);
+ =A0 =A0 =A0 =A0 =A0 =A0if (status < 0)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fprintf(stderr, "qemu: could not open= vbd '%s' or hard
disk image '%s' (drv '%s' format '%s')\n", buf= , params, drv ? drv : "?",
format ? format->format_name : "
=A0 =A0 =A0 =A0 }


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

Sorry to dig up an old thread. This patch doesnt see= m to be in any of the
qemu-xen-*, xen-*-testing or xen-unstable trees. A= ny reason why?

shriram

--000325554fbe11917404a68c1457-- --===============1449860737== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1449860737==--