[lustre-devel] [PATCH 03/13] lustre: quota: fallocate send UID/GID for quota

James Simmons jsimmons at infradead.org
Wed Dec 29 06:51:17 PST 2021


From: Arshad Hussain <arshad.hussain at aeoncomputing.com>

Calling fallocate() on a newly created file did not account quota
usage properly because the OST object did not have a UID/GID
assigned yet. Update the fallocate code in the OSC to always send
the file UID/GID/PROJID to the OST so that the object ownership
can be updated before space is allocated.

Fixes: d748d2ffa1bc ("lustre: fallocate: Implement fallocate preallocate operation")
WC-bug-id: https://jira.whamcloud.com/browse/LU-15167
Lustre-commit: 789038c97ae107287 ("LU-15167 quota: fallocate send UID/GID for quota")
Signed-off-by: Arshad Hussain <arshad.hussain at aeoncomputing.com>
Reviewed-on: https://review.whamcloud.com/45475
Reviewed-by: Andreas Dilger <adilger at whamcloud.com>
Reviewed-by: Bobi Jam <bobijam at hotmail.com>
Reviewed-by: Oleg Drokin <green at whamcloud.com>
Signed-off-by: James Simmons <jsimmons at infradead.org>
---
 fs/lustre/include/cl_object.h | 2 ++
 fs/lustre/llite/file.c        | 8 ++++++++
 fs/lustre/lov/lov_io.c        | 4 ++++
 fs/lustre/osc/osc_io.c        | 8 +++++++-
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/fs/lustre/include/cl_object.h b/fs/lustre/include/cl_object.h
index a65240b..1746c4e 100644
--- a/fs/lustre/include/cl_object.h
+++ b/fs/lustre/include/cl_object.h
@@ -1877,6 +1877,8 @@ struct cl_io {
 			int			sa_falloc_mode;
 			loff_t			sa_falloc_offset;
 			loff_t			sa_falloc_end;
+			uid_t			sa_falloc_uid;
+			gid_t			sa_falloc_gid;
 		} ci_setattr;
 		struct cl_data_version_io {
 			u64			dv_data_version;
diff --git a/fs/lustre/llite/file.c b/fs/lustre/llite/file.c
index 898db80..20571c9 100644
--- a/fs/lustre/llite/file.c
+++ b/fs/lustre/llite/file.c
@@ -5244,6 +5244,14 @@ int cl_falloc(struct file *file, struct inode *inode, int mode, loff_t offset,
 	io->u.ci_setattr.sa_falloc_offset = offset;
 	io->u.ci_setattr.sa_falloc_end = offset + len;
 	io->u.ci_setattr.sa_subtype = CL_SETATTR_FALLOCATE;
+
+	CDEBUG(D_INODE, "UID %u GID %u\n",
+	       from_kuid(&init_user_ns, inode->i_uid),
+	       from_kgid(&init_user_ns, inode->i_gid));
+
+	io->u.ci_setattr.sa_falloc_uid = from_kuid(&init_user_ns, inode->i_uid);
+	io->u.ci_setattr.sa_falloc_gid = from_kgid(&init_user_ns, inode->i_gid);
+
 	if (io->u.ci_setattr.sa_falloc_end > size) {
 		loff_t newsize = io->u.ci_setattr.sa_falloc_end;
 
diff --git a/fs/lustre/lov/lov_io.c b/fs/lustre/lov/lov_io.c
index d5f895f..8df13ee 100644
--- a/fs/lustre/lov/lov_io.c
+++ b/fs/lustre/lov/lov_io.c
@@ -680,6 +680,10 @@ static void lov_io_sub_inherit(struct lov_io_sub *sub, struct lov_io *lio,
 		if (cl_io_is_fallocate(io)) {
 			io->u.ci_setattr.sa_falloc_offset = start;
 			io->u.ci_setattr.sa_falloc_end = end;
+			io->u.ci_setattr.sa_falloc_uid =
+				parent->u.ci_setattr.sa_falloc_uid;
+			io->u.ci_setattr.sa_falloc_gid =
+				parent->u.ci_setattr.sa_falloc_gid;
 		}
 		if (cl_io_is_trunc(io)) {
 			loff_t new_size = parent->u.ci_setattr.sa_attr.lvb_size;
diff --git a/fs/lustre/osc/osc_io.c b/fs/lustre/osc/osc_io.c
index b867985..b84022b 100644
--- a/fs/lustre/osc/osc_io.c
+++ b/fs/lustre/osc/osc_io.c
@@ -669,7 +669,13 @@ static int osc_io_setattr_start(const struct lu_env *env,
 
 			oa->o_size = io->u.ci_setattr.sa_falloc_offset;
 			oa->o_blocks = io->u.ci_setattr.sa_falloc_end;
-			oa->o_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
+			oa->o_uid = io->u.ci_setattr.sa_falloc_uid;
+			oa->o_gid = io->u.ci_setattr.sa_falloc_gid;
+			oa->o_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
+				OBD_MD_FLUID | OBD_MD_FLGID;
+
+			CDEBUG(D_INODE, "size %llu blocks %llu uid %u gid %u\n",
+			       oa->o_size, oa->o_blocks, oa->o_uid, oa->o_gid);
 			result = osc_fallocate_base(osc_export(cl2osc(obj)),
 						    oa, osc_async_upcall,
 						    cbargs, falloc_mode);
-- 
1.8.3.1



More information about the lustre-devel mailing list