Page MenuHomeFreeBSD

D61569.1794767750.diff
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

D61569.1794767750.diff

diff --git a/lib/libnvmf/libnvmf.h b/lib/libnvmf/libnvmf.h
--- a/lib/libnvmf/libnvmf.h
+++ b/lib/libnvmf/libnvmf.h
@@ -128,6 +128,21 @@
bool nvmf_nqn_valid(const char *nqn);
bool nvmf_nqn_valid_strict(const char *nqn);
+/* Transport-specific APIs. */
+
+/*
+ * These TCP-specific queries are used by tests to verify if digests
+ * were negotiated and manually construct PDUs.
+ */
+size_t nvmf_tcp_max_icd(const struct nvmf_qpair *qp);
+uint32_t nvmf_tcp_maxh2cdata(const struct nvmf_qpair *qp);
+u_int nvmf_tcp_txpda(const struct nvmf_qpair *qp);
+bool nvmf_tcp_using_header_digests(const struct nvmf_qpair *qp);
+bool nvmf_tcp_using_data_digests(const struct nvmf_qpair *qp);
+
+/* Compute the digest for a TCP PDU data buffer. */
+uint32_t nvmf_tcp_compute_digest(const void *buf, size_t len);
+
/* Controller-specific APIs. */
/*
@@ -301,6 +316,13 @@
/* Return the CNTLID for a queue returned from CONNECT. */
uint16_t nvmf_cntlid(struct nvmf_qpair *qp);
+/*
+ * Return the command ID to use for the next command. This should
+ * only be used for transport-specific tests that manually construct
+ * and transmit command capsules.
+ */
+uint16_t nvmf_host_next_cid(struct nvmf_qpair *qp);
+
/*
* Send a command to the controller. This can fail with EBUSY if the
* submission queue is full.
diff --git a/lib/libnvmf/nvmf_host.c b/lib/libnvmf/nvmf_host.c
--- a/lib/libnvmf/nvmf_host.c
+++ b/lib/libnvmf/nvmf_host.c
@@ -199,6 +199,21 @@
return (qp->nq_cntlid);
}
+uint16_t
+nvmf_host_next_cid(struct nvmf_qpair *qp)
+{
+ uint16_t cid;
+
+ cid = htole16(qp->nq_cid);
+
+ /* 4.2 Skip CID of 0xFFFF. */
+ qp->nq_cid++;
+ if (qp->nq_cid == 0xFFFF)
+ qp->nq_cid = 0;
+
+ return (cid);
+}
+
int
nvmf_host_transmit_command(struct nvmf_capsule *nc)
{
@@ -211,12 +226,7 @@
if (new_sqtail == qp->nq_sqhd)
return (EBUSY);
- nc->nc_sqe.cid = htole16(qp->nq_cid);
-
- /* 4.2 Skip CID of 0xFFFF. */
- qp->nq_cid++;
- if (qp->nq_cid == 0xFFFF)
- qp->nq_cid = 0;
+ nc->nc_sqe.cid = nvmf_host_next_cid(qp);
error = nvmf_transmit_capsule(nc);
if (error != 0)
diff --git a/lib/libnvmf/nvmf_tcp.c b/lib/libnvmf/nvmf_tcp.c
--- a/lib/libnvmf/nvmf_tcp.c
+++ b/lib/libnvmf/nvmf_tcp.c
@@ -82,11 +82,12 @@
#define TCAP(nc) ((struct nvmf_tcp_capsule *)(nc))
#define CTCAP(nc) ((const struct nvmf_tcp_capsule *)(nc))
#define TQP(qp) ((struct nvmf_tcp_qpair *)(qp))
+#define CTQP(qp) ((const struct nvmf_tcp_qpair *)(qp))
static const char zero_padding[NVME_TCP_PDU_PDO_MAX_OFFSET];
-static uint32_t
-compute_digest(const void *buf, size_t len)
+uint32_t
+nvmf_tcp_compute_digest(const void *buf, size_t len)
{
return (calculate_crc32c(0xffffffff, buf, len) ^ 0xffffffff);
}
@@ -264,7 +265,7 @@
/* Check header digest if present. */
if ((ch->flags & NVME_TCP_CH_FLAGS_HDGSTF) != 0) {
- digest = compute_digest(ch, ch->hlen);
+ digest = nvmf_tcp_compute_digest(ch, ch->hlen);
memcpy(&rx_digest, (const char *)ch + ch->hlen,
sizeof(rx_digest));
if (digest != rx_digest) {
@@ -278,7 +279,8 @@
/* Check data digest if present. */
if ((ch->flags & NVME_TCP_CH_FLAGS_DDGSTF) != 0) {
- digest = compute_digest((const char *)ch + ch->pdo, data_len);
+ digest = nvmf_tcp_compute_digest((const char *)ch + ch->pdo,
+ data_len);
memcpy(&rx_digest, (const char *)ch + plen - sizeof(rx_digest),
sizeof(rx_digest));
if (digest != rx_digest) {
@@ -470,7 +472,7 @@
/* HDGST */
if (qp->header_digests) {
- header_digest = compute_digest(hdr, hlen);
+ header_digest = nvmf_tcp_compute_digest(hdr, hlen);
iov[iovcnt].iov_base = &header_digest;
iov[iovcnt].iov_len = sizeof(header_digest);
iovcnt++;
@@ -491,7 +493,7 @@
/* DDGST */
if (qp->data_digests) {
- data_digest = compute_digest(data, data_len);
+ data_digest = nvmf_tcp_compute_digest(data, data_len);
iov[iovcnt].iov_base = &data_digest;
iov[iovcnt].iov_len = sizeof(data_digest);
iovcnt++;
@@ -1519,3 +1521,48 @@
.receive_controller_data = tcp_receive_controller_data,
.send_controller_data = tcp_send_controller_data,
};
+
+size_t
+nvmf_tcp_max_icd(const struct nvmf_qpair *nq)
+{
+ const struct nvmf_tcp_qpair *qp = CTQP(nq);
+
+ assert(nq->nq_association->na_ops == &tcp_ops);
+ return (qp->max_icd);
+}
+
+uint32_t
+nvmf_tcp_maxh2cdata(const struct nvmf_qpair *nq)
+{
+ const struct nvmf_tcp_qpair *qp = CTQP(nq);
+
+ assert(nq->nq_association->na_ops == &tcp_ops);
+ return (qp->maxh2cdata);
+}
+
+u_int
+nvmf_tcp_txpda(const struct nvmf_qpair *nq)
+{
+ const struct nvmf_tcp_qpair *qp = CTQP(nq);
+
+ assert(nq->nq_association->na_ops == &tcp_ops);
+ return (qp->txpda);
+}
+
+bool
+nvmf_tcp_using_header_digests(const struct nvmf_qpair *nq)
+{
+ const struct nvmf_tcp_qpair *qp = CTQP(nq);
+
+ assert(nq->nq_association->na_ops == &tcp_ops);
+ return (qp->header_digests);
+}
+
+bool
+nvmf_tcp_using_data_digests(const struct nvmf_qpair *nq)
+{
+ const struct nvmf_tcp_qpair *qp = CTQP(nq);
+
+ assert(nq->nq_association->na_ops == &tcp_ops);
+ return (qp->data_digests);
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 15, 6:35 PM (20 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41746828
Default Alt Text
D61569.1794767750.diff (4 KB)

Event Timeline