From 95d7592a9f33f62accade96d81e0cc3ca0fb94e2 Mon Sep 17 00:00:00 2001 From: Jian Yu Date: Thu, 8 Dec 2016 22:39:37 -0800 Subject: [PATCH] =?utf8?q?LU-8152=20utils:=20improve=20=E2=80=9Clfs=20df?= =?utf8?q?=E2=80=9D=20to=20show=20device=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch improves “lfs df” to check OS_STATE_* flags, and show the device status as follows: D stands for OS_STATE_DEGRADED R stands for OS_STATE_READONLY S stands for OS_STATE_ENOSPC I stands for OS_STATE_ENOINO Signed-off-by: Jian Yu Change-Id: Ic7389d935f1258bc4217dfe36fcbf2b468b14f20 Reviewed-on: https://review.whamcloud.com/23330 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Bob Glossman --- lustre/tests/sanity.sh | 24 +++++++++++++++++++ lustre/tests/test-framework.sh | 12 ++++++++++ lustre/utils/lfs.c | 52 ++++++++++++++++++++++++++++-------------- 3 files changed, 71 insertions(+), 17 deletions(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index c7dde17..a091e22 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -4549,6 +4549,30 @@ test_56b() { } run_test 56b "check $LFS getdirstripe" +test_56c() { + local ost_idx=0 + local ost_name=$(ostname_from_index $ost_idx) + + local old_status=$(ost_dev_status $ost_idx) + [[ -z "$old_status" ]] || + { skip_env "OST $ost_name is in $old_status status"; return 0; } + + do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1 + sleep_maxage + + local new_status=$(ost_dev_status $ost_idx) + [[ "$new_status" = "D" ]] || + error "OST $ost_name is in status of '$new_status', not 'D'" + + do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0 + sleep_maxage + + new_status=$(ost_dev_status $ost_idx) + [[ -z "$new_status" ]] || + error "OST $ost_name is in status of '$new_status', not ''" +} +run_test 56c "check 'lfs df' showing device status" + NUMFILES=3 NUMDIRS=3 setup_56() { diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index bd2dd52..732587e 100755 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -1536,6 +1536,18 @@ mdt_free_inodes() { echo $free_inodes } +# +# Get the OST device status from 'lfs df' with a given OST index. +# +ost_dev_status() { + local ost_idx=$1 + local mnt_pnt=${2:-$MOUNT} + local ost_uuid + + ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt) + lfs_df $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }' +} + setup_quota(){ local mntpt=$1 diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 933f455..b6665a1 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -2385,24 +2385,42 @@ static int showdf(char *mntdir, struct obd_statfs *stat, snprintf(abuf, sizeof(tbuf), CDF, avail); } - sprintf(rbuf, RDF, (int)(ratio * 100 + 0.5)); - printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s", - uuid, tbuf, ubuf, abuf, rbuf, mntdir); - if (type) - printf("[%s:%d]\n", type, index); - else - printf("\n"); - - break; - case -ENODATA: - printf(UUF": inactive device\n", uuid); - break; - default: - printf(UUF": %s\n", uuid, strerror(-rc)); - break; - } + sprintf(rbuf, RDF, (int)(ratio * 100 + 0.5)); + printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s", + uuid, tbuf, ubuf, abuf, rbuf, mntdir); + if (type) + printf("[%s:%d]", type, index); + + if (stat->os_state) { + /* + * Each character represents the matching + * OS_STATE_* bit. + */ + const char state_names[] = "DRSI"; + __u32 state; + __u32 i; + + printf(" "); + for (i = 0, state = stat->os_state; + state && i < sizeof(state_names); i++) { + if (!(state & (1 << i))) + continue; + printf("%c", state_names[i]); + state ^= 1 << i; + } + } - return 0; + printf("\n"); + break; + case -ENODATA: + printf(UUF": inactive device\n", uuid); + break; + default: + printf(UUF": %s\n", uuid, strerror(-rc)); + break; + } + + return 0; } struct ll_stat_type { -- 1.8.3.1