Commit graph

3793 commits

Author SHA1 Message Date
Treehugger Robot
26cb9dbfef Merge "Support batching ops across Add*Blocks() call" into main 2023-12-20 22:49:38 +00:00
Treehugger Robot
c4b9840456 Merge "Fix EmitSequenceData bug" into main 2023-12-20 22:49:38 +00:00
Kelvin Zhang
a008c9c1a4 Support batching ops across Add*Blocks() call
Performance of V3 COW writer is now on-par with V2 in both incremental
OTA and full OTA.

Test: th
Bug: 313962438
Change-Id: If56e0fe42367f947c513fc4c93119c3825763cb9
2023-12-19 16:32:02 -08:00
Treehugger Robot
e0b444802b Merge "Add op count check before attempting to write operations" into main 2023-12-19 20:18:41 +00:00
Akilesh Kailash
3a7774d650 Merge "libsnapshot: Detach the daemon explicitly before stopping the service" into main 2023-12-19 17:50:06 +00:00
Akilesh Kailash
1752c5f249 libsnapshot: Detach the daemon explicitly before stopping the service
If the daemon is alive, detach it before explicitly terminating service.

Bug: 316876960
Test: treehugger presubmit tests
Change-Id: I94d9d1a0dab09a6b016f422c7497098abc86add8
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-12-18 17:22:06 -08:00
Chun-Wei Wang
222ffc5919 Disable DSU in recovery mode
DSU (modifying mounting paths) will cause OTA update
to fail in recovery mode

Bug: 315887685
Test: 1. enter DSU mode
      2. adb reboot recovery
      3. select "Apply update from ADB"
      4. adb sideload some-ota-update.zip
Change-Id: I6aec86893b7f8aa9e34f158269ebe2fd9dd98b33
2023-12-18 07:03:07 +08:00
Kelvin Zhang
c85038b866 Fix EmitSequenceData bug
If sequence data is written and the number of ops reaches the maximum,
op data will corrupt the block data because location of block data is
stale after writing sequence data. Fix by resetting location of block
data after EmitSequenceData()

Test: th
Bug: 313962438
Change-Id: Ib53b81772ba341cdf5c240baaee7c10725a365c3
2023-12-15 20:12:20 -08:00
Kelvin Zhang
73ac5f184e Add op count check before attempting to write operations
Test: th
Bug: 313962438
Change-Id: I0e288a42984d737d327236693a6b69c03a7ecc6e
2023-12-14 16:42:45 -08:00
David Anderson
adb91b0e59 remount: Detect when flashall has happened in the bootloader.
This adds a new metadata header flag to the super partition. This flag
is set when "adb remount" is used, and is implicitly cleared when
flashing.

If there is a scratch partition present on /data, we require that the
flag be set in order to proceed using overlays. If not set, scratch is
not mapped in first-stage init, and scratch images are removed later
during startup.

Bug: 297923468
Test: adb remount -R, touch file in out/, sync, flashall
Change-Id: I9cc411a1632101b5fc043193b38db8ffb9c20e7f
2023-12-14 16:00:27 -08:00
Treehugger Robot
e2c6171f65 Merge changes If3a01ab8,Ib24d7c63 into main
* changes:
  Support batch writes for V3 cow format
  Optimize PrepareSnapshotPartitionsForUpdate runtime
2023-12-14 19:19:31 +00:00
Treehugger Robot
b0c6a5dfd7 Merge "Revert "snapuserd: opt out of Global ThinLTO to workaround segfault"" into main 2023-12-14 00:24:57 +00:00
Kelvin Zhang
557104c85a Support batch writes for V3 cow format
Test: th
Bug: 313962438
Change-Id: If3a01ab85a1a649b7476bee2d56b732f04d0509a
2023-12-13 14:22:12 -08:00
Akilesh Kailash
4ffbc33b14 libsnapshot: skip connecting to daemon for legacy VAB
There is no need to connect to daemon for legacy VAB.

Bug: 311900089
Test: treehugger - presubmit

Change-Id: I2256cee611431ab2a286730c61092d2c546caf1e
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-12-12 14:12:49 -08:00
Kelvin Zhang
cb3cfc1655 Optimize PrepareSnapshotPartitionsForUpdate runtime
During PrepareSnapshotPartitionsForUpdate, we attempt to connect to
snapuserd with a 5s timeout, only to tell snapuserd to shutdown
immediately. If snapuserd isn't running, we will wait-out the whole 5
seconds. Change the logic to return early if socket_connect() calls
return ENOENT, indicating that snapuserd socket isn't used by any
process. This reduces allocateSpaceForPayload() time from 6s to 1s.

