Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd122aa9 authored by Yifan Hong's avatar Yifan Hong Committed by Gerrit Code Review
Browse files

Merge changes from topic "libsnapshot_api_update_engine"

* changes:
  libsnapshot: tests for public APIs.
  fastbootd: skip COW group
  libsnapshot: no overlayfs during virtual a/b ota.
  libsnapshot: Also use empty space in super for COW
  libsnapshot: APIs for all partitions
  fs_mgr: CreateDmTable takes CreateLogicalPartitionParams
parents fd010252 26d7d953
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -143,6 +143,10 @@ cc_binary {
    static_libs: [
        "libhealthhalutils",
    ],

    header_libs: [
        "libsnapshot_headers",
    ]
}

cc_defaults {
+6 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include <fstab/fstab.h>
#include <liblp/builder.h>
#include <liblp/liblp.h>
#include <libsnapshot/snapshot.h>
#include <sparse/sparse.h>

#include "fastboot_device.h"
@@ -171,6 +172,11 @@ bool UpdateSuper(FastbootDevice* device, const std::string& super_name, bool wip
        if (!slot_suffix.empty() && GetPartitionSlotSuffix(partition_name) == slot_suffix) {
            continue;
        }
        std::string group_name = GetPartitionGroupName(old_metadata->groups[partition.group_index]);
        // Skip partitions in the COW group
        if (group_name == android::snapshot::kCowGroupName) {
            continue;
        }
        partitions_to_keep.emplace(partition_name);
    }

+26 −20
Original line number Diff line number Diff line
@@ -79,22 +79,22 @@ static bool GetPhysicalPartitionDevicePath(const IPartitionOpener& opener,
    return true;
}

bool CreateDmTable(const IPartitionOpener& opener, const LpMetadata& metadata,
                   const LpMetadataPartition& partition, const std::string& super_device,
                   DmTable* table) {
bool CreateDmTableInternal(const CreateLogicalPartitionParams& params, DmTable* table) {
    const auto& super_device = params.block_device;

    uint64_t sector = 0;
    for (size_t i = 0; i < partition.num_extents; i++) {
        const auto& extent = metadata.extents[partition.first_extent_index + i];
    for (size_t i = 0; i < params.partition->num_extents; i++) {
        const auto& extent = params.metadata->extents[params.partition->first_extent_index + i];
        std::unique_ptr<DmTarget> target;
        switch (extent.target_type) {
            case LP_TARGET_TYPE_ZERO:
                target = std::make_unique<DmTargetZero>(sector, extent.num_sectors);
                break;
            case LP_TARGET_TYPE_LINEAR: {
                const auto& block_device = metadata.block_devices[extent.target_source];
                const auto& block_device = params.metadata->block_devices[extent.target_source];
                std::string dev_string;
                if (!GetPhysicalPartitionDevicePath(opener, metadata, block_device, super_device,
                                                    &dev_string)) {
                if (!GetPhysicalPartitionDevicePath(*params.partition_opener, *params.metadata,
                                                    block_device, super_device, &dev_string)) {
                    LOG(ERROR) << "Unable to complete device-mapper table, unknown block device";
                    return false;
                }
@@ -111,12 +111,21 @@ bool CreateDmTable(const IPartitionOpener& opener, const LpMetadata& metadata,
        }
        sector += extent.num_sectors;
    }
    if (partition.attributes & LP_PARTITION_ATTR_READONLY) {
    if (params.partition->attributes & LP_PARTITION_ATTR_READONLY) {
        table->set_readonly(true);
    }
    if (params.force_writable) {
        table->set_readonly(false);
    }
    return true;
}

bool CreateDmTable(CreateLogicalPartitionParams params, DmTable* table) {
    CreateLogicalPartitionParams::OwnedData owned_data;
    if (!params.InitDefaults(&owned_data)) return false;
    return CreateDmTableInternal(params, table);
}

bool CreateLogicalPartitions(const std::string& block_device) {
    uint32_t slot = SlotNumberForSlotSuffix(fs_mgr_get_slot_suffix());
    auto metadata = ReadMetadata(block_device.c_str(), slot);
@@ -160,6 +169,11 @@ bool CreateLogicalPartitionParams::InitDefaults(CreateLogicalPartitionParams::Ow
        return false;
    }

    if (!partition_opener) {
        owned->partition_opener = std::make_unique<PartitionOpener>();
        partition_opener = owned->partition_opener.get();
    }

    // Read metadata if needed.
    if (!metadata) {
        if (!metadata_slot) {
@@ -167,7 +181,8 @@ bool CreateLogicalPartitionParams::InitDefaults(CreateLogicalPartitionParams::Ow
            return false;
        }
        auto slot = *metadata_slot;
        if (owned->metadata = ReadMetadata(block_device, slot); !owned->metadata) {
        if (owned->metadata = ReadMetadata(*partition_opener, block_device, slot);
            !owned->metadata) {
            LOG(ERROR) << "Could not read partition table for: " << block_device;
            return false;
        }
@@ -195,11 +210,6 @@ bool CreateLogicalPartitionParams::InitDefaults(CreateLogicalPartitionParams::Ow
        return false;
    }

    if (!partition_opener) {
        owned->partition_opener = std::make_unique<PartitionOpener>();
        partition_opener = owned->partition_opener.get();
    }

    if (device_name.empty()) {
        device_name = partition_name;
    }
@@ -212,13 +222,9 @@ bool CreateLogicalPartition(CreateLogicalPartitionParams params, std::string* pa
    if (!params.InitDefaults(&owned_data)) return false;

    DmTable table;
    if (!CreateDmTable(*params.partition_opener, *params.metadata, *params.partition,
                       params.block_device, &table)) {
    if (!CreateDmTableInternal(params, &table)) {
        return false;
    }
    if (params.force_writable) {
        table.set_readonly(false);
    }

    DeviceMapper& dm = DeviceMapper::Instance();
    if (!dm.CreateDevice(params.device_name, table, path, params.timeout_ms)) {
+1 −3
Original line number Diff line number Diff line
@@ -105,9 +105,7 @@ bool CreateLogicalPartition(CreateLogicalPartitionParams params, std::string* pa
bool DestroyLogicalPartition(const std::string& name);

// Helper for populating a DmTable for a logical partition.
bool CreateDmTable(const IPartitionOpener& opener, const LpMetadata& metadata,
                   const LpMetadataPartition& partition, const std::string& super_device,
                   android::dm::DmTable* table);
bool CreateDmTable(CreateLogicalPartitionParams params, android::dm::DmTable* table);

}  // namespace fs_mgr
}  // namespace android
+26 −0
Original line number Diff line number Diff line
@@ -40,6 +40,10 @@ bool LinearExtent::AddTo(LpMetadata* out) const {
    return true;
}

Interval LinearExtent::AsInterval() const {
    return Interval(device_index(), physical_sector(), end_sector());
}

bool ZeroExtent::AddTo(LpMetadata* out) const {
    out->extents.emplace_back(LpMetadataExtent{num_sectors_, LP_TARGET_TYPE_ZERO, 0, 0});
    return true;
@@ -96,6 +100,20 @@ void Partition::ShrinkTo(uint64_t aligned_size) {
    DCHECK(size_ == aligned_size);
}

Partition Partition::GetBeginningExtents(uint64_t aligned_size) const {
    Partition p(name_, group_name_, attributes_);
    for (const auto& extent : extents_) {
        auto le = extent->AsLinearExtent();
        if (le) {
            p.AddExtent(std::make_unique<LinearExtent>(*le));
        } else {
            p.AddExtent(std::make_unique<ZeroExtent>(extent->num_sectors()));
        }
    }
    p.ShrinkTo(aligned_size);
    return p;
}

uint64_t Partition::BytesOnDisk() const {
    uint64_t sectors = 0;
    for (const auto& extent : extents_) {
@@ -602,6 +620,10 @@ std::vector<Interval> Interval::Intersect(const std::vector<Interval>& a,
    return ret;
}

std::unique_ptr<Extent> Interval::AsExtent() const {
    return std::make_unique<LinearExtent>(length(), device_index, start);
}

bool MetadataBuilder::GrowPartition(Partition* partition, uint64_t aligned_size,
                                    const std::vector<Interval>& free_region_hint) {
    uint64_t space_needed = aligned_size - partition->size();
@@ -1168,5 +1190,9 @@ std::string MetadataBuilder::GetBlockDevicePartitionName(uint64_t index) const {
                   : "";
}

uint64_t MetadataBuilder::logical_block_size() const {
    return geometry_.logical_block_size;
}

}  // namespace fs_mgr
}  // namespace android
Loading