Commit graph

3246 commits

Author SHA1 Message Date
David Anderson
efcc9ae010 snapshotctl: Display merge progress and phases.
Bug: N/A
Test: snapshotctl dump during merge phase
Change-Id: Ife319450b28c8c58268a03127e9f58c47fc224d8
2023-03-13 10:53:54 -07:00
David Anderson
6aaae78047 Remove the libsnapshot fuzzer.
The only bugs in the corpus here were bugs in the fuzzer itself. Part
of the reason is its speed - it's limited by the dm layer so can't fuzz
optimally. That also makes it difficult to maintain, since it's
effectively a functional OTA fuzzer, and is very sensitive to the
implementation of libsnapshot.

After discussing this through with the team, we think the best course is
to sunset this and aim for improved unit and functional OTA testing.

Bug: 227656961
Test: builds
Change-Id: I2ecf838be336ee06459988ef282f0694cebfce51
2023-03-09 08:35:49 -08:00
Kelvin Zhang
b5a9607232 Initialize COW options using update manifest
Update manifest contains feature specifications such as whether to use
multi-threading or batched writes, initialize COW options using the
manifest allows these features to be enabled/disabled at update install
time.

Test: th
Change-Id: Iff66c43567d4890ae1c88624db49014584b1d96f
2023-02-23 13:21:20 -08:00
David Anderson
5169ec88c6 snapuserd: Use fixtures in snapuserd_test.
This refactors snapuserd_test to use SnapuserdTest as a fixture, to
avoid needing a separate harness instance.

Bug: 269361087
Test: snapuserd_test
Change-Id: Iffdc7b621dbe0aff72eff790e7af3f6bb33036ee
2023-02-14 16:59:31 -08:00
David Anderson
69863bd977 Merge "liblp: Fix a crash when adding an image to a partition with no extents." 2023-02-13 23:28:14 +00:00
Akilesh Kailash
d2063ad7dd libsnapshot: Wait for daemon to terminate after snapshot unamp
During verification, update-engine will invoke
SnapshotMap() and Unmap() for every partition verification.

Post Unmap(), update-engine immediately invokes Map()
for next partition. This is a narrow window wherein, daemon
from previous unmap() is still present and init hasn't
terminated it. Thus, when next MapSnapshot() is invoked,
Connect() fails as init may end up terminating the service.

Wait for the daemon to fully terminate and exit
when Detach() is invoked.

Bug: 258514587
Test: OTA on Pixel, Map/Unmap in a loop
Change-Id: I36b7ce183dfa4c89a873118876d195480e28d48c
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-02-10 14:31:52 -08:00
David Anderson
8fc623eb63 liblp: Fix a crash when adding an image to a partition with no extents.
Bug: N/A
Test: lpmake --partition=system:readonly:0 --image=system=system.img
Change-Id: I4de616cc1b9ca2838d38518ec24a382f4bc1b1be
2023-02-08 22:09:58 -08:00
David Anderson
40bb403c45 Merge changes I72cf6f52,I9620e5b4
* changes:
  libsnapshot: Fix crash in cow writer test due to missing ASSERT.
  libsnapshot: Improve low space tests.
2023-02-08 04:03:55 +00:00
Treehugger Robot
525c8bbc08 Merge "UDC: Dm-Bow failed to load when size is not Multiple of 4096" 2023-02-07 18:44:37 +00:00
David Anderson
bda181a86a libsnapshot: Fix crash in cow writer test due to missing ASSERT.
Bug: N/A
Test: vts_libsnapshot_test
Change-Id: I72cf6f52fc15061da669d14cf5d334b44ad83501
2023-02-07 05:24:27 +00:00
David Anderson
111bec1e90 libsnapshot: Improve low space tests.
These tests have historically been pretty flaky, and have gone through a
few rounds of improvement. This is yet another: remove the
parameterization, so we can test that at least one variant of the test
succeeds, rather than all of them.

Filesystems (especially F2FS) have a lot going on underneath the hood,
and there's no guarantee that precise free space can be allocated,
measured, or relied upon in the ways this test expects. And all that we
really need to test is that some kind of out-of-space error can be
triggered.

Bug: 266645706
Test: vts_libsnapshot_test
Change-Id: I9620e5b496d5020b21cc37074e87dd21fc419ed2
2023-02-07 05:24:26 +00:00
Greg Kaiser
451dfee3c7 Set output value in error case
We want to set the contents of "out_size_num_byte", and not
the pointer value, in the error case.

Bug: 266757931
Change-Id: I02edddcbcc4fc80dbb61efe8dc7c45bd3ce1c904
Test: TreeHugger
2023-02-02 00:05:21 +00:00
David Anderson
7cf627bac9 Merge changes Ib744d763,I74278bb5,I3d240d6e,I1b41d233
* changes:
  fastboot: Move some helpers into util.h/.cpp.
  fastboot: Allow using LOG().
  fastboot: Use RAII for sparse_file objects.
  liblp: Add a helper class for building sparse-compatible super image layouts.
2023-02-01 21:27:03 +00:00
Zhou Xuezan
45eee7fe52 OTA: make lp_metadata write more atomic
Powerloss of OS failure occurs when super is merging,
then the device can't bring up again for no lp_metadata sync,
so make lp_metadata sync in time.

Change-Id: I1ea31662b838e35022a566b614796f2d5e05df4b
Signed-off-by: Jia Jia <jia.jia@zte.com.cn>
2023-02-01 08:17:38 +00:00
David Anderson
e6cef616f1 liblp: Add a helper class for building sparse-compatible super image layouts.
This class helps export a list of regions comprising a super partition,
and what the contents of those regions should be. It is very similar to
ImageBuilder, except that it does not require actual partition image
files, nor does it actually write an image file to disk.

The goal is to support building an in-memory super image that uses as
little memory and backing storage as possible. For example, fastboot can
use this to upload a super image without having to read and write
gigabytes of unnecessary data.

Since the goal is to optimize fastboot, we've taken some shortcuts here.
Retrofit devices and other edge-casey behavior are safely rejected. We
also don't rely on libsparse behavior here, and attempt to make the
translation to sparse records as trivial as possible, by explicitly
declaring where fill/dontcare gaps are, and only exporting 4KB aligned
regions. Hopefully this will allow the code to be portable to
non-fastboot consumers.

Bug: 266982466
Test: liblp_test
Change-Id: I1b41d233bc4512c4b62e19603e8e77bc5867cfab
2023-01-31 18:46:35 -08:00
Treehugger Robot
06a150b9f5 Merge "Report partition sizes to avb" 2023-01-31 20:07:54 +00:00
Kelvin Zhang
dbc4a788f7 Report partition sizes to avb
This might allow avb to save some memory by only allocate as much memory
needed to hold the partition data, instead of allocating for maximum
possible partition size(64K).

Bug: 266757931

Change-Id: I82a4b1ba3544910072050e45a7cb91e0dcbc4d05
2023-01-31 10:20:25 -08:00
Yi-Yo Chiang
bc851b6dbf fs_mgr: Add one space between [libfs_mgr] tag and log msg
This is but a cosmetic change. Before:

