@@ -1456,15 +1456,7 @@ fn validate_vm_sandbox(sandbox: &Sandbox, gpu_enabled: bool) -> Result<(), Statu
14561456 . as_ref ( )
14571457 . ok_or_else ( || Status :: invalid_argument ( "sandbox spec is required" ) ) ?;
14581458
1459- if spec. gpu && !gpu_enabled {
1460- return Err ( Status :: failed_precondition (
1461- "GPU support is not enabled on this driver; start with --gpu" ,
1462- ) ) ;
1463- }
1464-
1465- if !spec. gpu && !spec. gpu_device . is_empty ( ) {
1466- return Err ( Status :: invalid_argument ( "gpu_device requires gpu=true" ) ) ;
1467- }
1459+ validate_gpu_request ( spec. gpu , & spec. gpu_device , gpu_enabled) ?;
14681460
14691461 if let Some ( template) = spec. template . as_ref ( ) {
14701462 if !template. agent_socket_path . is_empty ( ) {
@@ -1481,7 +1473,6 @@ fn validate_vm_sandbox(sandbox: &Sandbox, gpu_enabled: bool) -> Result<(), Statu
14811473 Ok ( ( ) )
14821474}
14831475
1484- #[ allow( clippy:: result_large_err) ]
14851476fn validate_sandbox_id ( sandbox_id : & str ) -> Result < ( ) , Status > {
14861477 if sandbox_id. is_empty ( ) {
14871478 return Err ( Status :: invalid_argument ( "sandbox id is required" ) ) ;
@@ -1507,6 +1498,20 @@ fn validate_sandbox_id(sandbox_id: &str) -> Result<(), Status> {
15071498 Ok ( ( ) )
15081499}
15091500
1501+ #[ allow( clippy:: result_large_err) ]
1502+ fn validate_gpu_request ( gpu : bool , gpu_device : & str , gpu_enabled : bool ) -> Result < ( ) , Status > {
1503+ if gpu && !gpu_enabled {
1504+ return Err ( Status :: failed_precondition (
1505+ "GPU support is not enabled on this driver; start with --gpu" ,
1506+ ) ) ;
1507+ }
1508+
1509+ if !gpu && !gpu_device. is_empty ( ) {
1510+ return Err ( Status :: invalid_argument ( "gpu_device requires gpu=true" ) ) ;
1511+ }
1512+ Ok ( ( ) )
1513+ }
1514+
15101515#[ allow( clippy:: result_large_err) ]
15111516fn parse_registry_reference ( image_ref : & str ) -> Result < Reference , Status > {
15121517 Reference :: try_from ( image_ref) . map_err ( |err| {
0 commit comments