Whamcloud - gitweb
EX-6265 llite: disable mmap on compressed files
authorAlex Zhuravlev <bzzz@whamcloud.com>
Thu, 22 Jun 2023 08:36:51 +0000 (11:36 +0300)
committerAndreas Dilger <adilger@whamcloud.com>
Sat, 1 Jul 2023 10:05:03 +0000 (10:05 +0000)
disable mmap(2) on compressed files until well tested.

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: I3464a03b16708edcd0692bc9db337eb8473ea047
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/51413
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/llite/llite_mmap.c
lustre/tests/sanity.sh

index 4b55eab..11d0570 100644 (file)
@@ -603,6 +603,68 @@ static const struct vm_operations_struct ll_file_vm_ops = {
        .close                  = ll_vm_close,
 };
 
+int ll_mmap_check_compression(struct file *file, unsigned long off)
+{
+       struct inode *inode = file_inode(file);
+       struct ll_inode_info *lli = ll_i2info(inode);
+       struct vvp_io_args *args;
+       struct kiocb kiocb;
+       struct lu_env *env;
+       struct cl_io *io;
+       __u16 refcheck;
+       int rc = 0;
+       __u32 gen;
+
+       rc = ll_layout_refresh(inode, &gen);
+       if (rc) {
+               CERROR("can't refresh layout: rc=%d\n", rc);
+               RETURN(rc);
+       }
+       if (ll_layout_version_get(lli) == CL_LAYOUT_GEN_EMPTY)
+               RETURN(0);
+       /* XXX: ignore PCC for a while */
+       if (lli->lli_pcc_inode || lli->lli_pcc_generation)
+               RETURN(0);
+       init_sync_kiocb(&kiocb, file);
+       kiocb.ki_pos = off;
+#ifdef HAVE_KIOCB_KI_LEFT
+       kiocb.ki_left = 4096;
+#elif defined(HAVE_KI_NBYTES)
+       kiocb.ki_nbytes = 4096;
+#endif
+
+       env = cl_env_get(&refcheck);
+       if (IS_ERR(env))
+               RETURN(PTR_ERR(env));
+
+       io = vvp_env_thread_io(env);
+
+       args = ll_env_args(env);
+       args->u.normal.via_iter = NULL;
+       args->u.normal.via_iocb = &kiocb;
+       ll_io_init(io, file, CIT_FAULT, args);
+
+       io->ci_dio_aio = NULL;
+       io->ci_dio_lock = 0;
+       io->ci_ndelay_tried = 0;
+       io->ci_parallel_dio = false;
+
+       rc = cl_io_rw_init(env, io, CIT_FAULT, off, 4096);
+       if (rc == 0) {
+               if (io->ci_compressed_io)
+                       rc = -EOPNOTSUPP;
+       } else if (rc == 1 || rc == -ENODATA) {
+               rc = 0;
+       } else
+               CDEBUG(D_ERROR, "rc=%d\n", rc);
+
+       cl_io_fini(env, io);
+
+       cl_env_put(env, &refcheck);
+
+       RETURN(rc);
+}
+
 int ll_file_mmap(struct file *file, struct vm_area_struct * vma)
 {
        struct inode *inode = file_inode(file);
@@ -619,6 +681,10 @@ int ll_file_mmap(struct file *file, struct vm_area_struct * vma)
        if (ll_file_nolock(file))
                RETURN(-EOPNOTSUPP);
 
+       rc = ll_mmap_check_compression(file, vma->vm_pgoff << PAGE_SHIFT);
+       if (rc)
+               RETURN(rc);
+
        rc = pcc_file_mmap(file, vma, &cached);
        if (cached && rc != 0)
                RETURN(rc);
index 8a08408..321a4ca 100755 (executable)
@@ -27777,6 +27777,38 @@ test_460d() {
 }
 run_test 460d "Check encrypt pools output"
 
+test_460e() {
+       (( MDS1_VERSION >= $(version_code 2.14.0.85) )) ||
+               skip "Need MDS version at least 2.14.0.85"
+
+       local tf=$DIR/$tfile
+
+       stack_trap "rm -Rf $DIR/$tfile; disable_compression"
+       enable_compression
+
+       $LFS setstripe -E -1 -Z lz4:5 --compress-chunk=64 $tf ||
+               error "set a compress component in $tf failed"
+
+       dd if=/dev/zero of=$tf bs=32k count=5 ||
+               error "dd to $stored failed"
+
+       sync; echo 3 > /proc/sys/vm/drop_caches
+
+       $LFS getstripe $tf
+       $LFS getstripe $tf | grep lcme_flags.*compress ||
+               error "no compressed component"
+
+       $MULTIOP $tf OSMc && error "mmap must be disabled"
+
+       rm -f $tf
+       dd if=/dev/zero of=$tf bs=32k count=5 ||
+               error "dd to $stored failed"
+       $MULTIOP $tf OSMc || error "mmap must be disabled"
+
+       return 0
+}
+run_test 460e "verify mmap is disabled with compressed files"
+
 test_460f() {
        (( MDS1_VERSION >= $(version_code 2.14.0.90) )) ||
                skip "Need MDS version at least 2.14.0.90"