Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/sm/launcher/runtimes/rootfs/rootfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ Error RootfsRuntime::StartInstance(const InstanceInfo& instance, InstanceStatus&
return ErrorEnum::eNone;
}

if (static_cast<const InstanceIdent&>(mPendingInstance) == static_cast<const InstanceIdent&>(instance)
&& instance.mManifestDigest == mPendingInstance.mManifestDigest) {
status.mState = InstanceStateEnum::eActivating;

mStatusReceiver->OnInstancesStatusesReceived(Array<InstanceStatus> {&status, 1});

return ErrorEnum::eNone;
}

mStatusReceiver->OnInstancesStatusesReceived(Array<InstanceStatus> {&status, 1});

Error err = ErrorEnum::eNone;
Expand Down Expand Up @@ -197,25 +206,28 @@ Error RootfsRuntime::GetInstanceMonitoringData(

void RootfsRuntime::RunHealthCheck(std::unique_ptr<InstanceStatus> status)
{
LOG_DBG() << "Start health check for rootfs update" << Log::Field("version", mPendingVersion);
LOG_DBG() << "Start health check for rootfs update" << Log::Field("version", mPendingInstance.mVersion);

ActionType nextAction = ActionTypeEnum::eDoApply;

if (auto err = mUpdateChecker.Check(); !err.IsNone()) {
LOG_ERR() << "Health check for rootfs update failed" << err;

status->mState = InstanceStateEnum::eFailed;
status->mError = AOS_ERROR_WRAP(err);

nextAction = ActionTypeEnum::eFailed;
}

if (auto err = StoreAction(nextAction); !err.IsNone()) {
LOG_ERR() << "Failed to store rootfs update action" << err;

status->mState = InstanceStateEnum::eFailed;
status->mError = AOS_ERROR_WRAP(err);
}

if (auto err = mRebooter.Reboot(); !err.IsNone()) {
status->mState = InstanceStateEnum::eFailed;
status->mError = AOS_ERROR_WRAP(err);
LOG_WRN() << "Failed to reboot system after rootfs update health check" << err;
}

mStatusReceiver->OnInstancesStatusesReceived(Array<InstanceStatus> {status.get(), 1});
Expand Down Expand Up @@ -427,6 +439,7 @@ Error RootfsRuntime::SaveInstanceInfo(const InstanceInfo& instance, const std::f
try {
json->set("itemId", instance.mItemID.CStr());
json->set("subjectId", instance.mSubjectID.CStr());
json->set("instance", instance.mInstance);
json->set("manifestDigest", instance.mManifestDigest.CStr());
json->set("type", instance.mType.ToString().CStr());
json->set("version", instance.mVersion.CStr());
Expand Down Expand Up @@ -464,6 +477,8 @@ Error RootfsRuntime::LoadInstanceInfo(const std::filesystem::path& path, Instanc
err = instance.mSubjectID.Assign(jsonObject.GetValue<std::string>("subjectId").c_str());
AOS_ERROR_CHECK_AND_THROW(err);

instance.mInstance = jsonObject.GetValue<uint64_t>("instance");

err = instance.mManifestDigest.Assign(jsonObject.GetValue<std::string>("manifestDigest").c_str());
AOS_ERROR_CHECK_AND_THROW(err);

Expand Down
2 changes: 0 additions & 2 deletions src/sm/launcher/runtimes/rootfs/rootfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,8 @@ class RootfsRuntime : public RuntimeItf {
mutable std::mutex mMutex;
std::optional<std::thread> mHealthCheckThread;
InstanceInfo mCurrentInstance {};
StaticString<cVersionLen> mCurrentVersion;
RuntimeInfo mRuntimeInfo;
InstanceInfo mPendingInstance;
StaticString<cVersionLen> mPendingVersion;
};

} // namespace aos::sm::launcher
Expand Down