]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/env/env_dpdk_post_init/env_dpdk_post_init.c
4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "spdk/stdinc.h"
36 #include "spdk/nvme.h"
38 #include "spdk/env_dpdk.h"
39 #include <rte_config.h>
45 struct spdk_nvme_ctrlr
*ctrlr
;
46 struct spdk_nvme_ns
*ns
;
47 struct spdk_nvme_qpair
*qpair
;
48 char name
[SPDK_NVMF_TRADDR_MAX_LEN
+ 1];
51 static struct dev g_nvme_devs
[MAX_DEVS
];
52 static int g_num_devs
= 0;
53 static int g_failed
= 0;
56 probe_cb(void *cb_ctx
, const struct spdk_nvme_transport_id
*trid
,
57 struct spdk_nvme_ctrlr_opts
*opts
)
59 printf("Attaching to %s\n", trid
->traddr
);
65 attach_cb(void *cb_ctx
, const struct spdk_nvme_transport_id
*trid
,
66 struct spdk_nvme_ctrlr
*ctrlr
, const struct spdk_nvme_ctrlr_opts
*opts
)
72 dev
= &g_nvme_devs
[g_num_devs
++];
73 if (g_num_devs
>= MAX_DEVS
) {
78 nsid
= spdk_nvme_ctrlr_get_first_active_ns(ctrlr
);
79 dev
->ns
= spdk_nvme_ctrlr_get_ns(ctrlr
, nsid
);
81 dev
->qpair
= spdk_nvme_ctrlr_alloc_io_qpair(ctrlr
, NULL
, 0);
82 if (dev
->qpair
== NULL
) {
87 snprintf(dev
->name
, sizeof(dev
->name
), "%s",
90 printf("Attached to %s\n", dev
->name
);
94 main(int argc
, char **argv
)
99 printf("Starting DPDK initialization...\n");
100 ret
= rte_eal_init(argc
, argv
);
102 fprintf(stderr
, "Failed to initialize DPDK\n");
106 printf("Starting SPDK post initialization...\n");
107 ret
= spdk_env_dpdk_post_init(false);
109 fprintf(stderr
, "Failed to initialize SPDK\n");
113 printf("SPDK NVMe probe\n");
114 if (spdk_nvme_probe(NULL
, NULL
, probe_cb
, attach_cb
, NULL
) != 0) {
115 fprintf(stderr
, "spdk_nvme_probe() failed\n");
119 printf("Cleaning up...\n");
120 for (i
= 0; i
< g_num_devs
; i
++) {
121 struct dev
*dev
= &g_nvme_devs
[i
];
122 spdk_nvme_detach(dev
->ctrlr
);