From 17de267e417ed6c2d6c6a99fee172dc64b48170e Mon Sep 17 00:00:00 2001 From: deepin Date: Thu, 29 Oct 2026 11:38:55 +0800 Subject: [PATCH] fix: add watchdog timer for mkfs progress stuck at 99% MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: mkfs quick format uses simulated progress timer that caps at 0.99; completion relies solely on DUDisksJob::completed signal which may not fire for large drives (1TB+ ext3) 2. Fix: after progress reaches 0.99, start a 5s watchdog timer that checks if the specific device's mkfs process is still running via pgrep -f with the device path; if exited, force-complete the flow 3. Impact: only activates when completed signal fails to arrive; normal formatting path is unaffected; watchdog has 5min max retry Log: fix format progress stuck at 99% for large drives Influence: 1. Test formatting with small USB drive (normal path) 2. Test formatting with large drive (1TB+) using ext3 3. Verify progress completes to 100% when mkfs finishes 4. Test concurrent formatting of multiple devices fix: 修复大容量磁盘格式化进度卡在99%的问题 1. 根因:mkfs快速格式化使用模拟进度计时器,上限为0.99;完成 仅依赖DUDisksJob::completed信号,大容量磁盘(1TB+)该信号可能不触发 2. 方案:进度到达0.99后启动5秒看门狗计时器,通过pgrep -f结合 设备路径检测对应mkfs进程是否退出;若已退出则强制完成格式化流程 3. 影响:仅在completed信号未到达时激活,不影响正常格式化路径; 看门狗最大重试5分钟后超时失败 Log: 修复大容量磁盘格式化进度卡在99%的问题 Influence: 1. 测试小容量U盘格式化(正常路径) 2. 测试大容量磁盘(1TB+) ext3格式化 3. 验证mkfs完成后进度能推进到100% 4. 测试多设备并发格式化场景 Bug: #291279 --- view/mainwindow.cpp | 26 +++++++++++++++++++++----- view/mainwindow.h | 4 +++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/view/mainwindow.cpp b/view/mainwindow.cpp index 870efc6..f629d6a 100755 --- a/view/mainwindow.cpp +++ b/view/mainwindow.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2016 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "dialogs/messagedialog.h" #include "utils/udisksutils.h" @@ -117,13 +118,28 @@ void MainWindow::initConnect() else if (m_job->operation().contains("mkfs")) { QTimer *timer = new QTimer(); m_simulationProgressValue = 0; + m_watchdogRetryCount = 0; connect(timer, &QTimer::timeout, [this, timer]() { - m_simulationProgressValue += 0.06; if (m_simulationProgressValue < 1) { - timer->start(300); - m_formatingPage->setProgress(m_simulationProgressValue); + m_simulationProgressValue += 0.06; + if (m_simulationProgressValue < 1) { + m_formatingPage->setProgress(m_simulationProgressValue); + } else { + m_formatingPage->setProgress(0.99); + timer->start(5000); + } } else { - m_formatingPage->setProgress(0.99); + int ret = QProcess::execute("pgrep", QStringList() << "-f" << QString("mkfs.*%1").arg(m_formatPath)); + if (ret == 1) { + timer->stop(); + m_formatingPage->setProgress(1); + disconnect(m_job.data(), &DUDisksJob::completed, nullptr, nullptr); + this->onFormatingFinished(true); + } else if (++m_watchdogRetryCount >= 60) { + timer->stop(); + disconnect(m_job.data(), &DUDisksJob::completed, nullptr, nullptr); + this->onFormatingFinished(false); + } } }); timer->start(300); diff --git a/view/mainwindow.h b/view/mainwindow.h index 85701da..688d646 100755 --- a/view/mainwindow.h +++ b/view/mainwindow.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2016 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -85,6 +85,8 @@ public slots: //模拟进度值 double m_simulationProgressValue; + //看门狗重试计数 + int m_watchdogRetryCount = 0; }; #endif // DIALOG_H