Skip to content

Commit

Permalink
tree: optionally skip namespaces during scanning
Browse files Browse the repository at this point in the history
Add a flag 'create_only' to nvme_root_t to skip namespaces
during scanning.

Signed-off-by: Hannes Reinecke <[email protected]>
  • Loading branch information
hreinecke authored and igaw committed Jun 7, 2024
1 parent fa0f82c commit a7d7e1d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libnvme.map
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
LIBNVME_1.10 {
global:
nvme_free_uri;
nvme_init_default_logging;
nvme_parse_uri;
nvme_free_uri;
nvme_root_skip_namespaces;
nvmf_hostid_generate;
nvmf_hostnqn_generate_from_hostid;
};
Expand Down
1 change: 1 addition & 0 deletions src/nvme/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ struct nvme_root {
struct nvme_log log;
bool modified;
bool mi_probe_enabled;
bool create_only;
struct nvme_fabric_options *options;
};

Expand Down
21 changes: 21 additions & 0 deletions src/nvme/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ void nvme_root_set_application(nvme_root_t r, const char *a)
r->application = strdup(a);
}

void nvme_root_skip_namespaces(nvme_root_t r)
{
r->create_only = true;
}

nvme_host_t nvme_first_host(nvme_root_t r)
{
return list_top(&r->hosts, struct nvme_host, entry);
Expand Down Expand Up @@ -644,6 +649,12 @@ static int nvme_subsystem_scan_namespaces(nvme_root_t r, nvme_subsystem_t s,
_cleanup_dirents_ struct dirents namespaces = {};
int i, ret;

if (r->create_only) {
nvme_msg(r, LOG_DEBUG,
"skipping namespace scan for subsys %s\n",
s->subsysnqn);
return 0;
}
namespaces.num = nvme_scan_subsystem_namespaces(s, &namespaces.ents);
if (namespaces.num < 0) {
nvme_msg(r, LOG_DEBUG,
Expand Down Expand Up @@ -1676,6 +1687,11 @@ static int nvme_ctrl_scan_paths(nvme_root_t r, struct nvme_ctrl *c)
_cleanup_dirents_ struct dirents paths = {};
int i;

if (r->create_only) {
nvme_msg(r, LOG_DEBUG,
"skipping path scan for ctrl %s\n", c->name);
return 0;
}
paths.num = nvme_scan_ctrl_namespace_paths(c, &paths.ents);
if (paths.num < 0)
return paths.num;
Expand All @@ -1691,6 +1707,11 @@ static int nvme_ctrl_scan_namespaces(nvme_root_t r, struct nvme_ctrl *c)
_cleanup_dirents_ struct dirents namespaces = {};
int i;

if (r->create_only) {
nvme_msg(r, LOG_DEBUG, "skipping namespace scan for ctrl %s\n",
c->name);
return 0;
}
namespaces.num = nvme_scan_ctrl_namespaces(c, &namespaces.ents);
for (i = 0; i < namespaces.num; i++)
nvme_ctrl_scan_namespace(r, c, namespaces.ents[i]->d_name);
Expand Down
8 changes: 8 additions & 0 deletions src/nvme/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ void nvme_root_set_application(nvme_root_t r, const char *a);
*/
const char *nvme_root_get_application(nvme_root_t r);

/**
* nvme_root_skip_namespaces - Skip namespace scanning
* @r: &nvme_root_t object
*
* Sets a flag to skip namespaces during scanning.
*/
void nvme_root_skip_namespaces(nvme_root_t r);

/**
* nvme_root_release_fds - Close all opened file descriptors in the tree
* @r: &nvme_root_t object
Expand Down

0 comments on commit a7d7e1d

Please sign in to comment.