From 659b63fe001af60913ccc68788967df3f48f95f8 Mon Sep 17 00:00:00 2001 From: Paul Crowley Date: Fri, 7 Feb 2020 12:15:56 -0800 Subject: [PATCH] Use DM layer directly to manage private DM volumes Abolish cryptfs_revert_ext_volume, handle in caller. This allows us to use DeleteDeviceIfExists, avoiding a spurious error message. Test: create private volume on Cuttlefish, eject, check logs Bug: 147814592 Change-Id: I836d8bd11b29e32da0863aaa75144543bb9cab9c --- cryptfs.cpp | 8 -------- cryptfs.h | 1 - model/PrivateVolume.cpp | 13 ++++++++++--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cryptfs.cpp b/cryptfs.cpp index e00165f..c0816ab 100644 --- a/cryptfs.cpp +++ b/cryptfs.cpp @@ -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); } -/* - * 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) { return do_crypto_complete("/data"); } diff --git a/cryptfs.h b/cryptfs.h index 463db7f..9b5eae7 100644 --- a/cryptfs.h +++ b/cryptfs.h @@ -66,7 +66,6 @@ int cryptfs_changepw(int type, const char* newpw); int cryptfs_enable_default(int no_ui); int cryptfs_setup_ext_volume(const char* label, const char* real_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_setfield(const char* fieldname, const char* value); int cryptfs_mount_default_encrypted(void); diff --git a/model/PrivateVolume.cpp b/model/PrivateVolume.cpp index 1653fae..4a0b250 100644 --- a/model/PrivateVolume.cpp +++ b/model/PrivateVolume.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -66,7 +67,11 @@ status_t PrivateVolume::doCreate() { } // 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 @@ -80,8 +85,10 @@ status_t PrivateVolume::doCreate() { } status_t PrivateVolume::doDestroy() { - if (cryptfs_revert_ext_volume(getId().c_str())) { - LOG(ERROR) << getId() << " failed to revert cryptfs"; + auto& dm = dm::DeviceMapper::Instance(); + if (!dm.DeleteDevice(getId())) { + PLOG(ERROR) << "Cannot remove dm device " << getId(); + return -EIO; } return DestroyDeviceNode(mRawDevPath); }