fix(deps): update module github.com/crc-org/vfkit to v0.6.1

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
renovate[bot]
2025-05-12 15:14:39 +00:00
committed by GitHub
parent 74f04e9118
commit 6a96f70180
72 changed files with 785 additions and 273 deletions

View File

@@ -22,6 +22,7 @@ const (
vfBlk vmComponentKind = "virtioblk"
vfFs vmComponentKind = "virtiofs"
vfRng vmComponentKind = "virtiorng"
vfBalloon vmComponentKind = "virtioballoon"
vfSerial vmComponentKind = "virtioserial"
vfGpu vmComponentKind = "virtiogpu"
vfInput vmComponentKind = "virtioinput"
@@ -159,6 +160,10 @@ func unmarshalDevice(rawMsg json.RawMessage) (VirtioDevice, error) {
var newDevice VirtioRng
err = json.Unmarshal(rawMsg, &newDevice)
dev = &newDevice
case vfBalloon:
var newDevice VirtioBalloon
err = json.Unmarshal(rawMsg, &newDevice)
dev = &newDevice
case vfSerial:
var newDevice VirtioSerial
err = json.Unmarshal(rawMsg, &newDevice)
@@ -346,6 +351,17 @@ func (dev *VirtioRng) MarshalJSON() ([]byte, error) {
})
}
func (dev *VirtioBalloon) MarshalJSON() ([]byte, error) {
type devWithKind struct {
jsonKind
VirtioBalloon
}
return json.Marshal(devWithKind{
jsonKind: kind(vfBalloon),
VirtioBalloon: *dev,
})
}
func (dev *VirtioSerial) MarshalJSON() ([]byte, error) {
type devWithKind struct {
jsonKind

View File

@@ -59,7 +59,7 @@ type VirtioVsock struct {
// VirtioBlk configures a disk device.
type VirtioBlk struct {
StorageConfig
DiskStorageConfig
DeviceIdentifier string `json:"deviceIdentifier,omitempty"`
}
@@ -82,7 +82,7 @@ type RosettaShare struct {
// NVMExpressController configures a NVMe controller in the guest
type NVMExpressController struct {
StorageConfig
DiskStorageConfig
}
// VirtioRng configures a random number generator (RNG) device.
@@ -117,13 +117,28 @@ const (
)
type NetworkBlockDevice struct {
VirtioBlk
NetworkBlockStorageConfig
DeviceIdentifier string
Timeout time.Duration
SynchronizationMode NBDSynchronizationMode
}
// TODO: Add VirtioBalloon
// https://github.com/Code-Hex/vz/blob/master/memory_balloon.go
type VirtioBalloon struct{}
func VirtioBalloonNew() (VirtioDevice, error) {
return &VirtioBalloon{}, nil
}
func (v *VirtioBalloon) FromOptions(options []option) error {
if len(options) != 0 {
return fmt.Errorf("unknown options for virtio-balloon devices: %s", options)
}
return nil
}
func (v *VirtioBalloon) ToCmdLine() ([]string, error) {
return []string{"--device", "virtio-balloon"}, nil
}
type option struct {
key string
@@ -184,6 +199,8 @@ func deviceFromCmdLine(deviceOpts string) (VirtioDevice, error) {
dev = &VirtioInput{}
case "virtio-gpu":
dev = &VirtioGPU{}
case "virtio-balloon":
dev = &VirtioBalloon{}
case "nbd":
dev = networkBlockDeviceNewEmpty()
default:
@@ -479,8 +496,10 @@ func (dev *VirtioRng) FromOptions(options []option) error {
func nvmExpressControllerNewEmpty() *NVMExpressController {
return &NVMExpressController{
StorageConfig: StorageConfig{
DevName: "nvme",
DiskStorageConfig: DiskStorageConfig{
StorageConfig: StorageConfig{
DevName: "nvme",
},
},
}
}
@@ -496,8 +515,10 @@ func NVMExpressControllerNew(imagePath string) (*NVMExpressController, error) {
func virtioBlkNewEmpty() *VirtioBlk {
return &VirtioBlk{
StorageConfig: StorageConfig{
DevName: "virtio-blk",
DiskStorageConfig: DiskStorageConfig{
StorageConfig: StorageConfig{
DevName: "virtio-blk",
},
},
DeviceIdentifier: "",
}
@@ -527,11 +548,11 @@ func (dev *VirtioBlk) FromOptions(options []option) error {
}
}
return dev.StorageConfig.FromOptions(unhandledOpts)
return dev.DiskStorageConfig.FromOptions(unhandledOpts)
}
func (dev *VirtioBlk) ToCmdLine() ([]string, error) {
cmdLine, err := dev.StorageConfig.ToCmdLine()
cmdLine, err := dev.DiskStorageConfig.ToCmdLine()
if err != nil {
return []string{}, err
}
@@ -681,12 +702,12 @@ func (dev *RosettaShare) FromOptions(options []option) error {
func networkBlockDeviceNewEmpty() *NetworkBlockDevice {
return &NetworkBlockDevice{
VirtioBlk: VirtioBlk{
NetworkBlockStorageConfig: NetworkBlockStorageConfig{
StorageConfig: StorageConfig{
DevName: "nbd",
},
DeviceIdentifier: "",
},
DeviceIdentifier: "",
Timeout: time.Duration(15000 * time.Millisecond), // set a default timeout to 15s
SynchronizationMode: SynchronizationFullMode, // default mode to full
}
@@ -707,7 +728,7 @@ func NetworkBlockDeviceNew(uri string, timeout uint32, synchronization NBDSynchr
}
func (nbd *NetworkBlockDevice) ToCmdLine() ([]string, error) {
cmdLine, err := nbd.VirtioBlk.ToCmdLine()
cmdLine, err := nbd.NetworkBlockStorageConfig.ToCmdLine()
if err != nil {
return []string{}, err
}
@@ -715,6 +736,9 @@ func (nbd *NetworkBlockDevice) ToCmdLine() ([]string, error) {
return []string{}, fmt.Errorf("unexpected storage config commandline")
}
if nbd.DeviceIdentifier != "" {
cmdLine[1] = fmt.Sprintf("%s,deviceId=%s", cmdLine[1], nbd.DeviceIdentifier)
}
if nbd.Timeout.Milliseconds() > 0 {
cmdLine[1] = fmt.Sprintf("%s,timeout=%d", cmdLine[1], nbd.Timeout.Milliseconds())
}
@@ -729,6 +753,8 @@ func (nbd *NetworkBlockDevice) FromOptions(options []option) error {
unhandledOpts := []option{}
for _, option := range options {
switch option.key {
case "deviceId":
nbd.DeviceIdentifier = option.value
case "timeout":
timeoutMS, err := strconv.ParseInt(option.value, 10, 32)
if err != nil {
@@ -749,17 +775,19 @@ func (nbd *NetworkBlockDevice) FromOptions(options []option) error {
}
}
return nbd.VirtioBlk.FromOptions(unhandledOpts)
return nbd.NetworkBlockStorageConfig.FromOptions(unhandledOpts)
}
type USBMassStorage struct {
StorageConfig
DiskStorageConfig
}
func usbMassStorageNewEmpty() *USBMassStorage {
return &USBMassStorage{
StorageConfig{
DevName: "usb-mass-storage",
DiskStorageConfig: DiskStorageConfig{
StorageConfig: StorageConfig{
DevName: "usb-mass-storage",
},
},
}
}
@@ -779,38 +807,66 @@ func (dev *USBMassStorage) SetReadOnly(readOnly bool) {
// StorageConfig configures a disk device.
type StorageConfig struct {
DevName string `json:"devName"`
ImagePath string `json:"imagePath,omitempty"`
URI string `json:"uri,omitempty"`
ReadOnly bool `json:"readOnly,omitempty"`
DevName string `json:"devName"`
ReadOnly bool `json:"readOnly,omitempty"`
}
func (config *StorageConfig) ToCmdLine() ([]string, error) {
if config.ImagePath != "" && config.URI != "" {
return nil, fmt.Errorf("%s devices cannot have both path to a disk image and a uri to a remote block device", config.DevName)
}
if config.ImagePath == "" && config.URI == "" {
return nil, fmt.Errorf("%s devices need a path to a disk image or a uri to a remote block device", config.DevName)
}
var value string
if config.ImagePath != "" {
value = fmt.Sprintf("%s,path=%s", config.DevName, config.ImagePath)
}
if config.URI != "" {
value = fmt.Sprintf("%s,uri=%s", config.DevName, config.URI)
type DiskStorageConfig struct {
StorageConfig
ImagePath string `json:"imagePath,omitempty"`
}
type NetworkBlockStorageConfig struct {
StorageConfig
URI string `json:"uri,omitempty"`
}
func (config *DiskStorageConfig) ToCmdLine() ([]string, error) {
if config.ImagePath == "" {
return nil, fmt.Errorf("%s devices need the path to a disk image", config.DevName)
}
value := fmt.Sprintf("%s,path=%s", config.DevName, config.ImagePath)
if config.ReadOnly {
value += ",readonly"
}
return []string{"--device", value}, nil
}
func (config *StorageConfig) FromOptions(options []option) error {
func (config *DiskStorageConfig) FromOptions(options []option) error {
for _, option := range options {
switch option.key {
case "path":
config.ImagePath = option.value
case "readonly":
if option.value != "" {
return fmt.Errorf("unexpected value for virtio-blk 'readonly' option: %s", option.value)
}
config.ReadOnly = true
default:
return fmt.Errorf("unknown option for %s devices: %s", config.DevName, option.key)
}
}
return nil
}
func (config *NetworkBlockStorageConfig) ToCmdLine() ([]string, error) {
if config.URI == "" {
return nil, fmt.Errorf("%s devices need the uri to a remote block device", config.DevName)
}
value := fmt.Sprintf("%s,uri=%s", config.DevName, config.URI)
if config.ReadOnly {
value += ",readonly"
}
return []string{"--device", value}, nil
}
func (config *NetworkBlockStorageConfig) FromOptions(options []option) error {
for _, option := range options {
switch option.key {
case "uri":
config.URI = option.value
case "readonly":

View File

@@ -0,0 +1,60 @@
package util
import (
"log"
"os"
"os/signal"
"sync"
"syscall"
)
type exitHandlerRegistry struct {
handlers []func()
mutex sync.Mutex
}
var exitRegistry = exitHandlerRegistry{}
// RegisterExitHandler appends a func Exit handler to the list of handlers.
// The handlers will be invoked when vfkit receives a termination or interruption signal
//
// This method is useful when a caller wishes to execute a func before a shutdown.
func RegisterExitHandler(handler func()) {
exitRegistry.mutex.Lock()
defer exitRegistry.mutex.Unlock()
exitRegistry.handlers = append(exitRegistry.handlers, handler)
}
// SetupExitSignalHandling sets up a signal channel to listen for termination or interruption signals.
// When one of these signals is received, all the registered exit handlers will be invoked, just
// before terminating the program.
func SetupExitSignalHandling() {
setupExitSignalHandling(true)
}
// setupExitSignalHandling sets up a signal channel to listen for termination or interruption signals.
// When one of these signals is received, all the registered exit handlers will be invoked.
// It is possible to prevent the program from exiting by setting the doExit param to false (used for testing)
func setupExitSignalHandling(doExit bool) {
sigChan := make(chan os.Signal, 2)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
go func() {
for sig := range sigChan {
log.Printf("captured %v, calling exit handlers and exiting..", sig)
ExecuteExitHandlers()
if doExit {
os.Exit(1)
}
}
}()
}
// ExecuteExitHandlers is call all registered exit handlers
// This function should be called when program finish work(i.e. when VM is turned off by guest OS)
func ExecuteExitHandlers() {
exitRegistry.mutex.Lock()
for _, handler := range exitRegistry.handlers {
handler()
}
exitRegistry.mutex.Unlock()
}