Commit graph

926 commits

Author SHA1 Message Date
Daniel Zheng
ed1a7d5faf Add v3 Cow Header
Adding Version 3 of CowHeader. This will inherit from original
CowHeader and add a compression field. We are no longer supporting
different compressions per operation so having this one field is enough.

Test: cow_api_test
Change-Id: If88dceda139807cc5e647b706ddeb2b3e83c024f
2023-10-10 15:06:26 -07:00
Daniel Zheng
73b3428e1c Rename BLOCK_SZ to block_size
BLOCK_SZ name to block_size as we should reserve all caps for compile
time constants

Test: th
Change-Id: I542632662e81b272ffec50d6b50c290d701b08e3
2023-10-10 12:55:28 -07:00
Daniel Zheng
76b1e83fad Move ReadCowHeader to CowReader
Moving this function to cow reader first we have to read the version of
cow from the header before deciding which parser to use. This is a more
logical place for this code to be in

Test: th
Change-Id: Ie5ba53439b4fc3c4c409426b818a2d53c0cbc3e5
2023-10-10 12:55:27 -07:00
Daniel Zheng
e90a39aee2 Shove type into source_info
We can shove type into source info to save 8 bits in per cow operation.
We only need 4 bits inside of source_info to enumerate all the types of
Cow Operation:

static constexpr uint8_t kCowCopyOp = 1;
static constexpr uint8_t kCowReplaceOp = 2;
static constexpr uint8_t kCowZeroOp = 3;
static constexpr uint8_t kCowLabelOp = 4;
static constexpr uint8_t kCowClusterOp = 5;
static constexpr uint8_t kCowXorOp = 6;
static constexpr uint8_t kCowSequenceOp = 7;
static constexpr uint8_t kCowFooterOp = -1;

Test: critical ota paths on pixel
Change-Id: I22049db0b39a55bd8f863339f3751d3146d5c1e9
2023-10-10 12:55:27 -07:00
Daniel Zheng
c197df70d8 Update API usage for source
replacing any instance of op->source_info with GetCowSourceinfoData as
that's what we're really looking for. This function will return the 48
bits associated with the source and not the extra bits that will store
type + other information. We should never be making a reference to
op->source_info directly as that has no real meaning, we should be
masking for the data that we really need

Test: cow_api_test
Change-Id: I259c790efdd13c61a4599e9edfc75cf0ba000c61
2023-10-09 20:15:34 -07:00
Daniel Zheng
f9f833066d Move Sync to base class
This function will be called in header write for both v3 and v2 writer.
Seems okay to move to base class as theres no unique functionality to
the v2 writer.

Test: cow_api_test

Change-Id: I70c1b08ce67127c9dcbd0f54b574d2cd5ad1d0b5
2023-10-09 20:15:34 -07:00
Daniel Zheng
f7f3b62f24 Merge "Removing compression bit from v3 op" into main 2023-10-10 03:09:58 +00:00
Daniel Zheng
3062a64f06 Merge "Add v3 writer" into main 2023-10-10 02:25:38 +00:00
Daniel Zheng
ce57c58e6b Removing compression bit from v3 op
We don't need the compression bit in v3 op since all operations will
have the same compression per COW Device and it will be stored within the COW header.
We can check to see if an operation contains compressioned data by
checking data_length and see if it's less than BLOCK_SZ

Test: 4 critical OTA paths
Change-Id: I3f86756d83bf54bf6efd15d9cb7ac064eefdd949
2023-10-09 13:31:20 -07:00
Daniel Zheng
04e4c2a6c2 Add v3 writer
Adding v3 writer that works off of Cow Operation v3. Adding test file
that will test this new writer. Adding in stub implementations to v3 writer. None of these functions
have to work yet, we just need the implementations here to compile.

Test: m libsnapshot
Change-Id: If86437d5ceb2c33520d4ca26dea5193984f86546
2023-10-09 13:31:19 -07:00
Daniel Zheng
7248d1b0d8 Merge "Refactor off V2 Cow Ops" into main am: adad3dbefe
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2736101

