diff options
| author | Fabiano Rosas <farosas@suse.de> | 2024-02-29 12:29:59 -0300 |
|---|---|---|
| committer | Peter Xu <peterx@redhat.com> | 2024-03-01 15:42:04 +0800 |
| commit | c05dfcb7f2c5e39fc47c347de305df4e6afb4fa9 (patch) | |
| tree | 81260a1275b385de671dc652e0a0757ff7e475e7 | |
| parent | 0478b030fa2530cbbfc4d6432e8e39a16d06865b (diff) | |
| download | focaccia-qemu-c05dfcb7f2c5e39fc47c347de305df4e6afb4fa9.tar.gz focaccia-qemu-c05dfcb7f2c5e39fc47c347de305df4e6afb4fa9.zip | |
io: fsync before closing a file channel
Make sure the data is flushed to disk before closing file channels. This is to ensure data is on disk and not lost in the event of a host crash. This is currently being implemented to affect the migration code when migrating to a file, but all QIOChannelFile users should benefit from the change. Reviewed-by: "Daniel P. Berrangé" <berrange@redhat.com> Acked-by: "Daniel P. Berrangé" <berrange@redhat.com> Signed-off-by: Fabiano Rosas <farosas@suse.de> Link: https://lore.kernel.org/r/20240229153017.2221-6-farosas@suse.de Signed-off-by: Peter Xu <peterx@redhat.com>
| -rw-r--r-- | io/channel-file.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/io/channel-file.c b/io/channel-file.c index a6ad7770c6..d4706fa592 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -242,6 +242,11 @@ static int qio_channel_file_close(QIOChannel *ioc, { QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc); + if (qemu_fdatasync(fioc->fd) < 0) { + error_setg_errno(errp, errno, + "Unable to synchronize file data with storage device"); + return -1; + } if (qemu_close(fioc->fd) < 0) { error_setg_errno(errp, errno, "Unable to close file"); |