@@ -5565,6 +5565,88 @@ static int sanitize_cmd(int argc, char **argv, struct command *acmd, struct plug
55655565 return err ;
55665566}
55675567
5568+ static int sanitize_ns_cmd (int argc , char * * argv , struct command * acmd ,
5569+ struct plugin * plugin )
5570+ {
5571+ const char * desc = "Send a sanitize namespace command." ;
5572+ const char * emvs_desc = "Enter media verification state." ;
5573+ const char * ause_desc = "Allow unrestricted sanitize exit." ;
5574+ const char * sanact_desc = "Sanitize action: 1 = Exit failure mode, "
5575+ "4 = Start a crypto erase namespace sanitize operation, "
5576+ "5 = Exit media verification state" ;
5577+
5578+ _cleanup_nvme_transport_handle_ struct nvme_transport_handle * hdl = NULL ;
5579+ _cleanup_nvme_global_ctx_ struct nvme_global_ctx * ctx = NULL ;
5580+ struct nvme_passthru_cmd cmd ;
5581+ nvme_print_flags_t flags ;
5582+ int err ;
5583+
5584+ struct config {
5585+ bool ause ;
5586+ __u8 sanact ;
5587+ bool emvs ;
5588+ };
5589+
5590+ struct config cfg = {
5591+ .ause = false,
5592+ .sanact = 0 ,
5593+ .emvs = false,
5594+ };
5595+
5596+ OPT_VALS (sanact ) = {
5597+ VAL_BYTE ("exit-failure" , NVME_SANITIZE_SANACT_EXIT_FAILURE ),
5598+ VAL_BYTE ("start-crypto-erase" ,
5599+ NVME_SANITIZE_SANACT_START_CRYPTO_ERASE ),
5600+ VAL_BYTE ("exit-media-verification" ,
5601+ NVME_SANITIZE_SANACT_EXIT_MEDIA_VERIF ),
5602+ VAL_END ()
5603+ };
5604+
5605+ NVME_ARGS (opts ,
5606+ OPT_FLAG ("ause" , 'u' , & cfg .ause , ause_desc ),
5607+ OPT_BYTE ("sanact" , 'a' , & cfg .sanact , sanact_desc , sanact ),
5608+ OPT_FLAG ("emvs" , 'e' , & cfg .emvs , emvs_desc ));
5609+
5610+ err = parse_and_open (& ctx , & hdl , argc , argv , desc , opts );
5611+ if (err )
5612+ return err ;
5613+
5614+ err = validate_output_format (nvme_cfg .output_format , & flags );
5615+ if (err < 0 ) {
5616+ nvme_show_error ("Invalid output format" );
5617+ return err ;
5618+ }
5619+
5620+ switch (cfg .sanact ) {
5621+ case NVME_SANITIZE_SANACT_EXIT_FAILURE :
5622+ case NVME_SANITIZE_SANACT_START_CRYPTO_ERASE :
5623+ case NVME_SANITIZE_SANACT_EXIT_MEDIA_VERIF :
5624+ break ;
5625+ default :
5626+ nvme_show_error ("Invalid Sanitize Action" );
5627+ return - EINVAL ;
5628+ }
5629+
5630+ if (cfg .ause ) {
5631+ if (cfg .sanact == NVME_SANITIZE_SANACT_EXIT_FAILURE ) {
5632+ nvme_show_error ("SANACT is Exit Failure Mode" );
5633+ return - EINVAL ;
5634+ } else if (cfg .sanact == NVME_SANITIZE_SANACT_EXIT_MEDIA_VERIF ) {
5635+ nvme_show_error ("SANACT is Exit Media Verification State" );
5636+ return - EINVAL ;
5637+ }
5638+ }
5639+
5640+ nvme_init_sanitize_ns (& cmd , cfg .sanact , cfg .ause , cfg .emvs );
5641+ err = nvme_submit_admin_passthru (hdl , & cmd );
5642+ if (err < 0 )
5643+ nvme_show_error ("sanitize ns: %s" , nvme_strerror (err ));
5644+ else if (err > 0 )
5645+ nvme_show_status (err );
5646+
5647+ return err ;
5648+ }
5649+
55685650static int nvme_get_single_property (struct nvme_transport_handle * hdl , struct get_reg_config * cfg , __u64 * value )
55695651{
55705652 struct nvme_passthru_cmd cmd ;
0 commit comments