Return-Path: Received: from mail-wm0-f67.google.com ([74.125.82.67]:34163 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753352AbcGZFds (ORCPT ); Tue, 26 Jul 2016 01:33:48 -0400 Received: by mail-wm0-f67.google.com with SMTP id q128so19668167wma.1 for ; Mon, 25 Jul 2016 22:33:47 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH 2/3] fs: super: switch to using ida_simple_.. functions To: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Message-ID: Date: Tue, 26 Jul 2016 07:33:11 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Ida handling can be much simplified using the ida_simple_.. functions. This also removes the need for an own spinlock. Signed-off-by: Heiner Kallweit --- fs/super.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/fs/super.c b/fs/super.c index 362e765..37de8f5 100644 --- a/fs/super.c +++ b/fs/super.c @@ -880,34 +880,20 @@ void emergency_remount(void) */ static DEFINE_IDA(unnamed_dev_ida); -static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */ int get_anon_bdev(dev_t *p) { int dev; - int error; - retry: - if (ida_pre_get(&unnamed_dev_ida, GFP_ATOMIC) == 0) - return -ENOMEM; - spin_lock(&unnamed_dev_lock); /* Many userspace utilities consider an FSID of 0 invalid. * Always return at least 1 from get_anon_bdev. */ - error = ida_get_new_above(&unnamed_dev_ida, 1, &dev); - spin_unlock(&unnamed_dev_lock); - if (error == -EAGAIN) - /* We raced and lost with another CPU. */ - goto retry; - else if (error) - return -EAGAIN; - - if (dev >= (1 << MINORBITS)) { - spin_lock(&unnamed_dev_lock); - ida_remove(&unnamed_dev_ida, dev); - spin_unlock(&unnamed_dev_lock); + dev = ida_simple_get(&unnamed_dev_ida, 1, 1 << MINORBITS, GFP_ATOMIC); + if (dev == -ENOSPC) return -EMFILE; - } + else if (dev < 0) + return dev; + *p = MKDEV(0, dev & MINORMASK); return 0; } @@ -915,10 +901,7 @@ EXPORT_SYMBOL(get_anon_bdev); void free_anon_bdev(dev_t dev) { - int slot = MINOR(dev); - spin_lock(&unnamed_dev_lock); - ida_remove(&unnamed_dev_ida, slot); - spin_unlock(&unnamed_dev_lock); + ida_simple_remove(&unnamed_dev_ida, MINOR(dev)); } EXPORT_SYMBOL(free_anon_bdev); -- 2.9.0