btrfs: kill magical embedded struct superblock

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2011-07-07 15:44:25 -04:00
parent fb408e6ccc
commit 0ee5dc676a
5 changed files with 32 additions and 23 deletions

View file

@ -1219,7 +1219,7 @@ struct btrfs_root {
* right now this just gets used so that a root has its own devid * right now this just gets used so that a root has its own devid
* for stat. It may be used for more later * for stat. It may be used for more later
*/ */
struct super_block anon_super; dev_t anon_dev;
}; };
struct btrfs_ioctl_defrag_range_args { struct btrfs_ioctl_defrag_range_args {

View file

@ -1077,12 +1077,7 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
init_completion(&root->kobj_unregister); init_completion(&root->kobj_unregister);
root->defrag_running = 0; root->defrag_running = 0;
root->root_key.objectid = objectid; root->root_key.objectid = objectid;
root->anon_super.s_root = NULL; root->anon_dev = 0;
root->anon_super.s_dev = 0;
INIT_LIST_HEAD(&root->anon_super.s_list);
INIT_LIST_HEAD(&root->anon_super.s_instances);
init_rwsem(&root->anon_super.s_umount);
return 0; return 0;
} }
@ -1311,7 +1306,7 @@ struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info,
spin_lock_init(&root->cache_lock); spin_lock_init(&root->cache_lock);
init_waitqueue_head(&root->cache_wait); init_waitqueue_head(&root->cache_wait);
ret = set_anon_super(&root->anon_super, NULL); ret = get_anon_bdev(&root->anon_dev);
if (ret) if (ret)
goto fail; goto fail;
@ -2393,10 +2388,8 @@ static void free_fs_root(struct btrfs_root *root)
{ {
iput(root->cache_inode); iput(root->cache_inode);
WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree)); WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree));
if (root->anon_super.s_dev) { if (root->anon_dev)
down_write(&root->anon_super.s_umount); free_anon_bdev(root->anon_dev);
kill_anon_super(&root->anon_super);
}
free_extent_buffer(root->node); free_extent_buffer(root->node);
free_extent_buffer(root->commit_root); free_extent_buffer(root->commit_root);
kfree(root->free_ino_ctl); kfree(root->free_ino_ctl);

View file

@ -6900,7 +6900,7 @@ static int btrfs_getattr(struct vfsmount *mnt,
{ {
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
generic_fillattr(inode, stat); generic_fillattr(inode, stat);
stat->dev = BTRFS_I(inode)->root->anon_super.s_dev; stat->dev = BTRFS_I(inode)->root->anon_dev;
stat->blksize = PAGE_CACHE_SIZE; stat->blksize = PAGE_CACHE_SIZE;
stat->blocks = (inode_get_bytes(inode) + stat->blocks = (inode_get_bytes(inode) +
BTRFS_I(inode)->delalloc_bytes) >> 9; BTRFS_I(inode)->delalloc_bytes) >> 9;

View file

@ -693,7 +693,7 @@ static DEFINE_IDA(unnamed_dev_ida);
static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */ static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */
static int unnamed_dev_start = 0; /* don't bother trying below it */ static int unnamed_dev_start = 0; /* don't bother trying below it */
int set_anon_super(struct super_block *s, void *data) int get_anon_bdev(dev_t *p)
{ {
int dev; int dev;
int error; int error;
@ -720,23 +720,37 @@ int set_anon_super(struct super_block *s, void *data)
spin_unlock(&unnamed_dev_lock); spin_unlock(&unnamed_dev_lock);
return -EMFILE; return -EMFILE;
} }
s->s_dev = MKDEV(0, dev & MINORMASK); *p = MKDEV(0, dev & MINORMASK);
s->s_bdi = &noop_backing_dev_info;
return 0; 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);
}
EXPORT_SYMBOL(free_anon_bdev);
int set_anon_super(struct super_block *s, void *data)
{
int error = get_anon_bdev(&s->s_dev);
if (!error)
s->s_bdi = &noop_backing_dev_info;
return error;
}
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)
{ {
int slot = MINOR(sb->s_dev); dev_t dev = sb->s_dev;
generic_shutdown_super(sb); generic_shutdown_super(sb);
spin_lock(&unnamed_dev_lock); free_anon_bdev(dev);
ida_remove(&unnamed_dev_ida, slot);
if (slot < unnamed_dev_start)
unnamed_dev_start = slot;
spin_unlock(&unnamed_dev_lock);
} }
EXPORT_SYMBOL(kill_anon_super); EXPORT_SYMBOL(kill_anon_super);

View file

@ -1835,6 +1835,8 @@ void kill_litter_super(struct super_block *sb);
void deactivate_super(struct super_block *sb); void deactivate_super(struct super_block *sb);
void deactivate_locked_super(struct super_block *sb); void deactivate_locked_super(struct super_block *sb);
int set_anon_super(struct super_block *s, void *data); int set_anon_super(struct super_block *s, void *data);
int get_anon_bdev(dev_t *);
void free_anon_bdev(dev_t);
struct super_block *sget(struct file_system_type *type, struct super_block *sget(struct file_system_type *type,
int (*test)(struct super_block *,void *), int (*test)(struct super_block *,void *),
int (*set)(struct super_block *,void *), int (*set)(struct super_block *,void *),