MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / get_lock_state

Function get_lock_state

block/src/fcntl.rs:236–254  ·  view source on GitHub ↗

Returns the current lock state using [`fcntl`] with respect to the given parameters. # Parameters - `file`: The file for which to get the lock state. - `granularity`: The [`LockGranularity`].

(
    file: &Fd,
    granularity: LockGranularity,
)

Source from the content-addressed store, hash-verified

234/// - `file`: The file for which to get the lock state.
235/// - `granularity`: The [`LockGranularity`].
236pub fn get_lock_state<Fd: AsRawFd>(
237 file: &Fd,
238 granularity: LockGranularity,
239) -> Result<LockState, LockError> {
240 let mut flock = get_flock(LockType::Write, granularity);
241 let res = fcntl(file.as_raw_fd(), FcntlArg::F_OFD_GETLK(&mut flock));
242 match res {
243 0 => {
244 let state = flock.l_type as libc::c_int;
245 let state = LockState::new(state);
246 Ok(state)
247 }
248 -1 => {
249 let io_error = io::Error::last_os_error();
250 Err(LockError::Io(io_error))
251 }
252 val => panic!("Unexpected return value from fcntl(): {val}"),
253 }
254}

Callers 1

try_lock_imageMethod · 0.85

Calls 4

get_flockFunction · 0.85
fcntlFunction · 0.85
newFunction · 0.85
as_raw_fdMethod · 0.45

Tested by

no test coverage detected