mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(host,glance): qemuimg convert optimize, allow write out of order and increase coroutines (#21373)
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user