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

lib/env_dpdk: replace printf() and fprintf(stderr,) usage



And modify test/env/vtophys to resolve linking errors.

SPDK_PRINTF() and SPDK_ERRLOG() use spdk_log() procedure which is
customizable and redirectable, so it is preffered over printf()

In case of test/env/vtophys/ program,
we have to make it an app first to avoid linking errors.

Change-Id: Id806ec3bb235745316063bbdf6b5a15a9d5dc2d9
Signed-off-by: default avatarVitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1944


Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
parent 494dc66d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include "spdk/stdinc.h"
#include "spdk/util.h"
#include "spdk/env_dpdk.h"
#include "spdk/log.h"

#include "env_internal.h"

@@ -70,7 +71,7 @@ spdk_malloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, uint3
	buf = rte_malloc_socket(NULL, size, align, socket_id);
	if (buf && phys_addr) {
#ifdef DEBUG
		fprintf(stderr, "phys_addr param in spdk_*malloc() is deprecated\n");
		SPDK_ERRLOG("phys_addr param in spdk_*malloc() is deprecated\n");
#endif
		*phys_addr = virt_to_phys(buf);
	}
+12 −11
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@

#include "spdk/version.h"
#include "spdk/env_dpdk.h"
#include "spdk/log.h"

#include <rte_config.h>
#include <rte_eal.h>
@@ -147,7 +148,7 @@ push_arg(char *args[], int *argcount, char *arg)
	char **tmp;

	if (arg == NULL) {
		fprintf(stderr, "%s: NULL arg supplied\n", __func__);
		SPDK_ERRLOG("%s: NULL arg supplied\n", __func__);
		free_args(args, *argcount);
		return NULL;
	}
@@ -486,13 +487,13 @@ spdk_env_dpdk_post_init(bool legacy_mem)

	rc = mem_map_init(legacy_mem);
	if (rc < 0) {
		fprintf(stderr, "Failed to allocate mem_map\n");
		SPDK_ERRLOG("Failed to allocate mem_map\n");
		return rc;
	}

	rc = vtophys_init();
	if (rc < 0) {
		fprintf(stderr, "Failed to initialize vtophys\n");
		SPDK_ERRLOG("Failed to initialize vtophys\n");
		return rc;
	}

@@ -539,16 +540,16 @@ spdk_env_init(const struct spdk_env_opts *opts)

	rc = build_eal_cmdline(opts);
	if (rc < 0) {
		fprintf(stderr, "Invalid arguments to initialize DPDK\n");
		SPDK_ERRLOG("Invalid arguments to initialize DPDK\n");
		return -EINVAL;
	}

	printf("Starting %s / %s initialization...\n", SPDK_VERSION_STRING, rte_version());
	printf("[ DPDK EAL parameters: ");
	SPDK_PRINTF("Starting %s / %s initialization...\n", SPDK_VERSION_STRING, rte_version());
	SPDK_PRINTF("[ DPDK EAL parameters: ");
	for (i = 0; i < g_eal_cmdline_argcount; i++) {
		printf("%s ", g_eal_cmdline[i]);
		SPDK_PRINTF("%s ", g_eal_cmdline[i]);
	}
	printf("]\n");
	SPDK_PRINTF("]\n");

	/* DPDK rearranges the array we pass to it, so make a copy
	 * before passing so we can still free the individual strings
@@ -556,7 +557,7 @@ spdk_env_init(const struct spdk_env_opts *opts)
	 */
	dpdk_args = calloc(g_eal_cmdline_argcount, sizeof(char *));
	if (dpdk_args == NULL) {
		fprintf(stderr, "Failed to allocate dpdk_args\n");
		SPDK_ERRLOG("Failed to allocate dpdk_args\n");
		return -ENOMEM;
	}
	memcpy(dpdk_args, g_eal_cmdline, sizeof(char *) * g_eal_cmdline_argcount);
@@ -571,9 +572,9 @@ spdk_env_init(const struct spdk_env_opts *opts)

	if (rc < 0) {
		if (rte_errno == EALREADY) {
			fprintf(stderr, "DPDK already initialized\n");
			SPDK_ERRLOG("DPDK already initialized\n");
		} else {
			fprintf(stderr, "Failed to initialize DPDK\n");
			SPDK_ERRLOG("Failed to initialize DPDK\n");
		}
		return -rte_errno;
	}
+2 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@
#include "spdk/util.h"
#include "spdk/memory.h"
#include "spdk/env_dpdk.h"
#include "spdk/log.h"

#ifdef __FreeBSD__
#define VFIO_ENABLED 0
@@ -87,7 +88,7 @@ static struct vfio_cfg g_vfio = {
#endif

#if DEBUG
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
#define DEBUG_PRINT(...) SPDK_ERRLOG(__VA_ARGS__)
#else
#define DEBUG_PRINT(...)
#endif
+9 −8
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include <rte_alarm.h>
#include <rte_devargs.h>
#include "spdk/env.h"
#include "spdk/log.h"

#define SYSFS_PCI_DRIVERS	"/sys/bus/pci/drivers"

@@ -164,7 +165,7 @@ detach_rte(struct spdk_pci_device *dev)
	removed = dev->internal.removed;
	pthread_mutex_unlock(&g_pci_mutex);
	if (!removed) {
		fprintf(stderr, "Timeout waiting for DPDK to remove PCI device %s.\n",
		SPDK_ERRLOG("Timeout waiting for DPDK to remove PCI device %s.\n",
			    rte_dev->name);
		/* If we reach this state, then the device couldn't be removed and most likely
		   a subsequent hot add of a device in the same BDF will fail */
@@ -381,7 +382,7 @@ pci_env_fini(void)
	TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) {
		if (dev->internal.attached) {
			spdk_pci_addr_fmt(bdf, sizeof(bdf), &dev->addr);
			fprintf(stderr, "Device %s is still attached at shutdown!\n", bdf);
			SPDK_ERRLOG("Device %s is still attached at shutdown!\n", bdf);
		}
	}

@@ -924,12 +925,12 @@ spdk_pci_device_claim(struct spdk_pci_device *dev)

	dev_fd = open(dev_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
	if (dev_fd == -1) {
		fprintf(stderr, "could not open %s\n", dev_name);
		SPDK_ERRLOG("could not open %s\n", dev_name);
		return -errno;
	}

	if (ftruncate(dev_fd, sizeof(int)) != 0) {
		fprintf(stderr, "could not truncate %s\n", dev_name);
		SPDK_ERRLOG("could not truncate %s\n", dev_name);
		close(dev_fd);
		return -errno;
	}
@@ -937,14 +938,14 @@ spdk_pci_device_claim(struct spdk_pci_device *dev)
	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", dev_name, errno);
		SPDK_ERRLOG("could not mmap dev %s (%d)\n", dev_name, errno);
		close(dev_fd);
		return -errno;
	}

	if (fcntl(dev_fd, F_SETLK, &pcidev_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", dev_name, pid);
		munmap(dev_map, sizeof(int));
		close(dev_fd);
+8 −3
Original line number Diff line number Diff line
@@ -32,8 +32,13 @@
#

SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
include $(SPDK_ROOT_DIR)/mk/spdk.modules.mk

UNIT_TEST_LINK_ENV = 1
TEST_FILE = vtophys.c
APP = vtophys
C_SRCS := vtophys.c
SPDK_LIB_LIST += thread util log

include $(SPDK_ROOT_DIR)/mk/spdk.unittest.mk
SYS_LIBS += -lcunit

include $(SPDK_ROOT_DIR)/mk/spdk.app.mk