summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-12-19 08:43:01 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:14 -0400
commit2fab25cdd70be6868936639dfb03eaa9fa0245c0 (patch)
treebe7d06507d673e81f7400edb3a9c5565f00b0de9
parent69d46f903120d4aab0e0ad239191245d839224cc (diff)
downloadlinux-2fab25cdd70be6868936639dfb03eaa9fa0245c0.tar.gz
linux-2fab25cdd70be6868936639dfb03eaa9fa0245c0.tar.bz2
linux-2fab25cdd70be6868936639dfb03eaa9fa0245c0.zip
bcachefs: more project quota fixes
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/fs-ioctl.c26
-rw-r--r--fs/bcachefs/fs.h13
-rw-r--r--fs/bcachefs/quota.h2
-rw-r--r--fs/bcachefs/xattr.c7
4 files changed, 27 insertions, 21 deletions
diff --git a/fs/bcachefs/fs-ioctl.c b/fs/bcachefs/fs-ioctl.c
index 92939befe507..4925a127a335 100644
--- a/fs/bcachefs/fs-ioctl.c
+++ b/fs/bcachefs/fs-ioctl.c
@@ -104,19 +104,6 @@ static int bch2_ioc_fsgetxattr(struct bch_inode_info *inode,
return copy_to_user(arg, &fa, sizeof(fa));
}
-static int bch2_set_projid(struct bch_fs *c,
- struct bch_inode_info *inode,
- u32 projid)
-{
- struct bch_qid qid = inode->ei_qid;
-
- qid.q[QTYP_PRJ] = projid;
-
- return bch2_fs_quota_transfer(c, inode, qid,
- 1 << QTYP_PRJ,
- KEY_TYPE_QUOTA_PREALLOC);
-}
-
static int fssetxattr_inode_update_fn(struct bch_inode_info *inode,
struct bch_inode_unpacked *bi,
void *p)
@@ -124,11 +111,7 @@ static int fssetxattr_inode_update_fn(struct bch_inode_info *inode,
struct flags_set *s = p;
if (s->projid != bi->bi_project) {
- if (s->projid)
- bi->bi_fields_set |= 1U << Inode_opt_project;
- else
- bi->bi_fields_set &= ~(1U << Inode_opt_project);
-
+ bi->bi_fields_set |= 1U << Inode_opt_project;
bi->bi_project = s->projid;
}
@@ -151,7 +134,10 @@ static int bch2_ioc_fssetxattr(struct bch_fs *c,
if (fa.fsx_xflags)
return -EOPNOTSUPP;
- s.projid = fa.fsx_projid;
+ if (fa.fsx_projid >= U32_MAX)
+ return -EINVAL;
+
+ s.projid = fa.fsx_projid + 1;
ret = mnt_want_write_file(file);
if (ret)
@@ -164,7 +150,7 @@ static int bch2_ioc_fssetxattr(struct bch_fs *c,
}
mutex_lock(&inode->ei_update_lock);
- ret = bch2_set_projid(c, inode, fa.fsx_projid);
+ ret = bch2_set_projid(c, inode, s.projid);
if (ret)
goto err_unlock;
diff --git a/fs/bcachefs/fs.h b/fs/bcachefs/fs.h
index 4c584d3a27c3..f949cd0d2a68 100644
--- a/fs/bcachefs/fs.h
+++ b/fs/bcachefs/fs.h
@@ -121,6 +121,19 @@ int bch2_fs_quota_transfer(struct bch_fs *,
unsigned,
enum quota_acct_mode);
+static inline int bch2_set_projid(struct bch_fs *c,
+ struct bch_inode_info *inode,
+ u32 projid)
+{
+ struct bch_qid qid = inode->ei_qid;
+
+ qid.q[QTYP_PRJ] = projid;
+
+ return bch2_fs_quota_transfer(c, inode, qid,
+ 1 << QTYP_PRJ,
+ KEY_TYPE_QUOTA_PREALLOC);
+}
+
struct inode *bch2_vfs_inode_get(struct bch_fs *, u64);
/* returns 0 if we want to do the update, or error is passed up */
diff --git a/fs/bcachefs/quota.h b/fs/bcachefs/quota.h
index 72b5ea0d77c5..51e4f9713ef0 100644
--- a/fs/bcachefs/quota.h
+++ b/fs/bcachefs/quota.h
@@ -20,7 +20,7 @@ static inline struct bch_qid bch_qid(struct bch_inode_unpacked *u)
return (struct bch_qid) {
.q[QTYP_USR] = u->bi_uid,
.q[QTYP_GRP] = u->bi_gid,
- .q[QTYP_PRJ] = u->bi_project,
+ .q[QTYP_PRJ] = u->bi_project ? u->bi_project - 1 : 0,
};
}
diff --git a/fs/bcachefs/xattr.c b/fs/bcachefs/xattr.c
index dfb5c385e8c3..f31eec2f1fce 100644
--- a/fs/bcachefs/xattr.c
+++ b/fs/bcachefs/xattr.c
@@ -515,7 +515,14 @@ static int bch2_xattr_bcachefs_set(const struct xattr_handler *handler,
}
mutex_lock(&inode->ei_update_lock);
+ if (inode_opt_id == Inode_opt_project) {
+ ret = bch2_set_projid(c, inode, s.v);
+ if (ret)
+ goto err;
+ }
+
ret = bch2_write_inode(c, inode, inode_opt_set_fn, &s, 0);
+err:
mutex_unlock(&inode->ei_update_lock);
if (value &&