44#include "nvme.h"
55#include "plugin.h"
66#include "nvme-print.h"
7+ #include "common.h"
78
89#define CREATE_CMD
910#include "feat-nvme.h"
@@ -28,6 +29,7 @@ static const char *sel = "[0-3]: current/default/saved/supported";
2829static const char * save = "Specifies that the controller shall save the attribute" ;
2930static const char * perfc_feat = "performance characteristics feature" ;
3031static const char * hctm_feat = "host controlled thermal management feature" ;
32+ static const char * timestamp_feat = "timestamp feature" ;
3133
3234static int feat_get (struct nvme_dev * dev , const __u8 fid , __u32 cdw11 , __u8 sel , const char * feat )
3335{
@@ -315,3 +317,71 @@ static int feat_hctm(int argc, char **argv, struct command *cmd, struct plugin *
315317
316318 return err ;
317319}
320+
321+ static int timestamp_set (struct nvme_dev * dev , const __u8 fid , __u64 tstmp , bool save )
322+ {
323+ __u32 result ;
324+ int err ;
325+ struct nvme_timestamp ts ;
326+ __le64 timestamp = cpu_to_le64 (tstmp );
327+
328+ struct nvme_set_features_args args = {
329+ .args_size = sizeof (args ),
330+ .fd = dev_fd (dev ),
331+ .fid = fid ,
332+ .save = save ,
333+ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT ,
334+ .result = & result ,
335+ .data = & ts ,
336+ .data_len = sizeof (ts ),
337+ };
338+
339+ memcpy (ts .timestamp , & timestamp , sizeof (ts .timestamp ));
340+
341+ err = nvme_set_features (& args );
342+
343+ nvme_show_init ();
344+
345+ if (err > 0 ) {
346+ nvme_show_status (err );
347+ } else if (err < 0 ) {
348+ nvme_show_perror ("Set %s" , timestamp_feat );
349+ } else {
350+ nvme_show_result ("Set %s: (%s)" , timestamp_feat , save ? "Save" : "Not save" );
351+ nvme_feature_show_fields (fid , args .cdw11 , args .data );
352+ }
353+
354+ nvme_show_finish ();
355+
356+ return err ;
357+ }
358+
359+ static int feat_timestamp (int argc , char * * argv , struct command * cmd , struct plugin * plugin )
360+ {
361+ const __u8 fid = NVME_FEAT_FID_TIMESTAMP ;
362+ const char * tstmp = "timestamp" ;
363+
364+ _cleanup_nvme_dev_ struct nvme_dev * dev = NULL ;
365+ int err ;
366+
367+ struct config {
368+ __u64 tstmp ;
369+ bool save ;
370+ __u8 sel ;
371+ };
372+
373+ struct config cfg = { 0 };
374+
375+ FEAT_ARGS (opts , OPT_LONG ("tstmp" , 't' , & cfg .tstmp , tstmp ));
376+
377+ err = parse_and_open (& dev , argc , argv , TIMESTAMP_DESC , opts );
378+ if (err )
379+ return err ;
380+
381+ if (argconfig_parse_seen (opts , "tstmp" ))
382+ err = timestamp_set (dev , fid , cfg .tstmp , cfg .save );
383+ else
384+ err = feat_get (dev , fid , 0 , cfg .sel , timestamp_feat );
385+
386+ return err ;
387+ }
0 commit comments