Commit 81551144 authored by Xiaodong Liu's avatar Xiaodong Liu Committed by Jim Harris
Browse files

env: add spdk_env_dpdk_post_init

Based on requirement of initializing SPDK env
from a DPDK application, relative to spdk_env_init,
add spdk_env_dpdk_post_init for calling after rte_env_init.
More details, visit
https://github.com/spdk/spdk/issues/529



Change-Id: I6fda1593e0296ef93b705e31cc76bcd0d248673a
Signed-off-by: default avatarXiaodong Liu <xiaodong.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/437225


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent ed1e9613
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2,6 +2,12 @@

## v19.01: (Upcoming Release)

### environment

A new public header file env_dpdk.h has been introduced, and function spdk_env_dpdk_post_init
is added into it. If user is using DPDK, and already called rte_eal_init, then include
include/spdk/env_dpdk.h, and call spdk_env_dpdk_post_init() instead of spdk_env_init.

### util

A new uuid API `spdk_uuid_copy` was added to make a copy of the source uuid.
+59 −0
Original line number Diff line number Diff line
/*-
 *   BSD LICENSE
 *
 *   Copyright (c) Intel Corporation.
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.
 *     * Neither the name of Intel Corporation nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/** \file
 * Encapsulated DPDK specific dependencies
 */

#ifndef SPDK_ENV_DPDK_H
#define SPDK_ENV_DPDK_H

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Initialize the environment library after DPDK env is already initialized.
 * If DPDK's rte_eal_init is already called, this function must be called
 * instead of spdk_env_init, prior to using any other functions in SPDK
 * env library.
 *
 * \return 0 on success, or negative errno on failure.
 */
int spdk_env_dpdk_post_init(void);

#ifdef __cplusplus
}
#endif

#endif
+21 −13
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include "env_internal.h"

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

#include <rte_config.h>
#include <rte_eal.h>
@@ -342,7 +343,25 @@ spdk_build_eal_cmdline(const struct spdk_env_opts *opts)
	return argcount;
}

int spdk_env_init(const struct spdk_env_opts *opts)
int
spdk_env_dpdk_post_init(void)
{
	spdk_pci_init();

	if (spdk_mem_map_init() < 0) {
		fprintf(stderr, "Failed to allocate mem_map\n");
		return -1;
	}
	if (spdk_vtophys_init() < 0) {
		fprintf(stderr, "Failed to initialize vtophys\n");
		return -1;
	}

	return 0;
}

int
spdk_env_init(const struct spdk_env_opts *opts)
{
	char **dpdk_args = NULL;
	int i, rc;
@@ -396,16 +415,5 @@ int spdk_env_init(const struct spdk_env_opts *opts)
		spdk_env_unlink_shared_files();
	}

	spdk_pci_init();

	if (spdk_mem_map_init() < 0) {
		fprintf(stderr, "Failed to allocate mem_map\n");
		return -1;
	}
	if (spdk_vtophys_init() < 0) {
		fprintf(stderr, "Failed to initialize vtophys\n");
		return -1;
	}

	return 0;
	return spdk_env_dpdk_post_init();
}
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ ENV_NAME := $(notdir $(CONFIG_ENV))
DIRS-y = vtophys

ifeq ($(ENV_NAME),env_dpdk)
DIRS-y += memory pci
DIRS-y += env_dpdk_post_init memory pci
endif

.PHONY: all clean $(DIRS-y)
+4 −0
Original line number Diff line number Diff line
@@ -20,5 +20,9 @@ timing_enter pci
$testdir/pci/pci_ut
timing_exit pci

timing_enter env_dpdk_post_init
$testdir/env_dpdk_post_init/env_dpdk_post_init
timing_exit env_dpdk_post_init

report_test_completion "env"
timing_exit env
Loading