> [libfs_mgr]__mount(...

After:

> [libfs_mgr] __mount(...

Also change liblp, libfs_avb and libvbmeta.

Bug: 241688845
Test: Presubmit
Change-Id: I7d408a94a7fe279d9b65d699e22159b167f34526
2023-01-31 09:41:43 +00:00
David Anderson
09545d1454 Merge "libdm: Remove dm_linear_fuzzer." 2023-01-25 18:05:25 +00:00
David Anderson
b888430f15 libdm: Remove dm_linear_fuzzer.
This fuzzer can only mutate the numerical inputs to a dm-linear table,
which is unlikely to find kernel bugs, and very unlikely to find libdm
bugs. There are a number of automated notifications from it due to
making ASSERT_EQ a no-op, which causes misuse of libdm API calls. None
of these appear to be real bugs.

Bug: 174907083
Test: N/A
Change-Id: Iaa8955eaa4423e4315b8cb74741e6425a56cc303
2023-01-24 21:37:18 -08:00
David Anderson
0c1d449f29 Merge "libsnapshot: Test more configurations in presubmit." 2023-01-25 00:07:43 +00:00
David Anderson
f723ef3043 Merge "libdm: Fix failing test on older kernels." 2023-01-24 23:51:08 +00:00
David Anderson
124d980aad libsnapshot: Test more configurations in presubmit.
Take 2: remove the shell script, which wasn't working very well, and
just provide different builds of the same binary.

Bug: 208944665
Test: presubmit
Change-Id: I994a93e4e364bc210ddd2eb60025c656caa86b1c
2023-01-24 14:11:00 -08:00
Swapneel Mashalkar
d3d6b84552 UDC: Dm-Bow failed to load when size is not Multiple of 4096
BUG : 240098675

Skip Dm-Bow load incase size is not a Multiple of 4096.
Rounding down does not hurt, since ext4 will only use full blocks

Change-Id: Ie4e6634b2c49762e4669e66d94effc91d8e581ca
Signed-off-by: Swapneel Mashalkar <quic_smashalk@quicinc.com>
2023-01-24 09:59:32 +00:00
David Anderson
717b97a201 libdm: Fix failing test on older kernels.
This test was added only for behavior introduced in the 5.15 kernel, where uevents are delayed until a table is laoded.

Bug: 263291020
Test: libdm_test
Change-Id: I6236c4304d8e6b780704df405290f7361d5827cc
2023-01-24 05:20:57 +00:00
Eric Biggers
5265b8d425 Clean up references to FDE in documentation and comments
Bug: 208476087
Change-Id: I328026d68c9dd7a5042ef4b5369f34af93760b37
2023-01-18 02:17:43 +00:00
Treehugger Robot
b9e1821201 Merge "Find a zoned partition automatically" 2023-01-17 22:22:26 +00:00
Treehugger Robot
aaa402ae6a Merge "TEST_MAPPING: add vts core lib tests" 2023-01-17 18:40:24 +00:00
Jaegeuk Kim
b92e5b5c48 Find a zoned partition automatically
Since we cannot create a gpt table on zoned LU, we cannot make a generic symlink
from it. Instead, let's make it by uevent, "/dev/block/by-name/zoned_device".
Note that, we support only one zoned device in the system.

Bug: 265180564
Change-Id: Ie62b0fd68b77e3e43cf0f5c5cad9503150174271
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2023-01-14 10:29:31 -08:00
Akilesh Kailash
545870e53a Merge "init: Wait for daemon to fully spin up all threads" 2023-01-13 06:35:33 +00:00
Treehugger Robot
99b26cf41b Merge "remount: Add checkpoint instructions with warning" 2023-01-12 01:44:03 +00:00
Treehugger Robot
a4dae3c6f5 Merge "Do not create worker thread if threading isn't enabled" 2023-01-12 01:12:06 +00:00
Daniel Rosenberg
61b2304ffb remount: Add checkpoint instructions with warning
When debugging an issue before boot complete, it may be necessary to
remount before checkpointing can finish. This gives instructions on
ending checkpointing early, allowing a remount, along with a warning to
not do that unless you know what you are doing.

Bug: 252989722
Test: Displays text in log
Change-Id: Ibdd39464b980ec531a900e162469a884f9096904
2023-01-12 00:04:54 +00:00
Akilesh Kailash
5140f3ad47 init: Wait for daemon to fully spin up all threads
During selinux transition, daemon will notify `init` process
by writing to file "/metadata/ota/daemon-alive-indicator".

Init will wait until daemon notifies it. Furthermore, daemon
will only write to that file once all threads are spin up
and attached to dm-user misc devices.

Once snapshot-merge is completed, this file will be removed.
Additionally, during boot, init will also ensure that
there are no stale files and will try to remove just
before selinux transition.

Bug: 262407519
Test: OTA on Pixel - Verify new file exits and init waits until daemon
is fully up.
Change-Id: Iabef58ad282d80a7afa493e9df9468ae41a13e44
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-01-11 19:24:56 +00:00
Akilesh Kailash
2c52d09078 init: Avoid killing all processes during reboot if update is in progress
Bug: 262321167
Test: Reboot device post OTA reboot
Change-Id: I5d13844e4e157d24a414dce668163bb1915bf65e
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-01-11 06:00:34 +00:00
Kelvin Zhang
124492d875 Do not create worker thread if threading isn't enabled
Currently, we would create worker threads even if number of compression
thread is set to 1. This works, but having context switches and data
exchange between two threads is complete overhead if main thread is just
blocking on the worker thread.

Test: th
Change-Id: I02f98ee1e0c4889dc1ae602eb06667b05796d3f0
2023-01-10 12:09:46 -08:00
Edward Liaw
51c52426f7 TEST_MAPPING: add vts core lib tests
Bug: 258819618
Test: atest :kernel-presubmit
Change-Id: I5e60c69e4f442d33a67b138314918725c6321137
Signed-off-by: Edward Liaw <edliaw@google.com>
2023-01-09 22:05:37 +00:00
David Anderson
1c34ae8864 Merge "Update vts_fs_test to reflect VSR." 2022-12-15 19:17:03 +00:00
David Anderson
37b52b6576 Update vts_fs_test to reflect VSR.
Bug: 253052346
Test: vts_fs_test
Change-Id: I8dbdf731acea9ff5d5006ee3767eda5417d476fd
2022-12-14 22:08:40 -08:00
David Anderson
6433d16543 libdm: Add a helper function for creating placeholder devices.
Bug: 259328366
Test: device boots and mounts userdata
Change-Id: I7aced2eeca984e8ec69633c25d44cd411d0a0583
2022-12-14 21:56:45 -08:00
Yi-Yo Chiang
b0e6c82a86 overlayfs: Mount overlay with context= fs_options if original mount has it
Say we have mount configurations as follows:
  mount <dev> /mnt_point -t ext4 -o ro,context=<se_file_context>
  mount overlay /mnt_point2 -t overlay -o lowerdir=/mnt_point,upperdir=...

Overlayfs driver doesn't forward the overridden file context from
/mnt_point to /mnt_point2, thus the same file (same inode) would have
different file context when accessed via /mnt_point and /mnt_point2.

This change makes adb remount to mount filesystem overlays with context=
option if the overlaid mountpoint has it too. This makes the files under
context= mountpoint to retain the same file context after remount.

Also run clang-format on the whole file to fix some formatting issues.

Bug: 243501054
Test: adb remount && check file context with "ls -Z"
Change-Id: Ie4815604c56f1ce81b755cd0569b6577bd5f575f
2022-12-13 12:00:38 +00:00
Yi-yo Chiang
e0877535ab Merge "overlayfs: fs_mgr_overlayfs_setup() should accept Fstab as input" 2022-12-13 11:56:17 +00:00
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
e508ac4f2e overlayfs: fs_mgr_overlayfs_setup() should accept Fstab as input
Right now fs_mgr_overlayfs_setup() always reads the default fstab and
this makes the "-T" option of remount useless.
Change it so that the fstab is passed in by the caller.

Bug: 243501054
Test: adb remount -vT <path/to/fstab>
Test: and check that overlay is active after reboot
Change-Id: Ia4101938a50c305f105c57018b02aec01f862dec
2022-12-13 01:53:37 +08: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