From patchwork Thu Mar 24 22:51:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Durgin X-Patchwork-Id: 660671 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2OMpm7b018002 for ; Thu, 24 Mar 2011 22:51:48 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934180Ab1CXWvm (ORCPT ); Thu, 24 Mar 2011 18:51:42 -0400 Received: from mail.hq.newdream.net ([66.33.206.127]:37530 "EHLO mail.hq.newdream.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933783Ab1CXWvl (ORCPT ); Thu, 24 Mar 2011 18:51:41 -0400 Received: from mail.hq.newdream.net (localhost [127.0.0.1]) by mail.hq.newdream.net (Postfix) with ESMTP id 29B6BC064; Thu, 24 Mar 2011 15:51:41 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=dreamhost.com; h=message-id :date:from:mime-version:to:cc:subject:content-type :content-transfer-encoding; q=dns; s=dreamhost.com; b=OIuIZte3xt o2MfF1eGQSf/7Kye/GfgB/J44hkyjWrAqmbfkJSr9X2M3Vt37Ykg/Yo3FPxDlidd +ODMvsVL71G16IHYvS64DKvPAAuLJnnxhpAL5he+CRnNGc8Et/55C37ZOWts1j7S t90vGrlmq3DMfHMmHT/9INKuGMfXAtp8Y= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=dreamhost.com; h= message-id:date:from:mime-version:to:cc:subject:content-type :content-transfer-encoding; s=dreamhost.com; bh=AdXw+UtEXu5M/McD KlVbmEGUBuo=; b=fB60GHxuk8fJvdOXaxRqi+dllD0iQs2IE3AJpiRdbAS5VIrX 36i25veZZVR2MIcfJiLnrW8WKZxc1Zy/OOnV+XEvuzMtINif6w3mSaM0G1o8ihtk gXtAXXKV7yuQkC7j0aJ4/G8gYNbk9Mv2y4NgbzHI/5O27x4mSVK6GNRkHco= Received: from [10.0.1.9] (ip-66-33-206-8.dreamhost.com [66.33.206.8]) by mail.hq.newdream.net (Postfix) with ESMTP id 042FBC063; Thu, 24 Mar 2011 15:51:41 -0700 (PDT) Message-ID: <4D8BCAFC.5090904@dreamhost.com> Date: Thu, 24 Mar 2011 15:51:40 -0700 From: Josh Durgin User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100916 Lanikai/3.1.4 MIME-Version: 1.0 To: kvm@vger.kernel.org, qemu-devel@nongnu.org CC: ceph-devel@vger.kernel.org Subject: [PATCH 2/2] rbd: allow configuration of rados from the rbd filename Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 24 Mar 2011 22:51:49 +0000 (UTC) diff --git a/block/rbd.c b/block/rbd.c index 5c3287e..b146fcb 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -22,13 +22,16 @@ /* * When specifying the image filename use: * - * rbd:poolname/devicename + * rbd:poolname/devicename[@snapshotname][:option1=value1[:option2=value2...]] * * poolname must be the name of an existing rados pool * * devicename is the basename for all objects used to * emulate the raw device. * + * 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. + * * Metadata information (image size, ...) is stored in an * object with the name "devicename.rbd". * @@ -121,7 +124,8 @@ static int qemu_rbd_next_tok(char *dst, int dst_len, static int qemu_rbd_parsename(const char *filename, char *pool, int pool_len, char *snap, int snap_len, - char *name, int name_len) + char *name, int name_len, + char *conf, int conf_len) { const char *start; char *p, *buf; @@ -133,28 +137,82 @@ static int qemu_rbd_parsename(const char *filename, buf = qemu_strdup(start); p = buf; + *snap = '\0'; + *conf = '\0'; ret = qemu_rbd_next_tok(pool, pool_len, p, '/', "pool name", &p); if (ret < 0 || !p) { ret = -EINVAL; goto done; } - ret = qemu_rbd_next_tok(name, name_len, p, '@', "object name", &p); - if (ret < 0) { - goto done; + + if (strchr(p, '@')) { + ret = qemu_rbd_next_tok(name, name_len, p, '@', "object name", &p); + if (ret < 0) { + goto done; + } + ret = qemu_rbd_next_tok(snap, snap_len, p, ':', "snap name", &p); + } else { + ret = qemu_rbd_next_tok(name, name_len, p, ':', "object name", &p); } - if (!p) { - *snap = '\0'; + if (ret < 0 || !p) { goto done; } - ret = qemu_rbd_next_tok(snap, snap_len, p, '\0', "snap name", &p); + ret = qemu_rbd_next_tok(conf, conf_len, p, '\0', "configuration", &p); done: qemu_free(buf); return ret; } +static int qemu_rbd_set_conf(rados_t cluster, const char *conf) +{ + char *p, *buf; + char name[RBD_MAX_CONF_NAME_SIZE]; + char value[RBD_MAX_CONF_VAL_SIZE]; + int ret = 0; + + buf = qemu_strdup(conf); + p = buf; + + while (p) { + ret = qemu_rbd_next_tok(name, sizeof(name), p, '=', "conf option name", &p); + if (ret < 0) { + break; + } + + if (!p) { + error_report("conf option %s has no value", name); + ret = -EINVAL; + break; + } + + ret = qemu_rbd_next_tok(value, sizeof(value), p, ':', "conf option value", &p); + if (ret < 0) { + break; + } + + if (strncmp(name, "conf", strlen("conf"))) { + ret = rados_conf_set(cluster, name, value); + if (ret < 0) { + error_report("invalid conf option %s", name); + ret = -EINVAL; + break; + } + } else { + ret = rados_conf_read_file(cluster, value); + if (ret < 0) { + error_report("error reading conf file %s", value); + break; + } + } + } + + qemu_free(buf); + return ret; +} + static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options) { int64_t bytes = 0; @@ -163,6 +221,7 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options) char pool[RBD_MAX_POOL_NAME_SIZE]; char name[RBD_MAX_IMAGE_NAME_SIZE]; char snap_buf[RBD_MAX_SNAP_NAME_SIZE];