bcachefs: Move bch2_evict_subvolume_inodes() to fs.c
authorKent Overstreet <kent.overstreet@gmail.com>
Thu, 28 Oct 2021 20:24:39 +0000 (16:24 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:15 +0000 (17:09 -0400)
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>
fs/bcachefs/fs.c
fs/bcachefs/fs.h
fs/bcachefs/subvolume.c
fs/bcachefs/subvolume.h

index c325e5c4325cce2e24ef32528500dced251d5f0d..7647e117013d20d165110e0f9a026ddb8b7dc458 100644 (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,
index 2616b15eb51ccb911c3f5abd9c0ae4e9028fdb4c..38c04282da6475565b111279bb2708a28ac16559 100644 (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; }
 
index 58cda98989b1d636f49683195c8eed633bada0d7..4d385c9e9268d1da9f4bffb11e3bc88922de46b2 100644 (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,
index 45234c9de0f6c16f8fa57095e9eb3dab9c34ee29..b5067dc68fc7790f05e45e79f8e1fb2e4a12c01d 100644 (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 *);