Commit graph

879 commits

Author SHA1 Message Date
Mark Salyzyn
b5065fcb28 fs_mgr: fs_mgr_update_verity_state take std::function
By changing to a std:function from a plain function pointer as an
argument to fs_mgr_update_verity_state(), a lambda with captured
objects can be executed providing thread safety.

Test: compile and boot
Bug: 109821005
Change-Id: I2699a08cc2c5216625dcbf84eeac0c460f4ae36a
2018-06-28 08:43:35 -07:00
Mark Salyzyn
eba4706a2e fs_mgr: Add support in fs_mgr_read_fstab_file for /proc/mounts
Generate fstab from /proc/mounts.  Basically like any regular fstab
minus the requirement for the Android fs_mgr_flags.  Added a unit
test to confirm that fs_mgr_read_fstab("/proc/mounts") matches the
setmntent("/proc/mounts")+getmntent() content.

As a result, discovered a bug in parse_flags that would report "ro"
if the "rootcontext=..." flag was referenced.

Test: fs_mgr_unit_test
Bug: 109821005
Change-Id: I635ee979e11ee089b09adbedb5f42b6ba78026de
2018-06-27 14:49:06 -07:00
David Anderson
51c02c4a5a Merge changes Ia35a4541,Iaf13450d
am: b27d572d21

Change-Id: I6933bb0fe4e3a239068459c2321c849c86d24220
2018-06-27 13:06:10 -07:00
David Anderson
b5acb1ac4a fs_mgr: remove fs_mgr_dm_ioctl
Bug: 110035986
Test: N/A
Change-Id: Ia35a45415f1b2bc476784890d838b44e6854d5b9
2018-06-27 12:48:29 -07:00
David Anderson
40b594827f fs_mgr: replace DM_TABLE_STATUS use with libdm.
This change introduces a new GetTableStatus method on DeviceMapper,
which returns a vector of information about each target in a device's
table. Some target types (such as verity) can also return additional
information as a string.

Support for this call has also been added to the "dmctl" tool via a
"table" command. Examples:

    $ dmctl create blah zero 0 8000 linear 8000 1000 /dev/block/sdd1 0
    $ dmctl table blah
    Targets in the device-mapper table for blah:
    0-8000: zero
    8000-9000: linear

    For verity:
    sailfish:/ # dmctl table system
    Targets in the device-mapper table for system:
    0-4128792: android-verity, V

Bug: 110035986
Test: libdm_test gtest; AVB1 device still boots
Change-Id: Iaf13450d3b32e2264c7c399a8af8d6bade260592
2018-06-27 12:48:28 -07:00
David Anderson
c75ab5e7c7 Merge "fs_mgr: Use libdm for fs_mgr_verity."
am: b4a2f5797c

Change-Id: I0a119197135f1719192e9e6cee48e1b5b4d7d259
2018-06-26 18:44:43 -07:00
David Anderson
cf50322e74 Merge "libdm: Add DmTargetVerity and use it in fs_mgr_avb."
am: b0ea3d38b4

Change-Id: If04e5f2e684bdc6036383a4e85e7d3e54ca82a8a
2018-06-26 12:54:56 -07:00
David Anderson
9803fbf30b fs_mgr: Use libdm for fs_mgr_verity.
This change uses libdm to replace the hand-coded ioctl code in fs_mgr_verity.
Since AVB2 is now preferred to AVB1, this is a surgical change to allow
us to remove fs_mgr_dm_ioctl. Rather than refactor the target string
construction code, we instead provide a DmTargetVerityString class which
passes a raw parameter string directly to DmTable.

Bug: 110035986
Test: AVB1 device still boots
Change-Id: Iad88993a98abb388a12cec9e6d4543dfb4157414
2018-06-26 12:41:47 -07:00
David Anderson
1d17339560 libdm: Add DmTargetVerity and use it in fs_mgr_avb.
This change adds a DmTargetVerity class and replaces the existing verity
table builder in fs_mgr_avb.cpp. DmTargetVerity must be constructed with
all the required parameters for dm-verity. Additional arguments can be
appended via helper methods.

Bug: 110035986
Test: libdm_test gtest; boots with verity on AVB devices
Change-Id: I4fc2f7ef122c841e8b4ec4156177a6224ffbac30
2018-06-25 17:56:12 -07:00
David Anderson
01d3de5e41 Merge "fs_mgr: Use libdm for dm-linear devices."
am: 7a8bed30dd

Change-Id: I84523a58883b86977b167cefa4d818da759a9c2a
2018-06-25 17:09:53 -07:00
David Anderson
6124d75d4a Merge "libdm: Add unit tests for dm-linear."
am: 9d254f0dac

Change-Id: Iddfbd69da03022672f163759c3db5d95e6a12a79
2018-06-25 15:36:04 -07:00
David Anderson
2603850bdf Merge "libdm: Add helper classes for loop control."
am: 516ec4c257

Change-Id: I8412530900df6a36435903d6ec4123924ec2c486
2018-06-25 14:35:55 -07:00
David Anderson
4b52440812 fs_mgr: Use libdm for dm-linear devices.
This removes the custom ioctl code in fs_mgr_dm_linear.cpp in favor of
using libdm.

Bug: 110035986
Test: logical partitions are still created in first-stage init
Change-Id: I941a27ce865aa1bc712b91d8d4c874462e0d11df
2018-06-25 12:56:15 -07:00
David Anderson
2d3e79f5d5 libdm: Add unit tests for dm-linear.
Bug: 110035986
Test: libdm_test gtest
Change-Id: I83fb978931aa36b83880c4d44745cc45ee516fc4
2018-06-25 12:56:14 -07:00
David Anderson
1f428ea054 libdm: Add helper classes for loop control.
This change adds a LoopControl class for interacting with the loop
control device. In addition it provides a LoopDevice class for creating
temporary loop devices. This is aimed at being a building block for libdm
tests, so the current functionality is limited to attaching and
detaching file descriptors and finding free loop devices.

Bug: 110035986
Test: libdm_test gtest
Change-Id: Ice2891e3a44a037aff7b81c63ac793815640d582
2018-06-25 11:37:51 -07:00
David Anderson
6aa16f4eb0 Merge "libdm: Implement GetDmDevicePathByName()."
am: a67b00a322

Change-Id: If7bd99f875375ad1f4e5f2aad996ede3cd0fb40d
2018-06-22 17:08:44 -07:00
Treehugger Robot
a67b00a322 Merge "libdm: Implement GetDmDevicePathByName()." 2018-06-23 00:00:51 +00:00
David Anderson
72e8546026 Merge "liblp: Add unit tests for flashing and readback."
am: 245b03248f

