Skip to content

Pr0731#163

Merged
deepin-bot[bot] merged 3 commits intolinuxdeepin:masterfrom
wangrong1069:pr0731
Jul 31, 2025
Merged

Pr0731#163
deepin-bot[bot] merged 3 commits intolinuxdeepin:masterfrom
wangrong1069:pr0731

Conversation

@wangrong1069
Copy link
Contributor

@wangrong1069 wangrong1069 commented Jul 31, 2025

Summary by Sourcery

Improve storage device info retrieval by adding NVMe support in lshw parsing, enhancing lshw output handling to consider namespaces, and simplifying smartctl line filtering

Enhancements:

  • Skip KeyToLshw matching for NVMe devices in addInfoFromlshw
  • Enhance lshw output parsing to handle namespaces when extracting disk info
  • Simplify smartctl output filtering by removing redundant regex capture conditions

- Remove conflicting filtering conditions

Log: Fix incomplete retrieval of disk hardware information
- Adjust conditions to bypass key checks for NVMe devices.
- Adjust for new version lshw.

lshw output example:
    *-disk:0
        description: ATA Disk
        product: VBOX HARDDISK
        vendor: VirtualBox
        physical id: 0
        bus info: scsi@2:0.0.0
        logical name: /dev/sda
        version: 1.0
        serial: VB899a842b-39025490
        size: 80GiB (85GB)
        capabilities: partitioned partitioned:dos
        configuration: ansiversion=5 logicalsectorsize=512 sectorsize=512 signature=ff40caad
    *-disk:1
        description: ATA Disk
        product: VBOX HARDDISK
        vendor: VirtualBox
        physical id: 1
        bus info: scsi@3:0.0.0
        logical name: /dev/sdb
        version: 1.0
        serial: VB6950fcbf-358a6d1e
        size: 1GiB (1073MB)
        capabilities: partitioned partitioned:dos
        configuration: ansiversion=5 logicalsectorsize=512 sectorsize=512 signature=84232800
    *-namespace:0
        description: NVMe disk
        physical id: 0
        logical name: hwmon0
    *-namespace:1
        description: NVMe disk
        physical id: 2
        logical name: /dev/ng0n1
    *-namespace:2
        description: NVMe disk
        physical id: 1
        bus info: nvme@0:1
        logical name: /dev/nvme0n1
        size: 238GiB (256GB)
        capabilities: gpt-1.00 partitioned partitioned:gpt
        configuration: guid=36245768-2893-4b0c-9c9a-cfd42e90e7f2 logicalsectorsize=512 sectorsize=512 wwid=eui.6479a73c71a03470

Log: Improve disk info retrieval logic
As title.

Log: Update version to 6.0.11
@github-actions
Copy link

TAG Bot

TAG: 6.0.11
EXISTED: no
DISTRIBUTION: unstable

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 31, 2025

Reviewer's Guide

This PR adds a special NVMe bypass in lshw parsing, refactors getDiskInfoFromLshw for nested parsing and clearer variable usage, and streamlines the regex condition in getMapInfoFromSmartctl, alongside a changelog update.

Class diagram for DeviceStorage changes

classDiagram
    class DeviceStorage {
        +bool addInfoFromlshw(const QMap<QString, QString> &mapInfo)
        +bool getDiskInfoFromLshw(const QString &devicePath)
        +void getMapInfoFromSmartctl(QMap<QString, QString> &mapInfo, const QString &output)
        -QString m_KeyToLshw
    }

    DeviceStorage : addInfoFromlshw() now bypasses m_KeyToLshw check for NVMe
    DeviceStorage : getDiskInfoFromLshw() refactored for nested *-disk/*-namespace parsing
    DeviceStorage : getMapInfoFromSmartctl() regex condition streamlined
Loading

File-Level Changes

Change Details Files
Introduce NVMe device bypass in addInfoFromlshw
  • Check if bus info prefix is 'nvme' and skip KeyToLshw validation
  • Move key normalization into else branch for non-NVMe devices
  • Enhance debug logging with bus type, computed key, and expected m_KeyToLshw
service/diskoperation/DeviceStorage.cpp
Refactor lshw output parsing in getDiskInfoFromLshw
  • Replace split on "-disk\n" with split on "-disk" then "*-namespace"
  • Use nested loops with QStringList and foreach to locate devicePath
  • Rename outPut to diskInfo and adjust empty check accordingly
service/diskoperation/DeviceStorage.cpp
Simplify regex-based filtering in getMapInfoFromSmartctl
  • Remove redundant match.captured(0) == line check
  • Consolidate condition to only require index > 0, no regex match, and no error markers
service/diskoperation/DeviceStorage.cpp
Update Debian changelog
  • Bump package version and update entry metadata
debian/changelog

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

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, wangrong1069

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @wangrong1069 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `service/diskoperation/DeviceStorage.cpp:455` </location>
<code_context>
-            outPut = list.at(i);
-            break;
+    QString diskInfo;
+    QStringList list = outPut.split("*-disk");
+    foreach (const QString &item, list) {
+        QStringList list2 = item.split("*-namespace");
+        foreach (const QString &item2, list2) {
</code_context>

<issue_to_address>
Splitting on '*-disk' without the newline may cause parsing issues.

Switching from splitting on '*-disk\n' to '*-disk' may introduce empty or malformed entries and affect disk section parsing. Please verify that the output structure remains correct.
</issue_to_address>

### Comment 2
<location> `service/diskoperation/DeviceStorage.cpp:457` </location>
<code_context>
+    QString diskInfo;
+    QStringList list = outPut.split("*-disk");
+    foreach (const QString &item, list) {
+        QStringList list2 = item.split("*-namespace");
+        foreach (const QString &item2, list2) {
+            if (item2.contains(devicePath)) {
+                qDebug() << "devicePath found in lshw output";
</code_context>

<issue_to_address>
Nested splitting on '*-namespace' may not be robust for all lshw outputs.

This approach relies on a fixed lshw output structure, which may not be reliable. Please add validation or fallback handling for unexpected formats.
</issue_to_address>

### Comment 3
<location> `service/diskoperation/DeviceStorage.cpp:804` </location>
<code_context>
         int index = line.indexOf(ch);
 #if QT_VERSION_MAJOR > 5
         QRegularExpressionMatch match = reg.match(line);
-        if (index > 0 && !match.hasMatch() && match.captured(0) == line && false == line.contains("Error") && false == line.contains("hh:mm:SS")) {
+        if (index > 0 && !match.hasMatch() && false == line.contains("Error") && false == line.contains("hh:mm:SS")) {
 #else
         if (index > 0 && reg.exactMatch(line) == false && false == line.contains("Error") && false == line.contains("hh:mm:SS")) {
</code_context>

<issue_to_address>
Removed redundant match.captured(0) == line check, which may affect filtering.

Please verify that removing this condition won't result in partial matches being included in mapInfo unintentionally.
</issue_to_address>

### Comment 4
<location> `service/diskoperation/DeviceStorage.cpp:145` </location>
<code_context>
-    if (key != m_KeyToLshw) {
-        qDebug() << "lshw key does not match, returning false";
-        return false;
+    if (keys[0].trimmed() == "nvme") {
+        qDebug() << "nvme device found, not check KeyToLshw";
+    } else {
</code_context>

<issue_to_address>
Consider inverting conditionals and using regular expressions to flatten control flow and reduce string manipulation in the updated functions.

Here are two small focused ways to collapse the added nesting/branching without losing any behavior:

1) Simplify the NVMe‐vs‐key check in addInfoFromlshw by inverting and early‐returning, so you eliminate the else/indent:

```cpp
bool DeviceStorage::addInfoFromlshw(const QMap<QString, QString> &mapInfo) {
    qDebug() << "Adding lshw info for storage device";
    auto keys = mapInfo["bus info"].split("@");
    if (keys.size() != 2) {
        qWarning() << "Invalid bus info format:" << mapInfo["bus info"];
        return false;
    }

    const QString busType = keys[0].trimmed();
    // Only non‐NVMe needs to match m_KeyToLshw
    if (busType != "nvme") {
        QString key = keys[1].trimmed().replace(".", ":");
        if (key != m_KeyToLshw) {
            qDebug() << "lshw key does not match, returning false" 
                     << busType << key << m_KeyToLshw;
            return false;
        }
    }

    // now set m_KeyFromStorage as before...
    auto words = mapInfo["bus info"].split(":");
    if (words.size() == 2) {
        qDebug() << "Setting KeyFromStorage";
        m_KeyFromStorage = words[0].replace("@", "");
    } else {
        qDebug() << "Cannot set KeyFromStorage, invalid format for bus info";
    }
    return true;
}
```

2) Collapse the double‐split loop in getDiskInfoFromLshw into a single regex pass:

```cpp
bool DeviceStorage::getDiskInfoFromLshw(const QString &devicePath) {
    QString out, err;
    if (Utils::executCmd("lshw -C disk", out, err) != 0) {
        qDebug() << "Failed to execute lshw command, error:" << err;
        return false;
    }

    // grab each "*-disk…*-namespace" block and pick the one containing devicePath
    QRegularExpression re(QStringLiteral(R"(\*\-disk[\s\S]*?\*\-namespace)"));
    auto it = re.globalMatch(out);
    QString diskInfo;
    while (it.hasNext()) {
        const auto block = it.next().captured(0);
        if (block.contains(devicePath)) {
            qDebug() << "devicePath found in lshw output";
            diskInfo = block;
            break;
        }
    }

    if (diskInfo.isEmpty()) {
        qDebug() << "devicePath not found in lshw output, return false";
        return false;
    }

    QMap<QString, QString> mapInfo;
    getMapInfoFromLshw(diskInfo, mapInfo);
    addInfoFromlshw(mapInfo);
    return true;
}
```

These keep the new NVMe behavior and full data extraction, but flatten out the nesting and string gymnastics.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@wangrong1069
Copy link
Contributor Author

/merge

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