Commit graph

3203 commits

Author SHA1 Message Date
Yi-yo Chiang
acac60d5a4 Merge "libfstab: Add const overload of GetEntryForMountPoint()" 2022-12-13 06:24:46 +00:00
David Anderson
95cfb31bd2 Merge "Support sysfs changes in the Linux 5.15 kernel." 2022-12-12 18:38:04 +00:00
Yi-Yo Chiang
d45750aa2c libfstab: Add const overload of GetEntryForMountPoint()
Const version of GetEntryForMountPoint() accepts a pointer to const
Fstab and returns a pointer to const FstabEntry.

In order to refrain from adding more boilderplate, simplify the
implementation of GetEntryForMountPoint() to "return first entry of
GetEntriesForMountPoint()". The added overhead should be negligible as
fstab is usually small (around dozens of entries max), so iterating the
whole list is not computationally expensive.

Also templatize the implementation of GetEntriesByPred() to reduce the
amount of boilerplate.

Bug: 243501054
Test: Presubmit
Change-Id: I046d61d68385825656bb7bc7177c0d1d3e8b36e1
2022-12-13 01:53:37 +08:00
Akilesh Kailash
c4a5576fdf libsnapshot: Test batch writes and threaded compression
Test all compression algorithms.

Bug: 254188450
Test: cow_api_test
Change-Id: I977e631402eb2dfaa76205f5d8cb955e6d3bddbb
Signed-off-by: Akilesh Kailash <akailash@google.com>
2022-12-11 16:15:50 +00:00
Akilesh Kailash
4bc81b409b libsnapshot: Batch write COW operations in a cluster
COW operations are written in cluster. All the COW ops
and the COW data in this cluster are contiguous. Hence,
batch these writes and write them in one syscall.

Writes are done when the cluster is full or when
label ops are written.

OTA install time (without post-install) on Pixel 6 Pro:

          Without-this-patch        With-this-patch

Full OTA: 17 Minutes               13 Minutes

Following are the OTA install times with both the optimization.
viz - batch writes + 2 threads for compression.

OTA install (without post-install) on Pixel 6 Pro.

All numbers are in minutes.

Full ota - 2.2G

Compression   Without-this-patch     With-this-patch
=========================================================
gz            23                      13
lz4           13                       7
none          13                       7

Incremental OTA - 376M

Compression   Without-this-patch     With-this-patch
=========================================================

gz            22                     16
lz4           14                     11
none          15                     11

Bug: 254188450
Test: Full / Incremental OTA on Pixel
Change-Id: Ie3aba1ff28a6569d25a766377efab6cbe78d9277
Signed-off-by: Akilesh Kailash <akailash@google.com>
2022-12-11 16:15:42 +00:00
Akilesh Kailash
b1a05003a8 libsnapshot: Use two threads to run compression
Compression is a hot function in the install path. Use
two threads for compression.

By default, number of thread is set to 1. If the property,
"ro.virtual_ab.compression.threads" is true, the number
of threads is increased to 2.

OTA install time (without post-install) on Pixel 6 Pro with 2 threads:

	  Without-this-patch       With-this-patch

Full OTA: 23 Minutes               17 Minutes

Bug: 254188450
Test: Full/Incremental OTA on Pixel
Change-Id: I4a11dca3a5ebfe11dcc7f0d882332d491f2d7933
Signed-off-by: Akilesh Kailash <akailash@google.com>
2022-12-11 16:15:32 +00:00
David Anderson
d6bf86b8cf Support sysfs changes in the Linux 5.15 kernel.
DM_DEV_CREATE no longer creates sysfs nodes. Note this in ueventd and
add some helper APIs to libdm, so devices can be created with a
placeholder table.

This also fixes a bug in dmctl where the detailed info on suspended
devices was wrong.

