From a266f4ccc2ba7f156b4460849677c8f244148069 Mon Sep 17 00:00:00 2001 From: wanyaoqi <18528551+wanyaoqi@users.noreply.github.com> Date: Sat, 12 Oct 2024 10:01:23 +0800 Subject: [PATCH] fix(host,glance): qemuimg convert optimize, allow write out of order and increase coroutines (#21373) --- pkg/util/qemuimg/qemuimg.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pkg/util/qemuimg/qemuimg.go b/pkg/util/qemuimg/qemuimg.go index 182b88b060..d57214b5b4 100644 --- a/pkg/util/qemuimg/qemuimg.go +++ b/pkg/util/qemuimg/qemuimg.go @@ -37,8 +37,23 @@ import ( var ( ErrUnsupportedFormat = errors.Error("unsupported format") + + convertWorkInOrder = false + convertCoroutines = 16 ) +func SetConvertWorkInOrder(workInOrder bool) { + convertWorkInOrder = workInOrder +} + +func SetConvertCoroutines(coroutines int) error { + if coroutines < 1 || coroutines > 16 { + return errors.Errorf("coroutines %d out of range 1-16", coroutines) + } + convertCoroutines = coroutines + return nil +} + type TIONiceLevel int const ( @@ -49,6 +64,8 @@ const ( IONiceIdle = TIONiceLevel(3) ) +const DefaultConvertCorutines = 8 + type SQemuImage struct { Path string Password string @@ -340,6 +357,14 @@ func convertOther(srcInfo, destInfo SImageInfo, compact bool, workerOpions []str } else { cmdline = append(cmdline, workerOpions...) } + + if !utils.IsInStringArray("-W", workerOpions) && !convertWorkInOrder { + cmdline = append(cmdline, "-W") + } + if !utils.IsInStringArray("-m", workerOpions) && convertCoroutines != DefaultConvertCorutines { + cmdline = append(cmdline, "-m", strconv.Itoa(convertCoroutines)) + } + if compact { cmdline = append(cmdline, "-c") } @@ -392,6 +417,14 @@ func convertEncrypt(srcInfo, destInfo SImageInfo, compact bool, workerOpions []s } else { cmdline = append(cmdline, workerOpions...) } + + if !utils.IsInStringArray("-W", workerOpions) && !convertWorkInOrder { + cmdline = append(cmdline, "-W") + } + if !utils.IsInStringArray("-m", workerOpions) && convertCoroutines != DefaultConvertCorutines { + cmdline = append(cmdline, "-m", strconv.Itoa(convertCoroutines)) + } + if srcInfo.Encrypted() { if srcInfo.Format != qemuimgfmt.QCOW2 { return errors.Wrap(errors.ErrNotSupported, "source image not support encryption")