Skip to content

chore: More logs for base and service#156

Merged
re2zero merged 1 commit into
linuxdeepin:masterfrom
re2zero:bugfix
Jul 7, 2025
Merged

chore: More logs for base and service#156
re2zero merged 1 commit into
linuxdeepin:masterfrom
re2zero:bugfix

Conversation

@re2zero
Copy link
Copy Markdown
Contributor

@re2zero re2zero commented Jul 7, 2025

Add more logs for base and service. 77.11%

Log: More logs for base and service.

Summary by Sourcery

Add extensive debug logging throughout the disk manager codebase to improve observability of operations and ease troubleshooting.

Enhancements:

  • Add qDebug logging to PartedCore methods for DBus calls, partitioning and disk operations
  • Add logging in DiskManagerService to trace authorization, method entry and exit
  • Add debug output in DeviceStorage to record hardware info parsing from hwinfo, lsblk, smartctl and lshw
  • Instrument LVMOperator and LUKSOperator with logs around command execution, error handling and mapping workflows
  • Add logs in Utils for command execution, regex matching, size formatting and other utility functions
  • Instrument all filesystem handlers (XFS, NTFS, Btrfs, FAT16, Ext2/3/4, exFAT, LinuxSwap) with support detection and operation tracing
  • Add logging in MountInfo, thread classes (ProbeThread, WorkThread, FixThread, LVMThread), BlockSpecial and ProcPartitionsInfo for lifecycle and data flow tracing

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jul 7, 2025

Reviewer's Guide

The PR instruments the disk management service and core libraries with extensive qDebug/qWarning logging around method entry/exit, branch points, error conditions, and external command invocations to improve runtime observability and aid debugging.

Sequence diagram for logging in DiskManagerService public API methods

sequenceDiagram
    participant User as actor User
    participant DMS as DiskManagerService
    participant PC as PartedCore
    User->>DMS: Call public API method (e.g., mount, unmount, create)
    DMS->>DMS: qDebug() log method entry
    DMS->>DMS: checkAuthorization()
    alt Not authorized
        DMS->>DMS: qDebug() log authorization failure
        DMS-->>User: Return error/false
    else Authorized
        DMS->>PC: Call corresponding PartedCore method
        DMS->>DMS: qDebug() log before/after call
        DMS-->>User: Return result
    end
Loading

Sequence diagram for logging in Utils::findProgramInPath and command execution

sequenceDiagram
    participant Caller
    participant Utils
    Caller->>Utils: findProgramInPath(proName)
    Utils->>Utils: qDebug() log entry and proName
    alt proName is empty
        Utils->>Utils: qDebug() log empty program name
        Utils-->>Caller: Return empty string
    else proName not empty
        Utils->>Utils: Execute command
        Utils-->>Caller: Return result
    end
Loading

Sequence diagram for logging in PartedCore::getDevice

sequenceDiagram
    participant PC as PartedCore
    participant Ped as PedDevice
    PC->>PC: qDebug() log BEGIN with devicePath
    PC->>Ped: ped_device_get(devicePath)
    alt Device found
        PC->>PC: qDebug() log device found
        alt flush
            PC->>PC: flushDevice
        end
        PC->>PC: qDebug() log END, device found
        PC-->>Caller: Return true
    else Device not found
        PC->>PC: qDebug() log END, device not found
        PC-->>Caller: Return false
    end
Loading

Class diagram for logging additions in DiskManagerService and Utils

classDiagram
class DiskManagerService {
  +initConnection()
  +Quit()
  +Start()
  +getDeviceinfo()
  +getalldevice()
  +onGetAllDeviceInfomation()
  +setCurSelect(info)
  +unmount()
  +mount(mountpath)
  +deCrypt(luks)
  +cryptMount(luks)
  +cryptUmount(luks)
  +getallsupportfs()
  +format(fstype, name)
  +clear(wipe)
  +resize(info)
  +create(infovec)
  +onGetDeviceHardInfo(devicepath)
  +onGetDeviceHardStatus(devicepath)
  +onGetDeviceHardStatusInfo(devicepath)
  +onDeletePartition()
  +onHidePartition()
  +onShowPartition()
  +onDetectionPartitionTableError(devicePath)
  +onCreatePartitionTable(devicePath, ...)
  +onCheckBadBlocksCount(devicePath, ...)
  +onCheckBadBlocksTime(devicePath, ...)
  +onFixBadBlocks(devicePath, ...)
  +onCreateVG(vgName, devList, size)
  +onCreateLV(vgName, lvList)
  +onDeleteVG(vglist)
  +onDeleteLV(lvlist)
  +onResizeVG(vgName, devList, size)
  +onResizeLV(lvAction)
  +onMountLV(lvAction)
  +onUmountLV(lvAction)
  +onClearLV(lvAction)
  +onDeletePVList(devList)
  <<logging: qDebug() at entry, exit, and error branches>>
}

class Utils {
  +findProgramInPath(proName)
  +executCmd(strCmd, outPut, error)
  +executWithInputOutputCmd(strCmdArg, inPut, outPut, error)
  +regexpLabel(strText, strPatter)
  +getPartitionTypeString(type)
  +fileSystemTypeToString(type)
  +getFileSystemSoftWare(fileSystemType)
  +formatSize(sectors, sectorSize)
  +sectorToUnit(sectors, sectorSize, sizeUnit)
  +getMaxPartitionNameLength(tableType)
  +LVMFormatSize(lvmSize)
  +LVMSizeToUnit(lvmSize, sizeUnit)
  +adjudicationPVDelete(lvmInfo, pvStrList, bigDataMove, realMovePvList)
  +getCipherStr(cipher)
  +getCipher(cipher)
  <<logging: qDebug() at entry, exit, and branch points>>
}
Loading

Class diagram for logging additions in PartedCore

classDiagram
class PartedCore {
  +getDeviceinfo()
  +getAllDeviceinfo()
  +getAllLVMinfo()
  +getAllLUKSinfo()
  +getallsupportfs()
  +getDeviceHardInfo(devicepath)
  +getDeviceHardStatus(devicepath)
  +getDeviceHardStatusInfo(devicepath)
  +createPartitionTable(devicePath, ...)
  +detectionPartitionTableError(devicePath)
  +create(infovec)
  +format(fstype, name)
  +clear(wipe)
  +resize(info)
  +deletePartition()
  +showPartition()
  +hidePartition()
  +setCurSelect(info)
  +mountAndWriteFstab(mountpath, mountUid)
  +unmount()
  +cryptMount(luks)
  +cryptUmount(luks)
  +deCrypt(luks)
  +updateUsb()
  +updateUsbRemove()
  +checkBadBlocks(devicePath, ...)
  +fixBadBlocks(devicePath, ...)
  +refreshFunc()
  +createVG(vgName, devList, size)
  +deleteVG(vglist)
  +createLV(vgName, lvList)
  +deleteLV(lvlist)
  +resizeVG(vgName, devList, size)
  +resizeLV(lvAct)
  +mountLV(lvAction)
  +umountLV(lvAction)
  +clearLV(lvAction)
  +deletePVList(devList)
  +test()
  +setDeviceFromDisk(device, devicePath)
  +useableDevice(lpDevice)
  +delTempMountFile()
  +initConnection()
  +findSupportedCore()
  +setDeviceSerialNumber(device)
  +gptIsExpanded(devicePath)
  +autoMount()
  +autoUmount()
  +probeDeviceInfo(...)
  +onRefreshDeviceInfo(type, arg1, arg2)
  +syncDeviceInfo(...)
  +secuClear(path, start, end, size, fstype, name, count)
  +getDevice(devicePath, lpDevice, flush)
  +getDisk(lpDevice, lpDisk, strict)
  +getDeviceAndDisk(devicePath, lpDevice, lpDisk, strict, flush)
  +destroyDeviceAndDisk(lpDevice, lpDisk)
  +isBusy(fstype, path, lpPartition)
  +flushDevice(lpDevice)
  +commit(lpDisk)
  +commitToOs(lpDisk)
  +infoBelongToPartition(partition, info)
  +getLpPartition(lpDisk, partition)
  +setDeviceOnePartition(device, lpDevice, fstype)
  +setPartitionLabelAndUuid(partition)
  +setMountPoints(partition)
  +setMountPointsHelper(partition, path)
  <<logging: qDebug() at entry, exit, and branch points>>
}
Loading

File-Level Changes

Change Details Files
Instrument PartedCore with detailed debug traces
  • Log entry/exit of all public and internal methods
  • Trace key branches (e.g., nvme path parsing, smartctl fallbacks)
  • Log command invocations, return statuses and decision outcomes
service/diskoperation/partedcore.cpp
Add debug logs to DiskManagerService DBus handlers
  • Log method entry/exit and invoked parameters
  • Log authorization failures
  • Log signal emissions and returned statuses
service/diskmanagerservice.cpp
Enhance DeviceStorage information gathering with logs
  • Log hwinfo and lshw parsing steps
  • Log smartctl/lsblk calls and parsed values
  • Log media type and interface determinations
service/diskoperation/DeviceStorage.cpp
Log LVM operator workflows and error paths
  • Log start/end of create/delete/resize VG and LV operations
  • Log PV create/move/remove steps
  • Log error return codes and abort conditions
service/diskoperation/lvmoperator/lvmoperator.cpp
Instrument utility functions for command execution
  • Log command and arguments in executCmd and wrappers
  • Log regex matches and extracted groups
  • Log conversion and formatting functions entry/exit
basestruct/utils.cpp
Add logging to filesystem modules
  • Log detection of external tools and supported features
  • Log usage calculations and parsing for XFS, NTFS, EXT2, FAT16, Btrfs, ExFAT, LinuxSwap
  • Log create/resize/check method entry and results
service/diskoperation/filesystems/xfs.cpp
service/diskoperation/filesystems/ntfs.cpp
service/diskoperation/filesystems/ext2.cpp
service/diskoperation/filesystems/fat16.cpp
service/diskoperation/filesystems/btrfs.cpp
service/diskoperation/filesystems/exfat.cpp
service/diskoperation/filesystems/linuxswap.cpp
Trace mounting, partition and caching subsystems
  • Log mountinfo parsing from /proc and mount command
  • Log BlockSpecial major/minor resolution and comparisons
  • Log FsInfo cache load and blkid label/uuid lookups
  • Log Partition and PartitionInfo getters/setters
service/diskoperation/mountinfo.cpp
service/diskoperation/blockspecial.cpp
service/diskoperation/procpartitionsinfo.cpp
service/diskoperation/fsinfo.cpp
basestruct/partitioninfo.cpp
service/diskoperation/partition.cpp
Add logging to threading, service initialization, and serialization
  • Log WorkThread and FixThread operations and stop flags
  • Log main() argument handling and environment setup
  • Log supportedfilesystems cleanup and detection
  • Log QDBusArgument serialization stubs for DeviceInfo, PartitionInfo, LVM, LUKS
service/main.cpp
service/diskoperation/thread.cpp
service/diskoperation/supportedfilesystems.cpp
basestruct/deviceinfo.cpp
basestruct/partitioninfo.cpp

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

Copy link
Copy Markdown

@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 @re2zero - I've reviewed your changes - here's some feedback:

  • This change introduces a massive number of qDebug calls; consider using QLoggingCategory or a custom logging wrapper so you can control verbosity and disable debug logs in release builds.
  • Many of these debug statements are very low-level and repetitive; try consolidating key lifecycle events instead of tracing every branch to reduce log noise.
  • Remove commented-out or duplicate log lines, and consider grouping related logs behind a single entry to keep the code and logs clean and maintainable.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- This change introduces a massive number of qDebug calls; consider using QLoggingCategory or a custom logging wrapper so you can control verbosity and disable debug logs in release builds.
- Many of these debug statements are very low-level and repetitive; try consolidating key lifecycle events instead of tracing every branch to reduce log noise.
- Remove commented-out or duplicate log lines, and consider grouping related logs behind a single entry to keep the code and logs clean and maintainable.

## Individual Comments

