From 1c8a49bedff274677594833cb4958027c6b338db Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Thu, 20 Oct 2022 08:27:48 +0300 Subject: [PATCH] LU-11404 llite: only first sync to MDS matter fsync() is supposed to sync metadata and data, but given file's layout the only first MDS_SYNC matters to ensure the file creation has been committed, everything else go to OSTs (data and attributes) also, uid/gid/mode, EAs and ACLs must be subject to sync. Change-Id: Iaa9095a9ace319a6dfa8840313dc536e39786847 Signed-off-by: Alex Zhuravlev Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/33175 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Mikhail Pershin Reviewed-by: Oleg Drokin --- lustre/llite/acl.c | 2 ++ lustre/llite/file.c | 19 ++++++++++++++----- lustre/llite/llite_internal.h | 1 + lustre/llite/llite_lib.c | 1 + lustre/llite/xattr.c | 1 + 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lustre/llite/acl.c b/lustre/llite/acl.c index 5ae1aab..7d6d5be 100644 --- a/lustre/llite/acl.c +++ b/lustre/llite/acl.c @@ -108,6 +108,8 @@ int ll_set_acl(struct user_namespace *mnt_userns, struct inode *inode, rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), value ? OBD_MD_FLXATTR : OBD_MD_FLXATTRRM, name, value, value_size, 0, 0, &req); + if (!rc) + ll_i2info(inode)->lli_synced_to_mds = false; ptlrpc_req_finished(req); out_value: diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 70c55e8..04138c5 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -4798,11 +4798,20 @@ int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync) } } - err = md_fsync(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode), &req); - if (!rc) - rc = err; - if (!err) - ptlrpc_req_finished(req); + if (S_ISREG(inode->i_mode) && !lli->lli_synced_to_mds) { + /* + * only the first sync on MDS makes sense, + * everything else is stored on OSTs + */ + err = md_fsync(ll_i2sbi(inode)->ll_md_exp, + ll_inode2fid(inode), &req); + if (!rc) + rc = err; + if (!err) { + lli->lli_synced_to_mds = true; + ptlrpc_req_finished(req); + } + } if (S_ISREG(inode->i_mode)) { struct ll_file_data *fd = file->private_data; diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index 6e8b5c6..ab81f01 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -150,6 +150,7 @@ struct ll_inode_info { s64 lli_ctime; s64 lli_btime; spinlock_t lli_agl_lock; + bool lli_synced_to_mds; /* inode specific open lock caching threshold */ u32 lli_open_thrsh_count; diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index 4fcf0a7..39b3edb 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -2300,6 +2300,7 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, rc = ll_md_setattr(dentry, op_data); if (rc) GOTO(out, rc); + lli->lli_synced_to_mds = false; if (!S_ISREG(inode->i_mode) || hsm_import) GOTO(out, rc = 0); diff --git a/lustre/llite/xattr.c b/lustre/llite/xattr.c index 9231650..a6c0d91 100644 --- a/lustre/llite/xattr.c +++ b/lustre/llite/xattr.c @@ -175,6 +175,7 @@ static int ll_xattr_set_common(const struct xattr_handler *handler, } RETURN(rc); } + ll_i2info(inode)->lli_synced_to_mds = false; ptlrpc_req_finished(req); -- 1.8.3.1