]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/fs-ioctl.c
Update bcachefs sources to 841a95c29f4c bcachefs: fix userspace build errors
[bcachefs-tools-debian] / libbcachefs / fs-ioctl.c
index 269af9393824c14348a2c62b5544e8abb70b2b3c..8098a3a299d1c0e3fc1deea083b7cee1621ef44e 100644 (file)
@@ -31,7 +31,8 @@ struct flags_set {
        bool                    projinherit;
 };
 
-static int bch2_inode_flags_set(struct bch_inode_info *inode,
+static int bch2_inode_flags_set(struct btree_trans *trans,
+                               struct bch_inode_info *inode,
                                struct bch_inode_unpacked *bi,
                                void *p)
 {
@@ -44,13 +45,13 @@ static int bch2_inode_flags_set(struct bch_inode_info *inode,
        unsigned newflags = s->flags;
        unsigned oldflags = bi->bi_flags & s->mask;
 
-       if (((newflags ^ oldflags) & (BCH_INODE_APPEND|BCH_INODE_IMMUTABLE)) &&
+       if (((newflags ^ oldflags) & (BCH_INODE_append|BCH_INODE_immutable)) &&
            !capable(CAP_LINUX_IMMUTABLE))
                return -EPERM;
 
        if (!S_ISREG(bi->bi_mode) &&
            !S_ISDIR(bi->bi_mode) &&
-           (newflags & (BCH_INODE_NODUMP|BCH_INODE_NOATIME)) != newflags)
+           (newflags & (BCH_INODE_nodump|BCH_INODE_noatime)) != newflags)
                return -EINVAL;
 
        if (s->set_projinherit) {
@@ -121,10 +122,14 @@ static int bch2_ioc_fsgetxattr(struct bch_inode_info *inode,
 
        fa.fsx_projid = inode->ei_qid.q[QTYP_PRJ];
 
-       return copy_to_user(arg, &fa, sizeof(fa));
+       if (copy_to_user(arg, &fa, sizeof(fa)))
+               return -EFAULT;
+
+       return 0;
 }
 
-static int fssetxattr_inode_update_fn(struct bch_inode_info *inode,
+static int fssetxattr_inode_update_fn(struct btree_trans *trans,
+                                     struct bch_inode_info *inode,
                                      struct bch_inode_unpacked *bi,
                                      void *p)
 {
@@ -135,7 +140,7 @@ static int fssetxattr_inode_update_fn(struct bch_inode_info *inode,
                bi->bi_project = s->projid;
        }
 
-       return bch2_inode_flags_set(inode, bi, p);
+       return bch2_inode_flags_set(trans, inode, bi, p);
 }
 
 static int bch2_ioc_fssetxattr(struct bch_fs *c,
@@ -192,7 +197,8 @@ err:
        return ret;
 }
 
-static int bch2_reinherit_attrs_fn(struct bch_inode_info *inode,
+static int bch2_reinherit_attrs_fn(struct btree_trans *trans,
+                                  struct bch_inode_info *inode,
                                   struct bch_inode_unpacked *bi,
                                   void *p)
 {
@@ -281,39 +287,31 @@ static int bch2_ioc_goingdown(struct bch_fs *c, u32 __user *arg)
 
        bch_notice(c, "shutdown by ioctl type %u", flags);
 
-       down_write(&c->vfs_sb->s_umount);
-
        switch (flags) {
        case FSOP_GOING_FLAGS_DEFAULT:
                ret = freeze_bdev(c->vfs_sb->s_bdev);
                if (ret)
-                       goto err;
-
+                       break;
                bch2_journal_flush(&c->journal);
-               c->vfs_sb->s_flags |= SB_RDONLY;
                bch2_fs_emergency_read_only(c);
                thaw_bdev(c->vfs_sb->s_bdev);
                break;
-
        case FSOP_GOING_FLAGS_LOGFLUSH:
                bch2_journal_flush(&c->journal);
                fallthrough;
-
        case FSOP_GOING_FLAGS_NOLOGFLUSH:
-               c->vfs_sb->s_flags |= SB_RDONLY;
                bch2_fs_emergency_read_only(c);
                break;
        default:
                ret = -EINVAL;
                break;
        }
-err:
-       up_write(&c->vfs_sb->s_umount);
+
        return ret;
 }
 
-static long bch2_ioctl_subvolume_create(struct bch_fs *c, struct file *filp,
-                               struct bch_ioctl_subvolume arg)
+static long __bch2_ioctl_subvolume_create(struct bch_fs *c, struct file *filp,
+                                         struct bch_ioctl_subvolume arg)
 {
        struct inode *dir;
        struct bch_inode_info *inode;
@@ -382,7 +380,7 @@ retry:
 
        dir = dst_path.dentry->d_inode;
        if (IS_DEADDIR(dir)) {
-               error = -ENOENT;
+               error = -BCH_ERR_ENOENT_directory_dead;
                goto err3;
        }
 
@@ -407,7 +405,7 @@ retry:
 
        if ((arg.flags & BCH_SUBVOL_SNAPSHOT_CREATE) &&
            !arg.src_ptr)
-               snapshot_src.subvol = to_bch_ei(dir)->ei_inode.bi_subvol;
+               snapshot_src.subvol = inode_inum(to_bch_ei(dir)).subvol;
 
        inode = __bch2_create(file_mnt_idmap(filp), to_bch_ei(dir),
                              dst_dentry, arg.mode|S_IFDIR,
@@ -434,6 +432,16 @@ err1:
        return error;
 }
 
+static long bch2_ioctl_subvolume_create(struct bch_fs *c, struct file *filp,
+                                       struct bch_ioctl_subvolume arg)
+{
+       down_write(&c->snapshot_create_lock);
+       long ret = __bch2_ioctl_subvolume_create(c, filp, arg);
+       up_write(&c->snapshot_create_lock);
+
+       return ret;
+}
+
 static long bch2_ioctl_subvolume_destroy(struct bch_fs *c, struct file *filp,
                                struct bch_ioctl_subvolume arg)
 {