mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 08:47:56 +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())
|
ds.Type = string(device.DeviceType())
|
||||||
|
|
||||||
drive := device.BlockDrive
|
drive := device.BlockDrive
|
||||||
ds.BlockDrive = &persistapi.BlockDrive{
|
if drive != nil {
|
||||||
File: drive.File,
|
ds.BlockDrive = &persistapi.BlockDrive{
|
||||||
Format: drive.Format,
|
File: drive.File,
|
||||||
ID: drive.ID,
|
Format: drive.Format,
|
||||||
Index: drive.Index,
|
ID: drive.ID,
|
||||||
MmioAddr: drive.MmioAddr,
|
Index: drive.Index,
|
||||||
PCIAddr: drive.PCIAddr,
|
MmioAddr: drive.MmioAddr,
|
||||||
SCSIAddr: drive.SCSIAddr,
|
PCIAddr: drive.PCIAddr,
|
||||||
NvdimmID: drive.NvdimmID,
|
SCSIAddr: drive.SCSIAddr,
|
||||||
VirtPath: drive.VirtPath,
|
NvdimmID: drive.NvdimmID,
|
||||||
|
VirtPath: drive.VirtPath,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ds
|
return ds
|
||||||
}
|
}
|
||||||
|
@ -119,16 +119,19 @@ func (device *GenericDevice) bumpAttachCount(attach bool) (skip bool, err error)
|
|||||||
|
|
||||||
// Dump convert and return data in persist format
|
// Dump convert and return data in persist format
|
||||||
func (device *GenericDevice) Dump() persistapi.DeviceState {
|
func (device *GenericDevice) Dump() persistapi.DeviceState {
|
||||||
info := device.DeviceInfo
|
dss := persistapi.DeviceState{
|
||||||
return persistapi.DeviceState{
|
|
||||||
ID: device.ID,
|
ID: device.ID,
|
||||||
Type: string(device.DeviceType()),
|
Type: string(device.DeviceType()),
|
||||||
RefCount: device.RefCount,
|
RefCount: device.RefCount,
|
||||||
AttachCount: device.AttachCount,
|
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
|
devs := device.VfioDevs
|
||||||
for _, dev := range devs {
|
for _, dev := range devs {
|
||||||
ds.VFIODevs = append(ds.VFIODevs, &persistapi.VFIODev{
|
if dev != nil {
|
||||||
ID: dev.ID,
|
ds.VFIODevs = append(ds.VFIODevs, &persistapi.VFIODev{
|
||||||
Type: string(dev.Type),
|
ID: dev.ID,
|
||||||
BDF: dev.BDF,
|
Type: string(dev.Type),
|
||||||
SysfsDev: dev.SysfsDev,
|
BDF: dev.BDF,
|
||||||
})
|
SysfsDev: dev.SysfsDev,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ds
|
return ds
|
||||||
}
|
}
|
||||||
|
@ -98,9 +98,6 @@ func (fs *FS) ToDisk() (retErr error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := fs.lock(); err != nil {
|
if err := fs.lock(); err != nil {
|
||||||
if err1 := fs.Destroy(); err1 != nil {
|
|
||||||
fs.Logger().WithError(err1).Errorf("failed to destroy dirs")
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer fs.unlock()
|
defer fs.unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user