Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/raster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ regex = "1.12.2"
serial_test = "3.2.0"
nix = { version = "0.30.1", features = ["user","fs","signal"] }
is_executable = "1.0.5"
walkdir = "2.5.0"
23 changes: 23 additions & 0 deletions crates/raster/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct RawConfig {
edf_system_search_path: Option<String>,
hooks: Option<RawConfigHooks>,
parallax_imagestore: Option<String>,
parallax_imagestore_keepalive: Option<bool>,
parallax_mount_program: Option<String>,
parallax_path: Option<String>,
parallax_mp_uid: Option<u32>,
Expand Down Expand Up @@ -40,6 +41,8 @@ pub struct Config {
pub hooks: ConfigHooks,
#[serde(default = "get_default_parallax_imagestore")]
pub parallax_imagestore: String,
#[serde(default = "get_default_parallax_imagestore_keepalive")]
pub parallax_imagestore_keepalive: bool,
#[serde(default = "get_default_parallax_mount_program")]
pub parallax_mount_program: String,
#[serde(default = "get_default_parallax_path")]
Expand Down Expand Up @@ -91,6 +94,10 @@ fn get_default_parallax_imagestore() -> String {
return String::from("");
}

fn get_default_parallax_imagestore_keepalive() -> bool {
return false;
}

fn get_default_parallax_mount_program() -> String {
return String::from("");
}
Expand Down Expand Up @@ -173,6 +180,10 @@ impl From<RawConfig> for Config {
Some(s) => s,
None => get_default_parallax_imagestore(),
},
parallax_imagestore_keepalive: match r.parallax_imagestore_keepalive {
Some(s) => s,
None => get_default_parallax_imagestore_keepalive(),
},
parallax_mount_program: match r.parallax_mount_program {
Some(s) => s,
None => get_default_parallax_mount_program(),
Expand Down Expand Up @@ -245,6 +256,9 @@ impl RawConfig {
if i.parallax_imagestore.is_some() {
self.parallax_imagestore = i.parallax_imagestore;
}
if i.parallax_imagestore_keepalive.is_some() {
self.parallax_imagestore_keepalive = i.parallax_imagestore_keepalive;
}
if i.parallax_mount_program.is_some() {
self.parallax_mount_program = i.parallax_mount_program;
}
Expand Down Expand Up @@ -483,6 +497,15 @@ pub fn update_config_by_user(config: &mut Config, edf: EDF) -> SarusResult<()> {
config.parallax_imagestore = parallax_imagestore.unwrap().to_string();
}

let parallax_imagestore_keepalive = edf.annotations.get("com.sarus.parallax_imagestore_keepalive");
if parallax_imagestore_keepalive.is_some() {
config.parallax_imagestore_keepalive = match parallax_imagestore_keepalive.unwrap().as_str() {
"true" => true,
"false" => false,
_ => config.parallax_imagestore_keepalive,
};
}

let parallax_mount_program = edf.annotations.get("com.sarus.parallax_mount_program");
if parallax_mount_program.is_some() {
config.parallax_mount_program = parallax_mount_program.unwrap().to_string();
Expand Down
49 changes: 49 additions & 0 deletions crates/raster/src/imagestore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::path::Path;
use std::fs::{self, File, FileTimes};
use std::time::{Duration, SystemTime};
use walkdir::WalkDir;
use crate::Config;

pub fn imagestore_keepalive(config: &Config) -> Result<Option<String>,String> {

let output;
let imagestore = &config.parallax_imagestore;

if ! config.parallax_imagestore_keepalive {
return Ok(None);
}

let path = Path::new(&imagestore);
if ! path.exists() {
return Err(format!("imagestore {} doesn't exist", imagestore));
}

let now = SystemTime::now();
let mut num_entries = 0;
let mut upd_entries = 0;
for entry in WalkDir::new(&path) {
num_entries += 1;

// Best effort, skip errors
let Ok(entrystr) = entry else { continue };
let Ok(metadata) = fs::metadata(entrystr.path()) else { continue };
let Ok(atime) = metadata.accessed() else { continue };

// skip if recent
if atime.elapsed().unwrap() < Duration::new(86400, 0) { continue }

// Update atime if old
let Ok(file) = File::open(entrystr.path()) else { continue };
let Ok(mtime) = metadata.modified() else { continue };
let times = FileTimes::new()
.set_accessed(now)
.set_modified(mtime);
match file.set_times(times) {
Ok(_) => (),
Err(_) => continue,
}
upd_entries += 1;
}
output = Some(format!("Keep alive imagestore {}, refreshed {}/{} inodes", imagestore, upd_entries, num_entries));
Ok(output)
}
2 changes: 2 additions & 0 deletions crates/raster/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ pub mod common;
pub mod config;
pub mod error;
pub mod hooks;
pub mod imagestore;
pub mod mount;

pub use crate::common::expand_vars_string;
pub use crate::config::{Config, VarExpand, load_config, load_config_path, update_config_by_user};
pub use crate::hooks::{hook_run, ExecutedCommand};
pub use crate::imagestore::{imagestore_keepalive};

#[allow(dead_code)]
#[derive(Derivative, Serialize, Deserialize, Clone, Default)]
Expand Down
7 changes: 7 additions & 0 deletions crates/skybox/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@ pub(crate) fn sync_cleanup_fs_shared(
}
}

match raster::imagestore_keepalive(&ssb.config)? {
Some(output) => {
skybox_log_debug!("{}", output);
},
None => (),
};

Ok(())
}

Expand Down
Loading