summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/home/homework-luks.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c
index ba47688b0f..be296f1a4b 100644
--- a/src/home/homework-luks.c
+++ b/src/home/homework-luks.c
@@ -2174,8 +2174,22 @@ int home_create_luks(
goto fail;
}
+ /* Sync everything to disk before we move things into place under the final name. */
+ if (fsync(image_fd) < 0) {
+ r = log_error_errno(r, "Failed to synchronize image to disk: %m");
+ goto fail;
+ }
+
if (disk_uuid_path)
(void) ioctl(image_fd, BLKRRPART, 0);
+ else {
+ /* If we operate on a file, sync the contaning directory too. */
+ r = fsync_directory_of_file(image_fd);
+ if (r < 0) {
+ log_error_errno(r, "Failed to synchronize directory of image file to disk: %m");
+ goto fail;
+ }
+ }
/* Let's close the image fd now. If we are operating on a real block device this will release the BSD
* lock that ensures udev doesn't interfere with what we are doing */