bcachefs: Move bch2_evict_subvolume_inodes() to fs.c

This fixes building in userspace - code that's coupled to the kernel VFS
interface should live in fs.c

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2021-10-28 16:24:39 -04:00 committed by Kent Overstreet
parent 8325cd1ed4
commit 41f9b7d39f
4 changed files with 61 additions and 64 deletions

View File

@ -1292,12 +1292,6 @@ static int bch2_vfs_write_inode(struct inode *vinode,
return ret;
}
static int bch2_drop_inode(struct inode *vinode)
{
return generic_drop_inode(vinode);
}
static void bch2_evict_inode(struct inode *vinode)
{
struct bch_fs *c = vinode->i_sb->s_fs_info;
@ -1318,6 +1312,53 @@ static void bch2_evict_inode(struct inode *vinode)
}
}
void bch2_evict_subvolume_inodes(struct bch_fs *c,
struct snapshot_id_list *s)
{
struct super_block *sb = c->vfs_sb;
struct inode *inode;
spin_lock(&sb->s_inode_list_lock);
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
if (!snapshot_list_has_id(s, to_bch_ei(inode)->ei_subvol) ||
(inode->i_state & I_FREEING))
continue;
d_mark_dontcache(inode);
d_prune_aliases(inode);
}
spin_unlock(&sb->s_inode_list_lock);
again:
cond_resched();
spin_lock(&sb->s_inode_list_lock);
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
if (!snapshot_list_has_id(s, to_bch_ei(inode)->ei_subvol) ||
(inode->i_state & I_FREEING))
continue;
if (!(inode->i_state & I_DONTCACHE)) {
d_mark_dontcache(inode);
d_prune_aliases(inode);
}
spin_lock(&inode->i_lock);
if (snapshot_list_has_id(s, to_bch_ei(inode)->ei_subvol) &&
!(inode->i_state & I_FREEING)) {
wait_queue_head_t *wq = bit_waitqueue(&inode->i_state, __I_NEW);
DEFINE_WAIT_BIT(wait, &inode->i_state, __I_NEW);
prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE);
spin_unlock(&inode->i_lock);
spin_unlock(&sb->s_inode_list_lock);
schedule();
finish_wait(wq, &wait.wq_entry);
goto again;
}
spin_unlock(&inode->i_lock);
}
spin_unlock(&sb->s_inode_list_lock);
}
static int bch2_statfs(struct dentry *dentry, struct kstatfs *buf)
{
struct super_block *sb = dentry->d_sb;
@ -1502,7 +1543,6 @@ static const struct super_operations bch_super_operations = {
.alloc_inode = bch2_alloc_inode,
.destroy_inode = bch2_destroy_inode,
.write_inode = bch2_vfs_write_inode,
.drop_inode = bch2_drop_inode,
.evict_inode = bch2_evict_inode,
.sync_fs = bch2_sync_fs,
.statfs = bch2_statfs,

View File

@ -185,11 +185,15 @@ int bch2_setattr_nonsize(struct mnt_idmap *,
struct iattr *);
int __bch2_unlink(struct inode *, struct dentry *, bool);
void bch2_evict_subvolume_inodes(struct bch_fs *, struct snapshot_id_list *);
void bch2_vfs_exit(void);
int bch2_vfs_init(void);
#else
static inline void bch2_evict_subvolume_inodes(struct bch_fs *c,
struct snapshot_id_list *s) {}
static inline void bch2_vfs_exit(void) {}
static inline int bch2_vfs_init(void) { return 0; }

View File

@ -542,16 +542,6 @@ err:
return ret;
}
static bool snapshot_list_has_id(struct snapshot_id_list *s, u32 id)
{
unsigned i;
for (i = 0; i < s->nr; i++)
if (id == s->d[i])
return true;
return false;
}
static int snapshot_id_add(struct snapshot_id_list *s, u32 id)
{
BUG_ON(snapshot_list_has_id(s, id));
@ -870,53 +860,6 @@ err:
return ret;
}
static void bch2_evict_subvolume_inodes(struct bch_fs *c,
struct snapshot_id_list *s)
{
struct super_block *sb = c->vfs_sb;
struct inode *inode;
spin_lock(&sb->s_inode_list_lock);
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
if (!snapshot_list_has_id(s, to_bch_ei(inode)->ei_subvol) ||
(inode->i_state & I_FREEING))
continue;
d_mark_dontcache(inode);
d_prune_aliases(inode);
}
spin_unlock(&sb->s_inode_list_lock);
again:
cond_resched();
spin_lock(&sb->s_inode_list_lock);
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
if (!snapshot_list_has_id(s, to_bch_ei(inode)->ei_subvol) ||
(inode->i_state & I_FREEING))
continue;
if (!(inode->i_state & I_DONTCACHE)) {
d_mark_dontcache(inode);
d_prune_aliases(inode);
}
spin_lock(&inode->i_lock);
if (snapshot_list_has_id(s, to_bch_ei(inode)->ei_subvol) &&
!(inode->i_state & I_FREEING)) {
wait_queue_head_t *wq = bit_waitqueue(&inode->i_state, __I_NEW);
DEFINE_WAIT_BIT(wait, &inode->i_state, __I_NEW);
prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE);
spin_unlock(&inode->i_lock);
spin_unlock(&sb->s_inode_list_lock);
schedule();
finish_wait(wq, &wait.wq_entry);
goto again;
}
spin_unlock(&inode->i_lock);
}
spin_unlock(&sb->s_inode_list_lock);
}
void bch2_subvolume_wait_for_pagecache_and_delete(struct work_struct *work)
{
struct bch_fs *c = container_of(work, struct bch_fs,

View File

@ -94,6 +94,16 @@ static inline int snapshots_seen_add(struct bch_fs *c, struct snapshots_seen *s,
return 0;
}
static inline bool snapshot_list_has_id(struct snapshot_id_list *s, u32 id)
{
unsigned i;
for (i = 0; i < s->nr; i++)
if (id == s->d[i])
return true;
return false;
}
int bch2_fs_snapshots_check(struct bch_fs *);
void bch2_fs_snapshots_exit(struct bch_fs *);
int bch2_fs_snapshots_start(struct bch_fs *);