From b175a0cac37fc9c398e6898664362112b818e226 Mon Sep 17 00:00:00 2001 From: Patrick Farrell Date: Tue, 9 May 2023 13:53:23 -0400 Subject: [PATCH] EX-7389 pcc: open file for detach O_RDONLY llapi_pcc_detach_file is rdwr, but should just be rdonly. This means files can be attached but not detached if the client is mounted rdonly. The fix is just to open the file in detach with O_RDONLY. Signed-off-by: Patrick Farrell Change-Id: I3e289ab52ff760a8ab84a209b968109517953b52 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/50749 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/tests/sanity-pcc.sh | 17 +++++++++++++++++ lustre/utils/liblustreapi_pcc.c | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lustre/tests/sanity-pcc.sh b/lustre/tests/sanity-pcc.sh index 64f14f13..c83b7ba3 100644 --- a/lustre/tests/sanity-pcc.sh +++ b/lustre/tests/sanity-pcc.sh @@ -1622,6 +1622,23 @@ test_16() { do_facet $SINGLEAGT "[ -f $lpcc_path ]" && error "RO-PCC cached file '$lpcc_path' should be removed" + # Test pccro attach and detach with readonly client mount + umount_client $MOUNT + stack_trap "mount_client $MOUNT $MOUNT_OPS" EXIT + mount_client $MOUNT "$MOUNT_OPTS,ro" || + error "Mount client with 'ro' should succeed" + stack_trap "umount_client $MOUNT" EXIT + + do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER -r $file || + error "RO-PCC attach $file failed" + check_lpcc_state $file "readonly" + + do_facet $SINGLEAGT $LFS pcc detach $file || + error "RO-PCC detach $file failed" + check_lpcc_state $file "none" + do_facet $SINGLEAGT "[ -f $lpcc_path ]" && + error "RO-PCC cached file '$lpcc_path' should be removed" + return 0 } run_test 16 "Test detach with different options" diff --git a/lustre/utils/liblustreapi_pcc.c b/lustre/utils/liblustreapi_pcc.c index c95218f..3e84fb7 100644 --- a/lustre/utils/liblustreapi_pcc.c +++ b/lustre/utils/liblustreapi_pcc.c @@ -369,7 +369,7 @@ int llapi_pcc_detach_file(const char *path, __u32 flags) /* Specify O_FILE_ENC | O_DIRECT flags to allow pcc detach * on encrypted file without the key. */ - fd = open(path, O_RDWR | O_NONBLOCK | O_FILE_ENC | O_DIRECT); + fd = open(path, O_RDONLY | O_NONBLOCK | O_FILE_ENC | O_DIRECT); if (fd < 0) { rc = -errno; llapi_error(LLAPI_MSG_ERROR, rc, "cannot open '%s'", -- 1.8.3.1