From patchwork Tue Jul 26 05:33:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9247633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 786A860757 for ; Tue, 26 Jul 2016 05:33:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BC8126223 for ; Tue, 26 Jul 2016 05:33:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60AC8276AE; Tue, 26 Jul 2016 05:33:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1569126223 for ; Tue, 26 Jul 2016 05:33:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753872AbcGZFdt (ORCPT ); Tue, 26 Jul 2016 01:33:49 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=RdpHdIO0e2lszk6DnsKgsKgAMQJ80Iy+pbDM8SiOmWU=; b=J1HbzzIhsbR1R/+j5nOZnb32NZlqogJ/Cl8NoK7XVc7MIO1m8QEEQ4EfkB+NUL8jH4 NNLC5aH3jIDKcZaQERLso2Xu3Wtgzn5yoh9q7y7ddL0pqvYXoo3jdZ2NW2G3aLsc1F5y oX1s2RECVSFN6YgYhEgEsemAuDTlXHDTD1Gmq6dNOEZybblXTZ4AbEdvvQLwdrE3HJ0E OzF3oGZ6KhzW01MftiwMNS8nFs1V0rz6KfXE5AQGfD0hyCOhzacUgzarLnPEC6XNwEYY 2+tXwIif92eju5kac4MoeGvk1nrKQC/Dkk884LZN79PL0Warxq99TptR0yNR/xdlV9gi kTyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=RdpHdIO0e2lszk6DnsKgsKgAMQJ80Iy+pbDM8SiOmWU=; b=DfZij1kklruU/FfUfLXGCEvR2EdrUMZkdCLvPnfRLLjM9X+/qFvC5eln0gOq4Yo+N1 6LZb1CbUuHmA3CxHyT7aAWrsQ4RCunW9P2tDSqdAGyOubpMmQoduffk0vxP1Pout8jkt Ha+xRIHf2RUDQMJyp9pTtGtMKbG2VH4nQgIKJ4/vXIcVJUKLq0OsbNITTeXe5THoDvH5 cTfKTFR4w0O571e0kEO8U9sCSS9Msi+FMeh+Y4O8l70hkN4G0leL3mZSmDu6Nky4PeDT 6xAJak3qT+2FzFnePKbKQvmY1kGwKJtjK27ScLE8Rn9ZqIRMu2f/vBMSSNl83hsTrCoO 9B8w== X-Gm-Message-State: ALyK8tKOsSoJbdoR3//1cATMb5yqJy+68F/7xhGlFP6U4SOj2kLIFmQa2Ag3H6bfsJr9IA== X-Received: by 10.28.26.69 with SMTP id a66mr41380147wma.8.1469511226386; Mon, 25 Jul 2016 22:33:46 -0700 (PDT) Received: from ?IPv6:2003:62:5f01:4400:f15c:3bb5:5e12:3e94? (p200300625F014400F15C3BB55E123E94.dip0.t-ipconnect.de. [2003:62:5f01:4400:f15c:3bb5:5e12:3e94]) by smtp.googlemail.com with ESMTPSA id p4sm9756043wjq.27.2016.07.25.22.33.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jul 2016 22:33:46 -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 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);