Change-Id: Ibdff80c9a19ffac6a02b1e73ab55c2ddd898ec00
2018-06-22 16:36:59 -07:00
Treehugger Robot
245b03248f Merge "liblp: Add unit tests for flashing and readback." 2018-06-22 23:28:02 +00:00
David Anderson
5e9e74be61 libdm: Implement GetDmDevicePathByName().
This change implements the ability to get the path of a block device
given a device-mapper device name. In addition, dmctl now has a
"getpath" command to perform this query, as a shortcut for searching
through /sys/block/*/dm/name.

Bug: 110035986
Test: N/A
Change-Id: I9ebd824fa800004f591fc02fc1b1950e0c7fba65
2018-06-22 14:23:31 -07:00
David Anderson
628df89e8a Merge "liblp: Add unit tests."
am: 8ddd105545

Change-Id: I1c69cf75c70b56b87dac05c5fc0654c13f1dd9fe
2018-06-22 13:54:10 -07:00
Treehugger Robot
8ddd105545 Merge "liblp: Add unit tests." 2018-06-22 20:47:18 +00:00
David Anderson
dae1e7915a Merge "libdm: Implement zero and linear targets."
am: d9b581e9b5

Change-Id: Ifd8f9e3c09f993832e4a2eaa96a183fc66102351
2018-06-21 20:31:31 -07:00
David Anderson
efa61bf7ea Merge "libdm: Add DmTargetTypeInfo and a unit test."
am: 2502aa2a12

Change-Id: I9ddf61051c3cb292d351f42d0be5640fadcf9c2f
2018-06-21 20:30:22 -07:00
David Anderson
0a186a834e liblp: Add unit tests for flashing and readback.
These tests check that various aspects of liblp's on-disk management
are functioning as intended. This checks redundancy, metadata slot
management, and metadata update and readback.

Bug: 79173901
Test: liblp_test gtest
Change-Id: Ib780676e0f34f44aa255e8fcfded2ceb71fe3dce
2018-06-21 12:58:34 -07:00
David Anderson
e9619eb6d1 liblp: Add unit tests.
Bug: 79173901
Test: liblp_test gtest
Change-Id: Iba77f0a0886741e459ab65122c28e8bd52ec93e8
2018-06-21 12:58:34 -07:00
David Anderson
bac58aeecf libdm: Implement zero and linear targets.
This change implements DmTargetZero and DmTargetLinear, and integrates
them into dmctl. It also implements DmTarget and DmTable serialization.

Example dmctl invocation:

  dmctl create my-device -ro \
        linear 0 800 /dev/block/by-name/system 0 \
        zero   800 1200                          \
        linear 1200 1500 /dev/block/by-name/system 1200

Bug: 110035986
Test: libdm_test gtest
Change-Id: I7f945c1d9e23cfb78239c23a1aad88e8aef4972b
2018-06-21 12:48:34 -07:00
David Anderson
c7def6849a libdm: Add DmTargetTypeInfo and a unit test.
This change refactors DmTarget. It was satisfying two separate use cases
that have no overlap: (1) as a container for informational queries, and
(2) for specifying table targets.

The kernel's nomenclature for the former is a "target type," so the new
class is named DmTargetTypeInfo.

In addition, this change adds a unit test for
DeviceMapper::GetAvailableTargets that ensures the device has at least a
linear target type (with more TBD).

Bug: 110035986
Test: libdm_test gtest
Change-Id: Icb87976801e8a1e6ec79e48b1d58c308d36279e5
2018-06-21 12:48:34 -07:00
David Anderson
a93fdcb061 Merge "libdm: Implement LoadTableAndActivate."
am: 2e98fd23c3

Change-Id: I2fe21372eecc8d4568fa8a6cdf4f93c46c271c28
2018-06-21 12:16:49 -07:00
David Anderson
540ad62834 Merge "libdm: Move includes to a libdm folder."
am: bdc56b046e

Change-Id: Ibd1e51d03302bdf7d0a35dcf43ba1d09b799c96e
2018-06-21 12:16:16 -07:00
Treehugger Robot
2e98fd23c3 Merge "libdm: Implement LoadTableAndActivate." 2018-06-21 19:01:49 +00:00
Treehugger Robot
bdc56b046e Merge "libdm: Move includes to a libdm folder." 2018-06-21 19:01:20 +00:00
David Anderson
e1c0744c26 libdm: Implement LoadTableAndActivate.
This change implements DeviceMapper::LoadTableAndActivate by serializing
the given DmTable and issuing DM_TABLE_LOAD and DM_DEV_SUSPEND ioctls.
In addition, this makes the CreateDevice() method private, and
introduces a separate method for creating a device and loading a table
as a single operation. This will obviate the need for separate inactive
device cleanup logic later.

Note that this change does not yet implement DmTable::Serialize().

Bug: 110035986
Test: N/A
Change-Id: Ic8affe591db4930ce672b00db989978b57ca8cbf
2018-06-20 15:16:05 -07:00
David Anderson
b1a834ec31 libdm: Move includes to a libdm folder.
This places libdm includes into a libdm folder, to match how many other
library includes are organized.

Bug: 110035986
Test: N/A
Change-Id: I430b0cf749c8d16265481864f1f33927fd740a53
2018-06-20 15:16:04 -07:00
David Anderson
1e411be840 Merge "libdm: Clean up error messages and dm_ioctl use."
am: 9a2891c84b

Change-Id: I122084c2652b2a1924f0de5a225be186959c8d6e
2018-06-20 14:56:05 -07:00
Treehugger Robot
9a2891c84b Merge "libdm: Clean up error messages and dm_ioctl use." 2018-06-20 21:48:13 +00:00
David Anderson
b6181e3e46 libdm: Clean up error messages and dm_ioctl use.
This change removes unnecessary malloc() calls for dm_ioctls. It also
simplifies and fixes line endings on some error messages.

Bug: 110035986
Test: N/A
Change-Id: I2f56e5dab7f25cd9b2f80896f80101db56228981
2018-06-19 18:15:14 -07:00
David Anderson
39d0c5bef4 Merge "init: Create logical partitions via liblp."
am: 08839ff904

Change-Id: I8630d57e48a3016173a43b6dbd68ab974e6d5e01
2018-06-19 18:14:39 -07:00
David Anderson
041661fd86 Merge "fs_mgr: Add a library for managing logical partitions."
am: c86d3110be

Change-Id: I91af63bcb6e66fc2408d64d81e5125a73932f280
2018-06-19 16:35:09 -07:00
David Anderson
6590df2763 init: Create logical partitions via liblp.
Currently, init can create logical partitions by hardcoding them in
fs_mgr or by specifying them in device-tree. This change allows init to
also create logical partitions by using liblp, which stores partition
tables in a physical partition. The current name for this partition is
"android".

Two aspects of this code will change long-term. One, the prototype code
using device-tree will be deleted once fastboot supports logical
partitions. Two, libdm will obsolete most of the code in
fs_mgr_dm_linear.cpp. For now however we preserve how the prototype code
functions and we layer liblp on top of the existing dm_linear logic.

Bug: 79173901
Test: N/A
Change-Id: If014a109da78fa12269bf0df0dda39028ac2d1aa
2018-06-19 14:03:58 -07:00
David Anderson
ea3b8ac9ff fs_mgr: Add a library for managing logical partitions.
This library has methods to build, read, and modify logical partition tables
based on device-mapper targets. Targets currently supported are
dm-linear and dm-zero.

Note: this is a revert of a revert, with changes to fix Mac build
bustage.

Bug: 79173901
Test: N/A
Change-Id: If89a788d1919ce8ddc6eedaecc9687a92f111dfa
2018-06-19 14:03:57 -07:00
David Anderson
d953cdfdb2 Merge "Revert "fs_mgr: Add a library for managing logical partitions.""
am: b9a2243eb3

Change-Id: I5ab1ffd38354e1f54c85b3939c32217858667a77
2018-06-18 14:38:19 -07:00
David Anderson
89a1dca721 Revert "fs_mgr: Add a library for managing logical partitions."
This reverts commit e238358b76.

Reason for revert: Broke mac build.

Change-Id: I93390aa839d4471f328529fe5b86a498b3583d8a
2018-06-18 21:13:24 +00:00
David Anderson
12985226aa Merge "fs_mgr: Add a library for managing logical partitions."
am: 169aa989e3

Change-Id: Ifd7ce5750f41bb08262789815901f076aeb754fc
2018-06-18 12:17:43 -07:00
David Anderson
e238358b76 fs_mgr: Add a library for managing logical partitions.
This library has methods to build, read, and modify logical partition tables
based on device-mapper targets. Targets currently supported are
dm-linear and dm-zero.

Bug: 79173901
Test: N/A
Change-Id: I194c6832cb53f781c396016d961386d3ca833f87
2018-06-14 17:17:23 -07:00
Sandeep Patil
55be2b0c6c Merge "fs_mgr: dmctl: fix 'dmctl help' output"
am: 445eacd326

Change-Id: Iad17be9dce47a3e809e999ea41522bce102e1c57
2018-06-14 09:21:23 -07:00
Sandeep Patil
d34d0ef50e fs_mgr: dmctl: fix 'dmctl help' output
Test: adb shell dmctl help
Bug: 110035986

Change-Id: I5764b0b5f707dff03e715f975e54cdc2fd8fd437
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-06-13 18:38:59 -07:00
Sandeep Patil
ee888fe1d3 Merge changes from topic "libdm"
am: b066bbebd1

Change-Id: I2e7c1c71c9c7e25797a79702ceeafe756f457d26
2018-06-13 16:41:51 -07:00
Treehugger Robot
b066bbebd1 Merge changes from topic "libdm"
* changes:
  fs_mgr: libdm: Add support to list existing device mapper devices
  fs_mgr: libdm: add support to create and delete device mapper devices.
  fs_mgr: device mapper: Add libdm and 'dmctl' tool to use it.
2018-06-13 22:45:30 +00:00
Sandeep Patil
f603cfdd70 fs_mgr: libdm: Add support to list existing device mapper devices
Test: dmctl create system; dmctl list devices; dmctl delete system;
      dmctl list devices
Bug: 110035986

Change-Id: I4ae5d40041458421068976fa2a99c662c542a9a1
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-06-13 13:50:21 -07:00