From 0bb491b2ecf494c3f78fa08a101af8af7853a0fe Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Mon, 25 Jul 2022 16:26:40 +0300 Subject: [PATCH 1/1] 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. Signed-off-by: Alex Zhuravlev Signed-off-by: Yang Sheng Change-Id: Iba555ace2ce9ef34ab5517375ecb5c176f738a02 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/48033 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Sebastien Buisson Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- 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 02d3f45..3abab0f 100644 --- a/lustre/ofd/ofd_objects.c +++ b/lustre/ofd/ofd_objects.c @@ -912,6 +912,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); @@ -947,17 +952,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 a3bbd15..661690a 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -2899,6 +2899,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 4896da6..2ee7b41 100644 --- a/lustre/osd-ldiskfs/osd_io.c +++ b/lustre/osd-ldiskfs/osd_io.c @@ -2506,6 +2506,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; @@ -2524,15 +2525,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); } @@ -2576,15 +2587,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 b772570..9411183 100644 --- a/lustre/osd-zfs/osd_object.c +++ b/lustre/osd-zfs/osd_object.c @@ -1185,8 +1185,9 @@ static int osd_declare_attr_set(const struct lu_env *env, GOTO(out_sem, 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