]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/fs.c
Update bcachefs sources to b964c6cba8 bcachefs: Change lockrestart_do() to always...
[bcachefs-tools-debian] / libbcachefs / fs.c
index a95358ddefa52dd5df55c563c9e8d367ed3b2218..631fb87b81c9ca9866eaab3413fbe916a6fd4e5a 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/exportfs.h>
 #include <linux/fiemap.h>
 #include <linux/module.h>
+#include <linux/pagemap.h>
 #include <linux/posix_acl.h>
 #include <linux/random.h>
 #include <linux/statfs.h>
@@ -155,7 +156,6 @@ retry:
                bch2_inode_write(&trans, iter, &inode_u) ?:
                bch2_trans_commit(&trans, NULL,
                                  &inode->ei_journal_seq,
-                                 BTREE_INSERT_NOUNLOCK|
                                  BTREE_INSERT_NOFAIL);
 
        /*
@@ -293,8 +293,7 @@ retry:
        if (unlikely(ret))
                goto err_before_quota;
 
-       ret   = bch2_trans_commit(&trans, NULL, &journal_seq,
-                                 BTREE_INSERT_NOUNLOCK);
+       ret   = bch2_trans_commit(&trans, NULL, &journal_seq, 0);
        if (unlikely(ret)) {
                bch2_quota_acct(c, bch_qid(&inode_u), Q_INO, -1,
                                KEY_TYPE_QUOTA_WARN);
@@ -415,8 +414,7 @@ static int __bch2_link(struct bch_fs *c,
        mutex_lock(&inode->ei_update_lock);
        bch2_trans_init(&trans, c, 4, 1024);
 
-       ret = __bch2_trans_do(&trans, NULL, &inode->ei_journal_seq,
-                             BTREE_INSERT_NOUNLOCK,
+       ret = __bch2_trans_do(&trans, NULL, &inode->ei_journal_seq, 0,
                        bch2_link_trans(&trans,
                                        dir->v.i_ino,
                                        inode->v.i_ino, &dir_u, &inode_u,
@@ -468,7 +466,6 @@ static int bch2_unlink(struct inode *vdir, struct dentry *dentry)
        bch2_trans_init(&trans, c, 4, 1024);
 
        ret = __bch2_trans_do(&trans, NULL, &dir->ei_journal_seq,
-                             BTREE_INSERT_NOUNLOCK|
                              BTREE_INSERT_NOFAIL,
                        bch2_unlink_trans(&trans,
                                          dir->v.i_ino, &dir_u,
@@ -589,8 +586,7 @@ static int bch2_rename2(struct user_namespace *mnt_userns,
                        goto err;
        }
 
-       ret = __bch2_trans_do(&trans, NULL, &journal_seq,
-                             BTREE_INSERT_NOUNLOCK,
+       ret = __bch2_trans_do(&trans, NULL, &journal_seq, 0,
                        bch2_rename_trans(&trans,
                                          src_dir->v.i_ino, &src_dir_u,
                                          dst_dir->v.i_ino, &dst_dir_u,
@@ -647,10 +643,10 @@ err:
        return ret;
 }
 
-void bch2_setattr_copy(struct user_namespace *mnt_userns,
-                      struct bch_inode_info *inode,
-                      struct bch_inode_unpacked *bi,
-                      struct iattr *attr)
+static void bch2_setattr_copy(struct user_namespace *mnt_userns,
+                             struct bch_inode_info *inode,
+                             struct bch_inode_unpacked *bi,
+                             struct iattr *attr)
 {
        struct bch_fs *c = inode->v.i_sb->s_fs_info;
        unsigned int ia_valid = attr->ia_valid;
@@ -660,6 +656,9 @@ void bch2_setattr_copy(struct user_namespace *mnt_userns,
        if (ia_valid & ATTR_GID)
                bi->bi_gid = from_kgid(mnt_userns, attr->ia_gid);
 
+       if (ia_valid & ATTR_SIZE)
+               bi->bi_size = attr->ia_size;
+
        if (ia_valid & ATTR_ATIME)
                bi->bi_atime = timespec_to_bch2_time(c, attr->ia_atime);
        if (ia_valid & ATTR_MTIME)
@@ -680,9 +679,9 @@ void bch2_setattr_copy(struct user_namespace *mnt_userns,
        }
 }
 
-static int bch2_setattr_nonsize(struct user_namespace *mnt_userns,
-                               struct bch_inode_info *inode,
-                               struct iattr *attr)
+int bch2_setattr_nonsize(struct user_namespace *mnt_userns,
+                        struct bch_inode_info *inode,
+                        struct iattr *attr)
 {
        struct bch_fs *c = inode->v.i_sb->s_fs_info;
        struct bch_qid qid;
@@ -730,7 +729,6 @@ retry:
        ret =   bch2_inode_write(&trans, inode_iter, &inode_u) ?:
                bch2_trans_commit(&trans, NULL,
                                  &inode->ei_journal_seq,
-                                 BTREE_INSERT_NOUNLOCK|
                                  BTREE_INSERT_NOFAIL);
 btree_err:
        bch2_trans_iter_put(&trans, inode_iter);
@@ -806,7 +804,7 @@ static int bch2_setattr(struct user_namespace *mnt_userns,
                return ret;
 
        return iattr->ia_valid & ATTR_SIZE
-               ? bch2_truncate(inode, iattr)
+               ? bch2_truncate(mnt_userns, inode, iattr)
                : bch2_setattr_nonsize(mnt_userns, inode, iattr);
 }
 
@@ -905,6 +903,8 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info,
        iter = bch2_trans_get_iter(&trans, BTREE_ID_extents,
                                   POS(ei->v.i_ino, start >> 9), 0);
 retry:
+       bch2_trans_begin(&trans);
+
        while ((k = bch2_btree_iter_peek(iter)).k &&
               !(ret = bkey_err(k)) &&
               bkey_cmp(iter->pos, end) < 0) {
@@ -1322,9 +1322,6 @@ static char **split_devs(const char *_dev_name, unsigned *nr)
        char *dev_name = NULL, **devs = NULL, *s;
        size_t i, nr_devs = 0;
 
-       if (strlen(_dev_name) == 0)
-               return NULL;
-
        dev_name = kstrdup(_dev_name, GFP_KERNEL);
        if (!dev_name)
                return NULL;
@@ -1500,6 +1497,9 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
        if (ret)
                return ERR_PTR(ret);
 
+       if (!dev_name || strlen(dev_name) == 0)
+               return ERR_PTR(-EINVAL);
+
        devs = split_devs(dev_name, &nr_devs);
        if (!devs)
                return ERR_PTR(-ENOMEM);