From patchwork Fri Apr 26 14:52:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2494041 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 2E8A73FC64 for ; Fri, 26 Apr 2013 14:52:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753639Ab3DZOwT (ORCPT ); Fri, 26 Apr 2013 10:52:19 -0400 Received: from mail-ia0-f180.google.com ([209.85.210.180]:54917 "EHLO mail-ia0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751301Ab3DZOwT (ORCPT ); Fri, 26 Apr 2013 10:52:19 -0400 Received: by mail-ia0-f180.google.com with SMTP id t4so2799260iag.11 for ; Fri, 26 Apr 2013 07:52:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=ymzvwy8JALdmYn57Ju90JZ+5FbiogkPeWy8kf09LMsY=; b=cGoxWPUCMHUPYVyb+vIgwwKD1nn9n40WgJ4K7f3u1hHyLc1QIBis8n66Ku+SVDcbRW 8IU67CqfXCzdxZYpwxwVLxWFrC0kxAH1jHA2YvTSHZE06tLE7rVfARBLDYd9r4ipbaNy 4gduuxXX61YmPLim3varfEbVSEjFoPGI1Zj3YQTaoLs6TqDnzxOERWgf6TTynv65H4+r /rz+6V9CGOtm8Ko0pNsAf/W1VBPKJefzSonW/ZrR2e0Kv2rry1uELf7HB2EexDwrhJwt wSL6+T9OZxtnn9bgq3E8mKxjslaBljQ0XzdLenqPNYDsADFaFKrXIc8Pm1o6+b96bIUk LwiQ== X-Received: by 10.50.50.195 with SMTP id e3mr2133269igo.51.1366987938489; Fri, 26 Apr 2013 07:52:18 -0700 (PDT) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPSA id p10sm484827igj.5.2013.04.26.07.52.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Apr 2013 07:52:17 -0700 (PDT) Message-ID: <517A94A0.3010104@inktank.com> Date: Fri, 26 Apr 2013 09:52:16 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 1/4] rbd: have rbd_dev_image_id() set format 1 image id References: <517A945B.9040304@inktank.com> In-Reply-To: <517A945B.9040304@inktank.com> X-Gm-Message-State: ALoCoQlA3Exa+CrqRsC+up/qUCSgHmMPVYLj6gMruhXC9iuXxcAr1PVRFVorZ2aPqRHkqSs2kTVN Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Currently, rbd_dev_probe() assumes that any error returned by rbd_dev_image_id() is most likely -ENOENT, and responds by calling the format 1 probe routine, rbd_dev_v1_probe(). Then, at the top of rbd_dev_v1_probe(), an empty string is allocated for the image id. This is sort of unbalanced. Fix this by having rbd_dev_image_id() look for -ENOENT from its "get_id" method call. If that is seen, have it allocate the empty string there rather than depending on rbd_dev_v1_probe() to do it. Also drop a redundant hunk of code in rbd_dev_image_id(). Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) * When probing a parent image, the image id is already @@ -4511,24 +4506,28 @@ static int rbd_dev_image_id(struct rbd_device *rbd_dev) goto out; } + /* If it doesn't exist we'll assume it's a format 1 image */ + ret = rbd_obj_method_sync(rbd_dev, object_name, "rbd", "get_id", NULL, 0, response, RBD_IMAGE_ID_LEN_MAX, NULL); dout("%s: rbd_obj_method_sync returned %d\n", __func__, ret); - if (ret < 0) - goto out; + if (ret == -ENOENT) { + image_id = kstrdup("", GFP_KERNEL); + ret = image_id ? 0 : -ENOMEM; + } else if (ret > sizeof (__le32)) { + void *p = response; - p = response; - rbd_dev->spec->image_id = ceph_extract_encoded_string(&p, - p + ret, + image_id = ceph_extract_encoded_string(&p, p + ret, NULL, GFP_NOIO); - ret = 0; - - if (IS_ERR(rbd_dev->spec->image_id)) { - ret = PTR_ERR(rbd_dev->spec->image_id); - rbd_dev->spec->image_id = NULL; + ret = IS_ERR(image_id) ? PTR_ERR(image_id) : 0; } else { - dout("image_id is %s\n", rbd_dev->spec->image_id); + ret = -EINVAL; + } + + if (!ret) { + rbd_dev->spec->image_id = image_id; + dout("image_id is %s\n", image_id); } out: kfree(response); @@ -4542,12 +4541,6 @@ static int rbd_dev_v1_probe(struct rbd_device *rbd_dev) int ret; size_t size; - /* Version 1 images have no id; empty string is used */ - - rbd_dev->spec->image_id = kstrdup("", GFP_KERNEL); - if (!rbd_dev->spec->image_id) - return -ENOMEM; - /* Record the header object name for this rbd image. */ size = strlen(rbd_dev->spec->image_name) + sizeof (RBD_SUFFIX); @@ -4794,9 +4787,13 @@ static int rbd_dev_probe(struct rbd_device *rbd_dev) */ ret = rbd_dev_image_id(rbd_dev); if (ret) - ret = rbd_dev_v1_probe(rbd_dev); - else + return ret; + + rbd_assert(rbd_dev->spec->image_id); + if (*rbd_dev->spec->image_id) ret = rbd_dev_v2_probe(rbd_dev); + else + ret = rbd_dev_v1_probe(rbd_dev); if (ret) { dout("probe failed, returning %d\n", ret); diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 9e38967..0774ae1 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -4476,12 +4476,7 @@ static int rbd_dev_image_id(struct rbd_device *rbd_dev) size_t size; char *object_name; void *response; - void *p; - - /* If we already have it we don't need to look it up */ - - if (rbd_dev->spec->image_id) - return 0; + char *image_id; /*