From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 2A44B1FF15E for ; Mon, 29 Sep 2025 11:52:48 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9BC12E412; Mon, 29 Sep 2025 11:52:53 +0200 (CEST) From: Filip Schauer To: pbs-devel@lists.proxmox.com Date: Mon, 29 Sep 2025 11:52:31 +0200 Message-ID: <20250929095236.38251-2-f.schauer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250929095236.38251-1-f.schauer@proxmox.com> References: <20250929095236.38251-1-f.schauer@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1759139551545 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.007 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox v3 1/2] fix #5946: rest-server: worker_task: detect task status on multi-line message X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Properly detect the status of a task when the last log message spans over multiple lines. This fixes task status detection in Proxmox Backup Server when the directory creation task fails during creation of the partition on disk. With this fix the status becomes: TaskState::Error { message: "command "sgdisk" "-n1" "-t1:8300" "/dev/sdc" failed - status code: 2 - Caution: invalid main GPT header, but valid backup; regenerating main header" } instead of TaskState::Unknown. Signed-off-by: Filip Schauer --- proxmox-rest-server/src/worker_task.rs | 35 +++++++++++--------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs index a3a65add..c9ae5243 100644 --- a/proxmox-rest-server/src/worker_task.rs +++ b/proxmox-rest-server/src/worker_task.rs @@ -464,29 +464,22 @@ pub fn upid_read_status(upid: &UPID) -> Result { data.pop(); } - let last_line = match data.iter().rposition(|c| *c == b'\n') { - Some(start) if data.len() > (start + 1) => &data[start + 1..], - Some(_) => &data, // should not happen, since we removed all trailing newlines - None => &data, - }; - - let last_line = std::str::from_utf8(last_line) - .map_err(|err| format_err!("upid_read_status: utf8 parse failed: {}", err))?; - - let mut endtime = upid.starttime; // as fallback - let mut iter = last_line.splitn(2, ": "); - if let Some(time_str) = iter.next() { - if let Ok(parsed_endtime) = proxmox_time::parse_rfc3339(time_str) { - endtime = parsed_endtime; // save last found time for when the state cannot be parsed - if let Some(rest) = iter.next().and_then(|rest| rest.strip_prefix("TASK ")) { - if let Ok(state) = TaskState::from_endtime_and_message(parsed_endtime, rest) { - return Ok(state); - } - } + let state = data.rsplit(|&c| c == b'\n').find_map(|line| { + let line_str = std::str::from_utf8(line).ok()?; + let mut parts = line_str.splitn(2, ": "); + let time_str = parts.next()?; + let endtime = proxmox_time::parse_rfc3339(time_str).ok()?; + if let Some(rest) = parts.next().and_then(|rest| rest.strip_prefix("TASK ")) { + Some(TaskState::from_endtime_and_message(endtime, rest).ok()?) + } else { + // no last line with both, end-time and task-state, found. + Some(TaskState::Unknown { endtime }) } - } + }); - Ok(TaskState::Unknown { endtime }) // no last line with both, end-time and task-state, found. + Ok(state.unwrap_or(TaskState::Unknown { + endtime: upid.starttime, + })) } static WORKER_TASK_LIST: LazyLock>>> = -- 2.47.3 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel