OSDN Git Service

Lock while partitioning.
authorJeff Sharkey <jsharkey@android.com>
Wed, 15 Apr 2015 06:14:23 +0000 (23:14 -0700)
committerJeff Sharkey <jsharkey@android.com>
Wed, 15 Apr 2015 06:14:23 +0000 (23:14 -0700)
Otherwise we get really excited and trip over ourselves while
partitions are still being created.

Bug: 19993667
Change-Id: I034e56b3063a71d73f9311a945c05ea2ae255f7d

Disk.cpp
Disk.h
VolumeManager.cpp

index 04c43cf..51eeba8 100644 (file)
--- a/Disk.cpp
+++ b/Disk.cpp
@@ -223,6 +223,8 @@ status_t Disk::readMetadata() {
 }
 
 status_t Disk::readPartitions() {
+    std::lock_guard<std::mutex> lock(mLock);
+
     int8_t maxMinors = getMaxMinors();
     if (maxMinors < 0) {
         return -ENOTSUP;
@@ -311,6 +313,8 @@ status_t Disk::unmountAll() {
 }
 
 status_t Disk::partitionPublic() {
+    std::lock_guard<std::mutex> lock(mLock);
+
     // TODO: improve this code
     destroyAllVolumes();
     mJustPartitioned = true;
@@ -357,6 +361,8 @@ status_t Disk::partitionPrivate() {
 }
 
 status_t Disk::partitionMixed(int8_t ratio) {
+    std::lock_guard<std::mutex> lock(mLock);
+
     int res;
 
     destroyAllVolumes();
diff --git a/Disk.h b/Disk.h
index a8461fb..5ba6bae 100644 (file)
--- a/Disk.h
+++ b/Disk.h
@@ -21,6 +21,7 @@
 
 #include <utils/Errors.h>
 
+#include <mutex>
 #include <vector>
 
 namespace android {
@@ -100,6 +101,8 @@ private:
     int mFlags;
     /* Flag indicating object is created */
     bool mCreated;
+    /* Lock held while partitioning */
+    std::mutex mLock;
     /* Flag that we just partitioned and should format all volumes */
     bool mJustPartitioned;
 
index 86e3fd4..dcadd14 100644 (file)
@@ -310,6 +310,7 @@ void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
         break;
     }
     case NetlinkEvent::Action::kChange: {
+        LOG(DEBUG) << "Disk at " << major << ":" << minor << " changed";
         for (auto disk : mDisks) {
             if (disk->getDevice() == device) {
                 disk->readMetadata();