mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 12:14:48 +00:00
govmm: Refactor qmp functions for adding block device
Instead of passing a bunch of arguments to qmp functions for adding block devices, use govmm BlockDevice structure to reduce these. Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
parent
598884f374
commit
c1e3b8f40f
@ -771,18 +771,18 @@ func (q *QMP) ExecuteQuit(ctx context.Context) error {
|
||||
return q.executeCommand(ctx, "quit", nil, nil)
|
||||
}
|
||||
|
||||
func (q *QMP) blockdevAddBaseArgs(driver, device, blockdevID, aio string, ro bool) map[string]interface{} {
|
||||
func (q *QMP) blockdevAddBaseArgs(driver string, blockDevice *BlockDevice) map[string]interface{} {
|
||||
blockdevArgs := map[string]interface{}{
|
||||
"driver": "raw",
|
||||
"read-only": ro,
|
||||
"read-only": blockDevice.ReadOnly,
|
||||
"file": map[string]interface{}{
|
||||
"driver": driver,
|
||||
"filename": device,
|
||||
"aio": aio,
|
||||
"filename": blockDevice.File,
|
||||
"aio": string(blockDevice.AIO),
|
||||
},
|
||||
}
|
||||
|
||||
blockdevArgs["node-name"] = blockdevID
|
||||
blockdevArgs["node-name"] = blockDevice.ID
|
||||
|
||||
return blockdevArgs
|
||||
}
|
||||
@ -791,8 +791,8 @@ func (q *QMP) blockdevAddBaseArgs(driver, device, blockdevID, aio string, ro boo
|
||||
// path of the device to add, e.g., /dev/rdb0, and blockdevID is an identifier
|
||||
// used to name the device. As this identifier will be passed directly to QMP,
|
||||
// it must obey QMP's naming rules, e,g., it must start with a letter.
|
||||
func (q *QMP) ExecuteBlockdevAdd(ctx context.Context, device, blockdevID, aio string, ro bool) error {
|
||||
args := q.blockdevAddBaseArgs("host_device", device, blockdevID, aio, ro)
|
||||
func (q *QMP) ExecuteBlockdevAdd(ctx context.Context, blockDevice *BlockDevice) error {
|
||||
args := q.blockdevAddBaseArgs("host_device", blockDevice)
|
||||
|
||||
return q.executeCommand(ctx, "blockdev-add", args, nil)
|
||||
}
|
||||
@ -804,8 +804,8 @@ func (q *QMP) ExecuteBlockdevAdd(ctx context.Context, device, blockdevID, aio st
|
||||
// direct denotes whether use of O_DIRECT (bypass the host page cache)
|
||||
// is enabled. noFlush denotes whether flush requests for the device are
|
||||
// ignored.
|
||||
func (q *QMP) ExecuteBlockdevAddWithCache(ctx context.Context, device, blockdevID, aio string, direct, noFlush, ro bool) error {
|
||||
blockdevArgs := q.blockdevAddBaseArgs("host_device", device, blockdevID, aio, ro)
|
||||
func (q *QMP) ExecuteBlockdevAddWithCache(ctx context.Context, blockDevice *BlockDevice, direct, noFlush bool) error {
|
||||
blockdevArgs := q.blockdevAddBaseArgs("host_device", blockDevice)
|
||||
|
||||
blockdevArgs["cache"] = map[string]interface{}{
|
||||
"direct": direct,
|
||||
@ -818,8 +818,8 @@ func (q *QMP) ExecuteBlockdevAddWithCache(ctx context.Context, device, blockdevI
|
||||
// ExecuteBlockdevAddWithDriverCache has three one parameter driver
|
||||
// than ExecuteBlockdevAddWithCache.
|
||||
// Parameter driver can set the driver of block device.
|
||||
func (q *QMP) ExecuteBlockdevAddWithDriverCache(ctx context.Context, driver, device, blockdevID, aio string, direct, noFlush, ro bool) error {
|
||||
blockdevArgs := q.blockdevAddBaseArgs(driver, device, blockdevID, aio, ro)
|
||||
func (q *QMP) ExecuteBlockdevAddWithDriverCache(ctx context.Context, driver string, blockDevice *BlockDevice, direct, noFlush bool) error {
|
||||
blockdevArgs := q.blockdevAddBaseArgs(driver, blockDevice)
|
||||
|
||||
blockdevArgs["cache"] = map[string]interface{}{
|
||||
"direct": direct,
|
||||
|
@ -400,8 +400,13 @@ func TestQMPBlockdevAdd(t *testing.T) {
|
||||
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||
q.version = checkVersion(t, connectedCh)
|
||||
err := q.ExecuteBlockdevAdd(context.Background(), "/dev/rbd0",
|
||||
fmt.Sprintf("drive_%s", volumeUUID), false)
|
||||
dev := BlockDevice{
|
||||
ID: fmt.Sprintf("drive_%s", volumeUUID),
|
||||
File: "/dev/rbd0",
|
||||
ReadOnly: false,
|
||||
AIO: Native,
|
||||
}
|
||||
err := q.ExecuteBlockdevAdd(context.Background(), &dev)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
@ -424,8 +429,13 @@ func TestQMPBlockdevAddWithCache(t *testing.T) {
|
||||
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||
q.version = checkVersion(t, connectedCh)
|
||||
err := q.ExecuteBlockdevAddWithCache(context.Background(), "/dev/rbd0",
|
||||
fmt.Sprintf("drive_%s", volumeUUID), true, true, false)
|
||||
dev := BlockDevice{
|
||||
ID: fmt.Sprintf("drive_%s", volumeUUID),
|
||||
File: "/dev/rbd0",
|
||||
ReadOnly: false,
|
||||
AIO: Native,
|
||||
}
|
||||
err := q.ExecuteBlockdevAddWithCache(context.Background(), &dev, true, true)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
|
@ -1292,13 +1292,19 @@ func (q *qemu) hotplugAddBlockDevice(ctx context.Context, drive *config.BlockDri
|
||||
return nil
|
||||
}
|
||||
|
||||
aio := q.config.BlockDeviceAIO
|
||||
qblkDevice := govmmQemu.BlockDevice{
|
||||
ID: drive.ID,
|
||||
File: drive.File,
|
||||
ReadOnly: drive.ReadOnly,
|
||||
AIO: govmmQemu.BlockDeviceAIO(q.config.BlockDeviceAIO),
|
||||
}
|
||||
|
||||
if drive.Swap {
|
||||
err = q.qmpMonitorCh.qmp.ExecuteBlockdevAddWithDriverCache(q.qmpMonitorCh.ctx, "file", drive.File, drive.ID, aio, false, false, false)
|
||||
err = q.qmpMonitorCh.qmp.ExecuteBlockdevAddWithDriverCache(q.qmpMonitorCh.ctx, "file", &qblkDevice, false, false)
|
||||
} else if q.config.BlockDeviceCacheSet {
|
||||
err = q.qmpMonitorCh.qmp.ExecuteBlockdevAddWithCache(q.qmpMonitorCh.ctx, drive.File, drive.ID, aio, q.config.BlockDeviceCacheDirect, q.config.BlockDeviceCacheNoflush, drive.ReadOnly)
|
||||
err = q.qmpMonitorCh.qmp.ExecuteBlockdevAddWithCache(q.qmpMonitorCh.ctx, &qblkDevice, q.config.BlockDeviceCacheDirect, q.config.BlockDeviceCacheNoflush)
|
||||
} else {
|
||||
err = q.qmpMonitorCh.qmp.ExecuteBlockdevAdd(q.qmpMonitorCh.ctx, drive.File, drive.ID, aio, drive.ReadOnly)
|
||||
err = q.qmpMonitorCh.qmp.ExecuteBlockdevAdd(q.qmpMonitorCh.ctx, &qblkDevice)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user