[PATCH 1/1 libnvme] fabrics: add support for new cli --skip-cid-gen flag

Max Gurtovoy
2021-11-08T14:48:00Z

Setting this flag will enable NVME_QUIRK_SKIP_CID_GEN quirk and will
actually add the ability to ignore the command id generation for
other transport alongside PCI transport that is possible today.

Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
---
doc/libnvme.rst | 3 +++
examples/discover-loop.c | 2 +-
pynvme/nvme.i | 2 ++
src/nvme/fabrics.c | 10 +++++++---
src/nvme/fabrics.h | 4 +++-
src/nvme/tree.c | 7 +++++++
src/nvme/tree.h | 9 +++++++++
7 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/doc/libnvme.rst b/doc/libnvme.rst
index d52462f..e2555f9 100644
--- a/doc/libnvme.rst
+++ b/doc/libnvme.rst
@@ -11435,6 +11435,7 @@ errno set otherwise.
bool disable_sqflow;
bool hdr_digest;
bool data_digest;
+ bool skip_cid_gen;
};

**Members**
@@ -11496,6 +11497,8 @@ errno set otherwise.
``data_digest``
Generate/verify data digest (TCP)

+``skip_cid_gen``
+ Skip command id generation control

.. c:function:: int nvmf_add_ctrl_opts (struct nvme_fabrics_config * cfg)
diff --git a/examples/discover-loop.c b/examples/discover-loop.c
index c2a2385..66e9d8b 100644
--- a/examples/discover-loop.c
+++ b/examples/discover-loop.c
@@ -70,7 +70,7 @@ int main()
fprintf(stderr, "Failed to allocate memory\n");
return ENOMEM;
}
- ret = nvmf_add_ctrl(h, c, &cfg, false);
+ ret = nvmf_add_ctrl(h, c, &cfg, false, false);
if (ret < 0) {
fprintf(stderr, "no controller found\n");
return errno;
diff --git a/pynvme/nvme.i b/pynvme/nvme.i
index 4c45a04..cfa0a44 100644
--- a/pynvme/nvme.i
+++ b/pynvme/nvme.i
@@ -145,6 +145,8 @@ static int discover_err = 0;
temp.hdr_digest = PyObject_IsTrue(value) ? true : false;
if (!PyUnicode_CompareWithASCIIString(key, "data_digest"))
temp.data_digest = PyObject_IsTrue(value) ? true : false;
+ if (!PyUnicode_CompareWithASCIIString(key, "skip_cid_gen"))
+ temp.skip_cid_gen = PyObject_IsTrue(value) ? true : false;
}
$1 = &temp;
};
diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c
index 94cecd0..2005dc4 100644
--- a/src/nvme/fabrics.c
+++ b/src/nvme/fabrics.c
@@ -162,6 +162,7 @@ static struct nvme_fabrics_config *merge_config(nvme_ctrl_t c,
UPDATE_CFG_OPTION(ctrl_cfg, cfg, disable_sqflow, false);
UPDATE_CFG_OPTION(ctrl_cfg, cfg, hdr_digest, false);
UPDATE_CFG_OPTION(ctrl_cfg, cfg, data_digest, false);
+ UPDATE_CFG_OPTION(ctrl_cfg, cfg, skip_cid_gen, false);

return ctrl_cfg;
}
@@ -445,6 +446,8 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
cfg->duplicate_connect) ||
add_bool_argument(argstr, "disable_sqflow",
cfg->disable_sqflow) ||
+ add_bool_argument(argstr, "skip_cid_gen",
+ cfg->skip_cid_gen) ||
(!strcmp(transport, "tcp") &&
add_bool_argument(argstr, "hdr_digest", cfg->hdr_digest)) ||
(!strcmp(transport, "tcp") &&
@@ -531,13 +534,14 @@ int nvmf_add_ctrl_opts(nvme_ctrl_t c, struct nvme_fabrics_config *cfg)

int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c,
const struct nvme_fabrics_config *cfg,
- bool disable_sqflow)
+ bool disable_sqflow, bool skip_cid_gen)
{
char *argstr;
int ret;

cfg = merge_config(c, cfg);
nvme_ctrl_disable_sqflow(c, disable_sqflow);
+ nvme_ctrl_skip_cid_gen(c, skip_cid_gen);
nvme_ctrl_set_discovered(c, true);
if (traddr_is_hostname(c)) {
ret = hostname2traddr(c);
@@ -644,7 +648,7 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h,
if (e->treq & NVMF_TREQ_DISABLE_SQFLOW)
disable_sqflow = true;

- ret = nvmf_add_ctrl(h, c, cfg, disable_sqflow);
+ ret = nvmf_add_ctrl(h, c, cfg, disable_sqflow, false);
if (!ret)
return c;

@@ -654,7 +658,7 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h,
nvme_msg(LOG_INFO, "failed to connect controller, "
"retry with disabling SQ flow control\n");
disable_sqflow = false;
- ret = nvmf_add_ctrl(h, c, cfg, disable_sqflow);
+ ret = nvmf_add_ctrl(h, c, cfg, disable_sqflow, false);
if (!ret)
return c;
}
diff --git a/src/nvme/fabrics.h b/src/nvme/fabrics.h
index 9b796be..e9e4b21 100644
--- a/src/nvme/fabrics.h
+++ b/src/nvme/fabrics.h
@@ -31,6 +31,7 @@
* @disable_sqflow: Disable controller sq flow control
* @hdr_digest: Generate/verify header digest (TCP)
* @data_digest: Generate/verify data digest (TCP)
+ * @skip_cid_gen: Skip command id generation control
*/
struct nvme_fabrics_config {
int queue_size;
@@ -47,6 +48,7 @@ struct nvme_fabrics_config {
bool disable_sqflow;
bool hdr_digest;
bool data_digest;
+ bool skip_cid_gen;
};

/**
@@ -133,7 +135,7 @@ int nvmf_add_ctrl_opts(nvme_ctrl_t c, struct nvme_fabrics_config *cfg);
*/
int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c,
const struct nvme_fabrics_config *cfg,
- bool disable_sqflow);
+ bool disable_sqflow, bool skip_cid_gen);

