From 80f8cdf14a0e13b123777a8967ab4fb34c1ebfe9 Mon Sep 17 00:00:00 2001 From: Daichi Sakaue Date: Tue, 21 Jul 2020 16:05:51 +0900 Subject: [PATCH] Fix aio option when volume cache parameter is specified Signed-off-by: Daichi Sakaue --- mtest/cluster.yml | 4 ++++ mtest/volume.go | 11 ++++++++--- node_volume.go | 13 ++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/mtest/cluster.yml b/mtest/cluster.yml index ada6373a..e69c4d61 100644 --- a/mtest/cluster.yml +++ b/mtest/cluster.yml @@ -37,6 +37,10 @@ volumes: name: raw-raw size: 5G format: raw +- kind: raw + name: raw-writeback + size: 5G + cache: writeback - kind: @KIND_LV@ name: lv size: 5G diff --git a/mtest/volume.go b/mtest/volume.go index 2d9929f7..d8e84d53 100644 --- a/mtest/volume.go +++ b/mtest/volume.go @@ -26,13 +26,18 @@ func TestVolume() { Expect(err).To(Succeed()) }) + By("writing to vde (raw volume, qcow2 format, cache=writeback)", func() { + _, _, err := execAt(node1, "sudo", "dd", "if=/dev/zero", "of=/dev/vde", "bs=1M", "count=1") + Expect(err).To(Succeed()) + }) + if vg != "" { - By("writing to vde (lv volume)", func() { - _, _, err := execAt(node1, "sudo", "dd", "if=/dev/zero", "of=/dev/vde", "bs=1M", "count=1") + By("writing to vdf (lv volume)", func() { + _, _, err := execAt(node1, "sudo", "dd", "if=/dev/zero", "of=/dev/vdf", "bs=1M", "count=1") Expect(err).To(Succeed()) }) } else { - By("skipping test for vde (lv volume)") + By("skipping test for vdf (lv volume)") } By("terminating placemat", func() { diff --git a/node_volume.go b/node_volume.go index 38a46cfd..3eb6603b 100644 --- a/node_volume.go +++ b/node_volume.go @@ -46,6 +46,13 @@ const ( nodeVolumeFormatRaw = "raw" ) +func selectAIOforCache(cache string) string { + if cache == nodeVolumeCacheNone { + return "native" + } + return "threads" +} + type baseVolume struct { name string cache string @@ -62,7 +69,7 @@ func volumePath(dataDir, name string) string { func (v baseVolume) qemuArgs(p string) []string { return []string{ "-drive", - fmt.Sprintf("if=virtio,cache=%s,aio=native,file=%s", v.cache, p), + fmt.Sprintf("if=virtio,cache=%s,aio=%s,file=%s", v.cache, selectAIOforCache(v.cache), p), } } @@ -250,7 +257,7 @@ func (v *rawVolume) Create(ctx context.Context, dataDir string) ([]string, error func (v *rawVolume) qemuArgs(p string) []string { return []string{ "-drive", - fmt.Sprintf("if=virtio,cache=%s,aio=native,format=%s,file=%s", v.cache, v.format, p), + fmt.Sprintf("if=virtio,cache=%s,aio=%s,format=%s,file=%s", v.cache, selectAIOforCache(v.cache), v.format, p), } } @@ -311,7 +318,7 @@ func (v *lvVolume) Create(ctx context.Context, dataDir string) ([]string, error) func (v *lvVolume) qemuArgs(p string) []string { return []string{ "-drive", - fmt.Sprintf("if=virtio,cache=%s,aio=native,format=raw,file=%s", v.cache, p), + fmt.Sprintf("if=virtio,cache=%s,aio=%s,format=raw,file=%s", v.cache, selectAIOforCache(v.cache), p), } }