From patchwork Fri Sep 7 15:45:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1423581 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 666F23FC85 for ; Fri, 7 Sep 2012 15:45:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752249Ab2IGPpG (ORCPT ); Fri, 7 Sep 2012 11:45:06 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:36790 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751017Ab2IGPpF (ORCPT ); Fri, 7 Sep 2012 11:45:05 -0400 Received: by mail-iy0-f174.google.com with SMTP id k25so3327563iah.19 for ; Fri, 07 Sep 2012 08:45:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=VB4qeiDbzqBNVbrWsuYY73aM9pVDmAY49Z1JZ3FMGuQ=; b=Pi9uRi32SH1JWloptzQ01AqM6Sq9hBGbDJDEeX6vK2hXqzvOIQxThv9h3XLTN5OasT lfdiICotuI1F17NAgd4vg3HJwajllDq3J4b59JhG2lCHFeXKDW4+rx464XB3luUNZhj9 FWV38BT0lctTM4gH4+JQLAWYz0TjTNrYvy6OHxaSnk0lQWTZ/X4jBl3maZ964bDG/hj4 OvCvaRM3EWzA1dBaBhWSbBfnCNOa1vwvqECpSK4jmXT3rgvgYVqsKXvAHIfCLFe3PinQ 3auKv7yfGqfETeDPOuaab67pf0IRPAi8glfw8ybObqRxL5A4QmKdsdw+rEr/4GPdfpke lzWA== Received: by 10.50.51.234 with SMTP id n10mr9435628igo.74.1347032704765; Fri, 07 Sep 2012 08:45:04 -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 ESMTPS id ch4sm8543942igb.2.2012.09.07.08.45.02 (version=SSLv3 cipher=OTHER); Fri, 07 Sep 2012 08:45:03 -0700 (PDT) Message-ID: <504A167D.7000405@inktank.com> Date: Fri, 07 Sep 2012 10:45:01 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 5/9] rbd: defer setting device id References: <504A152E.4000905@inktank.com> In-Reply-To: <504A152E.4000905@inktank.com> X-Gm-Message-State: ALoCoQmdc1jAOBk4/fENSNb+/udiqikoJNjBPDGessy+rQ6/kFTSsWeKp9WI0yE+XpnTormXDdcl Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Hold off setting the device id and formatting the device name in rbd_add() until just before it's needed. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 89d8ed7..53e5308 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -2549,10 +2549,10 @@ static ssize_t rbd_add(struct bus_type *bus, options = kmalloc(count, GFP_KERNEL); if (!options) - goto err_nomem; + goto err_out_mem; rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL); if (!rbd_dev) - goto err_nomem; + goto err_out_mem; /* static rbd_device initialization */ spin_lock_init(&rbd_dev->lock); @@ -2562,25 +2562,17 @@ static ssize_t rbd_add(struct bus_type *bus, down_write(&rbd_dev->header_rwsem); - /* generate unique id: find highest unique id, add one */ - rbd_dev_id_get(rbd_dev); - - /* Fill in the device name, now that we have its id. */ - BUILD_BUG_ON(DEV_NAME_LEN - < sizeof (RBD_DRV_NAME) + MAX_INT_FORMAT_WIDTH); - sprintf(rbd_dev->name, "%s%d", RBD_DRV_NAME, rbd_dev->dev_id); - /* parse add command */ snap_name = rbd_add_parse_args(rbd_dev, buf, &mon_addrs, &mon_addrs_size, options, count); if (IS_ERR(snap_name)) { rc = PTR_ERR(snap_name); - goto err_put_id; + goto err_out_mem; } rc = rbd_get_client(rbd_dev, mon_addrs, mon_addrs_size - 1, options); if (rc < 0) - goto err_put_id; + goto err_out_args; /* pick the pool */ osdc = &rbd_dev->rbd_client->client->osdc; @@ -2612,10 +2604,19 @@ static ssize_t rbd_add(struct bus_type *bus, if (rc) goto err_out_header; - /* register our block device */ + /* generate unique id: find highest unique id, add one */ + rbd_dev_id_get(rbd_dev); + + /* Fill in the device name, now that we have its id. */ + BUILD_BUG_ON(DEV_NAME_LEN + < sizeof (RBD_DRV_NAME) + MAX_INT_FORMAT_WIDTH); + sprintf(rbd_dev->name, "%s%d", RBD_DRV_NAME, rbd_dev->dev_id); + + /* Get our block major device number. */ + rc = register_blkdev(0, rbd_dev->name); if (rc < 0) - goto err_out_header; + goto err_out_id; rbd_dev->major = rc; rc = rbd_bus_add_dev(rbd_dev); @@ -2663,20 +2664,19 @@ err_out_bus: err_out_blkdev: unregister_blkdev(rbd_dev->major, rbd_dev->name); +err_out_id: + rbd_dev_id_put(rbd_dev); err_out_header: rbd_header_free(&rbd_dev->header); err_out_client: kfree(rbd_dev->header_name); rbd_put_client(rbd_dev); -err_put_id: - if (rbd_dev->pool_name) { - kfree(rbd_dev->mapping.snap_name); - kfree(rbd_dev->image_name); - kfree(rbd_dev->pool_name); - } - rbd_dev_id_put(rbd_dev); +err_out_args: + kfree(rbd_dev->mapping.snap_name); + kfree(rbd_dev->image_name); + kfree(rbd_dev->pool_name); up_write(&rbd_dev->header_rwsem); -err_nomem: +err_out_mem: kfree(rbd_dev); kfree(options);