From patchwork Wed Feb 6 19:40:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 2107011 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by patchwork1.kernel.org (Postfix) with ESMTP id 2F2C13FCFC for ; Wed, 6 Feb 2013 19:54:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r16JpU1b023853; Wed, 6 Feb 2013 14:51:31 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r16Jognl002125 for ; Wed, 6 Feb 2013 14:50:42 -0500 Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.20]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r16Jogmk019538; Wed, 6 Feb 2013 14:50:42 -0500 Received: from mail-oa0-f50.google.com (mail-oa0-f50.google.com [209.85.219.50]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r16JofXj014752; Wed, 6 Feb 2013 14:50:41 -0500 Received: by mail-oa0-f50.google.com with SMTP id l20so1914787oag.23 for ; Wed, 06 Feb 2013 11:50:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=SV2/BIhWITa9yRBkMjNs3m4cgevx2AAFv9o3HZ2hhIQ=; b=bKX6N/QWnvXBIf1hidcyDebWFXJatFUa5Bi0yuj4ZjMDEYSP2UtV/ADSgXC6gW1NVW Kop+Tqr+g7jl+x6zMkvuHoDpjZhtt+w0gUzFPC7G2V8uiE62FC0EDvXtBPizS8E1eCJ9 FmfhBz8jYvxeTH+ZjkjrR+5K+IKBB7v9MjP3MfSBNY5QIT4UI2nZNVxtIGt5i11wSB2l 5qBgnZPUUNkhfmi8zm+c8yaBY2iMYQa9G0jQ6ij2bLchTC3ML+zYbO8PNd6f6gtg6kZ5 4sn3CO1icmmktVWvBPaw1BLTk+MTK+mq92qM/EWZBxOPR20pH7kTTazzAFEVpnHUrlg3 RGBg== X-Received: by 10.60.10.226 with SMTP id l2mr17440809oeb.67.1360180240815; Wed, 06 Feb 2013 11:50:40 -0800 (PST) Received: from htj.dyndns.org (c-69-181-251-227.hsd1.ca.comcast.net. [69.181.251.227]) by mx.google.com with ESMTPS id l5sm39989590pax.10.2013.02.06.11.50.39 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 06 Feb 2013 11:50:40 -0800 (PST) From: Tejun Heo To: akpm@linux-foundation.org Date: Wed, 6 Feb 2013 11:40:19 -0800 Message-Id: <1360179649-22465-48-git-send-email-tj@kernel.org> In-Reply-To: <1360179649-22465-1-git-send-email-tj@kernel.org> References: <1360179649-22465-1-git-send-email-tj@kernel.org> X-RedHat-Spam-Score: -3 (BAYES_00, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.20 X-loop: dm-devel@redhat.com Cc: Tejun Heo , dm-devel@redhat.com, linux-kernel@vger.kernel.org, Alasdair Kergon Subject: [dm-devel] [PATCH 47/77] dm: convert to idr_alloc() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com Convert to the much saner new idr interface. Only compile tested. Signed-off-by: Tejun Heo Cc: Alasdair Kergon Cc: dm-devel@redhat.com --- drivers/md/dm.c | 54 +++++++++++++++--------------------------------------- 1 file changed, 15 insertions(+), 39 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index c644eb6..ac74b81 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1801,62 +1801,38 @@ static void free_minor(int minor) */ static int specific_minor(int minor) { - int r, m; + int r; if (minor >= (1 << MINORBITS)) return -EINVAL; - r = idr_pre_get(&_minor_idr, GFP_KERNEL); - if (!r) - return -ENOMEM; - + idr_preload(GFP_KERNEL); spin_lock(&_minor_lock); - if (idr_find(&_minor_idr, minor)) { - r = -EBUSY; - goto out; - } - - r = idr_get_new_above(&_minor_idr, MINOR_ALLOCED, minor, &m); - if (r) - goto out; + r = idr_alloc(&_minor_idr, MINOR_ALLOCED, minor, minor + 1, GFP_NOWAIT); - if (m != minor) { - idr_remove(&_minor_idr, m); - r = -EBUSY; - goto out; - } - -out: spin_unlock(&_minor_lock); - return r; + idr_preload_end(); + if (r < 0) + return r == -ENOSPC ? -EBUSY : r; + return 0; } static int next_free_minor(int *minor) { - int r, m; - - r = idr_pre_get(&_minor_idr, GFP_KERNEL); - if (!r) - return -ENOMEM; + int r; + idr_preload(GFP_KERNEL); spin_lock(&_minor_lock); - r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m); - if (r) - goto out; - - if (m >= (1 << MINORBITS)) { - idr_remove(&_minor_idr, m); - r = -ENOSPC; - goto out; - } - - *minor = m; + r = idr_alloc(&_minor_idr, MINOR_ALLOCED, 0, 1 << MINORBITS, GFP_NOWAIT); -out: spin_unlock(&_minor_lock); - return r; + idr_preload_end(); + if (r < 0) + return r; + *minor = r; + return 0; } static const struct block_device_operations dm_blk_dops;