Skip to content

fix: Improve ext* filesystem usage display logic#158

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/1071from
itsXuSt:1071
Jul 10, 2025
Merged

fix: Improve ext* filesystem usage display logic#158
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/1071from
itsXuSt:1071

Conversation

@itsXuSt
Copy link
Copy Markdown
Contributor

@itsXuSt itsXuSt commented Jul 9, 2025

​​Changes​​:
​1. ​Reserved space handling​​

  • Now counts reserved blocks as ​​used space​​ for ext2/3/4 filesystems
  • Matches behavior of standard tools like df
    ​2. ​Mounted device detection​​
  • Uses stat-based calculation for ​​accurate free space​​ on mounted devices
  • Falls back to previous method for unmounted devices

​​Technical Impact​​:

  • Fixes discrepancy between displayed and actual available space
  • Provides more consistent behavior with system utilities

​​Log:​​ Improved ext* filesystem space calculation accuracy

Bug: https://pms.uniontech.com/bug-view-323359.html

Summary by Sourcery

Improve ext* filesystem usage reporting by accounting for reserved blocks and using statvfs data for mounted partitions to align displayed values with actual available space.

Bug Fixes:

  • Include reserved blocks in ext2/3/4 space calculation to match system utilities.
  • Use statvfs’s available-block count for mounted devices to report accurate free space.

Enhancements:

  • Refactor ext* filesystem usage logic to parse block metadata from dumpe2fs header.
  • Simplify free-space computation by unifying handling of free and reserved blocks.
  • Adjust getMountedFileSystemUsage to multiply by f_bsize and use f_bavail for free space.

Changes:
1. Reserved space handling
- Now counts reserved blocks as used space for ext2/3/4 filesystems
- Matches behavior of standard tools like df
2. Mounted device detection
- Uses stat-based calculation for accurate free space on mounted devices
- Falls back to previous method for unmounted devices

Technical Impact:
- Fixes discrepancy between displayed and actual available space
- Provides more consistent behavior with system utilities

Log: Improved ext* filesystem space calculation accuracy

Bug: https://pms.uniontech.com/bug-view-323359.html
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jul 9, 2025

Reviewer's Guide

This PR refactors the ext* filesystem space calculation to parse and account for reserved blocks from dumpe2fs output, converts all metrics to sector units, and—when a partition is mounted—leverages statvfs for more accurate free‐space reporting; it also corrects statvfs field usage in Utils to match system utilities.

Class diagram for updated EXT2 usage calculation

classDiagram
    class EXT2 {
        +void setUsedSectors(Partition &partition)
        -long long blockCount
        -long long blockSize
        -long long freeBlocks
        -long long reservedBlocks
        -Sector totalSectors
        -Sector availableSectors
        -Sector statAvailableSectors
    }
    class Partition {
        +QString getPath()
        +QString getMountPoint()
        +bool m_busy
        +QList<QString> getMountPoints()
        +void setSectorUsage(Sector total, Sector available)
        +int m_sectorSize
        +int m_fsBlockSize
    }
    class Utils {
        +static bool executCmd(QString, QString&, QString&)
        +static int getMountedFileSystemUsage(QString, Byte_Value&, Byte_Value&)
        +static QString regexpLabel(QString, QString)
    }
    EXT2 --> Partition : uses
    EXT2 --> Utils : uses
    Utils --> Partition : uses mountpoint
Loading

Flow diagram for ext* filesystem usage calculation logic

flowchart TD
    A[Start setUsedSectors] --> B{Partition mounted?}
    B -- Yes --> C[Call getMountedFileSystemUsage]
    C --> D[Use statvfs: f_bsize, f_bavail]
    D --> E[Set sector usage with stat data]
    B -- No --> F[Parse dumpe2fs output]
    F --> G[Calculate userAvailableBlocks = freeBlocks - reservedBlocks]
    G --> H[Convert to sector units]
    H --> I[Set sector usage with calculated data]
    E --> J[End]
    I --> J[End]
Loading

File-Level Changes

Change Details Files
Unified parsing of dumpe2fs output and reserved‐block accounting
  • Extract Block count, Block size, Free blocks and Reserved block count via regexp
  • Subtract reserved blocks from free blocks to get user‐available blocks
  • Convert block counts to sectors before reporting usage
  • Add debug logging for all intermediate values
  • Simplify fallback logic by removing resize2fs path
service/diskoperation/filesystems/ext2.cpp
Mounted partition detection now prefers statvfs over dumpe2fs
  • Check partition.m_busy and mountPoints to detect mounted state
  • Call Utils::getMountedFileSystemUsage for statvfs‐based totals and available space
  • Fallback to dumpe2fs-derived calculation if statvfs call fails
service/diskoperation/filesystems/ext2.cpp
Correct statvfs field usage in Utils::getMountedFileSystemUsage
  • Compute total size using sfs.f_blocks * sfs.f_bsize instead of f_frsize
  • Compute available space using sfs.f_bavail * sfs.f_bsize instead of f_bfree
basestruct/utils.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

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

代码审查意见:

  1. .gitignore 文件修改:

    • 新增的 build*.cache/**.claude/* 规则可能会影响构建过程和缓存文件的管理,需要确认这些规则是否符合项目的构建和部署流程。
  2. utils.cpp 文件修改:

    • statvfs 函数中,fileSystemFree 变量的计算已从 sfs.f_bfree 改为 sfs.f_bavail,这可能是为了获取未分配给超级用户的块数。需要确认这一改动是否符合预期,并确保所有相关的代码都已更新以反映这一变化。
  3. ext2.cpp 文件修改:

    • EXT2::setUsedSectors 函数中,新增了多个变量来存储从 dumpe2fs 命令输出中提取的信息,这有助于提高代码的可读性和可维护性。
    • 新增了对 blockCountblockSizefreeBlocksreservedBlocks 的有效性检查,确保在进行计算之前这些值都是有效的。
    • 增加了 qDebug 输出,用于调试和记录计算过程中的关键信息,这在开发和调试阶段非常有用,但在生产环境中可能需要移除或禁用。
    • 如果分区已挂载,代码会使用 stat 命令获取更准确的可用块数,这有助于提高数据的准确性。需要确保 Utils::getMountedFileSystemUsage 函数的实现是正确的,并且能够处理所有可能的错误情况。

总体来说,代码的修改提高了代码的可读性和健壮性,但需要注意以下几点:

  • 确认所有新增的 qDebug 输出在生产环境中是否应该被移除或禁用。
  • 确保所有修改后的代码都已经通过了充分的测试,特别是那些涉及到文件系统操作的部分。
  • 如果 Utils::executCmdUtils::regexpLabel 函数的实现有变化,需要确保这些变化已经反映在所有相关的调用中。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: itsXuSt, max-lvs

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

@itsXuSt
Copy link
Copy Markdown
Contributor Author

itsXuSt commented Jul 10, 2025

/merge

@deepin-bot deepin-bot Bot merged commit 93a5108 into linuxdeepin:release/1071 Jul 10, 2025
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