From patchwork Fri Aug 24 16:32:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1372111 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 9BF82DF28C for ; Fri, 24 Aug 2012 16:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932620Ab2HXQcS (ORCPT ); Fri, 24 Aug 2012 12:32:18 -0400 Received: from mail-ob0-f174.google.com ([209.85.214.174]:58290 "EHLO mail-ob0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932586Ab2HXQcR (ORCPT ); Fri, 24 Aug 2012 12:32:17 -0400 Received: by obbuo13 with SMTP id uo13so4590607obb.19 for ; Fri, 24 Aug 2012 09:32:16 -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=h4bOKKWK3Npl73P7WYzNbzp9hboYN5fNGWGht7eegMk=; b=e7uqek9Pk9zPO4PXVPm2Xc5EMMnBbmLGmrlTRRlPLfnVcUDCh/deYp7TBThiQnpfFC gqcUTfPZMl2WRi4yciW+/i2tzk/SLUO0Xm2w/pJ813/iEmoznmi4RFxGY4Lh6SmqDDSV vpf9brSPMlByzH7xBdnoKM4gbWCuAy1GpOSMOPk9Ck/hwhhn3HLU5SSS/yRrsyJ+pf31 bidWOPziszpcF+KDmFvy9KQjJ8M8nZeHo2+j/PamL0QZNBJdeUmR+CbeYlqFyig0UI8J lTonjKJEB08ivXwxT5fzIlK25tKLtPp2jK6tNTBsAovLmiYrOcCcBxLcVsdyVPhPJAeI eHDQ== Received: by 10.50.94.133 with SMTP id dc5mr2845035igb.16.1345825936614; Fri, 24 Aug 2012 09:32:16 -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 at10sm197283igc.16.2012.08.24.09.32.11 (version=SSLv3 cipher=OTHER); Fri, 24 Aug 2012 09:32:12 -0700 (PDT) Message-ID: <5037AC8B.6070608@inktank.com> Date: Fri, 24 Aug 2012 11:32:11 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 01/11] rbd: handle locking inside __rbd_client_find() References: <5037AB20.4000103@inktank.com> In-Reply-To: <5037AB20.4000103@inktank.com> X-Gm-Message-State: ALoCoQlgJFcGWvM/1Ej3sJLAtRhfKee9ON4qUtIBXuCnDIIwV8f1Cpcg1As6QsZBJcdVpi+YYFxJ Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org There is only one caller of __rbd_client_find(), and it somewhat clumsily gets the appropriate lock and gets a reference to the existing ceph_client structure if it's found. Instead, have that function handle its own locking, and acquire the reference if found while it holds the lock. Drop the underscores from the name because there's no need to signify anything special about this function. Signed-off-by: Alex Elder Reviewed-by: Yehuda Sadeh --- drivers/block/rbd.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 8e6e29e..81b5344 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -322,19 +322,28 @@ out_opt: } /* - * Find a ceph client with specific addr and configuration. + * Find a ceph client with specific addr and configuration. If + * found, bump its reference count. */ -static struct rbd_client *__rbd_client_find(struct ceph_options *ceph_opts) +static struct rbd_client *rbd_client_find(struct ceph_options *ceph_opts) { struct rbd_client *client_node; + bool found = false; if (ceph_opts->flags & CEPH_OPT_NOSHARE) return NULL; - list_for_each_entry(client_node, &rbd_client_list, node) - if (!ceph_compare_options(ceph_opts, client_node->client)) - return client_node; - return NULL; + spin_lock(&rbd_client_list_lock); + list_for_each_entry(client_node, &rbd_client_list, node) { + if (!ceph_compare_options(ceph_opts, client_node->client)) { + kref_get(&client_node->kref); + found = true; + break; + } + } + spin_unlock(&rbd_client_list_lock); + + return found ? client_node : NULL; } /* @@ -416,22 +425,16 @@ static struct rbd_client *rbd_get_client(const char *mon_addr, return ERR_CAST(ceph_opts); } - spin_lock(&rbd_client_list_lock); - rbdc = __rbd_client_find(ceph_opts); + rbdc = rbd_client_find(ceph_opts); if (rbdc) { /* using an existing client */ - kref_get(&rbdc->kref); - spin_unlock(&rbd_client_list_lock); - ceph_destroy_options(ceph_opts); kfree(rbd_opts); return rbdc; } - spin_unlock(&rbd_client_list_lock); rbdc = rbd_client_create(ceph_opts, rbd_opts); - if (IS_ERR(rbdc)) kfree(rbd_opts);