Bug: 259328366
Test: dmctl with "uevents" tool
Change-Id: I822f8010e48d32841aa0ee508822f76d03a3dd85
2022-12-08 16:22:47 -08:00
Chih-Hung Hsieh
784e63c9a2 Fix potential memory leaks
Bug: 259995529
Test: make tidy-system_subset
Change-Id: I604a308caf498a854b916dc86a8e274148c21ab0
2022-12-05 23:52:58 +00:00
Treehugger Robot
9e6005ada4 Merge "Fix nullptr access when cow reader open fails" 2022-12-02 19:25:32 +00:00
Kelvin Zhang
bc1a5b1393 Fix nullptr access when cow reader open fails
Bug: 260805150
Test: th
Change-Id: Id945cc4fa0fce141e3d52b8259241e22ba590ebd
2022-12-02 09:50:44 -08:00
Treehugger Robot
2e2fed7668 Merge "fs_mgr/OWNERS: Update bug component" 2022-12-01 17:16:57 +00:00
Yi-Yo Chiang
701d643b2a fs_mgr/OWNERS: Update bug component
Fix: 261015598
Test: none
Change-Id: I52c6cca5d46f7c6f02e6b4ca608e14ef3a3de81b
2022-12-01 23:47:02 +08:00
David Anderson
85b7bbf41f Merge "libsnapshot: Disable 32-bit VTS tests on 64-bit systems." 2022-12-01 00:25:24 +00:00
Yi-Yo Chiang
b4a86eeb2f remount: Treat disable verity error as fatal only if verity is enabled
If device doesn't enable AVB altogether, then it might not have a vbmeta
partition at all. In this case, we shall ignore disable-verity errors.
We still disable verity unconditionally to keep the logic simple, but we
ignore any disable-verity error if AVB is not enabled in the first
place.

Bug: 241688845
Test: adb-remount-test on emulator
Test: Test remount on yukawa
Change-Id: Ifc763b3f0ca6989550c139a8c3a2308c9c2a7c3e
2022-11-22 15:26:37 +08:00
Yi-Yo Chiang
f48d5778a1 remount: Check device mapper to see if verity is already disabled
No matter verity is enabled or disabled, androidboot.veritymode is
always "enforcing" on emulator kernel cmdline.

This is a violation of the AVB contract:
https://cs.android.com/android/platform/superproject/+/master:external/avb/README.md#handling-dm-verity-errors

Before emulator can fix this, workaround this by checking the device
mapper table to see if verity is disabled or not.
If no "<partition>-verity" device is present, than assume verity is
already disabled.

Also log mountpoints that are successfully remounted.

Bug: 241688845
Bug: 259207493
Test: adb-remount-test
Test: Run adb remount on emulator
Change-Id: Id5767b05cbfb48adf2a8c372dfdad4d15b98e091
2022-11-18 00:35:45 +08:00
Yi-Yo Chiang
dea063b65d remount: Remove all remaining opaque exit code (RemountStatus enum)
All errors are already logged and the exit code is not used anywhere by
anyone.
Functions should instead return (true/false) or
(EXIT_SUCCESS/EXIT_FAILURE) to indicate error state, and log error
reasons to logd and stderr.

Bug: 241688845
Test: adb-remount-test
Change-Id: Iba86a814a75f81ed0f6e43659d1aca72813824bc
2022-11-09 17:12:39 +08:00
Yi-Yo Chiang
6be7351bab remount: Don't assert ro.boot.vbmeta.* properties
ro.boot.vbmeta.* properties could be missing if device is verification
disabled.
Instead use ro.boot.verifiedbootstate to check device locked state.
No need to check ro.boot.vbmeta.digest, as we no longer support VB1.0.
In other words, all device running this piece of code must be using AVB.

Bug: 241688845
Test: adb-remount-test
Change-Id: If5d702ab3a6f12deef8204dba698e6c62eaae46f
2022-11-09 17:12:39 +08:00
Yi-Yo Chiang
99ec013d58 remount: Simplify disable verity logic
We are calling avb_user_verity_set() _for each_ fstab entry in order to
disable verity. This is an artifact from back when each partition has
its own verity flag (VB1.0). Since AVB, the verity flag in vbmeta
affects all dm-verity device, thus we only need to call
avb_user_verity_set() once.

Bug: 241688845
Test: adb-remount-test
Change-Id: Ie5b788e2d34f83152228db62f84d26a32e2b26e0
2022-11-09 17:12:39 +08:00
Yi-Yo Chiang
ab4dd01395 set-verity-state: Use ro.boot.veritymode to determine current verity state
On a device that don't use overlayfs remount (e.g. no EXT4 dup blocks;
this can be simulated by patching fs_mgr_wants_overlayfs()), if we run
disable-verity or enable-verity twice in a row then the second
invocation would not suggest a reboot:

  adb disable-verity
  > Successfully disabled verity
  > Reboot to take effect...
  adb disable-verity
  > Verity is already disabled
              ^^^ this is WRONG! verity is disabled only after a reboot

It behaves like this because it suggest a reboot only if the vbmeta
verity (HASHTREE) flag is changed.
Read the ro.boot.veritymode property instead to determine the current
dm-verity state and suggest a reboot by comparing current and future
verity state:
* If AVB verification is disabled, then ro.boot.veritymode is undefined
  (probably empty), don't suggest reboot in this case as it's pointless.
* Otherwise suggest a reboot if the new state (which would take effect
  after reboot) differs from the current verity state.
* Reference:
  https://android.googlesource.com/platform/external/avb/+/master/README.md#handling-dm_verity-errors

Bug: 241688845
Test: adb-remount-test
Test: Run "adb enable-verity" & "adb disable-verity" multiple times
Change-Id: If1df5bee6e5dcbda580b3dff6c32da93d08bbb46
2022-11-09 17:12:38 +08:00
Yi-yo Chiang
2a501a11dc Merge changes from topic "merge_set-verity-state_with_remount"
* changes:
  remount: Merge 'remount' and 'set-verity-state'
  remount: Use MyLogger class and sundry improvements
2022-11-09 09:02:38 +00:00
Kelvin Zhang
0b8c4ebfa8 Store lz4 blocks as uncompressed if compression makes data larger
This will change cow size estimation. But since we haven't put lz4 on
SAC website yet, we can still change it.

Bug: 228478555
Test: th
Change-Id: Ifba7107954622ea04cbd25115700dfba50cec9c6
2022-11-08 10:17:26 -08:00
Kelvin Zhang
149fa74db5 Fsync on directory after rename() call
rename() isn't necessarily atomic, call fsync() on the directory to
ensure that changes in fs structure hit the disk.

Test: th
Bug: 254211456
Change-Id: I2de842f03766a1108e0f54581738fb964989658a
2022-11-08 10:02:12 -08:00
Kelvin Zhang
b190f3cbe1 Merge "Check for COW space before writing to COW" 2022-11-07 23:52:22 +00:00
Yi-yo Chiang
955460e5a9 Merge "remount: prefer 'cache' backing storage for non-A/B devices" 2022-11-07 11:43:15 +00:00
Yi-Yo Chiang
e8d85b5814 remount: Merge 'remount' and 'set-verity-state'
Dedup fs_mgr_remount.cpp and set-verity-state.cpp by merging them
together and make '/system/bin/set-verity-state' a symlink to
'/system/bin/remount'.

Bug: 241688845
Test: adb-remount-test
Change-Id: I42a2344b9bdac112bf8767d428a99cb020267546
2022-11-03 22:58:43 +08:00
Yi-Yo Chiang
a799a58842 remount: Use MyLogger class and sundry improvements
* Use the MyLogger class from set-verity-state.cpp and eliminate the
  |verbose| global variable.
* Support specifying reboot() reason. Log error if reboot() failed to
  reboot.
* Move precondition checks after all |argv| are processed. This way (-h)
  help message can be shown w/o root user.
* Log "remount [succeeded|failed]" message before auto-reboot. Give
  users a clear succeeded/failed message.

Bug: 241688845
Test: adb-remount-test
Change-Id: If45de2eba0d532632de43b19c797ffdeea90cd6d
2022-11-03 16:17:12 +08:00
Kelvin Zhang
c903ef4517 Check for COW space before writing to COW
This gives a more detailed message when we run out of cow space.
Also, previously, it's possible that the COW op metadata writes
successfully but op data fails due to out of space, resulting in a
broken COW image. After this change, we won't write anything unless
there's sufficient space for both OP metadata and block data. This makes
COW operations more atomic and easier to debug/inspect.

Test: th
Change-Id: I6c1347e91b4ec2d7e434b47a0f47b290e288e600
2022-11-02 11:01:26 -07:00
Oleg Lyovin
c227809041 remount: prefer 'cache' backing storage for non-A/B devices
In non-A/B configurations system partitions often
have layout with not so much free space left, while having
large /cache partition.

In a dynamic partitions configuration 'remount' for backing
storage will user either:

-- /data partition, which is not guaranteed to have
enough space due to applications disk usage;

-- or super partition, which is tied to system images size
having a little room for growing.

At the same time, /cache is guaranteed to be free,
so non-A/B platform can force it to be used as
backing storage.

Test: remount
Signed-off-by: Oleg Lyovin <ovlevin@sberdevices.ru>
Change-Id: I68e621b884b2fe21a5c464b3deaf679186232eb3
2022-11-02 15:11:21 +03:00
David Anderson
32fa3e96f4 libsnapshot: Disable 32-bit VTS tests on 64-bit systems.
These tests don't work because 32-bit dependencies are not normally
packaged on a 64-bit system.

Bug: N/A
Test: builds
Change-Id: I68859a9e9c029a528ee12c02569a3693261c7251
2022-10-31 21:32:40 -07:00
Yi-Yo Chiang
c82ad4fd90 fs_mgr_overlayfs: Remove backing image if failed to allocate scratch
In CreateScratchOnData(), if backing image is allocated but failed to
map, then remove the backing image. Otherwise the unusable (unmappable)
image would waste a lot of space.

Bug: 255593675
Test: On device that don't support mapping gsid scratch,
  run `adb remount` and then check that gsid scratch is removed and
  scratch is allocated on super.
Test: TH run g3-app-compat-main
Change-Id: I0c01c2fd93a30ac0e46f4350c900403337530406
2022-10-31 16:15:35 +08:00
Nathan Huckleberry
997d738dda Expose system property for dm-verity check_at_most_once
Allow us to check if check_at_most_once is set for any partitions.

This property should be false for any device with a reasonable amount of
RAM and a modern CPU. Enabling check_at_most_once violates AVB best
practices, it should only be allowed on performance limited devices.

Bug: 253033920
Test: Ensure that avbHashtreeNotUsingSha1 CTS test still passes
    and that partition.system.verified.check_at_most_once is set.
Change-Id: I8174adf81111cc0df547ea01f81b0dfaca32631f
Signed-off-by: Nathan Huckleberry <nhuck@google.com>
2022-10-25 21:12:52 +00:00
Treehugger Robot
c052460659 Merge "fs_mgr_overlayfs: Fallback to allocate scratch on super if /data failed" 2022-10-25 20:56:59 +00:00
Yi-Yo Chiang
1c76ccb554 fs_mgr_overlayfs: Fallback to allocate scratch on super if /data failed
b/255593675 showed that gsid can fail to allocate scratch on /data on
some device configurations. Before we can locate the root cause,
gracefully fallback to previous "scratch-on-super" logic in case of
error.

Bug: 255593675
Test: Presubmit
Test: manual test
Change-Id: I229ab51f11fa354a6f231c4d083dd6329d6a9579
2022-10-26 03:17:37 +08:00
Akilesh Kailash
b71b32dc83 libsnapshot: Do not store CowOperations in memory during writes
The only use case of storing COW operations in memory
was to calculate SHA256 sum during Finalize() - However,
we haven't been doing that since day one of libsnapshot_cow library.

This consumes peak memory ~14mb on an incremental OTA which has 700k+
COW operations writes on one partition.

We can rather use this memory for Async operations where we will have
to cache the buffers.

Bug: 254188450
Test: Incremental OTA
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I2165ed95ff26a9dfb465dc3120df61bb02eee27b
2022-10-25 06:59:36 +00:00
David Anderson
9d8637289b Merge "snapshotctl: Add a test-blank-ota command for development." 2022-10-24 20:36:58 +00:00
David Anderson
d62bdd2974 snapshotctl: Add a test-blank-ota command for development.
The test-blank-ota command is for iterating on changes to snapuserd or
the Virtual A/B boot flow, which is normally very time consuming to
test.

It works by creating a partial OTA outside of update_engine, purely
through SnapshotManager calls. Every partition except system is
preserved. system is "updated" entirely with copy operations. The entire
"OTA" takes about ten seconds.

Tested on cuttlefish, but a physical device should work as long as
physical partitions are flashed to both slots beforehand.

The big limitation is that since update_engine does not run, there is no
merge action on reboot. This can be done manually with "snapshotctl
merge" however.

This type of tool could be easily used in the future for quickly testing
specific bugs or performance ideas in snapuserd.

Bug: N/A
Test: launch_cvd
      adb wait-for-device root
      adb shell snapshotctl test-blank-ota
      adb reboot
      adb wait-for-device root
      adb shell snapshotctl dump
Change-Id: I5911440cbe14ee909905a0b0fc17da95ba4c5d68
2022-10-24 11:49:25 -07:00
Treehugger Robot
882c1681df Merge "libfstab_fuzzer: fuzz TransformFstabForDsu() and skip mount logic" 2022-10-24 09:48:05 +00:00
Yi-Yo Chiang
40a8223d34 libfstab_fuzzer: fuzz TransformFstabForDsu() and skip mount logic
These functions contain complex logic and parse user input. It shall be
valuable to fuzz these functions to prevent regression.

Bug: 254832225
Test: Build and run the fuzzer
Change-Id: I21099c3fc1c226f95a0f8f996bb751030e0c59bc
2022-10-21 19:51:25 +08:00
Yi-yo Chiang
cc7ddc04f9 Merge "Revert "fs_mgr_overlayfs: Revert to use /data only if VAB"" 2022-10-20 08:11:57 +00:00
Akilesh Kailash
b23bf16efc libsnapshot: Changes to AddCopy() API
If the copy blocks are contiguous, add a third
argument which takes the number of blocks
which are contiguous. With this, update engine
can call the API in one shot for all the
contiguous COPY operations.

