|
| 1 | +// Copyright (c) 2023-2026, Nubificus LTD |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package hypervisors |
| 16 | + |
| 17 | +import ( |
| 18 | + "strings" |
| 19 | + |
| 20 | + "github.com/urunc-dev/urunc/pkg/unikontainers/types" |
| 21 | +) |
| 22 | + |
| 23 | +const ( |
| 24 | + HyperlightVmm VmmType = "hyperlight" |
| 25 | + HyperlightBinary string = "" |
| 26 | +) |
| 27 | + |
| 28 | +type Hyperlight struct { |
| 29 | + binaryPath string |
| 30 | + binary string |
| 31 | +} |
| 32 | + |
| 33 | +// Stop kills the hyperlight process |
| 34 | +func (h *Hyperlight) Stop(pid int) error { |
| 35 | + return killProcess(pid) |
| 36 | +} |
| 37 | + |
| 38 | +// UsesKVM returns a bool value depending on if the monitor uses KVM |
| 39 | +func (h *Hyperlight) UsesKVM() bool { |
| 40 | + return true |
| 41 | +} |
| 42 | + |
| 43 | +// SupportsSharedfs returns a bool value depending on the monitor support for shared-fs |
| 44 | +func (h *Hyperlight) SupportsSharedfs(_ string) bool { |
| 45 | + return false |
| 46 | +} |
| 47 | + |
| 48 | +// Path returns the path to the hyperlight binary. |
| 49 | +func (h *Hyperlight) Path() string { |
| 50 | + return h.binaryPath |
| 51 | +} |
| 52 | + |
| 53 | +// Ok checks if the hyperlight binary is available. |
| 54 | +// Since hyperlight is embedded, we just return nil. |
| 55 | +func (h *Hyperlight) Ok() error { |
| 56 | + return nil |
| 57 | +} |
| 58 | + |
| 59 | +func (h *Hyperlight) BuildExecCmd(args types.ExecArgs, _ types.Unikernel) ([]string, error) { |
| 60 | + // Hyperlight is an embedded VMM, so we just run the unikernel directly. |
| 61 | + cmdArgs := []string{args.UnikernelPath} |
| 62 | + if args.Command != "" { |
| 63 | + cmdArgs = append(cmdArgs, strings.Split(args.Command, " ")...) |
| 64 | + } |
| 65 | + return cmdArgs, nil |
| 66 | +} |
| 67 | + |
| 68 | +// PreExec performs pre-execution setup. Hyperlight has no special pre-exec requirements. |
| 69 | +func (h *Hyperlight) PreExec(_ types.ExecArgs) error { |
| 70 | + return nil |
| 71 | +} |
0 commit comments