package hostbox import ( "context" "github.com/carlosframework/platform/internal/hostguard" ) func (j *LaunchJournal) ReadStopKernelJournal(ctx context.Context, target hostguard.FenceTarget) (StopKernelJournal, error) { in, err := j.Read(ctx, target) if err != nil { return StopKernelJournal{}, err } return launchStopKernelJournal(in, target) } func launchStopKernelJournal(in LaunchInventory, target hostguard.FenceTarget) (StopKernelJournal, error) { if !in.Completed.Valid() || !SameLaunchOwner(in.Target, target) || (!in.NoState && len(in.Files) == 0) { return StopKernelJournal{}, ErrTypedInventory } out := StopKernelJournal{WritersClosed: in.WritersClosed, Completed: in.Completed, ControllerPID: in.ControllerPID, ProcessStart: in.ProcessStart, V: 1, Target: in.Target, Settled: true, ProducerIDs: append([]string{}, in.ProducerIDs...)} for _, r := range in.Reservations { if IsUnitReservation(r) { out.UnitReservationIDs = append(out.UnitReservationIDs, r.ID) } if r.State == "intended" { out.PendingRoles = true } if r.State != "started" && r.State != "settled" { out.Settled = false } } for _, g := range in.Groups { out.Cgroups = append(out.Cgroups, StopCgroupIdentity{RelativePath: g.RelativePath, Device: g.Device, Inode: g.Inode, InvocationID: g.InvocationID}) } for _, f := range in.Files { out.Files = append(out.Files, StopFileIdentity{Device: f.Device, Inode: f.Inode}) } return out, nil } func (j *LaunchJournal) SettleRecovered(ctx context.Context, target hostguard.FenceTarget) error { return j.mutate(ctx, target, func(in *LaunchInventory) error { for _, r := range in.Reservations { if r.State == "intended" || r.State == UnitIntended || r.State == UnitStarted { return ErrTypedInventory } } for i := range in.Reservations { in.Reservations[i].State = "settled" } return nil }) }