From: nathan Date: Wed, 8 Jul 2009 19:51:03 +0000 (+0000) Subject: b=19889 X-Git-Tag: v1_8_2_01~1^2~261 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=2e287834b492d8e108aaf7d4ea1069da05a04fa4;p=fs%2Flustre-release.git b=19889 i=rread i=manoj return error codes from pool_cmd (and others) --- diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index c589231..c5d35fe 100644 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -523,7 +523,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!; @@ -587,7 +587,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 @@ -615,7 +615,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; @@ -690,7 +690,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); diff --git a/lustre/utils/lctl.c b/lustre/utils/lctl.c index 84c0c11..81e2cff 100644 --- a/lustre/utils/lctl.c +++ b/lustre/utils/lctl.c @@ -367,7 +367,7 @@ int lctl_main(int argc, char **argv) } obd_finalize(argc, argv); - return rc; + return rc < 0 ? -rc : rc; } #ifndef LIBLUSTRE_TEST diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 061c9c5..10518bd 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -2215,5 +2215,5 @@ int main(int argc, char **argv) } obd_finalize(argc, argv); - return rc; + return rc < 0 ? -rc : rc; } diff --git a/lustre/utils/loadgen.c b/lustre/utils/loadgen.c index 92f63b5..d278bbc 100644 --- a/lustre/utils/loadgen.c +++ b/lustre/utils/loadgen.c @@ -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" @@ -867,7 +867,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; } @@ -916,7 +916,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"; @@ -955,7 +955,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); @@ -995,7 +995,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(); @@ -1037,7 +1037,7 @@ static int loadgen_main(int argc, char **argv) out: obd_finalize(argc, argv); - return rc; + return rc < 0 ? -rc : rc; } #ifndef LIBLUSTRE_TEST diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index 1f2a5af..5b8f7ca 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -2577,7 +2577,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 */ @@ -2629,11 +2629,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; @@ -2641,12 +2649,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", @@ -2656,32 +2659,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); @@ -2689,91 +2680,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) @@ -3097,6 +3102,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) { @@ -3123,14 +3131,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]); diff --git a/lustre/utils/parser.c b/lustre/utils/parser.c index ec53f12..a750d4c 100644 --- a/lustre/utils/parser.c +++ b/lustre/utils/parser.c @@ -118,6 +118,11 @@ void Parser_ignore_errors(int ignore) ignore_errors = ignore; } +/* Returns: + 0 on success + >0 CMD_* values + <0 errnos +*/ int Parser_execarg(int argc, char **argv, command_t cmds[]) { command_t *cmd; @@ -129,12 +134,12 @@ int Parser_execarg(int argc, char **argv, command_t cmds[]) fprintf(stderr, "%s\n", cmd->pc_help); return rc; } else { - printf("Try interactive use without arguments or use one of:\n"); + printf("Try interactive use without arguments or use one of:\n"); for (cmd = cmds; cmd->pc_name; cmd++) printf("\"%s\"\n", cmd->pc_name); printf("as argument.\n"); } - return -1; + return -EINVAL; } /* returns the command_t * (NULL if not found) corresponding to a @@ -254,9 +259,9 @@ static char **command_completion(char * text, int start, int end) char * pos; match_tbl = top_level; - + for (table = find_cmd(rl_line_buffer, match_tbl, &pos); - table; table = find_cmd(pos, match_tbl, &pos)) + table; table = find_cmd(pos, match_tbl, &pos)) { if (*(pos - 1) == ' ') match_tbl = table->pc_sub_cmd;