Whamcloud - gitweb
EX-7389 pcc: open file for detach O_RDONLY
authorPatrick Farrell <pfarrell@whamcloud.com>
Tue, 9 May 2023 17:53:23 +0000 (13:53 -0400)
committerAndreas Dilger <adilger@whamcloud.com>
Thu, 11 May 2023 00:41:59 +0000 (00:41 +0000)
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 <pfarrell@whamcloud.com>
Change-Id: I3e289ab52ff760a8ab84a209b968109517953b52
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/50749
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/tests/sanity-pcc.sh
lustre/utils/liblustreapi_pcc.c

index 64f14f1..c83b7ba 100644 (file)
@@ -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"
index c95218f..3e84fb7 100644 (file)
@@ -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'",