From ffdf7a3a6e992470d2da95ddcdf7b995216e49fc Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Tue, 3 Jun 2025 13:39:30 +0800 Subject: [PATCH] fix(host): losetup package initialization order (#22652) --- pkg/hostman/host_services.go | 2 ++ pkg/util/losetup/manager/manager.go | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/hostman/host_services.go b/pkg/hostman/host_services.go index 0d35881f5f..b46663e078 100644 --- a/pkg/hostman/host_services.go +++ b/pkg/hostman/host_services.go @@ -38,6 +38,7 @@ import ( "yunion.io/x/onecloud/pkg/hostman/storageman" "yunion.io/x/onecloud/pkg/hostman/storageman/diskhandlers" "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/sysutils" ) @@ -67,6 +68,7 @@ func (host *SHostService) InitService() { execlient.SetTimeoutSeconds(options.HostOptions.ExecutorConnectTimeoutSeconds) procutils.SetRemoteExecutor() } + losetupman.Init() } func (host *SHostService) OnExitService() {} diff --git a/pkg/util/losetup/manager/manager.go b/pkg/util/losetup/manager/manager.go index 536cbd8f4c..66ee31950b 100644 --- a/pkg/util/losetup/manager/manager.go +++ b/pkg/util/losetup/manager/manager.go @@ -15,6 +15,8 @@ package manager import ( + "sync" + "yunion.io/x/jsonutils" "yunion.io/x/log" "yunion.io/x/pkg/errors" @@ -22,10 +24,18 @@ import ( "yunion.io/x/onecloud/pkg/util/losetup" ) -var managerObj iManager +var ( + managerObj iManager + managerInitLock sync.Mutex +) -func init() { - managerObj = newManager() +func Init() { + managerInitLock.Lock() + defer managerInitLock.Unlock() + + if managerObj == nil { + managerObj = newManager() + } } func ListDevices() (*losetup.Devices, error) {