This is required for batching the I/O
for async writes.

This should still continue to support the existing
API where we pass one COPY block at a time.

Bug: 254188450
Test: Incremental OTA from A->B with new API changes in A
      Incremental OTA from A->B with plain VAB
      cow_api_test
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I7edc52a152e02de28a44ef1dc2c88b76a28c4109
2022-10-19 17:55:52 +00:00
Akilesh Kailash
63190d2e3a Merge changes I7681e9a4,If84ff730
* changes:
  libsnapshot: Refactor compress function
  libsnapshot: Refactor code
2022-10-18 21:58:16 +00:00
Akilesh Kailash
1119e8e018 libsnapshot: Refactor compress function
Move compress() function to a dedicated file.
This is in preparation for variable block size
compression and async writes.

No change in functional logic.

Bug: 254188450
Test: Full OTA Pixel
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I7681e9a4d884eac1ccbf8adeb1fc6bd1a9fedfa6
2022-10-18 16:49:02 +00:00
Akilesh Kailash
e8f6a126fb libsnapshot: Refactor code
Move all files related to libsnapshot_cow library to
a seperate directory. Libsnapshot directory is getting
crowded and we will be adding more files to this library
with async writes.

No changes to any logic.

Bug: 254188450
Test: Full OTA on Pixel
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: If84ff730d477c85a8ef57864d2185f2f897cf8e0
2022-10-18 16:48:33 +00:00
Yi-yo Chiang
956a45485a Revert "fs_mgr_overlayfs: Revert to use /data only if VAB"
This reverts commit c540ab9bf8.

Reason for revert: root cause is fixed

Bug: 253207748
Test: TH run g3-app-compat-main
Change-Id: I44c2535508a5718a823cdd61ad1938bba739c2a0
2022-10-18 09:43:20 +00:00
Yi-yo Chiang
eb88e7b677 Use ro.product.vendor.device to determine if running on Cuttlefish
Similar reasoning as aosp/2255456. ro.product.device could be overridden
by GSI if system.img was replaced with GSI.
Use ro.product.vendor.device, which comes from the vendor.img, to
determine the "device" type.

Bug: 243116800
Test: adb-remount-test on cuttlefish
Change-Id: Ib4a956047ef46d8e4837b27334f8d58162d4fa2a
2022-10-18 07:34:45 +00:00
Yi-yo Chiang
e7f5532e0a Merge "fs_mgr_overlayfs: Add scratch size override system property" 2022-10-18 06:56:24 +00:00
Jaegeuk Kim
c114177985 overlayfs: use overlayfs for f2fs readonly mode
F2FS doesn't allow remount,rw for RO partition, so that it caused adb remount.
Fix it.

Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Change-Id: Ia4410d08e8be344d79292c16a335a7e5be7a48bb
2022-10-17 11:38:45 -07:00
Kelvin Zhang
7e05c04432 Fix bug in WriteStringToFileAtomic
According to https://www.slideshare.net/nan1nan1/eat-my-data ,
rename() without an fsync() is not safe, and cannot guarantee data
integrity in case of powerloss of OS failure.

Test: partner verification, th
Bug: 238702018
Change-Id: I5809770062ed7bfa47df81de418a2d8f7cbc6620
2022-10-13 09:43:44 -07:00
Yi-Yo Chiang
15f94436b3 fs_mgr_overlayfs: Add scratch size override system property
Bug: 253207748
Test: Treehugger
Change-Id: I7140044d127e7db99d86decbe818be3680d26995
2022-10-12 20:23:19 +08:00
yi.sun
301adfcc07 Replacing fs_mgr_dir_is_writable(work) with fs_mgr_rw_access(work) to
check whether the scratch partition is writable.

Delate fs_mgr_dir_is_writable, as it may cause remount to fail.

Steps to reproduce:
1.adb root
2.adb remount
3.adb reboot
4.adb remount
5.push files to the system partition until the scratch partition is full
6.check that the Available of /mnt/scratch is zero through the df command
7.reboot
8.adb root
9.adb remount
Now, overlayfs failed to mount.

But I want to continue to view the files that were previously pushed to
the system partition.
Mounting of overlayfs should not be blocked when there is not enough space.
It seems reasonable to use fs_mgr_rw_access(work) to check whether
the partition is writable.
We should allow mount even if scratch is full, because this allows
the user to delete previously pushed files to free up space.

Bug: 240635368
Change-Id: I726ccd064cfabfab29789e7c690ea8cb574a6344
Signed-off-by: yi.sun <yi.sun@unisoc.com>
2022-10-12 03:06:22 +00:00