From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:52862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPJcS-0008Vk-9f for qemu-devel@nongnu.org; Wed, 25 May 2011 15:19:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QPJcQ-0003bN-PN for qemu-devel@nongnu.org; Wed, 25 May 2011 15:19:48 -0400 Received: from mail-vw0-f45.google.com ([209.85.212.45]:46986) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPJcQ-0003bJ-Hp for qemu-devel@nongnu.org; Wed, 25 May 2011 15:19:46 -0400 Received: by vws17 with SMTP id 17so6970996vws.4 for ; Wed, 25 May 2011 12:19:46 -0700 (PDT) MIME-Version: 1.0 Sender: c.m.brunner@gmail.com In-Reply-To: <1306263078-18089-3-git-send-email-josh.durgin@dreamhost.com> References: <1306263078-18089-1-git-send-email-josh.durgin@dreamhost.com> <1306263078-18089-3-git-send-email-josh.durgin@dreamhost.com> Date: Wed, 25 May 2011 21:19:38 +0200 Message-ID: From: Christian Brunner Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v4 2/4] rbd: allow configuration of rados from the rbd filename Reply-To: chb@muc.de List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Josh Durgin Cc: Kevin Wolf , ceph-devel@vger.kernel.org, qemu-devel@nongnu.org, kvm@vger.kernel.org Looks good to me: Reviewed-by: Christian Brunner 2011/5/24 Josh Durgin : > The new format is rbd:pool/image[@snapshot][:option1=3Dvalue1[:option2=3D= value2...]] > Each option is used to configure rados, and may be any Ceph option, or "c= onf". > The "conf" option specifies a Ceph configuration file to read. > > This allows rbd volumes from more than one Ceph cluster to be used by > specifying different monitor addresses, as well as having different > logging levels or locations for different volumes. > > Signed-off-by: Josh Durgin > --- > =A0block/rbd.c | =A0119 +++++++++++++++++++++++++++++++++++++++++++++++++= +-------- > =A01 files changed, 102 insertions(+), 17 deletions(-) > > diff --git a/block/rbd.c b/block/rbd.c > index 1c8e7c7..ff74e8b 100644 > --- a/block/rbd.c > +++ b/block/rbd.c > @@ -23,13 +23,17 @@ > =A0/* > =A0* When specifying the image filename use: > =A0* > - * rbd:poolname/devicename > + * rbd:poolname/devicename[@snapshotname][:option1=3Dvalue1[:option2=3Dv= alue2...]] > =A0* > =A0* poolname must be the name of an existing rados pool > =A0* > =A0* devicename is the basename for all objects used to > =A0* emulate the raw device. > =A0* > + * Each option given is used to configure rados, and may be > + * any Ceph option, or "conf". The "conf" option specifies > + * a Ceph configuration file to read. > + * > =A0* Metadata information (image size, ...) is stored in an > =A0* object with the name "devicename.rbd". > =A0* > @@ -122,7 +126,8 @@ static int qemu_rbd_next_tok(char *dst, int dst_len, > =A0static int qemu_rbd_parsename(const char *filename, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 char *pool, i= nt pool_len, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 char *snap, i= nt snap_len, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0char *name, = int name_len) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0char *name, = int name_len, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0char *conf, = int conf_len) > =A0{ > =A0 =A0 const char *start; > =A0 =A0 char *p, *buf; > @@ -134,28 +139,84 @@ static int qemu_rbd_parsename(const char *filename, > > =A0 =A0 buf =3D qemu_strdup(start); > =A0 =A0 p =3D buf; > + =A0 =A0*snap =3D '\0'; > + =A0 =A0*conf =3D '\0'; > > =A0 =A0 ret =3D qemu_rbd_next_tok(pool, pool_len, p, '/', "pool name", &p= ); > =A0 =A0 if (ret < 0 || !p) { > =A0 =A0 =A0 =A0 ret =3D -EINVAL; > =A0 =A0 =A0 =A0 goto done; > =A0 =A0 } > - =A0 =A0ret =3D qemu_rbd_next_tok(name, name_len, p, '@', "object name",= &p); > - =A0 =A0if (ret < 0) { > - =A0 =A0 =A0 =A0goto done; > + > + =A0 =A0if (strchr(p, '@')) { > + =A0 =A0 =A0 =A0ret =3D qemu_rbd_next_tok(name, name_len, p, '@', "objec= t name", &p); > + =A0 =A0 =A0 =A0if (ret < 0) { > + =A0 =A0 =A0 =A0 =A0 =A0goto done; > + =A0 =A0 =A0 =A0} > + =A0 =A0 =A0 =A0ret =3D qemu_rbd_next_tok(snap, snap_len, p, ':', "snap = name", &p); > + =A0 =A0} else { > + =A0 =A0 =A0 =A0ret =3D qemu_rbd_next_tok(name, name_len, p, ':', "objec= t name", &p); > =A0 =A0 } > - =A0 =A0if (!p) { > - =A0 =A0 =A0 =A0*snap =3D '\0'; > + =A0 =A0if (ret < 0 || !p) { > =A0 =A0 =A0 =A0 goto done; > =A0 =A0 } > > - =A0 =A0ret =3D qemu_rbd_next_tok(snap, snap_len, p, '\0', "snap name", = &p); > + =A0 =A0ret =3D qemu_rbd_next_tok(conf, conf_len, p, '\0', "configuratio= n", &p); > > =A0done: > =A0 =A0 qemu_free(buf); > =A0 =A0 return ret; > =A0} > > +static int qemu_rbd_set_conf(rados_t cluster, const char *conf) > +{ > + =A0 =A0char *p, *buf; > + =A0 =A0char name[RBD_MAX_CONF_NAME_SIZE]; > + =A0 =A0char value[RBD_MAX_CONF_VAL_SIZE]; > + =A0 =A0int ret =3D 0; > + > + =A0 =A0buf =3D qemu_strdup(conf); > + =A0 =A0p =3D buf; > + > + =A0 =A0while (p) { > + =A0 =A0 =A0 =A0ret =3D qemu_rbd_next_tok(name, sizeof(name), p, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'=3D', "= conf option name", &p); > + =A0 =A0 =A0 =A0if (ret < 0) { > + =A0 =A0 =A0 =A0 =A0 =A0break; > + =A0 =A0 =A0 =A0} > + > + =A0 =A0 =A0 =A0if (!p) { > + =A0 =A0 =A0 =A0 =A0 =A0error_report("conf option %s has no value", name= ); > + =A0 =A0 =A0 =A0 =A0 =A0ret =3D -EINVAL; > + =A0 =A0 =A0 =A0 =A0 =A0break; > + =A0 =A0 =A0 =A0} > + > + =A0 =A0 =A0 =A0ret =3D qemu_rbd_next_tok(value, sizeof(value), p, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0':', "co= nf option value", &p); > + =A0 =A0 =A0 =A0if (ret < 0) { > + =A0 =A0 =A0 =A0 =A0 =A0break; > + =A0 =A0 =A0 =A0} > + > + =A0 =A0 =A0 =A0if (strncmp(name, "conf", strlen("conf"))) { > + =A0 =A0 =A0 =A0 =A0 =A0ret =3D rados_conf_set(cluster, name, value); > + =A0 =A0 =A0 =A0 =A0 =A0if (ret < 0) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0error_report("invalid conf option %s", n= ame); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D -EINVAL; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > + =A0 =A0 =A0 =A0 =A0 =A0} > + =A0 =A0 =A0 =A0} else { > + =A0 =A0 =A0 =A0 =A0 =A0ret =3D rados_conf_read_file(cluster, value); > + =A0 =A0 =A0 =A0 =A0 =A0if (ret < 0) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0error_report("error reading conf file %s= ", value); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > + =A0 =A0 =A0 =A0 =A0 =A0} > + =A0 =A0 =A0 =A0} > + =A0 =A0} > + > + =A0 =A0qemu_free(buf); > + =A0 =A0return ret; > +} > + > =A0static int qemu_rbd_create(const char *filename, QEMUOptionParameter *= options) > =A0{ > =A0 =A0 int64_t bytes =3D 0; > @@ -164,6 +225,7 @@ static int qemu_rbd_create(const char *filename, QEMU= OptionParameter *options) > =A0 =A0 char pool[RBD_MAX_POOL_NAME_SIZE]; > =A0 =A0 char name[RBD_MAX_IMAGE_NAME_SIZE]; > =A0 =A0 char snap_buf[RBD_MAX_SNAP_NAME_SIZE]; > + =A0 =A0char conf[RBD_MAX_CONF_SIZE]; > =A0 =A0 char *snap =3D NULL; > =A0 =A0 rados_t cluster; > =A0 =A0 rados_ioctx_t io_ctx; > @@ -171,7 +233,8 @@ static int qemu_rbd_create(const char *filename, QEMU= OptionParameter *options) > > =A0 =A0 if (qemu_rbd_parsename(filename, pool, sizeof(pool), > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0snap_buf, sizeof(s= nap_buf), > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 name, sizeof(name))= < 0) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 name, sizeof(name), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 conf, sizeof(conf))= < 0) { > =A0 =A0 =A0 =A0 return -EINVAL; > =A0 =A0 } > =A0 =A0 if (snap_buf[0] !=3D '\0') { > @@ -204,8 +267,17 @@ static int qemu_rbd_create(const char *filename, QEM= UOptionParameter *options) > =A0 =A0 =A0 =A0 return -EIO; > =A0 =A0 } > > - =A0 =A0if (rados_conf_read_file(cluster, NULL) < 0) { > - =A0 =A0 =A0 =A0error_report("error reading config file"); > + =A0 =A0if (strstr(conf, "conf=3D") =3D=3D NULL) { > + =A0 =A0 =A0 =A0if (rados_conf_read_file(cluster, NULL) < 0) { > + =A0 =A0 =A0 =A0 =A0 =A0error_report("error reading config file"); > + =A0 =A0 =A0 =A0 =A0 =A0rados_shutdown(cluster); > + =A0 =A0 =A0 =A0 =A0 =A0return -EIO; > + =A0 =A0 =A0 =A0} > + =A0 =A0} > + > + =A0 =A0if (conf[0] !=3D '\0' && > + =A0 =A0 =A0 =A0qemu_rbd_set_conf(cluster, conf) < 0) { > + =A0 =A0 =A0 =A0error_report("error setting config options"); > =A0 =A0 =A0 =A0 rados_shutdown(cluster); > =A0 =A0 =A0 =A0 return -EIO; > =A0 =A0 } > @@ -315,11 +387,13 @@ static int qemu_rbd_open(BlockDriverState *bs, cons= t char *filename, int flags) > =A0 =A0 BDRVRBDState *s =3D bs->opaque; > =A0 =A0 char pool[RBD_MAX_POOL_NAME_SIZE]; > =A0 =A0 char snap_buf[RBD_MAX_SNAP_NAME_SIZE]; > + =A0 =A0char conf[RBD_MAX_CONF_SIZE]; > =A0 =A0 int r; > > =A0 =A0 if (qemu_rbd_parsename(filename, pool, sizeof(pool), > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0snap_buf, sizeof(s= nap_buf), > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 s->name, sizeof(s->= name)) < 0) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 s->name, sizeof(s->= name), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 conf, sizeof(conf))= < 0) { > =A0 =A0 =A0 =A0 return -EINVAL; > =A0 =A0 } > =A0 =A0 s->snap =3D NULL; > @@ -333,11 +407,22 @@ static int qemu_rbd_open(BlockDriverState *bs, cons= t char *filename, int flags) > =A0 =A0 =A0 =A0 return r; > =A0 =A0 } > > - =A0 =A0r =3D rados_conf_read_file(s->cluster, NULL); > - =A0 =A0if (r < 0) { > - =A0 =A0 =A0 =A0error_report("error reading config file"); > - =A0 =A0 =A0 =A0rados_shutdown(s->cluster); > - =A0 =A0 =A0 =A0return r; > + =A0 =A0if (strstr(conf, "conf=3D") =3D=3D NULL) { > + =A0 =A0 =A0 =A0r =3D rados_conf_read_file(s->cluster, NULL); > + =A0 =A0 =A0 =A0if (r < 0) { > + =A0 =A0 =A0 =A0 =A0 =A0error_report("error reading config file"); > + =A0 =A0 =A0 =A0 =A0 =A0rados_shutdown(s->cluster); > + =A0 =A0 =A0 =A0 =A0 =A0return r; > + =A0 =A0 =A0 =A0} > + =A0 =A0} > + > + =A0 =A0if (conf[0] !=3D '\0') { > + =A0 =A0 =A0 =A0r =3D qemu_rbd_set_conf(s->cluster, conf); > + =A0 =A0 =A0 =A0if (r < 0) { > + =A0 =A0 =A0 =A0 =A0 =A0error_report("error setting config options"); > + =A0 =A0 =A0 =A0 =A0 =A0rados_shutdown(s->cluster); > + =A0 =A0 =A0 =A0 =A0 =A0return r; > + =A0 =A0 =A0 =A0} > =A0 =A0 } > > =A0 =A0 r =3D rados_connect(s->cluster); > -- > 1.7.2.3 > > >