Test: th
Bug: 315215541
Change-Id: Ib24d7c63733a896c082ac92aaa88ad52d050a2a5
2023-12-12 13:36:34 -08:00
Yi Kong
edd04f1b38 Revert "snapuserd: opt out of Global ThinLTO to workaround segfault"
This reverts commit 9d0c06d3e2.

The failure is fixed by https://r.android.com/2725997. Workaround no
longer needed.

Test: manual
Bug: 208565717
Bug: 295944813
Change-Id: I83638938bf52a4b2b1e72743f892c579622ba9e6
2023-12-12 16:35:07 +09:00
Treehugger Robot
314818029c Merge "Support batch writes for non-compressed ops" into main 2023-12-12 01:43:24 +00:00
Xin Li
c5db6f6ca0 Merge UQ1A.231205.015
Bug: 308969284
Merged-In: I856c812d22363cc1d1e8aa88706d4d3b89044f52
Change-Id: I678b5d4e8418a905a7ca167a41888dcba5af2367
2023-12-07 15:48:04 -08:00
Kelvin Zhang
84e5e6f751 Support batch writes for non-compressed ops
This also improves atomicity of ops. If a single Add*Blocks() call
with 100 blocks failed in the middle, partially written blocks would be
discarded, and op count on disk stays unchanged. Previously wew ould
update the op count on disk with partially written blocks, causing
labels to be inaccurate.

Test: th
Bug: 313962438
Change-Id: If175a705f6ec46c1b25c52d0d9f02f01a540ce55
2023-12-06 16:41:25 -08:00
Treehugger Robot
442990fc5c Merge "Fix cow v3 size estimation errors" into main 2023-12-06 06:32:13 +00:00
Kelvin Zhang
d45c50911f Fix cow v3 size estimation errors
Current cow size estimation is computed by taking the offset of next
data write. However, during COW size estimation we repeatdly increment
op_count_max. Since data section is placed right after op section,
incrementing  op_count_max has the effect of moving the beginning of
data section. next_data_pos_ is never updated in this process, causing
the final estiamte to be off.

Test: th
Bug: 313962438
Change-Id: I250dff54c470c9c20d6db33d91bac898358dee31
2023-12-05 21:27:38 -08:00
Jaegeuk Kim
995dd0385e Use target path when handling dm-bow
Refactor getting sysfs directory.

Bug: 312817490
Change-Id: Icc12002d3f5a2e24f86ce88e5e602cf7a71b0f84
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2023-12-05 17:16:17 -08:00
Kelvin Zhang
ad51f09b05 Merge "Fix multiple calls to set_[source/type]" into main 2023-12-05 20:15:41 +00:00
Kelvin Zhang
12e0531224 Fix multiple calls to set_[source/type]
Since currently implementation just does an bitwise or with the
storage unit, multiple calls to set_source would result in overlapping
bits. Fix by first clear the existing storage.

Test: th
Bug: 313962438
Change-Id: Iecfe8dd244c0f65ecd3cacb0404fdc39ef836d97
2023-12-05 10:28:12 -08:00
Lucas Henneman
eadaf5faff Merge "TEST_MAPPING: fix syntax of TODO tag" into main 2023-12-05 14:29:55 +00:00
Akilesh Kailash
160e4c3cee Merge changes from topic "ota-tune-1" into main
* changes:
  Allow direct reads on source device
  libsnapshot: Tune readahead during OTA for source and COW block device
2023-12-04 23:53:41 +00:00
Treehugger Robot
f7fffb62d4 Merge "Allow Cow version v3 to be used" into main 2023-12-04 23:02:53 +00:00
Akilesh Kailash
52f1c19a17 Allow direct reads on source device
Allow O_DIRECT reads on source block device.
This will further cut down the Active and Inactive file pages
during partition verification.

On Pixel 6 after incremental OTA - Post OTA reboot:

		Without patch      With patch     Delta
--------------------------------------------------------
Inactive(File):  4992MB             3887MB         ~22%
Active(File):    1465MB             1014MB         ~30%

Boot time however increases from 25 to 30 seconds.

This is not yet enabled. This will be behind a sysprop flag
or for low memory devices and will be enabled later.

Additionally, set the priority of worker threads to normal.
Merge threads priority is reduced. This will help low memory
devices as tested on Pixel watch.

