From 6b40857206ece4b2ac3edd341abbb0344ebeedaa Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Sat, 18 Apr 2020 14:12:43 +0200 Subject: [PATCH] lib: replace fprintf(stderr,) by SPDK_ERRLOG SPDK_ERRLOG() uses spdk_log() procedure which is customizable and redirectable, so it is preffered over fprintf. It also prints source location which is useful. Change-Id: I27574be4a774169f356ebd8dcdfd2a33a057f051 Signed-off-by: Vitaliy Mysak Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1943 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris --- lib/event/app.c | 45 ++++++++++++++++++++--------------------- lib/event/json_config.c | 6 +++--- lib/ftl/ftl_debug.h | 2 +- lib/nvme/nvme_cuse.c | 10 ++++----- lib/trace/trace.c | 13 ++++++------ 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/lib/event/app.c b/lib/event/app.c index cd12fa3cf..b0bb5fb46 100644 --- a/lib/event/app.c +++ b/lib/event/app.c @@ -514,7 +514,7 @@ spdk_app_setup_env(struct spdk_app_opts *opts) free(env_opts.pci_whitelist); if (rc < 0) { - fprintf(stderr, "Unable to initialize SPDK env\n"); + SPDK_ERRLOG("Unable to initialize SPDK env\n"); } return rc; @@ -808,7 +808,7 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts, cmdline_options = calloc(global_long_opts_len + app_long_opts_len + 1, sizeof(*cmdline_options)); if (!cmdline_options) { - fprintf(stderr, "Out of memory\n"); + SPDK_ERRLOG("Out of memory\n"); return SPDK_APP_PARSE_ARGS_FAIL; } @@ -821,15 +821,15 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts, if (app_getopt_str != NULL) { ch = spdk_app_opts_validate(app_getopt_str); if (ch) { - fprintf(stderr, "Duplicated option '%c' between the generic and application specific spdk opts.\n", - ch); + SPDK_ERRLOG("Duplicated option '%c' between the generic and application specific spdk opts.\n", + ch); goto out; } } cmdline_short_opts = spdk_sprintf_alloc("%s%s", app_getopt_str, SPDK_APP_GETOPT_STRING); if (!cmdline_short_opts) { - fprintf(stderr, "Out of memory\n"); + SPDK_ERRLOG("Out of memory\n"); goto out; } @@ -862,7 +862,7 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts, case SHM_ID_OPT_IDX: opts->shm_id = spdk_strtol(optarg, 0); if (opts->shm_id < 0) { - fprintf(stderr, "Invalid shared memory ID %s\n", optarg); + SPDK_ERRLOG("Invalid shared memory ID %s\n", optarg); goto out; } break; @@ -872,14 +872,14 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts, case MEM_CHANNELS_OPT_IDX: opts->mem_channel = spdk_strtol(optarg, 0); if (opts->mem_channel < 0) { - fprintf(stderr, "Invalid memory channel %s\n", optarg); + SPDK_ERRLOG("Invalid memory channel %s\n", optarg); goto out; } break; case MASTER_CORE_OPT_IDX: opts->master_core = spdk_strtol(optarg, 0); if (opts->master_core < 0) { - fprintf(stderr, "Invalid master core %s\n", optarg); + SPDK_ERRLOG("Invalid master core %s\n", optarg); goto out; } break; @@ -895,7 +895,7 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts, rc = spdk_parse_capacity(optarg, &mem_size_mb, &mem_size_has_prefix); if (rc != 0) { - fprintf(stderr, "invalid memory pool size `-s %s`\n", optarg); + SPDK_ERRLOG("invalid memory pool size `-s %s`\n", optarg); usage(app_usage); goto out; } @@ -908,7 +908,7 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts, } if (mem_size_mb > INT_MAX) { - fprintf(stderr, "invalid memory pool size `-s %s`\n", optarg); + SPDK_ERRLOG("invalid memory pool size `-s %s`\n", optarg); usage(app_usage); goto out; } @@ -926,7 +926,7 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts, if (opts->pci_whitelist) { free(opts->pci_whitelist); opts->pci_whitelist = NULL; - fprintf(stderr, "-B and -W cannot be used at the same time\n"); + SPDK_ERRLOG("-B and -W cannot be used at the same time\n"); usage(app_usage); goto out; } @@ -940,14 +940,14 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts, break; case LOGFLAG_OPT_IDX: #ifndef DEBUG - fprintf(stderr, "%s must be configured with --enable-debug for -L flag\n", - argv[0]); + SPDK_ERRLOG("%s must be configured with --enable-debug for -L flag\n", + argv[0]); usage(app_usage); goto out; #else rc = spdk_log_set_flag(optarg); if (rc < 0) { - fprintf(stderr, "unknown flag\n"); + SPDK_ERRLOG("unknown flag\n"); usage(app_usage); goto out; } @@ -961,7 +961,7 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts, if (opts->pci_blacklist) { free(opts->pci_blacklist); opts->pci_blacklist = NULL; - fprintf(stderr, "-B and -W cannot be used at the same time\n"); + SPDK_ERRLOG("-B and -W cannot be used at the same time\n"); usage(app_usage); goto out; } @@ -979,20 +979,19 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts, case NUM_TRACE_ENTRIES_OPT_IDX: tmp = spdk_strtoll(optarg, 0); if (tmp <= 0) { - fprintf(stderr, "Invalid num-trace-entries %s\n", optarg); + SPDK_ERRLOG("Invalid num-trace-entries %s\n", optarg); usage(app_usage); goto out; } opts->num_entries = (uint64_t)tmp; if (opts->num_entries & (opts->num_entries - 1)) { - fprintf(stderr, "num-trace-entries must be power of 2\n"); + SPDK_ERRLOG("num-trace-entries must be power of 2\n"); usage(app_usage); goto out; } break; case MAX_REACTOR_DELAY_OPT_IDX: - fprintf(stderr, - "Deprecation warning: The maximum allowed latency parameter is no longer supported.\n"); + SPDK_ERRLOG("Deprecation warning: The maximum allowed latency parameter is no longer supported.\n"); break; case VERSION_OPT_IDX: printf(SPDK_VERSION_STRING"\n"); @@ -1009,19 +1008,19 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts, default: rc = app_parse(ch, optarg); if (rc) { - fprintf(stderr, "Parsing application specific arguments failed: %d\n", rc); + SPDK_ERRLOG("Parsing application specific arguments failed: %d\n", rc); goto out; } } } if (opts->config_file && opts->json_config_file) { - fprintf(stderr, "ERROR: Legacy config and JSON config can't be used together.\n"); + SPDK_ERRLOG("ERROR: Legacy config and JSON config can't be used together.\n"); goto out; } if (opts->json_config_file && opts->delay_subsystem_init) { - fprintf(stderr, "ERROR: JSON configuration file can't be used together with --wait-for-rpc.\n"); + SPDK_ERRLOG("ERROR: JSON configuration file can't be used together with --wait-for-rpc.\n"); goto out; } @@ -1049,7 +1048,7 @@ void spdk_app_usage(void) { if (g_executable_name == NULL) { - fprintf(stderr, "%s not valid before calling spdk_app_parse_args()\n", __func__); + SPDK_ERRLOG("%s not valid before calling spdk_app_parse_args()\n", __func__); return; } diff --git a/lib/event/json_config.c b/lib/event/json_config.c index f953041f7..ebc1f5174 100644 --- a/lib/event/json_config.c +++ b/lib/event/json_config.c @@ -500,21 +500,21 @@ spdk_app_json_config_read(const char *config_file, struct load_json_config_ctx * rc = spdk_json_parse(json, json_size, NULL, 0, &end, SPDK_JSON_PARSE_FLAG_ALLOW_COMMENTS); if (rc < 0) { - fprintf(stderr, "Parsing JSON configuration failed (%zd)\n", rc); + SPDK_ERRLOG("Parsing JSON configuration failed (%zd)\n", rc); goto err; } values_cnt = rc; values = calloc(values_cnt, sizeof(struct spdk_json_val)); if (values == NULL) { - fprintf(stderr, "Out of memory\n"); + SPDK_ERRLOG("Out of memory\n"); goto err; } rc = spdk_json_parse(json, json_size, values, values_cnt, &end, SPDK_JSON_PARSE_FLAG_ALLOW_COMMENTS); if (rc != values_cnt) { - fprintf(stderr, "Parsing JSON configuration failed (%zd)\n", rc); + SPDK_ERRLOG("Parsing JSON configuration failed (%zd)\n", rc); goto err; } diff --git a/lib/ftl/ftl_debug.h b/lib/ftl/ftl_debug.h index 2c2e9973d..c90c92ef2 100644 --- a/lib/ftl/ftl_debug.h +++ b/lib/ftl/ftl_debug.h @@ -44,7 +44,7 @@ #define FTL_DUMP_STATS 1 #define ftl_debug(msg, ...) \ - fprintf(stderr, msg, ## __VA_ARGS__) + SPDK_ERRLOG(msg, ## __VA_ARGS__) #else #define ftl_debug(msg, ...) #endif diff --git a/lib/nvme/nvme_cuse.c b/lib/nvme/nvme_cuse.c index 8913dcc5e..b0eafa51b 100644 --- a/lib/nvme/nvme_cuse.c +++ b/lib/nvme/nvme_cuse.c @@ -727,12 +727,12 @@ nvme_cuse_claim(struct cuse_device *ctrlr_device, uint32_t index) dev_fd = open(ctrlr_device->lock_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (dev_fd == -1) { - fprintf(stderr, "could not open %s\n", ctrlr_device->lock_name); + SPDK_ERRLOG("could not open %s\n", ctrlr_device->lock_name); return -errno; } if (ftruncate(dev_fd, sizeof(int)) != 0) { - fprintf(stderr, "could not truncate %s\n", ctrlr_device->lock_name); + SPDK_ERRLOG("could not truncate %s\n", ctrlr_device->lock_name); close(dev_fd); return -errno; } @@ -740,15 +740,15 @@ nvme_cuse_claim(struct cuse_device *ctrlr_device, uint32_t index) dev_map = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, dev_fd, 0); if (dev_map == MAP_FAILED) { - fprintf(stderr, "could not mmap dev %s (%d)\n", ctrlr_device->lock_name, errno); + SPDK_ERRLOG("could not mmap dev %s (%d)\n", ctrlr_device->lock_name, errno); close(dev_fd); return -errno; } if (fcntl(dev_fd, F_SETLK, &cusedev_lock) != 0) { pid = *(int *)dev_map; - fprintf(stderr, "Cannot create lock on device %s, probably" - " process %d has claimed it\n", ctrlr_device->lock_name, pid); + SPDK_ERRLOG("Cannot create lock on device %s, probably" + " process %d has claimed it\n", ctrlr_device->lock_name, pid); munmap(dev_map, sizeof(int)); close(dev_fd); /* F_SETLK returns unspecified errnos, normalize them */ diff --git a/lib/trace/trace.c b/lib/trace/trace.c index 048553db1..621c52aae 100644 --- a/lib/trace/trace.c +++ b/lib/trace/trace.c @@ -38,6 +38,7 @@ #include "spdk/trace.h" #include "spdk/util.h" #include "spdk/barrier.h" +#include "spdk/log.h" static int g_trace_fd = -1; static char g_shm_name[64]; @@ -102,20 +103,20 @@ spdk_trace_init(const char *shm_name, uint64_t num_entries) g_trace_fd = shm_open(shm_name, O_RDWR | O_CREAT, 0600); if (g_trace_fd == -1) { - fprintf(stderr, "could not shm_open spdk_trace\n"); - fprintf(stderr, "errno=%d %s\n", errno, spdk_strerror(errno)); + SPDK_ERRLOG("could not shm_open spdk_trace\n"); + SPDK_ERRLOG("errno=%d %s\n", errno, spdk_strerror(errno)); return 1; } if (ftruncate(g_trace_fd, histories_size) != 0) { - fprintf(stderr, "could not truncate shm\n"); + SPDK_ERRLOG("could not truncate shm\n"); goto trace_init_err; } g_trace_histories = mmap(NULL, histories_size, PROT_READ | PROT_WRITE, MAP_SHARED, g_trace_fd, 0); if (g_trace_histories == MAP_FAILED) { - fprintf(stderr, "could not mmap shm\n"); + SPDK_ERRLOG("could not mmap shm\n"); goto trace_init_err; } @@ -125,9 +126,9 @@ spdk_trace_init(const char *shm_name, uint64_t num_entries) */ #if defined(__linux__) if (mlock(g_trace_histories, histories_size) != 0) { - fprintf(stderr, "Could not mlock shm for tracing - %s.\n", spdk_strerror(errno)); + SPDK_ERRLOG("Could not mlock shm for tracing - %s.\n", spdk_strerror(errno)); if (errno == ENOMEM) { - fprintf(stderr, "Check /dev/shm for old tracing files that can be deleted.\n"); + SPDK_ERRLOG("Check /dev/shm for old tracing files that can be deleted.\n"); } goto trace_init_err; }