]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lib/blkdev: add support for --lock and LOCK_BLOCK_DEVICE
authorKarel Zak <kzak@redhat.com>
Tue, 26 May 2020 15:21:04 +0000 (17:21 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 26 May 2020 15:30:39 +0000 (17:30 +0200)
commit37b302046a62ddfe0524f7bd8c725d4ddc5184b1
treee97e2f2fc52516f78d7ebe81c859d36d4bdb3d39
parent498f910eeb0167c75b0421a9a12974e6bb0afb04
lib/blkdev: add support for --lock and LOCK_BLOCK_DEVICE

All simple function to parse --lock <mode> and $LOCK_BLOCK_DEVICE,
and to flock the fd.

The supported <mode> is:

"1" or "yes" - LOCK_EX
"0" or "no" - do nothing
"nonblock" - LOCK_EX | LOCK_NB

The function tries LOCK_NB before the solo LOCK_EX and prints
inform user that it will wait, for example:

session A:
# sfdisk --lock /dev/sdc

session B:
# sfdisk --lock /dev/sdc
sfdisk: /dev/sdc: device already locked, waiting to get lock ...
^C

# sfdisk --lock=nonblock /dev/sdc
sfdisk: /dev/sdc: device already locked

Addresses: https://github.com/karelzak/util-linux/issues/921
Signed-off-by: Karel Zak <kzak@redhat.com>
include/blkdev.h
lib/blkdev.c