Bug: 311233916
Test: OTA on Pixel 6
Change-Id: Icacdef08d68e28d3062611477703e7cf393a9f10
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-12-04 14:07:42 -08:00
Akilesh Kailash
a8f6ce3344 libsnapshot: Tune readahead during OTA for source and COW block device
Scanning of partitions post OTA leads to memory pressure. Tune
the read-ahead of source and COW block device. This is currently
set to 32KB.

This reduces Inactive(file) and Active(file) usage during entire
duration of boot post OTA.

On Pixel 6: For incremental OTA ~400M. During boot:

                            Without-patch         With-patch    Delta
			    --------------------------------------------
1: Peak Inactive(file):     4469MB                3118MB        ~30%

2: Peak Active(file):       985MB                 712MB         ~27%

No regression observed on boot time.

Additionally, cut down the number of threads to verify the partitions.

Bug: 311233916
Test: Incremental OTA on Pixel 6
Change-Id: I0b842776c36fa089c39c170fa7bf0f246e16636d
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-12-04 14:07:26 -08:00
Treehugger Robot
240f7084be Merge "Shove CowOperation type into source_info" into main 2023-12-04 18:50:46 +00:00
Kelvin Zhang
7d526560df Allow Cow version v3 to be used
This does not change the default cow version. Currently v2 is still the
default. This CL only enables OEMs to set virtual_ab_cow_version to 3
for testing purposes.

Test: th
Bug: 313962438
Change-Id: I7a328fa32283560a48604ffe02edd2551ac49a83
2023-12-04 09:29:20 -08:00
Kelvin Zhang
2bf1da5d2c Shove CowOperation 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. Since CowOperationV3 is not used on disk(just yet) , we
can make format changes.

This CL is mechanical:
    1. Remove tye .type field from CowOperation struct
    2. Add a type() getter method to CowOperation struct
    3. Replace all existing usage of `type` member with the new getter

No functional changes, just refactorings.

Test: th
Bug: 304602386
Bug: 313962438

Change-Id: I85d89c71fc6afede12ea299a4a3e3b2184ea2d8b
2023-12-04 09:14:20 -08:00
Treehugger Robot
3ecba6b927 Merge "fs_mgr_overlayfs: MapScratchPartitionIfNeeded always tries to create scratch" into main 2023-12-04 02:53:30 +00:00
Elliott Hughes
1784219094 Merge "fs_mgr: IWYU include <algorithm> for std::sort" into main 2023-12-01 22:22:34 +00:00
Lucas Henneman
3bcfa9c039 TEST_MAPPING: fix syntax of TODO tag
Bug: 279009697
Test: git diff
Change-Id: I7133bc0abe6634193b0fb006f5cd77ed2dc05844
Signed-off-by: Lucas Henneman <henneman@google.com>
2023-12-01 20:17:42 +00:00
Daniel Rosenberg
4ae617f676 Merge changes I1ecdffcb,Ib0d1ea81 into main
* changes:
  fs_mgr: Support 16k F2FS
  fs_mgr_overlayfs: Support 16k F2FS
2023-12-01 00:52:16 +00:00
Akilesh Kailash
37e7498fc0 Merge "snapshotctl: fsync after writing every 1MB buffer" into main 2023-11-29 20:37:55 +00:00
Akilesh Kailash
b78d0e2856 snapshotctl: fsync after writing every 1MB buffer
Sync writes after every 1MB instead of flushing at the end.

Bug: 299011882
Test: Boot device off snapshots
Change-Id: If91168ec92c2b2995bdf296ea1c7d4c261b12411
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-11-29 11:26:46 -08:00
Kelvin Zhang
1ccb347e87 Turn CowOperationType into an enum
There's a bug previsouly where we compare return value of
GetCowOpSourceInfoData() with CowOperationType. Such bugs are possible
because cow operation enums are weakly typed integers. Turn
CowOperationType into strongly typed enum to prevent such bugs.

Test: th
Bug: 304602386
Change-Id: If6941a4740c374ed066cf0aee9e52f4df05a9b38
2023-11-29 10:46:10 -08:00
Christopher Fore
fad8b7a130 fs_mgr: IWYU include <algorithm> for std::sort
GCC 14 starts to no longer include <algorithm> by default, resulting in
it needing to be explicitly declared.

Test: Recompiled with GCC 14 and succeeded

Change-Id: Ifc5dd58b7476ba728ae604cd2924cb68fbcab701
Signed-off-by: Christopher Fore <csfore@posteo.net>
2023-11-27 14:55:19 -05:00
Yi-Yo Chiang
3a22c9e16e fs_mgr_overlayfs: MapScratchPartitionIfNeeded always tries to create scratch
Simplify the logic of MapScratchPartitionIfNeeded to just map the
scratch partition unconditionally. If there is a "scratch" logical
partition available, we just assume it must be needed later to
facilitate overlayfs.

