-#include "bcache.h"
+#include "bcachefs.h"
#include "acl.h"
#include "btree_update.h"
#include "buckets.h"
#include <linux/statfs.h>
#include <linux/xattr.h>
-static struct kmem_cache *bch_inode_cache;
+static struct kmem_cache *bch2_inode_cache;
-static void bch_vfs_inode_init(struct bch_fs *,
- struct bch_inode_info *,
- struct bch_inode_unpacked *);
+static void bch2_vfs_inode_init(struct bch_fs *,
+ struct bch_inode_info *,
+ struct bch_inode_unpacked *);
/*
* I_SIZE_DIRTY requires special handling:
* be set explicitly.
*/
-int __must_check __bch_write_inode(struct bch_fs *c,
- struct bch_inode_info *ei,
- inode_set_fn set,
- void *p)
+int __must_check __bch2_write_inode(struct bch_fs *c,
+ struct bch_inode_info *ei,
+ inode_set_fn set,
+ void *p)
{
struct btree_iter iter;
struct inode *inode = &ei->vfs_inode;
lockdep_assert_held(&ei->update_lock);
- bch_btree_iter_init_intent(&iter, c, BTREE_ID_INODES, POS(inum, 0));
+ bch2_btree_iter_init_intent(&iter, c, BTREE_ID_INODES, POS(inum, 0));
do {
- struct bkey_s_c k = bch_btree_iter_peek_with_holes(&iter);
+ struct bkey_s_c k = bch2_btree_iter_peek_with_holes(&iter);
if ((ret = btree_iter_err(k)))
goto out;
if (WARN_ONCE(k.k->type != BCH_INODE_FS,
"inode %llu not found when updating", inum)) {
- bch_btree_iter_unlock(&iter);
+ bch2_btree_iter_unlock(&iter);
return -ENOENT;
}
- ret = bch_inode_unpack(bkey_s_c_to_inode(k), &inode_u);
+ ret = bch2_inode_unpack(bkey_s_c_to_inode(k), &inode_u);
if (WARN_ONCE(ret,
"error %i unpacking inode %llu", ret, inum)) {
ret = -ENOENT;
inode_u.i_gid = i_gid_read(inode);
inode_u.i_nlink = i_nlink - nlink_bias(inode->i_mode);
inode_u.i_dev = inode->i_rdev;
- inode_u.i_atime = timespec_to_bch_time(c, inode->i_atime);
- inode_u.i_mtime = timespec_to_bch_time(c, inode->i_mtime);
- inode_u.i_ctime = timespec_to_bch_time(c, inode->i_ctime);
+ inode_u.i_atime = timespec_to_bch2_time(c, inode->i_atime);
+ inode_u.i_mtime = timespec_to_bch2_time(c, inode->i_mtime);
+ inode_u.i_ctime = timespec_to_bch2_time(c, inode->i_ctime);
- bch_inode_pack(&inode_p, &inode_u);
+ bch2_inode_pack(&inode_p, &inode_u);
- ret = bch_btree_insert_at(c, NULL, NULL, &ei->journal_seq,
+ ret = bch2_btree_insert_at(c, NULL, NULL, &ei->journal_seq,
BTREE_INSERT_ATOMIC|
BTREE_INSERT_NOFAIL,
BTREE_INSERT_ENTRY(&iter, &inode_p.inode.k_i));
ei->i_flags = inode_u.i_flags;
}
out:
- bch_btree_iter_unlock(&iter);
+ bch2_btree_iter_unlock(&iter);
return ret < 0 ? ret : 0;
}
-int __must_check bch_write_inode(struct bch_fs *c,
- struct bch_inode_info *ei)
+int __must_check bch2_write_inode(struct bch_fs *c,
+ struct bch_inode_info *ei)
{
- return __bch_write_inode(c, ei, NULL, NULL);
+ return __bch2_write_inode(c, ei, NULL, NULL);
}
-int bch_inc_nlink(struct bch_fs *c, struct bch_inode_info *ei)
+int bch2_inc_nlink(struct bch_fs *c, struct bch_inode_info *ei)
{
int ret;
mutex_lock(&ei->update_lock);
inc_nlink(&ei->vfs_inode);
- ret = bch_write_inode(c, ei);
+ ret = bch2_write_inode(c, ei);
mutex_unlock(&ei->update_lock);
return ret;
}
-int bch_dec_nlink(struct bch_fs *c, struct bch_inode_info *ei)
+int bch2_dec_nlink(struct bch_fs *c, struct bch_inode_info *ei)
{
int ret = 0;
mutex_lock(&ei->update_lock);
drop_nlink(&ei->vfs_inode);
- ret = bch_write_inode(c, ei);
+ ret = bch2_write_inode(c, ei);
mutex_unlock(&ei->update_lock);
return ret;
}
-static struct inode *bch_vfs_inode_get(struct super_block *sb, u64 inum)
+static struct inode *bch2_vfs_inode_get(struct super_block *sb, u64 inum)
{
struct bch_fs *c = sb->s_fs_info;
struct inode *inode;
if (!(inode->i_state & I_NEW))
return inode;
- ret = bch_inode_find_by_inum(c, inum, &inode_u);
+ ret = bch2_inode_find_by_inum(c, inum, &inode_u);
if (ret) {
iget_failed(inode);
return ERR_PTR(ret);
}
ei = to_bch_ei(inode);
- bch_vfs_inode_init(c, ei, &inode_u);
+ bch2_vfs_inode_init(c, ei, &inode_u);
- ei->journal_seq = bch_inode_journal_seq(&c->journal, inum);
+ ei->journal_seq = bch2_inode_journal_seq(&c->journal, inum);
unlock_new_inode(inode);
return inode;
}
-static struct inode *bch_vfs_inode_create(struct bch_fs *c,
- struct inode *parent,
- umode_t mode, dev_t rdev)
+static struct inode *bch2_vfs_inode_create(struct bch_fs *c,
+ struct inode *parent,
+ umode_t mode, dev_t rdev)
{
struct inode *inode;
struct posix_acl *default_acl = NULL, *acl = NULL;
ei = to_bch_ei(inode);
- bch_inode_init(c, &inode_u, i_uid_read(inode),
+ bch2_inode_init(c, &inode_u, i_uid_read(inode),
i_gid_read(inode), inode->i_mode, rdev);
- bch_inode_pack(&inode_p, &inode_u);
+ bch2_inode_pack(&inode_p, &inode_u);
- ret = bch_inode_create(c, &inode_p.inode.k_i,
+ ret = bch2_inode_create(c, &inode_p.inode.k_i,
BLOCKDEV_INODE_MAX, 0,
&c->unused_inode_hint);
if (unlikely(ret)) {
}
inode_u.inum = inode_p.inode.k.p.inode;
- bch_vfs_inode_init(c, ei, &inode_u);
+ bch2_vfs_inode_init(c, ei, &inode_u);
if (default_acl) {
- ret = bch_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
+ ret = bch2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
if (unlikely(ret))
goto err;
}
if (acl) {
- ret = bch_set_acl(inode, acl, ACL_TYPE_ACCESS);
+ ret = bch2_set_acl(inode, acl, ACL_TYPE_ACCESS);
if (unlikely(ret))
goto err;
}
goto out;
}
-static int bch_vfs_dirent_create(struct bch_fs *c, struct inode *dir,
- u8 type, const struct qstr *name,
- struct inode *dst)
+static int bch2_vfs_dirent_create(struct bch_fs *c, struct inode *dir,
+ u8 type, const struct qstr *name,
+ struct inode *dst)
{
struct bch_inode_info *dir_ei = to_bch_ei(dir);
int ret;
- ret = bch_dirent_create(c, dir->i_ino, &dir_ei->str_hash,
+ ret = bch2_dirent_create(c, dir->i_ino, &dir_ei->str_hash,
type, name, dst->i_ino,
&dir_ei->journal_seq,
BCH_HASH_SET_MUST_CREATE);
return 0;
}
-static int __bch_create(struct inode *dir, struct dentry *dentry,
- umode_t mode, dev_t rdev)
+static int __bch2_create(struct inode *dir, struct dentry *dentry,
+ umode_t mode, dev_t rdev)
{
struct bch_inode_info *dir_ei = to_bch_ei(dir);
struct bch_fs *c = dir->i_sb->s_fs_info;
struct bch_inode_info *ei;
int ret;
- inode = bch_vfs_inode_create(c, dir, mode, rdev);
+ inode = bch2_vfs_inode_create(c, dir, mode, rdev);
if (unlikely(IS_ERR(inode)))
return PTR_ERR(inode);
ei = to_bch_ei(inode);
- ret = bch_vfs_dirent_create(c, dir, mode_to_type(mode),
+ ret = bch2_vfs_dirent_create(c, dir, mode_to_type(mode),
&dentry->d_name, inode);
if (unlikely(ret)) {
clear_nlink(inode);
/* methods */
-static struct dentry *bch_lookup(struct inode *dir, struct dentry *dentry,
- unsigned int flags)
+static struct dentry *bch2_lookup(struct inode *dir, struct dentry *dentry,
+ unsigned int flags)
{
struct bch_fs *c = dir->i_sb->s_fs_info;
struct bch_inode_info *dir_ei = to_bch_ei(dir);
struct inode *inode = NULL;
u64 inum;
- inum = bch_dirent_lookup(c, dir->i_ino,
+ inum = bch2_dirent_lookup(c, dir->i_ino,
&dir_ei->str_hash,
&dentry->d_name);
if (inum)
- inode = bch_vfs_inode_get(dir->i_sb, inum);
+ inode = bch2_vfs_inode_get(dir->i_sb, inum);
return d_splice_alias(inode, dentry);
}
-static int bch_create(struct inode *dir, struct dentry *dentry,
- umode_t mode, bool excl)
+static int bch2_create(struct inode *dir, struct dentry *dentry,
+ umode_t mode, bool excl)
{
- return __bch_create(dir, dentry, mode|S_IFREG, 0);
+ return __bch2_create(dir, dentry, mode|S_IFREG, 0);
}
-static int bch_link(struct dentry *old_dentry, struct inode *dir,
- struct dentry *dentry)
+static int bch2_link(struct dentry *old_dentry, struct inode *dir,
+ struct dentry *dentry)
{
struct bch_fs *c = dir->i_sb->s_fs_info;
struct inode *inode = old_dentry->d_inode;
inode->i_ctime = current_fs_time(dir->i_sb);
- ret = bch_inc_nlink(c, ei);
+ ret = bch2_inc_nlink(c, ei);
if (ret)
return ret;
ihold(inode);
- ret = bch_vfs_dirent_create(c, dir, mode_to_type(inode->i_mode),
+ ret = bch2_vfs_dirent_create(c, dir, mode_to_type(inode->i_mode),
&dentry->d_name, inode);
if (unlikely(ret)) {
- bch_dec_nlink(c, ei);
+ bch2_dec_nlink(c, ei);
iput(inode);
return ret;
}
return 0;
}
-static int bch_unlink(struct inode *dir, struct dentry *dentry)
+static int bch2_unlink(struct inode *dir, struct dentry *dentry)
{
struct bch_fs *c = dir->i_sb->s_fs_info;
struct bch_inode_info *dir_ei = to_bch_ei(dir);
lockdep_assert_held(&inode->i_rwsem);
- ret = bch_dirent_delete(c, dir->i_ino, &dir_ei->str_hash,
+ ret = bch2_dirent_delete(c, dir->i_ino, &dir_ei->str_hash,
&dentry->d_name, &dir_ei->journal_seq);
if (ret)
return ret;
inode->i_ctime = dir->i_ctime;
if (S_ISDIR(inode->i_mode)) {
- bch_dec_nlink(c, dir_ei);
+ bch2_dec_nlink(c, dir_ei);
drop_nlink(inode);
}
- bch_dec_nlink(c, ei);
+ bch2_dec_nlink(c, ei);
return 0;
}
-static int bch_symlink(struct inode *dir, struct dentry *dentry,
- const char *symname)
+static int bch2_symlink(struct inode *dir, struct dentry *dentry,
+ const char *symname)
{
struct bch_fs *c = dir->i_sb->s_fs_info;
struct inode *inode;
struct bch_inode_info *ei, *dir_ei = to_bch_ei(dir);
int ret;
- inode = bch_vfs_inode_create(c, dir, S_IFLNK|S_IRWXUGO, 0);
+ inode = bch2_vfs_inode_create(c, dir, S_IFLNK|S_IRWXUGO, 0);
if (unlikely(IS_ERR(inode)))
return PTR_ERR(inode);
if (dir_ei->journal_seq < ei->journal_seq)
dir_ei->journal_seq = ei->journal_seq;
- ret = bch_vfs_dirent_create(c, dir, DT_LNK, &dentry->d_name, inode);
+ ret = bch2_vfs_dirent_create(c, dir, DT_LNK, &dentry->d_name, inode);
if (unlikely(ret))
goto err;
return ret;
}
-static int bch_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
+static int bch2_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
{
struct bch_fs *c = dir->i_sb->s_fs_info;
int ret;
lockdep_assert_held(&dir->i_rwsem);
- ret = __bch_create(dir, dentry, mode|S_IFDIR, 0);
+ ret = __bch2_create(dir, dentry, mode|S_IFDIR, 0);
if (unlikely(ret))
return ret;
- bch_inc_nlink(c, to_bch_ei(dir));
+ bch2_inc_nlink(c, to_bch_ei(dir));
return 0;
}
-static int bch_rmdir(struct inode *dir, struct dentry *dentry)
+static int bch2_rmdir(struct inode *dir, struct dentry *dentry)
{
struct bch_fs *c = dir->i_sb->s_fs_info;
struct inode *inode = dentry->d_inode;
- if (bch_empty_dir(c, inode->i_ino))
+ if (bch2_empty_dir(c, inode->i_ino))
return -ENOTEMPTY;
- return bch_unlink(dir, dentry);
+ return bch2_unlink(dir, dentry);
}
-static int bch_mknod(struct inode *dir, struct dentry *dentry,
- umode_t mode, dev_t rdev)
+static int bch2_mknod(struct inode *dir, struct dentry *dentry,
+ umode_t mode, dev_t rdev)
{
- return __bch_create(dir, dentry, mode, rdev);
+ return __bch2_create(dir, dentry, mode, rdev);
}
-static int bch_rename(struct inode *old_dir, struct dentry *old_dentry,
- struct inode *new_dir, struct dentry *new_dentry)
+static int bch2_rename(struct inode *old_dir, struct dentry *old_dentry,
+ struct inode *new_dir, struct dentry *new_dentry)
{
struct bch_fs *c = old_dir->i_sb->s_fs_info;
struct inode *old_inode = old_dentry->d_inode;
if (!S_ISDIR(new_inode->i_mode))
return -ENOTDIR;
- if (bch_empty_dir(c, new_inode->i_ino))
+ if (bch2_empty_dir(c, new_inode->i_ino))
return -ENOTEMPTY;
- ret = bch_dirent_rename(c,
+ ret = bch2_dirent_rename(c,
old_dir, &old_dentry->d_name,
new_dir, &new_dentry->d_name,
&ei->journal_seq, BCH_RENAME_OVERWRITE);
return ret;
clear_nlink(new_inode);
- bch_dec_nlink(c, to_bch_ei(old_dir));
+ bch2_dec_nlink(c, to_bch_ei(old_dir));
} else if (new_inode) {
lockdep_assert_held(&new_inode->i_rwsem);
- ret = bch_dirent_rename(c,
+ ret = bch2_dirent_rename(c,
old_dir, &old_dentry->d_name,
new_dir, &new_dentry->d_name,
&ei->journal_seq, BCH_RENAME_OVERWRITE);
return ret;
new_inode->i_ctime = now;
- bch_dec_nlink(c, to_bch_ei(new_inode));
+ bch2_dec_nlink(c, to_bch_ei(new_inode));
} else if (S_ISDIR(old_inode->i_mode)) {
- ret = bch_dirent_rename(c,
+ ret = bch2_dirent_rename(c,
old_dir, &old_dentry->d_name,
new_dir, &new_dentry->d_name,
&ei->journal_seq, BCH_RENAME);
if (unlikely(ret))
return ret;
- bch_inc_nlink(c, to_bch_ei(new_dir));
- bch_dec_nlink(c, to_bch_ei(old_dir));
+ bch2_inc_nlink(c, to_bch_ei(new_dir));
+ bch2_dec_nlink(c, to_bch_ei(old_dir));
} else {
- ret = bch_dirent_rename(c,
+ ret = bch2_dirent_rename(c,
old_dir, &old_dentry->d_name,
new_dir, &new_dentry->d_name,
&ei->journal_seq, BCH_RENAME);
return 0;
}
-static int bch_rename_exchange(struct inode *old_dir, struct dentry *old_dentry,
- struct inode *new_dir, struct dentry *new_dentry)
+static int bch2_rename_exchange(struct inode *old_dir, struct dentry *old_dentry,
+ struct inode *new_dir, struct dentry *new_dentry)
{
struct bch_fs *c = old_dir->i_sb->s_fs_info;
struct inode *old_inode = old_dentry->d_inode;
struct timespec now = current_fs_time(old_dir->i_sb);
int ret;
- ret = bch_dirent_rename(c,
+ ret = bch2_dirent_rename(c,
old_dir, &old_dentry->d_name,
new_dir, &new_dentry->d_name,
&ei->journal_seq, BCH_RENAME_EXCHANGE);
if (S_ISDIR(old_inode->i_mode) !=
S_ISDIR(new_inode->i_mode)) {
if (S_ISDIR(old_inode->i_mode)) {
- bch_inc_nlink(c, to_bch_ei(new_dir));
- bch_dec_nlink(c, to_bch_ei(old_dir));
+ bch2_inc_nlink(c, to_bch_ei(new_dir));
+ bch2_dec_nlink(c, to_bch_ei(old_dir));
} else {
- bch_dec_nlink(c, to_bch_ei(new_dir));
- bch_inc_nlink(c, to_bch_ei(old_dir));
+ bch2_dec_nlink(c, to_bch_ei(new_dir));
+ bch2_inc_nlink(c, to_bch_ei(old_dir));
}
}
return 0;
}
-static int bch_rename2(struct inode *old_dir, struct dentry *old_dentry,
- struct inode *new_dir, struct dentry *new_dentry,
- unsigned flags)
+static int bch2_rename2(struct inode *old_dir, struct dentry *old_dentry,
+ struct inode *new_dir, struct dentry *new_dentry,
+ unsigned flags)
{
if (flags & ~(RENAME_NOREPLACE|RENAME_EXCHANGE))
return -EINVAL;
if (flags & RENAME_EXCHANGE)
- return bch_rename_exchange(old_dir, old_dentry,
+ return bch2_rename_exchange(old_dir, old_dentry,
new_dir, new_dentry);
- return bch_rename(old_dir, old_dentry, new_dir, new_dentry);
+ return bch2_rename(old_dir, old_dentry, new_dir, new_dentry);
}
-static int bch_setattr(struct dentry *dentry, struct iattr *iattr)
+static int bch2_setattr(struct dentry *dentry, struct iattr *iattr)
{
struct inode *inode = dentry->d_inode;
struct bch_inode_info *ei = to_bch_ei(inode);
return ret;
if (iattr->ia_valid & ATTR_SIZE) {
- ret = bch_truncate(inode, iattr);
+ ret = bch2_truncate(inode, iattr);
} else {
mutex_lock(&ei->update_lock);
setattr_copy(inode, iattr);
- ret = bch_write_inode(c, ei);
+ ret = bch2_write_inode(c, ei);
mutex_unlock(&ei->update_lock);
}
return ret;
}
-static int bch_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
+static int bch2_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
{
struct bch_fs *c = dir->i_sb->s_fs_info;
struct inode *inode;
/* XXX: i_nlink should be 0? */
- inode = bch_vfs_inode_create(c, dir, mode, 0);
+ inode = bch2_vfs_inode_create(c, dir, mode, 0);
if (unlikely(IS_ERR(inode)))
return PTR_ERR(inode);
return 0;
}
-static int bch_fill_extent(struct fiemap_extent_info *info,
- const struct bkey_i *k, unsigned flags)
+static int bch2_fill_extent(struct fiemap_extent_info *info,
+ const struct bkey_i *k, unsigned flags)
{
if (bkey_extent_is_data(&k->k)) {
struct bkey_s_c_extent e = bkey_i_to_s_c_extent(k);
}
}
-static int bch_fiemap(struct inode *inode, struct fiemap_extent_info *info,
- u64 start, u64 len)
+static int bch2_fiemap(struct inode *inode, struct fiemap_extent_info *info,
+ u64 start, u64 len)
{
struct bch_fs *c = inode->i_sb->s_fs_info;
struct btree_iter iter;
break;
if (have_extent) {
- ret = bch_fill_extent(info, &tmp.k, 0);
+ ret = bch2_fill_extent(info, &tmp.k, 0);
if (ret)
goto out;
}
}
if (have_extent)
- ret = bch_fill_extent(info, &tmp.k, FIEMAP_EXTENT_LAST);
+ ret = bch2_fill_extent(info, &tmp.k, FIEMAP_EXTENT_LAST);
out:
- bch_btree_iter_unlock(&iter);
+ bch2_btree_iter_unlock(&iter);
return ret < 0 ? ret : 0;
}
static const struct vm_operations_struct bch_vm_ops = {
.fault = filemap_fault,
.map_pages = filemap_map_pages,
- .page_mkwrite = bch_page_mkwrite,
+ .page_mkwrite = bch2_page_mkwrite,
};
-static int bch_mmap(struct file *file, struct vm_area_struct *vma)
+static int bch2_mmap(struct file *file, struct vm_area_struct *vma)
{
file_accessed(file);
[__BCH_INODE_NOATIME] = FS_NOATIME_FL,
};
-/* Set VFS inode flags from bcache inode: */
-static void bch_inode_flags_to_vfs(struct inode *inode)
+/* Set VFS inode flags from bcachefs inode: */
+static void bch2_inode_flags_to_vfs(struct inode *inode)
{
unsigned i, flags = to_bch_ei(inode)->i_flags;
inode->i_flags &= ~bch_inode_flags_to_vfs_flags_map[i];
}
-/* Get FS_IOC_GETFLAGS flags from bcache inode: */
-static unsigned bch_inode_flags_to_user_flags(unsigned flags)
+/* Get FS_IOC_GETFLAGS flags from bcachefs inode: */
+static unsigned bch2_inode_flags_to_user_flags(unsigned flags)
{
unsigned i, ret = 0;
return ret;
}
-static int bch_inode_user_flags_set(struct bch_inode_info *ei,
- struct bch_inode_unpacked *bi,
- void *p)
+static int bch2_inode_user_flags_set(struct bch_inode_info *ei,
+ struct bch_inode_unpacked *bi,
+ void *p)
{
/*
* We're relying on btree locking here for exclusion with other ioctl
* calls - use the flags in the btree (@bi), not ei->i_flags:
*/
unsigned bch_flags = bi->i_flags;
- unsigned oldflags = bch_inode_flags_to_user_flags(bch_flags);
+ unsigned oldflags = bch2_inode_flags_to_user_flags(bch_flags);
unsigned newflags = *((unsigned *) p);
unsigned i;
#define FS_IOC_GOINGDOWN _IOR ('X', 125, __u32)
-static long bch_fs_file_ioctl(struct file *filp, unsigned int cmd,
- unsigned long arg)
+static long bch2_fs_file_ioctl(struct file *filp, unsigned int cmd,
+ unsigned long arg)
{
struct inode *inode = file_inode(filp);
struct super_block *sb = inode->i_sb;
switch (cmd) {
case FS_IOC_GETFLAGS:
- return put_user(bch_inode_flags_to_user_flags(ei->i_flags),
+ return put_user(bch2_inode_flags_to_user_flags(ei->i_flags),
(int __user *) arg);
case FS_IOC_SETFLAGS: {
inode_lock(inode);
mutex_lock(&ei->update_lock);
- ret = __bch_write_inode(c, ei, bch_inode_user_flags_set, &flags);
+ ret = __bch2_write_inode(c, ei, bch2_inode_user_flags_set, &flags);
mutex_unlock(&ei->update_lock);
if (!ret)
- bch_inode_flags_to_vfs(inode);
+ bch2_inode_flags_to_vfs(inode);
inode_unlock(inode);
setflags_out:
down_write(&sb->s_umount);
sb->s_flags |= MS_RDONLY;
- bch_fs_emergency_read_only(c);
+ bch2_fs_emergency_read_only(c);
up_write(&sb->s_umount);
return 0;
default:
- return bch_fs_ioctl(c, cmd, (void __user *) arg);
+ return bch2_fs_ioctl(c, cmd, (void __user *) arg);
}
}
#ifdef CONFIG_COMPAT
-static long bch_compat_fs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+static long bch2_compat_fs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
/* These are just misnamed, they actually get/put from/to user an int */
switch (cmd) {
default:
return -ENOIOCTLCMD;
}
- return bch_fs_file_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
+ return bch2_fs_file_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
}
#endif
/* Directories: */
-static loff_t bch_dir_llseek(struct file *file, loff_t offset, int whence)
+static loff_t bch2_dir_llseek(struct file *file, loff_t offset, int whence)
{
return generic_file_llseek_size(file, offset, whence,
S64_MAX, S64_MAX);
}
-static int bch_vfs_readdir(struct file *file, struct dir_context *ctx)
+static int bch2_vfs_readdir(struct file *file, struct dir_context *ctx)
{
struct inode *inode = file_inode(file);
struct bch_fs *c = inode->i_sb->s_fs_info;
- return bch_readdir(c, file, ctx);
+ return bch2_readdir(c, file, ctx);
}
static const struct file_operations bch_file_operations = {
- .llseek = bch_llseek,
+ .llseek = bch2_llseek,
.read_iter = generic_file_read_iter,
- .write_iter = bch_write_iter,
- .mmap = bch_mmap,
+ .write_iter = bch2_write_iter,
+ .mmap = bch2_mmap,
.open = generic_file_open,
- .fsync = bch_fsync,
+ .fsync = bch2_fsync,
.splice_read = generic_file_splice_read,
.splice_write = iter_file_splice_write,
- .fallocate = bch_fallocate_dispatch,
- .unlocked_ioctl = bch_fs_file_ioctl,
+ .fallocate = bch2_fallocate_dispatch,
+ .unlocked_ioctl = bch2_fs_file_ioctl,
#ifdef CONFIG_COMPAT
- .compat_ioctl = bch_compat_fs_ioctl,
+ .compat_ioctl = bch2_compat_fs_ioctl,
#endif
};
static const struct inode_operations bch_file_inode_operations = {
- .setattr = bch_setattr,
- .fiemap = bch_fiemap,
- .listxattr = bch_xattr_list,
- .get_acl = bch_get_acl,
- .set_acl = bch_set_acl,
+ .setattr = bch2_setattr,
+ .fiemap = bch2_fiemap,
+ .listxattr = bch2_xattr_list,
+ .get_acl = bch2_get_acl,
+ .set_acl = bch2_set_acl,
};
static const struct inode_operations bch_dir_inode_operations = {
- .lookup = bch_lookup,
- .create = bch_create,
- .link = bch_link,
- .unlink = bch_unlink,
- .symlink = bch_symlink,
- .mkdir = bch_mkdir,
- .rmdir = bch_rmdir,
- .mknod = bch_mknod,
- .rename = bch_rename2,
- .setattr = bch_setattr,
- .tmpfile = bch_tmpfile,
- .listxattr = bch_xattr_list,
- .get_acl = bch_get_acl,
- .set_acl = bch_set_acl,
+ .lookup = bch2_lookup,
+ .create = bch2_create,
+ .link = bch2_link,
+ .unlink = bch2_unlink,
+ .symlink = bch2_symlink,
+ .mkdir = bch2_mkdir,
+ .rmdir = bch2_rmdir,
+ .mknod = bch2_mknod,
+ .rename = bch2_rename2,
+ .setattr = bch2_setattr,
+ .tmpfile = bch2_tmpfile,
+ .listxattr = bch2_xattr_list,
+ .get_acl = bch2_get_acl,
+ .set_acl = bch2_set_acl,
};
static const struct file_operations bch_dir_file_operations = {
- .llseek = bch_dir_llseek,
+ .llseek = bch2_dir_llseek,
.read = generic_read_dir,
- .iterate = bch_vfs_readdir,
- .fsync = bch_fsync,
- .unlocked_ioctl = bch_fs_file_ioctl,
+ .iterate = bch2_vfs_readdir,
+ .fsync = bch2_fsync,
+ .unlocked_ioctl = bch2_fs_file_ioctl,
#ifdef CONFIG_COMPAT
- .compat_ioctl = bch_compat_fs_ioctl,
+ .compat_ioctl = bch2_compat_fs_ioctl,
#endif
};
static const struct inode_operations bch_symlink_inode_operations = {
.readlink = generic_readlink,
.get_link = page_get_link,
- .setattr = bch_setattr,
- .listxattr = bch_xattr_list,
- .get_acl = bch_get_acl,
- .set_acl = bch_set_acl,
+ .setattr = bch2_setattr,
+ .listxattr = bch2_xattr_list,
+ .get_acl = bch2_get_acl,
+ .set_acl = bch2_set_acl,
};
static const struct inode_operations bch_special_inode_operations = {
- .setattr = bch_setattr,
- .listxattr = bch_xattr_list,
- .get_acl = bch_get_acl,
- .set_acl = bch_set_acl,
+ .setattr = bch2_setattr,
+ .listxattr = bch2_xattr_list,
+ .get_acl = bch2_get_acl,
+ .set_acl = bch2_set_acl,
};
static const struct address_space_operations bch_address_space_operations = {
- .writepage = bch_writepage,
- .readpage = bch_readpage,
- .writepages = bch_writepages,
- .readpages = bch_readpages,
- .set_page_dirty = bch_set_page_dirty,
- .write_begin = bch_write_begin,
- .write_end = bch_write_end,
- .invalidatepage = bch_invalidatepage,
- .releasepage = bch_releasepage,
- .direct_IO = bch_direct_IO,
+ .writepage = bch2_writepage,
+ .readpage = bch2_readpage,
+ .writepages = bch2_writepages,
+ .readpages = bch2_readpages,
+ .set_page_dirty = bch2_set_page_dirty,
+ .write_begin = bch2_write_begin,
+ .write_end = bch2_write_end,
+ .invalidatepage = bch2_invalidatepage,
+ .releasepage = bch2_releasepage,
+ .direct_IO = bch2_direct_IO,
#ifdef CONFIG_MIGRATION
- .migratepage = bch_migrate_page,
+ .migratepage = bch2_migrate_page,
#endif
.error_remove_page = generic_error_remove_page,
};
-static void bch_vfs_inode_init(struct bch_fs *c,
- struct bch_inode_info *ei,
- struct bch_inode_unpacked *bi)
+static void bch2_vfs_inode_init(struct bch_fs *c,
+ struct bch_inode_info *ei,
+ struct bch_inode_unpacked *bi)
{
struct inode *inode = &ei->vfs_inode;
inode->i_rdev = bi->i_dev;
inode->i_generation = bi->i_generation;
inode->i_size = bi->i_size;
- inode->i_atime = bch_time_to_timespec(c, bi->i_atime);
- inode->i_mtime = bch_time_to_timespec(c, bi->i_mtime);
- inode->i_ctime = bch_time_to_timespec(c, bi->i_ctime);
- bch_inode_flags_to_vfs(inode);
+ inode->i_atime = bch2_time_to_timespec(c, bi->i_atime);
+ inode->i_mtime = bch2_time_to_timespec(c, bi->i_mtime);
+ inode->i_ctime = bch2_time_to_timespec(c, bi->i_ctime);
+ bch2_inode_flags_to_vfs(inode);
- ei->str_hash = bch_hash_info_init(bi);
+ ei->str_hash = bch2_hash_info_init(c, bi);
inode->i_mapping->a_ops = &bch_address_space_operations;
}
}
-static struct inode *bch_alloc_inode(struct super_block *sb)
+static struct inode *bch2_alloc_inode(struct super_block *sb)
{
struct bch_inode_info *ei;
- ei = kmem_cache_alloc(bch_inode_cache, GFP_NOFS);
+ ei = kmem_cache_alloc(bch2_inode_cache, GFP_NOFS);
if (!ei)
return NULL;
return &ei->vfs_inode;
}
-static void bch_i_callback(struct rcu_head *head)
+static void bch2_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
- kmem_cache_free(bch_inode_cache, to_bch_ei(inode));
+ kmem_cache_free(bch2_inode_cache, to_bch_ei(inode));
}
-static void bch_destroy_inode(struct inode *inode)
+static void bch2_destroy_inode(struct inode *inode)
{
- call_rcu(&inode->i_rcu, bch_i_callback);
+ call_rcu(&inode->i_rcu, bch2_i_callback);
}
-static int bch_vfs_write_inode(struct inode *inode,
- struct writeback_control *wbc)
+static int bch2_vfs_write_inode(struct inode *inode,
+ struct writeback_control *wbc)
{
struct bch_fs *c = inode->i_sb->s_fs_info;
struct bch_inode_info *ei = to_bch_ei(inode);
int ret;
mutex_lock(&ei->update_lock);
- ret = bch_write_inode(c, ei);
+ ret = bch2_write_inode(c, ei);
mutex_unlock(&ei->update_lock);
if (c->opts.journal_flush_disabled)
return ret;
if (!ret && wbc->sync_mode == WB_SYNC_ALL)
- ret = bch_journal_flush_seq(&c->journal, ei->journal_seq);
+ ret = bch2_journal_flush_seq(&c->journal, ei->journal_seq);
return ret;
}
-static void bch_evict_inode(struct inode *inode)
+static void bch2_evict_inode(struct inode *inode)
{
struct bch_fs *c = inode->i_sb->s_fs_info;
truncate_inode_pages_final(&inode->i_data);
- if (!bch_journal_error(&c->journal) && !is_bad_inode(inode)) {
+ if (!bch2_journal_error(&c->journal) && !is_bad_inode(inode)) {
struct bch_inode_info *ei = to_bch_ei(inode);
/* XXX - we want to check this stuff iff there weren't IO errors: */
clear_inode(inode);
if (!inode->i_nlink && !is_bad_inode(inode)) {
- bch_inode_rm(c, inode->i_ino);
+ bch2_inode_rm(c, inode->i_ino);
atomic_long_dec(&c->nr_inodes);
}
}
-static int bch_statfs(struct dentry *dentry, struct kstatfs *buf)
+static int bch2_statfs(struct dentry *dentry, struct kstatfs *buf)
{
struct super_block *sb = dentry->d_sb;
struct bch_fs *c = sb->s_fs_info;
buf->f_type = BCACHE_STATFS_MAGIC;
buf->f_bsize = sb->s_blocksize;
buf->f_blocks = c->capacity >> PAGE_SECTOR_SHIFT;
- buf->f_bfree = (c->capacity - bch_fs_sectors_used(c)) >> PAGE_SECTOR_SHIFT;
+ buf->f_bfree = (c->capacity - bch2_fs_sectors_used(c)) >> PAGE_SECTOR_SHIFT;
buf->f_bavail = buf->f_bfree;
buf->f_files = atomic_long_read(&c->nr_inodes);
buf->f_ffree = U64_MAX;
return 0;
}
-static int bch_sync_fs(struct super_block *sb, int wait)
+static int bch2_sync_fs(struct super_block *sb, int wait)
{
struct bch_fs *c = sb->s_fs_info;
if (!wait) {
- bch_journal_flush_async(&c->journal, NULL);
+ bch2_journal_flush_async(&c->journal, NULL);
return 0;
}
- return bch_journal_flush(&c->journal);
+ return bch2_journal_flush(&c->journal);
}
-static struct bch_fs *bch_open_as_blockdevs(const char *_dev_name,
- struct bch_opts opts)
+static struct bch_fs *bch2_open_as_blockdevs(const char *_dev_name,
+ struct bch_opts opts)
{
size_t nr_devs = 0, i = 0;
char *dev_name, *s, **devs;
(s = strchr(s, ':')) && (*s++ = '\0'))
devs[i++] = s;
- err = bch_fs_open(devs, nr_devs, opts, &c);
+ err = bch2_fs_open(devs, nr_devs, opts, &c);
if (err) {
/*
* Already open?
if (IS_ERR(bdev))
goto err;
- c2 = bch_bdev_to_fs(bdev);
+ c2 = bch2_bdev_to_fs(bdev);
bdput(bdev);
if (!c)
mutex_lock(&c->state_lock);
- if (!bch_fs_running(c)) {
+ if (!bch2_fs_running(c)) {
mutex_unlock(&c->state_lock);
closure_put(&c->cl);
err = "incomplete filesystem";
return c;
}
-static int bch_remount(struct super_block *sb, int *flags, char *data)
+static int bch2_remount(struct super_block *sb, int *flags, char *data)
{
struct bch_fs *c = sb->s_fs_info;
- struct bch_opts opts = bch_opts_empty();
+ struct bch_opts opts = bch2_opts_empty();
int ret;
opts.read_only = (*flags & MS_RDONLY) != 0;
- ret = bch_parse_mount_opts(&opts, data);
+ ret = bch2_parse_mount_opts(&opts, data);
if (ret)
return ret;
const char *err = NULL;
if (opts.read_only) {
- bch_fs_read_only(c);
+ bch2_fs_read_only(c);
sb->s_flags |= MS_RDONLY;
} else {
- err = bch_fs_read_write(c);
+ err = bch2_fs_read_write(c);
if (err) {
bch_err(c, "error going rw: %s", err);
return -EINVAL;
}
static const struct super_operations bch_super_operations = {
- .alloc_inode = bch_alloc_inode,
- .destroy_inode = bch_destroy_inode,
- .write_inode = bch_vfs_write_inode,
- .evict_inode = bch_evict_inode,
- .sync_fs = bch_sync_fs,
- .statfs = bch_statfs,
+ .alloc_inode = bch2_alloc_inode,
+ .destroy_inode = bch2_destroy_inode,
+ .write_inode = bch2_vfs_write_inode,
+ .evict_inode = bch2_evict_inode,
+ .sync_fs = bch2_sync_fs,
+ .statfs = bch2_statfs,
.show_options = generic_show_options,
- .remount_fs = bch_remount,
+ .remount_fs = bch2_remount,
#if 0
- .put_super = bch_put_super,
- .freeze_fs = bch_freeze,
- .unfreeze_fs = bch_unfreeze,
+ .put_super = bch2_put_super,
+ .freeze_fs = bch2_freeze,
+ .unfreeze_fs = bch2_unfreeze,
#endif
};
-static int bch_test_super(struct super_block *s, void *data)
+static int bch2_test_super(struct super_block *s, void *data)
{
return s->s_fs_info == data;
}
-static int bch_set_super(struct super_block *s, void *data)
+static int bch2_set_super(struct super_block *s, void *data)
{
s->s_fs_info = data;
return 0;
}
-static struct dentry *bch_mount(struct file_system_type *fs_type,
- int flags, const char *dev_name, void *data)
+static struct dentry *bch2_mount(struct file_system_type *fs_type,
+ int flags, const char *dev_name, void *data)
{
struct bch_fs *c;
struct bch_dev *ca;
struct super_block *sb;
struct inode *inode;
- struct bch_opts opts = bch_opts_empty();
+ struct bch_opts opts = bch2_opts_empty();
unsigned i;
int ret;
opts.read_only = (flags & MS_RDONLY) != 0;
- ret = bch_parse_mount_opts(&opts, data);
+ ret = bch2_parse_mount_opts(&opts, data);
if (ret)
return ERR_PTR(ret);
- c = bch_open_as_blockdevs(dev_name, opts);
+ c = bch2_open_as_blockdevs(dev_name, opts);
if (!c)
return ERR_PTR(-ENOENT);
- sb = sget(fs_type, bch_test_super, bch_set_super, flags|MS_NOSEC, c);
+ sb = sget(fs_type, bch2_test_super, bch2_set_super, flags|MS_NOSEC, c);
if (IS_ERR(sb)) {
closure_put(&c->cl);
return ERR_CAST(sb);
sb->s_blocksize_bits = PAGE_SHIFT;
sb->s_maxbytes = MAX_LFS_FILESIZE;
sb->s_op = &bch_super_operations;
- sb->s_xattr = bch_xattr_handlers;
+ sb->s_xattr = bch2_xattr_handlers;
sb->s_magic = BCACHE_STATFS_MAGIC;
sb->s_time_gran = c->sb.time_precision;
c->vfs_sb = sb;
else
sb->s_flags |= opts.posix_acl ? MS_POSIXACL : 0;
- inode = bch_vfs_inode_get(sb, BCACHE_ROOT_INO);
+ inode = bch2_vfs_inode_get(sb, BCACHE_ROOT_INO);
if (IS_ERR(inode)) {
ret = PTR_ERR(inode);
goto err_put_super;
return ERR_PTR(ret);
}
-static void bch_kill_sb(struct super_block *sb)
+static void bch2_kill_sb(struct super_block *sb)
{
struct bch_fs *c = sb->s_fs_info;
generic_shutdown_super(sb);
if (test_bit(BCH_FS_BDEV_MOUNTED, &c->flags))
- bch_fs_stop(c);
+ bch2_fs_stop(c);
else
closure_put(&c->cl);
}
static struct file_system_type bcache_fs_type = {
.owner = THIS_MODULE,
- .name = "bcache",
- .mount = bch_mount,
- .kill_sb = bch_kill_sb,
+ .name = "bcachefs",
+ .mount = bch2_mount,
+ .kill_sb = bch2_kill_sb,
.fs_flags = FS_REQUIRES_DEV,
};
-MODULE_ALIAS_FS("bcache");
+MODULE_ALIAS_FS("bcachefs");
-void bch_vfs_exit(void)
+void bch2_vfs_exit(void)
{
unregister_filesystem(&bcache_fs_type);
- if (bch_dio_write_bioset)
- bioset_free(bch_dio_write_bioset);
- if (bch_dio_read_bioset)
- bioset_free(bch_dio_read_bioset);
- if (bch_writepage_bioset)
- bioset_free(bch_writepage_bioset);
- if (bch_inode_cache)
- kmem_cache_destroy(bch_inode_cache);
+ if (bch2_dio_write_bioset)
+ bioset_free(bch2_dio_write_bioset);
+ if (bch2_dio_read_bioset)
+ bioset_free(bch2_dio_read_bioset);
+ if (bch2_writepage_bioset)
+ bioset_free(bch2_writepage_bioset);
+ if (bch2_inode_cache)
+ kmem_cache_destroy(bch2_inode_cache);
}
-int __init bch_vfs_init(void)
+int __init bch2_vfs_init(void)
{
int ret = -ENOMEM;
- bch_inode_cache = KMEM_CACHE(bch_inode_info, 0);
- if (!bch_inode_cache)
+ bch2_inode_cache = KMEM_CACHE(bch_inode_info, 0);
+ if (!bch2_inode_cache)
goto err;
- bch_writepage_bioset =
+ bch2_writepage_bioset =
bioset_create(4, offsetof(struct bch_writepage_io, bio.bio));
- if (!bch_writepage_bioset)
+ if (!bch2_writepage_bioset)
goto err;
- bch_dio_read_bioset = bioset_create(4, offsetof(struct dio_read, rbio.bio));
- if (!bch_dio_read_bioset)
+ bch2_dio_read_bioset = bioset_create(4, offsetof(struct dio_read, rbio.bio));
+ if (!bch2_dio_read_bioset)
goto err;
- bch_dio_write_bioset = bioset_create(4, offsetof(struct dio_write, bio.bio));
- if (!bch_dio_write_bioset)
+ bch2_dio_write_bioset = bioset_create(4, offsetof(struct dio_write, bio.bio));
+ if (!bch2_dio_write_bioset)
goto err;
ret = register_filesystem(&bcache_fs_type);
return 0;
err:
- bch_vfs_exit();
+ bch2_vfs_exit();
return ret;
}