| 1 | package hostbox |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "github.com/carlosframework/platform/internal/hostguard" |
| 6 | ) |
| 7 | |
| 8 | func (j *LaunchJournal) ReadStopKernelJournal(ctx context.Context, target hostguard.FenceTarget) (StopKernelJournal, error) { |
| 9 | in, err := j.Read(ctx, target) |
| 10 | if err != nil { |
| 11 | return StopKernelJournal{}, err |
| 12 | } |
| 13 | return launchStopKernelJournal(in, target) |
| 14 | } |
| 15 | func launchStopKernelJournal(in LaunchInventory, target hostguard.FenceTarget) (StopKernelJournal, error) { |
| 16 | if !in.Completed.Valid() || !SameLaunchOwner(in.Target, target) || (!in.NoState && len(in.Files) == 0) { |
| 17 | return StopKernelJournal{}, ErrTypedInventory |
| 18 | } |
| 19 | 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...)} |
| 20 | for _, r := range in.Reservations { |
| 21 | if IsUnitReservation(r) { |
| 22 | out.UnitReservationIDs = append(out.UnitReservationIDs, r.ID) |
| 23 | } |
| 24 | if r.State == "intended" { |
| 25 | out.PendingRoles = true |
| 26 | } |
| 27 | if r.State != "started" && r.State != "settled" { |
| 28 | out.Settled = false |
| 29 | } |
| 30 | } |
| 31 | for _, g := range in.Groups { |
| 32 | out.Cgroups = append(out.Cgroups, StopCgroupIdentity{RelativePath: g.RelativePath, Device: g.Device, Inode: g.Inode, InvocationID: g.InvocationID}) |
| 33 | } |
| 34 | for _, f := range in.Files { |
| 35 | out.Files = append(out.Files, StopFileIdentity{Device: f.Device, Inode: f.Inode}) |
| 36 | } |
| 37 | return out, nil |
| 38 | } |
| 39 | |
| 40 | func (j *LaunchJournal) SettleRecovered(ctx context.Context, target hostguard.FenceTarget) error { |
| 41 | return j.mutate(ctx, target, func(in *LaunchInventory) error { |
| 42 | for _, r := range in.Reservations { |
| 43 | if r.State == "intended" || r.State == UnitIntended || r.State == UnitStarted { |
| 44 | return ErrTypedInventory |
| 45 | } |
| 46 | } |
| 47 | for i := range in.Reservations { |
| 48 | in.Reservations[i].State = "settled" |
| 49 | } |
| 50 | return nil |
| 51 | }) |
| 52 | } |
| 53 | |