tty: Re-evaluate ignored nodes on udev add events and session resume (#3651)
Browse files at this commit1 changed file +23 -29
- src/backend/tty.rs +23 -29
src/backend/tty.rsmodified+23 -29
| @@ -97,9 +97,6 @@ pub struct Tty { | |||
| 97 | dmabuf_global: Option<DmabufGlobal>, | 97 | dmabuf_global: Option<DmabufGlobal>, |
| 98 | // The output config had changed, but the session is paused, so we need to update it on resume. | 98 | // The output config had changed, but the session is paused, so we need to update it on resume. |
| 99 | update_output_config_on_resume: bool, | 99 | update_output_config_on_resume: bool, |
| 100 | - // The ignored nodes have changed, but the session is paused, so we need to update it on | ||
| 101 | - // resume. | ||
| 102 | - update_ignored_nodes_on_resume: bool, | ||
| 103 | // Whether the debug tinting is enabled. | 100 | // Whether the debug tinting is enabled. |
| 104 | debug_tint: bool, | 101 | debug_tint: bool, |
| 105 | ipc_outputs: Arc<Mutex<IpcOutputMap>>, | 102 | ipc_outputs: Arc<Mutex<IpcOutputMap>>, |
| @@ -495,11 +492,6 @@ impl Tty { | |||
| 495 | } | 492 | } |
| 496 | info!("using as the render node: {node_path}"); | 493 | info!("using as the render node: {node_path}"); |
| 497 | 494 | ||
| 498 | - let mut ignored_nodes = ignored_nodes_from_config(&config.borrow()); | ||
| 499 | - if ignored_nodes.remove(&primary_node) || ignored_nodes.remove(&primary_render_node) { | ||
| 500 | - warn!("ignoring the primary node or render node is not allowed"); | ||
| 501 | - } | ||
| 502 | - | ||
| 503 | Ok(Self { | 495 | Ok(Self { |
| 504 | config, | 496 | config, |
| 505 | session, | 497 | session, |
| @@ -508,11 +500,10 @@ impl Tty { | |||
| 508 | gpu_manager, | 500 | gpu_manager, |
| 509 | primary_node, | 501 | primary_node, |
| 510 | primary_render_node, | 502 | primary_render_node, |
| 511 | - ignored_nodes, | 503 | + ignored_nodes: HashSet::new(), |
| 512 | devices: HashMap::new(), | 504 | devices: HashMap::new(), |
| 513 | dmabuf_global: None, | 505 | dmabuf_global: None, |
| 514 | update_output_config_on_resume: false, | 506 | update_output_config_on_resume: false, |
| 515 | - update_ignored_nodes_on_resume: false, | ||
| 516 | debug_tint: false, | 507 | debug_tint: false, |
| 517 | ipc_outputs: Arc::new(Mutex::new(HashMap::new())), | 508 | ipc_outputs: Arc::new(Mutex::new(HashMap::new())), |
| 518 | }) | 509 | }) |
| @@ -527,6 +518,9 @@ impl Tty { | |||
| 527 | return; | 518 | return; |
| 528 | } | 519 | } |
| 529 | 520 | ||
| 521 | + // Initialize the ignored nodes. | ||
| 522 | + self.ignored_nodes = self.compute_ignored_nodes(); | ||
| 523 | + | ||
| 530 | let udev = self.udev_dispatcher.clone(); | 524 | let udev = self.udev_dispatcher.clone(); |
| 531 | let udev = udev.as_source_ref(); | 525 | let udev = udev.as_source_ref(); |
| 532 | 526 | ||
| @@ -566,6 +560,10 @@ impl Tty { | |||
| 566 | return; | 560 | return; |
| 567 | } | 561 | } |
| 568 | 562 | ||
| 563 | + // Recompute ignored nodes to resolve symlinks (like /dev/dri/by-path/...) to their | ||
| 564 | + // new underlying device IDs. | ||
| 565 | + self.ignored_nodes = self.compute_ignored_nodes(); | ||
| 566 | + | ||
| 569 | if let Err(err) = self.device_added(device_id, &path, niri) { | 567 | if let Err(err) = self.device_added(device_id, &path, niri) { |
| 570 | warn!("error adding device: {err:?}"); | 568 | warn!("error adding device: {err:?}"); |
| 571 | } | 569 | } |
| @@ -613,16 +611,9 @@ impl Tty { | |||
| 613 | warn!("error resuming libinput"); | 611 | warn!("error resuming libinput"); |
| 614 | } | 612 | } |
| 615 | 613 | ||
| 616 | - if self.update_ignored_nodes_on_resume { | 614 | + // While the session was suspended, GPUs could have been added, so |
| 617 | - self.update_ignored_nodes_on_resume = false; | 615 | + // /dev/dri/by-path/... symlinks need to be re-resolved. |
| 618 | - let mut ignored_nodes = ignored_nodes_from_config(&self.config.borrow()); | 616 | + self.ignored_nodes = self.compute_ignored_nodes(); |
| 619 | - if ignored_nodes.remove(&self.primary_node) | ||
| 620 | - || ignored_nodes.remove(&self.primary_render_node) | ||
| 621 | - { | ||
| 622 | - warn!("ignoring the primary node or render node is not allowed"); | ||
| 623 | - } | ||
| 624 | - self.ignored_nodes = ignored_nodes; | ||
| 625 | - } | ||
| 626 | 617 | ||
| 627 | let mut device_list = self | 618 | let mut device_list = self |
| 628 | .udev_dispatcher | 619 | .udev_dispatcher |
| @@ -2292,22 +2283,25 @@ impl Tty { | |||
| 2292 | } | 2283 | } |
| 2293 | } | 2284 | } |
| 2294 | 2285 | ||
| 2295 | - pub fn update_ignored_nodes_config(&mut self, niri: &mut Niri) { | 2286 | + fn compute_ignored_nodes(&self) -> HashSet<DrmNode> { |
| 2296 | - let _span = tracy_client::span!("Tty::update_ignored_nodes_config"); | ||
| 2297 | - | ||
| 2298 | - // If we're inactive, we can't do anything, so just set a flag for later. | ||
| 2299 | - if !self.session.is_active() { | ||
| 2300 | - self.update_ignored_nodes_on_resume = true; | ||
| 2301 | - return; | ||
| 2302 | - } | ||
| 2303 | - | ||
| 2304 | let mut ignored_nodes = ignored_nodes_from_config(&self.config.borrow()); | 2287 | let mut ignored_nodes = ignored_nodes_from_config(&self.config.borrow()); |
| 2305 | if ignored_nodes.remove(&self.primary_node) | 2288 | if ignored_nodes.remove(&self.primary_node) |
| 2306 | || ignored_nodes.remove(&self.primary_render_node) | 2289 | || ignored_nodes.remove(&self.primary_render_node) |
| 2307 | { | 2290 | { |
| 2308 | warn!("ignoring the primary node or render node is not allowed"); | 2291 | warn!("ignoring the primary node or render node is not allowed"); |
| 2309 | } | 2292 | } |
| 2293 | + ignored_nodes | ||
| 2294 | + } | ||
| 2295 | + | ||
| 2296 | + pub fn update_ignored_nodes_config(&mut self, niri: &mut Niri) { | ||
| 2297 | + let _span = tracy_client::span!("Tty::update_ignored_nodes_config"); | ||
| 2298 | + | ||
| 2299 | + // If we're inactive, we can't do anything, but we'll recompute in ActivateSession. | ||
| 2300 | + if !self.session.is_active() { | ||
| 2301 | + return; | ||
| 2302 | + } | ||
| 2310 | 2303 | ||
| 2304 | + let ignored_nodes = self.compute_ignored_nodes(); | ||
| 2311 | if ignored_nodes == self.ignored_nodes { | 2305 | if ignored_nodes == self.ignored_nodes { |
| 2312 | return; | 2306 | return; |
| 2313 | } | 2307 | } |