Merge "ueventd: populate /dev/block/mapper link" am: 5c811fd01a
am: ee32edb306
am: ae0c91dad4
Change-Id: I00cf5253eb00976f38792aef63b72f9216c6cc2f
This commit is contained in:
commit
f080bf39d3
1 changed files with 38 additions and 0 deletions
|
@ -21,8 +21,14 @@
|
|||
#include <sys/sysmacros.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <android-base/chrono_utils.h>
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
#include <android-base/strings.h>
|
||||
|
@ -37,12 +43,16 @@
|
|||
#error "Do not include init.h in files used by ueventd; it will expose init's globals"
|
||||
#endif
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
using android::base::Basename;
|
||||
using android::base::Dirname;
|
||||
using android::base::ReadFileToString;
|
||||
using android::base::Readlink;
|
||||
using android::base::Realpath;
|
||||
using android::base::StartsWith;
|
||||
using android::base::StringPrintf;
|
||||
using android::base::Trim;
|
||||
|
||||
namespace android {
|
||||
namespace init {
|
||||
|
@ -101,6 +111,31 @@ static bool FindVbdDevicePrefix(const std::string& path, std::string* result) {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Given a path that may start with a virtual dm block device, populate
|
||||
// the supplied buffer with the dm module's instantiated name.
|
||||
// If it doesn't start with a virtual block device, or there is some
|
||||
// error, return false.
|
||||
static bool FindDmDevicePartition(const std::string& path, std::string* result) {
|
||||
result->clear();
|
||||
if (!StartsWith(path, "/devices/virtual/block/dm-")) return false;
|
||||
if (getpid() == 1) return false; // first_stage_init has no sepolicy needs
|
||||
|
||||
static std::map<std::string, std::string> cache;
|
||||
// wait_for_file will not work, the content is also delayed ...
|
||||
for (android::base::Timer t; t.duration() < 200ms; std::this_thread::sleep_for(10ms)) {
|
||||
if (ReadFileToString("/sys" + path + "/dm/name", result) && !result->empty()) {
|
||||
// Got it, set cache with result, when node arrives
|
||||
cache[path] = *result = Trim(*result);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
auto it = cache.find(path);
|
||||
if ((it == cache.end()) || (it->second.empty())) return false;
|
||||
// Return cached results, when node goes away
|
||||
*result = it->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
Permissions::Permissions(const std::string& name, mode_t perm, uid_t uid, gid_t gid)
|
||||
: name_(name), perm_(perm), uid_(uid), gid_(gid), prefix_(false), wildcard_(false) {
|
||||
// Set 'prefix_' or 'wildcard_' based on the below cases:
|
||||
|
@ -293,6 +328,7 @@ void SanitizePartitionName(std::string* string) {
|
|||
std::vector<std::string> DeviceHandler::GetBlockDeviceSymlinks(const Uevent& uevent) const {
|
||||
std::string device;
|
||||
std::string type;
|
||||
std::string partition;
|
||||
|
||||
if (FindPlatformDevice(uevent.path, &device)) {
|
||||
// Skip /devices/platform or /devices/ if present
|
||||
|
@ -310,6 +346,8 @@ std::vector<std::string> DeviceHandler::GetBlockDeviceSymlinks(const Uevent& uev
|
|||
type = "pci";
|
||||
} else if (FindVbdDevicePrefix(uevent.path, &device)) {
|
||||
type = "vbd";
|
||||
} else if (FindDmDevicePartition(uevent.path, &partition)) {
|
||||
return {"/dev/block/mapper/" + partition};
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue