Skip to content

fix(inputdevices): fsync udev rule and rebuild on boot for touchpad - #1221

Merged
fly602 merged 1 commit into
linuxdeepin:masterfrom
fly602:master
Aug 26, 2026
Merged

fix(inputdevices): fsync udev rule and rebuild on boot for touchpad#1221
fly602 merged 1 commit into
linuxdeepin:masterfrom
fly602:master

Conversation

@fly602

@fly602 fly602 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor
  1. Replace os.WriteFile with os.Create + f.Sync() to ensure the udev rule file is flushed to disk before close
  2. On startup, call setTouchpadEnableViaUdev directly instead of setTouchpadEnable to avoid skipped udev rebuild when changed=false due to pre-initialized Enable field
  3. Prevents touchpad disable state loss after forced power-off

Log: fix touchpad disabled state lost after forced power-off because udev rule file write was not fsynced and startup rebuild was skipped by changed=false check

Influence:

  1. Disable touchpad, force power off, reboot and verify it stays disabled
  2. Disable touchpad, normal reboot and verify it stays disabled
  3. Enable touchpad, force power off, reboot and verify it stays enabled

fix(inputdevices): 修复强制关机后触控板禁用状态丢失

  1. 将 os.WriteFile 改为 os.Create + f.Sync() 确保写入 udev 规则文件时强制刷盘,防止断电丢失
  2. 启动恢复时直接调用 setTouchpadEnableViaUdev 重建 udev 规 则,避免 changed=false 导致跳过写入
  3. 修复强制关机后触控板禁用失效的问题

Log: 修复强制关机后触控板禁用状态丢失,原因是 udev 规则文件
写入未调用 fsync 导致断电丢失,且启动恢复逻辑因 changed=false
跳过了 udev 规则重建

Influence:

  1. 禁用触控板后强制关机,重启后确认触控板仍为禁用状态
  2. 禁用触控板后正常重启,确认触控板仍为禁用状态
  3. 启用触控板后强制关机,重启后确认触控板仍为启用状态

PMS: BUG-374789

Summary by Sourcery

Ensure touchpad state survives forced power-offs by reliably persisting and rebuilding its udev configuration.

Bug Fixes:

  • Preserve the touchpad enabled or disabled state across forced power-offs and reboots by reliably persisting and restoring its udev rule.

Enhancements:

  • Ensure touchpad udev rule updates are flushed to disk before completion and rebuild the rule directly from the configured state during startup.

1. Replace os.WriteFile with os.Create + f.Sync() to ensure
   the udev rule file is flushed to disk before close
2. On startup, call setTouchpadEnableViaUdev directly instead
   of setTouchpadEnable to avoid skipped udev rebuild when
   changed=false due to pre-initialized Enable field
3. Prevents touchpad disable state loss after forced power-off

Log: fix touchpad disabled state lost after forced power-off
because udev rule file write was not fsynced and startup rebuild
was skipped by changed=false check

Influence:
1. Disable touchpad, force power off, reboot and verify it
   stays disabled
2. Disable touchpad, normal reboot and verify it stays disabled
3. Enable touchpad, force power off, reboot and verify it stays
   enabled

fix(inputdevices): 修复强制关机后触控板禁用状态丢失

1. 将 os.WriteFile 改为 os.Create + f.Sync() 确保写入 udev
   规则文件时强制刷盘,防止断电丢失
2. 启动恢复时直接调用 setTouchpadEnableViaUdev 重建 udev 规
   则,避免 changed=false 导致跳过写入
3. 修复强制关机后触控板禁用失效的问题

Log: 修复强制关机后触控板禁用状态丢失,原因是 udev 规则文件
写入未调用 fsync 导致断电丢失,且启动恢复逻辑因 changed=false
跳过了 udev 规则重建

Influence:
1. 禁用触控板后强制关机,重启后确认触控板仍为禁用状态
2. 禁用触控板后正常重启,确认触控板仍为禁用状态
3. 启用触控板后强制关机,重启后确认触控板仍为启用状态

PMS: BUG-374789

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @fly602, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR preserves touchpad enable state across forced power-offs by synchronously flushing the udev rule file to disk and unconditionally rebuilding that rule from the persisted configuration during startup.

Sequence diagram for durable touchpad state restoration

sequenceDiagram
    participant Startup
    participant InputDevices
    participant Touchpad
    participant UdevRuleFile
    participant Disk

    Startup->>InputDevices: init()
    InputDevices->>Touchpad: setTouchpadEnableViaUdev(enabled)
    Touchpad->>UdevRuleFile: os.Create(udevRuleFile)
    Touchpad->>UdevRuleFile: f.Write(udevRuleContent)
    Touchpad->>UdevRuleFile: f.Sync()
    UdevRuleFile->>Disk: Flush rule contents
    Touchpad->>UdevRuleFile: f.Close()
    Note over Disk: Rule survives forced power-off
Loading

Flow diagram for touchpad udev rule rebuilding on boot

flowchart TD
    A[Persisted touchpad enable state] --> B["init()"]
    B --> C["setTouchpadEnableViaUdev(enabled)"]
    C --> D["os.Create(udevRuleFile)"]
    D --> E["f.Write(udevRuleContent)"]
    E --> F["f.Sync()"]
    F --> G[udev rule durably rebuilt]
Loading

File-Level Changes

Change Details Files
Make udev rule persistence durable across forced power loss.
  • Replace atomic file writing with explicit create, write, fsync, and close steps.
  • Propagate write, sync, and close errors while cleaning up on intermediate failures.
system/inputdevices1/touchpad.go
Rebuild the touchpad udev rule unconditionally during startup restoration.
  • Call the udev-specific setter directly from dconfig initialization.
  • Avoid the changed-state guard caused by the touchpad’s preinitialized Enable value.
system/inputdevices1/inputdevices.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@fly602
fly602 requested a review from deepin-ci-robot August 25, 2026 01:08
@fly602

fly602 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@fly602

fly602 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

/retest deepin-ci-robot

@deepin-ci-robot

Copy link
Copy Markdown

@fly602: The /retest command does not accept any targets.
The following commands are available to trigger required jobs:

  • /test deepin-auto-translation
  • /test github-pr-review-ci

Use /test all to run the following jobs that were automatically triggered:

  • github-pr-review-ci
Details

In response to this:

/retest deepin-ci-robot

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@fly602

fly602 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

/test github-pr-review-ci

@fly602

fly602 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

/test all

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, mhduiy

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fly602
fly602 merged commit 53b46be into linuxdeepin:master Aug 26, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants