Emulated volumes above private volumes.

When a private volume is mounted, create an emulated volume above it
hosted at the /media path on that device.  That emulated volume is
automatically torn down when unmounting the private volume.

Add "removed" state for volume, which signals to framework that
media has left the building, send when the volume is destroyed.

Bug: 19993667
Change-Id: I1f82b51de578ac5cfcc5d7b9a6fb44f6f25c775c
gugelfrei
Jeff Sharkey 9 years ago
parent ce6a913aea
commit 3161fb3702

@ -163,6 +163,7 @@ void Disk::createPrivateVolume(dev_t device, const std::string& partGuid) {
void Disk::destroyAllVolumes() {
for (auto vol : mVolumes) {
notifyEvent(ResponseCode::DiskVolumeDestroyed, vol->getId());
vol->destroy();
}
mVolumes.clear();

@ -36,16 +36,18 @@ namespace vold {
static const char* kFusePath = "/system/bin/sdcard";
EmulatedVolume::EmulatedVolume(const std::string& rawPath,
const std::string& fsUuid) : VolumeBase(Type::kEmulated), mFusePid(0) {
if (fsUuid.empty()) {
setId("emulated");
} else {
setId(StringPrintf("emulated:%s", fsUuid.c_str()));
}
EmulatedVolume::EmulatedVolume(const std::string& rawPath) :
VolumeBase(Type::kEmulated), mFusePid(0) {
setId("emulated");
mFusePath = "/storage/emulated";
mRawPath = rawPath;
}
EmulatedVolume::EmulatedVolume(const std::string& rawPath, dev_t device,
const std::string& fsUuid) : VolumeBase(Type::kEmulated), mFusePid(0) {
setId(StringPrintf("emulated:%u,%u", major(device), minor(device)));
mFusePath = StringPrintf("/storage/%s", fsUuid.c_str());
mRawPath = rawPath;
mFusePath = StringPrintf("/storage/%s", getId().c_str());
}
EmulatedVolume::~EmulatedVolume() {

@ -37,7 +37,8 @@ namespace vold {
*/
class EmulatedVolume : public VolumeBase {
public:
EmulatedVolume(const std::string& rawPath, const std::string& fsUuid);
EmulatedVolume(const std::string& rawPath);
EmulatedVolume(const std::string& rawPath, dev_t device, const std::string& fsUuid);
virtual ~EmulatedVolume();
protected:

@ -16,6 +16,7 @@
#include "Ext4.h"
#include "PrivateVolume.h"
#include "EmulatedVolume.h"
#include "Utils.h"
#include "VolumeManager.h"
#include "ResponseCode.h"
@ -120,6 +121,14 @@ status_t PrivateVolume::doMount() {
return -EIO;
}
// Create a new emulated volume stacked above us, it will automatically
// be destroyed during unmount
std::string mediaPath(mPath + "/media");
auto vol = std::shared_ptr<VolumeBase>(
new EmulatedVolume(mediaPath, mRawDevice, mFsUuid));
addVolume(vol);
vol->create();
return OK;
}

@ -70,6 +70,7 @@ public:
static const int DiskSizeChanged = 641;
static const int DiskLabelChanged = 642;
static const int DiskVolumeCreated = 643;
static const int DiskVolumeDestroyed = 644;
static const int DiskDestroyed = 649;
static const int VolumeCreated = 650;

@ -135,6 +135,7 @@ status_t VolumeBase::create() {
mCreated = true;
status_t res = doCreate();
notifyEvent(ResponseCode::VolumeCreated, StringPrintf("%d", mType));
setState(State::kUnmounted);
return res;
}
@ -149,6 +150,7 @@ status_t VolumeBase::destroy() {
unmount();
}
setState(State::kRemoved);
notifyEvent(ResponseCode::VolumeDestroyed);
status_t res = doDestroy();
mCreated = false;
@ -185,8 +187,8 @@ status_t VolumeBase::unmount() {
setState(State::kUnmounting);
for (auto vol : mVolumes) {
if (vol->unmount()) {
LOG(WARNING) << getId() << " failed to unmount " << vol->getId()
if (vol->destroy()) {
LOG(WARNING) << getId() << " failed to destroy " << vol->getId()
<< " stacked above";
}
}

@ -75,6 +75,8 @@ public:
kUnmounting,
/* Next states: mounting, formatting */
kUnmountable,
/* Next states: none */
kRemoved,
};
const std::string& getId() { return mId; }

@ -260,7 +260,7 @@ int VolumeManager::start() {
// Assume that we always have an emulated volume on internal
// storage; the framework will decide if it should be mounted.
mInternalEmulated = std::shared_ptr<android::vold::VolumeBase>(
new android::vold::EmulatedVolume("/data/media", ""));
new android::vold::EmulatedVolume("/data/media"));
mInternalEmulated->create();
return 0;

Loading…
Cancel
Save