Skip to content

Commit 1ba8865

Browse files
committed
EncryptInplace: fsync cryptofd before reporting success
fsync() the cryptofd when done writing to it. Without this, any remaining dirty pages in the crypto_blkdev's page cache (which there might be a lot of, even as much as all the data that was written) won't be flushed to disk until the cryptofd is closed, which ignores I/O errors and is also after we already reported 100% completion. There wasn't an fsync() in the original version either, so we've been getting by without it, but it seems it should be there. Change-Id: Idd1be3ae67ce96ecf3946b9efb9fc57414f5805a
1 parent 91e4f1d commit 1ba8865

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

EncryptInplace.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ bool InPlaceEncrypter::EncryptInPlace(const std::string& crypto_blkdev,
345345

346346
if (success) success &= EncryptPendingData();
347347

348+
if (success && fsync(cryptofd_) != 0) {
349+
PLOG(ERROR) << "Error syncing " << crypto_blkdev_;
350+
success = false;
351+
}
352+
348353
if (!success) {
349354
LOG(ERROR) << "In-place encryption of " << DescribeFilesystem() << " failed";
350355
return false;

0 commit comments

Comments
 (0)