mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
bugfix:
- storage cache iso - guest start on host
This commit is contained in:
@@ -41,15 +41,12 @@ func (self *GuestInsertIsoTask) prepareIsoImage(ctx context.Context, obj db.ISta
|
||||
guest := obj.(*models.SGuest)
|
||||
imageId, _ := self.Params.GetString("image_id")
|
||||
db.OpsLog.LogEvent(obj, db.ACT_ISO_PREPARING, imageId, self.UserCred)
|
||||
var host *models.SHost
|
||||
if self.Params.Contains("host_id") {
|
||||
hostId, _ := self.Params.GetString("host_id")
|
||||
iHost, _ := models.HostManager.FetchById(hostId)
|
||||
host = iHost.(*models.SHost)
|
||||
} else {
|
||||
host = guest.GetHost()
|
||||
}
|
||||
storageCache := host.GetLocalStoragecache()
|
||||
|
||||
disks := guest.GetDisks()
|
||||
disk := disks[0].GetDisk()
|
||||
storage := disk.GetStorage()
|
||||
storageCache := storage.GetStoragecache()
|
||||
|
||||
if storageCache != nil {
|
||||
self.SetStage("OnIsoPrepareComplete", nil)
|
||||
storageCache.StartImageCacheTask(ctx, self.UserCred, imageId, "iso", false, self.GetTaskId())
|
||||
|
||||
@@ -44,10 +44,11 @@ func init() {
|
||||
}
|
||||
|
||||
type SKVMGuestDisk struct {
|
||||
imagePath string
|
||||
nbdDev string
|
||||
partitions []*guestfs.SKVMGuestDiskPartition
|
||||
lvms []*SKVMGuestLVMPartition
|
||||
imagePath string
|
||||
nbdDev string
|
||||
partitions []*guestfs.SKVMGuestDiskPartition
|
||||
lvms []*SKVMGuestLVMPartition
|
||||
acquiredLvm bool
|
||||
|
||||
imageRootBackFilePath string
|
||||
}
|
||||
@@ -208,6 +209,7 @@ func (d *SKVMGuestDisk) connectionPrecheck() int {
|
||||
pathType := lvmTool.GetPathType(d.rootImagePath())
|
||||
if pathType == LVM_PATH || pathType == PATH_TYPE_UNKNOWN {
|
||||
lvmTool.Acquire(d.rootImagePath())
|
||||
d.acquiredLvm = true
|
||||
}
|
||||
return pathType
|
||||
}
|
||||
@@ -219,7 +221,7 @@ func (d *SKVMGuestDisk) LvmDisconnectNotify() {
|
||||
}
|
||||
}()
|
||||
pathType := lvmTool.GetPathType(d.rootImagePath())
|
||||
if pathType != NON_LVM_PATH {
|
||||
if d.acquiredLvm || pathType != NON_LVM_PATH {
|
||||
lvmTool.Release(d.rootImagePath())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,28 +53,22 @@ func (s *SLVMImageConnectUniqueToolSet) CacheNonLvmImagePath(imagePath string) {
|
||||
s.lock.Lock()
|
||||
s.nonLvms[imagePath] = struct{}{}
|
||||
s.lock.Unlock()
|
||||
s.Release(imagePath)
|
||||
}
|
||||
|
||||
func (s *SLVMImageConnectUniqueToolSet) GetPathType(imagePath string) int {
|
||||
if _, ok := s.nonLvms[imagePath]; ok {
|
||||
return NON_LVM_PATH
|
||||
}
|
||||
if _, ok := s.lvms[imagePath]; ok {
|
||||
return LVM_PATH
|
||||
} else if _, ok := s.nonLvms[imagePath]; ok {
|
||||
return NON_LVM_PATH
|
||||
} else {
|
||||
return PATH_TYPE_UNKNOWN
|
||||
}
|
||||
return PATH_TYPE_UNKNOWN
|
||||
}
|
||||
|
||||
func (s *SLVMImageConnectUniqueToolSet) Release(imagePath string) {
|
||||
if _, ok := s.lvms[imagePath]; ok {
|
||||
s.lvms[imagePath].Unlock()
|
||||
}
|
||||
s.lock.Lock()
|
||||
if _, ok := s.nonLvms[imagePath]; ok {
|
||||
delete(s.lvms, imagePath)
|
||||
}
|
||||
s.lock.Unlock()
|
||||
}
|
||||
|
||||
func (s *SLVMImageConnectUniqueToolSet) Acquire(imagePath string) {
|
||||
|
||||
@@ -541,8 +541,7 @@ func (m *SGuestManager) CanMigrate(sid string) bool {
|
||||
func (m *SGuestManager) GetFreePortByBase(basePort int) int {
|
||||
var port = 1
|
||||
for {
|
||||
if netutils2.IsTcpPortUsed("0.0.0.0", basePort+port) ||
|
||||
netutils2.IsTcpPortUsed("127.0.0.1", basePort+port) {
|
||||
if netutils2.IsTcpPortUsed("0.0.0.0", basePort+port) {
|
||||
port += 1
|
||||
} else {
|
||||
return basePort + port
|
||||
|
||||
@@ -57,14 +57,12 @@ func GetFreePort() (int, error) {
|
||||
}
|
||||
|
||||
func IsTcpPortUsed(addr string, port int) bool {
|
||||
conn, _ := net.Dial("tcp", fmt.Sprintf("%s:%d", addr, port))
|
||||
if conn != nil {
|
||||
conn.Close()
|
||||
log.Infof("Tcp port in use: %s %d", addr, port)
|
||||
server, err := net.Listen("tcp", fmt.Sprintf("%s:%d", addr, port))
|
||||
if err != nil {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
server.Close()
|
||||
return false
|
||||
}
|
||||
|
||||
// MyIP returns source ip used to communicate with udp:114.114.114.114:53
|
||||
|
||||
Reference in New Issue
Block a user