From 1740effeaa29f7dd84d9068a98b42590ea7e99ce Mon Sep 17 00:00:00 2001 From: Denis Hsu Date: Thu, 26 Dec 2019 16:06:37 +0800 Subject: [PATCH] Consistently use CLOCK_MONOTONIC for timing encryption time_started in encryptGroupsData is set from and compared to clock_gettime(CLOCK_MONOTONIC, ...) nearly everywhere: "Clock that cannot be set and represents monotonic time since some unspecified starting point". However in cryptfs_enable_inplace_f2fs() it is set from a different clock, time(NULL), with the result that the setprop calls that indicate progress are wrong and can be called much too often. The fix is to make this function consistent with cryptfs_enable_inplace_ext4. Bug: 146877356 Change-Id: I2707180e5c5bf723a5a880f6a3aac47f2bb34ccd --- EncryptInplace.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/EncryptInplace.cpp b/EncryptInplace.cpp index 3755718..9d304da 100644 --- a/EncryptInplace.cpp +++ b/EncryptInplace.cpp @@ -391,6 +391,8 @@ static int cryptfs_enable_inplace_f2fs(const char* crypto_blkdev, const char* re struct encryptGroupsData data; struct f2fs_info* f2fs_info = NULL; int rc = ENABLE_INPLACE_ERR_OTHER; + struct timespec time_started = {0}; + if (previously_encrypted_upto > *size_already_done) { LOG(DEBUG) << "Not fast encrypting since resuming part way through"; return ENABLE_INPLACE_ERR_OTHER; @@ -423,9 +425,14 @@ static int cryptfs_enable_inplace_f2fs(const char* crypto_blkdev, const char* re data.one_pct = data.tot_used_blocks / 100; data.cur_pct = 0; - data.time_started = time(NULL); + if (clock_gettime(CLOCK_MONOTONIC, &time_started)) { + LOG(WARNING) << "Error getting time at start"; + // Note - continue anyway - we'll run with 0 + } + data.time_started = time_started.tv_sec; data.remaining_time = -1; + data.buffer = (char*)malloc(f2fs_info->block_size); if (!data.buffer) { LOG(ERROR) << "Failed to allocate crypto buffer";