Commit d26a9559 authored by Yusuke Sato's avatar Yusuke Sato Committed by Commit Bot

arcvm: Expand property files

With this CL, ArcVmClientAdapter copies two prop files in
/usr/share/arcvm to /run/arcvm/host_generated with or without
modifications (depending on whether the board is unibuild)
before asking vm_concierge to start ARCVM.

BUG=b:123309049
TEST=try, verify manually on coral, verify chrome can run
 cros_region_data command.

Change-Id: Ic04676f3fc07fea8bb5b4a61525206151cd6d5e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1906471Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Commit-Queue: Yusuke Sato <yusukes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714332}
parent 0fa0143f
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "components/arc/arc_features.h" #include "components/arc/arc_features.h"
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
#include "components/arc/session/arc_session.h" #include "components/arc/session/arc_session.h"
#include "components/arc/session/arc_vm_client_adapter_util.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
namespace arc { namespace arc {
...@@ -52,8 +53,11 @@ constexpr const char kBuiltinPath[] = "/opt/google/vms/android"; ...@@ -52,8 +53,11 @@ constexpr const char kBuiltinPath[] = "/opt/google/vms/android";
constexpr const char kCrosSystemPath[] = "/usr/bin/crossystem"; constexpr const char kCrosSystemPath[] = "/usr/bin/crossystem";
constexpr const char kDlcPath[] = "/run/imageloader/arcvm-dlc/package/root"; constexpr const char kDlcPath[] = "/run/imageloader/arcvm-dlc/package/root";
constexpr const char kFstab[] = "fstab"; constexpr const char kFstab[] = "fstab";
constexpr const char kGeneratedPropertyFilesPath[] =
"/run/arcvm/host_generated";
constexpr const char kHomeDirectory[] = "/home"; constexpr const char kHomeDirectory[] = "/home";
constexpr const char kKernel[] = "vmlinux"; constexpr const char kKernel[] = "vmlinux";
constexpr const char kPropertyFilesPath[] = "/usr/share/arcvm/properties";
constexpr const char kRootFs[] = "system.raw.img"; constexpr const char kRootFs[] = "system.raw.img";
constexpr const char kVendorImage[] = "vendor.raw.img"; constexpr const char kVendorImage[] = "vendor.raw.img";
...@@ -72,6 +76,7 @@ class FileSystemStatus { ...@@ -72,6 +76,7 @@ class FileSystemStatus {
const base::FilePath& vendor_image_path() const { return vendor_image_path_; } const base::FilePath& vendor_image_path() const { return vendor_image_path_; }
const base::FilePath& guest_kernel_path() const { return guest_kernel_path_; } const base::FilePath& guest_kernel_path() const { return guest_kernel_path_; }
const base::FilePath& fstab_path() const { return fstab_path_; } const base::FilePath& fstab_path() const { return fstab_path_; }
bool property_files_expanded() const { return property_files_expanded_; }
static FileSystemStatus GetFileSystemStatusBlocking() { static FileSystemStatus GetFileSystemStatusBlocking() {
return FileSystemStatus(); return FileSystemStatus();
...@@ -79,6 +84,10 @@ class FileSystemStatus { ...@@ -79,6 +84,10 @@ class FileSystemStatus {
static bool IsAndroidDebuggableForTesting(const base::FilePath& json_path) { static bool IsAndroidDebuggableForTesting(const base::FilePath& json_path) {
return IsAndroidDebuggable(json_path); return IsAndroidDebuggable(json_path);
} }
static bool ExpandPropertyFilesForTesting(const base::FilePath& source_path,
const base::FilePath& dest_path) {
return ExpandPropertyFiles(source_path, dest_path);
}
private: private:
FileSystemStatus() FileSystemStatus()
...@@ -88,7 +97,10 @@ class FileSystemStatus { ...@@ -88,7 +97,10 @@ class FileSystemStatus {
system_image_path_(SelectDlcOrBuiltin(base::FilePath(kRootFs))), system_image_path_(SelectDlcOrBuiltin(base::FilePath(kRootFs))),
vendor_image_path_(SelectDlcOrBuiltin(base::FilePath(kVendorImage))), vendor_image_path_(SelectDlcOrBuiltin(base::FilePath(kVendorImage))),
guest_kernel_path_(SelectDlcOrBuiltin(base::FilePath(kKernel))), guest_kernel_path_(SelectDlcOrBuiltin(base::FilePath(kKernel))),
fstab_path_(SelectDlcOrBuiltin(base::FilePath(kFstab))) {} fstab_path_(SelectDlcOrBuiltin(base::FilePath(kFstab))),
property_files_expanded_(
ExpandPropertyFiles(base::FilePath(kPropertyFilesPath),
base::FilePath(kGeneratedPropertyFilesPath))) {}
// Parse a JSON file which is like the following and returns a result: // Parse a JSON file which is like the following and returns a result:
// { // {
...@@ -148,12 +160,29 @@ class FileSystemStatus { ...@@ -148,12 +160,29 @@ class FileSystemStatus {
return base::FilePath(kBuiltinPath).Append(file); return base::FilePath(kBuiltinPath).Append(file);
} }
// Copies two prop files in /usr/share/arcvm to /run/arcvm/host_generated with
// or without modifications (depending on whether the board is unibuild).
// Returns true if the copy is successful.
static bool ExpandPropertyFiles(const base::FilePath& source_path,
const base::FilePath& dest_path) {
CrosConfig config;
for (const char* file : {"default.prop", "build.prop"}) {
if (!ExpandPropertyFile(source_path.Append(file), dest_path.Append(file),
&config)) {
LOG(ERROR) << "Failed to expand " << source_path.Append(file);
return false;
}
}
return true;
}
bool is_android_debuggable_; bool is_android_debuggable_;
bool is_host_rootfs_writable_; bool is_host_rootfs_writable_;
base::FilePath system_image_path_; base::FilePath system_image_path_;
base::FilePath vendor_image_path_; base::FilePath vendor_image_path_;
base::FilePath guest_kernel_path_; base::FilePath guest_kernel_path_;
base::FilePath fstab_path_; base::FilePath fstab_path_;
bool property_files_expanded_;
DISALLOW_COPY_AND_ASSIGN(FileSystemStatus); DISALLOW_COPY_AND_ASSIGN(FileSystemStatus);
}; };
...@@ -557,6 +586,11 @@ class ArcVmClientAdapter : public ArcClientAdapter, ...@@ -557,6 +586,11 @@ class ArcVmClientAdapter : public ArcClientAdapter,
const base::FilePath& data_disk_path, const base::FilePath& data_disk_path,
FileSystemStatus file_system_status) { FileSystemStatus file_system_status) {
VLOG(2) << "Got file system status"; VLOG(2) << "Got file system status";
if (!file_system_status.property_files_expanded()) {
// TODO(yusukes): Once build_image and push_to_device.py are updated, run
// the |callback| with false here and return.
}
if (serial_number_.empty()) { if (serial_number_.empty()) {
LOG(ERROR) << "Serial number is not set"; LOG(ERROR) << "Serial number is not set";
std::move(callback).Run(false); std::move(callback).Run(false);
...@@ -667,4 +701,10 @@ bool IsAndroidDebuggableForTesting(const base::FilePath& json_path) { ...@@ -667,4 +701,10 @@ bool IsAndroidDebuggableForTesting(const base::FilePath& json_path) {
return FileSystemStatus::IsAndroidDebuggableForTesting(json_path); return FileSystemStatus::IsAndroidDebuggableForTesting(json_path);
} }
bool ExpandPropertyFilesForTesting(const base::FilePath& source_path,
const base::FilePath& dest_path) {
return FileSystemStatus::ExpandPropertyFilesForTesting(source_path,
dest_path);
}
} // namespace arc } // namespace arc
...@@ -22,6 +22,8 @@ std::unique_ptr<ArcClientAdapter> CreateArcVmClientAdapter( ...@@ -22,6 +22,8 @@ std::unique_ptr<ArcClientAdapter> CreateArcVmClientAdapter(
// Function(s) below are for testing. // Function(s) below are for testing.
bool IsAndroidDebuggableForTesting(const base::FilePath& json_path); bool IsAndroidDebuggableForTesting(const base::FilePath& json_path);
bool ExpandPropertyFilesForTesting(const base::FilePath& source_path,
const base::FilePath& dest_path);
} // namespace arc } // namespace arc
......
...@@ -681,5 +681,47 @@ TEST_F(ArcVmClientAdapterTest, IsAndroidDebuggable_CannotRead) { ...@@ -681,5 +681,47 @@ TEST_F(ArcVmClientAdapterTest, IsAndroidDebuggable_CannotRead) {
EXPECT_FALSE(IsAndroidDebuggableForTesting(path)); EXPECT_FALSE(IsAndroidDebuggableForTesting(path));
} }
TEST_F(ArcVmClientAdapterTest, ExpandPropertyFilesForTesting_NoSource) {
// Both source and dest are not found.
EXPECT_FALSE(ExpandPropertyFilesForTesting(base::FilePath("/nonexistent1"),
base::FilePath("/nonexistent2")));
// Both source and dest exist, but the source directory is empty.
base::FilePath source_dir;
ASSERT_TRUE(base::CreateTemporaryDirInDir(GetTempDir(), "test", &source_dir));
base::FilePath dest_dir;
ASSERT_TRUE(base::CreateTemporaryDirInDir(GetTempDir(), "test", &dest_dir));
EXPECT_FALSE(ExpandPropertyFilesForTesting(source_dir, dest_dir));
// Add default.prop to the source, but not build.prop.
base::FilePath default_prop = source_dir.Append("default.prop");
constexpr const char kDefaultProp[] = "ro.foo=bar\n";
base::WriteFile(default_prop, kDefaultProp, strlen(kDefaultProp));
EXPECT_FALSE(ExpandPropertyFilesForTesting(source_dir, dest_dir));
// Add build.prop too. Then the call should succeed.
base::FilePath build_prop = source_dir.Append("build.prop");
constexpr const char kBuildProp[] = "ro.baz=boo\n";
base::WriteFile(build_prop, kBuildProp, strlen(kBuildProp));
EXPECT_TRUE(ExpandPropertyFilesForTesting(source_dir, dest_dir));
// Verify two dest files are there.
EXPECT_TRUE(base::PathExists(dest_dir.Append("default.prop")));
EXPECT_TRUE(base::PathExists(dest_dir.Append("build.prop")));
// Verify their content.
// Note: ExpandPropertyFile() adds a trailing LF.
std::string content;
EXPECT_TRUE(
base::ReadFileToString(dest_dir.Append("default.prop"), &content));
EXPECT_EQ(std::string(kDefaultProp) + "\n", content);
EXPECT_TRUE(base::ReadFileToString(dest_dir.Append("build.prop"), &content));
EXPECT_EQ(std::string(kBuildProp) + "\n", content);
// Finally, test the case where source is valid but the dest is not.
EXPECT_FALSE(ExpandPropertyFilesForTesting(source_dir,
base::FilePath("/nonexistent")));
}
} // namespace } // namespace
} // namespace arc } // namespace arc
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment