mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-03 01:17:37 +00:00
sys: file locking depends on timer feature
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
e2e7ea6d62
commit
d3364e07fb
@ -2,6 +2,7 @@ use std::fs::File;
|
|||||||
use std::io::{self, BufRead, BufReader, Write};
|
use std::io::{self, BufRead, BufReader, Write};
|
||||||
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd};
|
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
#[cfg(feature = "timer")]
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
@ -14,8 +15,10 @@ use serde_json::Value;
|
|||||||
|
|
||||||
use proxmox_lang::try_block;
|
use proxmox_lang::try_block;
|
||||||
|
|
||||||
use crate::error::{SysError, SysResult};
|
use crate::error::SysError;
|
||||||
use crate::linux::timer;
|
|
||||||
|
#[cfg(feature = "timer")]
|
||||||
|
use crate::{error::SysResult, linux::timer};
|
||||||
|
|
||||||
use crate::fs::CreateOptions;
|
use crate::fs::CreateOptions;
|
||||||
|
|
||||||
@ -346,6 +349,7 @@ pub fn image_size(path: &Path) -> Result<u64, Error> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "timer")]
|
||||||
/// Create a file lock using fntl. This function allows you to specify
|
/// Create a file lock using fntl. This function allows you to specify
|
||||||
/// a timeout if you want to avoid infinite blocking.
|
/// a timeout if you want to avoid infinite blocking.
|
||||||
///
|
///
|
||||||
@ -399,6 +403,7 @@ pub fn lock_file<F: AsRawFd>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "timer")]
|
||||||
/// Open or create a lock file (append mode). Then try to
|
/// Open or create a lock file (append mode). Then try to
|
||||||
/// acquire a lock using `lock_file()`.
|
/// acquire a lock using `lock_file()`.
|
||||||
pub fn open_file_locked<P: AsRef<Path>>(
|
pub fn open_file_locked<P: AsRef<Path>>(
|
||||||
|
@ -12,6 +12,7 @@ use regex::Regex;
|
|||||||
|
|
||||||
use proxmox_borrow::Tied;
|
use proxmox_borrow::Tied;
|
||||||
|
|
||||||
|
#[cfg(feature = "timer")]
|
||||||
use crate::error::SysError;
|
use crate::error::SysError;
|
||||||
|
|
||||||
pub type DirLockGuard = Dir;
|
pub type DirLockGuard = Dir;
|
||||||
@ -264,6 +265,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "timer")]
|
||||||
/// Attempt to acquire a shared flock on the given path, 'what' and
|
/// Attempt to acquire a shared flock on the given path, 'what' and
|
||||||
/// 'would_block_message' are used for error formatting.
|
/// 'would_block_message' are used for error formatting.
|
||||||
pub fn lock_dir_noblock_shared(
|
pub fn lock_dir_noblock_shared(
|
||||||
@ -274,6 +276,7 @@ pub fn lock_dir_noblock_shared(
|
|||||||
do_lock_dir_noblock(path, what, would_block_msg, false)
|
do_lock_dir_noblock(path, what, would_block_msg, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "timer")]
|
||||||
/// Attempt to acquire an exclusive flock on the given path, 'what' and
|
/// Attempt to acquire an exclusive flock on the given path, 'what' and
|
||||||
/// 'would_block_message' are used for error formatting.
|
/// 'would_block_message' are used for error formatting.
|
||||||
pub fn lock_dir_noblock(
|
pub fn lock_dir_noblock(
|
||||||
@ -284,6 +287,7 @@ pub fn lock_dir_noblock(
|
|||||||
do_lock_dir_noblock(path, what, would_block_msg, true)
|
do_lock_dir_noblock(path, what, would_block_msg, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "timer")]
|
||||||
fn do_lock_dir_noblock(
|
fn do_lock_dir_noblock(
|
||||||
path: &std::path::Path,
|
path: &std::path::Path,
|
||||||
what: &str,
|
what: &str,
|
||||||
|
Loading…
Reference in New Issue
Block a user