()
| 333 | } |
| 334 | |
| 335 | fn prepare_configfs() -> Result<String> { |
| 336 | if let Ok(path) = std::env::var(CONFIGFS_PATH_ENV) { |
| 337 | if path.len() < 240 && Path::new(&path).is_dir() && verify_configfs_provider(&path)? { |
| 338 | return Ok(path); |
| 339 | } |
| 340 | return Err(TdxAttestError::NotSupported(format!( |
| 341 | "invalid configfs path from env: {path}" |
| 342 | ))); |
| 343 | } |
| 344 | |
| 345 | let default_path = CONFIGFS_DEFAULT; |
| 346 | if Path::new(default_path).is_dir() && verify_configfs_provider(default_path)? { |
| 347 | return Ok(default_path.to_string()); |
| 348 | } |
| 349 | |
| 350 | { |
| 351 | let mut tried = CONFIGFS_MKDIR_TRIED |
| 352 | .lock() |
| 353 | .map_err(|_| TdxAttestError::Busy)?; |
| 354 | if *tried { |
| 355 | return Err(TdxAttestError::NotSupported( |
| 356 | "configfs already tried".to_string(), |
| 357 | )); |
| 358 | } |
| 359 | *tried = true; |
| 360 | } |
| 361 | |
| 362 | if !Path::new(CONFIGFS_BASE).is_dir() { |
| 363 | return Err(TdxAttestError::NotSupported(format!( |
| 364 | "configfs base not found: {CONFIGFS_BASE}" |
| 365 | ))); |
| 366 | } |
| 367 | |
| 368 | if fs::create_dir(default_path).is_ok() || Path::new(default_path).is_dir() { |
| 369 | let provider_path = format!("{}/provider", default_path); |
| 370 | for i in 0..5 { |
| 371 | if Path::new(&provider_path).exists() { |
| 372 | if verify_configfs_provider(default_path)? { |
| 373 | return Ok(default_path.to_string()); |
| 374 | } |
| 375 | break; |
| 376 | } |
| 377 | thread::sleep(Duration::from_micros(i as u64)); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | Err(TdxAttestError::NotSupported(format!( |
| 382 | "failed to prepare configfs: {default_path}" |
| 383 | ))) |
| 384 | } |
| 385 | |
| 386 | fn verify_configfs_provider(path: &str) -> Result<bool> { |
| 387 | let provider_path = format!("{}/provider", path); |
no test coverage detected