From 8519481b72365701d01ee58a0ef57ad1bea2c66c Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Thu, 26 May 2016 09:38:47 +0200 Subject: [PATCH] ceph-disk: partprobe should block udev induced BLKRRPART Wrap partprobe with flock to stop udev from issuing BLKRRPART because this is racy and frequently fails with a message like: Error: Error informing the kernel about modifications to partition /dev/vdc1 -- Device or resource busy. This means Linux won't know about any changes you made to /dev/vdc1 until you reboot -- so you shouldn't mount it or use it in any way before rebooting. Opening a device (/dev/vdc for instance) in write mode indirectly triggers a BLKRRPART ioctl from udev (starting version 214 and up) when the device is closed (see below for the udev release note). However, if udev fails to acquire an exclusive lock (with flock(fd, LOCK_EX|LOCK_NB); ) the BLKRRPART ioctl is not issued. https://github.com/systemd/systemd/blob/045e00cf16c47bc516c0823d059b7548f3ce9c7c/src/udev/udevd.c#L1042 Acquiring an exclusive lock before running the process that opens the device in write mode is therefore an effective way to control this behavior. git clone git://anonscm.debian.org/pkg-systemd/systemd.git systemd/NEWS: CHANGES WITH 214: * As an experimental feature, udev now tries to lock the disk device node (flock(LOCK_SH|LOCK_NB)) while it executes events for the disk or any of its partitions. Applications like partitioning programs can lock the disk device node (flock(LOCK_EX)) and claim temporary device ownership that way; udev will entirely skip all event handling for this disk and its partitions. If the disk was opened for writing, the close will trigger a partition table rescan in udev's "watch" facility, and if needed synthesize "change" events for the disk and all its partitions. This is now unconditionally enabled, and if it turns out to cause major problems, we might turn it on only for specific devices, or might need to disable it entirely. Device Mapper devices are excluded from this logic. Fixes: http://tracker.ceph.com/issues/15176 Signed-off-by: Marius Vollmer Signed-off-by: Loic Dachary --- src/ceph-disk/ceph_disk/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ceph-disk/ceph_disk/main.py b/src/ceph-disk/ceph_disk/main.py index 30e7e16b43bf4..47e654f9d5fc6 100755 --- a/src/ceph-disk/ceph_disk/main.py +++ b/src/ceph-disk/ceph_disk/main.py @@ -1395,10 +1395,11 @@ def update_partition(dev, description): LOG.debug('Calling partprobe on %s device %s', description, dev) partprobe_ok = False error = 'unknown error' + partprobe = _get_command_executable(['partprobe'])[0] for i in (1, 2, 3, 4, 5): command_check_call(['udevadm', 'settle', '--timeout=600']) try: - _check_output(['partprobe', dev]) + _check_output(['flock', '-s', dev, partprobe, dev]) partprobe_ok = True break except subprocess.CalledProcessError as e: -- 2.39.5