fix(host,glance): qemuimg convert optimize, allow write out of order and increase coroutines (#21373)

This commit is contained in:
wanyaoqi
2024-10-12 10:01:23 +08:00
committed by GitHub
parent 123b51a321
commit a266f4ccc2
+33
View File
@@ -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")