[pbs-devel] [PATCH proxmox-backup 02/10] server/worker_task: refactor locking of the task list

Dietmar Maurer dietmar at proxmox.com
Mon Sep 28 07:28:08 CEST 2020


> +fn lock_task_list_files(exclusive: bool) -> Result<std::fs::File, Error> {
> +    let backup_user = crate::backup::backup_user()?;
> +
> +    let lock = if exclusive {
> +        open_file_locked(PROXMOX_BACKUP_TASK_LOCK_FN, std::time::Duration::new(10, 0))?
> +    } else {
> +        open_file_locked_shared(PROXMOX_BACKUP_TASK_LOCK_FN, std::time::Duration::new(10, 0))?
> +    };
> +    nix::unistd::chown(PROXMOX_BACKUP_TASK_LOCK_FN, Some(backup_user.uid), Some(backup_user.gid))?;

You should use fchown here on the open file handle.

> +
> +    Ok(lock)
> +}

This starts to get clumsy. We have:

pub fn open_file_locked_shared<P: AsRef<Path>>(path: P, timeout: Duration) -> Result<File, Error>

and

pub fn open_file_locked<P: AsRef<Path>>(path: P, timeout: Duration) -> Result<File, Error>

and private:

fn open_file_locked_impl<P: AsRef<Path>>(path: P, timeout: Duration, exclusive: bool) -> Result<File, Error>

But we want:

pub fn open_file_locked<P: AsRef<Path>>(path: P, timeout: Duration, exclusive: bool) -> Result<File, Error>


...





More information about the pbs-devel mailing list