Change-Id: I0344daaa43ed555c0bcdd377629c70a167f2afa4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-10-05 19:39:28 +00:00
Daniel Zheng
adad3dbefe Merge "Refactor off V2 Cow Ops" into main 2023-10-05 19:12:56 +00:00
Daniel Zheng
4cda9ec9bb Merge "Adding test for reader compatibility" into main am: 4b3b6e2ff5
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2762279

Change-Id: I3720f7f966c54408c1c4dbe72222dac73ef6dbae
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-10-05 17:45:07 +00:00
Daniel Zheng
4b3b6e2ff5 Merge "Adding test for reader compatibility" into main 2023-10-05 17:04:17 +00:00
Akilesh Kailash
0d38654b34 Merge "snapuserd: I/O request on overlapping blocks during snapshot-merge." into main am: 743c4cdb1c
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2769106

Change-Id: Ie5a42ec523a948382b25200d92cfb1105d972138
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-10-05 14:18:31 +00:00
Akilesh Kailash
cffa413de4 snapuserd: I/O request on overlapping blocks during snapshot-merge.
This fixes the case when all the following conditions are true:

1: Incremental OTA
2: When there are sequence of overlapping COPY operations within one merge-window
   (510 blocks)
3: Device is rebooted when snapshot-merge is in-progress of this
   merge-window. When device reboots, the state of merge-window (of 510 blocks) was
   merge-in-progress (aka - only partial set of blocks were merged in
   this window thereby the state of the base device is in-complete for
   this window)
4: During the next boot, if there any I/O request from the filesystem
   which maps to the merge-window in (3):
   	a: The data has to be retrieved from the scratch space of the
	COW until the snapshot-merge for that window is completed.

	b: Once the snapshot-merge is complete for that window, data
	has to be retrieved from base device.

The bug was in step 4(a) wherein I/O request was getting routed to base
device.

This patch addresses the above flow by fixing step 4(a).

A new vts test has been added to explicitly track this issue.

Additionally, there is no need to re-scan the partition if partition is in merge resume path. This should cut down the overhead of the scan.

Bug: 275296365
Test: 1: 100 iterations of ./vts_snapuserd_test --gtest_filter=SnapuserdTest.Snapshot_COPY_Overlap_Merge_Resume_IO_Validate_TEST
2: Incremental OTA on Pixel 6 Pro with multiple iterations of device
   reboot when merge is in progress

Change-Id: Ib53be7f07ff192a84ec7f7049b2c6be01dad1041
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-10-05 05:32:31 +00:00
Daniel Zheng
c9770b29b9 Refactor off V2 Cow Ops
Refactor writer, reader + parser to work off v2 version of
CowOperations.

Test: m libsnapshot. ota on cuttlefish
Change-Id: Iec59be91e5f54782272b37702d645942df38c771
2023-10-04 18:09:35 -07:00
Treehugger Robot
72ba5c12be Merge changes Ib7509508,I7e256e8d into main am: 310e7ae496
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2767639

Change-Id: I7a3c878979b3d47963549b78df7d95509ec467a8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-10-05 00:42:27 +00:00
Daniel Zheng
a16436d5d7 Adding test for reader compatibility
Reader + Parser v3 should be able to read V2 cow format written to disk.
This test reads in a small cow file written by basic_v2_cow_writer and
parses it to ensure this compatibility checks out.

Test: cow_api_test
Change-Id: I46ebf4e3f12cdb3e4716ca5b624aab5836086733
2023-10-04 17:37:26 -07:00
David Anderson
c942daf179 snapuserd: Add an extractor tool.
This is similar to inspect_cow --extract-to, except it uses snapuserd.
It is a diagnostic host tool and uses the tooling added for host
testing.

Usage: snapuserd_extractor -cow COW_FILE -base BASE_FILE -out OUT_FILE
                           -num_sectors NUM_SECTORS

Unlike inspect_cow, this supports xor/copy operations.

The extractor code is separated into a utility file so we can use it for
additional tests later on.

Bug: N/A
Test: manual test
Change-Id: Ib7509508cba45e6c3a0db8c75454e33c2a503e03
2023-10-03 19:54:28 -07:00
David Anderson
8a28163d33 inspect_cow: Add an --extract-to argument.
This adds an --extract-to argument to inspect_cow to verify that full
OTA snapshots contain correct data. It does not yet work for ordered
ops.

Test: inspect_cow
Bug: N/A
Change-Id: I9014da3e83fd4fb5ea54ac1d36e527b3e3e6c9d5

Change-Id: I7e256e8ddec626980cdcf8680bbeac3c2e9d8de1
2023-10-03 16:02:26 -07:00
Treehugger Robot
95879d3e8b Merge "Log the CowOperation when decompression failed" into main am: e877885533
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2768488

Change-Id: Ic4b424caa8183140e53dc28c89990f5883f1e163
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-10-02 21:18:27 +00:00
Treehugger Robot
e877885533 Merge "Log the CowOperation when decompression failed" into main 2023-10-02 20:45:38 +00:00
Kelvin Zhang
ab4c9621d4 Log the CowOperation when decompression failed
Test: th
Bug: 302992208
Change-Id: I617062d75a79ae73dfdff13c2e9d2a62c5dfcfc0
2023-10-02 11:08:18 -07:00
Daniel Zheng
1b53b83925 Merge "Add copyright to libsnapshot/tools" into main am: 26bed5fc09
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2763850

Change-Id: I868a1db6b5920a827aa60c375992a3f21895290a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-27 19:45:07 +00:00
Daniel Zheng
e42df43569 Merge "Add binary to write basic COW" into main am: 0fc7feeafb
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2763849

Change-Id: I57488d1893a80bf44e5c3b12ec6f014691329c77
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-27 19:44:16 +00:00
Daniel Zheng
301acae35b Add copyright to libsnapshot/tools
Adding copyright to cow_benchmark + basic_v2_cow_writer

Test: th
Change-Id: Ic6c32b68bbeaa3c0c365f146ef4342356e13706a
2023-09-26 16:51:53 -07:00
Daniel Zheng
d7c5511095 Add binary to write basic COW
Adding small binary to write a simple COW for version 2. We will then
use updated reader to make sure we can read this version 2 cow. Think it
would be a good idea to keep the binary here to see how exactly we
generated the cow (useful for debugging and if we ever need to recreate
this cow)

Test: m basic_v2_cow_writer
Change-Id: I28435025b7a8280fc5c4574876cc9110b391cb0e
2023-09-26 16:51:48 -07:00
Treehugger Robot
8cd8ce3fc0 Merge "Create_cow: Hash of target blocks should not be stored." into main am: a2cd2202f0
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2759698

Change-Id: Ib652154e55c271260cbf0070af9c96f674c31709
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-24 01:59:18 +00:00
Akilesh Kailash
810274071d Create_cow: Hash of target blocks should not be stored.
Target block hash was in-correctly getting added to map thereby
overriding the source-hash.

Bug: 299011882
Test: Flash Pixel 6 Pro from A->B and from B->A
Change-Id: Ib3887c29cd6b8f2abd50e932273a5cfc2a096bd5
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-09-23 01:07:47 -07:00
Ryan Prichard
4570cf0ce2 Merge changes I7790dde8,I065907a5,Id2e82024 into main am: 532a608f58
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2758070

Change-Id: I654dd3283ac4d072649d17afa6e091da35263be1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-22 20:50:27 +00:00
Ryan Prichard
532a608f58 Merge changes I7790dde8,I065907a5,Id2e82024 into main
* changes:
  Add missing <assert.h> include
  Add missing <functional> and <vector> includes
  snapuserd_test: don't discard result of std::async
2023-09-22 19:42:45 +00:00
Ryan Prichard
93377e99e2 snapuserd_test: don't discard result of std::async
std::async returns a std::future whose destructor blocks until the
async function has completed, which defeats the purpose of using
std::async. The future needs to be kept alive to allow the function to
run concurrently.

Starting in C++20, std::async marked [[nodiscard]] to help catch this
misuse. Upgrading libc++ adds the [[nodiscard]] attribute to
std::async, so fixing this bug is necessary to keep the code compiling
after libc++ is updated.

Bug: 175635923
Test: treehugger
Test: m && m snapuserd_test
Change-Id: Id2e820248c2b6111aa843fb709e08a2c19677066
2023-09-21 17:52:18 -07:00
Daniel Zheng
822c758b84 Merge "Updating comments on cow layout" into main am: 1b52ac6efe
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2754949

Change-Id: I137135d6473e83c79dcdc9ed016ef8d61050cba0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-19 17:41:26 +00:00
Daniel Zheng
1b52ac6efe Merge "Updating comments on cow layout" into main 2023-09-19 16:32:28 +00:00
Treehugger Robot
a7d2ddb1cd Merge "Add static_assert to check sizeof off_t" into main am: 53a71f6b18
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2754946

Change-Id: I88a516d5cc76f06a142c75ea1b07dd4c21acedd9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-18 23:15:42 +00:00
Treehugger Robot
53a71f6b18 Merge "Add static_assert to check sizeof off_t" into main 2023-09-18 22:39:48 +00:00
Daniel Zheng
445d13f73f Merge "Add CowOperationV2" into main am: a10bfe1d13
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2736100

Change-Id: Ib2c7b4cdc556db7e594c2a1df8b3117ec986471b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-18 22:21:49 +00:00
Daniel Zheng
a10bfe1d13 Merge "Add CowOperationV2" into main 2023-09-18 21:30:29 +00:00
Akilesh Kailash
6ea36bd1e4 Add static_assert to check sizeof off_t
Add compile time flags which got dropped during refactoring.

Bug: 300178204
Test: Build on 32-bit userspace
Change-Id: I16be0973cb2cb2e174ff98c8b10fde27f997e4ab
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-09-18 14:09:27 -07:00
Daniel Zheng
cc44c37468 Updating comments on cow layout
Updating comments to match current format. Scratch space exists in
between header and operation

Test: th
Change-Id: I2f86e9dc4078f03370cdc38918136c894c6ca484
2023-09-18 14:02:17 -07:00
Daniel Zheng
d2ad53cf81 Add CowOperationV2
this is going to replace the current version of CowOperation and will
work with writer v2 and parser v2. This will be the on disk format of
the cow, while CowOperation will be updated to be the in memory format
of 15 bytes (implicitly will be the v3 version).

Test: m libsnapshot

Test: m libsnapshot
Change-Id: Ibd00ef014a9fc11cdf2bad97c52462db8eef9502
2023-09-18 12:47:59 -07:00
Akilesh Kailash
5fdf90777e Merge "Compile with -D_FILE_OFFSET_BITS to support 32-bit userspace" into main am: 81400915ef
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2753909

Change-Id: Ic0411e9cf2f10abdb2ce0c33f89a88b856b631ba
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-17 20:11:13 +00:00
Akilesh Kailash
0a59994c5a Compile with -D_FILE_OFFSET_BITS to support 32-bit userspace
This is to support when partition sizes are greater than 2GB (2^31)
on 32-bit userspace.

Bug: 300178204
Test: OTA on device with 32-bit userspace + product partition > 2GB
Change-Id: I7074682352d8388ed410c684cb7cb0fa346ba24c
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-09-17 09:34:43 -07:00
Daniel Zheng
d9c17e91bb Merge "Concatenate conditional" into main am: 5528777496
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2751931

Change-Id: I747433f20360ab65634db2642a8970c622d14d2f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-15 00:19:29 +00:00
Daniel Zheng
5528777496 Merge "Concatenate conditional" into main 2023-09-14 23:42:15 +00:00
Daniel Zheng
f5a280a03e Merge "Adding block sz to compressors" into main am: 7f13bc4f47
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2748856

Change-Id: I4ca4ee725b58a77aeb59144196ad98d0ac6ed0c5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-14 05:48:44 +00:00
Daniel Zheng
7f13bc4f47 Merge "Adding block sz to compressors" into main 2023-09-14 05:15:31 +00:00
Daniel Zheng
19a6aa6241 Concatenate conditional
Move two separate conditional checks to one in writer_v2

Test: m libsnapshot
Change-Id: Id70db313754b770e3fa091e9c127839b9f2a5138
2023-09-13 22:14:19 -07:00
Daniel Zheng
b309292859 Adding block sz to compressors
Adding block sz to compressor classes to prepare for variable block size
compression

Test: m libsnapshot
Change-Id: I84db20c80c0f95188f79ccc73b5c30678bd75e78
2023-09-13 22:14:19 -07:00