mirror of
https://github.com/lxc/incus.git
synced 2026-02-05 09:46:19 +01:00
incusd/device/nic: Fix connected logic for non-NIC QEMU devices
Signed-off-by: Benjamin Somers <benjamin.somers@imt-atlantique.fr>
This commit is contained in:
@@ -333,7 +333,7 @@ func (d *nicOVN) validateConfig(instConf instance.ConfigReader) error {
|
|||||||
// type: bool
|
// type: bool
|
||||||
// default: `true`
|
// default: `true`
|
||||||
// required: no
|
// required: no
|
||||||
// shortdesc: Whether the NIC is connected to the host network (container support requires setting `acceleration` to `none`)
|
// shortdesc: Whether the NIC is connected to the host network (requires `acceleration` set to `none`)
|
||||||
"connected",
|
"connected",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,9 +593,9 @@ func (d *nicOVN) validateConfig(instConf instance.ConfigReader) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The connected option can only be handled properly on containers if acceleration is set to none.
|
// The connected option can only be handled properly if acceleration is set to none.
|
||||||
if d.config["connected"] != "" && !d.canSetLink(instConf) {
|
if d.config["connected"] != "" && !d.canSetLink() {
|
||||||
return errors.New("The \"connected\" option requires setting acceleration=none on containers for OVN NICs")
|
return errors.New("The \"connected\" option requires setting acceleration=none for OVN NICs")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -1015,7 +1015,7 @@ func (d *nicOVN) Start() (*deviceConfig.RunConfig, error) {
|
|||||||
{Key: "link", Value: peerName},
|
{Key: "link", Value: peerName},
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.canSetLink(nil) {
|
if d.canSetLink() {
|
||||||
runConf.NetworkInterface = append(runConf.NetworkInterface, deviceConfig.RunConfigItem{Key: "connected", Value: d.config["connected"]})
|
runConf.NetworkInterface = append(runConf.NetworkInterface, deviceConfig.RunConfigItem{Key: "connected", Value: d.config["connected"]})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1173,7 +1173,7 @@ func (d *nicOVN) Update(oldDevices deviceConfig.Devices, isRunning bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if isRunning && d.canSetLink(nil) {
|
if isRunning && d.canSetLink() {
|
||||||
return d.setNICLink()
|
return d.setNICLink()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1571,13 +1571,6 @@ func (d *nicOVN) setupHostNIC(hostName string, ovnPortName ovn.OVNSwitchPort) (r
|
|||||||
}
|
}
|
||||||
|
|
||||||
// canSetLink determines whether the device supports setting a link state.
|
// canSetLink determines whether the device supports setting a link state.
|
||||||
func (d *nicOVN) canSetLink(instConf instance.ConfigReader) bool {
|
func (d *nicOVN) canSetLink() bool {
|
||||||
var instType instancetype.Type
|
return slices.Contains([]string{"", "none"}, d.config["acceleration"])
|
||||||
if instConf != nil {
|
|
||||||
instType = instConf.Type()
|
|
||||||
} else {
|
|
||||||
instType = d.inst.Type()
|
|
||||||
}
|
|
||||||
|
|
||||||
return instType == instancetype.VM || slices.Contains([]string{"", "none"}, d.config["acceleration"])
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,15 +142,6 @@ func (d *nicSRIOV) validateConfig(instConf instance.ConfigReader) error {
|
|||||||
// required: no
|
// required: no
|
||||||
// shortdesc: Whether the NIC is plugged in or not
|
// shortdesc: Whether the NIC is plugged in or not
|
||||||
"attached",
|
"attached",
|
||||||
|
|
||||||
// gendoc:generate(entity=devices, group=nic_sriov, key=connected)
|
|
||||||
//
|
|
||||||
// ---
|
|
||||||
// type: bool
|
|
||||||
// default: `true`
|
|
||||||
// required: no
|
|
||||||
// shortdesc: Whether the NIC is connected to the host network (VM only)
|
|
||||||
"connected",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that if network property is set that conflicting keys are not present.
|
// Check that if network property is set that conflicting keys are not present.
|
||||||
@@ -198,10 +189,6 @@ func (d *nicSRIOV) validateConfig(instConf instance.ConfigReader) error {
|
|||||||
requiredFields = append(requiredFields, "parent")
|
requiredFields = append(requiredFields, "parent")
|
||||||
}
|
}
|
||||||
|
|
||||||
if instConf.Type() != instancetype.VM && d.config["connected"] != "" {
|
|
||||||
return errors.New("The \"connected\" option is only supported on virtual machines for SR-IOV NICs")
|
|
||||||
}
|
|
||||||
|
|
||||||
err := d.config.Validate(nicValidationRules(requiredFields, optionalFields, instConf))
|
err := d.config.Validate(nicValidationRules(requiredFields, optionalFields, instConf))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -337,7 +324,6 @@ func (d *nicSRIOV) Start() (*deviceConfig.RunConfig, error) {
|
|||||||
{Key: "flags", Value: "up"},
|
{Key: "flags", Value: "up"},
|
||||||
{Key: "link", Value: saveData["host_name"]},
|
{Key: "link", Value: saveData["host_name"]},
|
||||||
{Key: "hwaddr", Value: d.config["hwaddr"]},
|
{Key: "hwaddr", Value: d.config["hwaddr"]},
|
||||||
{Key: "connected", Value: d.config["connected"]},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.inst.Type() == instancetype.VM {
|
if d.inst.Type() == instancetype.VM {
|
||||||
@@ -535,23 +521,3 @@ func nicSelected(device deviceConfig.Device, nic api.ResourcesNetworkCard) bool
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatableFields returns a list of fields that can be updated without triggering a device remove & add.
|
|
||||||
func (d *nicSRIOV) UpdatableFields(oldDevice Type) []string {
|
|
||||||
// Check old and new device types match.
|
|
||||||
_, match := oldDevice.(*nicSRIOV)
|
|
||||||
if !match {
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return []string{"connected"}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update applies configuration changes to a started device.
|
|
||||||
func (d *nicSRIOV) Update(oldDevices deviceConfig.Devices, isRunning bool) error {
|
|
||||||
if isRunning {
|
|
||||||
return d.setNICLink()
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user