Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp95842imm; Thu, 21 Jun 2018 14:36:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLkhf7GAtEy8N7orjG6p9tw/PpadYkdNYShIUoroLxFIPOkPe6AjwnGAxxqSlOd0zzDsePW X-Received: by 2002:a63:7f51:: with SMTP id p17-v6mr23856149pgn.36.1529616990269; Thu, 21 Jun 2018 14:36:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529616990; cv=none; d=google.com; s=arc-20160816; b=aZRrFoeAmqXsZDvMHZpAt+DbeXoo6oUkj8OiwtIQL04abcldkytu/WuR8Dd51oS00P EalRub6q6cr0FEwJmG6fI72gCBm4Wd6VLV8Ls5QvYKSJFIqifQJQGaweR9GnmXNPW3l8 zn2Z/4b8LIT9kk6dg9fwPiFfRrkvJKOWvWajTJuva72miGBsIEoDroJRYEjJ/kYELFTg TLf+P7ZlrWGYD68PwCRLVYUEphRaFSkuOvgsvy9SLvMJ+npciCxmm2MxX5hVbbwyNipF ert/dfvL3gfd0X6BHahbOKUVroqmCWBr3o4Eax4gKT82LrPtcH+LSx52A3UurFIm5bBw 0qBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=jX4Y14/+hUoeY3uBNX8+NURE5Dtq1h279x5XpbFxCXo=; b=q5M1giDdmUWV676FtM5pbZJ7kFRjr2ruSNPLvN5Vn3iXXPUnG5lwrbikpWtB2r9MU7 oMZv898cY/+IkKW69syXNncxgwpAL9KqJTsP/lcxLUMGJWb9qAf3QwxQRdio6WcUdh7Z 9jCypJogb+IAOUmWNERE/5V09E8eIu+kcbmsOzmiklujHIRL5IySW01rtAj8pgnowq8S bGwaQ1OaJ09BPkP7Tvk2nJ6OmcO1e4Mz2cO1ovviP7KYM7z5wioPMfYLqa7qCzldkm5H iif94v1h8e1fN9Wer2OQsD/12rJBdk9erkWJRKk7pX2FH32j5ihbpuBToNzeobwEf0lC yWfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=OCxuKWyj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a80-v6si5943255pfg.200.2018.06.21.14.36.15; Thu, 21 Jun 2018 14:36:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=OCxuKWyj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933807AbeFUVfG (ORCPT + 99 others); Thu, 21 Jun 2018 17:35:06 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:41738 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933919AbeFUV3G (ORCPT ); Thu, 21 Jun 2018 17:29:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=jX4Y14/+hUoeY3uBNX8+NURE5Dtq1h279x5XpbFxCXo=; b=OCxuKWyjKv7IMO+zmnWFL4RyW O67gRciw66T1kwHuhUOb7ax3BdVCnCl5w771PjrjNYlI+N22awCn4lxLmeH9lYuIXqxJeOhkfKrjI 5e6HczhgOb+zO/HGjUjgmLrzapQ7VKkuVY73FhdVeIDm/EkpKrJt+ggMuYgEzYGmfjEkQ/AHow3Nj Zg9KM1qtzrkgymqy2uGpB75QUVVQWAUCBj/Txk8gbwl3onK4o3t1I4hKT5SJEFlliyTxn9h/oENCm DuV5KzoYYi2rJapxrmTA/l9lB3WDtp0dbI5cq7OGKHaMm9iuNQE7UU0D53GzYIuKhcMMRw2FBdpjT SMdXUWBCQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fW78c-0001al-A8; Thu, 21 Jun 2018 21:29:06 +0000 From: Matthew Wilcox To: linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Alexander Viro , linux-fsdevel@vger.kernel.org Subject: [PATCH 05/26] fs: Convert unnamed_dev_ida to new API Date: Thu, 21 Jun 2018 14:28:14 -0700 Message-Id: <20180621212835.5636-6-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180621212835.5636-1-willy@infradead.org> References: <20180621212835.5636-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The new API is much easier for this user. Also add kerneldoc for get_anon_bdev(). Signed-off-by: Matthew Wilcox --- fs/super.c | 63 +++++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 41 deletions(-) diff --git a/fs/super.c b/fs/super.c index 50728d9c1a05..3e7a0aea716a 100644 --- a/fs/super.c +++ b/fs/super.c @@ -978,58 +978,42 @@ void emergency_thaw_all(void) } } -/* - * Unnamed block devices are dummy devices used by virtual - * filesystems which don't use real block-devices. -- jrs - */ - static DEFINE_IDA(unnamed_dev_ida); -static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */ -/* Many userspace utilities consider an FSID of 0 invalid. - * Always return at least 1 from get_anon_bdev. - */ -static int unnamed_dev_start = 1; +/** + * get_anon_bdev - Allocate a block device for filesystems which don't have one. + * @p: Pointer to a dev_t. + * + * Filesystems which don't use real block devices can call this function + * to allocate a virtual block device. + * + * Context: Any context. Frequently called while holding sb_lock. + * Return: 0 on success, -EMFILE if there are no anonymous bdevs left + * or -EAGAIN if memory allocation failed. + */ 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); - error = ida_get_new_above(&unnamed_dev_ida, unnamed_dev_start, &dev); - if (!error) - unnamed_dev_start = dev + 1; - spin_unlock(&unnamed_dev_lock); - if (error == -EAGAIN) - /* We raced and lost with another CPU. */ - goto retry; - else if (error) + /* + * Many userspace utilities consider an FSID of 0 invalid. + * Always return at least 1 from get_anon_bdev. + */ + dev = ida_alloc_range(&unnamed_dev_ida, 1, (1 << MINORBITS) - 1, + GFP_ATOMIC); + if (dev == -ENOSPC) + return -EMFILE; + if (dev < 0) return -EAGAIN; - if (dev >= (1 << MINORBITS)) { - spin_lock(&unnamed_dev_lock); - ida_remove(&unnamed_dev_ida, dev); - if (unnamed_dev_start > dev) - unnamed_dev_start = dev; - spin_unlock(&unnamed_dev_lock); - return -EMFILE; - } - *p = MKDEV(0, dev & MINORMASK); + *p = MKDEV(0, dev); return 0; } 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); - if (slot < unnamed_dev_start) - unnamed_dev_start = slot; - spin_unlock(&unnamed_dev_lock); + ida_free(&unnamed_dev_ida, MINOR(dev)); } EXPORT_SYMBOL(free_anon_bdev); @@ -1037,7 +1021,6 @@ int set_anon_super(struct super_block *s, void *data) { return get_anon_bdev(&s->s_dev); } - EXPORT_SYMBOL(set_anon_super); void kill_anon_super(struct super_block *sb) @@ -1046,7 +1029,6 @@ void kill_anon_super(struct super_block *sb) generic_shutdown_super(sb); free_anon_bdev(dev); } - EXPORT_SYMBOL(kill_anon_super); void kill_litter_super(struct super_block *sb) @@ -1055,7 +1037,6 @@ void kill_litter_super(struct super_block *sb) d_genocide(sb->s_root); kill_anon_super(sb); } - EXPORT_SYMBOL(kill_litter_super); static int ns_test_super(struct super_block *sb, void *data) -- 2.17.1