From 69520d2d39daf87edb75c3b68fef934ccf894c2f Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Tue, 3 Nov 2020 14:11:01 -0800 Subject: [PATCH] Remove special handling for missing crypto_blkdev This logic is no longer necessary, since the code that creates the crypto_blkdev (create_crypto_blk_dev() in MetadataCrypt.cpp or in cryptfs.cpp) now waits for the block device to appear before continuing. It's also worth noting that the retry loop was only present for ext4, not for f2fs, yet most Android devices are using f2fs these days. Test: see I08fc8465f7962abd698904b5466f3ed080d53953 Change-Id: I173ca6cc187a810e008990dfa22aede58632db25 --- EncryptInplace.cpp | 26 +++++--------------------- EncryptInplace.h | 1 - cryptfs.cpp | 7 ------- 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/EncryptInplace.cpp b/EncryptInplace.cpp index 438f959..4c1bb73 100644 --- a/EncryptInplace.cpp +++ b/EncryptInplace.cpp @@ -260,18 +260,10 @@ static int cryptfs_enable_inplace_ext4(const char* crypto_blkdev, const char* re } LOG(DEBUG) << "Opening" << crypto_blkdev; - // Wait until the block device appears. Re-use the mount retry values since it is reasonable. - while ((data.cryptofd = open(crypto_blkdev, O_WRONLY | O_CLOEXEC)) < 0) { - if (--retries) { - PLOG(ERROR) << "Error opening crypto_blkdev " << crypto_blkdev - << " for ext4 inplace encrypt, retrying"; - sleep(RETRY_MOUNT_DELAY_SECONDS); - } else { - PLOG(ERROR) << "Error opening crypto_blkdev " << crypto_blkdev - << " for ext4 inplace encrypt"; - rc = ENABLE_INPLACE_ERR_DEV; - goto errout; - } + if ((data.cryptofd = open(crypto_blkdev, O_WRONLY | O_CLOEXEC)) < 0) { + PLOG(ERROR) << "Error opening crypto_blkdev " << crypto_blkdev << " for inplace encrypt"; + rc = -1; + goto errout; } if (setjmp(setjmp_env)) { // NOLINT @@ -388,7 +380,6 @@ static int cryptfs_enable_inplace_f2fs(const char* crypto_blkdev, const char* re if ((data.cryptofd = open64(crypto_blkdev, O_WRONLY | O_CLOEXEC)) < 0) { PLOG(ERROR) << "Error opening crypto_blkdev " << crypto_blkdev << " for f2fs inplace encrypt"; - rc = ENABLE_INPLACE_ERR_DEV; goto errout; } @@ -456,7 +447,7 @@ static int cryptfs_enable_inplace_full(const char* crypto_blkdev, const char* re if ((cryptofd = open(crypto_blkdev, O_WRONLY | O_CLOEXEC)) < 0) { PLOG(ERROR) << "Error opening crypto_blkdev " << crypto_blkdev << " for inplace encrypt"; close(realfd); - return ENABLE_INPLACE_ERR_DEV; + return ENABLE_INPLACE_ERR_OTHER; } /* This is pretty much a simple loop of reading 4K, and writing 4K. @@ -547,12 +538,5 @@ int cryptfs_enable_inplace(const char* crypto_blkdev, const char* real_blkdev, o rc_full = cryptfs_enable_inplace_full(crypto_blkdev, real_blkdev, size, set_progress_properties); LOG(DEBUG) << "cryptfs_enable_inplace_full()=" << rc_full; - - /* Hack for b/17898962, the following is the symptom... */ - if (rc_ext4 == ENABLE_INPLACE_ERR_DEV && rc_f2fs == ENABLE_INPLACE_ERR_DEV && - rc_full == ENABLE_INPLACE_ERR_DEV) { - LOG(DEBUG) << "ENABLE_INPLACE_ERR_DEV"; - return ENABLE_INPLACE_ERR_DEV; - } return rc_full; } diff --git a/EncryptInplace.h b/EncryptInplace.h index 5967632..490a7b9 100644 --- a/EncryptInplace.h +++ b/EncryptInplace.h @@ -27,7 +27,6 @@ /* Return values for cryptfs_enable_inplace() */ #define ENABLE_INPLACE_OK 0 #define ENABLE_INPLACE_ERR_OTHER (-1) -#define ENABLE_INPLACE_ERR_DEV (-2) /* crypto_blkdev issue */ int cryptfs_enable_inplace(const char* crypto_blkdev, const char* real_blkdev, off64_t size, bool set_progress_properties); diff --git a/cryptfs.cpp b/cryptfs.cpp index 36bd43b..7830d6f 100644 --- a/cryptfs.cpp +++ b/cryptfs.cpp @@ -2068,13 +2068,6 @@ static int cryptfs_enable_all_volumes(struct crypt_mnt_ftr* crypt_ftr, const cha int rc = -1; rc = cryptfs_enable_inplace(crypto_blkdev, real_blkdev, crypt_ftr->fs_size, true); - - if (rc == ENABLE_INPLACE_ERR_DEV) { - /* Hack for b/17898962 */ - SLOGE("cryptfs_enable: crypto block dev failure. Must reboot...\n"); - cryptfs_reboot(RebootType::reboot); - } - if (!rc) { crypt_ftr->encrypted_upto = crypt_ftr->fs_size;