Skip to content

Commit b23b99a

Browse files
committed
libnvme: embed libnvme_fabrics_config in libnvmf_context
libnvme_fabrics_config is going to be removed from the API. The first step is to let libnvmf_context own the configuration, coupling the fabrics config lifetime to the context object. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 96e369d commit b23b99a

3 files changed

Lines changed: 78 additions & 82 deletions

File tree

libnvme/libnvme/nvme.i

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -450,25 +450,19 @@ struct libnvmf_context {};
450450
%extend libnvmf_context {
451451
libnvmf_context(struct libnvme_global_ctx *ctx) {
452452
struct libnvmf_context *fctx;
453-
struct libnvme_fabrics_config *cfg;
453+
struct libnvme_fabrics_config cfg = {};
454454
int err;
455455

456456
err = libnvmf_context_create(ctx, NULL, NULL, NULL, NULL, &fctx);
457457
if (err)
458458
return NULL;
459459

460-
cfg = calloc(1, sizeof(*cfg));
461-
if (!cfg) {
462-
libnvmf_context_free(fctx);
463-
return NULL;
464-
}
465-
libnvmf_default_config(cfg);
466-
libnvmf_context_set_fabrics_config(fctx, cfg);
460+
libnvmf_default_config(&cfg);
461+
libnvmf_context_set_fabrics_config(fctx, &cfg);
467462

468463
return fctx;
469464
}
470465
~libnvmf_context() {
471-
free($self->cfg);
472466
libnvmf_context_free($self);
473467
}
474468
int fctx_set_hostnqn(const char *hostnqn, const char *hostid = NULL) {
@@ -492,8 +486,6 @@ struct libnvmf_context {};
492486
Py_ssize_t pos = 0;
493487
PyObject *key, *value;
494488

495-
if (!$self->cfg)
496-
return;
497489
if (!PyDict_Check(dict)) {
498490
PyErr_SetString(PyExc_TypeError,
499491
"set_fabrics_config: argument must be a dict");
@@ -502,50 +494,50 @@ struct libnvmf_context {};
502494

503495
while (PyDict_Next(dict, &pos, &key, &value)) {
504496
if (!PyUnicode_CompareWithASCIIString(key, "nr_io_queues")) {
505-
$self->cfg->nr_io_queues = PyLong_AsLong(value);
497+
$self->cfg.nr_io_queues = PyLong_AsLong(value);
506498
continue;
507499
}
508500
if (!PyUnicode_CompareWithASCIIString(key, "reconnect_delay")) {
509-
$self->cfg->reconnect_delay = PyLong_AsLong(value);
501+
$self->cfg.reconnect_delay = PyLong_AsLong(value);
510502
continue;
511503
}
512504
if (!PyUnicode_CompareWithASCIIString(key, "ctrl_loss_tmo")) {
513-
$self->cfg->ctrl_loss_tmo = PyLong_AsLong(value);
505+
$self->cfg.ctrl_loss_tmo = PyLong_AsLong(value);
514506
continue;
515507
}
516508
if (!PyUnicode_CompareWithASCIIString(key, "keep_alive_tmo")) {
517-
$self->cfg->keep_alive_tmo = PyLong_AsLong(value);
509+
$self->cfg.keep_alive_tmo = PyLong_AsLong(value);
518510
continue;
519511
}
520512
if (!PyUnicode_CompareWithASCIIString(key, "nr_write_queues")) {
521-
$self->cfg->nr_write_queues = PyLong_AsLong(value);
513+
$self->cfg.nr_write_queues = PyLong_AsLong(value);
522514
continue;
523515
}
524516
if (!PyUnicode_CompareWithASCIIString(key, "nr_poll_queues")) {
525-
$self->cfg->nr_poll_queues = PyLong_AsLong(value);
517+
$self->cfg.nr_poll_queues = PyLong_AsLong(value);
526518
continue;
527519
}
528520
if (!PyUnicode_CompareWithASCIIString(key, "tos")) {
529-
$self->cfg->tos = PyLong_AsLong(value);
521+
$self->cfg.tos = PyLong_AsLong(value);
530522
continue;
531523
}
532524
if (!PyUnicode_CompareWithASCIIString(key, "duplicate_connect")) {
533-
$self->cfg->duplicate_connect =
525+
$self->cfg.duplicate_connect =
534526
PyObject_IsTrue(value) ? true : false;
535527
continue;
536528
}
537529
if (!PyUnicode_CompareWithASCIIString(key, "disable_sqflow")) {
538-
$self->cfg->disable_sqflow =
530+
$self->cfg.disable_sqflow =
539531
PyObject_IsTrue(value) ? true : false;
540532
continue;
541533
}
542534
if (!PyUnicode_CompareWithASCIIString(key, "hdr_digest")) {
543-
$self->cfg->hdr_digest =
535+
$self->cfg.hdr_digest =
544536
PyObject_IsTrue(value) ? true : false;
545537
continue;
546538
}
547539
if (!PyUnicode_CompareWithASCIIString(key, "data_digest")) {
548-
$self->cfg->data_digest =
540+
$self->cfg.data_digest =
549541
PyObject_IsTrue(value) ? true : false;
550542
continue;
551543
}
@@ -777,7 +769,7 @@ struct libnvmf_context {};
777769
struct libnvmf_context *fctx = NULL) {
778770
int ret;
779771
const char *dev;
780-
const struct libnvme_fabrics_config *cfg = fctx ? fctx->cfg : NULL;
772+
const struct libnvme_fabrics_config *cfg = fctx ? &fctx->cfg : NULL;
781773

782774
dev = libnvme_ctrl_get_name($self);
783775
if (dev && !(cfg && cfg->duplicate_connect)) {

0 commit comments

Comments
 (0)