diff --git a/sbin/nvmecontrol/devlist.c b/sbin/nvmecontrol/devlist.c --- a/sbin/nvmecontrol/devlist.c +++ b/sbin/nvmecontrol/devlist.c @@ -27,11 +27,13 @@ */ #include +#include #include #include #include #include +#include #include #include #include @@ -39,6 +41,7 @@ #include #include #include +#include #include #include "nvmecontrol.h" @@ -112,6 +115,30 @@ } } +static bool +fabrics_status(int fd) +{ + static struct timespec now; + static bool now_initted; + struct nvmf_connection_status cs; + struct timespec delta; + + if (nvmf_connection_status(fd, &cs) != 0) + return (true); + + if (cs.is_connected) + return (true); + + if (!now_initted) { + clock_gettime(CLOCK_REALTIME_FAST, &now); + now_initted = true; + } + + timespecsub(&now, &cs.last_disconnect, &delta); + printf(" (disconnected for %ju seconds)", (uintmax_t)delta.tv_sec); + return (false); +} + static bool scan_controller(int ctrlr) { @@ -121,6 +148,7 @@ uint8_t mn[64]; uint32_t nsid; int fd, ret; + bool connected; snprintf(name, sizeof(name), "%s%d", NVME_CTRLR_PREFIX, ctrlr); @@ -138,7 +166,13 @@ } nvme_strvis(mn, cdata.mn, sizeof(mn), NVME_MODEL_NUMBER_LENGTH); - printf("%6s: %s\n", name, mn); + printf("%6s: %s", name, mn); + connected = fabrics_status(fd); + printf("\n"); + if (!connected) { + close(fd); + return (true); + } nsid = 0; for (;;) {