79 lines
2.8 KiB
Diff
79 lines
2.8 KiB
Diff
|
|
From b4b66b26620bfaf5818c95d5cffafd85207694e7 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Lennart Poettering <lennart@poettering.net>
|
||
|
|
Date: Mon, 9 Sep 2024 17:53:03 +0200
|
||
|
|
Subject: [PATCH] shutdown: replace unbounded fsync() with bounded sync_with_progress()
|
||
|
|
|
||
|
|
Let's put a time-out on this syncing.
|
||
|
|
|
||
|
|
Inspired-by: #34289 #34283
|
||
|
|
|
||
|
|
Conflict:1.The file detach-loopback.c/detach-md.c/detach-dm.c all in
|
||
|
|
umount.c file in systemd 249.
|
||
|
|
2.context adaption:RET_NERRNO is a new macro for return elegant,no
|
||
|
|
function difference.And we only need to include shutdown.h once in
|
||
|
|
umount.c.
|
||
|
|
Reference:https://github.com/systemd/systemd/pull/34330/commits/b4b66b26620bfaf5818c95d5cffafd85207694e7
|
||
|
|
|
||
|
|
---
|
||
|
|
src/shutdown/umount.c | 16 ++++++++--------
|
||
|
|
1 file changed, 8 insertions(+), 8 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/src/shutdown/umount.c b/src/shutdown/umount.c
|
||
|
|
index 9325870..0d5bc7e 100644
|
||
|
|
--- a/src/shutdown/umount.c
|
||
|
|
+++ b/src/shutdown/umount.c
|
||
|
|
@@ -38,6 +38,7 @@
|
||
|
|
#include "signal-util.h"
|
||
|
|
#include "string-util.h"
|
||
|
|
#include "strv.h"
|
||
|
|
+#include "shutdown.h"
|
||
|
|
#include "umount.h"
|
||
|
|
#include "util.h"
|
||
|
|
#include "virt.h"
|
||
|
|
@@ -411,8 +412,7 @@ static int delete_loopback(const char *device) {
|
||
|
|
|
||
|
|
/* Loopback block devices don't sync in-flight blocks when we clear the fd, hence sync explicitly
|
||
|
|
* first */
|
||
|
|
- if (fsync(fd) < 0)
|
||
|
|
- log_debug_errno(errno, "Failed to sync loop block device %s, ignoring: %m", device);
|
||
|
|
+ (void) sync_with_progress(fd);
|
||
|
|
|
||
|
|
if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
|
||
|
|
if (errno == ENXIO) /* Nothing bound, didn't do anything */
|
||
|
|
@@ -474,7 +474,6 @@ static int delete_loopback(const char *device) {
|
||
|
|
|
||
|
|
static int delete_dm(MountPoint *m) {
|
||
|
|
_cleanup_close_ int fd = -1;
|
||
|
|
- int r;
|
||
|
|
|
||
|
|
assert(m);
|
||
|
|
assert(major(m->devnum) != 0);
|
||
|
|
@@ -484,9 +483,11 @@ static int delete_dm(MountPoint *m) {
|
||
|
|
if (fd < 0)
|
||
|
|
return -errno;
|
||
|
|
|
||
|
|
- r = fsync_path_at(AT_FDCWD, m->path);
|
||
|
|
- if (r < 0)
|
||
|
|
- log_debug_errno(r, "Failed to sync DM block device %s, ignoring: %m", m->path);
|
||
|
|
+ _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);
|
||
|
|
|
||
|
|
if (ioctl(fd, DM_DEV_REMOVE, &(struct dm_ioctl) {
|
||
|
|
.version = {
|
||
|
|
@@ -513,8 +514,7 @@ static int delete_md(MountPoint *m) {
|
||
|
|
if (fd < 0)
|
||
|
|
return -errno;
|
||
|
|
|
||
|
|
- if (fsync(fd) < 0)
|
||
|
|
- log_debug_errno(errno, "Failed to sync MD block device %s, ignoring: %m", m->path);
|
||
|
|
+ (void) sync_with_progress(fd);
|
||
|
|
|
||
|
|
if (ioctl(fd, STOP_ARRAY, NULL) < 0)
|
||
|
|
return -errno;
|
||
|
|
--
|
||
|
|
2.19.1
|
||
|
|
|