Commit graph

2449 commits

Author SHA1 Message Date
David Anderson
231cfc4fe6 Merge "libsnapshot: Add a helper for waiting for device paths." 2020-11-22 21:45:26 +00:00
David Anderson
189e8e3a25 libsnapshot: Add a helper for waiting for device paths.
Normally, DeviceMapper::CreateDevice() handles this for us. However, it
does not work in first-stage init, because ueventd is not running.
Therefore this patch adds a way for first-stage init to set a callback
to manually regenerate and process uevents.

Additionally, even with ueventd, dm-user misc device creation needs a
WaitForFile() call, since ueventd is asynchronous.

The WaitForDevice() helper in this patch accounts for both of these
scenarios.

Bug: 173476209
Test: device boots into first-stage init after full VABC ota
Change-Id: Ib7a9bfc2a5a5095aa00b358072f9cb1743c19ab2
2020-11-21 17:12:23 -08:00
David Anderson
84cfcc23c2 Merge "snapuserd: Include the misc device when logging in each snapuserd thread." 2020-11-22 00:49:59 +00:00
David Anderson
8d2bd038f4 snapuserd: Include the misc device when logging in each snapuserd thread.
Bug: N/A
Test: manual test
Change-Id: Ifd6ac5a802549ccc9271b62eedd1509552f27ead
2020-11-21 13:29:42 -08:00
Treehugger Robot
7cf47025ee Merge "dmuserd: Fix error checking" 2020-11-20 01:58:13 +00:00
Greg Kaiser
10e3d620b4 dmuserd: Fix error checking
We change read_all() and write_all() to return signed values, so
our negative error return values will be correctly caught.

Test: TreeHugger
Change-Id: I4d03d4475bccb40ae4b84a846966139b34ede2bd
2020-11-19 16:15:48 -08:00
David Anderson
3bb971dcc3 Merge "libsnapshot: Add a compression bit to SnapshotStatus." 2020-11-19 20:50:52 +00:00
Palmer Dabbelt
b065d2444a Merge "dmuserd: Simple dm-user daemon" 2020-11-17 03:45:50 +00:00
David Anderson
411339c727 libsnapshot: Add a compression bit to SnapshotStatus.
Using ro.virtual_ab.compression.enabled does not work in first-stage
init, since properties aren't available. Instead, attach a compression
bit to SnapshotStatus. Although there are no plans to have per-snapshot
compression toggles, this route avoids creating a new state or indicator
file elsewhere. And SnapshotStatus is available in every place that
cares about compression.

Bug: N/A
Test: apply OTA with VABC
Change-Id: I51deb5693a08417ea7a2c524e240191748907123
2020-11-16 18:24:30 -08:00
Akilesh Kailash
023c62798c libsnapshot: snapuserd: Handle flush request
Handle flush operations by dm-snap post merge and
the ABI changes from dm-user. This
is now in sync with the latest dm-user patch (patch 25).

In case of any failures observed in daemon in the IO
path, return error code back to dm-user which
will eventually fail the IO.

Bug: 168311203
Test: vts_libsnapshot_test, cow_snapuserd_test

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I4af63845f8c3e1c445f6c55374ea58b6f3454795
2020-11-16 23:59:35 +00:00
Palmer Dabbelt
c16e503faa dmuserd: Simple dm-user daemon
This provides a block device via dm-user, with all accesses backed by
in-memory storage.  It's essentially the same as what I have in
selftests, with the kselftests stuff removed so it'll build in Android.

Test: mkfs.f2fs, dd, fsck.f2fs
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
Change-Id: I68515d6e9001c2f6d199d394e67ebe528b382406
2020-11-16 22:23:07 +00:00
David Anderson
943dd5cff5 libsnapshot: Get DaemonTransition test passing again.
This fixes a number of small bugs in libsnapshot. It also refactors the
handler list a bit. Previously, it was a list of unique_ptrs. Now it is
a list of shared_ptrs to simplify ownership.

Additionally, Snapuserd is now keyed solely on the misc device name.
This allows two identical snapshots to run in the same daemon, with
different control names (a scenario that comes up in the
DaemonTransition test). As part of this change, the two-stage
initialization process has been refactored slightly. The "init" message
sets all the device paths, and the "start" message needs only the misc
name.

Both the init and start messages now validate that no duplicate handlers
exist, and that we're not overwriting any previous thread.

This cleanup also fixes a bug in DmUserHandler cleanup - if a control
device shut down raced with WaitForDelete(), the std::thread object
would delete without a call to detach() or join(). In the new
RemoveHandler(), we now correctly detach() in this scenario.

This also fixes a bug where, if a COW had no partition component (it
only resided on /data), the second-stage transition would fail because
it used the wrong device-mapper name.

Bug: N/A
Test: vts_libsnapshot_test
Change-Id: Ib4a281a3b5fe665c727c7077672e3c6b0b3abdba
2020-11-12 20:41:25 -08:00
David Anderson
3e3159c83e libsnapshot: Move first-stage pid var constant into IDeviceInfo.
This will fail in vts_libsnapshot_test because the pid isn't set (and
even if it was, we don't want to kill any running snapuserd instances).
Rather than start an instance just for the sake of killing it, use
dependency injection instead.

Bug: N/A
Test: vts_libsnapshot_test
Change-Id: I1569f927e018319cf4008673a32d5526573d8d57
2020-11-12 20:41:24 -08:00
David Anderson
9e6cef7f07 Merge changes Ie79ab525,I3befc71f
* changes:
  libsnapshot: Refactor COW reading/writing of footers.
  libsnapshot: Don't try to truncate block devices
2020-11-12 01:45:19 +00:00
Akilesh Kailash
70d27113d0 Merge "libsnapshot: Retrieve base sector for dm-user device creation" 2020-11-12 00:45:21 +00:00
David Anderson
ea79136740 libsnapshot: Refactor COW reading/writing of footers.
This simplifies the footer and label resume system for COW files.
Previously, a footer could be missing, and we'd try to recover the file.
Any ops we could recover were handed off to the CowWriter, which then
searched up to the correct resume label.

In the new model, a reader is opened with an optional label (resume
mode), or without a label.

When resuming to a label, a footer is optional. The read is terminated
by EOF, discovery of the requested label, or the presence of a footer.
However the requested label must be found, and parsing fails if it is
not found.

When opening a COW without a label, the footer must be present, as this
signals the file was successfully flushed. Parsing fails if no footer is
found.

Bug: N/A
Test: cow_api_test
      full OTA with VABC
Change-Id: Ie79ab5259f532dd16c72f0e42da7568c5c5c4623
2020-11-11 15:51:15 -08:00
Daniel Rosenberg
ce69f2985b libsnapshot: Don't try to truncate block devices
When we're writing to a block device, we can't truncate. Ignore those
commands. Truncate mostly just saves time in the read phase by chopping
off unused data in the event finalize wasn't called.

Bug: 172026020
Test: cow_api_test
Change-Id: I3befc71fa9597edf8243d0f9e17440db91409aea
2020-11-11 15:49:18 -08:00
Akilesh Kailash
8ec3fa8aba libsnapshot: Retrieve base sector for dm-user device creation
dm-user device requires sector information which is retrieved
from snapuserd daemon once the metadata read is completed.
Split up the initialization of daemon into two APIs. Once
the metadata read is completed, send the sector information
back to libsnapshot to create the dm-user device.

On a sidenote, remove unused code from snapuserd_client

Bug: 168311203
Test: vts_libsnapshot_test, cow_snapuserd_test

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I0647ebbeea3a4705599966974bfec2318a3e1e4e
2020-11-11 22:40:49 +00:00
George Burgess IV
3d0f195bcc Merge "fs_mgr: fix potential uses of nullptr" 2020-11-11 22:02:29 +00:00
Akilesh Kailash
d29c2f5dbc Merge "libsnapshot:snapuserd: Snapshot merge support." 2020-11-11 01:04:23 +00:00
Yo Chiang
26f47f8815 Merge "Use default DSU slot name when active DSU is empty" 2020-11-10 10:24:00 +00:00
George Burgess IV
1c8d814cea fs_mgr: fix potential uses of nullptr
Clang's static analyzer flagged the following potential null pointer
dereferences. Looks like a transitive caller of this function has

```
if (change) *change = foo;
```

...and no nullness checks between that and these unconditional
assignments to `*change`.

> system/core/fs_mgr/fs_mgr_overlayfs.cpp:1100:13: warning: Dereference
of null pointer (loaded from variable 'change')
[clang-analyzer-core.NullDereference] >
system/core/fs_mgr/fs_mgr_overlayfs.cpp:1167:17: warning: Dereference of
null pointer (loaded from variable 'change')
[clang-analyzer-core.NullDereference]

Bug: None
Test: TreeHugger
Change-Id: I656e3b0f56b18ec3ca3d1db773feb81adf163122
2020-11-09 22:24:37 -08:00
Akilesh Kailash
218059ff9f libsnapshot:snapuserd: Snapshot merge support.
Handle write IO during snapshot merge. When merge
is completed, dm-snapshot-merge issues WRITE IO
to indicate the completion of merge for a specific
operation. Snapuserd daemon tracks the merge completion
process in the COW header; this is required to handle
resuming merge operation gracefully if there is a crash
during merge.

Bug: 168311203
Test: vts_libsnapshot_test, cow_snapuserd_test
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I4fc8cc23a6ec5b26b7ae3339212efdd3b9a367e8
2020-11-10 03:54:52 +00:00
Akilesh Kailash
3e64e2ba25 Merge "libsnapshot:snapuserd: Read the cow_operation in reverse order" 2020-11-10 03:51:05 +00:00
Akilesh Kailash
d08195691b libsnapshot:snapuserd: Read the cow_operation in reverse order
This is required for merge IO path. During merge process,
kernel scans the metadata page from backwards when merge
is initiated. Since, merge ordering should follow our internal
COW format, read the COW operations from backwards and populate the metadata.

Additionally, Kernel can merge successive operations if the two chunk IDs
are contiguous. This can be problematic when there is a crash
during merge; specifically when the merge operation has dependency.
These dependencies can only happen during copy operations of the
overlapping regions. To avoid this problem, we make sure that
copy operations are merged individually.

Test: cow_snapuserd_test
Bug: 168311203

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Ic9c52b323ce58af897cfa343bf9277c8f1f022e3
2020-11-10 02:12:07 +00:00
Akilesh Kailash
bcf87898d7 Merge "libsnapshot:snapuserd: Fix cow_snapuserd_test." 2020-11-09 21:28:44 +00:00
Nikita Ioffe
f389e419ac Merge "Don't SIGABORT if device-mapper doesn't generate uevent for DeleteDevice" 2020-11-09 13:27:12 +00:00
Yo Chiang
cb1d0d90af Use default DSU slot name when active DSU is empty
If host system is Android Q and guest system is S, then reenable DSU in
the guest system (`adb shell gsi_tool enable -s`) would create an empty
DSU active indicator file.
In this case, use the default slot name "DSU" if DSU active indicator
file is non-existent or empty.

Bug: 172541102
Bug: 168571434
Test: Boot GSI S on Pixel Q with DSU
Test: Verify reenable DSU works
Test: adb shell gsi_tool enable -s && adb reboot
Change-Id: Ie59e4378d1aa4dca085c399a75abd4e662340030
2020-11-09 10:01:34 +00:00
David Anderson
4137dee0e5 libsnapshot: Fix broken iterator in CompressedSnapshotReader.
Bug: NA
Test: apply full OTA with VABC
Change-Id: I9173ac1c6fb601a6f9e0bfb935d7908e0f234f0f
2020-11-06 15:10:41 -08:00
Nikita Ioffe
3b39a9ef6a Don't SIGABORT if device-mapper doesn't generate uevent for DeleteDevice
It looks like in some rare scenarios device-mapper won't create an
uevent while handling DM_DEV_REMOVE ioctl.

Since failure to generate uevent will result in ueventd not cleaning up
/dev paths in user space, it should be ok to just fail DeleteDevice call
without aborting the entire process.

Test: presubmit
Bug: 171266986
Change-Id: Iece28e6e02c35ac4bf33b9be74dfe1bbbb466bd4
2020-11-06 22:38:23 +00:00
Daniel Rosenberg
d021544d04 Merge "libsnapshot: Remove Initialize(fd, APPEND)" 2020-11-06 22:16:43 +00:00
Akilesh Kailash
17b5a4433e libsnapshot:snapuserd: Fix cow_snapuserd_test.
This will test the IO operation
between dm-snapshot/dm-user/snapuserd daemon. This test was broken
after cow format and daemon related changes.

Test: cow_snapuserd_test

Bug: 168311203
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I3e5f435332957a2549fd029c84efe13efb98b909
2020-11-06 22:10:10 +00:00
David Anderson
f54cc3bbfd Merge changes I0b9ce272,I2bb3e55b
* changes:
  libsnapshot: Ignore non-data ops in snapshot_reader.
  libsnapshot: Round compressed COW sizes to the nearest block.
2020-11-06 19:05:42 +00:00
Yo Chiang
b445a01263 Use default dsu slot name when host is Android Q
DSU slotting support is added in Android R, so
android::gsi::GetActiveDsu() is guaranteed to fail if DSU guest system
is S and host is Q.
In that case, just assume the the DSU slot to be "dsu".

Bug: 172541102
Bug: 168571434
Test: Boot GSI S on Q pixel with DSU
Change-Id: I96e191907ce2fedf8c22b7887e930a7c455eb593
2020-11-06 09:00:41 +00:00
David Anderson
6404d11a20 libsnapshot: Ignore non-data ops in snapshot_reader.
Certain ops (label, footer) do not have actual block mappings, so ignore
these.

Bug: NA
Test: apply OTA with VABC
Change-Id: I0b9ce27239553d8126c17767f35c2651df951ea0
2020-11-06 00:50:35 -08:00
David Anderson
14ae4d1dee libsnapshot: Round compressed COW sizes to the nearest block.
This is needed to create and stack device-mapper devices. The kernel
complains (or rejects) the table otherwise.

