upid: use systemd escape to decode/encode the worker_id
This way we can store values containing "/" and ":".
This commit is contained in:
parent
5eb9dd0c8a
commit
4ebda996e5
@ -496,13 +496,13 @@ pub fn verify(
|
||||
|
||||
match (backup_type, backup_id, backup_time) {
|
||||
(Some(backup_type), Some(backup_id), Some(backup_time)) => {
|
||||
worker_id = format!("{}_{}_{}_{:08X}", store, backup_type, backup_id, backup_time);
|
||||
worker_id = format!("{}:{}/{}/{:08X}", store, backup_type, backup_id, backup_time);
|
||||
let dir = BackupDir::new(backup_type, backup_id, backup_time)?;
|
||||
backup_dir = Some(dir);
|
||||
worker_type = "verify_snapshot";
|
||||
}
|
||||
(Some(backup_type), Some(backup_id), None) => {
|
||||
worker_id = format!("{}_{}_{}", store, backup_type, backup_id);
|
||||
worker_id = format!("{}:{}/{}", store, backup_type, backup_id);
|
||||
let group = BackupGroup::new(backup_type, backup_id);
|
||||
backup_group = Some(group);
|
||||
worker_type = "verify_group";
|
||||
@ -668,7 +668,7 @@ fn prune(
|
||||
keep_yearly: param["keep-yearly"].as_u64(),
|
||||
};
|
||||
|
||||
let worker_id = format!("{}_{}_{}", store, backup_type, backup_id);
|
||||
let worker_id = format!("{}:{}/{}", store, backup_type, backup_id);
|
||||
|
||||
let mut prune_result = Vec::new();
|
||||
|
||||
|
@ -86,7 +86,7 @@ async move {
|
||||
bail!("unexpected http version '{:?}' (expected version < 2)", parts.version);
|
||||
}
|
||||
|
||||
let worker_id = format!("{}_{}_{}", store, backup_type, backup_id);
|
||||
let worker_id = format!("{}:{}/{}", store, backup_type, backup_id);
|
||||
|
||||
let env_type = rpcenv.env_type();
|
||||
|
||||
|
@ -506,7 +506,7 @@ impl BackupEnvironment {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let worker_id = format!("{}_{}_{}_{:08X}",
|
||||
let worker_id = format!("{}:{}/{}/{:08X}",
|
||||
self.datastore.name(),
|
||||
self.backup_dir.group().backup_type(),
|
||||
self.backup_dir.group().backup_id(),
|
||||
|
@ -342,7 +342,7 @@ pub fn list_tasks(
|
||||
if info.upid.worker_type == "backup" || info.upid.worker_type == "restore" ||
|
||||
info.upid.worker_type == "prune"
|
||||
{
|
||||
let prefix = format!("{}_", store);
|
||||
let prefix = format!("{}:", store);
|
||||
if !worker_id.starts_with(&prefix) { return None; }
|
||||
} else if info.upid.worker_type == "garbage_collection" {
|
||||
if worker_id != store { return None; }
|
||||
|
@ -108,7 +108,7 @@ fn upgrade_to_backup_reader_protocol(
|
||||
|
||||
//let files = BackupInfo::list_files(&path, &backup_dir)?;
|
||||
|
||||
let worker_id = format!("{}_{}_{}_{:08X}", store, backup_type, backup_id, backup_dir.backup_time());
|
||||
let worker_id = format!("{}:{}/{}/{:08X}", store, backup_type, backup_id, backup_dir.backup_time());
|
||||
|
||||
WorkerTask::spawn("reader", Some(worker_id), userid.clone(), true, move |worker| {
|
||||
let mut env = ReaderEnvironment::new(
|
||||
|
@ -628,7 +628,7 @@ async fn schedule_task_log_rotate() {
|
||||
parse_calendar_event, compute_next_event};
|
||||
|
||||
let worker_type = "logrotate";
|
||||
let job_id = "task-archive";
|
||||
let job_id = "task_archive";
|
||||
|
||||
let last = match jobstate::last_run_time(worker_type, job_id) {
|
||||
Ok(time) => time,
|
||||
|
@ -75,11 +75,6 @@ impl UPID {
|
||||
if worker_type.contains(bad) {
|
||||
bail!("illegal characters in worker type '{}'", worker_type);
|
||||
}
|
||||
if let Some(ref worker_id) = worker_id {
|
||||
if worker_id.contains(bad) {
|
||||
bail!("illegal characters in worker id '{}'", worker_id);
|
||||
}
|
||||
}
|
||||
|
||||
static WORKER_TASK_NEXT_ID: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
@ -112,13 +107,21 @@ impl std::str::FromStr for UPID {
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
if let Some(cap) = PROXMOX_UPID_REGEX.captures(s) {
|
||||
|
||||
let worker_id = if cap["wid"].is_empty() {
|
||||
None
|
||||
} else {
|
||||
let wid = crate::tools::systemd::unescape_unit(&cap["wid"])?;
|
||||
Some(wid)
|
||||
};
|
||||
|
||||
Ok(UPID {
|
||||
pid: i32::from_str_radix(&cap["pid"], 16).unwrap(),
|
||||
pstart: u64::from_str_radix(&cap["pstart"], 16).unwrap(),
|
||||
starttime: i64::from_str_radix(&cap["starttime"], 16).unwrap(),
|
||||
task_id: usize::from_str_radix(&cap["task_id"], 16).unwrap(),
|
||||
worker_type: cap["wtype"].to_string(),
|
||||
worker_id: if cap["wid"].is_empty() { None } else { Some(cap["wid"].to_string()) },
|
||||
worker_id,
|
||||
userid: cap["userid"].parse()?,
|
||||
node: cap["node"].to_string(),
|
||||
})
|
||||
@ -133,7 +136,11 @@ impl std::fmt::Display for UPID {
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
|
||||
let wid = if let Some(ref id) = self.worker_id { id } else { "" };
|
||||
let wid = if let Some(ref id) = self.worker_id {
|
||||
crate::tools::systemd::escape_unit(id, false)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
// Note: pstart can be > 32bit if uptime > 497 days, so this can result in
|
||||
// more that 8 characters for pstart
|
||||
|
Loading…
Reference in New Issue
Block a user