File 0005-tree-Factor-lookup-code-for-controller.patch of Package libnvme.27881
From: Daniel Wagner <dwagner@suse.de>
Date: Thu, 19 May 2022 10:44:24 +0200
Subject: tree: Factor lookup code for controller
Git-commit: c6611bb0962424f1cfbc528c2264bbbb5a0a661e
References: bsc#1199503
nvme_lookup_ctrl() will create a controller if it is not
found. In the case where we really just want the lookup
if a controller is in the tree we are missing a pure
lookup function. Hence factor out the lookup into a internal
function.
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
src/nvme/private.h | 5 +++++
src/nvme/tree.c | 34 ++++++++++++++++++++++++++--------
2 files changed, 31 insertions(+), 8 deletions(-)
--- a/src/nvme/private.h
+++ b/src/nvme/private.h
@@ -132,6 +132,11 @@ int json_update_config(nvme_root_t r, co
int json_dump_tree(nvme_root_t r);
+nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
+ const char *traddr, const char *host_traddr,
+ const char *host_iface, const char *trsvcid,
+ nvme_ctrl_t p);
+
#if (LOG_FUNCNAME == 1)
#define __nvme_log_func __func__
#else
--- a/src/nvme/tree.c
+++ b/src/nvme/tree.c
@@ -1018,17 +1018,14 @@ struct nvme_ctrl *nvme_create_ctrl(nvme_
return c;
}
-nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
- const char *traddr, const char *host_traddr,
- const char *host_iface, const char *trsvcid,
- nvme_ctrl_t p)
+nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
+ const char *traddr, const char *host_traddr,
+ const char *host_iface, const char *trsvcid,
+ nvme_ctrl_t p)
+
{
- nvme_root_t r;
struct nvme_ctrl *c;
- if (!s || !transport)
- return NULL;
- r = s->h ? s->h->r : NULL;
c = p ? nvme_subsystem_next_ctrl(s, p) : nvme_subsystem_first_ctrl(s);
for (; c != NULL; c = nvme_subsystem_next_ctrl(s, c)) {
if (strcmp(c->transport, transport))
@@ -1047,6 +1044,27 @@ nvme_ctrl_t nvme_lookup_ctrl(nvme_subsys
continue;
return c;
}
+
+ return NULL;
+}
+
+nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
+ const char *traddr, const char *host_traddr,
+ const char *host_iface, const char *trsvcid,
+ nvme_ctrl_t p)
+{
+ nvme_root_t r;
+ struct nvme_ctrl *c;
+
+ if (!s || !transport)
+ return NULL;
+
+ c = __nvme_lookup_ctrl(s, transport, traddr, host_traddr,
+ host_iface, trsvcid, p);
+ if (c)
+ return c;
+
+ r = s->h ? s->h->r : NULL;
c = nvme_create_ctrl(r, s->subsysnqn, transport, traddr,
host_traddr, host_iface, trsvcid);
if (c) {