Bug: N/A
Test: manual test
Change-Id: I2bb3e55b7d999522c4c990b4ab7c46bcb78553a8
2020-11-06 00:50:34 -08:00
Daniel Rosenberg
dd6cb0d236 libsnapshot: Remove Initialize(fd, APPEND)
All cases where we want to append are done via label, so we can remove
the far more complicated open mode for append. Since this only leaves
open, we can remove the mode entirely.

Bug: 172026020
Test: cow_api_test
Change-Id: Ibe305e56b434da25952a129764398f606ca58aff
2020-11-05 18:38:58 -08:00
David Anderson
1b9ab3f544 libsnapshot: Add an open /dev/null mode for CowWriter.
This will be used by payload_generator to estimate the COW size without
using extra storage space.

Bug: 168554689
Test: cow_api_test, ota_from_target_files
Change-Id: I095c809e7d81eff5321b86f4c6bdfb6e9467e84e
2020-11-04 20:38:50 -08:00
Treehugger Robot
f2609b2b0f Merge "libsnapshot: Only sync after labels" 2020-11-05 03:52:04 +00:00
David Anderson
c497a1c63c Merge "libsnapshot: Use the COW size from the update manifest." 2020-11-04 20:20:14 +00:00
Yo Chiang
cc86e967c7 Fix unused function error for user build
```
system/core/fs_mgr/fs_mgr_overlayfs.cpp:83:6: error: unused function
'fs_mgr_is_dsu_running' [-Werror,-Wunused-function]
```

Bug: 172405271
Bug: 165925766
Test: build aosp_bonito-user, no warning/error
Change-Id: I3206e5bd13658ab0b7f5826e8e1c206c8df65684
2020-11-04 07:02:47 +00:00
Treehugger Robot
f6d42d45c5 Merge changes I669a03a6,Ibb774d6d
* changes:
  libsnapshot: Fix footer values and verification
  libsnapshot: Fix some minor formatting bugs
2020-11-04 04:50:42 +00:00
Yo Chiang
65f4f4359d Merge changes from topic "dsu-overlayfs"
* changes:
  Refactor fs_mgr_overlayfs_teardown()
  Enable overlayFS on DSU system
2020-11-04 03:30:31 +00:00
Yo Chiang
497bca09c7 Merge "adb-remount-test.sh: Make devt errors warnings instead" 2020-11-04 03:30:31 +00:00
Yo Chiang
5ab4400db1 Merge "TransformFstabForDsu() skips handling special devices" 2020-11-04 03:30:31 +00:00
David Anderson
dfaede06bc Merge changes from topic "init-snapuserd"
* changes:
  libsnapshot: Implement MapAllSnapshots and UnmapAllSnapshots.
  Start snapuserd if needed as soon as possible during second-stage init.
  libsnapshot: Add support for first-to-second-stage transitions of snapuserd.
2020-11-03 18:24:49 +00:00
Daniel Rosenberg
d5bcbaa066 libsnapshot: Only sync after labels
This changes labels to belong at the end of the set of ops that they
refer to. We only sync after writing a label, or the footer, saving the
cost of syncing after ever op.

Change-Id: Iee9dd69132b8e3321eccfe1e43fa0c072a94d3bd
Bug: 172026020
Test: cow_api_test
2020-11-03 00:40:02 -08:00
Daniel Rosenberg
290b0ed4b3 libsnapshot: Fix footer values and verification
A few values in the footer were being set inconsistently. We weren't
verifying them, so it didn't matter. This adds verification and sets
them properly.

Change-Id: I669a03a6e1e87ace31775aba5b67dde9b6e5ecf5
Bug: 168829493
Test: cow_api_test
2020-11-03 00:40:02 -08:00
Daniel Rosenberg
46ef7595d0 libsnapshot: Fix some minor formatting bugs
A few minor issues snuck through code review.
Removed a debug line in cow_api_test to persist file.
Removed unused function declaration for cow writer
Switched PLOG to LOG where no errno exists.

Change-Id: Ibb774d6de518fc2a8746e4b9eefc3655c9973c30
Bug: 168554689
Test: cow_api_test
2020-11-03 00:39:45 -08:00
David Anderson
eb7eb4bef6 libsnapshot: Use the COW size from the update manifest.
When Virtual A/B Compression is enabled, the manifest contains the
predicted COW size. Use this instead of the algorithm based on the
kernel COW format.

Bug: 168554689
Test: vts_libsnapshot_test
Change-Id: I545679b4834957ff80a930d91cb44afbadebb66c
2020-11-02 13:24:16 -08:00