From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 6AF3891D15 for ; Tue, 4 Apr 2023 13:21:25 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 408211B4F3 for ; Tue, 4 Apr 2023 13:21:25 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 4 Apr 2023 13:21:24 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 752AD45945 for ; Tue, 4 Apr 2023 13:21:24 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Tue, 4 Apr 2023 13:21:15 +0200 Message-Id: <20230404112115.184009-2-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230404112115.184009-1-f.gruenbichler@proxmox.com> References: <20230404112115.184009-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.071 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: [pve-devel] [PATCH proxmox-offline-mirror 2/2] fix #4261: allow GC for all configured mirrors X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Apr 2023 11:21:25 -0000 by making the --id parameter optional, and structuring the output accordingly. since pools are per base-dir, GC only needs to run once per base-dir instead of for each mirror entry. Signed-off-by: Fabian Grünbichler --- src/bin/proxmox_offline_mirror_cmds/mirror.rs | 52 +++++++++++++++++-- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/src/bin/proxmox_offline_mirror_cmds/mirror.rs b/src/bin/proxmox_offline_mirror_cmds/mirror.rs index a3fb258..07db92f 100644 --- a/src/bin/proxmox_offline_mirror_cmds/mirror.rs +++ b/src/bin/proxmox_offline_mirror_cmds/mirror.rs @@ -4,7 +4,7 @@ use proxmox_section_config::SectionConfigData; use proxmox_subscription::SubscriptionStatus; use serde_json::Value; use std::{ - collections::{BTreeMap, HashMap}, + collections::{BTreeMap, HashMap, HashSet}, path::PathBuf, }; @@ -285,6 +285,7 @@ async fn remove_snapshot( }, id: { schema: MIRROR_ID_SCHEMA, + optional: true, }, "output-format": { schema: OUTPUT_FORMAT, @@ -293,14 +294,55 @@ async fn remove_snapshot( } }, )] -/// Run Garbage Collection on pool -async fn garbage_collect(config: Option, id: String, _param: Value) -> Result<(), Error> { +/// Run Garbage Collection on pool(s). If no `id` is specified, the pools of all configured mirrors +/// will be GCed. +async fn garbage_collect( + config: Option, + id: Option, + _param: Value, +) -> Result<(), Error> { let config = config.unwrap_or_else(get_config_path); let (config, _digest) = proxmox_offline_mirror::config::config(&config)?; - let config: MirrorConfig = config.lookup("mirror", &id)?; - let (count, size) = mirror::gc(&config)?; + let (count, size) = if let Some(id) = id { + let config: MirrorConfig = config.lookup("mirror", &id)?; + mirror::gc(&config)? + } else { + let mut total_count = 0; + let mut total_size = 0; + let mut error_count = 0; + let mut base_dirs = HashSet::new(); + + for mirror_config in config.convert_to_typed_array::("mirror")? { + if base_dirs.insert(mirror_config.base_dir.clone()) { + match mirror::gc(&mirror_config) { + Ok((count, size)) => { + println!( + "{}: removed {count} files totalling {size}b", + mirror_config.id + ); + total_count += count; + total_size += size; + } + Err(err) => { + error_count += 1; + eprintln!("{}: failed to run GC - {err}", mirror_config.id); + } + } + } else { + println!( + "{}: base dir '{}' already GCed", + mirror_config.id, mirror_config.base_dir + ); + } + println!(); + } + if error_count > 0 { + eprintln!("Encountered {error_count} errors, please check log."); + } + (total_count, total_size) + }; println!("Removed {} files totalling {}b", count, size); -- 2.30.2