diff --git a/lib/env_dpdk/env.c b/lib/env_dpdk/env.c index 94b709de9..6294bbe51 100644 --- a/lib/env_dpdk/env.c +++ b/lib/env_dpdk/env.c @@ -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); } diff --git a/lib/env_dpdk/init.c b/lib/env_dpdk/init.c index 0376dbe7b..d5eaf050b 100644 --- a/lib/env_dpdk/init.c +++ b/lib/env_dpdk/init.c @@ -37,6 +37,7 @@ #include "spdk/version.h" #include "spdk/env_dpdk.h" +#include "spdk/log.h" #include #include @@ -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; } diff --git a/lib/env_dpdk/memory.c b/lib/env_dpdk/memory.c index 4c2205a46..304bc3e1e 100644 --- a/lib/env_dpdk/memory.c +++ b/lib/env_dpdk/memory.c @@ -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 diff --git a/lib/env_dpdk/pci.c b/lib/env_dpdk/pci.c index efe9f61b1..43b0e9f35 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -36,6 +36,7 @@ #include #include #include "spdk/env.h" +#include "spdk/log.h" #define SYSFS_PCI_DRIVERS "/sys/bus/pci/drivers" @@ -164,8 +165,8 @@ 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", - rte_dev->name); + 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,15 +938,15 @@ 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" - " process %d has claimed it\n", dev_name, pid); + 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); /* F_SETLK returns unspecified errnos, normalize them */ diff --git a/test/env/vtophys/Makefile b/test/env/vtophys/Makefile index 68c4632a3..4b881e012 100644 --- a/test/env/vtophys/Makefile +++ b/test/env/vtophys/Makefile @@ -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