Merge "Use DM layer directly to manage private DM volumes"

This commit is contained in:
Paul Crowley 2020-02-13 18:35:26 +00:00 committed by Gerrit Code Review
commit dd12ea5bd2
3 changed files with 10 additions and 12 deletions

View file

@ -1939,14 +1939,6 @@ int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev, const K
real_blkdev, out_crypto_blkdev, label, flags); real_blkdev, out_crypto_blkdev, label, flags);
} }
/*
* Called by vold when it's asked to unmount an encrypted external
* storage volume.
*/
int cryptfs_revert_ext_volume(const char* label) {
return delete_crypto_blk_dev(label);
}
int cryptfs_crypto_complete(void) { int cryptfs_crypto_complete(void) {
return do_crypto_complete("/data"); return do_crypto_complete("/data");
} }

View file

@ -66,7 +66,6 @@ int cryptfs_changepw(int type, const char* newpw);
int cryptfs_enable_default(int no_ui); int cryptfs_enable_default(int no_ui);
int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev, int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev,
const android::vold::KeyBuffer& key, std::string* out_crypto_blkdev); const android::vold::KeyBuffer& key, std::string* out_crypto_blkdev);
int cryptfs_revert_ext_volume(const char* label);
int cryptfs_getfield(const char* fieldname, char* value, int len); int cryptfs_getfield(const char* fieldname, char* value, int len);
int cryptfs_setfield(const char* fieldname, const char* value); int cryptfs_setfield(const char* fieldname, const char* value);
int cryptfs_mount_default_encrypted(void); int cryptfs_mount_default_encrypted(void);

View file

@ -25,6 +25,7 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android-base/stringprintf.h> #include <android-base/stringprintf.h>
#include <cutils/fs.h> #include <cutils/fs.h>
#include <libdm/dm.h>
#include <private/android_filesystem_config.h> #include <private/android_filesystem_config.h>
#include <fcntl.h> #include <fcntl.h>
@ -66,7 +67,11 @@ status_t PrivateVolume::doCreate() {
} }
// Recover from stale vold by tearing down any old mappings // Recover from stale vold by tearing down any old mappings
cryptfs_revert_ext_volume(getId().c_str()); auto& dm = dm::DeviceMapper::Instance();
if (!dm.DeleteDeviceIfExists(getId())) {
PLOG(ERROR) << "Cannot remove dm device " << getId();
return -EIO;
}
// TODO: figure out better SELinux labels for private volumes // TODO: figure out better SELinux labels for private volumes
@ -80,8 +85,10 @@ status_t PrivateVolume::doCreate() {
} }
status_t PrivateVolume::doDestroy() { status_t PrivateVolume::doDestroy() {
if (cryptfs_revert_ext_volume(getId().c_str())) { auto& dm = dm::DeviceMapper::Instance();
LOG(ERROR) << getId() << " failed to revert cryptfs"; if (!dm.DeleteDevice(getId())) {
PLOG(ERROR) << "Cannot remove dm device " << getId();
return -EIO;
} }
return DestroyDeviceNode(mRawDevPath); return DestroyDeviceNode(mRawDevPath);
} }