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 {
|
for _, key := range c.orderedChanges {
|
||||||
change := c.changesMap[key.(string)]
|
change := c.changesMap[key.(string)]
|
||||||
|
if change == nil {
|
||||||
|
c.l.Error().Str("key", key.(string)).Msg("fileChange not found")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if !initial {
|
if !initial {
|
||||||
change.ResetActionResolution()
|
change.ResetActionResolution()
|
||||||
}
|
}
|
||||||
|
@ -123,7 +128,11 @@ func (c *ChangeSetResolver) applyChanges() error {
|
||||||
|
|
||||||
err := c.changeset.applyChange(change)
|
err := c.changeset.applyChange(change)
|
||||||
if err != nil {
|
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]
|
u.udc = udcs[0]
|
||||||
|
|
||||||
err := u.WithTransaction(func() error {
|
err := u.configureUsbGadget(false)
|
||||||
u.tx.MountConfigFS()
|
|
||||||
u.tx.CreateConfigPath()
|
|
||||||
u.tx.WriteGadgetConfig()
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return u.logError("unable to initialize USB stack", err)
|
return u.logError("unable to initialize USB stack", err)
|
||||||
}
|
}
|
||||||
|
@ -196,13 +191,22 @@ func (u *UsbGadget) UpdateGadgetConfig() error {
|
||||||
|
|
||||||
u.loadGadgetConfig()
|
u.loadGadgetConfig()
|
||||||
|
|
||||||
err := u.WithTransaction(func() error {
|
err := u.configureUsbGadget(true)
|
||||||
u.tx.WriteGadgetConfig()
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return u.logError("unable to update gadget config", err)
|
return u.logError("unable to update gadget config", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
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)
|
// bound the gadget to a UDC (USB Device Controller)
|
||||||
path := path.Join(tx.kvmGadgetPath, "UDC")
|
path := path.Join(tx.kvmGadgetPath, "UDC")
|
||||||
tx.addFileChange("udc", RequestedFileChange{
|
tx.addFileChange("udc", RequestedFileChange{
|
||||||
|
Key: "udc",
|
||||||
Path: path,
|
Path: path,
|
||||||
ExpectedState: FileStateFileContentMatch,
|
ExpectedState: FileStateFileContentMatch,
|
||||||
ExpectedContent: []byte(tx.udc),
|
ExpectedContent: []byte(tx.udc),
|
||||||
|
@ -334,6 +335,8 @@ func (tx *UsbGadgetTransaction) RebindUsb(ignoreUnbindError bool) {
|
||||||
ExpectedState: FileStateFileWrite,
|
ExpectedState: FileStateFileWrite,
|
||||||
ExpectedContent: []byte(tx.udc),
|
ExpectedContent: []byte(tx.udc),
|
||||||
Description: "unbind UDC",
|
Description: "unbind UDC",
|
||||||
|
DependsOn: []string{"udc"},
|
||||||
|
IgnoreErrors: ignoreUnbindError,
|
||||||
})
|
})
|
||||||
// bind the gadget to the UDC
|
// bind the gadget to the UDC
|
||||||
tx.addFileChange("udc", RequestedFileChange{
|
tx.addFileChange("udc", RequestedFileChange{
|
||||||
|
@ -342,6 +345,5 @@ func (tx *UsbGadgetTransaction) RebindUsb(ignoreUnbindError bool) {
|
||||||
ExpectedContent: []byte(tx.udc),
|
ExpectedContent: []byte(tx.udc),
|
||||||
Description: "bind UDC",
|
Description: "bind UDC",
|
||||||
DependsOn: []string{path.Join(tx.dwc3Path, "unbind")},
|
DependsOn: []string{path.Join(tx.dwc3Path, "unbind")},
|
||||||
IgnoreErrors: ignoreUnbindError,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue