fix: check for DEVTYPE=drm_minor when trying to find usable gpu paths instead of using the name

This commit is contained in:
Ilya Zlobintsev 2023-04-22 10:27:47 +03:00
parent b461106edd
commit 0bc59a02cc

View File

@ -8,7 +8,7 @@ use lact_schema::{
}; };
use std::{ use std::{
collections::HashMap, collections::HashMap,
env, env, fs,
path::PathBuf, path::PathBuf,
sync::{Arc, RwLock}, sync::{Arc, RwLock},
}; };
@ -35,27 +35,25 @@ impl<'a> Handler {
{ {
let entry = entry?; let entry = entry?;
let name = entry if let Ok(drm_uevent) = fs::read_to_string(entry.path().join("uevent")) {
.file_name() if drm_uevent.contains("DEVTYPE=drm_minor") {
.into_string() trace!("trying gpu controller at {:?}", entry.path());
.map_err(|_| anyhow!("non-utf path"))?; let device_path = entry.path().join("device");
if name.starts_with("card") && !name.contains('-') { match GpuController::new_from_path(device_path) {
trace!("trying gpu controller at {:?}", entry.path()); Ok(controller) => match controller.get_id() {
let device_path = entry.path().join("device"); Ok(id) => {
match GpuController::new_from_path(device_path) { let path = controller.get_path();
Ok(controller) => match controller.get_id() { debug!("initialized GPU controller {id} for path {path:?}",);
Ok(id) => { controllers.insert(id, controller);
let path = controller.get_path(); }
debug!("initialized GPU controller {id} for path {path:?}",); Err(err) => warn!("could not initialize controller: {err:#}"),
controllers.insert(id, controller); },
Err(error) => {
warn!(
"failed to initialize controller at {:?}, {error}",
entry.path()
);
} }
Err(err) => warn!("could not initialize controller: {err:#}"),
},
Err(error) => {
warn!(
"failed to initialize controller at {:?}, {error}",
entry.path()
);
} }
} }
} }