Skip to content

Commit b01f2bc

Browse files
committed
Add imagestore keepalive
1 parent 8448dec commit b01f2bc

6 files changed

Lines changed: 111 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/raster/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ regex = "1.12.2"
1414
serial_test = "3.2.0"
1515
nix = { version = "0.30.1", features = ["user","fs","signal"] }
1616
is_executable = "1.0.5"
17+
walkdir = "2.5.0"

crates/raster/src/config.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct RawConfig {
1111
edf_system_search_path: Option<String>,
1212
hooks: Option<RawConfigHooks>,
1313
parallax_imagestore: Option<String>,
14+
parallax_imagestore_keepalive: Option<bool>,
1415
parallax_mount_program: Option<String>,
1516
parallax_path: Option<String>,
1617
parallax_mp_uid: Option<u32>,
@@ -40,6 +41,8 @@ pub struct Config {
4041
pub hooks: ConfigHooks,
4142
#[serde(default = "get_default_parallax_imagestore")]
4243
pub parallax_imagestore: String,
44+
#[serde(default = "get_default_parallax_imagestore_keepalive")]
45+
pub parallax_imagestore_keepalive: bool,
4346
#[serde(default = "get_default_parallax_mount_program")]
4447
pub parallax_mount_program: String,
4548
#[serde(default = "get_default_parallax_path")]
@@ -91,6 +94,10 @@ fn get_default_parallax_imagestore() -> String {
9194
return String::from("");
9295
}
9396

97+
fn get_default_parallax_imagestore_keepalive() -> bool {
98+
return false;
99+
}
100+
94101
fn get_default_parallax_mount_program() -> String {
95102
return String::from("");
96103
}
@@ -173,6 +180,10 @@ impl From<RawConfig> for Config {
173180
Some(s) => s,
174181
None => get_default_parallax_imagestore(),
175182
},
183+
parallax_imagestore_keepalive: match r.parallax_imagestore_keepalive {
184+
Some(s) => s,
185+
None => get_default_parallax_imagestore_keepalive(),
186+
},
176187
parallax_mount_program: match r.parallax_mount_program {
177188
Some(s) => s,
178189
None => get_default_parallax_mount_program(),
@@ -245,6 +256,9 @@ impl RawConfig {
245256
if i.parallax_imagestore.is_some() {
246257
self.parallax_imagestore = i.parallax_imagestore;
247258
}
259+
if i.parallax_imagestore_keepalive.is_some() {
260+
self.parallax_imagestore_keepalive = i.parallax_imagestore_keepalive;
261+
}
248262
if i.parallax_mount_program.is_some() {
249263
self.parallax_mount_program = i.parallax_mount_program;
250264
}
@@ -483,6 +497,15 @@ pub fn update_config_by_user(config: &mut Config, edf: EDF) -> SarusResult<()> {
483497
config.parallax_imagestore = parallax_imagestore.unwrap().to_string();
484498
}
485499

500+
let parallax_imagestore_keepalive = edf.annotations.get("com.sarus.parallax_imagestore_keepalive");
501+
if parallax_imagestore_keepalive.is_some() {
502+
config.parallax_imagestore_keepalive = match parallax_imagestore_keepalive.unwrap().as_str() {
503+
"true" => true,
504+
"false" => false,
505+
_ => config.parallax_imagestore_keepalive,
506+
};
507+
}
508+
486509
let parallax_mount_program = edf.annotations.get("com.sarus.parallax_mount_program");
487510
if parallax_mount_program.is_some() {
488511
config.parallax_mount_program = parallax_mount_program.unwrap().to_string();

crates/raster/src/imagestore.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use std::path::Path;
2+
use std::fs::{self, File, FileTimes};
3+
use std::time::{Duration, SystemTime};
4+
use walkdir::WalkDir;
5+
use crate::Config;
6+
7+
pub fn imagestore_keepalive(config: &Config) -> Result<Option<String>,String> {
8+
9+
let output;
10+
let imagestore = &config.parallax_imagestore;
11+
12+
if ! config.parallax_imagestore_keepalive {
13+
return Ok(None);
14+
}
15+
16+
let path = Path::new(&imagestore);
17+
if ! path.exists() {
18+
return Err(format!("imagestore {} doesn't exist", imagestore));
19+
}
20+
21+
let now = SystemTime::now();
22+
let mut num_entries = 0;
23+
let mut upd_entries = 0;
24+
for entry in WalkDir::new(&path) {
25+
num_entries += 1;
26+
27+
// Best effort, skip errors
28+
let Ok(entrystr) = entry else { continue };
29+
let Ok(metadata) = fs::metadata(entrystr.path()) else { continue };
30+
let Ok(atime) = metadata.accessed() else { continue };
31+
32+
// skip if recent
33+
if atime.elapsed().unwrap() < Duration::new(86400, 0) { continue }
34+
35+
// Update atime if old
36+
let Ok(file) = File::open(entrystr.path()) else { continue };
37+
let Ok(mtime) = metadata.modified() else { continue };
38+
let times = FileTimes::new()
39+
.set_accessed(now)
40+
.set_modified(mtime);
41+
match file.set_times(times) {
42+
Ok(_) => (),
43+
Err(_) => continue,
44+
}
45+
upd_entries += 1;
46+
}
47+
output = Some(format!("Keep alive imagestore {}, refreshed {}/{} inodes", imagestore, upd_entries, num_entries));
48+
Ok(output)
49+
}

crates/raster/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ pub mod common;
1616
pub mod config;
1717
pub mod error;
1818
pub mod hooks;
19+
pub mod imagestore;
1920
pub mod mount;
2021

2122
pub use crate::common::expand_vars_string;
2223
pub use crate::config::{Config, VarExpand, load_config, load_config_path, update_config_by_user};
2324
pub use crate::hooks::{hook_run, ExecutedCommand};
25+
pub use crate::imagestore::{imagestore_keepalive};
2426

2527
#[allow(dead_code)]
2628
#[derive(Derivative, Serialize, Deserialize, Clone, Default)]

crates/skybox/src/sync.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@ pub(crate) fn sync_cleanup_fs_shared(
363363
}
364364
}
365365

366+
match raster::imagestore_keepalive(&ssb.config)? {
367+
Some(output) => {
368+
skybox_log_debug!("{}", output);
369+
},
370+
None => (),
371+
};
372+
366373
Ok(())
367374
}
368375

0 commit comments

Comments
 (0)