Whamcloud - gitweb
LU-8152 utils: improve “lfs df” to show device status 30/23330/9
authorJian Yu <jian.yu@intel.com>
Fri, 9 Dec 2016 06:39:37 +0000 (22:39 -0800)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 6 Apr 2017 01:00:06 +0000 (01:00 +0000)
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 <jian.yu@intel.com>
Change-Id: Ic7389d935f1258bc4217dfe36fcbf2b468b14f20
Reviewed-on: https://review.whamcloud.com/23330
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
lustre/tests/sanity.sh
lustre/tests/test-framework.sh
lustre/utils/lfs.c

index c7dde17..a091e22 100755 (executable)
@@ -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() {
index bd2dd52..732587e 100755 (executable)
@@ -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
 
index 933f455..b6665a1 100644 (file)
@@ -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 {