Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1236868imm; Fri, 22 Jun 2018 12:48:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIcMd8wZc7kMKezTGGGbzvmarIEM0EedUg7i0JVRTRI8R6/lSyl5zgq4el83p8bm+o1wc1X X-Received: by 2002:a62:84e:: with SMTP id c75-v6mr3127352pfd.35.1529696891683; Fri, 22 Jun 2018 12:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529696891; cv=none; d=google.com; s=arc-20160816; b=bGZymiVYuH44MbbJ8lhTuPbSk/xfHpiuEaraGtiEdUc1NXzT/oTmDRZnxI26CaCRJ6 DhVstoWEGmH/ktjhbIldPRKAAxAtk1DcNVTR5wQUenbGmYP2ktBcdgCHDK40M9uwv1ED h0WGPoFpDfE9iPxY885ED2VEVnyolmamEj3qnSYar3+ddMh/3OrzQeP+Itcv8882wDL/ fQwz6ER5wu8eTE4DXxsqnb3TTGdFu/i0iaQjcMN/7TOR1hkuktqvwCBqecexQyzPDn3J WELbpv3W8FCvZhWion4Yh3jBbvD5S5ZNgBj4Ykw3ngWVCc1yJbYewbonOYeKOySGFPUG hnKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=0o6v2bzvM5nIE+l8CrVO6hQZkUi2HWECIrT4GGbiDGo=; b=a40/NIKDVqKoZUFGuw1k0viYJfeGTf7beYdzoLXeP3SJEKKTxLl5iPfEvVRDW9PUYL vTUR+3kWJ/B7sPAbQh6YQ7+tsdNKr8mrUkcEScXupwUA3ZmAVC85mfDSVZ1CMvg0rJ94 xpPgzIS22pnYUjiqU/8jeFoJKuNhC6CJbvt82WkExynvaUmsxYlnFPrVeUpdr5xR3Fh2 aB46q7aWxFga9vvRNQTzrBy8bnBh0Z+S3T+rEqeOkP8Hg9MAQ2YUYmur9UtZg/hg9YJh 1iQJLNeOjmKhb3FrOgHguxzD5I1+G5Ak05mq9ceuUCnIObwYhzDdf1a7xXIN14VPZTIw 6/0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=B2lyQlnB; 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 b125-v6si6900757pgc.514.2018.06.22.12.47.57; Fri, 22 Jun 2018 12:48:11 -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=merlin.20170209 header.b=B2lyQlnB; 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 S934550AbeFVTpR (ORCPT + 99 others); Fri, 22 Jun 2018 15:45:17 -0400 Received: from merlin.infradead.org ([205.233.59.134]:54664 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934111AbeFVTpP (ORCPT ); Fri, 22 Jun 2018 15:45:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To: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=0o6v2bzvM5nIE+l8CrVO6hQZkUi2HWECIrT4GGbiDGo=; b=B2lyQlnBfwfiIYdGQLsoChtXuM C3Elweyx3Svx/lFM03Phtsa/d/xBclORF38itHnVsp8K0dyHEATpZOqFv6JwXaoG0c9xQkjHbviD/ FzLN7BvuAYiKYFwVTXovP1R6S+pL1puEUdOW0QErbUxJDnr3Fj4/+wisZ6eipL3FmjlxyZGCaOZlX Y6c4s7nDdNKfU9Y6teurmQYIKwNLU8fK7pdIe0YdlGxuZGopmKfRmV0Y+CSvJLTmXc0ppyVhJKpZN q87XATPp7WI6O5bFtUAp1YW+HlJmCWQbRMejUKR2jlCoWERXABl/fUlydjfgSeK93NRpaudwnaB/W 08DVOgKQ==; Received: from static-50-53-52-16.bvtn.or.frontiernet.net ([50.53.52.16] helo=midway.dunlab) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fWRze-0003BA-PC; Fri, 22 Jun 2018 19:45:14 +0000 Subject: Re: [PATCH 05/26] fs: Convert unnamed_dev_ida to new API To: Matthew Wilcox , linux-kernel@vger.kernel.org Cc: Alexander Viro , linux-fsdevel@vger.kernel.org References: <20180621212835.5636-1-willy@infradead.org> <20180621212835.5636-6-willy@infradead.org> From: Randy Dunlap Message-ID: Date: Fri, 22 Jun 2018 12:45:10 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180621212835.5636-6-willy@infradead.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/21/2018 02:28 PM, Matthew Wilcox wrote: > 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. Looks to me like the code used to return -ENOMEM and used -EAGAIN as an internal retry code. confused? (/me) > + */ > 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); -- ~Randy