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