Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177841836
D61852.1795410051.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
D61852.1795410051.diff
View Options
diff --git a/sys/dev/nvmf/controller/nvmft_controller.c b/sys/dev/nvmf/controller/nvmft_controller.c
--- a/sys/dev/nvmf/controller/nvmft_controller.c
+++ b/sys/dev/nvmf/controller/nvmft_controller.c
@@ -433,9 +433,6 @@
/* If the controller has been re-enabled, nothing to do. */
mtx_lock(&ctrlr->lock);
if (NVMEV(NVME_CC_REG_EN, ctrlr->cc) != 0) {
- if (ctrlr->ka_sbt != 0)
- callout_schedule_sbt(&ctrlr->ka_timer, ctrlr->ka_sbt, 0,
- C_HARDCLOCK);
mtx_unlock(&ctrlr->lock);
return;
}
@@ -1221,6 +1218,17 @@
cancel_terminate = true;
ctrlr->csts &= ~NVMEM(NVME_CSTS_REG_SHST);
ctrlr->csts |= NVMEF(NVME_CSTS_REG_RDY, 1);
+
+ /*
+ * If the KeepAlive timer was stopped by a
+ * prior shutdown or reset, restart it now.
+ */
+ if (ctrlr->ka_sbt != 0 &&
+ !callout_active(&ctrlr->ka_timer)) {
+ callout_reset_sbt(&ctrlr->ka_timer,
+ ctrlr->ka_sbt, 0, nvmft_keep_alive_timer,
+ ctrlr, C_HARDCLOCK);
+ }
}
}
diff --git a/tests/sys/cam/ctl/nvmft/nvmft.c b/tests/sys/cam/ctl/nvmft/nvmft.c
--- a/tests/sys/cam/ctl/nvmft/nvmft.c
+++ b/tests/sys/cam/ctl/nvmft/nvmft.c
@@ -1577,6 +1577,80 @@
nvmf_free_qpair(admin);
}
+ATF_TC(keepalive_timeout_after_reenable);
+ATF_TC_HEAD(keepalive_timeout_after_reenable, tc)
+{
+ require_nvmft(tc);
+}
+ATF_TC_BODY(keepalive_timeout_after_reenable, tc)
+{
+ struct nvmf_qpair_params qparams;
+ struct nvmf_association *na;
+ struct nvmf_qpair *admin;
+ struct nvmf_capsule *cc, *rc;
+ char hostnqn[NVMF_NQN_MAX_LEN];
+ uint8_t hostid[16];
+ useconds_t delay;
+ uint32_t kato, kato_after;
+ int error;
+
+ init_hostid(hostid, hostnqn);
+
+ na = create_association(tc);
+
+ memset(&qparams, 0, sizeof(qparams));
+ qparams.admin = true;
+ qparams.tcp.fd = open_socket(tc, NULL, NULL);
+
+ /* Request a keep alive timeout of 100ms. */
+ admin = connect_admin_queue(tc, na, &qparams, hostid, hostnqn, 100);
+ if (admin == NULL)
+ atf_tc_fail("Failed to create admin queue: %s",
+ nvmf_association_error(na));
+ nvmf_free_association(na);
+
+ /* Query the actual KATO after rounding. */
+ kato = get_simple_feature(admin, NVME_FEAT_KEEP_ALIVE_TIMER);
+ ATF_REQUIRE(kato >= 100);
+
+ /* Shutdown and wait for the shutdown to complete. */
+ shutdown_controller(admin);
+ wait_for_shutdown(admin);
+
+ /* Re-enable the controller. */
+ enable_controller(admin);
+
+ /* Verify the KATO is the same. */
+ kato_after = get_simple_feature(admin, NVME_FEAT_KEEP_ALIVE_TIMER);
+ ATF_REQUIRE(kato == kato_after);
+
+ /*
+ * Similar to the previous test, wait for at least two and a
+ * half timeouts to ensure timeout expiration.
+ */
+ delay = kato * 5 / 2;
+ if (delay < 500)
+ delay = 500;
+ usleep(delay * 1000);
+
+ /* Try to send a keep alive command. */
+ cc = nvmf_keepalive(admin);
+ ATF_REQUIRE(cc != NULL);
+
+ /*
+ * This send can succeed as only the remote host has closed
+ * the connection at this point, but the receive should
+ * definitely fail.
+ */
+ error = nvmf_host_transmit_command(cc);
+ if (error == 0)
+ error = nvmf_host_wait_for_response(cc, &rc);
+ ATF_REQUIRE(error == ECONNRESET);
+
+ nvmf_free_capsule(cc);
+ nvmf_free_qpair(admin);
+}
+
static void
nvmf_init_read_sqe(void *sqe, uint32_t nsid, uint64_t lba, u_int nlb)
{
@@ -2047,6 +2121,7 @@
ATF_TP_ADD_TC(tp, get_kato);
ATF_TP_ADD_TC(tp, get_hostid);
ATF_TP_ADD_TC(tp, keepalive_timeout);
+ ATF_TP_ADD_TC(tp, keepalive_timeout_after_reenable);
ATF_TP_ADD_TC(tp, read_block);
ATF_TP_ADD_TC(tp, compare_block);
ATF_TP_ADD_TC(tp, compare_mismatch);
diff --git a/tests/sys/cam/ctl/nvmft/nvmft_subr.h b/tests/sys/cam/ctl/nvmft/nvmft_subr.h
--- a/tests/sys/cam/ctl/nvmft/nvmft_subr.h
+++ b/tests/sys/cam/ctl/nvmft/nvmft_subr.h
@@ -16,6 +16,7 @@
const struct nvmf_qpair_params *params, const uint8_t hostid[16],
const char *hostnqn);
struct nvmf_association *create_association(const atf_tc_t *tc);
+void enable_controller(struct nvmf_qpair *qp);
void init_hostid(uint8_t hostid[16], char hostnqn[NVMF_NQN_MAX_LEN]);
int open_socket(const atf_tc_t *tc, struct addrinfo **aip,
struct addrinfo **listp);
@@ -27,5 +28,6 @@
void shutdown_controller(struct nvmf_qpair *qp);
u_int validate_namespace(const atf_tc_t *tc, struct nvmf_qpair *qp,
u_int *block_size);
+void wait_for_shutdown(struct nvmf_qpair *qp);
#endif /* !__NVMFT_SUBR_H__ */
diff --git a/tests/sys/cam/ctl/nvmft/nvmft_subr.c b/tests/sys/cam/ctl/nvmft/nvmft_subr.c
--- a/tests/sys/cam/ctl/nvmft/nvmft_subr.c
+++ b/tests/sys/cam/ctl/nvmft/nvmft_subr.c
@@ -148,9 +148,6 @@
{
struct nvmf_qpair *qp;
const char *subnqn;
- uint64_t cap, cc, csts;
- u_int mps, mpsmin, mpsmax;
- int error, timo;
uint16_t cntlid;
cntlid = parse_cntlid(tc);
@@ -160,6 +157,17 @@
if (qp == NULL)
return (NULL);
+ enable_controller(qp);
+ return (qp);
+}
+
+void
+enable_controller(struct nvmf_qpair *qp)
+{
+ uint64_t cap, cc, csts;
+ u_int mps, mpsmin, mpsmax;
+ int error, timo;
+
/* Fetch Controller Capabilities Property */
error = nvmf_read_property(qp, NVMF_PROP_CAP, 8, &cap);
if (error != 0)
@@ -217,8 +225,6 @@
timo--;
usleep(500 * 1000);
}
-
- return (qp);
}
void
@@ -239,6 +245,34 @@
strerror(error));
}
+void
+wait_for_shutdown(struct nvmf_qpair *qp)
+{
+ uint64_t cap, csts;
+ int error, timo;
+
+ error = nvmf_read_property(qp, NVMF_PROP_CAP, 8, &cap);
+ if (error != 0)
+ atf_tc_fail("Failed to fetch CAP: %s", strerror(error));
+
+ /* Wait for CSTS.RDY == 0 in Controller Status */
+ timo = NVME_CAP_LO_TO(cap);
+ for (;;) {
+ error = nvmf_read_property(qp, NVMF_PROP_CSTS, 4, &csts);
+ if (error != 0)
+ atf_tc_fail("Failed to fetch CSTS: %s",
+ strerror(error));
+
+ if (NVMEV(NVME_CSTS_REG_RDY, csts) == 0)
+ break;
+
+ if (timo == 0)
+ atf_tc_fail("Controller failed to shutdown");
+ timo--;
+ usleep(500 * 1000);
+ }
+}
+
void
require_nvm(struct nvmf_qpair *qp)
{
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 23, 5:00 AM (14 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41923283
Default Alt Text
D61852.1795410051.diff (5 KB)
Attached To
Mode
D61852: nvmft: Restart the KeepAlive timer when a controller is re-enabled
Attached
Detach File
Event Timeline