From patchwork Tue Feb 14 20:11:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 9572781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BF79660578 for ; Tue, 14 Feb 2017 20:13:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB784271BC for ; Tue, 14 Feb 2017 20:13:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B090C28417; Tue, 14 Feb 2017 20:13:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55021271BC for ; Tue, 14 Feb 2017 20:13:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755045AbdBNUNA (ORCPT ); Tue, 14 Feb 2017 15:13:00 -0500 Received: from mail-qk0-f193.google.com ([209.85.220.193]:33458 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754829AbdBNUMo (ORCPT ); Tue, 14 Feb 2017 15:12:44 -0500 Received: by mail-qk0-f193.google.com with SMTP id 11so20554627qkl.0 for ; Tue, 14 Feb 2017 12:12:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ON4xTaIYErDYcPhIZuJtWDCj1mqV0OuQMeK8KThYij8=; b=Nv0hqzweiQ38T9TghU3Dz9GmuDm8bfjx5Nz1DXvLsiPTIqNygYfKxaV973u5nfE/qm JpV8eVNGvsGh8ljtCexVsLnKhCgvsSeJ5e15qoDXaXgeEyW49XxjUGM+fZNsFXWgYvCe 5eCmga+tM81Hbek7AFWDVTe6jL463eBfsv/NJOKq2SF6xLGsd6iCjVL1TN+D05fpzqEL Es+FsKsfU8zedhkvRfg+RIXtpHGSQ9goAlDt72VAA7oAupleawEub+AXjX9rEK1wDzgJ E52fBTVvNGLzJNQ1TGVScW4aGuq+5GPT9/C/2FBfWWl/2Zr5G7JxnxsSs1b84NuyAQGW 0ofA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ON4xTaIYErDYcPhIZuJtWDCj1mqV0OuQMeK8KThYij8=; b=KDEtbtgVWX/7stGppPmnOZ0k8ycd7g3Fwy8cIw4mBqPEQuMkoCv+npqf4t2kRVBMkg 3mRP9n/EWUFqhv8Er69OeaTS0J+s/mw3mJi7sxXwLfLXS3xykGJYCCQH3E7TFTdOUM+Z ej5SJetwd8dfctt6VWDhWqS31TTROkK15240E01tUF01pKmFTjxZAWm27RM65d7pJFSI 0QALfN35yz1vEspyDcgdEyINpr/1PGUA7by7LlgVYJ9VWPBx+U0u6sLtSOOQTHIKvmSf Jj5Pt1U9RuOzUoYs4ruCH/zvL0dyPzC5qsqBpTuWomvjy8JOkF6zWcFVSIsF3hEXJHYD BT0Q== X-Gm-Message-State: AMke39k3TZKIH6nyBUoLjMAf2s/+hGzWwZ4g+qceR2PzD+lsLG/3vSQ01ds0RbYnUUnJdw== X-Received: by 10.55.110.6 with SMTP id j6mr32550314qkc.92.1487103162970; Tue, 14 Feb 2017 12:12:42 -0800 (PST) Received: from dhcp-1-235.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id w138sm939945qka.27.2017.02.14.12.12.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Feb 2017 12:12:42 -0800 (PST) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Cc: Alex Elder Subject: [PATCH 09/15] rbd: introduce rbd_init_layout() Date: Tue, 14 Feb 2017 21:11:58 +0100 Message-Id: <1487103124-2974-10-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1487103124-2974-1-git-send-email-idryomov@gmail.com> References: <1487103124-2974-1-git-send-email-idryomov@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Rather than initializing layout fields with some made up values in __rbd_dev_create(), move the initialization into rbd_init_layout() and call it after the header is actually populated. Signed-off-by: Ilya Dryomov --- drivers/block/rbd.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index f2f52b7db33d..aac1d3259738 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -978,6 +978,21 @@ static u32 rbd_obj_bytes(struct rbd_image_header *header) return 1U << header->obj_order; } +static void rbd_init_layout(struct rbd_device *rbd_dev) +{ + if (rbd_dev->header.stripe_unit == 0 || + rbd_dev->header.stripe_count == 0) { + rbd_dev->header.stripe_unit = rbd_obj_bytes(&rbd_dev->header); + rbd_dev->header.stripe_count = 1; + } + + rbd_dev->layout.stripe_unit = rbd_dev->header.stripe_unit; + rbd_dev->layout.stripe_count = rbd_dev->header.stripe_count; + rbd_dev->layout.object_size = rbd_obj_bytes(&rbd_dev->header); + rbd_dev->layout.pool_id = rbd_dev->spec->pool_id; + RCU_INIT_POINTER(rbd_dev->layout.pool_ns, NULL); +} + /* * Fill an rbd image header with information from the given format 1 * on-disk header. @@ -1053,6 +1068,7 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev, if (first_time) { header->object_prefix = object_prefix; header->obj_order = ondisk->options.order; + rbd_init_layout(rbd_dev); } else { ceph_put_snap_context(header->snapc); kfree(header->snap_names); @@ -4804,12 +4820,6 @@ static struct rbd_device *__rbd_dev_create(struct rbd_client *rbdc, rbd_dev->rbd_client = rbdc; rbd_dev->spec = spec; - rbd_dev->layout.stripe_unit = 1 << RBD_MAX_OBJ_ORDER; - rbd_dev->layout.stripe_count = 1; - rbd_dev->layout.object_size = 1 << RBD_MAX_OBJ_ORDER; - rbd_dev->layout.pool_id = spec->pool_id; - RCU_INIT_POINTER(rbd_dev->layout.pool_ns, NULL); - return rbd_dev; } @@ -5848,12 +5858,13 @@ static int rbd_dev_v2_header_onetime(struct rbd_device *rbd_dev) goto out_err; } + rbd_init_layout(rbd_dev); return 0; + out_err: rbd_dev->header.features = 0; kfree(rbd_dev->header.object_prefix); rbd_dev->header.object_prefix = NULL; - return ret; }