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: Vitaliy 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: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
parent
494dc66ddb
commit
d8190d0288
@ -34,6 +34,7 @@
|
|||||||
#include "spdk/stdinc.h"
|
#include "spdk/stdinc.h"
|
||||||
#include "spdk/util.h"
|
#include "spdk/util.h"
|
||||||
#include "spdk/env_dpdk.h"
|
#include "spdk/env_dpdk.h"
|
||||||
|
#include "spdk/log.h"
|
||||||
|
|
||||||
#include "env_internal.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);
|
buf = rte_malloc_socket(NULL, size, align, socket_id);
|
||||||
if (buf && phys_addr) {
|
if (buf && phys_addr) {
|
||||||
#ifdef DEBUG
|
#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
|
#endif
|
||||||
*phys_addr = virt_to_phys(buf);
|
*phys_addr = virt_to_phys(buf);
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include "spdk/version.h"
|
#include "spdk/version.h"
|
||||||
#include "spdk/env_dpdk.h"
|
#include "spdk/env_dpdk.h"
|
||||||
|
#include "spdk/log.h"
|
||||||
|
|
||||||
#include <rte_config.h>
|
#include <rte_config.h>
|
||||||
#include <rte_eal.h>
|
#include <rte_eal.h>
|
||||||
@ -147,7 +148,7 @@ push_arg(char *args[], int *argcount, char *arg)
|
|||||||
char **tmp;
|
char **tmp;
|
||||||
|
|
||||||
if (arg == NULL) {
|
if (arg == NULL) {
|
||||||
fprintf(stderr, "%s: NULL arg supplied\n", __func__);
|
SPDK_ERRLOG("%s: NULL arg supplied\n", __func__);
|
||||||
free_args(args, *argcount);
|
free_args(args, *argcount);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -486,13 +487,13 @@ spdk_env_dpdk_post_init(bool legacy_mem)
|
|||||||
|
|
||||||
rc = mem_map_init(legacy_mem);
|
rc = mem_map_init(legacy_mem);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
fprintf(stderr, "Failed to allocate mem_map\n");
|
SPDK_ERRLOG("Failed to allocate mem_map\n");
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = vtophys_init();
|
rc = vtophys_init();
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
fprintf(stderr, "Failed to initialize vtophys\n");
|
SPDK_ERRLOG("Failed to initialize vtophys\n");
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,16 +540,16 @@ spdk_env_init(const struct spdk_env_opts *opts)
|
|||||||
|
|
||||||
rc = build_eal_cmdline(opts);
|
rc = build_eal_cmdline(opts);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
fprintf(stderr, "Invalid arguments to initialize DPDK\n");
|
SPDK_ERRLOG("Invalid arguments to initialize DPDK\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Starting %s / %s initialization...\n", SPDK_VERSION_STRING, rte_version());
|
SPDK_PRINTF("Starting %s / %s initialization...\n", SPDK_VERSION_STRING, rte_version());
|
||||||
printf("[ DPDK EAL parameters: ");
|
SPDK_PRINTF("[ DPDK EAL parameters: ");
|
||||||
for (i = 0; i < g_eal_cmdline_argcount; i++) {
|
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
|
/* DPDK rearranges the array we pass to it, so make a copy
|
||||||
* before passing so we can still free the individual strings
|
* 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 *));
|
dpdk_args = calloc(g_eal_cmdline_argcount, sizeof(char *));
|
||||||
if (dpdk_args == NULL) {
|
if (dpdk_args == NULL) {
|
||||||
fprintf(stderr, "Failed to allocate dpdk_args\n");
|
SPDK_ERRLOG("Failed to allocate dpdk_args\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
memcpy(dpdk_args, g_eal_cmdline, sizeof(char *) * g_eal_cmdline_argcount);
|
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 (rc < 0) {
|
||||||
if (rte_errno == EALREADY) {
|
if (rte_errno == EALREADY) {
|
||||||
fprintf(stderr, "DPDK already initialized\n");
|
SPDK_ERRLOG("DPDK already initialized\n");
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to initialize DPDK\n");
|
SPDK_ERRLOG("Failed to initialize DPDK\n");
|
||||||
}
|
}
|
||||||
return -rte_errno;
|
return -rte_errno;
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include "spdk/util.h"
|
#include "spdk/util.h"
|
||||||
#include "spdk/memory.h"
|
#include "spdk/memory.h"
|
||||||
#include "spdk/env_dpdk.h"
|
#include "spdk/env_dpdk.h"
|
||||||
|
#include "spdk/log.h"
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
#define VFIO_ENABLED 0
|
#define VFIO_ENABLED 0
|
||||||
@ -87,7 +88,7 @@ static struct vfio_cfg g_vfio = {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
|
#define DEBUG_PRINT(...) SPDK_ERRLOG(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define DEBUG_PRINT(...)
|
#define DEBUG_PRINT(...)
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <rte_alarm.h>
|
#include <rte_alarm.h>
|
||||||
#include <rte_devargs.h>
|
#include <rte_devargs.h>
|
||||||
#include "spdk/env.h"
|
#include "spdk/env.h"
|
||||||
|
#include "spdk/log.h"
|
||||||
|
|
||||||
#define SYSFS_PCI_DRIVERS "/sys/bus/pci/drivers"
|
#define SYSFS_PCI_DRIVERS "/sys/bus/pci/drivers"
|
||||||
|
|
||||||
@ -164,8 +165,8 @@ detach_rte(struct spdk_pci_device *dev)
|
|||||||
removed = dev->internal.removed;
|
removed = dev->internal.removed;
|
||||||
pthread_mutex_unlock(&g_pci_mutex);
|
pthread_mutex_unlock(&g_pci_mutex);
|
||||||
if (!removed) {
|
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);
|
rte_dev->name);
|
||||||
/* If we reach this state, then the device couldn't be removed and most likely
|
/* 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 */
|
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) {
|
TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) {
|
||||||
if (dev->internal.attached) {
|
if (dev->internal.attached) {
|
||||||
spdk_pci_addr_fmt(bdf, sizeof(bdf), &dev->addr);
|
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);
|
dev_fd = open(dev_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
||||||
if (dev_fd == -1) {
|
if (dev_fd == -1) {
|
||||||
fprintf(stderr, "could not open %s\n", dev_name);
|
SPDK_ERRLOG("could not open %s\n", dev_name);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ftruncate(dev_fd, sizeof(int)) != 0) {
|
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);
|
close(dev_fd);
|
||||||
return -errno;
|
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,
|
dev_map = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE,
|
||||||
MAP_SHARED, dev_fd, 0);
|
MAP_SHARED, dev_fd, 0);
|
||||||
if (dev_map == MAP_FAILED) {
|
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);
|
close(dev_fd);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fcntl(dev_fd, F_SETLK, &pcidev_lock) != 0) {
|
if (fcntl(dev_fd, F_SETLK, &pcidev_lock) != 0) {
|
||||||
pid = *(int *)dev_map;
|
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);
|
" process %d has claimed it\n", dev_name, pid);
|
||||||
munmap(dev_map, sizeof(int));
|
munmap(dev_map, sizeof(int));
|
||||||
close(dev_fd);
|
close(dev_fd);
|
||||||
/* F_SETLK returns unspecified errnos, normalize them */
|
/* F_SETLK returns unspecified errnos, normalize them */
|
||||||
|
11
test/env/vtophys/Makefile
vendored
11
test/env/vtophys/Makefile
vendored
@ -32,8 +32,13 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
|
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
|
APP = vtophys
|
||||||
TEST_FILE = vtophys.c
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user