From d814318d8f15cdfa062b3b20bfe036f5b825f60e Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Mon, 25 Jul 2022 16:26:40 +0300 Subject: [PATCH] LU-16044 osd: discard pagecache in truncate's declaration to avoid taking pagelock inside a transaction which conflicts with the write path where we take pagelock before any another one. this should be safe as the write path writes the pages out synchronously, so they should be clean by truncate. Lustre-change: https://review.whamcloud.com/48033 Lustre-commit: 0bb491b2ecf494c3f78fa08a101af8af7853a0fe Signed-off-by: Alex Zhuravlev Signed-off-by: Yang Sheng Change-Id: Iba555ace2ce9ef34ab5517375ecb5c176f738a02 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/48885 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/ofd/ofd_objects.c | 16 +++++----------- lustre/osd-ldiskfs/osd_handler.c | 4 ++++ lustre/osd-ldiskfs/osd_io.c | 28 +++++++++++++++------------- lustre/osd-zfs/osd_object.c | 5 +++-- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/lustre/ofd/ofd_objects.c b/lustre/ofd/ofd_objects.c index f78566c..263a9ec 100644 --- a/lustre/ofd/ofd_objects.c +++ b/lustre/ofd/ofd_objects.c @@ -913,6 +913,11 @@ int ofd_object_punch(const struct lu_env *env, struct ofd_object *fo, if (IS_ERR(th)) GOTO(out, rc = PTR_ERR(th)); + if (oa->o_valid & OBD_MD_FLFLAGS && oa->o_flags & LUSTRE_ENCRYPT_FL) { + /* punch must be aware we are dealing with an encrypted file */ + la->la_valid |= LA_FLAGS; + la->la_flags |= LUSTRE_ENCRYPT_FL; + } rc = dt_declare_attr_set(env, dob, la, th); if (rc) GOTO(stop, rc); @@ -948,17 +953,6 @@ int ofd_object_punch(const struct lu_env *env, struct ofd_object *fo, GOTO(unlock, rc); } - if (oa->o_valid & OBD_MD_FLFLAGS && oa->o_flags & LUSTRE_ENCRYPT_FL) { - /* punch must be aware we are dealing with an encrypted file */ - struct lu_attr la = { - .la_valid = LA_FLAGS, - .la_flags = LUSTRE_ENCRYPT_FL, - }; - - rc = dt_attr_set(env, dob, &la, th); - if (rc) - GOTO(unlock, rc); - } rc = dt_punch(env, dob, start, OBD_OBJECT_EOF, th); if (rc) GOTO(unlock, rc); diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index e03a578..6f5478c 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -2958,6 +2958,10 @@ static int osd_declare_attr_set(const struct lu_env *env, RETURN(rc); } #endif + /* punch must be aware we are dealing with an encrypted file */ + if (attr->la_valid & LA_FLAGS && attr->la_flags & LUSTRE_ENCRYPT_FL) + obj->oo_lma_flags |= LUSTRE_ENCRYPT_FL; + RETURN(rc); } diff --git a/lustre/osd-ldiskfs/osd_io.c b/lustre/osd-ldiskfs/osd_io.c index 54bdc41..d2b7c5d 100644 --- a/lustre/osd-ldiskfs/osd_io.c +++ b/lustre/osd-ldiskfs/osd_io.c @@ -2449,6 +2449,7 @@ static int osd_declare_punch(const struct lu_env *env, struct dt_object *dt, __u64 start, __u64 end, struct thandle *th) { struct osd_thandle *oh; + struct osd_object *obj = osd_dt_obj(dt); struct inode *inode; int rc; ENTRY; @@ -2467,15 +2468,25 @@ static int osd_declare_punch(const struct lu_env *env, struct dt_object *dt, osd_trans_declare_op(env, oh, OSD_OT_PUNCH, osd_dto_credits_noquota[DTO_ATTR_SET_BASE] + 3); - inode = osd_dt_obj(dt)->oo_inode; + inode = obj->oo_inode; LASSERT(inode); rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode), - i_projid_read(inode), 0, oh, osd_dt_obj(dt), + i_projid_read(inode), 0, oh, obj, NULL, OSD_QID_BLK); - if (rc == 0) - rc = osd_trunc_lock(osd_dt_obj(dt), oh, false); + /* if object holds encrypted content, we need to make sure we truncate + * on an encryption unit boundary, or subsequent reads will get + * corrupted content + */ + if (rc == 0) { + if (obj->oo_lma_flags & LUSTRE_ENCRYPT_FL && + start & ~LUSTRE_ENCRYPTION_MASK) + start = (start & LUSTRE_ENCRYPTION_MASK) + + LUSTRE_ENCRYPTION_UNIT_SIZE; + ll_truncate_pagecache(inode, start); + rc = osd_trunc_lock(obj, oh, false); + } RETURN(rc); } @@ -2519,15 +2530,6 @@ static int osd_punch(const struct lu_env *env, struct dt_object *dt, grow = true; i_size_write(inode, start); spin_unlock(&inode->i_lock); - /* if object holds encrypted content, we need to make sure we truncate - * on an encryption unit boundary, or subsequent reads will get - * corrupted content - */ - if (obj->oo_lma_flags & LUSTRE_ENCRYPT_FL && - start & ~LUSTRE_ENCRYPTION_MASK) - start = (start & LUSTRE_ENCRYPTION_MASK) + - LUSTRE_ENCRYPTION_UNIT_SIZE; - ll_truncate_pagecache(inode, start); /* optimize grow case */ if (grow) { diff --git a/lustre/osd-zfs/osd_object.c b/lustre/osd-zfs/osd_object.c index 1c17136..e54fa0b 100644 --- a/lustre/osd-zfs/osd_object.c +++ b/lustre/osd-zfs/osd_object.c @@ -1157,8 +1157,9 @@ static int osd_declare_attr_set(const struct lu_env *env, GOTO(out, rc = -oh->ot_tx->tx_err); if (attr && attr->la_valid & LA_FLAGS) { - /* LMA is usually a part of bonus, no need to declare - * anything else */ + /* punch must be aware we are dealing with an encrypted file */ + if (attr->la_flags & LUSTRE_ENCRYPT_FL) + obj->oo_lma_flags |= LUSTRE_ENCRYPT_FL; } if (attr && (attr->la_valid & (LA_UID | LA_GID | LA_PROJID))) { -- 1.8.3.1