1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

shutdown: replace unbounded fsync() with bounded sync_with_progress()

Let's put a time-out on this syncing.

Inspired-by: #34289 #34283
This commit is contained in:
Lennart Poettering 2024-09-09 17:53:03 +02:00
parent 13b5225d62
commit b4b66b2662
3 changed files with 10 additions and 9 deletions

View 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 = {

View 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 */

View 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));
}