From c3ef1268a0b4b0d01dd76043a865b4acf144f3c9 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 27 May 2020 16:58:08 +0200 Subject: [PATCH] sfdisk: add --lock and LOCK_BLOCK_DEVICE Addresses: https://github.com/karelzak/util-linux/issues/921 Signed-off-by: Karel Zak --- disk-utils/sfdisk.8 | 23 ++++++------ disk-utils/sfdisk.c | 88 +++++++++++++++++++++++---------------------- 2 files changed, 58 insertions(+), 53 deletions(-) diff --git a/disk-utils/sfdisk.8 b/disk-utils/sfdisk.8 index 5cccfa70cd..819efee900 100644 --- a/disk-utils/sfdisk.8 +++ b/disk-utils/sfdisk.8 @@ -63,17 +63,8 @@ partitions. uses BLKRRPART (reread partition table) ioctl to make sure that the device is not used by system or another tools (see also \-\-no-reread). It's possible that this feature or another sfdisk activity races with \fBudevd\fR. The recommended way -how to avoid possible collisions is to use exclusive flock for the whole-disk -device to serialize device access. The exclusive lock will cause udevd to skip -the event handling on the device. For example: -.RS -.sp -.nf -.B "flock /dev/sdc sfdisk /dev/sdc" -.fi -.sp -.RE -Note, this semantic is not currently supported by udevd for MD and DM devices. +how to avoid possible collisions is to use \fB\-\-lock\fR option. +The exclusive lock will cause udevd to skip the event handling on the device. .PP The sfdisk prompt is only a hint for users and a displayed partition number does not mean that the same partition table entry will be created (if -N not @@ -221,6 +212,14 @@ Disable all consistency checking. Deprecated and ignored option. Partitioning that is compatible with Linux (and other modern operating systems) is the default. .TP +\fB\-\-lock\fR[=\fImode\fR] +Use exclusive BSD lock for device or file it operates. The optional argument +\fImode\fP can be \fByes\fR, \fBno\fR (or 1 and 0) or \fBnonblock\fR. If the \fImode\fR +argument is omitted, it defaults to \fB"yes"\fR. This option overwrites +environment variable \fB$LOCK_BLOCK_DEVICE\fR. The default is not to use any +lock at all, but it's recommended to avoid collisions with udevd or other +tools. +.TP .BR \-n , " \-\-no\-act" Do everything except writing to the device. .TP @@ -610,6 +609,8 @@ enables libfdisk debug output. enables libblkid debug output. .IP LIBSMARTCOLS_DEBUG=all enables libsmartcols debug output. +.IP LOCK_BLOCK_DEVICE= +use exclusive BSD lock. The mode is "1" or "0". See \fB\-\-lock\fR for more details. .SH NOTES Since version 2.26 \fBsfdisk\fR no longer provides the \fB\-R\fR or diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index e0c25fde76..192e9f951e 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -96,6 +96,7 @@ struct sfdisk { int partno; /* -N , default -1 */ int wipemode; /* remove foreign signatures from disk */ int pwipemode; /* remove foreign signatures from partitions */ + const char *lockmode; /* as specified by --lock */ const char *label; /* --label