From ec51688f7b8dfb3223c9a6be57e5da999964f95a Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 18 Feb 2009 00:04:39 +0000 Subject: [PATCH] b=18266 allow pool_cmd to work on MGS with no MDT or client b=18516 fix parsing to correctly handle hex OST numbers i=jc.lafoucriere i=johann --- lustre/tests/sanity.sh | 94 ++++++++++++++++++------------------------ lustre/tests/test-framework.sh | 17 +++++--- lustre/utils/obd.c | 66 +++++++++++++++++------------ 3 files changed, 91 insertions(+), 86 deletions(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 1c9edcb..a140cf5 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -5710,6 +5710,14 @@ POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools} POOL_DIR=$POOL_ROOT/dir_tst POOL_FILE=$POOL_ROOT/file_tst +skip_pools() +{ + [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep pools)" ] && + skip "missing pools support on server" && return 1 + remote_mgs_nodsh && skip "remote MGS with nodsh" && return 1 + return 0 +} + check_file_in_pool() { file=$1 @@ -5731,52 +5739,39 @@ check_file_in_pool() mdtlov=$(get_mdtlov_proc_path $FSNAME) test_200a() { - [ -z "$(lctl get_param -n mdc.*.connect_flags | grep pools)" ] && - skip "missing pools support on server" && return - remote_mds_nodsh && skip "remote MDS with nodsh" && return - do_facet mgs $LCTL pool_new $FSNAME.$POOL - do_facet mgs $LCTL get_param -n lov.$mdtlov.pools.$POOL - [ $? == 0 ] || error "Pool creation of $POOL failed" + skip_pools || return + do_facet mgs $LCTL pool_new $FSNAME.$POOL + # get param should return err until pool is created + wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null || echo foo" "" || error "Pool creation of $POOL failed" } run_test 200a "Create new pool ==========================================" test_200b() { - [ -z "$(lctl get_param -n mdc.*.connect_flags | grep pools)" ] && - skip "missing pools support on server" && return - remote_mds_nodsh && skip "remote MDS with nodsh" && return - TGT=$(seq -f $FSNAME-OST%04g_UUID $TGTPOOL_FIRST $TGTPOOL_STEP \ - $TGTPOOL_MAX | tr '\n' ' ') - do_facet mgs $LCTL pool_add $FSNAME.$POOL \ - $FSNAME-OST[$TGTPOOL_FIRST-$TGTPOOL_MAX/$TGTPOOL_STEP]_UUID - res=$(do_facet mgs $LCTL get_param -n lov.$mdtlov.pools.$POOL | - sort | tr '\n' ' ') - [ "$res" = "$TGT" ] || error "Pool ($res) do not match requested ($TGT)" + skip_pools || return + TGT=$(for i in `seq $TGTPOOL_FIRST $TGTPOOL_STEP $TGTPOOL_MAX`; do printf "$FSNAME-OST%04x_UUID " $i; done) + do_facet mgs $LCTL pool_add $FSNAME.$POOL \ + $FSNAME-OST[$TGTPOOL_FIRST-$TGTPOOL_MAX/$TGTPOOL_STEP] + wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | sort -u | tr '\n' ' ' " "$TGT" || error "Add to pool failed" } run_test 200b "Add targets to a pool ====================================" test_200c() { - [ -z "$(lctl get_param -n mdc.*.connect_flags | grep pools)" ] && - skip "missing pools support on server" && return - remote_mds_nodsh && skip "remote MDS with nodsh" && return - mkdir -p $POOL_DIR - $SETSTRIPE -c 2 -p $POOL $POOL_DIR - [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR" + skip_pools || return + mkdir -p $POOL_DIR + $SETSTRIPE -c 2 -p $POOL $POOL_DIR + [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR" } run_test 200c "Set pool on a directory =================================" test_200d() { - [ -z "$(lctl get_param -n mdc.*.connect_flags | grep pools)" ] && - skip "missing pools support on server" && return - remote_mds_nodsh && skip "remote MDS with nodsh" && return + skip_pools || return res=$($GETSTRIPE $POOL_DIR | grep pool: | cut -f8 -d " ") [ "$res" = $POOL ] || error "Pool on $POOL_DIR is not $POOL" } run_test 200d "Check pool on a directory ===============================" test_200e() { - [ -z "$(lctl get_param -n mdc.*.connect_flags | grep pools)" ] && - skip "missing pools support on server" && return - remote_mds_nodsh && skip "remote MDS with nodsh" && return + skip_pools || return failed=0 for i in $(seq -w 1 $(($TGT_COUNT * 3))); do file=$POOL_DIR/file-$i @@ -5791,9 +5786,7 @@ test_200e() { run_test 200e "Check files allocation from directory pool ==============" test_200f() { - [ -z "$(lctl get_param -n mdc.*.connect_flags | grep pools)" ] && - skip "missing pools support on server" && return - remote_mds_nodsh && skip "remote MDS with nodsh" && return + skip_pools || return mkdir -p $POOL_FILE failed=0 for i in $(seq -w 1 $(($TGT_COUNT * 3))); do @@ -5809,37 +5802,30 @@ test_200f() { run_test 200f "Create files in a pool ===================================" test_200g() { - [ -z "$(lctl get_param -n mdc.*.connect_flags | grep pools)" ] && - skip "missing pools support on server" && return - remote_mds_nodsh && skip "remote MDS with nodsh" && return - TGT=$(do_facet mgs $LCTL get_param -n lov.$mdtlov.pools.$POOL | - head -1) - do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT - res=$(do_facet mgs $LCTL get_param -n lov.$mdtlov.pools.$POOL | - grep $TGT) - [ "$res" = "" ] || error "$TGT not removed from $FSNAME.$POOL" + skip_pools || return + TGT=$($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | head -1) + do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT + wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | grep $TGT" "" || error "$TGT not removed from $FSNAME.$POOL" } run_test 200g "Remove a target from a pool =============================" test_200h() { - [ -z "$(lctl get_param -n mdc.*.connect_flags | grep pools)" ] && - skip "missing pools support on server" && return - remote_mds_nodsh && skip "remote MDS with nodsh" && return - for TGT in $(do_facet mgs $LCTL get_param -n lov.$mdtlov.pools.$POOL); do - do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT - done - res=$(do_facet mgs $LCTL get_param -n lov.$mdtlov.pools.$POOL) - [ "$res" = "" ] || error "Pool $FSNAME.$POOL cannot be drained" + skip_pools || return + for TGT in $($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | sort -u) + do + do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT + done + wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL" ""\ + || error "Pool $FSNAME.$POOL cannot be drained" } run_test 200h "Remove all targets from a pool ==========================" test_200i() { - [ -z "$(lctl get_param -n mdc.*.connect_flags | grep pools)" ] && - skip "missing pools support on server" && return - remote_mds_nodsh && skip "remote MDS with nodsh" && return - do_facet mgs $LCTL pool_destroy $FSNAME.$POOL - res=$(do_facet mgs "$LCTL get_param -n lov.$mdtlov.pools.$POOL 2>/dev/null") - [ "$res" = "" ] || error "Pool $FSNAME.$POOL is not destroyed" + skip_pools || return + do_facet mgs $LCTL pool_destroy $FSNAME.$POOL + # get param should return err once pool is gone + wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null || echo foo" "foo" && return 0 + error "Pool $FSNAME.$POOL is not destroyed" } run_test 200i "Remove a pool ============================================" diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index 0792d8f..4cb7d92 100644 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -605,16 +605,16 @@ wait_update () { local WAIT=0 local sleep=5 while [ $WAIT -lt $MAX ]; do - sleep $sleep RESULT=$(do_node $node "$TEST") - if [ $RESULT -eq $FINAL ]; then - echo "Updated after $WAIT sec: wanted $FINAL got $RESULT" + if [ "$RESULT" == "$FINAL" ]; then + echo "Updated after $WAIT sec: wanted '$FINAL' got '$RESULT'" return 0 fi - WAIT=$((WAIT + sleep)) echo "Waiting $((MAX - WAIT)) secs for update" + WAIT=$((WAIT + sleep)) + sleep $sleep done - echo "Update not seen after $MAX sec: wanted $FINAL got $RESULT" + echo "Update not seen after $MAX sec: wanted '$FINAL' got '$RESULT'" return 3 } @@ -1809,6 +1809,13 @@ remote_ost_nodsh() remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ] } +remote_mgs_nodsh() +{ + local MGS + MGS=$(facet_host mgs) + remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ] +} + remote_servers () { remote_ost && remote_mds } diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index a41bc04..4977f6f 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -183,7 +183,7 @@ static int get_mgs_device() do_disconnect(NULL, 1); rc = do_device("mgsioc", mgs); if (rc) { - fprintf(stderr, + fprintf(stderr, "This command must be run on the MGS.\n"); errno = ENODEV; return -1; @@ -2363,15 +2363,13 @@ static int find_target_obdpath(char *fsname, char *path) "/proc/fs/lustre/lov/%s-*/target_obd", fsname); rc = glob(pattern, GLOB_BRACE, NULL, &glob_info); - if (rc) + if (rc == GLOB_NOMATCH) + return -ENODEV; + else if (rc) return -EINVAL; - if (glob_info.gl_pathc == 0) { - globfree(&glob_info); - return -EINVAL; - } - strcpy(path, glob_info.gl_pathv[0]); + globfree(&glob_info); return 0; } @@ -2385,15 +2383,15 @@ static int find_poolpath(char *fsname, char *poolname, char *poolpath) "/proc/fs/lustre/lov/%s-*/pools/%s", fsname, poolname); rc = glob(pattern, GLOB_BRACE, NULL, &glob_info); + /* If no pools, make sure the lov is available */ + if ((rc == GLOB_NOMATCH) && + (find_target_obdpath(fsname, poolpath) == -ENODEV)) + return -ENODEV; if (rc) return -EINVAL; - if (glob_info.gl_pathc == 0) { - globfree(&glob_info); - return -EINVAL; - } - strcpy(poolpath, glob_info.gl_pathv[0]); + globfree(&glob_info); return 0; } @@ -2425,14 +2423,18 @@ static int search_ost(char *fsname, char *poolname, char *ostname) while (fgets(buffer, sizeof(buffer), fd) != NULL) { if (poolname == NULL) { - /* we search ostname in target_obd */ - if (strncmp(buffer + 3, ostname, len) == 0) { + char *ptr; + /* Search for an ostname in the list of OSTs + Line format is IDX: fsname-OSTxxxx_UUID STATUS */ + ptr = strchr(buffer, ' '); + if ((ptr != NULL) && + (strncmp(ptr + 1, ostname, len) == 0)) { fclose(fd); return 1; } } else { - /* we search a non empty pool or - an ostname in a pool */ + /* Search for an ostname in a pool, + (or an existing non-empty pool if no ostname) */ if ((ostname == NULL) || (strncmp(buffer, ostname, len) == 0)) { fclose(fd); @@ -2464,7 +2466,7 @@ static int check_pool_cmd(enum lcfg_command_type cmd, if (rc < 0) { fprintf(stderr, "Pool %s.%s not found\n", fsname, poolname); - return -ENOENT; + return rc; } if (rc == 1) { fprintf(stderr, "Pool %s.%s not empty, " @@ -2485,7 +2487,7 @@ static int check_pool_cmd(enum lcfg_command_type cmd, if (rc < 0) { fprintf(stderr, "Pool %s.%s not found\n", fsname, poolname); - return -ENOENT; + return rc; } if (rc == 1) { fprintf(stderr, "OST %s already in pool %s.%s\n", @@ -2499,7 +2501,7 @@ static int check_pool_cmd(enum lcfg_command_type cmd, if (rc < 0) { fprintf(stderr, "Pool %s.%s not found\n", fsname, poolname); - return -ENOENT; + return rc; } if (rc == 0) { fprintf(stderr, "OST %s not found in pool %s.%s\n", @@ -2525,6 +2527,8 @@ static void check_pool_cmd_result(enum lcfg_command_type cmd, case LCFG_POOL_NEW: { do { rc = search_ost(fsname, poolname, NULL); + if (rc == -ENODEV) + return; if (rc < 0) sleep(2); cpt--; @@ -2539,10 +2543,12 @@ static void check_pool_cmd_result(enum lcfg_command_type cmd, } case LCFG_POOL_DEL: { do { - rc = search_ost(fsname, poolname, NULL); - if (rc >= 0) + rc = search_ost(fsname, poolname, NULL); + if (rc == -ENODEV) + return; + if (rc >= 0) sleep(2); - cpt--; + cpt--; } while ((rc >= 0) && (cpt > 0)); if (rc < 0) fprintf(stderr, "Pool %s.%s destroyed\n", @@ -2555,6 +2561,8 @@ static void check_pool_cmd_result(enum lcfg_command_type cmd, case LCFG_POOL_ADD: { do { rc = search_ost(fsname, poolname, ostname); + if (rc == -ENODEV) + return; if (rc != 1) sleep(2); cpt--; @@ -2570,6 +2578,8 @@ static void check_pool_cmd_result(enum lcfg_command_type cmd, case LCFG_POOL_REM: { do { rc = search_ost(fsname, poolname, ostname); + if (rc == -ENODEV) + return; if (rc == 1) sleep(2); cpt--; @@ -2648,7 +2658,10 @@ static int pool_cmd(enum lcfg_command_type cmd, struct lustre_cfg *lcfg; rc = check_pool_cmd(cmd, fsname, poolname, ostname); - if (rc) + if (rc == -ENODEV) + fprintf(stderr, "Can't verify pool command since there " + "is no local MDT or client, proceeding anyhow...\n"); + else if (rc) return rc; lustre_cfg_bufs_reset(&bufs, NULL); @@ -2715,7 +2728,7 @@ static int get_array_idx(char *rule, char *format, int **array) end++; start++; /* put in format the printf format (the rule without the range) */ - sprintf(format, "%s%%.4d%s", rule, end); + sprintf(format, "%s%%.4x%s", rule, end); array_idx = 0; array_sz = 0; @@ -2723,7 +2736,7 @@ static int get_array_idx(char *rule, char *format, int **array) /* loop on , separator */ do { /* extract the 3 fields */ - rc = sscanf(start, "%u-%u/%u", &lo, &hi, &step); + rc = sscanf(start, "%x-%x/%u", &lo, &hi, &step); switch (rc) { case 0: { return 0; @@ -2834,8 +2847,7 @@ int jt_pool_cmd(int argc, char **argv) if (rc) break; - rc = pool_cmd(cmd, argv[0], argv[1], - fsname, poolname, NULL); + rc = pool_cmd(cmd, argv[0], argv[1], fsname, poolname, NULL); if (rc) break; -- 1.8.3.1