54 lines
1.9 KiB
Diff
54 lines
1.9 KiB
Diff
|
|
From c7689286f631b1dc6b4d7a56c9f056eb1d2eead1 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||
|
|
Date: Sat, 23 Nov 2024 05:47:40 +0900
|
||
|
|
Subject: [PATCH] shutdown: close DM block device before issuing DM_DEV_REMOVE
|
||
|
|
ioctl
|
||
|
|
|
||
|
|
Otherwise, the ioctl() may fail with EBUSY.
|
||
|
|
|
||
|
|
Follow-up for b4b66b26620bfaf5818c95d5cffafd85207694e7.
|
||
|
|
Hopefully fixes #35243.
|
||
|
|
|
||
|
|
(cherry picked from commit b76730f3fe0e824db001b38c8ea848302be786ee)
|
||
|
|
(cherry picked from commit b30364a0378881c6f0d0ff3124f56f4da989d91c)
|
||
|
|
(cherry picked from commit bb1823d3ffcf432b5175ef24049b65e7b348705b)
|
||
|
|
|
||
|
|
Conflict:NA
|
||
|
|
Reference:https://github.com/systemd/systemd-stable/commit/c7689286f631b1dc6b4d7a56c9f056eb1d2eead1
|
||
|
|
---
|
||
|
|
src/shutdown/detach-dm.c | 16 +++++++++-------
|
||
|
|
1 file changed, 9 insertions(+), 7 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/src/shutdown/detach-dm.c b/src/shutdown/detach-dm.c
|
||
|
|
index 0d1b0fc451..d6bc78df41 100644
|
||
|
|
--- a/src/shutdown/detach-dm.c
|
||
|
|
+++ b/src/shutdown/detach-dm.c
|
||
|
|
@@ -98,15 +98,17 @@ static int delete_dm(DeviceMapper *m) {
|
||
|
|
assert(major(m->devnum) != 0);
|
||
|
|
assert(m->path);
|
||
|
|
|
||
|
|
- fd = open("/dev/mapper/control", O_RDWR|O_CLOEXEC);
|
||
|
|
+ fd = open(m->path, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
|
||
|
|
if (fd < 0)
|
||
|
|
- return -errno;
|
||
|
|
-
|
||
|
|
- _cleanup_close_ int block_fd = open(m->path, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
|
||
|
|
- if (block_fd < 0)
|
||
|
|
log_debug_errno(errno, "Failed to open DM block device %s for syncing, ignoring: %m", m->path);
|
||
|
|
- else
|
||
|
|
- (void) sync_with_progress(block_fd);
|
||
|
|
+ else {
|
||
|
|
+ (void) sync_with_progress(fd);
|
||
|
|
+ fd = safe_close(fd);
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ fd = open("/dev/mapper/control", O_RDWR|O_CLOEXEC);
|
||
|
|
+ if (fd < 0)
|
||
|
|
+ return log_debug_errno(errno, "Failed to open /dev/mapper/control: %m");
|
||
|
|
|
||
|
|
return RET_NERRNO(ioctl(fd, DM_DEV_REMOVE, &(struct dm_ioctl) {
|
||
|
|
.version = {
|
||
|
|
--
|
||
|
|
2.33.0
|
||
|
|
|