Page MenuHomeFreeBSD

D61631.1795167461.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D61631.1795167461.diff

diff --git a/sbin/camcontrol/camcontrol.8 b/sbin/camcontrol/camcontrol.8
--- a/sbin/camcontrol/camcontrol.8
+++ b/sbin/camcontrol/camcontrol.8
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 21, 2026
+.Dd November 13, 2026
.Dt CAMCONTROL 8
.Os
.Sh NAME
@@ -2892,9 +2892,11 @@
.Pp
Host memory buffer.
.It Cm timestamp
-(not yet implemented)
-.Pp
-Timestamp.
+Timestamp
+.Pq get only .
+Prints the controller's time and whether it was set by the host or has
+counted from the last controller reset, and whether it may have stopped
+counting while the controller was in a non-operational power state.
.It Cm keepalive
(not yet implemented)
.Pp
diff --git a/sbin/camcontrol/nvfeature.c b/sbin/camcontrol/nvfeature.c
--- a/sbin/camcontrol/nvfeature.c
+++ b/sbin/camcontrol/nvfeature.c
@@ -33,6 +33,7 @@
* NVMe Feature support for camcontrol(8).
*/
+#include <sys/param.h>
#include <sys/endian.h>
#include <sys/stdint.h>
#include <sys/types.h>
@@ -45,6 +46,7 @@
#include <stdlib.h>
#include <string.h>
#include <strings.h>
+#include <time.h>
#include <unistd.h>
#include <uuid.h>
@@ -346,6 +348,80 @@
return error;
}
+static int
+nvmefeature_get_timestamp(struct cam_device *device, int sel, int verbosemode,
+ int err_recover, int retry_count, int timeout)
+{
+ struct nvme_timestamp_data ts;
+ union ccb *ccb;
+ uint64_t ms;
+ time_t secs;
+ char buf[32];
+ int error = 0;
+
+ if (!nvfeature_validate_select(sel))
+ return (1);
+
+ ccb = cam_getccb(device);
+ if (ccb == NULL) {
+ warnx("%s: error allocating CCB", __func__);
+ return (1);
+ }
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
+
+ bzero(&ts, sizeof(ts));
+ nvme_get_feature(&ccb->nvmeio, retry_count, NULL, 0, sel,
+ NVME_FEAT_TIMESTAMP, 0, 0, (uint8_t *)&ts, sizeof(ts), timeout);
+
+ if (err_recover != 0)
+ ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
+
+ if (cam_send_ccb(device, ccb) < 0) {
+ warnx("%s: error sending NVMe Get Feature", __func__);
+ error = 1;
+ goto bailout;
+ }
+ if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+ if (verbosemode != 0)
+ cam_error_print(device, ccb, CAM_ESF_ALL, CAM_EPF_ALL,
+ stderr);
+ error = 1;
+ goto bailout;
+ }
+
+ if (sel == NVME_FEAT_SEL_CAPABILITIES) {
+ error = nvfeature_print_caps(ccb, "Timestamp capabilities:");
+ goto bailout;
+ }
+
+ ms = 0;
+ for (size_t i = 0; i < nitems(ts.tstmp); i++)
+ ms |= (uint64_t)ts.tstmp[i] << (i * 8);
+ secs = ms / 1000;
+ strftime(buf, sizeof(buf), "%F %T", gmtime(&secs));
+ printf("Timestamp (%s): %ju ms (%s.%03ju UTC)\n",
+ nvfeature_select_to_str[sel], (uintmax_t)ms, buf,
+ (uintmax_t)(ms % 1000));
+ switch (NVMEV(NVME_TIMESTAMP_TSTMPS_ORIGIN, ts.tstmps)) {
+ case NVME_TIMESTAMP_ORIGIN_RESET:
+ printf(" Origin: cleared by a controller reset\n");
+ break;
+ case NVME_TIMESTAMP_ORIGIN_SET_FEATURES:
+ printf(" Origin: set by the host\n");
+ break;
+ default:
+ printf(" Origin: reserved (%u)\n",
+ NVMEV(NVME_TIMESTAMP_TSTMPS_ORIGIN, ts.tstmps));
+ break;
+ }
+ printf(" Synch: %s\n", NVMEV(NVME_TIMESTAMP_TSTMPS_SYNCH,
+ ts.tstmps) != 0 ? "may have stopped counting" : "continuous");
+
+bailout:
+ free(ccb);
+ return (error);
+}
+
static int
nvmefeature_set_hostid(struct cam_device *device, int save, int verbosemode,
int err_recover, char *hostid_str,
@@ -533,6 +609,10 @@
verbosemode, err_recover, output_uuid,
retry_count, timeout);
break;
+ case NVME_FEAT_TIMESTAMP:
+ error = nvmefeature_get_timestamp(device, s,
+ verbosemode, err_recover, retry_count, timeout);
+ break;
default:
warnx("%s: get feature %s not yet implemented",
__func__, feature->name);

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 20, 9:37 AM (21 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41864963
Default Alt Text
D61631.1795167461.diff (3 KB)

Event Timeline