From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-rrd-migration-tool] fix failure during migration when there are no guest metrics yet
Date: Thu, 31 Jul 2025 10:28:47 +0200 [thread overview]
Message-ID: <20250731082847.1113092-1-l.wagner@proxmox.com> (raw)
If a node never has had any guests on it, the pve2-vm directory does not
exist yet, which led to a failure when attempting to read the contents
of this directory. This is fixed by explicitly checking for a 'not
found' error (we still want to fail for other kinds of errors).
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
src/main.rs | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/main.rs b/src/main.rs
index 6fcdc10..fb58d3a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,6 +2,7 @@ use anyhow::{bail, Error, Result};
use std::{
ffi::{CStr, CString, OsString},
fs,
+ io::ErrorKind,
os::unix::{ffi::OsStrExt, fs::PermissionsExt},
path::{Path, PathBuf},
sync::Arc,
@@ -319,7 +320,15 @@ fn mv_old(file: &str) -> Result<()> {
fn collect_rrd_files(location: &PathBuf) -> Result<Vec<(CString, OsString)>> {
let mut files: Vec<(CString, OsString)> = Vec::new();
- fs::read_dir(location)?
+ let contents = match fs::read_dir(location) {
+ Ok(contents) => contents,
+ Err(e) if e.kind() == ErrorKind::NotFound => {
+ return Ok(files);
+ }
+ Err(e) => return Err(e.into()),
+ };
+
+ contents
.filter(|f| f.is_ok())
.map(|f| f.unwrap().path())
.filter(|f| f.is_file() && f.extension().is_none())
@@ -409,6 +418,11 @@ fn migrate_guests(
let guest_source_files = collect_rrd_files(&source_dir_guests)?;
+ if guest_source_files.is_empty() {
+ println!("No guest metrics to migrate");
+ return Ok(());
+ }
+
if !target_dir_guests.exists() && migrate {
println!("Creating new directory: '{}'", target_dir_guests.display());
std::fs::create_dir(&target_dir_guests)?;
--
2.47.2
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next reply other threads:[~2025-07-31 8:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-31 8:28 Lukas Wagner [this message]
2025-08-04 9:30 ` [pve-devel] applied: " Fiona Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250731082847.1113092-1-l.wagner@proxmox.com \
--to=l.wagner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox