payload_generator: Remove PartitionName enum.
payload_generator should be able to generate payload for any partition name
in major version 2, so we should use a string for partition name.
Bug: 23620828
TEST=cros_workon_make update_engine --test
Change-Id: Iee92af5d82e74b9be6ae793850a4ae6c31e008c5
diff --git a/payload_generator/ab_generator.cc b/payload_generator/ab_generator.cc
index 459b3b9..065408b 100644
--- a/payload_generator/ab_generator.cc
+++ b/payload_generator/ab_generator.cc
@@ -38,6 +38,7 @@
const PartitionConfig& new_part,
BlobFileWriter* blob_file,
vector<AnnotatedOperation>* aops) {
+ TEST_AND_RETURN_FALSE(old_part.name == new_part.name);
ssize_t hard_chunk_blocks = (config.hard_chunk_size == -1 ? -1 :
config.hard_chunk_size / config.block_size);
@@ -52,7 +53,7 @@
soft_chunk_blocks,
blob_file,
true)); // src_ops_allowed
- LOG(INFO) << "done reading " << PartitionNameString(new_part.name);
+ LOG(INFO) << "done reading " << new_part.name;
TEST_AND_RETURN_FALSE(FragmentOperations(aops,
new_part.path,
diff --git a/payload_generator/delta_diff_utils_unittest.cc b/payload_generator/delta_diff_utils_unittest.cc
index 4d81632..6b23197 100644
--- a/payload_generator/delta_diff_utils_unittest.cc
+++ b/payload_generator/delta_diff_utils_unittest.cc
@@ -143,8 +143,8 @@
// Old and new temporary partitions used in the tests. These are initialized
// with
- PartitionConfig old_part_{PartitionName::kRootfs};
- PartitionConfig new_part_{PartitionName::kRootfs};
+ PartitionConfig old_part_{"part"};
+ PartitionConfig new_part_{"part"};
// The file holding the output blob from the various diff utils functions.
string blob_path_;
diff --git a/payload_generator/full_update_generator.cc b/payload_generator/full_update_generator.cc
index 101f28a..7ece2ad 100644
--- a/payload_generator/full_update_generator.cc
+++ b/payload_generator/full_update_generator.cc
@@ -146,7 +146,7 @@
size_t chunk_blocks = full_chunk_size / config.block_size;
size_t max_threads = std::max(sysconf(_SC_NPROCESSORS_ONLN), 4L);
- LOG(INFO) << "Compressing partition " << PartitionNameString(new_part.name)
+ LOG(INFO) << "Compressing partition " << new_part.name
<< " from " << new_part.path << " splitting in chunks of "
<< chunk_blocks << " blocks (" << config.block_size
<< " bytes each) using " << max_threads << " threads";
@@ -164,8 +164,6 @@
chunk_processors.reserve(num_chunks);
blob_file->SetTotalBlobs(num_chunks);
- const string part_name_str = PartitionNameString(new_part.name);
-
for (size_t i = 0; i < num_chunks; ++i) {
size_t start_block = i * chunk_blocks;
// The last chunk could be smaller.
@@ -176,7 +174,7 @@
// ChunkProcessor will set the rest.
AnnotatedOperation* aop = aops->data() + i;
aop->name = base::StringPrintf("<%s-operation-%" PRIuS ">",
- part_name_str.c_str(), i);
+ new_part.name.c_str(), i);
Extent* dst_extent = aop->op.add_dst_extents();
dst_extent->set_start_block(start_block);
dst_extent->set_num_blocks(num_blocks);
diff --git a/payload_generator/full_update_generator_unittest.cc b/payload_generator/full_update_generator_unittest.cc
index ac37158..2f39126 100644
--- a/payload_generator/full_update_generator_unittest.cc
+++ b/payload_generator/full_update_generator_unittest.cc
@@ -52,7 +52,7 @@
}
PayloadGenerationConfig config_;
- PartitionConfig new_part_conf{PartitionName::kRootfs};
+ PartitionConfig new_part_conf{"part"};
vector<AnnotatedOperation> aops;
diff --git a/payload_generator/inplace_generator.cc b/payload_generator/inplace_generator.cc
index 9d108bd..0cfbe02 100644
--- a/payload_generator/inplace_generator.cc
+++ b/payload_generator/inplace_generator.cc
@@ -790,15 +790,16 @@
const PartitionConfig& new_part,
BlobFileWriter* blob_file,
vector<AnnotatedOperation>* aops) {
+ TEST_AND_RETURN_FALSE(old_part.name == new_part.name);
+
ssize_t hard_chunk_blocks = (config.hard_chunk_size == -1 ? -1 :
config.hard_chunk_size / config.block_size);
size_t soft_chunk_blocks = config.soft_chunk_size / config.block_size;
uint64_t partition_size = new_part.size;
- if (new_part.name == PartitionName::kRootfs)
+ if (new_part.name == kLegacyPartitionNameRoot)
partition_size = config.rootfs_partition_size;
- const string part_name = PartitionNameString(new_part.name);
- LOG(INFO) << "Delta compressing " << part_name << " partition...";
+ LOG(INFO) << "Delta compressing " << new_part.name << " partition...";
TEST_AND_RETURN_FALSE(
diff_utils::DeltaReadPartition(aops,
old_part,
@@ -807,7 +808,7 @@
soft_chunk_blocks,
blob_file,
false)); // src_ops_allowed
- LOG(INFO) << "Done reading " << part_name;
+ LOG(INFO) << "Done reading " << new_part.name;
TEST_AND_RETURN_FALSE(
ResolveReadAfterWriteDependencies(new_part,
@@ -815,7 +816,7 @@
config.block_size,
blob_file,
aops));
- LOG(INFO) << "Done reordering " << part_name;
+ LOG(INFO) << "Done reordering " << new_part.name;
return true;
}
diff --git a/payload_generator/inplace_generator_unittest.cc b/payload_generator/inplace_generator_unittest.cc
index 1cc20cf..d6430c8 100644
--- a/payload_generator/inplace_generator_unittest.cc
+++ b/payload_generator/inplace_generator_unittest.cc
@@ -608,7 +608,7 @@
aops.push_back(aop);
}
- PartitionConfig part(PartitionName::kRootfs);
+ PartitionConfig part("part");
part.path = "/dev/zero";
part.size = num_blocks * block_size;
diff --git a/payload_generator/payload_generation_config.cc b/payload_generator/payload_generation_config.cc
index ecf9627..a2d9311 100644
--- a/payload_generator/payload_generation_config.cc
+++ b/payload_generator/payload_generation_config.cc
@@ -26,16 +26,6 @@
namespace chromeos_update_engine {
-std::string PartitionNameString(PartitionName name) {
- switch (name) {
- case PartitionName::kKernel:
- return "kernel";
- case PartitionName::kRootfs:
- return "rootfs";
- }
- return "other";
-}
-
bool PartitionConfig::ValidateExists() const {
TEST_AND_RETURN_FALSE(!path.empty());
TEST_AND_RETURN_FALSE(utils::FileExists(path.c_str()));
@@ -50,7 +40,7 @@
if (path.empty())
return true;
fs_interface.reset();
- if (name == PartitionName::kRootfs) {
+ if (utils::IsExtFilesystem(path)) {
fs_interface = Ext2Filesystem::CreateFromFile(path);
}
@@ -58,7 +48,7 @@
// Fall back to a RAW filesystem.
TEST_AND_RETURN_FALSE(size % kBlockSize == 0);
fs_interface = RawFilesystem::Create(
- "<" + PartitionNameString(name) + "-partition>",
+ "<" + name + "-partition>",
kBlockSize,
size / kBlockSize);
}
diff --git a/payload_generator/payload_generation_config.h b/payload_generator/payload_generation_config.h
index 4e99688..b7bd484 100644
--- a/payload_generator/payload_generation_config.h
+++ b/payload_generator/payload_generation_config.h
@@ -23,22 +23,14 @@
#include <string>
#include <vector>
+#include "update_engine/payload_constants.h"
#include "update_engine/payload_generator/filesystem_interface.h"
#include "update_engine/update_metadata.pb.h"
namespace chromeos_update_engine {
-// The list different kind of partitions supported by the updater.
-enum class PartitionName {
- kKernel,
- kRootfs,
-};
-
-// Return a string name for the PartitionName.
-std::string PartitionNameString(PartitionName name);
-
struct PartitionConfig {
- explicit PartitionConfig(PartitionName name) : name(name) {}
+ explicit PartitionConfig(std::string name) : name(name) {}
// Returns whether the PartitionConfig is not an empty image and all the
// fields are set correctly to a valid image file.
@@ -64,7 +56,7 @@
// files.
std::unique_ptr<FilesystemInterface> fs_interface;
- PartitionName name;
+ std::string name;
};
// The ImageConfig struct describes a pair of binaries kernel and rootfs and the
@@ -88,8 +80,8 @@
ImageInfo image_info;
// The updated partitions.
- PartitionConfig rootfs = PartitionConfig{PartitionName::kRootfs};
- PartitionConfig kernel = PartitionConfig{PartitionName::kKernel};
+ PartitionConfig rootfs = PartitionConfig{kLegacyPartitionNameRoot};
+ PartitionConfig kernel = PartitionConfig{kLegacyPartitionNameKernel};
};
// The PayloadGenerationConfig struct encapsulates all the configuration to