diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-08-17 19:54:38 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2020-08-18 12:41:18 +0200 |
commit | a2a8a509cd56955c0ce42ba0650d163e0d3eeb82 (patch) | |
tree | dabfc31a985b2f77e1e8cb784459fb835bc9bb0a /src/home | |
parent | homed: downgrade quota message in containers (diff) | |
download | systemd-a2a8a509cd56955c0ce42ba0650d163e0d3eeb82.tar.xz systemd-a2a8a509cd56955c0ce42ba0650d163e0d3eeb82.zip |
homework: sync everything to disk before we rename LUKS loopback file into place
This how this works on Linux: when atomically creating a file we need to
fully populate it under a temporary name and then when we are fully
done, sync it and the directory it is contained in, before renaming it
to the final name.
Diffstat (limited to 'src/home')
-rw-r--r-- | src/home/homework-luks.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 1eb08e1423..7ce59c8bf3 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 */ |