From patchwork Fri Sep 7 14:50:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1423081 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 5DAC33FC33 for ; Fri, 7 Sep 2012 14:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933204Ab2IGOuX (ORCPT ); Fri, 7 Sep 2012 10:50:23 -0400 Received: from mail-ie0-f174.google.com ([209.85.223.174]:54481 "EHLO mail-ie0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932990Ab2IGOuW (ORCPT ); Fri, 7 Sep 2012 10:50:22 -0400 Received: by mail-ie0-f174.google.com with SMTP id e11so5147910iej.19 for ; Fri, 07 Sep 2012 07:50:22 -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=gU/s452CF+YlXDanIQ5wWDnOwBGwzcMorBrPtel1LYY=; b=mzIhS+TrcB32F1tGgOqQh6mHydooQR+VNlKainpAtPB6vDACb3edzWEjfCV0v4RZyn KLUJC14UAigAWbjRVjT/XPN2Gt2kEr52dBTEjYFkO3aYJyOYFYkQMBhrIyeDa0rF+3jE db4bl4/v3tCMZeihR2cl235NO2/6KwBlmZhIsoi2esRm2nNfFXFZP5UUkJWZHCj0uH1W ON9gzBXGPdYlHjaiCl9LWZRc/7LkkpKl0y3WGTuxBmeSMh//ckj0kb/76v/BVn6kcrds AQiFqO7I48ZH/wQjvf5i3wOOtsWSIvfACYtjvduIXDEq03SxgfyZa7M347ThzdjuwICj 3mVA== Received: by 10.50.214.1 with SMTP id nw1mr9096065igc.2.1347029422596; Fri, 07 Sep 2012 07:50:22 -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 ng5sm8373592igc.0.2012.09.07.07.50.21 (version=SSLv3 cipher=OTHER); Fri, 07 Sep 2012 07:50:21 -0700 (PDT) Message-ID: <504A09AD.80905@inktank.com> Date: Fri, 07 Sep 2012 09:50:21 -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 2/4] rbd: expand lock protection in rbd_add() References: <504A090F.7000706@inktank.com> In-Reply-To: <504A090F.7000706@inktank.com> X-Gm-Message-State: ALoCoQkmWvIuK4h6KJW+kAbO9y8iwISfDmv821BOIF2hMZjbFbslxSM3nLYbdWhhqDSpvH4Lvu2o Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Expand the region of code in rbd_add() protected by the header semaphore to include the complete initialization sequence. It may not be strictly necessary, but it doesn't hurt. And with the upcoming changes to the order of steps here this offers easy protection. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 214c937..6af09f1 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -2553,6 +2553,8 @@ static ssize_t rbd_add(struct bus_type *bus, INIT_LIST_HEAD(&rbd_dev->snaps); init_rwsem(&rbd_dev->header_rwsem); + down_write(&rbd_dev->header_rwsem); + /* generate unique id: find highest unique id, add one */ rbd_dev_id_get(rbd_dev); @@ -2598,18 +2600,17 @@ static ssize_t rbd_add(struct bus_type *bus, /* contact OSD, request size info about the object being mapped */ rc = rbd_read_header(rbd_dev, &rbd_dev->header); if (rc) - goto err_out_bus; + goto err_out_unlock; - /* no need to lock here, as rbd_dev is not registered yet */ rc = rbd_dev_snap_devs_update(rbd_dev); if (rc) - goto err_out_bus; + goto err_out_unlock; - down_write(&rbd_dev->header_rwsem); rc = rbd_header_set_snap(rbd_dev, snap_name); - up_write(&rbd_dev->header_rwsem); if (rc) - goto err_out_bus; + goto err_out_unlock; + + up_write(&rbd_dev->header_rwsem); /* Set up the blkdev mapping. */ @@ -2630,6 +2631,8 @@ static ssize_t rbd_add(struct bus_type *bus, return count; +err_out_unlock: + up_write(&rbd_dev->header_rwsem); err_out_bus: /* this will also clean up rest of rbd_dev stuff */ @@ -2649,6 +2652,7 @@ err_put_id: kfree(rbd_dev->pool_name); } rbd_dev_id_put(rbd_dev); + up_write(&rbd_dev->header_rwsem); err_nomem: kfree(rbd_dev); kfree(options);