### Comment 1
<location> `basestruct/utils.cpp:27` </location>
<code_context>
 QString Utils::findProgramInPath(const QString &proName)
 {
     qDebug() << "Utils::findProgramInPath----" << proName;
-    if (proName.isEmpty())
+    if (proName.isEmpty()) {
+        qDebug() << "Program name is empty";
         return QString();
+    }
</code_context>

<issue_to_address>
Debug output in utility functions may clutter logs.

Since these functions are called often, excessive debug output can flood logs. Please minimize or conditionally enable debug statements here.

Suggested implementation:

```cpp
#ifdef UTILS_DEBUG
    qDebug() << "Utils::findProgramInPath----" << proName;
#endif
    if (proName.isEmpty()) {
#ifdef UTILS_DEBUG
        qDebug() << "Program name is empty";
#endif
        return QString();
    }

```

```cpp
    for (int i = 1; i < cmdList.size(); i++) {
        if (!cmdList[i].isEmpty()) {
#ifdef UTILS_DEBUG
            qDebug() << "Appending argument:" << cmdList[i];
#endif
            argList.append(cmdList[i]);
        }
    }

```

To enable debug output, define the `UTILS_DEBUG` macro (e.g., by adding `-DUTILS_DEBUG` to your compiler flags). Otherwise, debug output will be suppressed.
</issue_to_address>

### Comment 2
<location> `service/diskoperation/filesystems/ntfs.cpp:76` </location>
<code_context>
     QString cmd = QString("ntfsinfo --mft --force %1").arg(partition.getPath());

     if (!Utils::executCmd(cmd, output, error)) {
+        qDebug() << "ntfsinfo executed successfully.";
         strmatch = "Cluster Size:";
</code_context>

<issue_to_address>
The logic for checking ntfsinfo command success is inverted.

The current check executes the success block when the command fails, which is counterintuitive and may cause confusion or bugs. Please invert the logic or clarify with a comment.
</issue_to_address>

### Comment 3
<location> `service/diskoperation/filesystems/ntfs.cpp:164` </location>
<code_context>
         exitcode = Utils::executCmd(QString("mkntfs -Q -v -F %1 -L %2").arg(newPartition.getPath()).arg(newPartition.getFileSystemLabel()),output, error);
     }
-    return exitcode == 0 && error.compare("Unknown error") == 0;
+    bool success = (exitcode == 0 && error.compare("Unknown error") == 0);
+    qDebug() << "[NTFS]::create - Exit with status:" << success;
+    return success;
</code_context>

<issue_to_address>
The NTFS create function only returns true if error is exactly 'Unknown error'.

The current condition may incorrectly report failures when the command succeeds but the error string differs. It's better to return true based solely on `exitcode == 0`.
</issue_to_address>

### Comment 4
<location> `service/diskoperation/filesystems/ntfs.cpp:146` </location>
<code_context>
     qDebug() << "[NTFS]::writeUuid - Enter";
     QString output, error;
     int exitcode = Utils::executCmd(QString("ntfslabel --new-serial ").arg(partition.getPath()), output, error);
-    return exitcode == 0 || error.compare("Unknown error") == 0;
-    qDebug() << "[NTFS]::writeUuid - Exit";
</code_context>

<issue_to_address>
The ntfslabel command string is missing a placeholder for the device path.

The command string should include a '%1' placeholder so that the device path is correctly inserted and the command operates on the intended device.
</issue_to_address>

### Comment 5
<location> `service/diskoperation/filesystems/ntfs.cpp:118` </location>
<code_context>
     qDebug() << "[NTFS]::readLabel - Enter";
     QString output, error;
     if (!Utils::executCmd(QString("ntfslabel --force").arg(partition.getPath()), output, error)) {
+        qDebug() << "Successfully read label:" << output.trimmed();
         partition.setFilesystemLabel(output.trimmed());
</code_context>

<issue_to_address>
The ntfslabel command for reading label is missing the device path.

`ntfslabel --force` is run without a device path, which may cause it to fail. Please include the device path in the command.
</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.

Comment thread basestruct/utils.cpp Outdated
@@ -65,33 +74,36 @@ void NTFS::setUsedSectors( Partition & partition )
QString cmd = QString("ntfsinfo --mft --force %1").arg(partition.getPath());

if (!Utils::executCmd(cmd, output, error)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: The logic for checking ntfsinfo command success is inverted.

The current check executes the success block when the command fails, which is counterintuitive and may cause confusion or bugs. Please invert the logic or clarify with a comment.

exitcode = Utils::executCmd(QString("mkntfs -Q -v -F %1 -L %2").arg(newPartition.getPath()).arg(newPartition.getFileSystemLabel()),output, error);
}
return exitcode == 0 && error.compare("Unknown error") == 0;
bool success = (exitcode == 0 && error.compare("Unknown error") == 0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): The NTFS create function only returns true if error is exactly 'Unknown error'.

The current condition may incorrectly report failures when the command succeeds but the error string differs. It's better to return true based solely on exitcode == 0.

Comment thread service/diskoperation/filesystems/ntfs.cpp Outdated
Comment thread service/diskoperation/filesystems/ntfs.cpp Outdated
Add more logs for base and service. 77.11%

Log: More logs for base and service.
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@re2zero re2zero merged commit c19111f into linuxdeepin:master Jul 7, 2025
16 of 17 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