]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shutdown: replace unbounded fsync() with bounded sync_with_progress() 34330/head
authorLennart Poettering <lennart@poettering.net>
Mon, 9 Sep 2024 15:53:03 +0000 (17:53 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 9 Sep 2024 17:12:31 +0000 (19:12 +0200)
Let's put a time-out on this syncing.

Inspired-by: #34289 #34283
src/shutdown/detach-dm.c
src/shutdown/detach-loopback.c
src/shutdown/detach-md.c

index f6f672c75ad5f2e99a64cd749c4f67d617cf2e9c..bddd748d63446f2407a6b80a2d73ec14c447566b 100644 (file)
@@ -15,7 +15,7 @@
 #include "devnum-util.h"
 #include "errno-util.h"
 #include "fd-util.h"
-#include "sync-util.h"
+#include "shutdown.h"
 
 typedef struct DeviceMapper {
         char *path;
@@ -93,7 +93,6 @@ static int dm_list_get(DeviceMapper **head) {
 
 static int delete_dm(DeviceMapper *m) {
         _cleanup_close_ int fd = -EBADF;
-        int r;
 
         assert(m);
         assert(major(m->devnum) != 0);
@@ -103,9 +102,11 @@ static int delete_dm(DeviceMapper *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);
 
         return RET_NERRNO(ioctl(fd, DM_DEV_REMOVE, &(struct dm_ioctl) {
                 .version = {
index 267509f7d02eb96f7b140906b9f1a881f94e3373..8778a9e0c441843a5168b3f60185f8435d721f29 100644 (file)
@@ -18,6 +18,7 @@
 #include "detach-loopback.h"
 #include "device-util.h"
 #include "fd-util.h"
+#include "shutdown.h"
 
 typedef struct LoopbackDevice {
         char *path;
@@ -111,8 +112,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 */
index ac46670f04f4432f34bb52390fa7aab42a6677cb..b1aad976e575e0ccaf9aa962a24aa5cb133d8d83 100644 (file)
@@ -17,6 +17,7 @@
 #include "devnum-util.h"
 #include "errno-util.h"
 #include "fd-util.h"
+#include "shutdown.h"
 #include "string-util.h"
 
 typedef struct RaidDevice {
@@ -133,8 +134,7 @@ static int delete_md(RaidDevice *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);
 
         return RET_NERRNO(ioctl(fd, STOP_ARRAY, NULL));
 }