Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

SDWire: record stable device link by id instead of diskseq#340

Merged
NickCao merged 1 commit intomainfrom
sdwire-fix
Mar 12, 2025
Merged

SDWire: record stable device link by id instead of diskseq#340
NickCao merged 1 commit intomainfrom
sdwire-fix

Conversation

@NickCao
Copy link
Copy Markdown
Collaborator

@NickCao NickCao commented Mar 12, 2025

Closes-Issue: #341

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced the logic for detecting stable storage devices, ensuring more precise configuration and improved operational reliability. Users should experience smoother system performance and fewer interruptions during device setup, contributing to overall system stability and efficiency. This update reinforces continuous improvements in hardware integration and user experience.
  • New Features

    • Introduced a new method for determining the effective storage device, centralizing the logic for improved reliability in file operations.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 12, 2025

Walkthrough

The changes introduce a new method, effective_storage_device, within the driver module that centralizes the logic for determining the effective storage device. This method checks if self.storage_device is None and retrieves the appropriate device link from the USB subsystem using pyudev. The __post_init__ method now calls this new method, and error handling in the wait_for_storage_device method has been updated to utilize it. The write and read methods have also been modified to ensure they use the correct storage device.

Changes

File Change Description
packages/jumpstarter-driver-sdwire/.../driver.py Added method effective_storage_device(self) to centralize storage device logic. Updated __post_init__, wait_for_storage_device, write, and read methods to utilize the new method and improved error handling.

Sequence Diagram(s)

sequenceDiagram
    participant D as Driver
    participant FS as Filesystem
    D->>FS: Call effective_storage_device
    alt storage_device is None
        D->>FS: Retrieve device link from USB subsystem
    end
    D->>D: Set storage_device attribute
    D->>FS: Perform read/write operations
Loading

Poem

Hoppin' through the code so bright,
A method new brings pure delight.
With links from USB, I find my way,
Effective storage leads the day!
In every byte, a joyful play!
🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 12, 2025

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit 0256430
🔍 Latest deploy log https://app.netlify.com/sites/jumpstarter-docs/deploys/67d1a0ef54eddc0008f70946
😎 Deploy Preview https://deploy-preview-340--jumpstarter-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mangelajo mangelajo self-requested a review March 12, 2025 13:33
@mangelajo
Copy link
Copy Markdown
Member

Can we check if it really works?

I remember that sdwire wasn't specially good with "disk by-id" ... as it didn't implement any serial number for the SD card reader.

@NickCao
Copy link
Copy Markdown
Collaborator Author

NickCao commented Mar 12, 2025

I remember that sdwire wasn't specially good with "disk by-id" ... as it didn't implement any serial number for the SD card reader.

From my two minutes of testing it seems to pass-through the id of the inserted sdcard.

@mangelajo
Copy link
Copy Markdown
Member

I remember that sdwire wasn't specially good with "disk by-id" ... as it didn't implement any serial number for the SD card reader.

From my two minutes of testing it seems to pass-through the id of the inserted sdcard.

May be it was my card that didn't have an id?

Would it work if we keep looking up the device by seq, but do it always before attempting to write or read?

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/jumpstarter-driver-sdwire/jumpstarter_driver_sdwire/driver.py (1)

34-38: Improve robustness by handling potential missing device links

Currently, there's no fallback mechanism if no device links matching the criteria are found. Consider adding a logging statement or fallback strategy for cases where SD cards might lack proper identifiers.

 for storage_device in filter(
     lambda link: link.startswith("/dev/disk/by-diskseq/"), block.device_links
 ):
     return storage_device
+# Fallback to direct block device if no stable links found
+return block.device_node
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe3b675 and 0256430.

📒 Files selected for processing (1)
  • packages/jumpstarter-driver-sdwire/jumpstarter_driver_sdwire/driver.py (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: pytest-matrix (3.13)
  • GitHub Check: e2e
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter Dockerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-utils Dockerfile.utils)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
🔇 Additional comments (5)
packages/jumpstarter-driver-sdwire/jumpstarter_driver_sdwire/driver.py (5)

106-107: LGTM - Good centralization of storage device logic

Centralizing the effective storage device lookup improves code maintainability and ensures consistent behavior.


115-121: Good improvement to error handling

The specific handling of error codes (123 for "No medium found" and 5 for "Input/output error") makes the code more robust. This properly distinguishes between expected transient errors and unexpected errors that should be raised.


123-124: Good defensive programming practice

Checking if fd exists in locals before closing it prevents potential errors in error handling flow.


127-128: Consistent use of storage device across operations

The consistent pattern of retrieving and using the storage device path across read and write operations ensures reliability. The changes effectively centralize the storage device determination logic.

Also applies to: 132-133, 141-142


24-41:

Details

❓ Verification inconclusive

Inconsistency between implementation and PR objective

The PR objective mentions recording stable device links by ID instead of diskseq, but line 36 still filters for paths starting with /dev/disk/by-diskseq/. Consider changing this to use /dev/disk/by-id/ instead to align with the PR's stated goal.

-                        lambda link: link.startswith("/dev/disk/by-diskseq/"), block.device_links
+                        lambda link: link.startswith("/dev/disk/by-id/"), block.device_links

🏁 Script executed:

#!/bin/bash
# Check if the device actually has by-id symlinks available
for udev in $(udevadm info --export-db | grep -o 'P: .*sd.*' | awk '{print $2}'); do
  echo "Device: $udev"
  udevadm info --query=symlink --name=$udev | grep -q "disk/by-id" && echo "Has by-id links" || echo "No by-id links"
  echo "---"
done

Length of output: 168


Action Required: Update Link Filtering to Use /dev/disk/by-id/

It appears that the shell script for verifying the presence of "by-id" symlinks failed because the udevadm command isn't available in our sandbox. As a result, the verification was inconclusive. The code still filters for /dev/disk/by-diskseq/ links, whereas the PR objective is to record stable device links using /dev/disk/by-id/.

  • File: packages/jumpstarter-driver-sdwire/jumpstarter_driver_sdwire/driver.py
  • Lines: 24-41
  • Required Change:
    -                        lambda link: link.startswith("/dev/disk/by-diskseq/"), block.device_links
    +                        lambda link: link.startswith("/dev/disk/by-id/"), block.device_links

Please update the logic accordingly. Important: Since the automated verification did not yield the expected output, manually verify on a system where udevadm is available that devices indeed expose stable "by-id" symlinks. This manual check is necessary to ensure the change aligns with the intended behavior.

@NickCao NickCao merged commit 28d6b1c into main Mar 12, 2025
@NickCao NickCao deleted the sdwire-fix branch March 12, 2025 17:02
@mangelajo mangelajo added this to the 0.6.0 milestone May 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants