Remove progress property support from encrypt_inplace()
Now that FDE support has been removed, encrypt_inplace() is only used by metadata encryption, which passes false for the set_progress_properties parameter. Therefore, remove the set_progress_properties parameter and the associated code to update the "vold.encrypt_inplace" and "vold.encrypt_time_remaining" system properties. Note that encrypt_inplace() still keeps track of its progress to some extent, for the purpose of printing log messages; that hasn't changed. Bug: 208476087 Change-Id: If695db1c4e23f568ff865bccc9fc1b98148815be
This commit is contained in:
parent
1e1bade6ff
commit
640a1a9f43
3 changed files with 11 additions and 67 deletions
|
@ -20,13 +20,11 @@
|
||||||
#include <ext4_utils/ext4_utils.h>
|
#include <ext4_utils/ext4_utils.h>
|
||||||
#include <f2fs_sparseblock.h>
|
#include <f2fs_sparseblock.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <android-base/properties.h>
|
|
||||||
#include <android-base/unique_fd.h>
|
#include <android-base/unique_fd.h>
|
||||||
|
|
||||||
enum EncryptInPlaceError {
|
enum EncryptInPlaceError {
|
||||||
|
@ -43,7 +41,7 @@ static uint64_t round_up(uint64_t val, size_t amount) {
|
||||||
class InPlaceEncrypter {
|
class InPlaceEncrypter {
|
||||||
public:
|
public:
|
||||||
bool EncryptInPlace(const std::string& crypto_blkdev, const std::string& real_blkdev,
|
bool EncryptInPlace(const std::string& crypto_blkdev, const std::string& real_blkdev,
|
||||||
uint64_t nr_sec, bool set_progress_properties);
|
uint64_t nr_sec);
|
||||||
bool ProcessUsedBlock(uint64_t block_num);
|
bool ProcessUsedBlock(uint64_t block_num);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -75,19 +73,14 @@ class InPlaceEncrypter {
|
||||||
std::string real_blkdev_;
|
std::string real_blkdev_;
|
||||||
std::string crypto_blkdev_;
|
std::string crypto_blkdev_;
|
||||||
uint64_t nr_sec_;
|
uint64_t nr_sec_;
|
||||||
bool set_progress_properties_;
|
|
||||||
|
|
||||||
android::base::unique_fd realfd_;
|
android::base::unique_fd realfd_;
|
||||||
android::base::unique_fd cryptofd_;
|
android::base::unique_fd cryptofd_;
|
||||||
|
|
||||||
time_t time_started_;
|
|
||||||
int remaining_time_;
|
|
||||||
|
|
||||||
std::string fs_type_;
|
std::string fs_type_;
|
||||||
uint64_t blocks_done_;
|
uint64_t blocks_done_;
|
||||||
uint64_t blocks_to_encrypt_;
|
uint64_t blocks_to_encrypt_;
|
||||||
unsigned int block_size_;
|
unsigned int block_size_;
|
||||||
unsigned int cur_pct_;
|
|
||||||
|
|
||||||
std::vector<uint8_t> io_buffer_;
|
std::vector<uint8_t> io_buffer_;
|
||||||
uint64_t first_pending_block_;
|
uint64_t first_pending_block_;
|
||||||
|
@ -108,7 +101,6 @@ void InPlaceEncrypter::InitFs(const std::string& fs_type, uint64_t blocks_to_enc
|
||||||
blocks_done_ = 0;
|
blocks_done_ = 0;
|
||||||
blocks_to_encrypt_ = blocks_to_encrypt;
|
blocks_to_encrypt_ = blocks_to_encrypt;
|
||||||
block_size_ = block_size;
|
block_size_ = block_size;
|
||||||
cur_pct_ = 0;
|
|
||||||
|
|
||||||
// Allocate the I/O buffer. kIOBufferSize should always be a multiple of
|
// Allocate the I/O buffer. kIOBufferSize should always be a multiple of
|
||||||
// the filesystem block size, but round it up just in case.
|
// the filesystem block size, but round it up just in case.
|
||||||
|
@ -136,46 +128,6 @@ void InPlaceEncrypter::UpdateProgress(size_t blocks, bool done) {
|
||||||
|
|
||||||
if (blocks_done_ >= blocks_next_msg)
|
if (blocks_done_ >= blocks_next_msg)
|
||||||
LOG(DEBUG) << "Encrypted " << blocks_next_msg << " of " << blocks_to_encrypt_ << " blocks";
|
LOG(DEBUG) << "Encrypted " << blocks_next_msg << " of " << blocks_to_encrypt_ << " blocks";
|
||||||
|
|
||||||
if (!set_progress_properties_) return;
|
|
||||||
|
|
||||||
uint64_t new_pct;
|
|
||||||
if (done) {
|
|
||||||
new_pct = 100;
|
|
||||||
} else {
|
|
||||||
new_pct = (blocks_done_ * 100) / std::max<uint64_t>(blocks_to_encrypt_, 1);
|
|
||||||
new_pct = std::min<uint64_t>(new_pct, 99);
|
|
||||||
}
|
|
||||||
if (new_pct > cur_pct_) {
|
|
||||||
cur_pct_ = new_pct;
|
|
||||||
android::base::SetProperty("vold.encrypt_progress", std::to_string(new_pct));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cur_pct_ >= 5) {
|
|
||||||
struct timespec time_now;
|
|
||||||
if (clock_gettime(CLOCK_MONOTONIC, &time_now)) {
|
|
||||||
PLOG(WARNING) << "Error getting time while updating encryption progress";
|
|
||||||
} else {
|
|
||||||
double elapsed_time = difftime(time_now.tv_sec, time_started_);
|
|
||||||
|
|
||||||
uint64_t remaining_blocks = 0;
|
|
||||||
if (blocks_done_ < blocks_to_encrypt_)
|
|
||||||
remaining_blocks = blocks_to_encrypt_ - blocks_done_;
|
|
||||||
|
|
||||||
int remaining_time = 0;
|
|
||||||
if (blocks_done_ != 0)
|
|
||||||
remaining_time = (int)(elapsed_time * remaining_blocks / blocks_done_);
|
|
||||||
|
|
||||||
// Change time only if not yet set, lower, or a lot higher for
|
|
||||||
// best user experience
|
|
||||||
if (remaining_time_ == -1 || remaining_time < remaining_time_ ||
|
|
||||||
remaining_time > remaining_time_ + 60) {
|
|
||||||
remaining_time_ = remaining_time;
|
|
||||||
android::base::SetProperty("vold.encrypt_time_remaining",
|
|
||||||
std::to_string(remaining_time));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InPlaceEncrypter::EncryptPendingData() {
|
bool InPlaceEncrypter::EncryptPendingData() {
|
||||||
|
@ -313,14 +265,10 @@ bool InPlaceEncrypter::DoEncryptInPlace() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InPlaceEncrypter::EncryptInPlace(const std::string& crypto_blkdev,
|
bool InPlaceEncrypter::EncryptInPlace(const std::string& crypto_blkdev,
|
||||||
const std::string& real_blkdev, uint64_t nr_sec,
|
const std::string& real_blkdev, uint64_t nr_sec) {
|
||||||
bool set_progress_properties) {
|
|
||||||
struct timespec time_started = {0};
|
|
||||||
|
|
||||||
real_blkdev_ = real_blkdev;
|
real_blkdev_ = real_blkdev;
|
||||||
crypto_blkdev_ = crypto_blkdev;
|
crypto_blkdev_ = crypto_blkdev;
|
||||||
nr_sec_ = nr_sec;
|
nr_sec_ = nr_sec;
|
||||||
set_progress_properties_ = set_progress_properties;
|
|
||||||
|
|
||||||
realfd_.reset(open64(real_blkdev.c_str(), O_RDONLY | O_CLOEXEC));
|
realfd_.reset(open64(real_blkdev.c_str(), O_RDONLY | O_CLOEXEC));
|
||||||
if (realfd_ < 0) {
|
if (realfd_ < 0) {
|
||||||
|
@ -334,13 +282,6 @@ bool InPlaceEncrypter::EncryptInPlace(const std::string& crypto_blkdev,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clock_gettime(CLOCK_MONOTONIC, &time_started)) {
|
|
||||||
PLOG(WARNING) << "Error getting time at start of in-place encryption";
|
|
||||||
// Note - continue anyway - we'll run with 0
|
|
||||||
}
|
|
||||||
time_started_ = time_started.tv_sec;
|
|
||||||
remaining_time_ = -1;
|
|
||||||
|
|
||||||
bool success = DoEncryptInPlace();
|
bool success = DoEncryptInPlace();
|
||||||
|
|
||||||
if (success) success &= EncryptPendingData();
|
if (success) success &= EncryptPendingData();
|
||||||
|
@ -359,8 +300,11 @@ bool InPlaceEncrypter::EncryptInPlace(const std::string& crypto_blkdev,
|
||||||
<< ") was incorrect; we actually encrypted " << blocks_done_
|
<< ") was incorrect; we actually encrypted " << blocks_done_
|
||||||
<< " blocks. Encryption progress was inaccurate";
|
<< " blocks. Encryption progress was inaccurate";
|
||||||
}
|
}
|
||||||
// Make sure vold.encrypt_progress gets set to 100.
|
// Ensure that the final progress message is printed, so the series of log
|
||||||
|
// messages ends with e.g. "Encrypted 50327 of 50327 blocks" rather than
|
||||||
|
// "Encrypted 50000 of 50327 blocks".
|
||||||
UpdateProgress(0, true);
|
UpdateProgress(0, true);
|
||||||
|
|
||||||
LOG(INFO) << "Successfully encrypted " << DescribeFilesystem();
|
LOG(INFO) << "Successfully encrypted " << DescribeFilesystem();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -371,10 +315,10 @@ bool InPlaceEncrypter::EncryptInPlace(const std::string& crypto_blkdev,
|
||||||
// sectors; however, if a filesystem is detected, then its size will be used
|
// sectors; however, if a filesystem is detected, then its size will be used
|
||||||
// instead, and only the in-use blocks of the filesystem will be encrypted.
|
// instead, and only the in-use blocks of the filesystem will be encrypted.
|
||||||
bool encrypt_inplace(const std::string& crypto_blkdev, const std::string& real_blkdev,
|
bool encrypt_inplace(const std::string& crypto_blkdev, const std::string& real_blkdev,
|
||||||
uint64_t nr_sec, bool set_progress_properties) {
|
uint64_t nr_sec) {
|
||||||
LOG(DEBUG) << "encrypt_inplace(" << crypto_blkdev << ", " << real_blkdev << ", " << nr_sec
|
LOG(DEBUG) << "encrypt_inplace(" << crypto_blkdev << ", " << real_blkdev << ", " << nr_sec
|
||||||
<< ", " << (set_progress_properties ? "true" : "false") << ")";
|
<< ")";
|
||||||
|
|
||||||
InPlaceEncrypter encrypter;
|
InPlaceEncrypter encrypter;
|
||||||
return encrypter.EncryptInPlace(crypto_blkdev, real_blkdev, nr_sec, set_progress_properties);
|
return encrypter.EncryptInPlace(crypto_blkdev, real_blkdev, nr_sec);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
bool encrypt_inplace(const std::string& crypto_blkdev, const std::string& real_blkdev,
|
bool encrypt_inplace(const std::string& crypto_blkdev, const std::string& real_blkdev,
|
||||||
uint64_t nr_sec, bool set_progress_properties);
|
uint64_t nr_sec);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -314,7 +314,7 @@ bool fscrypt_mount_metadata_encrypted(const std::string& blk_device, const std::
|
||||||
}
|
}
|
||||||
LOG(DEBUG) << "Format of " << crypto_blkdev << " for " << mount_point << " succeeded.";
|
LOG(DEBUG) << "Format of " << crypto_blkdev << " for " << mount_point << " succeeded.";
|
||||||
} else {
|
} else {
|
||||||
if (!encrypt_inplace(crypto_blkdev, blk_device, nr_sec, false)) {
|
if (!encrypt_inplace(crypto_blkdev, blk_device, nr_sec)) {
|
||||||
LOG(ERROR) << "encrypt_inplace failed in mountFstab";
|
LOG(ERROR) << "encrypt_inplace failed in mountFstab";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue