Add alias and option to support migration
The main goal of the change is to allow us to change the name of the
blobId while making sure the existing data is still valid during the
migration. Added an alias option which allow us to have two possible
valid blobId and will use the `baseBlobId` to commit the data even if
the current data match the alish ID. This allow us to change the blobId
of the binary store without loosing the data.
Also added an option to revert back to the alias blobId with the
`blobtool` to support backward compatibility when we need to downgrade
to a version without alias support. Created the base service that gets
trigger to start the blob id revert.
Tested:
Tested backward compatibility and working fine. The blob data are not
lost between versions.
Change-Id: I75bcbce3aff20c6ee8a491bef36fac260595d6f7
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/src/blobtool.cpp b/src/blobtool.cpp
index 2f45aab..c1e2e65 100644
--- a/src/blobtool.cpp
+++ b/src/blobtool.cpp
@@ -23,6 +23,7 @@
HELP,
LIST,
READ,
+ MIGRATE,
} action = Action::LIST;
} toolConfig;
@@ -34,6 +35,8 @@
"\t--list\t\tList all supported blobs. This is a default.\n"
"\t--read\t\tRead blob specified in --blob argument (which "
"becomes mandatory).\n"
+ "\t--migrate\tUpdate all binary stores to use the alias "
+ "blob id if enabled.\n"
"\t--config\tFILENAME\tPath to the configuration file. The "
"default is /usr/share/binaryblob/config.json.\n"
"\t--binary-store\tFILENAME\tPath to the binary storage. If "
@@ -53,6 +56,7 @@
{"help", no_argument, 0, 'h'},
{"list", no_argument, 0, 'l'},
{"read", no_argument, 0, 'r'},
+ {"migrate", no_argument, 0, 'm'},
{"config", required_argument, 0, 'c'},
{"binary-store", required_argument, 0, 's'},
{"blob", required_argument, 0, 'b'},
@@ -61,7 +65,6 @@
};
int optionIndex = 0;
- std::string configPath = defaultBlobConfigPath;
bool res = true;
while (1)
{
@@ -81,6 +84,9 @@
case 'r':
cfg.action = BlobToolConfig::Action::READ;
break;
+ case 'm':
+ cfg.action = BlobToolConfig::Action::MIGRATE;
+ break;
case 'c':
cfg.configPath = optarg;
break;
@@ -170,11 +176,30 @@
config.sysFilePath, config.offsetBytes);
auto store = binstore::BinaryStore::createFromConfig(
- config.blobBaseId, std::move(file));
- stores.push_back(std::move(store));
+ config.blobBaseId, std::move(file), config.maxSizeBytes,
+ config.aliasBlobBaseId);
+
+ if (toolConfig.action == BlobToolConfig::Action::MIGRATE)
+ {
+ if (config.migrateToAlias && config.aliasBlobBaseId.has_value())
+ {
+ store->setBaseBlobId(config.aliasBlobBaseId.value());
+ }
+ }
+ else
+ {
+ stores.push_back(std::move(store));
+ }
}
}
+ if (toolConfig.action == BlobToolConfig::Action::MIGRATE)
+ {
+ stdplus::print(stderr,
+ "Migrated all BinaryStore back to configured Alias\n");
+ return 0;
+ }
+
if (toolConfig.action == BlobToolConfig::Action::LIST)
{
stdplus::print(stderr, "Supported Blobs: \n");
@@ -185,8 +210,9 @@
blobIds.begin(), blobIds.end(),
std::ostream_iterator<decltype(blobIds[0])>(std::cout, "\n"));
}
+ return 0;
}
- else if (toolConfig.action == BlobToolConfig::Action::READ)
+ if (toolConfig.action == BlobToolConfig::Action::READ)
{
if (toolConfig.blobName.empty())
{
@@ -231,6 +257,7 @@
stdplus::print(stderr, "Blob {} not found.\n", toolConfig.blobName);
return 1;
}
+ return 0;
}
return 0;