Commit 5a66847e authored by Matthew Wilcox's avatar Matthew Wilcox

fs: Convert unnamed_dev_ida to new API

The new API is much easier for this user.  Also add kerneldoc for
get_anon_bdev().
Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
parent 3aed4bc1
...@@ -978,58 +978,42 @@ void emergency_thaw_all(void) ...@@ -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_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 -ENOMEM if memory allocation failed.
*/
int get_anon_bdev(dev_t *p) int get_anon_bdev(dev_t *p)
{ {
int dev; int dev;
int error;
retry: /*
if (ida_pre_get(&unnamed_dev_ida, GFP_ATOMIC) == 0) * Many userspace utilities consider an FSID of 0 invalid.
return -ENOMEM; * Always return at least 1 from get_anon_bdev.
spin_lock(&unnamed_dev_lock); */
error = ida_get_new_above(&unnamed_dev_ida, unnamed_dev_start, &dev); dev = ida_alloc_range(&unnamed_dev_ida, 1, (1 << MINORBITS) - 1,
if (!error) GFP_ATOMIC);
unnamed_dev_start = dev + 1; if (dev == -ENOSPC)
spin_unlock(&unnamed_dev_lock); dev = -EMFILE;
if (error == -EAGAIN) if (dev < 0)
/* We raced and lost with another CPU. */ return dev;
goto retry;
else if (error) *p = MKDEV(0, dev);
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);
return 0; return 0;
} }
EXPORT_SYMBOL(get_anon_bdev); EXPORT_SYMBOL(get_anon_bdev);
void free_anon_bdev(dev_t dev) void free_anon_bdev(dev_t dev)
{ {
int slot = MINOR(dev); ida_free(&unnamed_dev_ida, 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);
} }
EXPORT_SYMBOL(free_anon_bdev); EXPORT_SYMBOL(free_anon_bdev);
...@@ -1037,7 +1021,6 @@ int set_anon_super(struct super_block *s, void *data) ...@@ -1037,7 +1021,6 @@ int set_anon_super(struct super_block *s, void *data)
{ {
return get_anon_bdev(&s->s_dev); return get_anon_bdev(&s->s_dev);
} }
EXPORT_SYMBOL(set_anon_super); EXPORT_SYMBOL(set_anon_super);
void kill_anon_super(struct super_block *sb) void kill_anon_super(struct super_block *sb)
...@@ -1046,7 +1029,6 @@ void kill_anon_super(struct super_block *sb) ...@@ -1046,7 +1029,6 @@ void kill_anon_super(struct super_block *sb)
generic_shutdown_super(sb); generic_shutdown_super(sb);
free_anon_bdev(dev); free_anon_bdev(dev);
} }
EXPORT_SYMBOL(kill_anon_super); EXPORT_SYMBOL(kill_anon_super);
void kill_litter_super(struct super_block *sb) void kill_litter_super(struct super_block *sb)
...@@ -1055,7 +1037,6 @@ 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); d_genocide(sb->s_root);
kill_anon_super(sb); kill_anon_super(sb);
} }
EXPORT_SYMBOL(kill_litter_super); EXPORT_SYMBOL(kill_litter_super);
static int ns_test_super(struct super_block *sb, void *data) static int ns_test_super(struct super_block *sb, void *data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment