From 257a00547a7ba113fbcee4037733773bdf6a0b7f Mon Sep 17 00:00:00 2001 From: Pascal Scholz Date: Tue, 16 Jun 2026 16:17:53 +0200 Subject: [PATCH] block: Retry locking when interrupted by EINTR Acquiring an image lock can be interrupted with EINTR. In this case, we returned with an error. Instead, we now retry acquiring the lock. Signed-off-by: Pascal Scholz On-behalf-of: SAP pascal.scholz@sap.com --- block/src/io/fcntl.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/block/src/io/fcntl.rs b/block/src/io/fcntl.rs index 98084748c..0cb2ee552 100644 --- a/block/src/io/fcntl.rs +++ b/block/src/io/fcntl.rs @@ -201,20 +201,23 @@ pub fn try_acquire_lock( ) -> Result<(), LockError> { let flock = get_flock(lock_type, granularity); - let res = fcntl(file.as_raw_fd(), FcntlArg::F_OFD_SETLK(&flock)); - match res { - 0 => Ok(()), - -1 => { - let io_error = io::Error::last_os_error(); - let errno = io_error.raw_os_error().unwrap(); - match errno { - // See man page for error code: - // - libc::EAGAIN | libc::EACCES => Err(LockError::AlreadyLocked), - _ => Err(LockError::Io(io_error)), + loop { + let res = fcntl(file.as_raw_fd(), FcntlArg::F_OFD_SETLK(&flock)); + match res { + 0 => return Ok(()), + -1 => { + let io_error = io::Error::last_os_error(); + let errno = io_error.raw_os_error().unwrap(); + match errno { + // See man page for error code: + // + libc::EAGAIN | libc::EACCES => return Err(LockError::AlreadyLocked), + libc::EINTR => continue, + _ => return Err(LockError::Io(io_error)), + } } + val => panic!("Unexpected return value from fcntl(): {val}"), } - val => panic!("Unexpected return value from fcntl(): {val}"), } }