Skip to content

Commit

Permalink
EncryptInplace: fsync cryptofd before reporting success
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ebiggers committed Nov 5, 2020
1 parent 91e4f1d commit 1ba8865
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions EncryptInplace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ bool InPlaceEncrypter::EncryptInPlace(const std::string& crypto_blkdev,

if (success) success &= EncryptPendingData();

if (success && fsync(cryptofd_) != 0) {
PLOG(ERROR) << "Error syncing " << crypto_blkdev_;
success = false;
}

if (!success) {
LOG(ERROR) << "In-place encryption of " << DescribeFilesystem() << " failed";
return false;
Expand Down

0 comments on commit 1ba8865

Please sign in to comment.