mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 19:16:23 +00:00
Merge pull request #607 from amshinde/pass-disk-as-shared
Pass qemu --share-rw option for hotplugging disks
This commit is contained in:
commit
cc29b8d4b6
4
Gopkg.lock
generated
4
Gopkg.lock
generated
@ -115,11 +115,11 @@
|
|||||||
revision = "3520598351bb3500a49ae9563f5539666ae0a27c"
|
revision = "3520598351bb3500a49ae9563f5539666ae0a27c"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:a801632523299b53fbd954449f36020cf751e4bd6fe2d923e3416e8f0603b4af"
|
digest = "1:e35245b8aac4b53c6dd7b161c8c19f038e2ad29a54a03d276a88f3fc2a656c29"
|
||||||
name = "github.com/intel/govmm"
|
name = "github.com/intel/govmm"
|
||||||
packages = ["qemu"]
|
packages = ["qemu"]
|
||||||
pruneopts = "NUT"
|
pruneopts = "NUT"
|
||||||
revision = "eda239928bfa12b214e9c93192d548cccf4e7f1e"
|
revision = "d8f80cafe3ee3bba440a9ff8d234817b64a30b07"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:55460fbdfca464360cec902b0805126451908aa1a058fe4072b01650ebe768b3"
|
digest = "1:55460fbdfca464360cec902b0805126451908aa1a058fe4072b01650ebe768b3"
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/intel/govmm"
|
name = "github.com/intel/govmm"
|
||||||
revision = "eda239928bfa12b214e9c93192d548cccf4e7f1e"
|
revision = "d8f80cafe3ee3bba440a9ff8d234817b64a30b07"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/kata-containers/agent"
|
name = "github.com/kata-containers/agent"
|
||||||
|
19
vendor/github.com/intel/govmm/qemu/qemu.go
generated
vendored
19
vendor/github.com/intel/govmm/qemu/qemu.go
generated
vendored
@ -1064,17 +1064,13 @@ type RTC struct {
|
|||||||
|
|
||||||
// Valid returns true if the RTC structure is valid and complete.
|
// Valid returns true if the RTC structure is valid and complete.
|
||||||
func (rtc RTC) Valid() bool {
|
func (rtc RTC) Valid() bool {
|
||||||
if rtc.Clock != "" {
|
|
||||||
if rtc.Clock != Host && rtc.Clock != VM {
|
if rtc.Clock != Host && rtc.Clock != VM {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if rtc.DriftFix != "" {
|
|
||||||
if rtc.DriftFix != Slew && rtc.DriftFix != NoDriftFix {
|
if rtc.DriftFix != Slew && rtc.DriftFix != NoDriftFix {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -1239,7 +1235,7 @@ type Config struct {
|
|||||||
// Path is the qemu binary path.
|
// Path is the qemu binary path.
|
||||||
Path string
|
Path string
|
||||||
|
|
||||||
// Ctx is not used at the moment.
|
// Ctx is the context used when launching qemu.
|
||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
|
|
||||||
// Name is the qemu guest name
|
// Name is the qemu guest name
|
||||||
@ -1636,7 +1632,12 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return LaunchCustomQemu(config.Ctx, config.Path, config.qemuParams,
|
ctx := config.Ctx
|
||||||
|
if ctx == nil {
|
||||||
|
ctx = context.Background()
|
||||||
|
}
|
||||||
|
|
||||||
|
return LaunchCustomQemu(ctx, config.Path, config.qemuParams,
|
||||||
config.fds, nil, logger)
|
config.fds, nil, logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1644,10 +1645,6 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) {
|
|||||||
//
|
//
|
||||||
// The path parameter is used to pass the qemu executable path.
|
// The path parameter is used to pass the qemu executable path.
|
||||||
//
|
//
|
||||||
// The ctx parameter is not currently used but has been added so that the
|
|
||||||
// signature of this function will not need to change when launch cancellation
|
|
||||||
// is implemented.
|
|
||||||
//
|
|
||||||
// params is a slice of options to pass to qemu-system-x86_64 and fds is a
|
// params is a slice of options to pass to qemu-system-x86_64 and fds is a
|
||||||
// list of open file descriptors that are to be passed to the spawned qemu
|
// list of open file descriptors that are to be passed to the spawned qemu
|
||||||
// process. The attrs parameter can be used to control aspects of the
|
// process. The attrs parameter can be used to control aspects of the
|
||||||
@ -1672,7 +1669,7 @@ func LaunchCustomQemu(ctx context.Context, path string, params []string, fds []*
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* #nosec */
|
/* #nosec */
|
||||||
cmd := exec.Command(path, params...)
|
cmd := exec.CommandContext(ctx, path, params...)
|
||||||
if len(fds) > 0 {
|
if len(fds) > 0 {
|
||||||
logger.Infof("Adding extra file %v", fds)
|
logger.Infof("Adding extra file %v", fds)
|
||||||
cmd.ExtraFiles = fds
|
cmd.ExtraFiles = fds
|
||||||
|
48
vendor/github.com/intel/govmm/qemu/qmp.go
generated
vendored
48
vendor/github.com/intel/govmm/qemu/qmp.go
generated
vendored
@ -671,7 +671,8 @@ func (q *QMP) ExecuteBlockdevAdd(ctx context.Context, device, blockdevID string)
|
|||||||
// to a previous call to ExecuteBlockdevAdd. devID is the id of the device to
|
// to a previous call to ExecuteBlockdevAdd. devID is the id of the device to
|
||||||
// add. Both strings must be valid QMP identifiers. driver is the name of the
|
// add. Both strings must be valid QMP identifiers. driver is the name of the
|
||||||
// driver,e.g., virtio-blk-pci, and bus is the name of the bus. bus is optional.
|
// driver,e.g., virtio-blk-pci, and bus is the name of the bus. bus is optional.
|
||||||
func (q *QMP) ExecuteDeviceAdd(ctx context.Context, blockdevID, devID, driver, bus string) error {
|
// shared denotes if the drive can be shared allowing it to be passed more than once.
|
||||||
|
func (q *QMP) ExecuteDeviceAdd(ctx context.Context, blockdevID, devID, driver, bus string, shared bool) error {
|
||||||
args := map[string]interface{}{
|
args := map[string]interface{}{
|
||||||
"id": devID,
|
"id": devID,
|
||||||
"driver": driver,
|
"driver": driver,
|
||||||
@ -680,6 +681,9 @@ func (q *QMP) ExecuteDeviceAdd(ctx context.Context, blockdevID, devID, driver, b
|
|||||||
if bus != "" {
|
if bus != "" {
|
||||||
args["bus"] = bus
|
args["bus"] = bus
|
||||||
}
|
}
|
||||||
|
if shared && (q.version.Major > 2 || (q.version.Major == 2 && q.version.Minor >= 10)) {
|
||||||
|
args["share-rw"] = "on"
|
||||||
|
}
|
||||||
return q.executeCommand(ctx, "device_add", args, nil)
|
return q.executeCommand(ctx, "device_add", args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -689,8 +693,9 @@ func (q *QMP) ExecuteDeviceAdd(ctx context.Context, blockdevID, devID, driver, b
|
|||||||
// the device to add. Both strings must be valid QMP identifiers. driver is the name of the
|
// the device to add. Both strings must be valid QMP identifiers. driver is the name of the
|
||||||
// scsi driver,e.g., scsi-hd, and bus is the name of a SCSI controller bus.
|
// scsi driver,e.g., scsi-hd, and bus is the name of a SCSI controller bus.
|
||||||
// scsiID is the SCSI id, lun is logical unit number. scsiID and lun are optional, a negative value
|
// scsiID is the SCSI id, lun is logical unit number. scsiID and lun are optional, a negative value
|
||||||
// for scsiID and lun is ignored.
|
// for scsiID and lun is ignored. shared denotes if the drive can be shared allowing it
|
||||||
func (q *QMP) ExecuteSCSIDeviceAdd(ctx context.Context, blockdevID, devID, driver, bus string, scsiID, lun int) error {
|
// to be passed more than once.
|
||||||
|
func (q *QMP) ExecuteSCSIDeviceAdd(ctx context.Context, blockdevID, devID, driver, bus string, scsiID, lun int, shared bool) error {
|
||||||
// TBD: Add drivers for scsi passthrough like scsi-generic and scsi-block
|
// TBD: Add drivers for scsi passthrough like scsi-generic and scsi-block
|
||||||
drivers := []string{"scsi-hd", "scsi-cd", "scsi-disk"}
|
drivers := []string{"scsi-hd", "scsi-cd", "scsi-disk"}
|
||||||
|
|
||||||
@ -718,6 +723,9 @@ func (q *QMP) ExecuteSCSIDeviceAdd(ctx context.Context, blockdevID, devID, drive
|
|||||||
if lun >= 0 {
|
if lun >= 0 {
|
||||||
args["lun"] = lun
|
args["lun"] = lun
|
||||||
}
|
}
|
||||||
|
if shared && (q.version.Major > 2 || (q.version.Major == 2 && q.version.Minor >= 10)) {
|
||||||
|
args["share-rw"] = "on"
|
||||||
|
}
|
||||||
|
|
||||||
return q.executeCommand(ctx, "device_add", args, nil)
|
return q.executeCommand(ctx, "device_add", args, nil)
|
||||||
}
|
}
|
||||||
@ -820,8 +828,9 @@ func (q *QMP) ExecuteDeviceDel(ctx context.Context, devID string) error {
|
|||||||
|
|
||||||
// ExecutePCIDeviceAdd is the PCI version of ExecuteDeviceAdd. This function can be used
|
// ExecutePCIDeviceAdd is the PCI version of ExecuteDeviceAdd. This function can be used
|
||||||
// to hot plug PCI devices on PCI(E) bridges, unlike ExecuteDeviceAdd this function receive the
|
// to hot plug PCI devices on PCI(E) bridges, unlike ExecuteDeviceAdd this function receive the
|
||||||
// device address on its parent bus. bus is optional.
|
// device address on its parent bus. bus is optional. shared denotes if the drive can be shared
|
||||||
func (q *QMP) ExecutePCIDeviceAdd(ctx context.Context, blockdevID, devID, driver, addr, bus string) error {
|
// allowing it to be passed more than once.
|
||||||
|
func (q *QMP) ExecutePCIDeviceAdd(ctx context.Context, blockdevID, devID, driver, addr, bus string, shared bool) error {
|
||||||
args := map[string]interface{}{
|
args := map[string]interface{}{
|
||||||
"id": devID,
|
"id": devID,
|
||||||
"driver": driver,
|
"driver": driver,
|
||||||
@ -831,6 +840,10 @@ func (q *QMP) ExecutePCIDeviceAdd(ctx context.Context, blockdevID, devID, driver
|
|||||||
if bus != "" {
|
if bus != "" {
|
||||||
args["bus"] = bus
|
args["bus"] = bus
|
||||||
}
|
}
|
||||||
|
if shared && (q.version.Major > 2 || (q.version.Major == 2 && q.version.Minor >= 10)) {
|
||||||
|
args["share-rw"] = "on"
|
||||||
|
}
|
||||||
|
|
||||||
return q.executeCommand(ctx, "device_add", args, nil)
|
return q.executeCommand(ctx, "device_add", args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -865,6 +878,24 @@ func (q *QMP) ExecutePCIVFIODeviceAdd(ctx context.Context, devID, bdf, addr, bus
|
|||||||
return q.executeCommand(ctx, "device_add", args, nil)
|
return q.executeCommand(ctx, "device_add", args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecutePCIVFIOMediatedDeviceAdd adds a VFIO mediated device to a QEMU instance using the device_add command.
|
||||||
|
// This function can be used to hot plug VFIO mediated devices on PCI(E) bridges, unlike
|
||||||
|
// ExecuteVFIODeviceAdd this function receives the bus and the device address on its parent bus.
|
||||||
|
// bus is optional. devID is the id of the device to add. Must be valid QMP identifier. sysfsdev is the VFIO
|
||||||
|
// mediated device.
|
||||||
|
func (q *QMP) ExecutePCIVFIOMediatedDeviceAdd(ctx context.Context, devID, sysfsdev, addr, bus string) error {
|
||||||
|
args := map[string]interface{}{
|
||||||
|
"id": devID,
|
||||||
|
"driver": "vfio-pci",
|
||||||
|
"sysfsdev": sysfsdev,
|
||||||
|
"addr": addr,
|
||||||
|
}
|
||||||
|
if bus != "" {
|
||||||
|
args["bus"] = bus
|
||||||
|
}
|
||||||
|
return q.executeCommand(ctx, "device_add", args, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// ExecuteCPUDeviceAdd adds a CPU to a QEMU instance using the device_add command.
|
// ExecuteCPUDeviceAdd adds a CPU to a QEMU instance using the device_add command.
|
||||||
// driver is the CPU model, cpuID must be a unique ID to identify the CPU, socketID is the socket number within
|
// driver is the CPU model, cpuID must be a unique ID to identify the CPU, socketID is the socket number within
|
||||||
// node/board the CPU belongs to, coreID is the core number within socket the CPU belongs to, threadID is the
|
// node/board the CPU belongs to, coreID is the core number within socket the CPU belongs to, threadID is the
|
||||||
@ -956,12 +987,17 @@ func (q *QMP) ExecHotplugMemory(ctx context.Context, qomtype, id, mempath string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ExecutePCIVSockAdd adds a vhost-vsock-pci bus
|
// ExecutePCIVSockAdd adds a vhost-vsock-pci bus
|
||||||
func (q *QMP) ExecutePCIVSockAdd(ctx context.Context, id, guestCID, vhostfd string, disableModern bool) error {
|
func (q *QMP) ExecutePCIVSockAdd(ctx context.Context, id, guestCID, vhostfd, addr, bus string, disableModern bool) error {
|
||||||
args := map[string]interface{}{
|
args := map[string]interface{}{
|
||||||
"driver": VHostVSockPCI,
|
"driver": VHostVSockPCI,
|
||||||
"id": id,
|
"id": id,
|
||||||
"guest-cid": guestCID,
|
"guest-cid": guestCID,
|
||||||
"vhostfd": vhostfd,
|
"vhostfd": vhostfd,
|
||||||
|
"addr": addr,
|
||||||
|
}
|
||||||
|
|
||||||
|
if bus != "" {
|
||||||
|
args["bus"] = bus
|
||||||
}
|
}
|
||||||
|
|
||||||
if disableModern {
|
if disableModern {
|
||||||
|
@ -733,7 +733,7 @@ func (q *qemu) hotplugBlockDevice(drive *config.BlockDrive, op operation) error
|
|||||||
// PCI address is in the format bridge-addr/device-addr eg. "03/02"
|
// PCI address is in the format bridge-addr/device-addr eg. "03/02"
|
||||||
drive.PCIAddr = fmt.Sprintf("%02x", bridge.Addr) + "/" + addr
|
drive.PCIAddr = fmt.Sprintf("%02x", bridge.Addr) + "/" + addr
|
||||||
|
|
||||||
if err = q.qmpMonitorCh.qmp.ExecutePCIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, addr, bridge.ID); err != nil {
|
if err = q.qmpMonitorCh.qmp.ExecutePCIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, addr, bridge.ID, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -748,7 +748,7 @@ func (q *qemu) hotplugBlockDevice(drive *config.BlockDrive, op operation) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = q.qmpMonitorCh.qmp.ExecuteSCSIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, bus, scsiID, lun); err != nil {
|
if err = q.qmpMonitorCh.qmp.ExecuteSCSIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, bus, scsiID, lun, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user