OSDN Git Service

Use dm.CreateDevice() with a timeout.
authorMartijn Coenen <maco@google.com>
Mon, 12 Oct 2020 11:26:52 +0000 (13:26 +0200)
committerMartijn Coenen <maco@google.com>
Mon, 12 Oct 2020 14:59:50 +0000 (16:59 +0200)
Using the regular CreateDevice() variant with getDmDeviceByName() has a
race-condition that is documented in libdm/dm.h; instead, use the
variant with a timeout, which guarantees that the block device exists
when it returns.

Test: atest AdoptableHostTest
Bug: 150935323
Change-Id: Ic06cad9af7c44e23359d95b262f68dba27ddfb3a

MetadataCrypt.cpp

index c61132c..4b61373 100644 (file)
@@ -216,7 +216,7 @@ static bool create_crypto_blk_dev(const std::string& dm_name, const std::string&
 
     auto& dm = DeviceMapper::Instance();
     for (int i = 0;; i++) {
-        if (dm.CreateDevice(dm_name, table)) {
+        if (dm.CreateDevice(dm_name, table, crypto_blkdev, std::chrono::seconds(5))) {
             break;
         }
         if (i + 1 >= TABLE_LOAD_RETRIES) {
@@ -227,10 +227,6 @@ static bool create_crypto_blk_dev(const std::string& dm_name, const std::string&
         usleep(500000);
     }
 
-    if (!dm.GetDmDevicePathByName(dm_name, crypto_blkdev)) {
-        LOG(ERROR) << "Cannot retrieve default-key device status " << dm_name;
-        return false;
-    }
     return true;
 }