From 1ac9ba3d4b0db57ec75098ce543ccc4bc7af3d59 Mon Sep 17 00:00:00 2001 From: Jesse Taube Date: Mon, 15 Jun 2026 16:19:48 -0400 Subject: [PATCH 1/2] fabrics: Use setup_common_context in create_common_context Simplify create_common_context by calling setup_common_context. Add to set_fabrics_options to setup_common_context as both callers call it after setup_common_context. Signed-off-by: Jesse Taube --- fabrics.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/fabrics.c b/fabrics.c index 1780df7fb0..efc6dd4f94 100644 --- a/fabrics.c +++ b/fabrics.c @@ -361,10 +361,6 @@ static int hook_parser_next_line(struct libnvmf_context *fctx, void *user_data) if (ret) return ret; - ret = set_fabrics_options(fctx, &fa); - if (ret) - return ret; - libnvmf_context_set_discovery_hooks(fctx, hook_discovery_log, hook_parser_init, hook_parser_cleanup, hook_parser_next_line); @@ -395,7 +391,7 @@ static int setup_common_context(struct libnvmf_context *fctx, if (err) return err; - return 0; + return set_fabrics_options(fctx, fa); } static int create_common_context(struct libnvme_global_ctx *ctx, @@ -410,17 +406,7 @@ static int create_common_context(struct libnvme_global_ctx *ctx, if (err) return err; - err = libnvmf_context_set_connection(fctx, fa->subsysnqn, - fa->transport, fa->traddr, fa->trsvcid, - fa->host_traddr, fa->host_iface); - if (err) - goto err; - - err = libnvmf_context_set_hostnqn(fctx, fa->hostnqn, fa->hostid); - if (err) - goto err; - - err = set_fabrics_options(fctx, fa); + err = setup_common_context(fctx, fa); if (err) goto err; From a68098a01021ce4c5927647ceaee484c3ac5ae20 Mon Sep 17 00:00:00 2001 From: Jesse Taube Date: Tue, 16 Jun 2026 11:30:52 -0400 Subject: [PATCH 2/2] fabrics: Use do-while instead of goto in next_line hook_parser_next_line used gotos to implement a do-while loop. Replace the gotos with a do-while loop to improve readability. Signed-off-by: Jesse Taube --- fabrics.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/fabrics.c b/fabrics.c index efc6dd4f94..de6a9fac93 100644 --- a/fabrics.c +++ b/fabrics.c @@ -334,25 +334,23 @@ static int hook_parser_next_line(struct libnvmf_context *fctx, void *user_data) OPT_FLAG("force", 0, &force, "Force persistent discovery controller creation")); memcpy(&fa, hfd->fa, sizeof(fa)); -next: - if (fgets(line, sizeof(line), hfd->f) == NULL) - return -EOF; + do { + if (fgets(line, sizeof(line), hfd->f) == NULL) + return -EOF; - if (line[0] == '#' || line[0] == '\n') - goto next; + if (line[0] == '#' || line[0] == '\n') + continue; - argc = 1; - p = line; - while ((ptr = strsep(&p, " =\n")) != NULL) - hfd->argv[argc++] = ptr; - hfd->argv[argc] = NULL; + argc = 1; + p = line; + while ((ptr = strsep(&p, " =\n")) != NULL) + hfd->argv[argc++] = ptr; + hfd->argv[argc] = NULL; - fa.subsysnqn = NVME_DISC_SUBSYS_NAME; - ret = argconfig_parse(argc, hfd->argv, "config", opts); - if (ret) - goto next; - if (!fa.transport && !fa.traddr) - goto next; + fa.subsysnqn = NVME_DISC_SUBSYS_NAME; + if (argconfig_parse(argc, hfd->argv, "config", opts)) + continue; + } while (!fa.transport && !fa.traddr); if (!fa.trsvcid) fa.trsvcid = libnvmf_get_default_trsvcid(fa.transport, true);