Commit graph

3409 commits

Author SHA1 Message Date
Akilesh Kailash
3983f9aa6e libsnapshot: Check for valid snapshots based on current slot
We may have snapshot files in /metadata/ota/snapshot/ which ends with
.tmp such as system_a.tmp - This happens if the device
reboots just before `rename` in `WriteStringToFileAtomic`. This
can lead to spurious merge failures.

Log the error and skip these snapshot files. It is ok to skip
as we will still have original snapshot status files since
we are already in the merge path. Additionally, try to remove
these files when snapshot is deleted.

Bug: 292198189
Test: OTA
Change-Id: I5db3dbd5a919b263ae577185de3e7f79a5e9b89a
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-08-10 09:36:35 -07:00
David Anderson
8665b5f9df snapuserd: Remove host_supported from snapuserd_test until it passes.
Bug: 295074841
Test: snapuserd_test
Change-Id: Ie51263ec6971f9806bcfa2b522e5ed24da5d65cf
2023-08-08 16:34:19 -07:00
Daniel Zheng
5061a1cef8 Merge "Adding struct to hold compresion parameters" into main 2023-08-08 23:08:03 +00:00
David Anderson
1333d87bfe snapuserd: Reduce size of COWs in tests.
This greatly reduces the runtime of snapuserd_test, from 4 minutes to
about 1.5 minutes.

Bug: 269361087
Test: snapuserd_test
Change-Id: Ic18443d4e4318f6ef6adadeabd47ccceeeb19b6f
2023-08-08 10:41:56 -07:00
David Anderson
6aec095d68 snapuserd: Add unit tests for ReadWorker::ReadAlignedSector.
These tests are for real bugs that were previously not testable.

Bug: 288273605
Test: snapuserd_test
Change-Id: I9e9af999e4f5f988f4538750eba109f6b2fe448c
2023-08-08 10:41:56 -07:00
David Anderson
0ec9b0eb92 snapuesrd: Build snapuserd_test on host.
Bug: 288273605
Test: snapuserd_test
Change-Id: I10e099feff30f09b8c9f0b9dcca64336cb0861b9
2023-08-08 10:41:56 -07:00
David Anderson
27add51152 snapuserd: Add an ITestHarness implementation for hosts.
This adds an implementation of ITestHarness suitable for running tests
on the host. IUserDevice and ProcessRequests are implemented just enough
for shutdown of ReadWorker to work. Most snapuserd tests are focused on
merging, and do not need a ReadWorker accepting requests.

Bug: 288273605
Test: snapuserd_test
Change-Id: I00cf6ec941fb6423290f7a299e5321adea7d8919
2023-08-08 10:41:56 -07:00
David Anderson
4e0d58c9e5 snapuserd: Don't specify a path to TemporaryFile.
Placing temporary files in the executable dir creates unexpected files
in the build dir when running on the host, which linger if snapuserd
crashes.

Bug: 288273605
Test: snapuserd_test
Change-Id: Ia1ea4ba70b645a9d2f49419b91003bc62fb03cb2
2023-08-08 10:41:56 -07:00
David Anderson
dbda1300ae snapuserd: Factor a base class out of tests.
This factors a lighter weight class out of SnapuserdTest, so we can
construct tests without needing a HandlerManager/daemon.

Bug: 288273605
Test: snapuserd_test
Change-Id: Ib33dc593a5b3d3df86853e73f245918ef36fd9fa
2023-08-08 10:41:56 -07:00
David Anderson
9fb4fc307c snapuserd: Add error propagation to tests.
snapuserd_test in general doesn't propagate errors, which means the
first failure will cascade into many failures. This can make it harder
to figure out what's going on.

Unfortunately error propagation is difficult with gtest, since bool
returns don't work with ASSERT_EQ and Android doesn't use exceptions.

Use ASSERT_NO_FATAL_FAILURE for now, since that is the least invasive
change.

Bug: 288273605
Test: snapuserd_test
Change-Id: I6550682fd63602bc15649f705def2915f6329357
2023-08-08 10:41:56 -07:00
David Anderson
9aa4218246 snapuserd: Add diagnostics for debugging races.
Adds calls to pthread_setname_np for each thread.

Clarify error messages from io_uring calls that return -errno.

Add log messages for some failure paths that didn't have any.

Add an ostream overload for MERGE_IO_TRANSITION, and add an INVALID
state for initialization.

Bug: 288273605
Test: builds
Change-Id: Ic0681cbf0017af67bcf52b98db184a9b48752faf
2023-08-08 10:41:55 -07:00
David Anderson
02191dbfac snapuserd: Fix race condition in HandleManager shutdown.
When HandlerManager shuts down, the monitor thread is left detached. The
monitor thread does not hold a shared_ptr reference to the
HandlerManager, so the pointer can be left dangling.

Fix this by not detaching the monitor merge thread.

This patch also changes the test harness to destroy
SnapshotHandlerManager on "shutdown", to avoid state leaking into the
next instance of snapuserd.

Bug: 288273605
Test: snapuserd_test
Change-Id: Iaaf96a37657c85cff4d2a8b15ccfde4aa03d3220
2023-08-08 10:40:32 -07:00
David Anderson
db70cbf78a snapuserd: Remove test dependence on LoopDevice.
LoopDevice requires root, which is an obstacle to running this test in
automation. The test also requires memfd which is not available in our
included glibc. Create an IBackingDevice layer so we can use temporary
files instead on host tests, while keeping the block-device code for
on-device tests, which more closely matches how snapuserd runs.

Bug: 288273605
Test: snapuserd_test
Change-Id: I89b154921b6bbcf8fe213ef7f5c4da4d48322909
2023-08-08 10:40:32 -07:00
Daniel Zheng
1cb36d300e Adding struct to hold compresion parameters
Since we're adding compression levels should consolidate this
information into one structure.  Adding in CowCompression struct
to hold this information and refactoring code to work off this struct

Test: ota
Change-Id: I969a3ae19ec80fd964bcfb76b39f42f8dd31a56d
2023-08-08 10:14:14 -07:00
David Anderson
dba77ad737 snapuserd: Factor setpriority/settid calls into a helper.
This allows disabling the code in host builds, since settid() isn't
available in the glibc prebuilt.

Bug: 288273605
Test: snapuserd_test
Change-Id: Ifddb5cb8b04484a1ab0a29794d65c9839759a919
2023-08-07 13:37:47 -07:00
David Anderson
fe032d0391 snapuserd: Add a harness to run tests without dm-user specific code.
This patch adds an abstraction layer around Tempdevice (which wraps
device-mapper), and a layer to replace hardcoding of DmUserBlockServer.

The only implementation of the new layer, currently, is for dm-user.
However this will allow the harness to run with a backend chosen at
runtime, making testing on the host or of ublk much easier.

Bug: 288273605
Test: snapuserd_test
Change-Id: I8735ef6c373f3e5c5cdf3df461668ddd8e551f63
2023-08-07 13:37:47 -07:00
David Anderson
384b22ce58 snapuserd: Add an IBlockServerFactory abstraction.
To avoid SnapshotHandler hardcoding specifics about dm-user, this patch
adds a factory interface, responsible for providing IBlockServerOpener
objects.

The test harness will use this to facilitate dm-user-less testing on
host devices.

Bug: 288273605
Test: snapuserd_test
Change-Id: Ifd33c28ee7076f30a8a90f745353893188f97a08
2023-08-07 12:01:24 -07:00
David Anderson
2cffe186ad snapuserd: Remove ambiguous BufferSink in workers.
BufferSink is not needed/used in all worker types, so move it explicitly
to MergeWorker. This also moves the sizeof(dm_user_header) computation
to BufferSink::Initialize.

Bug: 288273605
Test: snapuserd_test
Change-Id: I8fcea6f0e587ca6d8672df5ec58c4d4d14d4b72e
2023-08-07 12:01:03 -07:00
David Anderson
a392fa3c78 snapuserd: Remove dm-user specific code from ReadWorker.
This uses the new IBlockServer abstraction layer instead.

Bug: 288273605
Test: snapuserd_test
Change-Id: Ie9a781e44da7447426706d4874644aabf1be1946
2023-08-07 11:25:55 -07:00
David Anderson
e9277f91f8 snapuserd: Add an IBlockServer abstraction around dm-user.
This adds the planned interface that will abstract around dm-user (for
now), and later ublk at which point it can be adjusted as needed.

This declares the interface and implements it, but does not yet switch
snapuserd to use it. The implementation is copied from read_worker.cpp.

Bug: 288273605
Test: snapuserd_test
Change-Id: I060788c91dba78e52d315b5616b84b37eaf4040f
2023-08-07 11:25:54 -07:00
David Anderson
76094b499c snapuserd: Rename snapuserd_merge to merge_worker.
This follows the recently added names read_worker and worker.

Bug: 288273605
Test: builds
Change-Id: Ie75e94405a018dd0068aa24aefd268adb1aee17e
2023-08-07 11:01:39 -07:00
David Anderson
bcb34d2c54 Merge "snapuserd: Move GetNumSectors call to snapuserd_server." into main 2023-08-07 15:12:20 +00:00
David Anderson
1d8e349cce Merge "snapuserd: Split Tempdevice into a separate file." into main 2023-08-07 02:55:24 +00:00
David Anderson
babf3a9874 Merge changes from topic "libsnapuserd_client" into main
* changes:
  snapuserd: Remove dependence on libfs_mgr.
  snapuserd: Rename libsnapshot_snapuserd to libsnapuserd_client.
2023-08-04 20:14:54 +00:00
Yi-Yo Chiang
656e28174b Merge "libfstab: Optimize out C++ object copy" into main 2023-08-04 05:29:48 +00:00
Yi-Yo Chiang
63a3f34e4c Merge "init: Use libfs_mgr kernel cmdline parser" into main 2023-08-04 03:46:07 +00:00
Yi-Yo Chiang
4131a3afd1 Merge "remount: Replace ServiceManager::getService with checkService" into main 2023-08-04 03:31:33 +00:00
David Anderson
48d1c39da7 snapuserd: Move GetNumSectors call to snapuserd_server.
Calling this in snapuserd_core fails when the base path is a regular
file. Since the value is only read once, just call it from
snapuserd_server instead, which also means we don't have to add an
S_ISBLK check here.

Bug: 288273605
Test: snapuserd_test
Change-Id: Ic26bf807b24611f2d97829d1b4eb1d0ede2feb6a
2023-08-03 16:24:26 -07:00
David Anderson
95f46b0758 snapuserd: Split Tempdevice into a separate file.
Bug: 288273605
Test: snapuserd_test
Change-Id: I3f1b01de8986d22de03bb31355ec09fe48c9204b
2023-08-03 16:15:37 -07:00
David Anderson
c132bf80ae snapuserd: Remove dependence on libfs_mgr.
The only function we use from libfs_mgr is WaitForFile, so factor that
out into libfs_mgr_file_wait. libfs_mgr has too much dependence on AOSP
internals to build on the host.

Bug: 288273605
Test: builds
Change-Id: I8e5eb4075ae01b9ca64074422171a487179e7943
2023-08-03 16:15:34 -07:00
David Anderson
75c5deed52 snapuserd: Rename libsnapshot_snapuserd to libsnapuserd_client.
We don't need this on the host, since the host will not be running
snapuserd as a server. Rename it for clarity and remove it where we can.

Bug: 288273605
Test: snapuserd_test
Change-Id: I679ef668a89411c670fea8d3b758bde589623548
2023-08-03 16:15:33 -07:00
David Anderson
c8ce6347db Merge "libsnapshot: Fix missing return keyword in error path." into main 2023-08-03 18:57:37 +00:00
David Anderson
fbc5f59737 libsnapshot: Fix missing return keyword in error path.
Bug: 288273605
Test: vts_libsnapshot_test
Change-Id: I0bee5ee1ebfb61f17d2a495440048d02e2c347b1
2023-08-03 09:45:20 -07:00
Yi-Yo Chiang
f2368d0744 Merge "init: Unify kernel bootconfig parser with libfs_mgr" into main 2023-08-03 07:54:14 +00:00
Yi-Yo Chiang
59442132d1 remount: Replace ServiceManager::getService with checkService
Address this build log message:
```
[ 18% 2/11] //system/core/fs_mgr:remount clang++ fs_mgr_remount.cpp
system/core/fs_mgr/fs_mgr_remount.cpp:133:31: warning: 'getService' is deprecated: this polls for 5s, prefer waitForService or checkService [-Wdeprecated-declarations]
        if (auto binder = sm->getService(android::String16("vold"))) {
                              ^
```

Bug: 293695109
Test: adb-remount-test
Change-Id: I3b5c7d338e9307dee58edeb0f6a00ba9a73d46f6
2023-08-02 18:01:19 +00:00
Yi-Yo Chiang
e54c0be60f libfstab: Optimize out C++ object copy
* Edit / truncate string objects in-place, don't copy a temporary string
  object just for storing intermeidate results.
* Replace copy construct semantics with move semantics.
* Use range-based std::vector::insert() to move whole range.

Bug: 293695109
Test: CtsFsMgrTestCases
Change-Id: I5437303ba9900dbad3276a981413cba138f17157
2023-08-03 01:31:16 +08:00
Mitchell Wills
b7cfba1ca2 Merge "Add logs in SuperLayoutBuilder::Open when the metadata isn't supported" into main 2023-08-02 16:30:04 +00:00
Yi-Yo Chiang
da5323e2d6 init: Use libfs_mgr kernel cmdline parser
Bug: 293695109
Test: CtsFsMgrTestCases
Change-Id: Ie2567d84cb80c392ad68aef0c438d8acc03a311e
2023-08-02 17:59:05 +08:00
Yi-Yo Chiang
79ad1e2e9b init: Unify kernel bootconfig parser with libfs_mgr
Right now there are two bootconfig parsers that gets linked into `init`.
One is from libinit itself and the other is from libfs_mgr.

The one in libinit removes all space characters between list elements,
so `key = "val1", "val2"` gets unquoted and squeezed into:
  `key=val1,val2`
The one in libfs_mgr doesn't remove spaces, it only unquotes:
  `key=val1, val2`

The libinit behavior is due to existing systems (such as sysprop)
expect the config value to be in the same format as kernel cmdline.
(aosp/1757971)
THe libfs_mgr behavior is due to the `androidboot.boot_device[s]`
format explicitly allows quoted comma appear in its list value, thus
relies on space, not comma, as the list value delimeter.

This commit merges the two parsers into libfs_mgr. Since all usages in
libfs_mgr besides `boot_device[s]` do not care about how list value are
delimited, and most usages in init expects the bootconfig value format
to be the same format as cmdline. We just special case the
`boot_device` scenario.

Also harden the test cases to cover all the different config value
format and expected result.

Note:
The format of kernel bootconfig is described here
https://docs.kernel.org/admin-guide/bootconfig.html

Bug: 293695109
Test: CtsFsMgrTestCases
Change-Id: I42b9bf626e8de38a60e8e09fac0693126b7efd91
2023-08-02 09:57:37 +00:00
Yi-Yo Chiang
0b30e34a04 Merge "init: Unify duplicated get_android_dt_dir with libfs_mgr" into main 2023-08-02 09:56:36 +00:00
David Anderson
c99cd86610 Merge "libsnapshot: Introduce a dynamically linked version of libsnapshot." into main 2023-08-01 16:35:44 +00:00
David Anderson
a637416a87 libsnapshot: Introduce a dynamically linked version of libsnapshot.
This will cut down on the binary sizes of update_engine, snapshotctl,
and lpdumpd.

Bug: 291688516
Test: treehugger
Change-Id: Idae5ea075ab21c2bd4fdb839eb065d865cb07d58
2023-08-01 16:35:38 +00:00
Yi-Yo Chiang
b8c23259b1 init: Unify duplicated get_android_dt_dir with libfs_mgr
init and libfs_mgr both defines get_android_dt_dir() with subtle
differences. Merge the two implementations into libfs_mgr to reduce code
duplication (in terms of source code and code gen)

Note:
init's implementation checks the kernel cmdline first and then the
kernel bootconfig, while libfs_mgr's order is the opposite.
Realistically I don't think this order matter much though. If any, we
should prioritize bootconfig over kernel cmdline most of the time.

Bug: 293695109
Test: Presubmit
Merged-In: Ic8d2c965c62f9e873ccdaf77d67c7708f25a7b56
Change-Id: Ic8d2c965c62f9e873ccdaf77d67c7708f25a7b56
2023-08-01 10:15:05 +00:00
Yi-Yo Chiang
96126069c2 fs_mgr: Split libfs_mgr and libfstab
The goal is to make the header definitions of the two curiously
intertwined libraries less chaotic.

After this change, libfstab's header would be self contained. In the
sense that all symbols exported by its headers are defined in its
compilation units.
libfs_mgr would still embed libfstab like before, it can use internal
symbols (symbols not exported by public headers) of libfstab through
the libfstab/fstab_priv.h private header.

Keep include_fstab/ as a symbolic link pointing to its new location.
This is a temporary workaround as there are still some bad build rules
(incorrectly) depending on the old include path with Android.bp
`include_dirs` directive.

Bug: 293695109
Test: build
Change-Id: Ib70a84984ac2cbfca5f5b27fadebf6a16e58146a
2023-08-01 04:56:41 +00:00
Yi-Yo Chiang
c30f033b4e fs_mgr: Remove include_dirs declaration
We aren't using anything through the removed path.
We also shouldn't use `include_dirs` to begin with, as it bypasses any
build system checks.

Bug: 293695109
Test: build
Change-Id: I06f7450c3ce545aa2583f8c3f8db18c45073f69e
2023-08-01 04:56:41 +00:00
Yi-Yo Chiang
d838dde6aa fs_mgr: Refactor mandatory overlayfs kernel patch checks
The check result can just return the exact mount flags to use, this
reduces code duplication at the caller's side.

Bug: 293695109
Test: adb-remount-test
Change-Id: I9b5c918968f2494c0c1be3cb8d8e6b527a9c4eb2
2023-08-01 03:32:54 +00:00
Yi-Yo Chiang
7b5c38f8eb libfstab: Unexport InRecovery()
It was accidentally moved to the public header when I was previously
refactoring the code. It hasn't caused any harm yet, but we probably
don't want to export this, too.

Bug: 293695109
Test: build
Change-Id: Id81c802cc6cc697c5a4204638aa467966bea1562
2023-08-01 03:19:39 +00:00
Akilesh Kailash
1db90d0aac Merge "libsnapshot: Verify the ordering of COW operations." into main 2023-07-28 22:52:20 +00:00
Akilesh Kailash
63ec4c6180 libsnapshot: Verify the ordering of COW operations.
Sequence op should contain all ordered ops followed
by Replace and Zero ops. There shouldn't be any non-ordered
ops embedded between ordered ops in the sequence ordering.

Bug: 290159346
Test: inspect_cow <cow_file>, OTA
Change-Id: Ia840340b0e4be07525f216838043bf0265f690c3
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-07-28 10:11:06 -07:00
Ryan Prichard
60dbdaa3fa Merge "Explicitly ignore the result of std::async" into main 2023-07-25 20:21:14 +00:00