Whamcloud - gitweb
b=18266
authornathan <nathan>
Tue, 17 Feb 2009 23:05:23 +0000 (23:05 +0000)
committernathan <nathan>
Tue, 17 Feb 2009 23:05:23 +0000 (23:05 +0000)
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
lustre/tests/test-framework.sh
lustre/utils/obd.c

index 9742fe1..61d799e 100644 (file)
@@ -6178,27 +6178,24 @@ check_file_in_pool()
 }
 
 test_200a() {
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        do_facet mgs $LCTL pool_new $FSNAME.$POOL
-       do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL
-       [ $? == 0 ] || error "Pool creation of $POOL failed"
+        # 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() {
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
-       TGT=$(seq -f $FSNAME-OST%04g_UUID $TGTPOOL_FIRST $TGTPOOL_STEP \
-               $TGTPOOL_MAX | tr '\n' ' ')
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && 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]_UUID
-       res=$(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL | sort \
-                       | tr '\n' ' ')
-       [ "$res" = "$TGT" ] || error "Pool content ($res) do not match requested ($TGT)"
+               $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() {
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        mkdir -p $POOL_DIR
        $SETSTRIPE -c 2 -p $POOL $POOL_DIR
        [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR"
@@ -6206,14 +6203,14 @@ test_200c() {
 run_test 200c "Set pool on a directory ================================="
 
 test_200d() {
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && 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() {
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        failed=0
        for i in $(seq -w 1 $(($TGT_COUNT * 3)))
        do
@@ -6230,7 +6227,7 @@ test_200e() {
 run_test 200e "Check files allocation from directory pool =============="
 
 test_200f() {
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        mkdir -p $POOL_FILE
        failed=0
        for i in $(seq -w 1 $(($TGT_COUNT * 3)))
@@ -6248,30 +6245,30 @@ test_200f() {
 run_test 200f "Create files in a pool ==================================="
 
 test_200g() {
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
-       TGT=$(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL | head -1)
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
+       TGT=$($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | head -1)
        do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
-       res=$(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL | grep $TGT)
-       [ "$res" = "" ] || error "$TGT not removed from $FSNAME.$POOL"
+       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() {
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
-       for TGT in $(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL)
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && 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
-       res=$(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL)
-       [ "$res" = "" ] || error "Pool $FSNAME.$POOL cannot be drained"
+       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() {
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        do_facet mgs $LCTL pool_destroy $FSNAME.$POOL
-       res=$(do_facet mgs "$LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL 2>/dev/null")
-       [ "$res" = "" ] || error "Pool $FSNAME.$POOL is not destroyed"
+       # 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 ============================================"
 
index 331fb5b..26e7f79 100644 (file)
@@ -768,16 +768,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
 }
 
@@ -2075,6 +2075,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" ]
+}
+
 mdts_nodes () {
     local MDSNODES
     local NODES_sort
index 8945f11..a60d2a1 100644 (file)
@@ -2532,15 +2532,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)
-                return -EINVAL;
-
-        if (glob_info.gl_pathc == 0) {
-                globfree(&glob_info);
+        if (rc == GLOB_NOMATCH)
+                return -ENODEV;
+        else if (rc)
                 return -EINVAL;
-        }
 
         strcpy(path, glob_info.gl_pathv[0]);
+        globfree(&glob_info);
         return 0;
 }
 
@@ -2554,15 +2552,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;
 }
 
@@ -2594,14 +2592,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);
@@ -2633,7 +2635,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, "
@@ -2654,7 +2656,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",
@@ -2668,7 +2670,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",
@@ -2694,6 +2696,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--;
@@ -2708,10 +2712,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",
@@ -2724,6 +2730,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--;
@@ -2739,6 +2747,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--;
@@ -2818,7 +2828,10 @@ static int pool_cmd(enum lcfg_command_type cmd,
         char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
 
         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);
@@ -2891,7 +2904,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;
@@ -2899,7 +2912,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;
@@ -3010,8 +3023,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;