diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 049e16ed..ae553eb0 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -509,32 +509,30 @@ fn start_garbage_collection( Ok(json!(upid_str)) } -#[sortable] -pub const API_METHOD_GARBAGE_COLLECTION_STATUS: ApiMethod = ApiMethod::new( - &ApiHandler::Sync(&garbage_collection_status), - &ObjectSchema::new( - "Garbage collection status.", - &sorted!([ - ("store", false, &DATASTORE_SCHEMA), - ]) - ) -); - +#[api( + input: { + properties: { + store: { + schema: DATASTORE_SCHEMA, + }, + }, + }, + returns: { + type: GarbageCollectionStatus, + } +)] +/// Garbage collection status. fn garbage_collection_status( - param: Value, + store: String, _info: &ApiMethod, _rpcenv: &mut dyn RpcEnvironment, -) -> Result { - - let store = param["store"].as_str().unwrap(); +) -> Result { let datastore = DataStore::lookup_datastore(&store)?; - println!("Garbage collection status on store {}", store); - let status = datastore.last_gc_status(); - Ok(serde_json::to_value(&status)?) + Ok(status) } diff --git a/src/api2/types.rs b/src/api2/types.rs index 393c32a6..268ef6ed 100644 --- a/src/api2/types.rs +++ b/src/api2/types.rs @@ -276,6 +276,48 @@ pub struct BackupContent { pub size: Option, } +#[api( + properties: { + "upid": { + optional: true, + schema: UPID_SCHEMA, + }, + }, +)] +#[derive(Clone, Serialize, Deserialize)] +#[serde(rename_all="kebab-case")] +/// Garbage collection status. +pub struct GarbageCollectionStatus { + pub upid: Option, + /// Number of processed index files. + pub index_file_count: usize, + /// Sum of bytes referred by index files. + pub index_data_bytes: u64, + /// Bytes used on disk. + pub disk_bytes: u64, + /// Chunks used on disk. + pub disk_chunks: usize, + /// Sum of removed bytes. + pub removed_bytes: u64, + /// Number of removed chunks. + pub removed_chunks: usize, +} + +impl Default for GarbageCollectionStatus { + fn default() -> Self { + GarbageCollectionStatus { + upid: None, + index_file_count: 0, + index_data_bytes: 0, + disk_bytes: 0, + disk_chunks: 0, + removed_bytes: 0, + removed_chunks: 0, + } + } +} + + #[api()] #[derive(Serialize, Deserialize)] /// Storage space usage information. diff --git a/src/backup/chunk_store.rs b/src/backup/chunk_store.rs index 76a2b3bc..fa9c2710 100644 --- a/src/backup/chunk_store.rs +++ b/src/backup/chunk_store.rs @@ -4,39 +4,15 @@ use std::path::{Path, PathBuf}; use std::io::Write; use std::sync::{Arc, Mutex}; use std::os::unix::io::AsRawFd; -use serde::Serialize; use proxmox::tools::fs::{CreateOptions, create_path, create_dir}; use crate::tools; +use crate::api2::types::GarbageCollectionStatus; + use super::DataBlob; use crate::server::WorkerTask; -#[derive(Clone, Serialize)] -pub struct GarbageCollectionStatus { - pub upid: Option, - pub index_file_count: usize, - pub index_data_bytes: u64, - pub disk_bytes: u64, - pub disk_chunks: usize, - pub removed_bytes: u64, - pub removed_chunks: usize, -} - -impl Default for GarbageCollectionStatus { - fn default() -> Self { - GarbageCollectionStatus { - upid: None, - index_file_count: 0, - index_data_bytes: 0, - disk_bytes: 0, - disk_chunks: 0, - removed_bytes: 0, - removed_chunks: 0, - } - } -} - /// File system based chunk store pub struct ChunkStore { name: String, // used for error reporting diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 47eb1b52..d4ee7dd4 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -8,7 +8,7 @@ use lazy_static::lazy_static; use chrono::{DateTime, Utc}; use super::backup_info::{BackupGroup, BackupDir}; -use super::chunk_store::{ChunkStore, GarbageCollectionStatus}; +use super::chunk_store::ChunkStore; use super::dynamic_index::{DynamicIndexReader, DynamicIndexWriter}; use super::fixed_index::{FixedIndexReader, FixedIndexWriter}; use super::manifest::{MANIFEST_BLOB_NAME, BackupManifest}; @@ -17,6 +17,7 @@ use super::{DataBlob, ArchiveType, archive_type}; use crate::config::datastore; use crate::server::WorkerTask; use crate::tools; +use crate::api2::types::GarbageCollectionStatus; lazy_static! { static ref DATASTORE_MAP: Mutex>> = Mutex::new(HashMap::new());