Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions libnvme/examples/discover-loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void print_discover_log(struct nvmf_discovery_log *log)

int main()
{
struct nvmf_discovery_log *log = NULL;
struct nvmf_discovery_log *log;
struct nvme_global_ctx *ctx;
nvme_host_t h;
nvme_ctrl_t c;
Expand All @@ -59,24 +59,30 @@ int main()

nvmf_default_config(&cfg);

ret = nvme_scan(NULL, &ctx);
if (ret)
return ret;
ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL);
if (!ctx)
return 1;

ret = nvme_scan_topology(ctx, NULL, NULL);
if (ret) {
nvme_free_global_ctx(ctx);
return 1;
}
ret = nvme_host_get(ctx, NULL, NULL, &h);
if (ret) {
fprintf(stderr, "Failed to allocated memory\n");
return ret;
return 1;
}
ret = nvme_create_ctrl(ctx, NVME_DISC_SUBSYS_NAME, "loop",
NULL, NULL, NULL, NULL, &c);
if (ret) {
fprintf(stderr, "Failed to allocate memory\n");
return ENOMEM;
return 1;
}
ret = nvmf_add_ctrl(h, c, &cfg);
if (ret) {
fprintf(stderr, "no controller found\n");
return ret;
return 1;
}

ret = nvmf_get_discovery_log(c, &log, 4);
Expand Down
12 changes: 10 additions & 2 deletions libnvme/examples/display-columnar.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@ int main()
nvme_ctrl_t c;
nvme_path_t p;
nvme_ns_t n;
int err;

if (nvme_scan(NULL, &ctx))
return -1;
ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL);
if (!ctx)
return 1;

err = nvme_scan_topology(ctx, NULL, NULL);
if (err) {
nvme_free_global_ctx(ctx);
return 1;
}

printf("%-16s %-96s %-.16s\n", "Subsystem", "Subsystem-NQN", "Controllers");
printf("%-.16s %-.96s %-.16s\n", dash, dash, dash);
Expand Down
12 changes: 10 additions & 2 deletions libnvme/examples/display-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ int main()
nvme_ctrl_t c, _c;
nvme_path_t p, _p;
nvme_ns_t n, _n;
int err;

if (nvme_scan(NULL, &ctx))
return -1;
ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL);
if (!ctx)
return 1;

err = nvme_scan_topology(ctx, NULL, NULL);
if (err) {
nvme_free_global_ctx(ctx);
return 1;
}

printf(".\n");
nvme_for_each_host(ctx, h) {
Expand Down
8 changes: 7 additions & 1 deletion libnvme/examples/telemetry-listen.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,14 @@ int main()
nvme_ctrl_t c;
nvme_host_t h;

if (nvme_scan(NULL, &ctx))
ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL);
if (!ctx)
return 1;

if (nvme_scan_topology(ctx, NULL, NULL)) {
nvme_free_global_ctx(ctx);
return EXIT_FAILURE;
}

nvme_for_each_host(ctx, h)
nvme_for_each_subsystem(h, s)
Expand Down
8 changes: 7 additions & 1 deletion libnvme/libnvme/nvme.i
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,14 @@ struct nvme_ns {
%extend nvme_global_ctx {
nvme_global_ctx(const char *config_file = NULL) {
struct nvme_global_ctx *ctx;
if (nvme_scan(config_file, &ctx))

ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL);
if (!ctx)
return NULL;

nvme_scan_topology(ctx, NULL, NULL);
nvme_read_config(ctx, config_file);

return ctx;
}
~nvme_global_ctx() {
Expand Down
1 change: 0 additions & 1 deletion libnvme/src/libnvme.ld
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ LIBNVME_2_0 {
nvme_release_fds;
nvme_rescan_ctrl;
nvme_revoke_tls_key;
nvme_scan;
nvme_scan_ctrl;
nvme_scan_ctrl_namespace_paths;
nvme_scan_ctrl_namespaces;
Expand Down
46 changes: 40 additions & 6 deletions libnvme/src/nvme/filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,37 +78,71 @@ int nvme_subsys_filter(const struct dirent *d)
int nvme_scan_subsystems(struct dirent ***subsys)
{
const char *dir = nvme_subsys_sysfs_dir();
int ret;

return scandir(dir, subsys, nvme_subsys_filter, alphasort);
ret = scandir(dir, subsys, nvme_subsys_filter, alphasort);
if (ret < 0)
return -errno;

return ret;
}

int nvme_scan_subsystem_namespaces(nvme_subsystem_t s, struct dirent ***ns)
{
return scandir(nvme_subsystem_get_sysfs_dir(s), ns,
int ret;

ret = scandir(nvme_subsystem_get_sysfs_dir(s), ns,
nvme_namespace_filter, alphasort);
if (ret < 0)
return -errno;

return ret;
}

int nvme_scan_ctrls(struct dirent ***ctrls)
{
const char *dir = nvme_ctrl_sysfs_dir();
int ret;

return scandir(dir, ctrls, nvme_ctrls_filter, alphasort);
ret = scandir(dir, ctrls, nvme_ctrls_filter, alphasort);
if (ret < 0)
return -errno;

return ret;
}

int nvme_scan_ctrl_namespace_paths(nvme_ctrl_t c, struct dirent ***paths)
{
return scandir(nvme_ctrl_get_sysfs_dir(c), paths,
int ret;

ret = scandir(nvme_ctrl_get_sysfs_dir(c), paths,
nvme_paths_filter, alphasort);
if (ret < 0)
return -errno;

return ret;
}

int nvme_scan_ctrl_namespaces(nvme_ctrl_t c, struct dirent ***ns)
{
return scandir(nvme_ctrl_get_sysfs_dir(c), ns,
int ret;

ret = scandir(nvme_ctrl_get_sysfs_dir(c), ns,
nvme_namespace_filter, alphasort);
if (ret < 0)
return -errno;

return ret;
}

int nvme_scan_ns_head_paths(nvme_ns_head_t head, struct dirent ***paths)
{
return scandir(nvme_ns_head_get_sysfs_dir(head), paths,
int ret;

ret = scandir(nvme_ns_head_get_sysfs_dir(head), paths,
nvme_paths_filter, alphasort);
if (ret < 0)
return -errno;

return ret;
}
12 changes: 6 additions & 6 deletions libnvme/src/nvme/filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int nvme_subsys_filter(const struct dirent *d);
* nvme_scan_subsystems() - Scan for subsystems
* @subsys: Pointer to array of dirents
*
* Return: number of entries in @subsys
* Return: number of entries in @subsys or a negative error code
*/
int nvme_scan_subsystems(struct dirent ***subsys);

Expand All @@ -64,15 +64,15 @@ int nvme_scan_subsystems(struct dirent ***subsys);
* @s: Subsystem to scan
* @ns: Pointer to array of dirents
*
* Return: number of entries in @ns
* Return: number of entries in @ns or a negative error code
*/
int nvme_scan_subsystem_namespaces(nvme_subsystem_t s, struct dirent ***ns);

/**
* nvme_scan_ctrls() - Scan for controllers
* @ctrls: Pointer to array of dirents
*
* Return: number of entries in @ctrls
* Return: number of entries in @ctrls or a negative error code
*/
int nvme_scan_ctrls(struct dirent ***ctrls);

Expand All @@ -81,7 +81,7 @@ int nvme_scan_ctrls(struct dirent ***ctrls);
* @c: Controller to scan
* @paths: Pointer to array of dirents
*
* Return: number of entries in @paths
* Return: number of entries in @paths or a negative error code
*/
int nvme_scan_ctrl_namespace_paths(nvme_ctrl_t c, struct dirent ***paths);

Expand All @@ -90,7 +90,7 @@ int nvme_scan_ctrl_namespace_paths(nvme_ctrl_t c, struct dirent ***paths);
* @c: Controller to scan
* @ns: Pointer to array of dirents
*
* Return: number of entries in @ns
* Return: number of entries in @ns or a negative error code
*/
int nvme_scan_ctrl_namespaces(nvme_ctrl_t c, struct dirent ***ns);

Expand All @@ -99,7 +99,7 @@ int nvme_scan_ctrl_namespaces(nvme_ctrl_t c, struct dirent ***ns);
* @head: Namespace head node to scan
* @paths : Pointer to array of dirents
*
* Return: number of entries in @ents
* Return: number of entries in @ents or a negative error code
*/
int nvme_scan_ns_head_paths(nvme_ns_head_t head, struct dirent ***paths);

Expand Down
6 changes: 4 additions & 2 deletions libnvme/src/nvme/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ static inline __u16 nvmf_exat_size(size_t val_len)
/**
* nvme_ns_get_transport_handle() - Get associated transport handle
* @n: Namespace instance
* @hdl: Transport handle
*
* libnvme will open() the file (if not already opened) and keep
* an internal copy of the link handle. Following calls to
Expand All @@ -747,9 +748,10 @@ static inline __u16 nvmf_exat_size(size_t val_len)
* remain cached until the ns object is deleted or
* nvme_ns_release_transport_handle() is called.
*
* Return: Link handle with @n or NULL
* Return: On success 0, else error code.
*/
struct nvme_transport_handle *nvme_ns_get_transport_handle(nvme_ns_t n);
int nvme_ns_get_transport_handle(nvme_ns_t n,
struct nvme_transport_handle **hdl);

/**
* nvme_ns_release_transport_handle() - Free transport handle from ns object
Expand Down
Loading
Loading