Skip to content

Commit 1598b0f

Browse files
committed
fabris: add nvmf_context_free
Introduce function to release all resource associated to a fabrics context. This allows makes the opaque data structure more useful inside the library. Signed-off-by: Daniel Wagner <[email protected]>
1 parent b7cdfb1 commit 1598b0f

5 files changed

Lines changed: 28 additions & 5 deletions

File tree

fabrics.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static int create_common_context(struct nvme_global_ctx *ctx,
389389
return 0;
390390

391391
err:
392-
free(fctx);
392+
nvmf_context_free(fctx);
393393
return err;
394394
}
395395

@@ -425,7 +425,7 @@ static int create_discovery_context(struct nvme_global_ctx *ctx,
425425
return 0;
426426

427427
err:
428-
free(fctx);
428+
nvmf_context_free(fctx);
429429
return err;
430430
}
431431

@@ -480,7 +480,7 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)
480480
char *context = NULL;
481481
nvme_print_flags_t flags;
482482
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
483-
_cleanup_free_ struct nvmf_context *fctx = NULL;
483+
_cleanup_nvmf_context_ struct nvmf_context *fctx = NULL;
484484
int ret;
485485
struct nvme_fabrics_config cfg;
486486
struct nvmf_args fa = { .subsysnqn = NVME_DISC_SUBSYS_NAME };
@@ -592,7 +592,7 @@ int fabrics_connect(const char *desc, int argc, char **argv)
592592
char *config_file = NULL;
593593
char *context = NULL;
594594
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
595-
_cleanup_free_ struct nvmf_context *fctx = NULL;
595+
_cleanup_nvmf_context_ struct nvmf_context *fctx = NULL;
596596
_cleanup_nvme_ctrl_ nvme_ctrl_t c = NULL;
597597
int ret;
598598
nvme_print_flags_t flags;
@@ -931,7 +931,7 @@ int fabrics_config(const char *desc, int argc, char **argv)
931931
}
932932

933933
if (modify_config) {
934-
_cleanup_free_ struct nvmf_context *fctx = NULL;
934+
_cleanup_nvmf_context_ struct nvmf_context *fctx = NULL;
935935

936936
if (!fa.subsysnqn) {
937937
fprintf(stderr,

libnvme/src/libnvmf.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ LIBNVMF_3 {
1010
nvmf_connect_config_json;
1111
nvmf_connect_ctrl;
1212
nvmf_context_create;
13+
nvmf_context_free;
1314
nvmf_context_set_connection;
1415
nvmf_context_set_crypto;
1516
nvmf_context_set_device;

libnvme/src/nvme/fabrics.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ __public int nvmf_context_create(struct nvme_global_ctx *ctx,
214214
return 0;
215215
}
216216

217+
__public void nvmf_context_free(struct nvmf_context *fctx)
218+
{
219+
free(fctx);
220+
}
221+
217222
__public int nvmf_context_set_discovery_cbs(struct nvmf_context *fctx,
218223
void (*discovery_log)(struct nvmf_context *fctx,
219224
bool connect,

libnvme/src/nvme/fabrics.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,17 @@ int nvmf_context_create(struct nvme_global_ctx *ctx,
381381
const char *trsvcid, void *user_data),
382382
void *user_data, struct nvmf_context **fctxp);
383383

384+
/**
385+
* nvmf_context_free() - Free a fabrics context
386+
* @fctx: Fabrics context to free
387+
*
388+
* Releases all resources associated with @fctx. The context must have
389+
* been previously created with nvmf_context_create().
390+
*
391+
* After this call, @fctx must not be used.
392+
*/
393+
void nvmf_context_free(struct nvmf_context *fctx);
394+
384395
/**
385396
* nvmf_context_set_discovery_cbs() - Set discovery callbacks for context
386397
* @fctx: Fabrics context

util/cleanup.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ static inline void free_uri(struct nvme_fabrics_uri **uri)
5252
nvmf_free_uri(*uri);
5353
}
5454
#define _cleanup_uri_ __cleanup__(free_uri)
55+
56+
static inline void cleanup_nvmf_context(struct nvmf_context **fctx)
57+
{
58+
nvmf_context_free(*fctx);
59+
}
60+
#define _cleanup_nvmf_context_ __cleanup__(cleanup_nvmf_context)
5561
#endif
5662

5763
static inline DEFINE_CLEANUP_FUNC(cleanup_file, FILE *, fclose)

0 commit comments

Comments
 (0)