From 95d256846f9b97244297cf71d7f200cba79301ff Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Wed, 15 Jun 2022 03:59:52 -0400 Subject: [PATCH] EX-5358 pcc: remove realpath() from lfs_pcc_state() Before Ubuntu 20.04, realpath() executes lstat() for each component of the path. If the file is still valid cached on PCC device with the layout generation unchanged, the Lustre file will be auto re-attach during the stat() call in the Lustre kernel. This may result in misunderstanding for the operation "lfs pcc state" on a file that has already detached but still valid cached on PCC according to the unchanged layout generation. This problem exposes on the newer Ubuntu 22.04 in which realpath() executes readlink() for each component of the path instead of lstat(): readlink("/mnt", 0x7fffd5760800, 1023) = -1 readlink("/mnt/lustre", 0x7fffd5760800, 1023) = -1 readlink("/mnt/lustre/sanity-pcc.f15", 0x7fffd5760800, 1023) = -1 In this patch, it remove realpath() from lfs_pcc_state() to avoid this misunderstanding behavior for the command: $LFS pcc state. And it also fixes the test scripts sanity-pcc: test_15, test_16, test_27, test_39. Change-Id: I50ae46a1e952a3faaf0d7a7293579e239156d6d3 Test-Parameters: clientdistro=el8.5 env=SANITY_PCC_EXCEPT="101a" testlist=sanity-pcc Test-Parameters: clientdistro=ubuntu2204 env=SANITY_PCC_EXCEPT="101a 39" testlist=sanity-pcc Test-Parameters: clientdistro=ubuntu2004 env=SANITY_PCC_EXCEPT="101a" testlist=sanity-pcc Signed-off-by: Qian Yingjin Reviewed-on: https://review.whamcloud.com/47632 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/tests/sanity-pcc.sh | 61 ++++++++++++++++++++++++++++++---------------- lustre/utils/lfs.c | 19 ++++----------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/lustre/tests/sanity-pcc.sh b/lustre/tests/sanity-pcc.sh index 9a4f9da..45bd1f0 100644 --- a/lustre/tests/sanity-pcc.sh +++ b/lustre/tests/sanity-pcc.sh @@ -12,8 +12,8 @@ export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin ONLY=${ONLY:-"$*"} ALWAYS_EXCEPT="$SANITY_PCC_EXCEPT " -# bug number for skipped test: EX-3763 -ALWAYS_EXCEPT+=" 44 " +# bug number for skipped test: EX-3763 LU-15969 +ALWAYS_EXCEPT+=" 44 39" # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT! ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true} @@ -1482,12 +1482,18 @@ test_15() { # detached automatically. do_facet $SINGLEAGT $LCTL \ set_param ldlm.namespaces.*mdc*.lru_size=clear + check_lpcc_state $file "none" $SINGLEAGT "$RUNAS" + do_facet $SINGLEAGT $RUNAS $MULTIOP $file oc || + error "failed to open $file" check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS" # Detach the file but keep the cache , as the file layout generation # is not changed, so the file is still valid cached in PCC, and can # be reused from PCC cache directly. do_facet $SINGLEAGT $RUNAS $LFS pcc detach -k $file || error "PCC detach $file failed" + check_lpcc_state $file "none" $SINGLEAGT "$RUNAS" + do_facet $SINGLEAGT $RUNAS $MULTIOP $file oc || + error "failed to open $file" check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS" do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file || error "PCC detach $file failed" @@ -1511,6 +1517,8 @@ test_15() { # and can be reused from PCC cache directly. do_facet $SINGLEAGT $LFS pcc detach -k $file || error "RW-PCC detach $file failed" + check_lpcc_state $file "none" + do_facet $SINGLEAGT $MULTIOP $file oc || error "failed to open $file" check_lpcc_state $file "readwrite" # HSM released exists archived status check_hsm_flags $file "0x0000000d" @@ -1541,6 +1549,8 @@ test_15() { # and can be reused from PCC cache directly. do_facet $SINGLEAGT $LFS pcc detach -k $file || error "RO-PCC detach $file failed" + check_lpcc_state $file "none" + do_facet $SINGLEAGT $MULTIOP $file oc || error "failed to open $file" check_lpcc_state $file "readonly" check_file_data $SINGLEAGT $file "autoattach_data" do_facet $SINGLEAGT $LFS pcc detach $file || @@ -1575,7 +1585,7 @@ test_16() { # Valid PCC cache can be reused do_facet $SINGLEAGT $LFS pcc detach -k $file || error "PCC detach $file failed" - check_lpcc_state $file "readwrite" + check_lpcc_state $file "none" # HSM released exists archived status check_hsm_flags $file "0x0000000d" @@ -1597,6 +1607,9 @@ test_16() { do_facet $SINGLEAGT $LFS pcc detach -k $file || error "RO-PCC detach $file failed" + check_lpcc_state $file "none" + # Reading the file will re-attach the file in readonly mode + do_facet $SINGLEAGT cat $file || error "cat $file failed" check_lpcc_state $file "readonly" do_facet $SINGLEAGT $LFS pcc detach $file || @@ -1737,7 +1750,7 @@ test_20() { local hsm_root="$mntpt/$tdir" local file=$DIR/$tfile - setup_loopdev $SINGLEAGT $loopfile $mntpt 50 + setup_loopdev $SINGLEAGT $loopfile $mntpt 120 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER" setup_pcc_mapping $SINGLEAGT \ "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1" @@ -2600,7 +2613,7 @@ test_27() { rmultiop_start $agt_host $file O_c || error "multiop $file failed" do_facet $SINGLEAGT $LFS pcc detach -k $file || error "detach $file failed" - check_lpcc_state $file "readwrite" + check_lpcc_state $file "none" check_file_data $SINGLEAGT $file "auto_attach_multi_open" check_lpcc_state $file "readwrite" do_facet $SINGLEAGT $LFS pcc detach $file || @@ -2617,7 +2630,7 @@ test_27() { rmultiop_start $agt_host $file O_c || error "multiop $file failed" do_facet $SINGLEAGT $LCTL \ set_param ldlm.namespaces.*mdc*.lru_size=clear - check_lpcc_state $file "readwrite" + check_lpcc_state $file "none" check_file_data $SINGLEAGT $file "auto_attach_multi_open" check_lpcc_state $file "readwrite" do_facet $SINGLEAGT $LFS pcc detach $file || @@ -2632,7 +2645,7 @@ test_27() { rmultiop_start $agt_host $file O_c || error "multiop $file failed" do_facet $SINGLEAGT $LFS pcc detach -k $file || error "detach $file failed" - check_lpcc_state $file "readonly" + check_lpcc_state $file "none" check_file_data $SINGLEAGT $file "auto_attach_multi_open" check_lpcc_state $file "readonly" do_facet $SINGLEAGT $LFS pcc detach $file || @@ -2646,7 +2659,7 @@ test_27() { rmultiop_start $agt_host $file O_c || error "multiop $file failed" do_facet $SINGLEAGT $LCTL \ set_param ldlm.namespaces.*mdc*.lru_size=clear - check_lpcc_state $file "readonly" + check_lpcc_state $file "none" check_file_data $SINGLEAGT $file "auto_attach_multi_open" check_lpcc_state $file "readonly" do_facet $SINGLEAGT $LFS pcc detach $file || @@ -3242,7 +3255,7 @@ test_39() { local file=$dir/$tfile local id=100 - setup_loopdev_project $SINGLEAGT $loopfile $mntpt 50 + setup_loopdev_project $SINGLEAGT $loopfile $mntpt 120 do_facet $SINGLEAGT quotaon -Ppv $mntpt do_facet $SINGLEAGT setquota -P $id 0 4096 0 0 $mntpt || error "setquota -P $id on $mntpt failed" @@ -4211,12 +4224,18 @@ test_101a() { # Revoke the layout lock, the PCC-cached file will be # detached automatically. do_facet $SINGLEAGT $LCTL set_param ldlm.namespaces.*mdc*.lru_size=clear + check_lpcc_state $file "none" $SINGLEAGT "$RUNAS" + do_facet $SINGLEAGT $RUNAS $MULTIOP $file oc || + error "failed to open $file" check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS" # Detach the file but keep the cache, as the file layout generation # is not changed, so the file is still valid cached in PCC, and can # be reused from PCC cache directly. do_facet $SINGLEAGT nsenter -t $PID -U -m $LFS pcc detach -k $file || error "PCC detach $file failed" + check_lpcc_state $file "none" $SINGLEAGT "$RUNAS" + do_facet $SINGLEAGT nsenter -t $PID -U -m $MULTIOP $file oc || + error "failed to open $file" check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS" do_facet $SINGLEAGT nsenter -t $PID -U -m $LFS pcc detach $file || error "PCC detach $file failed" @@ -4249,10 +4268,10 @@ test_101a() { # and can be reused from PCC cache directly. do_facet $SINGLEAGT $LFS pcc detach -k $file || error "RW-PCC detach $file failed" - check_lpcc_state $file "readwrite" # HSM released exists archived status check_hsm_flags $file "0x0000000d" check_file_data $SINGLEAGT $file "autoattach_data" $PID + check_lpcc_state $file "readwrite" # HSM restore the PCC cached file, the layout generation # was changed, so the file can not be auto attached. @@ -4319,7 +4338,7 @@ test_200() { LPCC_PURGE=${LPCC_PURGE:-$(do_facet $SINGLEAGT "which lpcc_purge")} [[ -n "$LPCC_PURGE" ]] || skip_env "lpcc_purge not found on $SINGLEAGT" - setup_loopdev $SINGLEAGT $loopfile $mntpt 14 + setup_loopdev $SINGLEAGT $loopfile $mntpt 120 do_facet $SINGLEAGT mkdir $hsm_root || error "mkdir $hsm_root failed" setup_pcc_mapping $SINGLEAGT \ "fname={*.dat}\ roid=$HSM_ARCHIVE_NUMBER\ pccro=1" @@ -4329,7 +4348,7 @@ test_200() { mkdir $DIR/$tdir for i in {1..100}; do file=$DIR/$tdir/$tfile.$i.dat - do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=100K count=1 status=none || + do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1M count=1 status=none || error "Write $file failed" done @@ -4390,7 +4409,7 @@ test_201() { LPCC_PURGE=${LPCC_PURGE:-$(do_facet $SINGLEAGT "which lpcc_purge")} [[ -n "$LPCC_PURGE" ]] || skip_env "lpcc_purge not found on $SINGLEAGT" - setup_loopdev $SINGLEAGT $loopfile $mntpt 14 + setup_loopdev $SINGLEAGT $loopfile $mntpt 120 do_facet $SINGLEAGT mkdir $hsm_root || error "mkdir $hsm_root failed" setup_pcc_mapping $SINGLEAGT \ "fname={*.dat}\ roid=$HSM_ARCHIVE_NUMBER\ pccro=1" @@ -4400,7 +4419,7 @@ test_201() { mkdir $DIR/$tdir for i in {1..100}; do file=$DIR/$tdir/$tfile.$i.dat - do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=100K count=1 status=none || + do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1M count=1 status=none || error "Write $file failed" done @@ -4462,7 +4481,7 @@ test_202() { LPCC_PURGE=${LPCC_PURGE:-$(do_facet $SINGLEAGT "which lpcc_purge")} [[ -n "$LPCC_PURGE" ]] || skip_env "lpcc_purge not found on $SINGLEAGT" - setup_loopdev $SINGLEAGT $loopfile $mntpt 14 + setup_loopdev $SINGLEAGT $loopfile $mntpt 120 do_facet $SINGLEAGT mkdir $hsm_root || error "mkdir $hsm_root failed" setup_pcc_mapping $SINGLEAGT \ "fname={*.dat}\ roid=$HSM_ARCHIVE_NUMBER\ pccro=1" @@ -4472,7 +4491,7 @@ test_202() { mkdir $DIR/$tdir for i in {1..100}; do file=$DIR/$tdir/$tfile.$i.dat - do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=100K count=1 status=none || + do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1M count=1 status=none || error "Write $file failed" done @@ -4523,7 +4542,7 @@ test_203() { local file=$DIR/$tfile local bs="1024" - setup_loopdev client $loopfile $mntpt 10 + setup_loopdev client $loopfile $mntpt 50 mkdir $hsm_root || error "mkdir $hsm_root failed" setup_pcc_mapping client \ "projid={0}\ roid=$HSM_ARCHIVE_NUMBER\ pccro=1" @@ -4563,7 +4582,7 @@ test_204a() { (( $MDS1_VERSION >= $(version_code 2.14.0.38) )) || skip "Need server version at least 2.14.0.38" - setup_loopdev $SINGLEAGT $loopfile $mntpt 14 + setup_loopdev $SINGLEAGT $loopfile $mntpt 50 do_facet $SINGLEAGT mkdir $hsm_root || error "mkdir $hsm_root failed" setup_pcc_mapping $SINGLEAGT \ "fname={*.dat}\ roid=$HSM_ARCHIVE_NUMBER\ pccro=1" @@ -4725,7 +4744,7 @@ test_204c() { (( $MDS1_VERSION >= $(version_code 2.14.0.38) )) || skip "Need server version at least 2.14.0.38" - setup_loopdev $SINGLEAGT $loopfile $mntpt 14 + setup_loopdev $SINGLEAGT $loopfile $mntpt 50 do_facet $SINGLEAGT mkdir $hsm_root || error "mkdir $hsm_root failed" setup_pcc_mapping $SINGLEAGT \ "fname={*.dat}\ roid=$HSM_ARCHIVE_NUMBER\ pccro=1" @@ -4772,7 +4791,7 @@ test_205() { LPCC_PURGE=${LPCC_PURGE:-$(do_facet $SINGLEAGT "which lpcc_purge")} [[ -n "$LPCC_PURGE" ]] || skip_env "lpcc_purge not found on $SINGLEAGT" - setup_loopdev $SINGLEAGT $loopfile $mntpt 14 + setup_loopdev $SINGLEAGT $loopfile $mntpt 120 do_facet $SINGLEAGT mkdir $hsm_root || error "mkdir $hsm_root failed" setup_pcc_mapping $SINGLEAGT \ "fname={*.dat}\ roid=$HSM_ARCHIVE_NUMBER\ pccro=1" @@ -4782,7 +4801,7 @@ test_205() { for i in {1..100}; do file=$DIR/$tdir/$tfile.$i.dat do_facet $SINGLEAGT \ - dd if=/dev/zero of=$file bs=100K count=1 status=none || + dd if=/dev/zero of=$file bs=1M count=1 status=none || error "Write $file failed" done diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 2980940..d1fa15e 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -12471,11 +12471,10 @@ static int lfs_pcc_detach_fid(int argc, char **argv) static int lfs_pcc_state(int argc, char **argv) { - int rc = 0; - const char *path; - char fullpath[PATH_MAX]; - struct lu_pcc_state state; - char buff[XATTR_SIZE_MAX]; + int rc = 0; + const char *path; + struct lu_pcc_state state; + char buff[XATTR_SIZE_MAX]; optind = 1; @@ -12489,15 +12488,7 @@ static int lfs_pcc_state(int argc, char **argv) int rc2; path = argv[optind++]; - if (!realpath(path, fullpath)) { - fprintf(stderr, "%s: could not find path '%s': %s\n", - argv[0], path, strerror(errno)); - if (rc == 0) - rc = -EINVAL; - continue; - } - - rc2 = llapi_pcc_state_get(fullpath, &state); + rc2 = llapi_pcc_state_get(path, &state); if (rc2 < 0) { if (rc == 0) rc = rc2; -- 1.8.3.1