/**
* nvmf_get_discovery_log() -
diff --git a/src/nvme/tree.c b/src/nvme/tree.c
index 0f72320..df1ac31 100644
--- a/src/nvme/tree.c
+++ b/src/nvme/tree.c
@@ -700,6 +700,13 @@ void nvme_ctrl_disable_sqflow(nvme_ctrl_t c, bool disable_sqflow)
c->s->h->r->modified = true;
}

+void nvme_ctrl_skip_cid_gen(nvme_ctrl_t c, bool skip_cid_gen)
+{
+ c->cfg.skip_cid_gen = skip_cid_gen;
+ if (c->s && c->s->h && c->s->h->r)
+ c->s->h->r->modified = true;
+}
+
void nvme_ctrl_set_discovered(nvme_ctrl_t c, bool discovered)
{
c->discovered = discovered;
diff --git a/src/nvme/tree.h b/src/nvme/tree.h
index f9e7d37..c819556 100644
--- a/src/nvme/tree.h
+++ b/src/nvme/tree.h
@@ -822,6 +822,15 @@ bool nvme_ctrl_is_persistent(nvme_ctrl_t c);
*/
void nvme_ctrl_disable_sqflow(nvme_ctrl_t c, bool disable_sqflow);

+/**
+ * nvme_ctrl_skip_cid_gen() -
+ * @c:
+ * @skip_cid_gen:
+ *
+ * Return:
+ */
+void nvme_ctrl_skip_cid_gen(nvme_ctrl_t c, bool skip_cid_gen);
+
/**
* nvme_ctrl_identify() -
* @c:
--
2.18.1