gitee.com/leisunstar/runtime@v0.0.0-20200521203717-5cef3e7b53f9/virtcontainers/persist/api/device.go (about)

     1  // Copyright (c) 2016 Intel Corporation
     2  // Copyright (c) 2019 Huawei Corporation
     3  //
     4  // SPDX-License-Identifier: Apache-2.0
     5  //
     6  
     7  package persistapi
     8  
     9  // ============= sandbox level resources =============
    10  
    11  // BlockDrive represents a block storage drive which may be used in case the storage
    12  // driver has an underlying block storage device.
    13  type BlockDrive struct {
    14  	// File is the path to the disk-image/device which will be used with this drive
    15  	File string
    16  
    17  	// Format of the drive
    18  	Format string
    19  
    20  	// ID is used to identify this drive in the hypervisor options.
    21  	ID string
    22  
    23  	// Index assigned to the drive. In case of virtio-scsi, this is used as SCSI LUN index
    24  	Index int
    25  
    26  	// MmioAddr is used to identify the slot at which the drive is attached (order?).
    27  	MmioAddr string
    28  
    29  	// PCIAddr is the PCI address used to identify the slot at which the drive is attached.
    30  	PCIAddr string
    31  
    32  	// SCSI Address of the block device, in case the device is attached using SCSI driver
    33  	// SCSI address is in the format SCSI-Id:LUN
    34  	SCSIAddr string
    35  
    36  	// NvdimmID is the nvdimm id inside the VM
    37  	NvdimmID string
    38  
    39  	// VirtPath at which the device appears inside the VM, outside of the container mount namespace
    40  	VirtPath string
    41  
    42  	// DevNo
    43  	DevNo string
    44  
    45  	// Pmem enabled persistent memory. Use File as backing file
    46  	// for a nvdimm device in the guest.
    47  	Pmem bool
    48  }
    49  
    50  // VFIODev represents a VFIO drive used for hotplugging
    51  type VFIODev struct {
    52  	// ID is used to identify this drive in the hypervisor options.
    53  	ID string
    54  
    55  	// Type of VFIO device
    56  	Type uint32
    57  
    58  	// BDF (Bus:Device.Function) of the PCI address
    59  	BDF string
    60  
    61  	// Sysfsdev of VFIO mediated device
    62  	SysfsDev string
    63  }
    64  
    65  // VhostUserDeviceAttrs represents data shared by most vhost-user devices
    66  type VhostUserDeviceAttrs struct {
    67  	DevID      string
    68  	SocketPath string
    69  	Type       string
    70  
    71  	// MacAddress is only meaningful for vhost user net device
    72  	MacAddress string
    73  
    74  	// PCIAddr is the PCI address used to identify the slot at which the drive is attached.
    75  	// It is only meaningful for vhost user block devices
    76  	PCIAddr string
    77  
    78  	// Block index of the device if assigned
    79  	Index int
    80  }
    81  
    82  // DeviceState is sandbox level resource which represents host devices
    83  // plugged to hypervisor, one Device can be shared among containers in POD
    84  // Refs: virtcontainers/device/drivers/generic.go:GenericDevice
    85  type DeviceState struct {
    86  	ID string
    87  
    88  	// Type is used to specify driver type
    89  	// Refs: virtcontainers/device/config/config.go:DeviceType
    90  	Type string
    91  
    92  	RefCount    uint
    93  	AttachCount uint
    94  
    95  	// Type of device: c, b, u or p
    96  	// c , u - character(unbuffered)
    97  	// p - FIFO
    98  	// b - block(buffered) special file
    99  	// More info in mknod(1).
   100  	DevType string
   101  
   102  	// Major, minor numbers for device.
   103  	Major int64
   104  	Minor int64
   105  
   106  	// DriverOptions is specific options for each device driver
   107  	// for example, for BlockDevice, we can set DriverOptions["blockDriver"]="virtio-blk"
   108  	DriverOptions map[string]string
   109  
   110  	// ============ device driver specific data ===========
   111  	// BlockDrive is specific for block device driver
   112  	BlockDrive *BlockDrive `json:",omitempty"`
   113  
   114  	// VFIODev is specific VFIO device driver
   115  	VFIODevs []*VFIODev `json:",omitempty"`
   116  
   117  	// VhostUserDeviceAttrs is specific for vhost-user device driver
   118  	VhostUserDev *VhostUserDeviceAttrs `json:",omitempty"`
   119  	// ============ end device driver specific data ===========
   120  }