Skip to content

Commit 9859262

Browse files
committed
fabrics: move nbft code to the library
Move more discovery code to the library. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 633cc91 commit 9859262

10 files changed

Lines changed: 558 additions & 527 deletions

File tree

fabrics.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
#include "common.h"
4444
#include "nvme.h"
45-
#include "nbft.h"
4645
#include "nvme-print.h"
4746
#include "fabrics.h"
4847
#include "util/cleanup.h"
@@ -342,6 +341,32 @@ static bool nvmf_decide_retry(struct nvmf_discovery_ctx *dctx, int err,
342341
return false;
343342
}
344343

344+
static void nvmf_connected(struct nvmf_discovery_ctx *dctx,
345+
struct nvme_ctrl *c, void *user_data)
346+
{
347+
struct cb_discovery_log_data *dld = user_data;
348+
349+
if (dld->flags == NORMAL) {
350+
printf("device: %s\n", nvme_ctrl_get_name(c));
351+
return;
352+
}
353+
354+
#ifdef CONFIG_JSONC
355+
if (dld->flags == JSON) {
356+
struct json_object *root;
357+
358+
root = json_create_object();
359+
360+
json_object_add_value_string(root, "device",
361+
nvme_ctrl_get_name(c));
362+
363+
json_print_object(root, NULL);
364+
printf("\n");
365+
json_free_object(root);
366+
}
367+
#endif
368+
}
369+
345370
static int create_discovery_log_ctx(struct nvme_global_ctx *ctx,
346371
bool persistent,
347372
struct nvme_fabrics_config *defcfg,
@@ -374,6 +399,10 @@ static int create_discovery_log_ctx(struct nvme_global_ctx *ctx,
374399
if (err)
375400
goto err;
376401

402+
err = nvmf_discovery_ctx_connected_set(dctx, nvmf_connected);
403+
if (err)
404+
goto err;
405+
377406
err = nvmf_discovery_ctx_persistent_set(dctx, persistent);
378407
if (err)
379408
goto err;
@@ -544,6 +573,8 @@ static int nvme_read_config_checked(struct nvme_global_ctx *ctx,
544573
return nvme_read_config(ctx, filename);
545574
}
546575

576+
#define NBFT_SYSFS_PATH "/sys/firmware/acpi/tables"
577+
547578
/* returns negative errno values */
548579
int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
549580
{
@@ -654,12 +685,10 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
654685
return ret;
655686

656687
if (!device && !transport && !traddr) {
657-
nvmf_discovery_ctx_persistent_set(dctx, true);
658-
659688
if (!nonbft)
660-
ret = discover_from_nbft(ctx, hostnqn, hostid,
661-
hnqn, hid, desc, connect,
662-
&cfg, nbft_path, flags, verbose);
689+
ret = nvmf_discovery_nbft(ctx, dctx, hostnqn, hostid,
690+
hnqn, hid, connect,
691+
&cfg, nbft_path);
663692
if (nbft)
664693
goto out_free;
665694

libnvme/src/libnvme.map

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,15 @@ LIBNVME_2_0 {
295295
nvmf_discovery;
296296
nvmf_discovery_config_json;
297297
nvmf_discovery_ctx_already_connected_set;
298+
nvmf_discovery_ctx_connected_set;
298299
nvmf_discovery_ctx_create;
299300
nvmf_discovery_ctx_decide_retry_set;
300301
nvmf_discovery_ctx_default_fabrics_config_set;
301302
nvmf_discovery_ctx_discovery_log_set;
302303
nvmf_discovery_ctx_keep_alive_timeout;
303304
nvmf_discovery_ctx_max_retries;
304305
nvmf_discovery_ctx_persistent_set;
306+
nvmf_discovery_nbft;
305307
nvmf_eflags_str;
306308
nvmf_exat_ptr_next;
307309
nvmf_get_default_trsvcid;
@@ -313,6 +315,8 @@ LIBNVME_2_0 {
313315
nvmf_hostnqn_generate;
314316
nvmf_hostnqn_generate_from_hostid;
315317
nvmf_is_registration_supported;
318+
nvmf_nbft_free;
319+
nvmf_nbft_read_files;
316320
nvmf_prtype_str;
317321
nvmf_qptype_str;
318322
nvmf_register_ctrl;

libnvme/src/nvme/cleanup.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <sys/socket.h>
1111
#include <netdb.h>
1212

13+
#include "fabrics.h"
14+
1315
#define __cleanup__(fn) __attribute__((cleanup(fn)))
1416

1517
#define DECLARE_CLEANUP_FUNC(name, type) \
@@ -44,4 +46,11 @@ static inline void cleanup_fd(int *fd)
4446
static inline DEFINE_CLEANUP_FUNC(cleanup_addrinfo, struct addrinfo *, freeaddrinfo)
4547
#define _cleanup_addrinfo_ __cleanup__(cleanup_addrinfo)
4648

49+
static inline void free_uri(struct nvme_fabrics_uri **uri)
50+
{
51+
if (*uri)
52+
nvme_free_uri(*uri);
53+
}
54+
#define _cleanup_uri_ __cleanup__(free_uri)
55+
4756
#endif

0 commit comments

Comments
 (0)