Commit 6b408572 authored by Vitaliy Mysak's avatar Vitaliy Mysak Committed by Tomasz Zawadzki
Browse files

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: default avatarVitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1943


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent caa9d4c8
Loading
Loading
Loading
Loading
+22 −23
Original line number Diff line number Diff line
@@ -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,7 +821,7 @@ 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",
			SPDK_ERRLOG("Duplicated option '%c' between the generic and application specific spdk opts.\n",
				    ch);
			goto out;
		}
@@ -829,7 +829,7 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,

	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",
			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;
	}

+3 −3
Original line number Diff line number Diff line
@@ -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;
	}

+1 −1
Original line number Diff line number Diff line
@@ -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
+5 −5
Original line number Diff line number Diff line
@@ -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,14 +740,14 @@ 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"
		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);
+7 −6
Original line number Diff line number Diff line
@@ -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;
	}