lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a403bace-a7b4-aa3e-8fa7-4c47051a7916@infradead.org>
Date:   Fri, 22 Jun 2018 12:45:10 -0700
From:   Randy Dunlap <rdunlap@...radead.org>
To:     Matthew Wilcox <willy@...radead.org>, linux-kernel@...r.kernel.org
Cc:     Alexander Viro <viro@...iv.linux.org.uk>,
        linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH 05/26] fs: Convert unnamed_dev_ida to new API

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 <willy@...radead.org>
> ---
>  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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