diff --git a/virtcontainers/device/drivers/block.go b/virtcontainers/device/drivers/block.go index 85ad8c63e4..9897118ade 100644 --- a/virtcontainers/device/drivers/block.go +++ b/virtcontainers/device/drivers/block.go @@ -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 } diff --git a/virtcontainers/device/drivers/generic.go b/virtcontainers/device/drivers/generic.go index e5b7e30ee3..d01014f67f 100644 --- a/virtcontainers/device/drivers/generic.go +++ b/virtcontainers/device/drivers/generic.go @@ -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 } diff --git a/virtcontainers/device/drivers/vfio.go b/virtcontainers/device/drivers/vfio.go index 82573ccb65..bea10dc2d9 100644 --- a/virtcontainers/device/drivers/vfio.go +++ b/virtcontainers/device/drivers/vfio.go @@ -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 } diff --git a/virtcontainers/persist/fs/fs.go b/virtcontainers/persist/fs/fs.go index 9b1e6be85b..765765f3c4 100644 --- a/virtcontainers/persist/fs/fs.go +++ b/virtcontainers/persist/fs/fs.go @@ -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()