]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/workunits/fs/misc/filelock_interrupt.py
3 from contextlib
import contextmanager
11 def timeout_handler(signum
, frame
):
12 raise InterruptedError
14 orig_handler
= signal
.signal(signal
.SIGALRM
, timeout_handler
)
20 signal
.signal(signal
.SIGALRM
, orig_handler
)
24 introduced by Linux 3.15
26 setattr(fcntl
, "F_OFD_GETLK", 36)
27 setattr(fcntl
, "F_OFD_SETLK", 37)
28 setattr(fcntl
, "F_OFD_SETLKW", 38)
32 f1
= open("testfile", 'w')
33 f2
= open("testfile", 'w')
35 fcntl
.flock(f1
, fcntl
.LOCK_SH | fcntl
.LOCK_NB
)
38 is flock interruptible?
42 fcntl
.flock(f2
, fcntl
.LOCK_EX
)
43 except InterruptedError
:
46 raise RuntimeError("expect flock to block")
48 fcntl
.flock(f1
, fcntl
.LOCK_UN
)
50 lockdata
= struct
.pack('hhllhh', fcntl
.F_WRLCK
, 0, 0, 10, 0, 0)
52 fcntl
.fcntl(f1
, fcntl
.F_OFD_SETLK
, lockdata
)
54 if e
.errno
!= errno
.EINVAL
:
57 print('kernel does not support fcntl.F_OFD_SETLK')
60 lockdata
= struct
.pack('hhllhh', fcntl
.F_WRLCK
, 0, 10, 10, 0, 0)
61 fcntl
.fcntl(f2
, fcntl
.F_OFD_SETLK
, lockdata
)
64 is posix lock interruptible?
68 lockdata
= struct
.pack('hhllhh', fcntl
.F_WRLCK
, 0, 0, 0, 0, 0)
69 fcntl
.fcntl(f2
, fcntl
.F_OFD_SETLKW
, lockdata
)
70 except InterruptedError
:
73 raise RuntimeError("expect posix lock to block")
76 file handler 2 should still hold lock on 10~10
79 lockdata
= struct
.pack('hhllhh', fcntl
.F_WRLCK
, 0, 10, 10, 0, 0)
80 fcntl
.fcntl(f1
, fcntl
.F_OFD_SETLK
, lockdata
)
82 if e
.errno
== errno
.EAGAIN
:
85 raise RuntimeError("expect file handler 2 to hold lock on 10~10")
87 lockdata
= struct
.pack('hhllhh', fcntl
.F_UNLCK
, 0, 0, 0, 0, 0)
88 fcntl
.fcntl(f1
, fcntl
.F_OFD_SETLK
, lockdata
)
89 fcntl
.fcntl(f2
, fcntl
.F_OFD_SETLK
, lockdata
)