mirror of https://github.com/jetkvm/kvm.git
fix(usbgadget): do not panic if a change isn't found (#481)
* fix(usbgadget): do not panic if a change isn't found * chore(usbgadget): rebind usb after updating config
This commit is contained in:
parent
b4dd4961fc
commit
a0f6d01465
|
@ -48,6 +48,11 @@ func (c *ChangeSetResolver) doResolveChanges(initial bool) error {
|
|||
|
||||
for _, key := range c.orderedChanges {
|
||||
change := c.changesMap[key.(string)]
|
||||
if change == nil {
|
||||
c.l.Error().Str("key", key.(string)).Msg("fileChange not found")
|
||||
continue
|
||||
}
|
||||
|
||||
if !initial {
|
||||
change.ResetActionResolution()
|
||||
}
|
||||
|
@ -123,7 +128,11 @@ func (c *ChangeSetResolver) applyChanges() error {
|
|||
|
||||
err := c.changeset.applyChange(change)
|
||||
if err != nil {
|
||||
return err
|
||||
if change.IgnoreErrors {
|
||||
c.l.Warn().Str("change", change.String()).Err(err).Msg("ignoring error")
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -177,12 +177,7 @@ func (u *UsbGadget) Init() error {
|
|||
|
||||
u.udc = udcs[0]
|
||||
|
||||
err := u.WithTransaction(func() error {
|
||||
u.tx.MountConfigFS()
|
||||
u.tx.CreateConfigPath()
|
||||
u.tx.WriteGadgetConfig()
|
||||
return nil
|
||||
})
|
||||
err := u.configureUsbGadget(false)
|
||||
if err != nil {
|
||||
return u.logError("unable to initialize USB stack", err)
|
||||
}
|
||||
|
@ -196,13 +191,22 @@ func (u *UsbGadget) UpdateGadgetConfig() error {
|
|||
|
||||
u.loadGadgetConfig()
|
||||
|
||||
err := u.WithTransaction(func() error {
|
||||
u.tx.WriteGadgetConfig()
|
||||
return nil
|
||||
})
|
||||
err := u.configureUsbGadget(true)
|
||||
if err != nil {
|
||||
return u.logError("unable to update gadget config", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UsbGadget) configureUsbGadget(resetUsb bool) error {
|
||||
return u.WithTransaction(func() error {
|
||||
u.tx.MountConfigFS()
|
||||
u.tx.CreateConfigPath()
|
||||
u.tx.WriteGadgetConfig()
|
||||
if resetUsb {
|
||||
u.tx.RebindUsb(true)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
|
@ -319,6 +319,7 @@ func (tx *UsbGadgetTransaction) WriteUDC() {
|
|||
// bound the gadget to a UDC (USB Device Controller)
|
||||
path := path.Join(tx.kvmGadgetPath, "UDC")
|
||||
tx.addFileChange("udc", RequestedFileChange{
|
||||
Key: "udc",
|
||||
Path: path,
|
||||
ExpectedState: FileStateFileContentMatch,
|
||||
ExpectedContent: []byte(tx.udc),
|
||||
|
@ -334,6 +335,8 @@ func (tx *UsbGadgetTransaction) RebindUsb(ignoreUnbindError bool) {
|
|||
ExpectedState: FileStateFileWrite,
|
||||
ExpectedContent: []byte(tx.udc),
|
||||
Description: "unbind UDC",
|
||||
DependsOn: []string{"udc"},
|
||||
IgnoreErrors: ignoreUnbindError,
|
||||
})
|
||||
// bind the gadget to the UDC
|
||||
tx.addFileChange("udc", RequestedFileChange{
|
||||
|
@ -342,6 +345,5 @@ func (tx *UsbGadgetTransaction) RebindUsb(ignoreUnbindError bool) {
|
|||
ExpectedContent: []byte(tx.udc),
|
||||
Description: "bind UDC",
|
||||
DependsOn: []string{path.Join(tx.dwc3Path, "unbind")},
|
||||
IgnoreErrors: ignoreUnbindError,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue