Skip to content

Commit b020730

Browse files
committed
fabrics: remove duplicate arguments from discover/connect
There a arguments which are already stored in the nvmf_context object, thus we can remove those. While at it, also remove the host lookup and configuring code to the library. Besides making the API more consistent it also more generic code to the library. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 0c978aa commit b020730

File tree

3 files changed

+136
-90
lines changed

3 files changed

+136
-90
lines changed

fabrics.c

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,10 @@ static int nvme_read_config_checked(struct nvme_global_ctx *ctx,
463463
int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)
464464
{
465465
char *config_file = PATH_NVMF_CONFIG;
466-
_cleanup_free_ char *hnqn = NULL;
467-
_cleanup_free_ char *hid = NULL;
468466
char *context = NULL;
469467
nvme_print_flags_t flags;
470468
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
471469
_cleanup_free_ struct nvmf_context *fctx = NULL;
472-
nvme_host_t h;
473470
unsigned int verbose = 0;
474471
int ret;
475472
char *format = "normal";
@@ -535,24 +532,12 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)
535532
return ret;
536533
}
537534

538-
ret = nvme_host_get_ids(ctx, fa.hostnqn, fa.hostid, &hnqn, &hid);
539-
if (ret < 0)
540-
return ret;
541-
542-
h = nvme_lookup_host(ctx, hnqn, hid);
543-
if (!h) {
544-
ret = -ENOMEM;
545-
goto out_free;
546-
}
547-
548535
if (device) {
549536
if (!strcmp(device, "none"))
550537
device = NULL;
551538
else if (!strncmp(device, "/dev/", 5))
552539
device += 5;
553540
}
554-
if (fa.hostkey)
555-
nvme_host_set_dhchap_key(h, fa.hostkey);
556541

557542
struct cb_fabrics_data dld = {
558543
.flags = flags,
@@ -566,25 +551,21 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)
566551
if (!device && !fa.transport && !fa.traddr) {
567552
if (!nonbft)
568553
ret = nvmf_discovery_nbft(ctx, fctx,
569-
fa.hostnqn, fa.hostid, hnqn, hid, connect,
570-
&cfg, nbft_path);
554+
connect, nbft_path);
571555
if (nbft)
572556
goto out_free;
573557

574558
if (json_config)
575559
ret = nvmf_discovery_config_json(ctx, fctx,
576-
fa.hostnqn, fa.hostid, connect, force);
560+
connect, force);
577561
if (ret || access(PATH_NVMF_DISC, F_OK))
578562
goto out_free;
579563

580-
ret = nvmf_discovery_config_file(ctx, fctx, h, connect, force);
564+
ret = nvmf_discovery_config_file(ctx, fctx, connect, force);
581565
goto out_free;
582566
}
583567

584-
if (!fa.trsvcid)
585-
fa.trsvcid = nvmf_get_default_trsvcid(fa.transport, true);
586-
587-
ret = nvmf_discovery(ctx, fctx, h, connect, force);
568+
ret = nvmf_discovery(ctx, fctx, connect, force);
588569

589570
out_free:
590571
if (dump_config)
@@ -630,7 +611,6 @@ int fabrics_connect(const char *desc, int argc, char **argv)
630611
unsigned int verbose = 0;
631612
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
632613
_cleanup_free_ struct nvmf_context *fctx = NULL;
633-
nvme_host_t h;
634614
_cleanup_nvme_ctrl_ nvme_ctrl_t c = NULL;
635615
int ret;
636616
nvme_print_flags_t flags;
@@ -704,22 +684,6 @@ int fabrics_connect(const char *desc, int argc, char **argv)
704684
return ret;
705685
}
706686

707-
ret = nvme_host_get_ids(ctx, fa.hostnqn, fa.hostid, &hnqn, &hid);
708-
if (ret < 0)
709-
return ret;
710-
711-
h = nvme_lookup_host(ctx, hnqn, hid);
712-
if (!h)
713-
return -ENOMEM;
714-
if (fa.hostkey)
715-
nvme_host_set_dhchap_key(h, fa.hostkey);
716-
if (!fa.trsvcid)
717-
fa.trsvcid = nvmf_get_default_trsvcid(fa.transport, false);
718-
719-
if (config_file)
720-
return nvmf_connect_config_json(ctx, fa.hostnqn,
721-
fa.hostid, &cfg);
722-
723687
struct cb_fabrics_data dld = {
724688
.flags = flags,
725689
.raw = raw,
@@ -729,7 +693,10 @@ int fabrics_connect(const char *desc, int argc, char **argv)
729693
if (ret)
730694
return ret;
731695

732-
ret = nvmf_connect(ctx, fctx, h);
696+
if (config_file)
697+
return nvmf_connect_config_json(ctx, fctx);
698+
699+
ret = nvmf_connect(ctx, fctx);
733700
if (ret) {
734701
fprintf(stderr, "failed to connected: %s\n",
735702
nvme_strerror(ret));

0 commit comments

Comments
 (0)