mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 16:27:50 +00:00
bugfix: fix potential panic
* Fix potential panic by nil pointer. * Address comments. Signed-off-by: Wei Zhang <zhangwei555@huawei.com>
This commit is contained in:
parent
9bd4e5008c
commit
3262da0207
@ -153,16 +153,18 @@ func (device *BlockDevice) Dump() persistapi.DeviceState {
|
||||
ds.Type = string(device.DeviceType())
|
||||
|
||||
drive := device.BlockDrive
|
||||
ds.BlockDrive = &persistapi.BlockDrive{
|
||||
File: drive.File,
|
||||
Format: drive.Format,
|
||||
ID: drive.ID,
|
||||
Index: drive.Index,
|
||||
MmioAddr: drive.MmioAddr,
|
||||
PCIAddr: drive.PCIAddr,
|
||||
SCSIAddr: drive.SCSIAddr,
|
||||
NvdimmID: drive.NvdimmID,
|
||||
VirtPath: drive.VirtPath,
|
||||
if drive != nil {
|
||||
ds.BlockDrive = &persistapi.BlockDrive{
|
||||
File: drive.File,
|
||||
Format: drive.Format,
|
||||
ID: drive.ID,
|
||||
Index: drive.Index,
|
||||
MmioAddr: drive.MmioAddr,
|
||||
PCIAddr: drive.PCIAddr,
|
||||
SCSIAddr: drive.SCSIAddr,
|
||||
NvdimmID: drive.NvdimmID,
|
||||
VirtPath: drive.VirtPath,
|
||||
}
|
||||
}
|
||||
return ds
|
||||
}
|
||||
|
@ -119,16 +119,19 @@ func (device *GenericDevice) bumpAttachCount(attach bool) (skip bool, err error)
|
||||
|
||||
// Dump convert and return data in persist format
|
||||
func (device *GenericDevice) Dump() persistapi.DeviceState {
|
||||
info := device.DeviceInfo
|
||||
return persistapi.DeviceState{
|
||||
dss := persistapi.DeviceState{
|
||||
ID: device.ID,
|
||||
Type: string(device.DeviceType()),
|
||||
RefCount: device.RefCount,
|
||||
AttachCount: device.AttachCount,
|
||||
|
||||
DevType: info.DevType,
|
||||
Major: info.Major,
|
||||
Minor: info.Minor,
|
||||
DriverOptions: info.DriverOptions,
|
||||
}
|
||||
|
||||
info := device.DeviceInfo
|
||||
if info != nil {
|
||||
dss.DevType = info.DevType
|
||||
dss.Major = info.Major
|
||||
dss.Minor = info.Minor
|
||||
dss.DriverOptions = info.DriverOptions
|
||||
}
|
||||
return dss
|
||||
}
|
||||
|
@ -147,12 +147,14 @@ func (device *VFIODevice) Dump() persistapi.DeviceState {
|
||||
|
||||
devs := device.VfioDevs
|
||||
for _, dev := range devs {
|
||||
ds.VFIODevs = append(ds.VFIODevs, &persistapi.VFIODev{
|
||||
ID: dev.ID,
|
||||
Type: string(dev.Type),
|
||||
BDF: dev.BDF,
|
||||
SysfsDev: dev.SysfsDev,
|
||||
})
|
||||
if dev != nil {
|
||||
ds.VFIODevs = append(ds.VFIODevs, &persistapi.VFIODev{
|
||||
ID: dev.ID,
|
||||
Type: string(dev.Type),
|
||||
BDF: dev.BDF,
|
||||
SysfsDev: dev.SysfsDev,
|
||||
})
|
||||
}
|
||||
}
|
||||
return ds
|
||||
}
|
||||
|
@ -98,9 +98,6 @@ func (fs *FS) ToDisk() (retErr error) {
|
||||
}
|
||||
|
||||
if err := fs.lock(); err != nil {
|
||||
if err1 := fs.Destroy(); err1 != nil {
|
||||
fs.Logger().WithError(err1).Errorf("failed to destroy dirs")
|
||||
}
|
||||
return err
|
||||
}
|
||||
defer fs.unlock()
|
||||
|
Loading…
Reference in New Issue
Block a user