update_engine: added CanRollback dbus method
Added a method to the update engine to check if a rollback
partition is available and can be booted from.
update_engine_client is also updated to call the function
when --can_rollback paramater is specified
BUG=chromium:343301
TEST=Ran "update_engine_client --can_rollback" and unit tests
Change-Id: If3fcb29a0067069a22812f60e9b67c6fdbbd18bd
Reviewed-on: https://chromium-review.googlesource.com/187157
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/hardware.cc b/hardware.cc
index 9f3fe00..d0e0fc0 100644
--- a/hardware.cc
+++ b/hardware.cc
@@ -76,6 +76,33 @@
return true;
}
+std::vector<std::string> Hardware::GetKernelDevices() {
+ LOG(INFO) << "GetAllKernelDevices";
+
+ std::string disk_name = utils::GetDiskName(Hardware::BootKernelDevice());
+ if(disk_name.empty()) {
+ LOG(ERROR) << "Failed to get the cuurent kernel boot disk name";
+ return std::vector<std::string>();
+ }
+
+ std::vector<std::string> devices;
+ const int slot_count = 2; // Use only partition slots A and B
+ devices.reserve(slot_count);
+ for(int slot = 0; slot < slot_count; slot++) {
+ int partition_num = (slot + 1) * 2; // for now, only #2, #4
+ std::string device = utils::MakePartitionName(disk_name, partition_num);
+ if(!device.empty()) {
+ devices.push_back(std::move(device));
+ } else {
+ LOG(ERROR) << "Cannot make a partition name for disk: "
+ << disk_name << ", partition: " << partition_num;
+ }
+ }
+
+ return devices;
+}
+
+
bool Hardware::MarkKernelUnbootable(const std::string& kernel_device) {
LOG(INFO) << "MarkPartitionUnbootable: " << kernel_device;