Going through the fstab & fs_mgr_overlayfs_candidate_list to determine
if overlayfs is needed or not might be inaccurate as the fstab passed into
MapScratchPartitionIfNeeded is incomplete (it includes only the
"first_stage_mount" entries). So the scratch device might not get created
even though there are some "late mount" partitions that need the scratch
device to facilitate overlayfs.

Bug: 306124139
Test: adb-remount-test
Change-Id: I8590750e822219dec3d7d3c8648e9c9a5a32f68c
2023-11-27 11:17:12 +00:00
Yi-Yo Chiang
16239ad862 fs_mgr_overlayfs: De-dup common methods
Keep only one copy of GetBootScratchDevice().

Bug: 306124139
Test: build
Change-Id: I11603566ab454eb028b50873d66f4ab967b204f9
2023-11-27 11:16:41 +00:00
Yi-Yo Chiang
28113cf3f6 second-stage-init: Don't move submounts when mounting overlayfs
Right now there is a bug in second-stage-init that screws up the
overlayfs overrides. This happens because:
1. second-stage-init mount_all might be executed in the "bootstrap"
   mount namespace.
2. In order to move (MS_MOVE) submounts in fs_mgr_overlayfs_mount_all(),
   we change the mount propagation type of overridden filesystems to
   MS_PRIVATE.
3. This means that the "default" mount namespace would not receive the
   mount events of the overlayfs overrides.
4. After /data is mounted, init would switch to the "default" namespace.
   This means any new processes spawned after this period would not be
   able to see the overlayfs overrides.

We fix this by changing the mount order of second-stage-init mount_all
to mount the overlayfs override of a partition immediately after the
partition is mounted. This way we don't need to move any submounts as
there can't be any, thus we don't need to set any mountpoint to
MS_PRIVATE so the mount event of the overlayfs would be propagated to
the "default" mount namespace, too.

Bug: 309407859
Bug: 306124139
Test: adb-remount-test
Test: verify that overlayfs tookover successfully from second-stage-init
Change-Id: If2ff4852516292ccbc7abdeebe0e9a7c1c7ba606
2023-11-27 17:16:40 +08:00
yanxu
3f9f595067 Add exfat fs in fs_mgr
Need to support exfat fs type point mount in recovery mode

Bug:312674538
Test: SIU (Apply update from SD card) in recovery mode

Change-Id: I2735e5068c47b183a25d2305bca89f08de1e32c7
2023-11-24 10:26:59 +00:00
Daniel Zheng
1056a1172a Merge "libsnapshot: add sequence data" into main 2023-11-21 22:31:57 +00:00
Daniel Zheng
43aeb22858 libsnapshot: add sequence data
v3 writer to write sequence data. Sequence data will be written after
the scratch space and before the resume space. Since this is just a list
of integers, writing and reading should be trivial

Test: cow_api_test
Change-Id: If3b6b1cfa155aeb65bf693263fc373154ba8e81d
2023-11-21 09:50:16 -08:00
Daniel Zheng
d2d7a1ff0e Merge changes I56a0d747,I1585601a,I9e44330e into main
* changes:
  libsnapshot: move header op count setup
  libsnapshot: sync header metadata
  libsnapshot: update variable name
2023-11-21 17:49:29 +00:00
Yi-Yo Chiang
7f322bcaf0 Merge changes I12bc2ccd,I8174257c into main
* changes:
  fs_mgr_overlayfs: Fix "/" mount propagation type after remount
  fs_mgr_overlayfs: Fix submount propagation type after remount
2023-11-21 09:36:47 +00:00
Daniel Zheng
209fda3562 libsnapshot: move header op count setup
Op count should be set before we sync the header. This way subsequence
writers can initialize with the correct op buffer size

Test: cow_api_test
Change-Id: I56a0d747b3f2a1d9d582d8f9d643b81cbdd9b8d7
2023-11-20 11:53:21 -08:00
Daniel Zheng
763776435d libsnapshot: sync header metadata
After we write emit a label, we need to update the number of resume
points + sequence data and op_count. Realistically we could just call
Finalize, but maybe synching these specific fields could prevent
unexpected outcomes.

Test: cow_api_test
Change-Id: I1585601a134221689ce8d5675a2a3e32f1e8a0e6
2023-11-20 11:53:20 -08:00