Skip to content

asusd: open scsi_generic /dev/sgN for SCSI Aura devices - #257

Open
NB-Group wants to merge 1 commit into
OpenGamingCollective:mainfrom
NB-Group:arion-scsi-sg-node
Open

asusd: open scsi_generic /dev/sgN for SCSI Aura devices#257
NB-Group wants to merge 1 commit into
OpenGamingCollective:mainfrom
NB-Group:arion-scsi-sg-node

Conversation

@NB-Group

@NB-Group NB-Group commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

SCSI Aura devices (e.g. ROG STRIX Arion, 0b05:1932) showed up on D-Bus and asusctl scsi reported success, but no traffic ever reached the enclosure. The LEDs never changed.

write_effect() opened the block node (/dev/sdX) and issued SG_IO with the vendor CDB. SG_IO with a vendor command on a block node requires CAP_SYS_RAWIO, but the hardened asusd unit strips every capability (empty CapabilityBoundingSet, NoNewPrivileges=true), so every ioctl returned EPERM. write_effect() then did perform(task).ok() and threw the error away, so asusd reported success while zero commands hit the wire. strace showed ioctl(N, SG_IO, ...) = -1 EPERM sixteen times per write, and usbmon showed only baseline usb-storage traffic.

Fix: resolve the scsi_generic node (/dev/sgN) backing the block device and open that instead. The sg driver gates access at open() through the file permissions, so SG_IO works with no capabilities, the same path sg3_utils and OpenRGB use. I also stopped swallowing the ioctl error in write_effect so this can't go silent again.

Verified on an Arion: 16/16 SG_IO return 0, the ENE vendor CDBs (mode 0x8021, colour registers 0x8160+, apply 0x80a0) show up in usbmon, and the LEDs change.

Two files, no kernel changes. This is the working userspace reference for the SCSI device-handler driver we discussed.

On hotplug the sg node can lag the block node by a moment, so init retries briefly before falling back to the block device; at startup the node already exists, so the first attempt hits with no delay.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved SCSI device detection for more reliable device initialization, including hotplug scenarios.
    • Added a fallback when a generic SCSI device node is unavailable.
    • SCSI effect execution failures are now logged while remaining effects continue processing.

Walkthrough

The SCSI path discovers and prefers existing /dev/sgN nodes. It retries discovery during hotplug and falls back to the block node when needed. SCSI task execution failures are logged while processing continues.

Changes

SCSI device handling

Layer / File(s) Summary
Generic node discovery and initialization
asusd/src/aura_manager.rs
The manager walks ancestor devices to find an existing /dev/sgN node. Initialization retries discovery up to eight times, then uses the generic node or logs a warning before falling back to the block node.
SCSI execution diagnostics
asusd/src/aura_scsi/mod.rs
Failed SCSI tasks now log their errors. Remaining tasks continue, and write_effect returns Ok(()).

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: asusd, rog-scsi, fix

Suggested reviewers: ghoul4500, scardracs

Sequence Diagram(s)

sequenceDiagram
  participant AuraManager
  participant Sysfs
  participant DevSg
  participant ScsiAura

  AuraManager->>Sysfs: Walk ancestor devices
  Sysfs-->>AuraManager: Return scsi_generic entries
  AuraManager->>DevSg: Check /dev/sgN
  DevSg-->>AuraManager: Return generic node or unavailable
  AuraManager->>ScsiAura: Initialize with /dev/sgN or block node
  ScsiAura->>ScsiAura: Execute SCSI tasks
  ScsiAura-->>ScsiAura: Log task errors and continue
Loading
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: opening the SCSI generic device for SCSI Aura devices.
Description check ✅ Passed The description clearly explains the problem, motivation, implementation, testing, and hotplug behavior, but omits issue and environment details.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added asusd System Daemon / D-Bus fix Fix a bug or an issue rog-aura Keyboard / Aura RGB rog-scsi Drive / SCSI LED labels Aug 3, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@asusd/src/aura_manager.rs`:
- Around line 317-335: Update the SCSI device-event handling around the
block-node initialization and monitor matching so a later scsi_generic
(/dev/sgN) add event triggers initialization retry for the same device. Replace
the retained /dev/sdX handle or re-run the relevant DeviceHandle initialization
once sg_node_for_block resolves, while preserving existing behavior when the
block event arrives after the generic node.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bfefcb49-ea96-4492-aa70-c133dd53aeb2

📥 Commits

Reviewing files that changed from the base of the PR and between 3d3c048 and 538ed80.

📒 Files selected for processing (2)
  • asusd/src/aura_manager.rs
  • asusd/src/aura_scsi/mod.rs
📜 Review details
🔇 Additional comments (1)
asusd/src/aura_scsi/mod.rs (1)

30-35: LGTM!

Comment thread asusd/src/aura_manager.rs
SG_IO with a vendor CDB on the block node (/dev/sdX) requires
CAP_SYS_RAWIO. The hardened asusd systemd unit strips all capabilities
(empty CapabilityBoundingSet, NoNewPrivileges=true), so every SG_IO on
the block node returned EPERM. write_effect() was doing
perform(task).ok(), so the error was silently swallowed; asusd reported
success while zero SCSI traffic reached the enclosure (confirmed via
usbmon).

Resolve the scsi_generic node (/dev/sgN) backing the block device and
open that instead. The sg driver gates access at open() through file
permissions, so SG_IO works without any capability, the same path
sg3_utils and OpenRGB use. On hotplug the sg node can appear just after
the block node, so init retries briefly before falling back to the block
device.

Also stop discarding the ioctl error in write_effect so a future failure
can't go invisible again.

Verified on a ROG STRIX Arion (0b05:1932): 16/16 SG_IO return 0, the
ENE vendor CDBs (mode 0x8021, colour registers 0x8160+, apply 0x80a0)
appear in usbmon, and the LEDs change.
@scardracs

Copy link
Copy Markdown
Contributor

BTW, we own sg.rs too if you want to take a look into it too. The one on crates.io is not supported anymore, like the one made by luke back in 2025, so I took the liberty to pick his version up and import it directly into code.

@NB-Group

NB-Group commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Nice, took a look. sg.rs sidesteps the cmd_len trap I hit in the kernel driver: it sets cmd_len from the slice length, so the 16-byte vendor CDB works as-is. The kernel sizes the CDB by opcode, 0xec maps to 10, cdb[13] (the ENE data-length byte) drops silently, and I had to hand-build the request there to force 16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

asusd System Daemon / D-Bus fix Fix a bug or an issue rog-scsi Drive / SCSI LED

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants