liblp: MetadataBuilder::GetBlockDevicePartitionName
Allow to retrieve name of a block device partition at a certain index. If the index is out of range, return empty string. This is needed for an hypothetical edge case when an intersection of two LinearExtent needs to be computed, and the two metadata have a different list of block device names. In reality, Virtual A/B devices are always launched with dynamic partitions, so it will always return "super" for index 0 and "" otherwise. Test: liblp_test_static Bug: 135752105 Change-Id: I9ea59edefdc41d0e69e3644aa2452676372938b4
This commit is contained in:
parent
4644f84208
commit
8367b9f73a
|
@ -140,7 +140,7 @@ std::unique_ptr<MetadataBuilder> MetadataBuilder::New(const LpMetadata& metadata
|
|||
}
|
||||
if (opener) {
|
||||
for (size_t i = 0; i < builder->block_devices_.size(); i++) {
|
||||
std::string partition_name = GetBlockDevicePartitionName(builder->block_devices_[i]);
|
||||
std::string partition_name = builder->GetBlockDevicePartitionName(i);
|
||||
BlockDeviceInfo device_info;
|
||||
if (opener->GetInfo(partition_name, &device_info)) {
|
||||
builder->UpdateBlockDeviceInfo(i, device_info);
|
||||
|
@ -164,7 +164,7 @@ std::unique_ptr<MetadataBuilder> MetadataBuilder::NewForUpdate(const IPartitionO
|
|||
// name and system properties.
|
||||
// See comments for UpdateMetadataForOtherSuper.
|
||||
auto super_device = GetMetadataSuperBlockDevice(*metadata.get());
|
||||
if (GetBlockDevicePartitionName(*super_device) != "super" &&
|
||||
if (android::fs_mgr::GetBlockDevicePartitionName(*super_device) != "super" &&
|
||||
IsRetrofitDynamicPartitionsDevice()) {
|
||||
if (!UpdateMetadataForOtherSuper(metadata.get(), source_slot_number, target_slot_number)) {
|
||||
return nullptr;
|
||||
|
@ -192,7 +192,8 @@ bool MetadataBuilder::UpdateMetadataForOtherSuper(LpMetadata* metadata, uint32_t
|
|||
// Translate block devices.
|
||||
auto source_block_devices = std::move(metadata->block_devices);
|
||||
for (const auto& source_block_device : source_block_devices) {
|
||||
std::string partition_name = GetBlockDevicePartitionName(source_block_device);
|
||||
std::string partition_name =
|
||||
android::fs_mgr::GetBlockDevicePartitionName(source_block_device);
|
||||
std::string slot_suffix = GetPartitionSlotSuffix(partition_name);
|
||||
if (slot_suffix.empty() || slot_suffix != source_slot_suffix) {
|
||||
// This should never happen. It means that the source metadata
|
||||
|
@ -375,7 +376,7 @@ bool MetadataBuilder::Init(const std::vector<BlockDeviceInfo>& block_devices,
|
|||
block_devices_.emplace_back(out);
|
||||
}
|
||||
}
|
||||
if (GetBlockDevicePartitionName(block_devices_[0]) != super_partition) {
|
||||
if (GetBlockDevicePartitionName(0) != super_partition) {
|
||||
LERROR << "No super partition was specified.";
|
||||
return false;
|
||||
}
|
||||
|
@ -849,7 +850,7 @@ uint64_t MetadataBuilder::AlignSector(const LpMetadataBlockDevice& block_device,
|
|||
bool MetadataBuilder::FindBlockDeviceByName(const std::string& partition_name,
|
||||
uint32_t* index) const {
|
||||
for (size_t i = 0; i < block_devices_.size(); i++) {
|
||||
if (GetBlockDevicePartitionName(block_devices_[i]) == partition_name) {
|
||||
if (GetBlockDevicePartitionName(i) == partition_name) {
|
||||
*index = i;
|
||||
return true;
|
||||
}
|
||||
|
@ -974,7 +975,8 @@ static bool CompareBlockDevices(const LpMetadataBlockDevice& first,
|
|||
// Note: we don't compare alignment, since it's a performance thing and
|
||||
// won't affect whether old extents continue to work.
|
||||
return first.first_logical_sector == second.first_logical_sector && first.size == second.size &&
|
||||
GetBlockDevicePartitionName(first) == GetBlockDevicePartitionName(second);
|
||||
android::fs_mgr::GetBlockDevicePartitionName(first) ==
|
||||
android::fs_mgr::GetBlockDevicePartitionName(second);
|
||||
}
|
||||
|
||||
bool MetadataBuilder::ImportPartitions(const LpMetadata& metadata,
|
||||
|
@ -1057,7 +1059,7 @@ bool MetadataBuilder::IsRetrofitDynamicPartitionsDevice() {
|
|||
}
|
||||
|
||||
bool MetadataBuilder::IsRetrofitMetadata() const {
|
||||
return GetBlockDevicePartitionName(block_devices_[0]) != LP_METADATA_DEFAULT_PARTITION_NAME;
|
||||
return GetBlockDevicePartitionName(0) != LP_METADATA_DEFAULT_PARTITION_NAME;
|
||||
}
|
||||
|
||||
bool MetadataBuilder::AddLinearExtent(Partition* partition, const std::string& block_device,
|
||||
|
@ -1121,5 +1123,11 @@ bool MetadataBuilder::ChangeGroupSize(const std::string& group_name, uint64_t ma
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string MetadataBuilder::GetBlockDevicePartitionName(uint64_t index) const {
|
||||
return index < block_devices_.size()
|
||||
? android::fs_mgr::GetBlockDevicePartitionName(block_devices_[index])
|
||||
: "";
|
||||
}
|
||||
|
||||
} // namespace fs_mgr
|
||||
} // namespace android
|
||||
|
|
|
@ -287,6 +287,9 @@ class MetadataBuilder {
|
|||
// Return true if a block device is found, else false.
|
||||
bool HasBlockDevice(const std::string& partition_name) const;
|
||||
|
||||
// Return the name of the block device at |index|.
|
||||
std::string GetBlockDevicePartitionName(uint64_t index) const;
|
||||
|
||||
private:
|
||||
MetadataBuilder();
|
||||
MetadataBuilder(const MetadataBuilder&) = delete;
|
||||
|
|
Loading…
Reference in New Issue