| 1 | //go:build linux |
| 2 | |
| 3 | package host |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | |
| 8 | "github.com/carlosframework/platform/internal/hostbox" |
| 9 | "github.com/carlosframework/platform/internal/hostguard" |
| 10 | "github.com/carlosframework/platform/internal/provision" |
| 11 | ) |
| 12 | |
| 13 | func (h ClaimRootHTTP) verifyServingHandoverDirectory(ctx context.Context, prior hostguard.FenceTarget, e hostbox.StopInventoryEntry, actual hostbox.Artifact) error { |
| 14 | if h.servingParks == nil || h.servingParks.authority == nil { |
| 15 | return hostbox.ErrChanged |
| 16 | } |
| 17 | authority, ok := h.servingParks.authority.(*servingParkRoot) |
| 18 | if !ok { |
| 19 | return hostbox.ErrChanged |
| 20 | } |
| 21 | l := authority.ledger |
| 22 | if l == nil { |
| 23 | return hostbox.ErrChanged |
| 24 | } |
| 25 | fs, ok := l.fs.(*servingParkFS) |
| 26 | if !ok { |
| 27 | return hostbox.ErrChanged |
| 28 | } |
| 29 | boot, err := fs.currentBoot() |
| 30 | if err != nil || !validServingParkBootID(prior.BootID) { |
| 31 | return hostbox.ErrChanged |
| 32 | } |
| 33 | if prior.BootID == boot { |
| 34 | if actual.Dev != e.Device { |
| 35 | return hostbox.ErrChanged |
| 36 | } |
| 37 | return ctx.Err() |
| 38 | } |
| 39 | slot, err := l.slot(servingParkAuthorization{Successor: servingArtifactIdentity{Host: prior.Host, Box: prior.Box}}) |
| 40 | if err != nil { |
| 41 | return err |
| 42 | } |
| 43 | r, err := l.readHistorical(slot.Last) |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | s := r.Authorization.Successor |
| 48 | if !r.Complete || s.Host != prior.Host || s.Box != prior.Box || s.Incarnation != prior.Incarnation || s.Stamp > prior.Stamp || e.Kind != "path" || e.ManagedRoot != "data" || e.RelativePath != "instances/"+provision.InstanceID(prior.Host) || e.Inode != r.Source.Directory.Inode || actual.Ino != e.Inode || actual.Type != 0040000 || e.Type != actual.Type { |
| 49 | return hostbox.ErrChanged |
| 50 | } |
| 51 | if _, err := fs.readNamespace(); err != nil { |
| 52 | return err |
| 53 | } |
| 54 | root, n, err := fs.namespace() |
| 55 | if err != nil { |
| 56 | return err |
| 57 | } |
| 58 | root.Close() |
| 59 | parent, pid, err := fs.parent() |
| 60 | if err != nil { |
| 61 | return err |
| 62 | } |
| 63 | defer parent.Close() |
| 64 | if pid != n.Parent { |
| 65 | return hostbox.ErrChanged |
| 66 | } |
| 67 | source, err := servingParkOpenDir(parent, provision.InstanceID(prior.Host)) |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | defer source.Close() |
| 72 | id, err := fs.rebootDirectory(source, r.Source.Directory, r.Source.Persistent, pid) |
| 73 | if err != nil || id.Device != actual.Dev || id.Inode != actual.Ino { |
| 74 | return hostbox.ErrChanged |
| 75 | } |
| 76 | if err := fs.checkBoot(boot); err != nil { |
| 77 | return err |
| 78 | } |
| 79 | return ctx.Err() |
| 80 | } |
| 81 | |