summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-prod (mdb)2018-05-07 15:59:40 -0500
committerGerrit Code Review2018-05-07 15:59:40 -0500
commita6a266af0038c13dfc8fd55bc4c902a60952fb24 (patch)
tree195beb3385382b249930381037c1674b169e25b0
parent035a1c7a0b08c09a8738053a00515d2307d2ea28 (diff)
parent0b8e22eb5fe849cdc7f62f8b9e428a7f5880ec48 (diff)
downloadplatform-system-core-android-p-preview-2.tar.gz
platform-system-core-android-p-preview-2.tar.xz
platform-system-core-android-p-preview-2.zip
Merge "fs_mgr: target-agnostic device-mapper helpers"android-p-preview-3android-p-preview-2
-rw-r--r--fs_mgr/fs_mgr.cpp2
-rw-r--r--fs_mgr/fs_mgr_avb.cpp8
-rw-r--r--fs_mgr/fs_mgr_dm_ioctl.cpp28
-rw-r--r--fs_mgr/fs_mgr_priv_dm_ioctl.h12
-rw-r--r--fs_mgr/fs_mgr_verity.cpp10
5 files changed, 30 insertions, 30 deletions
diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp
index 6769fda67..e9040dfe8 100644
--- a/fs_mgr/fs_mgr.cpp
+++ b/fs_mgr/fs_mgr.cpp
@@ -1383,7 +1383,7 @@ bool fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback) {
1383 mount_point = basename(fstab->recs[i].mount_point); 1383 mount_point = basename(fstab->recs[i].mount_point);
1384 } 1384 }
1385 1385
1386 fs_mgr_verity_ioctl_init(io, mount_point); 1386 fs_mgr_dm_ioctl_init(io, DM_BUF_SIZE, mount_point);
1387 1387
1388 const char* status; 1388 const char* status;
1389 if (ioctl(fd, DM_TABLE_STATUS, io)) { 1389 if (ioctl(fd, DM_TABLE_STATUS, io)) {
diff --git a/fs_mgr/fs_mgr_avb.cpp b/fs_mgr/fs_mgr_avb.cpp
index 6ea38335e..cf6b49702 100644
--- a/fs_mgr/fs_mgr_avb.cpp
+++ b/fs_mgr/fs_mgr_avb.cpp
@@ -303,7 +303,7 @@ static std::string construct_verity_table(const AvbHashtreeDescriptor& hashtree_
303 303
304static bool load_verity_table(struct dm_ioctl* io, const std::string& dm_device_name, int fd, 304static bool load_verity_table(struct dm_ioctl* io, const std::string& dm_device_name, int fd,
305 uint64_t image_size, const std::string& verity_table) { 305 uint64_t image_size, const std::string& verity_table) {
306 fs_mgr_verity_ioctl_init(io, dm_device_name); 306 fs_mgr_dm_ioctl_init(io, DM_BUF_SIZE, dm_device_name);
307 307
308 // The buffer consists of [dm_ioctl][dm_target_spec][verity_params]. 308 // The buffer consists of [dm_ioctl][dm_target_spec][verity_params].
309 char* buffer = (char*)io; 309 char* buffer = (char*)io;
@@ -360,14 +360,14 @@ static bool hashtree_dm_verity_setup(struct fstab_rec* fstab_entry,
360 alignas(dm_ioctl) char buffer[DM_BUF_SIZE]; 360 alignas(dm_ioctl) char buffer[DM_BUF_SIZE];
361 struct dm_ioctl* io = (struct dm_ioctl*)buffer; 361 struct dm_ioctl* io = (struct dm_ioctl*)buffer;
362 const std::string mount_point(basename(fstab_entry->mount_point)); 362 const std::string mount_point(basename(fstab_entry->mount_point));
363 if (!fs_mgr_create_verity_device(io, mount_point, fd)) { 363 if (!fs_mgr_dm_create_device(io, mount_point, fd)) {
364 LERROR << "Couldn't create verity device!"; 364 LERROR << "Couldn't create verity device!";
365 return false; 365 return false;
366 } 366 }
367 367
368 // Gets the name of the device file. 368 // Gets the name of the device file.
369 std::string verity_blk_name; 369 std::string verity_blk_name;
370 if (!fs_mgr_get_verity_device_name(io, mount_point, fd, &verity_blk_name)) { 370 if (!fs_mgr_dm_get_device_name(io, mount_point, fd, &verity_blk_name)) {
371 LERROR << "Couldn't get verity device number!"; 371 LERROR << "Couldn't get verity device number!";
372 return false; 372 return false;
373 } 373 }
@@ -386,7 +386,7 @@ static bool hashtree_dm_verity_setup(struct fstab_rec* fstab_entry,
386 } 386 }
387 387
388 // Activates the device. 388 // Activates the device.
389 if (!fs_mgr_resume_verity_table(io, mount_point, fd)) { 389 if (!fs_mgr_dm_resume_table(io, mount_point, fd)) {
390 return false; 390 return false;
391 } 391 }
392 392
diff --git a/fs_mgr/fs_mgr_dm_ioctl.cpp b/fs_mgr/fs_mgr_dm_ioctl.cpp
index 5f9b11868..3a7fae42e 100644
--- a/fs_mgr/fs_mgr_dm_ioctl.cpp
+++ b/fs_mgr/fs_mgr_dm_ioctl.cpp
@@ -23,9 +23,9 @@
23#include "fs_mgr_priv.h" 23#include "fs_mgr_priv.h"
24#include "fs_mgr_priv_dm_ioctl.h" 24#include "fs_mgr_priv_dm_ioctl.h"
25 25
26void fs_mgr_verity_ioctl_init(struct dm_ioctl* io, const std::string& name) { 26void fs_mgr_dm_ioctl_init(struct dm_ioctl* io, size_t size, const std::string& name) {
27 memset(io, 0, DM_BUF_SIZE); 27 memset(io, 0, size);
28 io->data_size = DM_BUF_SIZE; 28 io->data_size = size;
29 io->data_start = sizeof(struct dm_ioctl); 29 io->data_start = sizeof(struct dm_ioctl);
30 io->version[0] = 4; 30 io->version[0] = 4;
31 io->version[1] = 0; 31 io->version[1] = 0;
@@ -35,8 +35,8 @@ void fs_mgr_verity_ioctl_init(struct dm_ioctl* io, const std::string& name) {
35 } 35 }
36} 36}
37 37
38bool fs_mgr_create_verity_device(struct dm_ioctl* io, const std::string& name, int fd) { 38bool fs_mgr_dm_create_device(struct dm_ioctl* io, const std::string& name, int fd) {
39 fs_mgr_verity_ioctl_init(io, name); 39 fs_mgr_dm_ioctl_init(io, sizeof(*io), name);
40 if (ioctl(fd, DM_DEV_CREATE, io)) { 40 if (ioctl(fd, DM_DEV_CREATE, io)) {
41 PERROR << "Error creating device mapping"; 41 PERROR << "Error creating device mapping";
42 return false; 42 return false;
@@ -44,8 +44,8 @@ bool fs_mgr_create_verity_device(struct dm_ioctl* io, const std::string& name, i
44 return true; 44 return true;
45} 45}
46 46
47bool fs_mgr_destroy_verity_device(struct dm_ioctl* io, const std::string& name, int fd) { 47bool fs_mgr_dm_destroy_device(struct dm_ioctl* io, const std::string& name, int fd) {
48 fs_mgr_verity_ioctl_init(io, name); 48 fs_mgr_dm_ioctl_init(io, sizeof(*io), name);
49 if (ioctl(fd, DM_DEV_REMOVE, io)) { 49 if (ioctl(fd, DM_DEV_REMOVE, io)) {
50 PERROR << "Error removing device mapping"; 50 PERROR << "Error removing device mapping";
51 return false; 51 return false;
@@ -53,13 +53,13 @@ bool fs_mgr_destroy_verity_device(struct dm_ioctl* io, const std::string& name,
53 return true; 53 return true;
54} 54}
55 55
56bool fs_mgr_get_verity_device_name(struct dm_ioctl* io, const std::string& name, int fd, 56bool fs_mgr_dm_get_device_name(struct dm_ioctl* io, const std::string& name, int fd,
57 std::string* out_dev_name) { 57 std::string* out_dev_name) {
58 FS_MGR_CHECK(out_dev_name != nullptr); 58 FS_MGR_CHECK(out_dev_name != nullptr);
59 59
60 fs_mgr_verity_ioctl_init(io, name); 60 fs_mgr_dm_ioctl_init(io, sizeof(*io), name);
61 if (ioctl(fd, DM_DEV_STATUS, io)) { 61 if (ioctl(fd, DM_DEV_STATUS, io)) {
62 PERROR << "Error fetching verity device number"; 62 PERROR << "Error fetching device-mapper device number";
63 return false; 63 return false;
64 } 64 }
65 65
@@ -69,10 +69,10 @@ bool fs_mgr_get_verity_device_name(struct dm_ioctl* io, const std::string& name,
69 return true; 69 return true;
70} 70}
71 71
72bool fs_mgr_resume_verity_table(struct dm_ioctl* io, const std::string& name, int fd) { 72bool fs_mgr_dm_resume_table(struct dm_ioctl* io, const std::string& name, int fd) {
73 fs_mgr_verity_ioctl_init(io, name); 73 fs_mgr_dm_ioctl_init(io, sizeof(*io), name);
74 if (ioctl(fd, DM_DEV_SUSPEND, io)) { 74 if (ioctl(fd, DM_DEV_SUSPEND, io)) {
75 PERROR << "Error activating verity device"; 75 PERROR << "Error activating device table";
76 return false; 76 return false;
77 } 77 }
78 return true; 78 return true;
diff --git a/fs_mgr/fs_mgr_priv_dm_ioctl.h b/fs_mgr/fs_mgr_priv_dm_ioctl.h
index 792683eca..792475df7 100644
--- a/fs_mgr/fs_mgr_priv_dm_ioctl.h
+++ b/fs_mgr/fs_mgr_priv_dm_ioctl.h
@@ -20,15 +20,15 @@
20#include <linux/dm-ioctl.h> 20#include <linux/dm-ioctl.h>
21#include <string> 21#include <string>
22 22
23void fs_mgr_verity_ioctl_init(struct dm_ioctl* io, const std::string& name); 23void fs_mgr_dm_ioctl_init(struct dm_ioctl* io, size_t size, const std::string& name);
24 24
25bool fs_mgr_create_verity_device(struct dm_ioctl* io, const std::string& name, int fd); 25bool fs_mgr_dm_create_device(struct dm_ioctl* io, const std::string& name, int fd);
26 26
27bool fs_mgr_destroy_verity_device(struct dm_ioctl* io, const std::string& name, int fd); 27bool fs_mgr_dm_destroy_device(struct dm_ioctl* io, const std::string& name, int fd);
28 28
29bool fs_mgr_get_verity_device_name(struct dm_ioctl* io, const std::string& name, int fd, 29bool fs_mgr_dm_get_device_name(struct dm_ioctl* io, const std::string& name, int fd,
30 std::string* out_dev_name); 30 std::string* out_dev_name);
31 31
32bool fs_mgr_resume_verity_table(struct dm_ioctl* io, const std::string& name, int fd); 32bool fs_mgr_dm_resume_table(struct dm_ioctl* io, const std::string& name, int fd);
33 33
34#endif /* __CORE_FS_MGR_PRIV_DM_IOCTL_H */ 34#endif /* __CORE_FS_MGR_PRIV_DM_IOCTL_H */
diff --git a/fs_mgr/fs_mgr_verity.cpp b/fs_mgr/fs_mgr_verity.cpp
index d0bb05826..fe41f8ac2 100644
--- a/fs_mgr/fs_mgr_verity.cpp
+++ b/fs_mgr/fs_mgr_verity.cpp
@@ -258,7 +258,7 @@ static int load_verity_table(struct dm_ioctl *io, const std::string &name,
258 char *buffer = (char*) io; 258 char *buffer = (char*) io;
259 size_t bufsize; 259 size_t bufsize;
260 260
261 fs_mgr_verity_ioctl_init(io, name); 261 fs_mgr_dm_ioctl_init(io, DM_BUF_SIZE, name);
262 262
263 struct dm_target_spec *tgt = (struct dm_target_spec *) &buffer[sizeof(struct dm_ioctl)]; 263 struct dm_target_spec *tgt = (struct dm_target_spec *) &buffer[sizeof(struct dm_ioctl)];
264 264
@@ -805,13 +805,13 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool wait_for_verity_dev)
805 } 805 }
806 806
807 // create the device 807 // create the device
808 if (!fs_mgr_create_verity_device(io, mount_point, fd)) { 808 if (!fs_mgr_dm_create_device(io, mount_point, fd)) {
809 LERROR << "Couldn't create verity device!"; 809 LERROR << "Couldn't create verity device!";
810 goto out; 810 goto out;
811 } 811 }
812 812
813 // get the name of the device file 813 // get the name of the device file
814 if (!fs_mgr_get_verity_device_name(io, mount_point, fd, &verity_blk_name)) { 814 if (!fs_mgr_dm_get_device_name(io, mount_point, fd, &verity_blk_name)) {
815 LERROR << "Couldn't get verity device number!"; 815 LERROR << "Couldn't get verity device number!";
816 goto out; 816 goto out;
817 } 817 }
@@ -900,7 +900,7 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool wait_for_verity_dev)
900loaded: 900loaded:
901 901
902 // activate the device 902 // activate the device
903 if (!fs_mgr_resume_verity_table(io, mount_point, fd)) { 903 if (!fs_mgr_dm_resume_table(io, mount_point, fd)) {
904 goto out; 904 goto out;
905 } 905 }
906 906
@@ -923,7 +923,7 @@ loaded:
923 if (!verified_at_boot) { 923 if (!verified_at_boot) {
924 free(fstab->blk_device); 924 free(fstab->blk_device);
925 fstab->blk_device = strdup(verity_blk_name.c_str()); 925 fstab->blk_device = strdup(verity_blk_name.c_str());
926 } else if (!fs_mgr_destroy_verity_device(io, mount_point, fd)) { 926 } else if (!fs_mgr_dm_destroy_device(io, mount_point, fd)) {
927 LERROR << "Failed to remove verity device " << mount_point.c_str(); 927 LERROR << "Failed to remove verity device " << mount_point.c_str();
928 goto out; 928 goto out;
929 } 929 }