Skip to content

Commit a994a52

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 f41bf84 commit a994a52

10 files changed

Lines changed: 547 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"
@@ -341,6 +340,32 @@ static bool nvmf_decide_retry(struct nvmf_discovery_ctx *dctx, int err,
341340
return false;
342341
}
343342

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

401+
err = nvmf_discovery_ctx_connected_set(dctx, nvmf_connected);
402+
if (err)
403+
goto err;
404+
376405
err = nvmf_discovery_ctx_persistent_set(dctx, persistent);
377406
if (err)
378407
goto err;
@@ -543,6 +572,8 @@ static int nvme_read_config_checked(struct nvme_global_ctx *ctx,
543572
return nvme_read_config(ctx, filename);
544573
}
545574

575+
#define NBFT_SYSFS_PATH "/sys/firmware/acpi/tables"
576+
546577
/* returns negative errno values */
547578
int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
548579
{
@@ -653,12 +684,10 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
653684
return ret;
654685

655686
if (!device && !transport && !traddr) {
656-
nvmf_discovery_ctx_persistent_set(dctx, true);
657-
658687
if (!nonbft)
659-
ret = discover_from_nbft(ctx, hostnqn, hostid,
660-
hnqn, hid, desc, connect,
661-
&cfg, nbft_path, flags, verbose);
688+
ret = nvmf_discovery_nbft(ctx, dctx, hostnqn, hostid,
689+
hnqn, hid, connect,
690+
&cfg, nbft_path);
662691
if (nbft)
663692
goto out_free;
664693

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)