From e01057b7ef072a432bf7d6481fe45bc545d80e90 Mon Sep 17 00:00:00 2001 From: Alexandre Ioffe Date: Thu, 28 Oct 2021 13:27:38 -0700 Subject: [PATCH] EX-4075 lipe: Modify log messages, use xstrdup() Preserve errno across log message output Modify log messages for style reason and corresponded message in test script Removed trailing blanks Replace strdup() by xstrdup() Add double quotes in test script to prevent script's "ambiguous redirection" error Test-Parameters: trivial testlist=hot-pools Signed-off-by: Alexandre Ioffe Change-Id: Ie12fe9bbca60fe28ef260d820b55a8195492618f Reviewed-on: https://review.whamcloud.com/45366 Tested-by: jenkins Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-on: https://review.whamcloud.com/46126 --- lipe/src/lamigo.c | 24 ++++++++++++------------ lipe/src/lamigo_alr.c | 3 +-- lipe/src/lipe_ssh.c | 4 +--- lipe/src/lpurge.c | 12 ++++++------ lipe/src/lx_log.h | 3 +++ lustre/tests/hot-pools.sh | 3 +-- lustre/tests/yaml.sh | 2 +- 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/lipe/src/lamigo.c b/lipe/src/lamigo.c index a6452d1..4eb318f 100644 --- a/lipe/src/lamigo.c +++ b/lipe/src/lamigo.c @@ -1697,8 +1697,8 @@ static void lamigo_add_agent(const char *host, const char *mnt, char *jobs) a = xcalloc(1, sizeof(*a)); a->rag_index = lamigo_agent_count; - a->rag_hostname = strdup(host); - a->rag_mountpoint = strdup(mnt); + a->rag_hostname = xstrdup(host); + a->rag_mountpoint = xstrdup(mnt); if (jobs) { char *endptr; @@ -2021,7 +2021,7 @@ static void lamigo_process_opt(int c, char *optarg) LX_FATAL("invalid hot-after-idle '%s'\n", optarg); break; case LAMIGO_OPT_MIRROR_CMD: - opt.o_mirror_cmd = strdup(optarg); + opt.o_mirror_cmd = xstrdup(optarg); break; case LAMIGO_OPT_POOL_REFRESH: opt.o_pool_refresh = strtol(optarg, &endptr, 10); @@ -2129,7 +2129,7 @@ static void lamigo_process_opt(int c, char *optarg) opt.o_mdtname = xstrdup(optarg); break; case 'M': - opt.o_mntpt = strdup(optarg); + opt.o_mntpt = xstrdup(optarg); break; case 'n': opt.o_num_threads = strtoul(optarg, NULL, 0); @@ -2155,16 +2155,16 @@ static void lamigo_process_opt(int c, char *optarg) opt.o_slow_pool = strdup(optarg); break; case 'u': - opt.o_changelog_user = strdup(optarg); + opt.o_changelog_user = xstrdup(optarg); break; case 'v': lx_log_level++; break; case 'w': - opt.o_dump_file = strdup(optarg); + opt.o_dump_file = xstrdup(optarg); break; case 'W': - opt.o_heat_file = strdup(optarg); + opt.o_heat_file = xstrdup(optarg); break; default: rc = -EINVAL; @@ -2283,7 +2283,7 @@ static void load_config(char *name) opt = lamigo_keyword_lookup(t); if (!opt) { - LX_ERROR("unknown tunable: %s\n", t); + LX_ERROR("unknown tunable: '%s'\n", t); continue; } @@ -2373,12 +2373,12 @@ static void lamigo_parse_opts(int argc, char **argv) if (!opt.o_dump_file) { snprintf(buf, sizeof(buf), LAMIGO_DUMPFILE, opt.o_mdtname); - opt.o_dump_file = strdup(buf); + opt.o_dump_file = xstrdup(buf); } if (!opt.o_heat_file) { snprintf(buf, sizeof(buf), LAMIGO_HEAT_FILE, opt.o_mdtname); - opt.o_heat_file = strdup(buf); + opt.o_heat_file = xstrdup(buf); } opt.o_cached_fid_hiwm = opt.o_cache_size / sizeof(struct fid_rec); @@ -2528,7 +2528,7 @@ static int lamigo_find_device(const char *devname) continue; if (!S_ISREG(st.st_mode)) continue; - mdtprefix = strdup(paths.gl_pathv[i]); + mdtprefix = xstrdup(paths.gl_pathv[i]); break; } @@ -3528,7 +3528,7 @@ static void *lamigo_refresh_statfs_thread(void *arg) if (rc != 0) LX_FATAL("cannot find OSP root: %s\n", strerror(errno)); - osproot = strdup(paths.gl_pathv[0]); + osproot = xstrdup(paths.gl_pathv[0]); globfree(&paths); while (1) { diff --git a/lipe/src/lamigo_alr.c b/lipe/src/lamigo_alr.c index 4ce1dae..e5cab6f 100644 --- a/lipe/src/lamigo_alr.c +++ b/lipe/src/lamigo_alr.c @@ -887,8 +887,7 @@ void lamigo_add_alr_agent(const char *host) int rc; ala = xcalloc(1, sizeof(*ala)); - ala->ala_host = strdup(host); - assert(ala->ala_host != NULL); + ala->ala_host = xstrdup(host); rc = lipe_ssh_context_init(&ala->ala_ctx, ala->ala_host); assert(rc == SSH_OK); diff --git a/lipe/src/lipe_ssh.c b/lipe/src/lipe_ssh.c index 01d537f..ed510a3 100644 --- a/lipe/src/lipe_ssh.c +++ b/lipe/src/lipe_ssh.c @@ -188,9 +188,7 @@ int lipe_ssh_context_init(struct lipe_ssh_context *ctx, const char *host) { memset(ctx, 0, sizeof(*ctx)); - ctx->lsc_host = strdup(host); - if (ctx->lsc_host == NULL) - return SSH_ERROR; + ctx->lsc_host = xstrdup(host); /* Session creation will be done on demand. */ diff --git a/lipe/src/lpurge.c b/lipe/src/lpurge.c index 120dc95..169ac4b 100644 --- a/lipe/src/lpurge.c +++ b/lipe/src/lpurge.c @@ -307,7 +307,7 @@ static void lpurge_find_device(char *devname) continue; if (!S_ISREG(st.st_mode)) continue; - if (ostname) + if (ostname) LX_FATAL("Multiple OST devices found for '%s'\n", devname); ostname = xstrdup(devname); @@ -1498,7 +1498,7 @@ static void lpurge_process_opt(int c, char *optarg) break; default: LX_FATAL("unknown option '-%c'\n" - "Try '%s --help' for more information.\n", + "Try '%s --help' for more information.\n", optopt, program_invocation_short_name); } } @@ -1510,7 +1510,7 @@ static void load_config(char *name) f = fopen(name, "r"); if (!f) - LX_FATAL("can't open config file '%s': %s\n", + LX_FATAL("can't open config file '%s': %s\n", name, strerror(errno)); while (!feof(f)) { @@ -1806,7 +1806,7 @@ static void lpurge_usr2_handle(int sig) json_object_put(obj_summary); if (rc < 0) { - LX_ERROR("failed to dump [%s] to file: %s, %s\n", + LX_ERROR("failed to dump [%s] to file '%s': %s\n", output, opt.o_fids_dumpfile, strerror(errno)); return; @@ -1849,7 +1849,7 @@ static void lpurge_usr2_handle(int sig) json_object_put(slot_stats); json_object_put(obj_slot); if (rc < 0) { - LX_ERROR("failed to dump [%s] to file: %s, %s\n", + LX_ERROR("failed to dump [%s] to file '%s': %s\n", output, opt.o_fids_dumpfile, strerror(errno)); return; @@ -1894,7 +1894,7 @@ static void lpurge_usr2_handle(int sig) rc = flist_add_one(dflist, output); json_object_put(obj_stat); if (rc < 0) { - LX_DEBUG("failed to dump [%s] to file: '%s', '%s'\n", + LX_DEBUG("failed to dump [%s] to file '%s': %s\n", output, opt.o_fids_dumpfile, strerror(errno)); continue; diff --git a/lipe/src/lx_log.h b/lipe/src/lx_log.h index 9715046..cfb0a38 100644 --- a/lipe/src/lx_log.h +++ b/lipe/src/lx_log.h @@ -4,6 +4,7 @@ #include #include #include +#include #include extern enum llapi_message_level lx_log_level; @@ -19,11 +20,13 @@ extern char *lx_log_prefix; /* Device name the message is related to */ */ #define LX_PRINT(level, fmt, args...) \ do { \ + int _lx_print_saved_errno = errno; \ if (level <= lx_log_level) \ fprintf(stderr, "%s%s" fmt, \ lx_log_prefix ? lx_log_prefix : "", \ lx_log_prefix ? ": " : "", \ ##args); \ + errno = _lx_print_saved_errno; \ } while (0) #define LX_DEBUG(fmt, args...) \ diff --git a/lustre/tests/hot-pools.sh b/lustre/tests/hot-pools.sh index c19bb64..6af2243 100755 --- a/lustre/tests/hot-pools.sh +++ b/lustre/tests/hot-pools.sh @@ -1064,8 +1064,7 @@ test_4() { check_one_lamigo_is_started || error "failed to start lamigo" stack_trap stop_one_lamigo_cfg - do_facet $facet "cat $log_file" | - grep -q "unknown tunable: $unknown_param" || + do_facet $facet "cat $log_file" | grep -q "unknown tunable: '$unknown_param'" || error "failed to recognize unknown parameter '$unknown_param'" LAMIGO_THREAD_NUM=2 LAMIGO_PROG_INTV=300 \ diff --git a/lustre/tests/yaml.sh b/lustre/tests/yaml.sh index bd08571..d30183f 100644 --- a/lustre/tests/yaml.sh +++ b/lustre/tests/yaml.sh @@ -9,7 +9,7 @@ split_output() { while read line; do host=${line%%:*}; echo "$line" | sed "s/^${host}: //" | sed "s/^${host}://" \ - >> $logdir/node.$host.yml; + >> "$logdir/node.$host.yml"; done } -- 1.8.3.1