fix(region,host): add auto merge snapshots options, preallocation options (#22715)

This commit is contained in:
wanyaoqi
2025-06-13 15:20:28 +08:00
committed by GitHub
parent b8685af42c
commit a6c9fddc2c
9 changed files with 65 additions and 22 deletions
+1 -1
View File
@@ -129,7 +129,7 @@ func init() {
cmd.BatchPerform("stop-rescue", &options.ServerStartOptions{})
cmd.BatchPerform("sync-os-info", &options.ServerIdsOptions{})
cmd.BatchPerform("set-root-disk-matcher", &options.ServerSetRootDiskMatcher{})
cmd.Perform("disable-auto-merge-snapshot", &options.ServerDisableAutoMergeSnapshot{})
cmd.Get("vnc", new(options.ServerVncOptions))
cmd.Get("desc", new(options.ServerIdOptions))
cmd.Get("status", new(options.ServerIdOptions))
+17 -16
View File
@@ -316,22 +316,23 @@ const (
VM_AZURE_DEFAULT_LOGIN_USER = compute.VM_AZURE_DEFAULT_LOGIN_USER
VM_ZSTACK_DEFAULT_LOGIN_USER = compute.VM_ZSTACK_DEFAULT_LOGIN_USER
VM_METADATA_APP_TAGS = "app_tags"
VM_METADATA_CREATE_PARAMS = "create_params"
VM_METADATA_LOGIN_ACCOUNT = "login_account"
VM_METADATA_LOGIN_KEY = "login_key"
VM_METADATA_LAST_LOGIN_KEY = "last_login_key"
VM_METADATA_LOGIN_KEY_TIMESTAMP = "login_key_timestamp"
VM_METADATA_OS_ARCH = "os_arch"
VM_METADATA_OS_DISTRO = "os_distribution"
VM_METADATA_OS_NAME = "os_name"
VM_METADATA_OS_VERSION = "os_version"
VM_METADATA_CGROUP_CPUSET = "cgroup_cpuset"
VM_METADATA_ENABLE_MEMCLEAN = "enable_memclean"
VM_METADATA_HOTPLUG_CPU_MEM = "hotplug_cpu_mem"
VM_METADATA_HOT_REMOVE_NIC = "hot_remove_nic"
VM_METADATA_START_VMEM_MB = "start_vmem_mb"
VM_METADATA_START_VCPU_COUNT = "start_vcpu_count"
VM_METADATA_APP_TAGS = "app_tags"
VM_METADATA_CREATE_PARAMS = "create_params"
VM_METADATA_LOGIN_ACCOUNT = "login_account"
VM_METADATA_LOGIN_KEY = "login_key"
VM_METADATA_LAST_LOGIN_KEY = "last_login_key"
VM_METADATA_LOGIN_KEY_TIMESTAMP = "login_key_timestamp"
VM_METADATA_OS_ARCH = "os_arch"
VM_METADATA_OS_DISTRO = "os_distribution"
VM_METADATA_OS_NAME = "os_name"
VM_METADATA_OS_VERSION = "os_version"
VM_METADATA_CGROUP_CPUSET = "cgroup_cpuset"
VM_METADATA_ENABLE_MEMCLEAN = "enable_memclean"
VM_METADATA_HOTPLUG_CPU_MEM = "hotplug_cpu_mem"
VM_METADATA_HOT_REMOVE_NIC = "hot_remove_nic"
VM_METADATA_START_VMEM_MB = "start_vmem_mb"
VM_METADATA_START_VCPU_COUNT = "start_vcpu_count"
VM_METADATA_DISABLE_AUTO_MERGE_SNAPSHOT = "disable_auto_merge_snapshot"
VM_METADATA_RELEASED_DEVICES = "released_devices"
+1
View File
@@ -166,6 +166,7 @@ type HostCommonOptions struct {
ExecutorConnectTimeoutSeconds int `help:"executor client connection timeout in seconds, default is 30" default:"30"`
ImageDeployDriver string `help:"Image deploy driver" default:"qemu-kvm" choices:"qemu-kvm|nbd|libguestfs"`
DeployConcurrent int `help:"qemu-kvm deploy driver concurrent" default:"5"`
Qcow2Preallocation string `help:"Qcow2 image create preallocation" default:"metadata" choices:"disable|metadata|falloc|full"`
}
type DBOptions struct {
+6 -2
View File
@@ -2435,8 +2435,7 @@ func (self *SGuest) attachIsolatedDevice(ctx context.Context, userCred mcclient.
if len(dev.GuestId) > 0 {
return fmt.Errorf("Isolated device already attached to another guest: %s", dev.GuestId)
}
if dev.HostId !=
self.HostId {
if dev.HostId != self.HostId {
return fmt.Errorf("Isolated device and guest are not located in the same host")
}
drv, _ := self.GetDriver()
@@ -6784,3 +6783,8 @@ func (self *SGuest) StartChangeBillingTypeTask(ctx context.Context, userCred mcc
}
return task.ScheduleRun(nil)
}
func (self *SGuest) PerformDisableAutoMergeSnapshots(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
disableAutoMergeSnapshot := jsonutils.QueryBoolean(data, "disable_auto_merge_snapshot", false)
return nil, self.SetMetadata(ctx, api.VM_METADATA_DISABLE_AUTO_MERGE_SNAPSHOT, disableAutoMergeSnapshot, userCred)
}
+3
View File
@@ -2840,6 +2840,9 @@ func (s *SKVMGuestInstance) allocGuestNumaCpuset() error {
}
func (s *SKVMGuestInstance) GetNeedMergeBackingFileDiskIndexs() []int {
if s.isDisableAutoMergeSnapshots() {
return nil
}
res := make([]int, 0)
for _, disk := range s.Desc.Disks {
if disk.MergeSnapshot {
+5 -1
View File
@@ -234,7 +234,11 @@ func (s *SKVMGuestInstance) isWindows10() bool {
}
func (s *SKVMGuestInstance) isMemcleanEnabled() bool {
return s.Desc.Metadata["enable_memclean"] == "true"
return s.Desc.Metadata[api.VM_METADATA_ENABLE_MEMCLEAN] == "true"
}
func (s *SKVMGuestInstance) isDisableAutoMergeSnapshots() bool {
return s.Desc.Metadata[api.VM_METADATA_DISABLE_AUTO_MERGE_SNAPSHOT] == "true"
}
func (s *SKVMGuestInstance) getMachine() string {
+5
View File
@@ -40,6 +40,7 @@ import (
"yunion.io/x/onecloud/pkg/hostman/storageman/storagehandler"
losetupman "yunion.io/x/onecloud/pkg/util/losetup/manager"
"yunion.io/x/onecloud/pkg/util/procutils"
"yunion.io/x/onecloud/pkg/util/qemuimg"
"yunion.io/x/onecloud/pkg/util/sysutils"
)
@@ -78,6 +79,10 @@ func (host *SHostService) RunService() {
cronManager := cronman.InitCronJobManager(false, options.HostOptions.CronJobWorkerCount, options.HostOptions.TimeZone)
hostutils.Init()
if err := qemuimg.SetPreallocation(options.HostOptions.Qcow2Preallocation); err != nil {
log.Fatalf("failed set qemuimg preallocation to %s: %s", options.HostOptions.Qcow2Preallocation, err)
}
hostInstance := hostinfo.Instance()
if err := hostInstance.Init(app.GetContext()); err != nil {
log.Fatalf("Host instance init error: %v", err)
+10
View File
@@ -851,6 +851,16 @@ func (o *ServerModifySrcCheckOptions) Description() string {
return "Modify src ip, mac check settings"
}
type ServerDisableAutoMergeSnapshot struct {
ServerIdOptions
DisableAutoMergeSnapshot bool `help:"Disable auto merge snapshots"`
}
func (o *ServerDisableAutoMergeSnapshot) Params() (jsonutils.JSONObject, error) {
return options.StructToParams(o)
}
type ServerSendKeyOptions struct {
ID string `help:"ID or Name of server" metavar:"Guest" json:"-"`
KEYS string `help:"Special keys to send, eg. ctrl, alt, f12, shift, etc, separated by \"-\""`
+17 -2
View File
@@ -67,6 +67,19 @@ const (
const DefaultConvertCorutines = 8
var preallocation = "metadata"
func SetPreallocation(prealloc string) error {
if !utils.IsInStringArray(prealloc, []string{"", "disable", "metadata", "falloc", "full"}) {
return errors.Errorf("unsupported preallocation %s", prealloc)
}
if prealloc == "disable" {
prealloc = ""
}
preallocation = prealloc
return nil
}
type SQemuImage struct {
Path string
Password string
@@ -739,8 +752,10 @@ func (img *SQemuImage) CreateQcow2(sizeMB int, compact bool, backPath string, pa
}
} else if !compact {
sparseOpts := qcow2SparseOptions()
if sizeMB <= 1024*1024*4 {
options = append(options, "preallocation=metadata")
if preallocation != "" {
if sizeMB <= 1024*1024*4 {
options = append(options, fmt.Sprintf("preallocation=%s", preallocation))
}
}
options = append(options, sparseOpts...)
}