external_code/identify: use nvme_connect() if an address is provided
The identify app can now be used in two modes: - without any parameters it'll attach to all available NVMe controllers and print each one out, - with a single parameter specifying the BDF address of the controller it'll only attach and print out information about that controller. Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com> Change-Id: I02c7a8a072f1db5fdfd428a5ab84163f26338a09 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6666 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Mellanox Build Bot Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
5802856ece
commit
86b1b71f5f
@ -35,16 +35,21 @@
|
||||
#include "nvme.h"
|
||||
|
||||
static void
|
||||
attach_cb(void *cb_ctx, const struct spdk_pci_addr *addr,
|
||||
struct nvme_ctrlr *ctrlr)
|
||||
print_controller(const struct spdk_pci_addr *addr)
|
||||
{
|
||||
char fmtaddr[32] = {};
|
||||
|
||||
(void)cb_ctx;
|
||||
|
||||
spdk_pci_addr_fmt(fmtaddr, sizeof(fmtaddr), addr);
|
||||
printf("Found NVMe controller at: %s\n", fmtaddr);
|
||||
}
|
||||
|
||||
static void
|
||||
attach_cb(void *cb_ctx, const struct spdk_pci_addr *addr,
|
||||
struct nvme_ctrlr *ctrlr)
|
||||
{
|
||||
(void)cb_ctx;
|
||||
|
||||
print_controller(addr);
|
||||
nvme_detach(ctrlr);
|
||||
}
|
||||
|
||||
@ -52,10 +57,10 @@ int
|
||||
main(int argc, const char **argv)
|
||||
{
|
||||
struct spdk_env_opts opts;
|
||||
struct spdk_pci_addr addr;
|
||||
struct nvme_ctrlr *ctrlr;
|
||||
int rc;
|
||||
|
||||
(void)argc;
|
||||
|
||||
spdk_env_opts_init(&opts);
|
||||
opts.name = "identify";
|
||||
|
||||
@ -64,9 +69,30 @@ main(int argc, const char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = nvme_probe(attach_cb, NULL);
|
||||
if (rc != 0) {
|
||||
fprintf(stderr, "%s: nvme probe failed\n", argv[0]);
|
||||
if (argc == 2) {
|
||||
rc = spdk_pci_addr_parse(&addr, argv[1]);
|
||||
if (rc != 0) {
|
||||
fprintf(stderr, "%s: failed to parse the address\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ctrlr = nvme_connect(&addr);
|
||||
if (!ctrlr) {
|
||||
fprintf(stderr, "%s: failed to connect to controller at %s\n",
|
||||
argv[0], argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
print_controller(&addr);
|
||||
nvme_detach(ctrlr);
|
||||
} else if (argc == 1) {
|
||||
rc = nvme_probe(attach_cb, NULL);
|
||||
if (rc != 0) {
|
||||
fprintf(stderr, "%s: nvme probe failed\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Usage: %s [PCI_BDF_ADDRESS]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user