mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
disk: Add --share-rw option for hotplugging disks
With qemu 2.10, a write lock was added for qcow images that prevents the same image to be passed more than once. This can be over-ridden using the --share-rw option which is desired for raw images. This solves an issue with running Kata with devicemapper using the privileged mode as in this case all devices on the host are passed to the container using the block device associated with the rootfs, causing it to be passed twice to qemu. Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
parent
8d626afb0c
commit
4461c459a3
23
qemu/qmp.go
23
qemu/qmp.go
@ -670,7 +670,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,
|
||||||
@ -679,6 +680,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -688,8 +692,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"}
|
||||||
|
|
||||||
@ -717,6 +722,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)
|
||||||
}
|
}
|
||||||
@ -802,8 +810,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,
|
||||||
@ -813,6 +822,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,11 +438,11 @@ func TestQMPDeviceAdd(t *testing.T) {
|
|||||||
buf.AddCommand("device_add", nil, "return", nil)
|
buf.AddCommand("device_add", nil, "return", nil)
|
||||||
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||||
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||||
checkVersion(t, connectedCh)
|
q.version = checkVersion(t, connectedCh)
|
||||||
blockdevID := fmt.Sprintf("drive_%s", volumeUUID)
|
blockdevID := fmt.Sprintf("drive_%s", volumeUUID)
|
||||||
devID := fmt.Sprintf("device_%s", volumeUUID)
|
devID := fmt.Sprintf("device_%s", volumeUUID)
|
||||||
err := q.ExecuteDeviceAdd(context.Background(), blockdevID, devID,
|
err := q.ExecuteDeviceAdd(context.Background(), blockdevID, devID,
|
||||||
"virtio-blk-pci", "")
|
"virtio-blk-pci", "", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error %v", err)
|
t.Fatalf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
@ -463,11 +463,11 @@ func TestQMPSCSIDeviceAdd(t *testing.T) {
|
|||||||
buf.AddCommand("device_add", nil, "return", nil)
|
buf.AddCommand("device_add", nil, "return", nil)
|
||||||
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||||
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||||
checkVersion(t, connectedCh)
|
q.version = checkVersion(t, connectedCh)
|
||||||
blockdevID := fmt.Sprintf("drive_%s", volumeUUID)
|
blockdevID := fmt.Sprintf("drive_%s", volumeUUID)
|
||||||
devID := fmt.Sprintf("device_%s", volumeUUID)
|
devID := fmt.Sprintf("device_%s", volumeUUID)
|
||||||
err := q.ExecuteSCSIDeviceAdd(context.Background(), blockdevID, devID,
|
err := q.ExecuteSCSIDeviceAdd(context.Background(), blockdevID, devID,
|
||||||
"scsi-hd", "scsi0.0", 1, 2)
|
"scsi-hd", "scsi0.0", 1, 2, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error %v", err)
|
t.Fatalf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
@ -881,11 +881,11 @@ func TestQMPPCIDeviceAdd(t *testing.T) {
|
|||||||
buf.AddCommand("device_add", nil, "return", nil)
|
buf.AddCommand("device_add", nil, "return", nil)
|
||||||
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||||
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||||
checkVersion(t, connectedCh)
|
q.version = checkVersion(t, connectedCh)
|
||||||
blockdevID := fmt.Sprintf("drive_%s", volumeUUID)
|
blockdevID := fmt.Sprintf("drive_%s", volumeUUID)
|
||||||
devID := fmt.Sprintf("device_%s", volumeUUID)
|
devID := fmt.Sprintf("device_%s", volumeUUID)
|
||||||
err := q.ExecutePCIDeviceAdd(context.Background(), blockdevID, devID,
|
err := q.ExecutePCIDeviceAdd(context.Background(), blockdevID, devID,
|
||||||
"virtio-blk-pci", "0x1", "")
|
"virtio-blk-pci", "0x1", "", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error %v", err)
|
t.Fatalf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user