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")