per Intel policy to include file commit date using git cmd below. The policy does not apply to non-Intel (C) notices. git log --follow -C90% --format=%ad --date default <file> | tail -1 and then pull just the 4 digit year from the result. Intel copyrights were not added to files where Intel either had no contribution ot the contribution lacked substance (ie license header updates, formatting changes, etc). Contribution date used "--follow -C95%" to get the most accurate date. Note that several files in this patch didn't end the license/(c) block with a blank comment line so these were added as the vast majority of files do have this last blank line. Simply there for consistency. Signed-off-by: paul luse <paul.e.luse@intel.com> Change-Id: Id5b7ce4f658fe87132f14139ead58d6e285c04d4 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15192 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Community-CI: Mellanox Build Bot
188 lines
4.0 KiB
C
188 lines
4.0 KiB
C
/* SPDX-License-Identifier: BSD-3-Clause
|
|
* Copyright (C) 2017 Intel Corporation.
|
|
* All rights reserved.
|
|
*/
|
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
#include "spdk/event.h"
|
|
#include "spdk/nvme.h"
|
|
#include "spdk/string.h"
|
|
#include "spdk/thread.h"
|
|
|
|
static char g_path[256];
|
|
static struct spdk_poller *g_poller;
|
|
/* default sleep time in ms */
|
|
static uint32_t g_sleep_time = 1000;
|
|
|
|
struct ctrlr_entry {
|
|
struct spdk_nvme_ctrlr *ctrlr;
|
|
TAILQ_ENTRY(ctrlr_entry) link;
|
|
};
|
|
|
|
static TAILQ_HEAD(, ctrlr_entry) g_controllers = TAILQ_HEAD_INITIALIZER(g_controllers);
|
|
|
|
static void
|
|
cleanup(void)
|
|
{
|
|
struct ctrlr_entry *ctrlr_entry, *tmp;
|
|
struct spdk_nvme_detach_ctx *detach_ctx = NULL;
|
|
|
|
TAILQ_FOREACH_SAFE(ctrlr_entry, &g_controllers, link, tmp) {
|
|
TAILQ_REMOVE(&g_controllers, ctrlr_entry, link);
|
|
spdk_nvme_detach_async(ctrlr_entry->ctrlr, &detach_ctx);
|
|
free(ctrlr_entry);
|
|
}
|
|
|
|
if (detach_ctx) {
|
|
spdk_nvme_detach_poll(detach_ctx);
|
|
}
|
|
}
|
|
|
|
static void
|
|
usage(char *executable_name)
|
|
{
|
|
printf("%s [options]\n", executable_name);
|
|
printf("options:\n");
|
|
printf(" -i shared memory ID [required]\n");
|
|
printf(" -m mask core mask for DPDK\n");
|
|
printf(" -n channel number of memory channels used for DPDK\n");
|
|
printf(" -p core main (primary) core for DPDK\n");
|
|
printf(" -s size memory size in MB for DPDK\n");
|
|
printf(" -t msec sleep time (ms) between checking for admin completions\n");
|
|
printf(" -H show this usage\n");
|
|
}
|
|
|
|
static bool
|
|
probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
|
struct spdk_nvme_ctrlr_opts *opts)
|
|
{
|
|
/*
|
|
* Set the io_queue_size to UINT16_MAX to initialize
|
|
* the controller with the possible largest queue size.
|
|
*/
|
|
opts->io_queue_size = UINT16_MAX;
|
|
return true;
|
|
}
|
|
|
|
static void
|
|
attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
|
struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts)
|
|
{
|
|
struct ctrlr_entry *entry;
|
|
|
|
entry = malloc(sizeof(struct ctrlr_entry));
|
|
if (entry == NULL) {
|
|
fprintf(stderr, "Malloc error\n");
|
|
exit(1);
|
|
}
|
|
|
|
entry->ctrlr = ctrlr;
|
|
TAILQ_INSERT_TAIL(&g_controllers, entry, link);
|
|
}
|
|
|
|
static int
|
|
stub_sleep(void *arg)
|
|
{
|
|
struct ctrlr_entry *ctrlr_entry, *tmp;
|
|
|
|
usleep(g_sleep_time * 1000);
|
|
TAILQ_FOREACH_SAFE(ctrlr_entry, &g_controllers, link, tmp) {
|
|
spdk_nvme_ctrlr_process_admin_completions(ctrlr_entry->ctrlr);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void
|
|
stub_start(void *arg1)
|
|
{
|
|
int shm_id = (intptr_t)arg1;
|
|
|
|
spdk_unaffinitize_thread();
|
|
|
|
if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
|
|
fprintf(stderr, "spdk_nvme_probe() failed\n");
|
|
exit(1);
|
|
}
|
|
|
|
snprintf(g_path, sizeof(g_path), "/var/run/spdk_stub%d", shm_id);
|
|
if (mknod(g_path, S_IFREG, 0) != 0) {
|
|
fprintf(stderr, "could not create sentinel file %s\n", g_path);
|
|
exit(1);
|
|
}
|
|
|
|
g_poller = SPDK_POLLER_REGISTER(stub_sleep, NULL, 0);
|
|
}
|
|
|
|
static void
|
|
stub_shutdown(void)
|
|
{
|
|
spdk_poller_unregister(&g_poller);
|
|
unlink(g_path);
|
|
spdk_app_stop(0);
|
|
}
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
int ch;
|
|
struct spdk_app_opts opts = {};
|
|
long int val;
|
|
|
|
/* default value in opts structure */
|
|
spdk_app_opts_init(&opts, sizeof(opts));
|
|
|
|
opts.name = "stub";
|
|
opts.rpc_addr = NULL;
|
|
|
|
while ((ch = getopt(argc, argv, "i:m:n:p:s:t:H")) != -1) {
|
|
if (ch == 'm') {
|
|
opts.reactor_mask = optarg;
|
|
} else if (ch == '?' || ch == 'H') {
|
|
usage(argv[0]);
|
|
exit(EXIT_SUCCESS);
|
|
} else {
|
|
val = spdk_strtol(optarg, 10);
|
|
if (val < 0) {
|
|
fprintf(stderr, "Converting a string to integer failed\n");
|
|
exit(1);
|
|
}
|
|
switch (ch) {
|
|
case 'i':
|
|
opts.shm_id = val;
|
|
break;
|
|
case 'n':
|
|
opts.mem_channel = val;
|
|
break;
|
|
case 'p':
|
|
opts.main_core = val;
|
|
break;
|
|
case 's':
|
|
opts.mem_size = val;
|
|
break;
|
|
case 't':
|
|
g_sleep_time = val;
|
|
break;
|
|
default:
|
|
usage(argv[0]);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (opts.shm_id < 0) {
|
|
fprintf(stderr, "%s: -i shared memory ID must be specified\n", argv[0]);
|
|
usage(argv[0]);
|
|
exit(1);
|
|
}
|
|
|
|
opts.shutdown_cb = stub_shutdown;
|
|
|
|
ch = spdk_app_start(&opts, stub_start, (void *)(intptr_t)opts.shm_id);
|
|
|
|
cleanup();
|
|
spdk_app_fini();
|
|
|
|
return ch;
|
|
}
|