Commit graph

2744 commits

Author SHA1 Message Date
Bart Van Assche
155684c2bf Merge changes from topic "zram_loop"
* changes:
  Set the I/O scheduler of loop devices to 'none'
  Rename two local variables
2021-08-05 16:57:53 +00:00
Akilesh Kailash
e19f7be126 Merge "snapuserd: Read partition blocks to memory" 2021-08-05 03:02:07 +00:00
Bart Van Assche
ec5f635270 Set the I/O scheduler of loop devices to 'none'
The user interface of Android devices becomes very slow under memory
pressure. This is because Android uses the zram driver on top of the loop
driver for swapping, because under memory pressure the swap code alternates
reads and writes quickly, because mq-deadline is the default scheduler for
loop devices and because mq-deadline delays writes by five seconds for such
a workload with default settings. Fix this by selecting I/O scheduler 'none'
for loop devices.

Bug: 194450129
Test: Built Android images, installed these and verified that the I/O scheduler of all loop devices is 'none' instead of 'mq-deadline'.
Change-Id: Ia5f606504b663948ab56955cad5a71885a356430
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2021-08-04 08:57:32 -07:00
Bart Van Assche
06b95de973 Rename two local variables
Improve code readability by renaming 'device' into 'loop_device' and
'device_fd' into 'loop_fd'.

Bug: 194894000
Test: Built Android images and installed these on an Android device.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Change-Id: Ia9c2d7a525e727f8706e66631b97fc4678c6a4d9
2021-08-04 08:57:27 -07:00
Akilesh Kailash
a11a338e2b snapuserd: Read partition blocks to memory
When the device is rebooted after OTA is done,
daemon will read through all the dynamic partitions
to bring the blocks to memory. When update-verifier
runs, all the blocks would be in page-cache thereby
cutting down the boot time.

Boot time improvements on Pixel:

Full OTA:
===========

VABC (Without this patch): 37.308 seconds
VABC (With this patch): 28.604 seconds

Incremental OTA:
=================

VABC (Without this patch): 39.072 seconds
VABC (With this patch): 27.523 seconds

We read the blocks only during second stage transition. Thus,
it shouldn't impact when snapuserd is spin up during
post-install phase or during first-stage init.

Bug: 193863442
Test: Full and Incremental OTA on pixel
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Id654449238e22125f7d6288c7100fde512cc2ced
2021-08-04 08:38:10 +00:00
David Anderson
381c0fc07c Merge "Add a helper script for dumping snapshot protos." 2021-08-04 06:03:04 +00:00
David Anderson
6a2963e05a Merge "libsnapshot: Use std::unordered_set in DmSnapCowSizeCalculator." 2021-08-03 16:47:11 +00:00
Yi-Yo Chiang
215fde0fde Merge "fs_mgr: Add fs_mgr_flag overlayfs_remove_missing_lowerdir" 2021-08-03 08:46:57 +00:00
Daniel Rosenberg
c90b727301 Merge changes from topic "CowXorOp"
* changes:
  libsnapshot: Don't PrepMergeOps on resume
  snapuserd: Add support for Xor ops in snapuserd
  snapuserd: Rename Read Ahead Iterator
  snapuserd: Add XorSink
  libsnapshot: Clone worker readers from snapuserd
  libsnapshot: Add support for Xor ops in Cow Format
2021-08-03 03:15:49 +00:00
David Anderson
2a1603d07e Merge "snapuserd: Improve EnsureSnapuserdConnected logic." 2021-08-02 18:45:44 +00:00
Eric Biggers
392b9778e6 Merge "fs_mgr: Look for fstab file in /system/etc" 2021-08-02 17:07:03 +00:00
Yi-Yo Chiang
e7783a98af fs_mgr: Add fs_mgr_flag overlayfs_remove_missing_lowerdir
If this flag is given, then fs_mgr_mount_overlayfs_fstab_entry() shall
filter out missing directories in the lowerdir= list.

For example,

  test /mnt/vendor/overlay_test overlay \
    ro,lowerdir=/dir1:/dir2:/missing_dir3 \
    first_stage_mount,overlayfs_remove_missing_lowerdir

should mount the overlayfs device with "lowerdir=/dir1:/dir2".

Bug: 186342252
Test: Manual boot test with modified fstab on CF
Change-Id: Id06b37d0c236528cef981e495280b4f4e9c2b4bb
2021-08-03 01:02:31 +08:00
Eric Biggers
e98afa2687 fs_mgr: Look for fstab file in /system/etc
Look for the fstab file in /system/etc as an alternative to /, in order
to allow fstab files to be installed using the "prebuilt_etc" Soong
module.

This new path is meant to be used by the vendor ramdisk only. As before,
fstabs should *not* be placed in /system/etc on the system partition.

In more detail: sometimes, multiple nearly-identical fstabs need to be
installed to a device, with the correct one being selected at boot time
(b/191417025 as well as other cases that partners have run into).  To
avoid error-prone duplication of configuration files, these fstabs
should be generated from a template by the build system instead of being
duplicated in the source tree.  But if this is done, the usual way of
installing fstabs (PRODUCT_COPY_FILES) can't be used; they need to be
made into real build system modules instead.

Currently, the "prebuilt_etc" Soong module can't correctly install the
vendor_ramdisk copy of the fstab(s), since it will install it into the
/system/etc directory whereas Android currently requires that the
vendor_ramdisk copy of the fstab(s) be placed in the root directory.

Earlier I proposed adding a "prebuilt_fstab" module to handle this quirk
(https://r.android.com/1744033).  However, it was requested to instead
always look for the fstabs in /etc too, in order to allow "prebuilt_etc"
to be used and because /etc is the appropriate place for this file.
This change implements that suggestion (but actually using /system/etc,
since that is where "prebuilt_etc" actually installs it).

Bug: 191417025
Test: Tested that a device boots both with this, both before and after
      http://ag/15075136 which uses the new location.
Change-Id: Id083070e51ae85959167e4615cd96b31a0b1bd6a
2021-08-02 09:59:51 -07:00
Daniel Rosenberg
a7573c7b90 libsnapshot: Don't PrepMergeOps on resume
If we're reading up to a label, we're resuming setting up the file, and
there is no reason to expect the ops we require for sequence ops to be
present. In that case, skip prepping for merge, and return an empty
merge iterator if it is mistakenly requested.

Test: cow_api_test CowTest.ResumeSeqOp
Change-Id: Idd93bd4c4209197b9728fcb21a7191aae971b62d
2021-07-30 20:44:46 -07:00
Daniel Rosenberg
e278cee742 snapuserd: Add support for Xor ops in snapuserd
This adds the ability to read the blocks corresponding to xor operations
from snapuserd. Xor Operations should be treated the same as copy
operations during the merge, but before their data is written to disk,
it must be xor'ed against the operation's data. For the purposes of
readahead, this acts as a copy op. Post readahead, it acts more like a
replace op.

Change-Id: I7d74bbdd43bfc5277ef4c8aade57dd375be9180a
Bug: 177104308
Test: vts_libsnapshot_test and cow_snapuserd_test
2021-07-30 20:44:46 -07:00
Daniel Rosenberg
35bbf11ec1 snapuserd: Rename Read Ahead Iterator
Test: Builds
Change-Id: I1644da1e410141660f3d78447be1da590476505e
2021-07-30 20:44:46 -07:00
Daniel Rosenberg
edf7c667da snapuserd: Add XorSink
We can compute the xor while decompessing by computing it within a
buffer. This would allow us to use a smaller buffer than the full block
size if we wish to cut down on the extra memory required.

Bug: 177104308
Test: cow_snapuserd_test (Snapuserd_Test.xor_buffer)
Change-Id: Id18505841c77340760cea2d20e83454f1142b9b5
2021-07-30 20:44:46 -07:00
Daniel Rosenberg
d091522de9 libsnapshot: Clone worker readers from snapuserd
We'll need to have the Cow Files parsed to deal with xor ops, since
their data location is implicit from the format. Since the relevant data
is all stored in shared pointers, we can pass that data into the workers
without needing to reparse or copy.

Bug: 177104308
Test: builds
Change-Id: I96ac3da1ae620be48e5340c9f146c523b3ce74b6
2021-07-30 20:44:46 -07:00
Daniel Rosenberg
d83b2efb12 libsnapshot: Add support for Xor ops in Cow Format
This adds support for Xor Ops in the Cow Format. These represent store
possibly compressed data which must be xor'ed against the given section
of source data to be interpreted as a block in the new image. The cow
reader and writer do not have access to this data, so they assume the
provider and user of the data will handle the xor-ing.

Bug: 177104308
Test: cow_api_test (ReadWriteXor)
Change-Id: I7a313d2643773d6b81a878a3e5bc87e3bdfc387b
2021-07-30 20:44:46 -07:00
David Anderson
2ed67c9ca4 Add a helper script for dumping snapshot protos.
Bug: N/A
Test: manual test
Change-Id: Iba789cef899d8cbd2b5d623913d169a8258471c5
2021-07-30 16:48:16 -07:00
David Anderson
8c1e93196b libsnapshot: Use std::unordered_set in DmSnapCowSizeCalculator.
There is a check here if vector resize fails. In practice, this would
throw bad_alloc or length_error and cause a runtime abort, so the check
is dead code.

To protect against bad chunk_ids we can switch to unordered_set instead.
The original memory concerns for std::set are less applicable since
unordered_set is bucketed.

Bug: 194431534
Test: apply OTA; run vts_libsnapshot_tests
Change-Id: I09c108b700d2f83acf80a9eaa5099b46aedcab89
2021-07-30 11:02:28 -07:00
David Anderson
2ed2f814fa Merge "Enhance checkpoint=disable GC threshold fallback mechanism" 2021-07-30 17:12:50 +00:00
Daniel Rosenberg
3acae5450f Merge "libsnapshot: Validate Sequence Op data" 2021-07-29 22:40:04 +00:00
David Anderson
e94fffbacd snapuserd: Improve EnsureSnapuserdConnected logic.
This uses a property to communicate when snapuserd is ready to accept
connections, to eliminate some non-determinism from the connect loop.

Bug: 193833730
Test: update_engine connects to snapuserd
Change-Id: I2fc0063486c3df542db1e60d12564a5bc1581a37
2021-07-28 22:27:26 -07:00
Akilesh Kailash
f724176173 Crash during OTA merge may lead to blocks with stale data
This is a corner case wherein a crash during OTA
merge can lead to missing of some COW operations to be
merged thereby some blocks may end up with stale data.

Fix here is to avoid any re-ordering of COW operations.
Merge the COW operations as present in the COW file.

New tests have been added to cow_snapuserd.

Bug: 194955361
Test: cow_snapuserd_test, Incremental OTA
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Id895fe7a3d6b4510676490a86d0caf62dec9b079
2021-07-29 01:02:40 +00:00
Jerry Wong
1f3e92c34e Enhance checkpoint=disable GC threshold fallback mechanism
Enhanced the checkpoint=disable GC threshold fallback mechanism by first
dropping to checkpoint=disable before dropping the option completely for
kernel compatibility.

Test: atest vts_kernel_checkpoint_test
Bug: 193216993
Change-Id: I50ecdf3a82eb7bc677965e8fd3821227fd41bfc2
Signed-off-by: Jerry Wong <jerry.wong@broadcom.com>
2021-07-28 17:31:16 -07:00
David Anderson
0e5ad5a093 snapuserd: Allow connecting to the first-stage daemon.
Currently there is no socket for daemon instances launched during the
selinux phase of init. We don't create any sockets due to the complexity
of the required sepolicy.

This workaround will allow us to create the socket with very minimal
sepolicy changes. init will launch a one-off instance of snapuserd in
"proxy" mode, and then the following steps will occur:

1. The proxy daemon will be given two sockets, the "normal" socket that
snapuserd clients would connect to, and a "proxy" socket.
2. The proxy daemon will listen on the proxy socket.
3. The first-stage daemon will wake up and connect to the proxy daemon
as a client.
4. The proxy will send the normal socket via SCM_RIGHTS, then exit.
5. The first-stage daemon can now listen and accept on the normal
socket.

Ordering of these events is achieved through a snapuserd.proxy_ready
property.

Some special-casing was needed in init to make this work. The snapuserd
socket owned by snapuserd_proxy is placed into a "persist" mode so it
doesn't get deleted when snapuserd_proxy exits. There's also a special
case method to create a Service object around a previously existing pid.

Finally, first-stage init is technically on a different updateable
partition than snapuserd. Thus, we add a way to query snapuserd to see
if it supports socket handoff. If it does, we communicate this
information through an environment variable to second-stage init.

Bug: 193833730
Test: manual test
Change-Id: I1950b31028980f0138bc03578cd455eb60ea4a58
2021-07-27 19:35:29 -07:00
Daniel Rosenberg
ab3b441f94 libsnapshot: Validate Sequence Op data
If the sequence op contains a Cow Operation that doesn't exist, we
should log the error and abort. Otherwise we'll try to merge an op that
doesn't exist.

Test: cow_api_test CowTest.MissingSeqOp
Bug: 177104308
Change-Id: I1a96f09798bc16126ae1338c6259506b18c88f51
2021-07-27 21:59:07 +00:00
Akilesh Kailash
0b23b2a346 Merge "snapuserd: Refactor code to a seperate directory" 2021-07-27 21:14:19 +00:00
David Anderson
f204986802 Merge changes from topic "fs_mgr-vendor-ramdisk"
* changes:
  Make libfs_mgr and its dependencies vendor_ramdisk_available.
  Make libfs_mgr dependencies vendor_ramdisk_available.
2021-07-26 20:54:04 +00:00
Akilesh Kailash
36aeeb3f56 snapuserd: Refactor code to a seperate directory
Move all the code relevant to snapuserd to a seperate
directory. Add OWNERS file.

No other code changes apart from moving files around
and fixing couple location of header paths
at few places.

Bug: 194642092
Test: Compile, Full OTA
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Ib1d852bfeda4eca5c996d6cd7b057f141cb5ddad
2021-07-26 07:04:06 +00:00
David Anderson
a07503afc1 Make libfs_mgr and its dependencies vendor_ramdisk_available.
This is needed to link libfs_mgr with snapuserd.

Bug: 193833730
Test: builds
Change-Id: I5abd706fe134fecebb80ecb790b5be0495e2b925
2021-07-23 16:50:06 -07:00
David Anderson
4e2362ea0a Merge "libfiemap: Fix removal of corrupted split fiemaps." 2021-07-23 02:29:31 +00:00
David Anderson
b0a9c30b6d libfiemap: Fix removal of corrupted split fiemaps.
If a split fiemap header gets corrupted, we could get ENAMETOOLONG and
removal fails. Handle this gracefully.

Bug: N/A
Test: fiemap_writer_test
Change-Id: I4af9ca7ad4b4fa87a91ff05b8fadac4258006ab6
2021-07-19 14:02:56 -07:00
David Anderson
d32f5df728 Merge "libsnapshot: Propagate merge phase across merge failures." 2021-07-19 21:01:06 +00:00
David Anderson
edefadd242 Merge "fiemap: add fsync after write split file name" 2021-07-19 18:14:49 +00:00
David Anderson
c2bb3ee6d6 libsnapshot: Propagate merge phase across merge failures.
If a merge fails we write a new snapshot status indicating that the merge
failed. If this happens to occur during the second merge phase, we fail
to propagate the phase counter to the new status. This means the merge
is unlikely to make progress and succeed later.

Bug: 193549218
Test: manual test
Change-Id: I31fdae6bde48e3a71b6f3fcc663541257f7ebd8f
2021-07-16 20:05:39 -07:00
lijiazi
ebff7b8b97 fiemap: add fsync after write split file name
If device abnormal restart during upgrade, update_engine just
created split cow image file and wrote the name to xxx-cow-img.img.
After restart, update_engine will report following err:

06-30 08:48:06.466  root  8918  8920 E gsid    : Error removing image
product_b-cow-img: File name too long

That is because SplitFiemap::Create->DetermineMaximumFileSize
open xxx-cow-img.img to get some info, then fsync and unlink this
file.

On device use f2fs, after restart, f2fs_recover_fsync_data will
recover this file with inode block sync to ufs in following path:
DetermineMaximumFileSize
    ->FiemapWriter::Open
        ->AllocateFile
This make xxx-cow-img.img file content corruption.

Update_engine call TryCancelUpdate to clean up the residual files
of last upgrade, cannot read valid split file name from
xxx-cow-img.img, then report err log mentioned above.

Add fsync, f2fs can use correct inode to recover related files.
This can reduce the probability of this issue.

Test: abnormal restart when upgrade

Change-Id: Iceb3e5604d90495350c5fb1fb3433732372f3fec
Signed-off-by: lijiazi <lijiazi@xiaomi.com>
2021-07-16 16:25:31 +08:00
Nikita Ioffe
7756779289 Deflake libdm#CreateEmptyDevice test
Judging from local experiments, it looks like device-mapper doesn't
always generate a uevent after DM_DEV_CREATE ioctl.

Test: presubmit
Bug: 193462349
Change-Id: I8a74375631b20c14a32a41dbaf38380ebc0078e6
2021-07-15 15:33:17 +01:00
David Anderson
0f707941d4 libsnapshot: Fix inconsistency in how merge ops are counted.
A recent change to libsnapshot caused us to filter out duplicate COW
ops. The merge consistency check relied on the old method of manually
counting ops, causing it to come up with a different number. Fix this by
using the already computed "official" count.

Bug: 193532829
Test: new test case in vts_libsnapshot_test
      manual test with incremental OTA
Change-Id: I68d1e41f5c140af20a04ba80e3db0780a916ecf8
2021-07-14 16:44:54 -07:00
Treehugger Robot
df72c168d3 Merge "fs_mgr: License boilerplate" 2021-07-13 01:33:43 +00:00
Bowgo Tsai
a8c6b9d27f fs_mgr: License boilerplate
Bug: 191507548
Test: TreeHugger
Change-Id: I2924d1733fc64de69681971ab42a526dc3bbcc1d
2021-07-09 06:24:04 +00:00
Kelvin Zhang
c801d5b8f0 Correctly implement a stub for ICowWriter::AddXorBlocks
Test: th
Change-Id: I70c174c4d44ef979993063256e3eededf18bd086
2021-07-08 16:12:16 -04:00
Kelvin Zhang
e475852cf6 Add MockSnapshotWriter
Test: th
Change-Id: Ifc365e3bafc07f0708d9e2113afa434d73f32e28
2021-07-08 16:11:16 -04:00
Daniel Rosenberg
b19c333f2f Merge changes from topic "CowSequenceOp"
* changes:
  libsnapshot: Switch merge to CowRevMergeOpItr
  libsnapshot: Add seq op support to inspect_cow
  libsnapshot: Add CowRevMergeOpIter
  libsnapshot: Add IsOrderedOp
  libsnapshot: Cleanup iterators
  libsnapshot: Add Sequence Ops
2021-07-07 23:59:43 +00:00
Daniel Rosenberg
437a49ae66 libsnapshot: Switch merge to CowRevMergeOpItr
This switches merge code over from using the old RevOpItr to the new
MergeRevOpItr. Since there are no other users, RevOpItr is no longer
needed.

Changed names of copy_ops_ and total_data_ops_ to more accurately
reflect their meaning.

Bug: 177104308
Test: cow_snapuserd_test
Change-Id: Ic053be4877cfdc86656551f5a3d5d95f3825f937
2021-07-07 22:23:44 +00:00
Daniel Rosenberg
fffb9ff8ee libsnapshot: Add seq op support to inspect_cow
This adds the -m option to inspect_cow, allowing it to display the ops
according to CowRevMergeOpItr

Bug: 177104308
Test: inspect_cow -m on file with and without seq ops
Change-Id: Ic9a062b8175c77084e76c437414c23fd09e34cc6
2021-07-07 22:23:38 +00:00
Daniel Rosenberg
9b34ea8541 libsnapshot: Add CowRevMergeOpIter
This presents cow ops in the reverse of their merge order, as requested
when we perform a merge. It starts with sorted non-ordered ops sorted by
blocks, and then the ordered ops. Already merged ops are removed.

Bug: 177104308
Test: cow_api_test
Change-Id: I864bcab5cda447cf4a197abc02d954f9db08b744
2021-07-07 22:23:27 +00:00
Daniel Rosenberg
f7001fad6f libsnapshot: Add IsOrderedOp
Ordered Ops are Cow Ops with source block dependencies.
Currently this is only Copy Ops, but will extend to XOR
blocks when they're added.

Bug: 177104308
Test: Builds, does not impace cow_api_test/cow_snapuserd_test
Change-Id: I0a50dfe3316ec3a3b1d035335f094c62296649a5
2021-07-07 22:23:22 +00:00
Daniel Rosenberg
f0d9beb162 libsnapshot: Cleanup iterators
The libsnapshot iterators can all use the same interface instead of
duplicating the interface. We don't have any need for the internal class
variable iterators, so remove them.

Test: Builds, does not impact cow_api_test/cow_snapuserd_test
Change-Id: I5f008401e067a55a57812b7bf101a472ad97df18
2021-07-02 20:53:16 +00:00