[pbs-devel] [PATCH proxmox-backup 3/6] add a CACHE_DIR to the created directories on daemon startup

Dominik Csapak d.csapak at proxmox.com
Wed Mar 31 11:44:15 CEST 2021


we can use this for having a semi-persistent file cache

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/bin/proxmox-backup-api.rs | 2 +-
 src/buildcfg.rs               | 6 ++++++
 src/server/worker_task.rs     | 9 +++++----
 tests/worker-task-abort.rs    | 2 +-
 4 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs
index 7d800259..6e813414 100644
--- a/src/bin/proxmox-backup-api.rs
+++ b/src/bin/proxmox-backup-api.rs
@@ -30,7 +30,7 @@ async fn run() -> Result<(), Error> {
         bail!("unable to inititialize syslog - {}", err);
     }
 
-    server::create_task_log_dirs()?;
+    server::create_dirs()?;
 
     config::create_configdir()?;
 
diff --git a/src/buildcfg.rs b/src/buildcfg.rs
index 4f333288..40625fad 100644
--- a/src/buildcfg.rs
+++ b/src/buildcfg.rs
@@ -7,12 +7,18 @@ pub const JS_DIR: &str = "/usr/share/javascript/proxmox-backup";
 #[macro_export]
 macro_rules! PROXMOX_BACKUP_RUN_DIR_M { () => ("/run/proxmox-backup") }
 
+#[macro_export]
+macro_rules! PROXMOX_BACKUP_CACHE_DIR_M { () => ("/var/cache/proxmox-backup") }
+
 #[macro_export]
 macro_rules! PROXMOX_BACKUP_LOG_DIR_M { () => ("/var/log/proxmox-backup") }
 
 /// namespaced directory for in-memory (tmpfs) run state
 pub const PROXMOX_BACKUP_RUN_DIR: &str = PROXMOX_BACKUP_RUN_DIR_M!();
 
+/// namespaced directory for on-disk file caches
+pub const PROXMOX_BACKUP_CACHE_DIR: &str = PROXMOX_BACKUP_CACHE_DIR_M!();
+
 /// namespaced directory for persistent logging
 pub const PROXMOX_BACKUP_LOG_DIR: &str = PROXMOX_BACKUP_LOG_DIR_M!();
 
diff --git a/src/server/worker_task.rs b/src/server/worker_task.rs
index 6c5456c9..8e072526 100644
--- a/src/server/worker_task.rs
+++ b/src/server/worker_task.rs
@@ -153,8 +153,8 @@ fn parse_worker_status_line(line: &str) -> Result<(String, UPID, Option<TaskStat
     }
 }
 
-/// Create task log directory with correct permissions
-pub fn create_task_log_dirs() -> Result<(), Error> {
+/// Create necessary directories with correct permissions
+pub fn create_dirs() -> Result<(), Error> {
 
     try_block!({
         let backup_user = crate::backup::backup_user()?;
@@ -164,9 +164,10 @@ pub fn create_task_log_dirs() -> Result<(), Error> {
 
         create_path(buildcfg::PROXMOX_BACKUP_LOG_DIR, None, Some(opts.clone()))?;
         create_path(PROXMOX_BACKUP_TASK_DIR, None, Some(opts.clone()))?;
-        create_path(buildcfg::PROXMOX_BACKUP_RUN_DIR, None, Some(opts))?;
+        create_path(buildcfg::PROXMOX_BACKUP_RUN_DIR, None, Some(opts.clone()))?;
+        create_path(buildcfg::PROXMOX_BACKUP_CACHE_DIR, None, Some(opts))?;
         Ok(())
-    }).map_err(|err: Error| format_err!("unable to create task log dir - {}", err))?;
+    }).map_err(|err: Error| format_err!("unable to create dirs - {}", err))?;
 
     Ok(())
 }
diff --git a/tests/worker-task-abort.rs b/tests/worker-task-abort.rs
index 1a0d938d..a68ab1aa 100644
--- a/tests/worker-task-abort.rs
+++ b/tests/worker-task-abort.rs
@@ -32,7 +32,7 @@ fn garbage_collection(worker: &server::WorkerTask) -> Result<(), Error> {
 #[test] #[ignore]
 fn worker_task_abort() -> Result<(), Error> {
 
-    server::create_task_log_dirs()?;
+    server::create_dirs()?;
 
     use std::sync::{Arc, Mutex};
 
-- 
2.20.1






More information about the pbs-devel mailing list