Skip to content

Commit 74667d4

Browse files
poetteringbluca
authored andcommitted
shutdown: replace unbounded fsync() with bounded sync_with_progress()
Let's put a time-out on this syncing. Inspired-by: #34289 #34283 (cherry picked from commit b4b66b2) (cherry picked from commit dbf9334)
1 parent be91329 commit 74667d4

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/shutdown/detach-dm.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "devnum-util.h"
1616
#include "errno-util.h"
1717
#include "fd-util.h"
18-
#include "sync-util.h"
18+
#include "shutdown.h"
1919

2020
typedef struct DeviceMapper {
2121
char *path;
@@ -93,7 +93,6 @@ static int dm_list_get(DeviceMapper **head) {
9393

9494
static int delete_dm(DeviceMapper *m) {
9595
_cleanup_close_ int fd = -EBADF;
96-
int r;
9796

9897
assert(m);
9998
assert(major(m->devnum) != 0);
@@ -103,9 +102,11 @@ static int delete_dm(DeviceMapper *m) {
103102
if (fd < 0)
104103
return -errno;
105104

106-
r = fsync_path_at(AT_FDCWD, m->path);
107-
if (r < 0)
108-
log_debug_errno(r, "Failed to sync DM block device %s, ignoring: %m", m->path);
105+
_cleanup_close_ int block_fd = open(m->path, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
106+
if (block_fd < 0)
107+
log_debug_errno(errno, "Failed to open DM block device %s for syncing, ignoring: %m", m->path);
108+
else
109+
(void) sync_with_progress(block_fd);
109110

110111
return RET_NERRNO(ioctl(fd, DM_DEV_REMOVE, &(struct dm_ioctl) {
111112
.version = {

src/shutdown/detach-loopback.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "detach-loopback.h"
1919
#include "device-util.h"
2020
#include "fd-util.h"
21+
#include "shutdown.h"
2122

2223
typedef struct LoopbackDevice {
2324
char *path;
@@ -111,8 +112,7 @@ static int delete_loopback(const char *device) {
111112

112113
/* Loopback block devices don't sync in-flight blocks when we clear the fd, hence sync explicitly
113114
* first */
114-
if (fsync(fd) < 0)
115-
log_debug_errno(errno, "Failed to sync loop block device %s, ignoring: %m", device);
115+
(void) sync_with_progress(fd);
116116

117117
if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
118118
if (errno == ENXIO) /* Nothing bound, didn't do anything */

src/shutdown/detach-md.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "devnum-util.h"
1818
#include "errno-util.h"
1919
#include "fd-util.h"
20+
#include "shutdown.h"
2021
#include "string-util.h"
2122

2223
typedef struct RaidDevice {
@@ -133,8 +134,7 @@ static int delete_md(RaidDevice *m) {
133134
if (fd < 0)
134135
return -errno;
135136

136-
if (fsync(fd) < 0)
137-
log_debug_errno(errno, "Failed to sync MD block device %s, ignoring: %m", m->path);
137+
(void) sync_with_progress(fd);
138138

139139
return RET_NERRNO(ioctl(fd, STOP_ARRAY, NULL));
140140
}

0 commit comments

Comments
 (0)