diff --git a/drives.go b/drives.go index e41a8424..c0f984bd 100644 --- a/drives.go +++ b/drives.go @@ -110,3 +110,12 @@ func WithCacheType(cacheType string) DriveOpt { d.CacheType = String(cacheType) } } + +// WithIoEngine sets the io engine of the drive +// Defaults to Sync, Async is in developer preview at the moment +// https://github.com/firecracker-microvm/firecracker/blob/v1.1.0/docs/api_requests/block-io-engine.md +func WithIoEngine(ioEngine string) DriveOpt { + return func(d *models.Drive) { + d.IoEngine = String(ioEngine) + } +} diff --git a/drives_test.go b/drives_test.go index 9cb2dd14..f16d20b0 100644 --- a/drives_test.go +++ b/drives_test.go @@ -155,3 +155,23 @@ func TestDrivesBuilderAddDrive(t *testing.T) { t.Errorf("expected drives %+v\n, but received %+v", e, a) } } + +func TestDrivesBuilderWithIoEngine(t *testing.T) { + expectedPath := "/path/to/rootfs" + expectedVal := "Async" + expectedDrives := []models.Drive{ + { + DriveID: String(rootDriveName), + PathOnHost: &expectedPath, + IsRootDevice: Bool(true), + IsReadOnly: Bool(false), + IoEngine: &expectedVal, + }, + } + + drives := NewDrivesBuilder(expectedPath).WithRootDrive(expectedPath, + WithDriveID(string(rootDriveName)), WithIoEngine(expectedVal)).Build() + if e, a := expectedDrives, drives; !reflect.DeepEqual(e, a) { + t.Errorf("expected drives %+v, but received %+v", e, a) + } +}