Merge "Avoid sysfs name clashes." into sc-dev

This commit is contained in:
TreeHugger Robot
2021-05-08 21:11:13 +00:00
committed by Android (Google) Code Review
2 changed files with 26 additions and 13 deletions

View File

@@ -206,23 +206,27 @@ static bool isValidMountTarget(std::string_view path) {
return path::isAbsolute(path) && path::isEmptyDir(path).value_or(true); return path::isAbsolute(path) && path::isEmptyDir(path).value_or(true);
} }
std::string makeBindMdName() { std::string makeUniqueName(std::string_view prefix) {
static constexpr auto uuidStringSize = 36; static constexpr auto uuidStringSize = 36;
uuid_t guid; uuid_t guid;
uuid_generate(guid); uuid_generate(guid);
std::string name; std::string name;
const auto prefixSize = constants().mountpointMdPrefix.size(); const auto prefixSize = prefix.size();
name.reserve(prefixSize + uuidStringSize); name.reserve(prefixSize + uuidStringSize);
name = constants().mountpointMdPrefix; name = prefix;
name.resize(prefixSize + uuidStringSize); name.resize(prefixSize + uuidStringSize);
uuid_unparse(guid, name.data() + prefixSize); uuid_unparse(guid, name.data() + prefixSize);
return name; return name;
} }
std::string makeBindMdName() {
return makeUniqueName(constants().mountpointMdPrefix);
}
static bool checkReadLogsDisabledMarker(std::string_view root) { static bool checkReadLogsDisabledMarker(std::string_view root) {
const auto markerPath = path::c_str(path::join(root, constants().readLogsDisabledMarkerName)); const auto markerPath = path::c_str(path::join(root, constants().readLogsDisabledMarkerName));
struct stat st; struct stat st;
@@ -422,7 +426,7 @@ void IncrementalService::onDump(int fd) {
} else { } else {
dprintf(fd, " mountId: %d\n", mnt.mountId); dprintf(fd, " mountId: %d\n", mnt.mountId);
dprintf(fd, " root: %s\n", mnt.root.c_str()); dprintf(fd, " root: %s\n", mnt.root.c_str());
const auto metricsInstanceName = path::basename(ifs->root); const auto& metricsInstanceName = ifs->metricsKey;
dprintf(fd, " metrics instance name: %s\n", path::c_str(metricsInstanceName).get()); dprintf(fd, " metrics instance name: %s\n", path::c_str(metricsInstanceName).get());
dprintf(fd, " nextStorageDirNo: %d\n", mnt.nextStorageDirNo.load()); dprintf(fd, " nextStorageDirNo: %d\n", mnt.nextStorageDirNo.load());
dprintf(fd, " flags: %d\n", int(mnt.flags)); dprintf(fd, " flags: %d\n", int(mnt.flags));
@@ -615,6 +619,7 @@ StorageId IncrementalService::createStorage(std::string_view mountPoint,
return kInvalidStorageId; return kInvalidStorageId;
} }
std::string metricsKey;
IncFsMount::Control control; IncFsMount::Control control;
{ {
std::lock_guard l(mMountOperationLock); std::lock_guard l(mMountOperationLock);
@@ -630,7 +635,8 @@ StorageId IncrementalService::createStorage(std::string_view mountPoint,
if (!mkdirOrLog(path::join(backing, ".incomplete"), 0777)) { if (!mkdirOrLog(path::join(backing, ".incomplete"), 0777)) {
return kInvalidStorageId; return kInvalidStorageId;
} }
auto status = mVold->mountIncFs(backing, mountTarget, 0, mountKey, &controlParcel); metricsKey = makeUniqueName(mountKey);
auto status = mVold->mountIncFs(backing, mountTarget, 0, metricsKey, &controlParcel);
if (!status.isOk()) { if (!status.isOk()) {
LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8(); LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8();
return kInvalidStorageId; return kInvalidStorageId;
@@ -653,8 +659,8 @@ StorageId IncrementalService::createStorage(std::string_view mountPoint,
const auto mountId = mountIt->first; const auto mountId = mountIt->first;
l.unlock(); l.unlock();
auto ifs = auto ifs = std::make_shared<IncFsMount>(std::move(mountRoot), std::move(metricsKey), mountId,
std::make_shared<IncFsMount>(std::move(mountRoot), mountId, std::move(control), *this); std::move(control), *this);
// Now it's the |ifs|'s responsibility to clean up after itself, and the only cleanup we need // Now it's the |ifs|'s responsibility to clean up after itself, and the only cleanup we need
// is the removal of the |ifs|. // is the removal of the |ifs|.
(void)firstCleanupOnFailure.release(); (void)firstCleanupOnFailure.release();
@@ -1483,8 +1489,11 @@ std::unordered_set<std::string_view> IncrementalService::adoptMountedInstances()
dataLoaderParams.arguments = loader.arguments(); dataLoaderParams.arguments = loader.arguments();
} }
auto ifs = std::make_shared<IncFsMount>(std::string(expectedRoot), mountId, // Not way to obtain a real sysfs key at this point - metrics will stop working after "soft"
std::move(control), *this); // reboot.
std::string metricsKey{};
auto ifs = std::make_shared<IncFsMount>(std::string(expectedRoot), std::move(metricsKey),
mountId, std::move(control), *this);
(void)cleanupFiles.release(); // ifs will take care of that now (void)cleanupFiles.release(); // ifs will take care of that now
// Check if marker file present. // Check if marker file present.
@@ -1641,7 +1650,8 @@ bool IncrementalService::mountExistingImage(std::string_view root) {
std::string mountKey(path::basename(path::dirname(mountTarget))); std::string mountKey(path::basename(path::dirname(mountTarget)));
IncrementalFileSystemControlParcel controlParcel; IncrementalFileSystemControlParcel controlParcel;
auto status = mVold->mountIncFs(backing, mountTarget, 0, mountKey, &controlParcel); auto metricsKey = makeUniqueName(mountKey);
auto status = mVold->mountIncFs(backing, mountTarget, 0, metricsKey, &controlParcel);
if (!status.isOk()) { if (!status.isOk()) {
LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8(); LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8();
return false; return false;
@@ -1654,7 +1664,8 @@ bool IncrementalService::mountExistingImage(std::string_view root) {
controlParcel.blocksWritten ? controlParcel.blocksWritten->release().release() : -1; controlParcel.blocksWritten ? controlParcel.blocksWritten->release().release() : -1;
IncFsMount::Control control = mIncFs->createControl(cmd, pendingReads, logs, blocksWritten); IncFsMount::Control control = mIncFs->createControl(cmd, pendingReads, logs, blocksWritten);
auto ifs = std::make_shared<IncFsMount>(std::string(root), -1, std::move(control), *this); auto ifs = std::make_shared<IncFsMount>(std::string(root), std::move(metricsKey), -1,
std::move(control), *this);
auto mount = parseFromIncfs<metadata::Mount>(mIncFs.get(), ifs->control, auto mount = parseFromIncfs<metadata::Mount>(mIncFs.get(), ifs->control,
path::join(mountTarget, constants().infoMdName)); path::join(mountTarget, constants().infoMdName));
@@ -2455,7 +2466,7 @@ void IncrementalService::getMetrics(StorageId storageId, android::os::Persistabl
const auto& kMetricsReadLogsEnabled = const auto& kMetricsReadLogsEnabled =
os::incremental::BnIncrementalService::METRICS_READ_LOGS_ENABLED(); os::incremental::BnIncrementalService::METRICS_READ_LOGS_ENABLED();
result->putBoolean(String16(kMetricsReadLogsEnabled.c_str()), ifs->readLogsEnabled() != 0); result->putBoolean(String16(kMetricsReadLogsEnabled.c_str()), ifs->readLogsEnabled() != 0);
const auto incfsMetrics = mIncFs->getMetrics(path::basename(ifs->root)); const auto incfsMetrics = mIncFs->getMetrics(ifs->metricsKey);
if (incfsMetrics) { if (incfsMetrics) {
const auto& kMetricsTotalDelayedReads = const auto& kMetricsTotalDelayedReads =
os::incremental::BnIncrementalService::METRICS_TOTAL_DELAYED_READS(); os::incremental::BnIncrementalService::METRICS_TOTAL_DELAYED_READS();

View File

@@ -340,6 +340,7 @@ private:
mutable std::mutex lock; mutable std::mutex lock;
const std::string root; const std::string root;
const std::string metricsKey;
Control control; Control control;
/*const*/ MountId mountId; /*const*/ MountId mountId;
int32_t flags = StorageFlags::ReadLogsAllowed; int32_t flags = StorageFlags::ReadLogsAllowed;
@@ -350,9 +351,10 @@ private:
std::atomic<int> nextStorageDirNo{0}; std::atomic<int> nextStorageDirNo{0};
const IncrementalService& incrementalService; const IncrementalService& incrementalService;
IncFsMount(std::string root, MountId mountId, Control control, IncFsMount(std::string root, std::string metricsKey, MountId mountId, Control control,
const IncrementalService& incrementalService) const IncrementalService& incrementalService)
: root(std::move(root)), : root(std::move(root)),
metricsKey(std::move(metricsKey)),
control(std::move(control)), control(std::move(control)),
mountId(mountId), mountId(mountId),
incrementalService(incrementalService) {} incrementalService(incrementalService) {}