From d0d23b6d0121fb526c39aa39cfffa7e0c4c3a097 Mon Sep 17 00:00:00 2001 From: Patrick Farrell Date: Thu, 29 Jun 2023 13:52:01 -0400 Subject: [PATCH] EX-6265 llite: allow mmap reads of compressed files mmap reads of compressed files work, so we should only block writes. We cannot block the actual fault operations because that will cause the application to get a SIGBUS, so we check the file open mode when we go to create the memory mapping. Signed-off-by: Patrick Farrell Change-Id: I636f398fd247ddcd153f94bf8116440540e8469c Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/51506 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Qian Yingjin Reviewed-by: Andreas Dilger --- lustre/llite/llite_mmap.c | 17 ++++++++++++----- lustre/tests/multiop.c | 23 +++++++++++++++++++++-- lustre/tests/sanity.sh | 33 +++++++++++++++++---------------- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/lustre/llite/llite_mmap.c b/lustre/llite/llite_mmap.c index 11d0570..096c589 100644 --- a/lustre/llite/llite_mmap.c +++ b/lustre/llite/llite_mmap.c @@ -603,7 +603,7 @@ 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) +int ll_mmap_check_compression(struct file *file, loff_t off) { struct inode *inode = file_inode(file); struct ll_inode_info *lli = ll_i2info(inode); @@ -615,9 +615,14 @@ int ll_mmap_check_compression(struct file *file, unsigned long off) int rc = 0; __u32 gen; + /* mmap reads of compressed files are supported */ + if ((file->f_flags & O_ACCMODE) == O_RDONLY) + RETURN(0); + rc = ll_layout_refresh(inode, &gen); if (rc) { - CERROR("can't refresh layout: rc=%d\n", rc); + CERROR("%s: "DFID" cannot refresh layout: rc = %d\n", + ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid), rc); RETURN(rc); } if (ll_layout_version_get(lli) == CL_LAYOUT_GEN_EMPTY) @@ -655,8 +660,10 @@ int ll_mmap_check_compression(struct file *file, unsigned long off) rc = -EOPNOTSUPP; } else if (rc == 1 || rc == -ENODATA) { rc = 0; - } else - CDEBUG(D_ERROR, "rc=%d\n", rc); + } else { + CERROR("%s: "DFID" cl_io_rw_init() failed: rc = %d\n", + ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid), rc); + } cl_io_fini(env, io); @@ -681,7 +688,7 @@ 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); + rc = ll_mmap_check_compression(file, (loff_t)vma->vm_pgoff<= $(version_code 2.14.0.85) )) || - skip "Need MDS version at least 2.14.0.85" + (( MDS1_VERSION >= $(version_code 2.14.0.91) )) || + skip "Need MDS version at least 2.14.0.91" local tf=$DIR/$tfile - stack_trap "rm -Rf $DIR/$tfile; disable_compression" + stack_trap "rm -f $tf; 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" + 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 || + $LFS getstripe $tf | grep -q lcme_flags.*compress || error "no compressed component" - $MULTIOP $tf OSMc && error "mmap must be disabled" + $MULTIOP $tf OSMc && + error "(0) writeable mmap of compressed files should not work" + $MULTIOP $tf oSMc || + error "(1) readonly mmap of compressed files should work" 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 + dd if=/dev/zero of=$tf bs=32k count=5 || error "dd(2) to $stored failed" + $MULTIOP $tf OSMc || + error "(2) writeable mmap of uncompressed files should work" + $MULTIOP $tf oSMc || + error "(3) readonly mmap of uncompressed files should work" } 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" + (( MDS1_VERSION >= $(version_code 2.14.0.91) )) || + skip "Need MDS version at least 2.14.0.91" local tf=$DIR/$tfile - stack_trap "rm -f $DIR/$tfile; disable_compression" + stack_trap "rm -f $tf; disable_compression" enable_compression $LFS setstripe -E -1 -Z gzip:3 --compress-chunk=64 $tf || @@ -27836,7 +27838,6 @@ test_460f() { [[ $offset == 131072 ]] || error "offset $offset != 131072" printf "Seeking data from $offset ... " lseek_test -d $offset $tf && error "data lseek should fail" - rm -f $tf return 0 } -- 1.8.3.1