Whamcloud - gitweb
b=19889
authornathan <nathan>
Wed, 8 Jul 2009 17:04:53 +0000 (17:04 +0000)
committernathan <nathan>
Wed, 8 Jul 2009 17:04:53 +0000 (17:04 +0000)
i=rread
i=manoj
return error codes from pool (and other) commands

lustre/tests/test-framework.sh
lustre/utils/lctl.c
lustre/utils/lfs.c
lustre/utils/loadgen.c
lustre/utils/obd.c

index c9435e7..1cc28d4 100644 (file)
@@ -666,7 +666,7 @@ sanity_mount_check_nodes () {
 
     local rc=0
     for mnt in $mnts ; do
-        do_nodes $nodes "set -x; running=\\\$(grep -c $mnt' ' /proc/mounts);
+        do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
 mpts=\\\$(mount | grep -w -c $mnt);
 if [ \\\$running -ne \\\$mpts ]; then
     echo \\\$(hostname) env are INSANE!;
@@ -731,7 +731,7 @@ zconf_mount_clients() {
 
     echo "Starting client $clients: $OPTIONS $device $mnt"
 
-    do_nodes $clients "set -x;
+    do_nodes $clients "
 running=\\\$(mount | grep -c $mnt' ');
 rc=0;
 if [ \\\$running -eq 0 ] ; then
@@ -759,7 +759,7 @@ zconf_umount_clients() {
     [ "$3" ] && force=-f
 
     echo "Stopping clients: $clients $mnt (opts:$force)"
-    do_nodes $clients "set -x; running=\\\$(grep -c $mnt' ' /proc/mounts);
+    do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
 if [ \\\$running -ne 0 ] ; then
 echo Stopping client \\\$(hostname) client $mnt opts:$force;
 lsof -t $mnt || need_kill=no;
@@ -834,7 +834,7 @@ check_progs_installed () {
     shift
     local progs=$@
 
-    do_nodes $clients "set -x ; PATH=:$PATH; status=true;
+    do_nodes $clients "PATH=:$PATH; status=true;
 for prog in $progs; do
     if ! [ \\\"\\\$(which \\\$prog)\\\"  -o  \\\"\\\${!prog}\\\" ]; then
        echo \\\$prog missing on \\\$(hostname);
index aae7494..0a586a4 100644 (file)
@@ -372,7 +372,7 @@ int lctl_main(int argc, char **argv)
         }
 
         obd_finalize(argc, argv);
-        return rc;
+        return rc < 0 ? -rc : rc;
 }
 
 #ifndef LIBLUSTRE_TEST
index 044671a..69433cd 100644 (file)
@@ -2614,6 +2614,6 @@ int main(int argc, char **argv)
         }
 
         obd_finalize(argc, argv);
-        return rc;
+        return rc < 0 ? -rc : rc;
 }
 
index 0df9ae3..9670ad6 100644 (file)
@@ -78,7 +78,7 @@ static int jt_quit(int argc, char **argv) {
 static int loadgen_usage(int argc, char **argv)
 {
         if (argc == 1) {
-                fprintf(stderr, 
+                fprintf(stderr,
         "This is a test program used to simulate large numbers of\n"
         "clients.  The echo obds are used, so the obdecho module must\n"
         "be loaded.\n"
@@ -868,7 +868,7 @@ static int loadgen_write(int argc, char **argv)
                         threads, live_threads);
                 return -EOVERFLOW;
         }
-        trigger(C_WRITE, threads, atoi(argv[2]), 
+        trigger(C_WRITE, threads, atoi(argv[2]),
                 (argc == 4) ? atoi(argv[3]) : 0);
         return 0;
 }
@@ -917,7 +917,7 @@ static int loadgen_start_echosrv(int argc, char **argv)
                         cmdname, rc);
                 goto clean;
         }
-  
+
         /* Create an OSS to handle the communications */
         /* attach ost OSS OSS_UUID */
         args[1] = "ost";
@@ -956,7 +956,7 @@ clean:
 
 static int loadgen_wait(int argc, char **argv)
 {
-        /* Give scripts a chance to start some threads */   
+        /* Give scripts a chance to start some threads */
         sleep(1);
         while (!all_done) {
                 sleep(1);
@@ -996,7 +996,7 @@ static int loadgen_init(int argc, char **argv)
 static int loadgen_exit()
 {
         int rc;
-        
+
         printf("stopping %d children\n", live_threads);
         kill_kids();
         rc = wait_for_threads();
@@ -1038,7 +1038,7 @@ static int loadgen_main(int argc, char **argv)
 
 out:
         obd_finalize(argc, argv);
-        return rc;
+        return rc < 0 ? -rc : rc;
 }
 
 #ifndef LIBLUSTRE_TEST
index 8d1b671..9fe5d4b 100644 (file)
@@ -2567,7 +2567,7 @@ static int find_poolpath(char *fsname, char *poolname, char *poolpath)
 /*
  * if pool is NULL, search ostname in target_obd
  * if pool is no NULL
- *  if pool not found returns < 0
+ *  if pool not found returns errno < 0
  *  if ostname is NULL, returns 1 if pool is not empty and 0 if pool empty
  *  if ostname is not NULL, returns 1 if OST is in pool and 0 if not
  */
@@ -2619,11 +2619,19 @@ static int check_pool_cmd(enum lcfg_command_type cmd,
                           char *fsname, char *poolname,
                           char *ostname)
 {
-        int rc = 0;
+        int rc;
+
+        rc = search_ost(fsname, poolname, ostname);
+        if (rc < 0 && (cmd != LCFG_POOL_NEW)) {
+                fprintf(stderr, "Pool %s.%s not found\n",
+                        fsname, poolname);
+                return rc;
+        }
 
         switch (cmd) {
         case LCFG_POOL_NEW: {
-                if (search_ost(fsname, poolname, NULL) >= 0) {
+                LASSERT(ostname == NULL);
+                if (rc >= 0) {
                         fprintf(stderr, "Pool %s.%s already exists\n",
                                 fsname, poolname);
                         return -EEXIST;
@@ -2631,12 +2639,7 @@ static int check_pool_cmd(enum lcfg_command_type cmd,
                 return 0;
         }
         case LCFG_POOL_DEL: {
-                rc = search_ost(fsname, poolname, NULL);
-                if (rc < 0) {
-                        fprintf(stderr, "Pool %s.%s not found\n",
-                                fsname, poolname);
-                        return rc;
-                }
+                LASSERT(ostname == NULL);
                 if (rc == 1) {
                         fprintf(stderr, "Pool %s.%s not empty, "
                                 "please remove all members\n",
@@ -2646,32 +2649,20 @@ static int check_pool_cmd(enum lcfg_command_type cmd,
                 return 0;
         }
         case LCFG_POOL_ADD: {
+                if (rc == 1) {
+                        fprintf(stderr, "OST %s is already in pool %s.%s\n",
+                                ostname, fsname, poolname);
+                        return -EEXIST;
+                }
                 rc = search_ost(fsname, NULL, ostname);
                 if (rc == 0) {
-                        fprintf(stderr, "OST %s not found in lov of %s\n",
+                        fprintf(stderr, "OST %s is not part of the '%s' fs.\n",
                                 ostname, fsname);
                         return -ENOENT;
                 }
-                rc = search_ost(fsname, poolname, ostname);
-                if (rc < 0) {
-                        fprintf(stderr, "Pool %s.%s not found\n",
-                                fsname, poolname);
-                        return rc;
-                }
-                if (rc == 1) {
-                        fprintf(stderr, "OST %s already in pool %s.%s\n",
-                                ostname, fsname, poolname);
-                        return -EEXIST;
-                }
                 return 0;
         }
         case LCFG_POOL_REM: {
-                rc = search_ost(fsname, poolname, ostname);
-                if (rc < 0) {
-                        fprintf(stderr, "Pool %s.%s not found\n",
-                                fsname, poolname);
-                        return rc;
-                }
                 if (rc == 0) {
                         fprintf(stderr, "OST %s not found in pool %s.%s\n",
                                 ostname, fsname, poolname);
@@ -2679,91 +2670,105 @@ static int check_pool_cmd(enum lcfg_command_type cmd,
                 }
                 return 0;
         }
-        default: {
-        }
-        }
-        return 0;
+        default:
+                break;
+        } /* switch */
+        return -EINVAL;
 }
 
-static void check_pool_cmd_result(enum lcfg_command_type cmd,
-                                  char *fsname, char *poolname,
-                                  char *ostname)
+/* This check only verifies that the changes have been "pushed out" to
+   the client successfully.  This involves waiting for a config update,
+   and so may fail because of problems in that code or post-command
+   network loss. So reporting a warning is appropriate, but not a failure.
+*/
+static int check_pool_cmd_result(enum lcfg_command_type cmd,
+                                 char *fsname, char *poolname,
+                                 char *ostname)
 {
-        int cpt, rc = 0;
+        int cpt = 10;
+        int rc = 0;
 
-        cpt = 10;
         switch (cmd) {
         case LCFG_POOL_NEW: {
                 do {
                         rc = search_ost(fsname, poolname, NULL);
                         if (rc == -ENODEV)
-                                return;
+                                return rc;
                         if (rc < 0)
                                 sleep(2);
                         cpt--;
                 } while ((rc < 0) && (cpt > 0));
-                if (rc >= 0)
+                if (rc >= 0) {
                         fprintf(stderr, "Pool %s.%s created\n",
                                 fsname, poolname);
-                else
+                        return 0;
+                } else {
                         fprintf(stderr, "Warning, pool %s.%s not found\n",
                                 fsname, poolname);
-                return;
+                        return -ENOENT;
+                }
         }
         case LCFG_POOL_DEL: {
                 do {
                         rc = search_ost(fsname, poolname, NULL);
                         if (rc == -ENODEV)
-                                return;
+                                return rc;
                         if (rc >= 0)
                                 sleep(2);
                         cpt--;
                 } while ((rc >= 0) && (cpt > 0));
-                if (rc < 0)
+                if (rc < 0) {
                         fprintf(stderr, "Pool %s.%s destroyed\n",
                                 fsname, poolname);
-                else
+                        return 0;
+                } else {
                         fprintf(stderr, "Warning, pool %s.%s still found\n",
                                 fsname, poolname);
-                return;
+                        return -EEXIST;
+                }
         }
         case LCFG_POOL_ADD: {
                 do {
                         rc = search_ost(fsname, poolname, ostname);
                         if (rc == -ENODEV)
-                                return;
+                                return rc;
                         if (rc != 1)
                                 sleep(2);
                         cpt--;
                 } while ((rc != 1) && (cpt > 0));
-                if (rc == 1)
+                if (rc == 1) {
                         fprintf(stderr, "OST %s added to pool %s.%s\n",
                                 ostname, fsname, poolname);
-                else
+                        return 0;
+                } else {
                         fprintf(stderr, "Warning, OST %s not found in pool %s.%s\n",
                                 ostname, fsname, poolname);
-                return;
+                        return -ENOENT;
+                }
         }
         case LCFG_POOL_REM: {
                 do {
                         rc = search_ost(fsname, poolname, ostname);
                         if (rc == -ENODEV)
-                                return;
+                                return rc;
                         if (rc == 1)
                                 sleep(2);
                         cpt--;
                 } while ((rc == 1) && (cpt > 0));
-                if (rc != 1)
+                if (rc != 1) {
                         fprintf(stderr, "OST %s removed from pool %s.%s\n",
                                 ostname, fsname, poolname);
-                else
+                        return 0;
+                } else {
                         fprintf(stderr, "Warning, OST %s still found in pool %s.%s\n",
                                 ostname, fsname, poolname);
-                return;
-        }
-        default: {
+                        return -EEXIST;
+                }
         }
+        default:
+                break;
         }
+        return -EINVAL;
 }
 
 static int check_and_complete_ostname(char *fsname, char *ostname)
@@ -3087,6 +3092,9 @@ int jt_pool_cmd(int argc, char **argv)
                                 cmds[j].rc = pool_cmd(cmd, argv[0], argv[1],
                                                       fsname, poolname,
                                                       ostname);
+                                /* Return an err if any of the add/dels fail */
+                                if (!rc)
+                                        rc = cmds[j].rc;
                         }
                         for (j = 0; j < array_sz; j++) {
                                 if (!cmds[j].rc) {
@@ -3113,14 +3121,11 @@ int jt_pool_cmd(int argc, char **argv)
                         if (ostnames_buf);
                                 free(ostnames_buf);
                 }
-                return 0;
-        }
+                /* fall through */
         }
-
+        } /* switch */
 
 out:
-        if ((rc == -EINVAL) || (rc == -ENOENT))
-                fprintf(stderr, "Does the fs, pool or ost exist?\n");
         if (rc != 0) {
                 errno = -rc;
                 perror(argv[0]);