Whamcloud - gitweb
LU-16044 osd: discard pagecache in truncate's declaration
authorAlex Zhuravlev <bzzz@whamcloud.com>
Mon, 25 Jul 2022 13:26:40 +0000 (16:26 +0300)
committerAndreas Dilger <adilger@whamcloud.com>
Thu, 27 Oct 2022 03:17:42 +0000 (03:17 +0000)
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 <bzzz@whamcloud.com>
Signed-off-by: Yang Sheng <ys@whamcloud.com>
Change-Id: Iba555ace2ce9ef34ab5517375ecb5c176f738a02
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/48885
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/ofd/ofd_objects.c
lustre/osd-ldiskfs/osd_handler.c
lustre/osd-ldiskfs/osd_io.c
lustre/osd-zfs/osd_object.c

index f78566c..263a9ec 100644 (file)
@@ -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);
index e03a578..6f5478c 100644 (file)
@@ -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);
 }
 
index 54bdc41..d2b7c5d 100644 (file)
@@ -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) {
index 1c17136..e54fa0b 100644 (file)
@@ -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))) {