From 219e1d16efe82a81ee4855fb1bd037e3cd2c7f92 Mon Sep 17 00:00:00 2001 From: Christoph Ostarek Date: Thu, 2 May 2024 17:12:45 +0200 Subject: [PATCH 1/4] pillar/zedmanager: doInactivateHalt fix state transition from RESTARTING to HALT(ING) if an edge app upgrade is done while an EVE update is done, the app status state stays in RESTARTING although EVE will restart and therefore halt the app instance; therefore the app status should go to HALT in this case. Signed-off-by: Christoph Ostarek --- pkg/pillar/cmd/zedmanager/updatestatus.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pkg/pillar/cmd/zedmanager/updatestatus.go b/pkg/pillar/cmd/zedmanager/updatestatus.go index 6f3bbd6207..b1f4ecc116 100644 --- a/pkg/pillar/cmd/zedmanager/updatestatus.go +++ b/pkg/pillar/cmd/zedmanager/updatestatus.go @@ -1174,15 +1174,10 @@ func doInactivateHalt(ctx *zedmanagerContext, changed = true } if ds.State != status.State { - switch status.State { - case types.RESTARTING, types.PURGING: - // Leave unchanged - default: - log.Functionf("Set State from DomainStatus from %d to %d", - status.State, ds.State) - status.State = ds.State - changed = true - } + log.Functionf("Set State from DomainStatus from %d to %d", + status.State, ds.State) + status.State = ds.State + changed = true } // Ignore errors during a halt if ds.HasError() { From 40742671604816d5660d86ef341c3532a76a434a Mon Sep 17 00:00:00 2001 From: Christoph Ostarek Date: Wed, 15 May 2024 16:17:58 +0200 Subject: [PATCH 2/4] zedcloud/deferred: clarify variable name 'lock' is used for locking deferredItems, so let's clarify this! Signed-off-by: Christoph Ostarek --- pkg/pillar/zedcloud/deferred.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/pillar/zedcloud/deferred.go b/pkg/pillar/zedcloud/deferred.go index 0364394711..5e2610c0c0 100644 --- a/pkg/pillar/zedcloud/deferred.go +++ b/pkg/pillar/zedcloud/deferred.go @@ -56,9 +56,9 @@ const longTime2 = time.Hour * 48 // DeferredContext is part of ZedcloudContext type DeferredContext struct { deferredItems []*deferredItem + deferredItemsLock *sync.Mutex Ticker flextimer.FlexTickerHandle priorityCheckFunctions []TypePriorityCheckFunction - lock *sync.Mutex sentHandler *SentHandlerFunction zedcloudCtx *ZedCloudContext iteration int @@ -92,7 +92,7 @@ func CreateDeferredCtx(zedcloudCtx *ZedCloudContext, }) ctx := &DeferredContext{ - lock: &sync.Mutex{}, + deferredItemsLock: &sync.Mutex{}, Ticker: flextimer.NewRangeTicker(longTime1, longTime2), sentHandler: sentHandler, priorityCheckFunctions: priorityCheckFunctions, @@ -134,10 +134,10 @@ func (ctx *DeferredContext) processQueueTask(ps *pubsub.PubSub, // handleDeferred try to send all deferred items func (ctx *DeferredContext) handleDeferred() bool { - ctx.lock.Lock() + ctx.deferredItemsLock.Lock() reqs := ctx.deferredItems ctx.deferredItems = []*deferredItem{} - ctx.lock.Unlock() + ctx.deferredItemsLock.Unlock() log := ctx.zedcloudCtx.log @@ -235,13 +235,13 @@ func (ctx *DeferredContext) handleDeferred() bool { } } - ctx.lock.Lock() + ctx.deferredItemsLock.Lock() // Merge with the incoming requests, recently added are in the tail ctx.deferredItems = append(notSentReqs, ctx.deferredItems...) if len(ctx.deferredItems) == 0 { stopTimer(log, ctx) } - ctx.lock.Unlock() + ctx.deferredItemsLock.Unlock() allSent := len(notSentReqs) == 0 @@ -258,8 +258,8 @@ func (ctx *DeferredContext) handleDeferred() bool { func (ctx *DeferredContext) SetDeferred( key string, buf *bytes.Buffer, size int64, url string, bailOnHTTPErr, withNetTracing, ignoreErr bool, itemType interface{}) { - ctx.lock.Lock() - defer ctx.lock.Unlock() + ctx.deferredItemsLock.Lock() + defer ctx.deferredItemsLock.Unlock() log := ctx.zedcloudCtx.log log.Functionf("SetDeferred(%s) size %d items %d", @@ -300,8 +300,8 @@ func (ctx *DeferredContext) SetDeferred( // RemoveDeferred removes key from deferred items if exists func (ctx *DeferredContext) RemoveDeferred(key string) { - ctx.lock.Lock() - defer ctx.lock.Unlock() + ctx.deferredItemsLock.Lock() + defer ctx.deferredItemsLock.Unlock() log := ctx.zedcloudCtx.log log.Functionf("RemoveDeferred(%s) items %d", From b9770fd985bfa5f0850379835ebb4360ad27d1cd Mon Sep 17 00:00:00 2001 From: Christoph Ostarek Date: Thu, 16 May 2024 18:26:18 +0200 Subject: [PATCH 3/4] zedmanager: do not report RESTARTING or PURGING include removing dead code Signed-off-by: Christoph Ostarek Signed-off-by: Christoph Ostarek --- pkg/pillar/cmd/zedagent/parseconfig.go | 4 ---- pkg/pillar/cmd/zedmanager/updatestatus.go | 13 ++++--------- pkg/pillar/cmd/zedmanager/zedmanager.go | 5 +---- pkg/pillar/types/types.go | 16 +++------------- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/pkg/pillar/cmd/zedagent/parseconfig.go b/pkg/pillar/cmd/zedagent/parseconfig.go index e1c80e002e..071715cf8b 100644 --- a/pkg/pillar/cmd/zedagent/parseconfig.go +++ b/pkg/pillar/cmd/zedagent/parseconfig.go @@ -219,10 +219,6 @@ func countRunningApps(getconfigCtx *getconfigContext) (runningCount uint) { switch status.State { case types.BOOTING, types.RUNNING, types.HALTING: runningCount++ - case types.PURGING, types.RESTARTING: - log.Noticef("countRunningApps: %s for %s in %s", - status.Key(), status.DisplayName, status.State) - runningCount++ } } return runningCount diff --git a/pkg/pillar/cmd/zedmanager/updatestatus.go b/pkg/pillar/cmd/zedmanager/updatestatus.go index b1f4ecc116..636c7c191d 100644 --- a/pkg/pillar/cmd/zedmanager/updatestatus.go +++ b/pkg/pillar/cmd/zedmanager/updatestatus.go @@ -802,15 +802,10 @@ func doActivate(ctx *zedmanagerContext, uuidStr string, } } if ds.State != status.State { - switch status.State { - case types.RESTARTING, types.PURGING: - // Leave unchanged - default: - log.Functionf("Set State from DomainStatus from %d to %d", - status.State, ds.State) - status.State = ds.State - changed = true - } + log.Functionf("Set State from DomainStatus from %d to %d", + status.State, ds.State) + status.State = ds.State + changed = true } // XXX compare with equal before setting changed? status.IoAdapterList = ds.IoAdapterList diff --git a/pkg/pillar/cmd/zedmanager/zedmanager.go b/pkg/pillar/cmd/zedmanager/zedmanager.go index ada80d8f96..64858f4421 100644 --- a/pkg/pillar/cmd/zedmanager/zedmanager.go +++ b/pkg/pillar/cmd/zedmanager/zedmanager.go @@ -1062,7 +1062,6 @@ func handleCreate(ctxArg interface{}, key string, log.Warnf("handleCreate(%v) for %s found different purge counter %d vs. %d", config.UUIDandVersion, config.DisplayName, persistedCounter, configCounter) status.PurgeInprogress = types.DownloadAndVerify - status.State = types.PURGING status.PurgeStartedAt = time.Now() // We persist the PurgeCmd Counter when // PurgeInprogress is done @@ -1222,8 +1221,7 @@ func handleModify(ctxArg interface{}, key string, // Will restart even if we crash/power cycle since that // would also restart the app. Hence we can update // the status counter here. - status.RestartInprogress = types.BringDown - status.State = types.RESTARTING + status.RestartInprogress = types.BringDown // indicate to restart status.RestartStartedAt = time.Now() } else { log.Functionf("handleModify(%v) for %s restartcmd ignored config !Activate", @@ -1254,7 +1252,6 @@ func handleModify(ctxArg interface{}, key string, status.ClearErrorWithSource() } status.PurgeInprogress = types.DownloadAndVerify - status.State = types.PURGING status.PurgeStartedAt = time.Now() // We persist the PurgeCmd Counter when PurgeInprogress is done } else if needPurge { diff --git a/pkg/pillar/types/types.go b/pkg/pillar/types/types.go index 79a279f9a2..d27a6d209a 100644 --- a/pkg/pillar/types/types.go +++ b/pkg/pillar/types/types.go @@ -18,7 +18,7 @@ import ( // SwState started with enum names from OMA-TS-LWM2M_SwMgmt-V1_0-20151201-C // but now has many additions. -// They are in order of progression (except for the RESTARTING and PURGING ones) +// They are in order of progression // We map this to info.ZSwState type SwState uint8 @@ -44,10 +44,8 @@ const ( PAUSED HALTING // being halted HALTED - RESTARTING // Restarting due to config change or zcli - PURGING // Purging due to config change - BROKEN // Domain is still alive, but its device model has failed - UNKNOWN // State of the domain can't be determined + BROKEN // BROKEN means domain is still alive, but its device model has failed + UNKNOWN // UNKNOWN means state of the domain can't be determined // PENDING to start PENDING // SCHEDULING waiting to be scheduled @@ -98,10 +96,6 @@ func (state SwState) String() string { return "HALTING" case HALTED: return "HALTED" - case RESTARTING: - return "RESTARTING" - case PURGING: - return "PURGING" case PENDING: return "PENDING" case FAILED: @@ -170,10 +164,6 @@ func (state SwState) ZSwState() info.ZSwState { return info.ZSwState_HALTING case HALTED: return info.ZSwState_HALTED - case RESTARTING: - return info.ZSwState_RESTARTING - case PURGING: - return info.ZSwState_PURGING // we map BROKEN to HALTING to indicate that EVE has an active // role in reaping BROKEN domains and transitioning them to // a final HALTED state From 973c1acec1e267b2dc32ac4e1720f847899bfaed Mon Sep 17 00:00:00 2001 From: Christoph Ostarek Date: Fri, 17 May 2024 17:30:55 +0200 Subject: [PATCH 4/4] zedmanager: report HALTING state correctly when doing a purge; otherwise HALTED state would be reported directly Signed-off-by: Christoph Ostarek --- pkg/pillar/cmd/zedmanager/updatestatus.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/pillar/cmd/zedmanager/updatestatus.go b/pkg/pillar/cmd/zedmanager/updatestatus.go index 636c7c191d..47bd347a85 100644 --- a/pkg/pillar/cmd/zedmanager/updatestatus.go +++ b/pkg/pillar/cmd/zedmanager/updatestatus.go @@ -171,6 +171,7 @@ func doUpdate(ctx *zedmanagerContext, log.Functionf("PurgeInprogress(%s) volumemgr done", status.Key()) status.PurgeInprogress = types.BringDown + status.State = types.HALTING changed = true // Keep the old volumes in place _, done := doRemove(ctx, status, false)