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

Commit 398203d1 authored by Akilesh Kailash's avatar Akilesh Kailash
Browse files

libsnapshot: Move snapshot metadata to super partition.



snapshot metadata files are stored in /metadata. This means, we cannot
wipe after installing any update.

This patch does the following:

1: Create a scratch space in super partition. The scratch space for ota
   metadata is just about 1MB.

2: Create ext4 filesystem on top of scratch block device.

3: Mount the scratch on /mnt/scratch_super

4: When snapshot-manager instance is created, point the /mnt/scratch/ota
to metadata_dir_ so that all the snapshot files are stored in the new
path.

All the logic of OTA remains the same. This flow is enabled only on userdebug builds for now and the only consumer would be snapshotctl

$snapshotctl apply-update /data/nbd/ -w

During init, we would have to mount the scratch partition to detect
if there is any pending updates.

With this, we would now be able to wipe the device along with the update flow. This will help incremental flashing wherein we would end up saving ~35-40 seconds on Pixel devices.

With this flow, the end-to-end update for incremental builds takes
~20-30 seconds.

Bug: 330744468
Test: Pixel 6 incremental flashing with wipe, Full OTA, vts_libsnapshot
Change-Id: Iac6ce2cf37b70ea221cd18175c8962988d03d95b
Signed-off-by: default avatarAkilesh Kailash <akailash@google.com>
parent adcba868
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -186,6 +186,7 @@ cc_binary {
        "libprotobuf-cpp-lite",
        "libsparse",
        "libutils",
        "libselinux",
    ],

    static_libs: [
+0 −2
Original line number Diff line number Diff line
@@ -80,10 +80,8 @@

using namespace std::chrono_literals;

bool fs_mgr_set_blk_ro(const std::string& blockdev, bool readonly = true);
bool fs_mgr_is_device_unlocked();

bool fs_mgr_is_ext4(const std::string& blk_device);
bool fs_mgr_is_f2fs(const std::string& blk_device);

bool fs_mgr_filesystem_available(const std::string& filesystem);
+6 −0
Original line number Diff line number Diff line
@@ -104,6 +104,12 @@ int fs_mgr_setup_verity(android::fs_mgr::FstabEntry* fstab, bool wait_for_verity
// returned. Otherwise, it will use the current slot.
std::string fs_mgr_get_super_partition_name(int slot = -1);

// Set readonly for the block device
bool fs_mgr_set_blk_ro(const std::string& blockdev, bool readonly = true);

// Check if the block device has ext4 filesystem
bool fs_mgr_is_ext4(const std::string& blk_device);

enum FsMgrUmountStatus : int {
    SUCCESS = 0,
    ERROR_UNKNOWN = 1 << 0,
+3 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ cc_defaults {
        "libfstab",
        "libsnapuserd_client",
        "libz",
        "libselinux",
    ],
    header_libs: [
        "libfiemap_headers",
@@ -91,6 +92,7 @@ filegroup {
        "partition_cow_creator.cpp",
        "return.cpp",
        "utility.cpp",
        "scratch_super.cpp",
    ],
}

@@ -351,6 +353,7 @@ cc_binary {
    ],
    srcs: [
        "snapshotctl.cpp",
        "scratch_super.cpp",
    ],
    static_libs: [
        "libbrotli",
+18 −1
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
// limitations under the License.

#include "device_info.h"
#include "scratch_super.h"

#include <android-base/logging.h>
#include <fs_mgr.h>
@@ -37,8 +38,24 @@ constexpr bool kIsRecovery = true;
constexpr bool kIsRecovery = false;
#endif

DeviceInfo::DeviceInfo() {
    std::string scratch_device = android::snapshot::GetScratchOtaMetadataPartition();
    if (!scratch_device.empty()) {
        std::string scratch_metadata =
                android::snapshot::MapScratchOtaMetadataPartition(scratch_device);
        if (!scratch_metadata.empty()) {
            SetMetadataDir(scratch_metadata);
            SetTempMetadata();
        }
    }
}

std::string DeviceInfo::GetMetadataDir() const {
    return "/metadata/ota"s;
    return metadata_dir_;
}

void DeviceInfo::SetMetadataDir(const std::string& value) {
    metadata_dir_ = value;
}

std::string DeviceInfo::GetSlotSuffix() const {
Loading