Whamcloud - gitweb
LU-16044 osd: discard pagecache in truncate's declaration 33/48033/14
authorAlex Zhuravlev <bzzz@whamcloud.com>
Mon, 25 Jul 2022 13:26:40 +0000 (16:26 +0300)
committerOleg Drokin <green@whamcloud.com>
Sat, 15 Oct 2022 05:56:23 +0000 (05:56 +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.

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/fs/lustre-release/+/48033
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@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 02d3f45..3abab0f 100644 (file)
@@ -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);
index a3bbd15..661690a 100644 (file)
@@ -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);
 }
 
index 4896da6..2ee7b41 100644 (file)
@@ -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) {
index b772570..9411183 100644 (file)
@@ -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))) {