bow-restore: Mitigating error message 40/314140/2
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 5 Jul 2024 14:22:40 +0000 (16:22 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 10 Jul 2024 13:25:21 +0000 (15:25 +0200)
The bow-restore is called every time the system is booting. There will
never be a checkpoint to restore outside of an ongoing OS Upgrade.

Change-Id: I3e0f99a3d01edbeef4eae595e70c894c63e23b1e

src/bow-restore/bow-restore.cpp

index b867294a17912fe893d6ae7afe663ae3b62eef3e..9f694cf9aef4dd0166ab2e71b491f8cba98c1588 100644 (file)
@@ -44,6 +44,11 @@ public:
         return st;
     }
 
+    static Status ok(const std::string &message) {
+        Status st = {0, message};
+        return st;
+    }
+
     static Status error(int value, const std::string &message) {
         Status st = {value, message};
         return st;
@@ -62,6 +67,7 @@ public:
     std::string &message() { return _msg; };
 
     bool isOk() { return _status == 0; }
+    bool hasMessage() { return !_msg.empty(); }
 };
 
 Status error(int value, const std::string &message) {
@@ -72,6 +78,10 @@ Status error(const std::string &message) {
     return Status::error(message);
 }
 
+Status ok(const std::string &message) {
+    return Status::ok(message);
+}
+
 // END
 
 const int kSectorSize = 512;
@@ -311,9 +321,17 @@ Status cp_restoreCheckpoint(const std::string& blockDevice, int restore_limit) {
             action = "Restoring";
         } else if (original_ls.magic != kMagic) {
             close(device_fd);
-            return error(EINVAL, "No magic");
+            if (validating) {
+                // "No magic" during validating means that that there is simply no
+                // checkpoint to restore. This is not an error, we are simply not
+                // in the process of OS upgrade.
+                return ok("No magic (It is ok if OS Upgrade is not in progress or has been successful)");
+            } else {
+                // If there was "Magic" during validation, and now there is
+                // not, then we have reason to worry.
+                return error(EINVAL, "No magic");
+            }
         }
-
         LOG(INFO) << action << " " << original_ls.sequence << " log sectors" << "\n";
 
         for (int sequence = original_ls.sequence; sequence >= 0 && status.isOk(); sequence--) {
@@ -419,5 +437,8 @@ int main(int argc, char *argv[]) {
         LOG(ERROR) << "bow-restore error: " << status.message() << "\n";
         return EXIT_FAILURE;
     }
+    if (status.hasMessage()) {
+        LOG(INFO) << "bow-restore info: " << status.message() << "\n";
+    }
     return EXIT_SUCCESS;
 }