mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
Merge pull request #977 from wanyaoqi/bugfix/wyq/fix-glance-notify
Bugfix/wyq/fix glance notify
This commit is contained in:
@@ -63,15 +63,17 @@ func (d *SKVMGuestDisk) IsLVMPartition() bool {
|
||||
return len(d.lvms) > 0
|
||||
}
|
||||
|
||||
func (d *SKVMGuestDisk) Connect() bool {
|
||||
func (d *SKVMGuestDisk) ConnectWithoutDetectLvm() bool {
|
||||
return d.connect()
|
||||
}
|
||||
|
||||
func (d *SKVMGuestDisk) connect() bool {
|
||||
d.nbdDev = nbd.GetNBDManager().AcquireNbddev()
|
||||
if len(d.nbdDev) == 0 {
|
||||
log.Errorln("Cannot get nbd device")
|
||||
return false
|
||||
}
|
||||
|
||||
pathType := d.connectionPrecheck()
|
||||
|
||||
var cmd []string
|
||||
if strings.HasPrefix(d.imagePath, "rbd:") || d.getImageFormat() == "raw" {
|
||||
//qemu-nbd 连接ceph时 /etc/ceph/ceph.conf 必须存在
|
||||
@@ -109,6 +111,15 @@ func (d *SKVMGuestDisk) Connect() bool {
|
||||
}
|
||||
tried += 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (d *SKVMGuestDisk) Connect() bool {
|
||||
pathType := d.connectionPrecheck()
|
||||
|
||||
if d.connect() == false {
|
||||
return false
|
||||
}
|
||||
|
||||
if pathType == LVM_PATH {
|
||||
d.setupLVMS()
|
||||
@@ -250,24 +261,33 @@ func (d *SKVMGuestDisk) PutdownLVMs() {
|
||||
d.lvms = []*SKVMGuestLVMPartition{}
|
||||
}
|
||||
|
||||
func (d *SKVMGuestDisk) DisconnectWithoutLvm() bool {
|
||||
return d.disconnect()
|
||||
}
|
||||
|
||||
func (d *SKVMGuestDisk) Disconnect() bool {
|
||||
if len(d.nbdDev) > 0 {
|
||||
defer d.LvmDisconnectNotify()
|
||||
d.PutdownLVMs()
|
||||
_, err := procutils.NewCommand(qemutils.GetQemuNbd(), "-d", d.nbdDev).Run()
|
||||
if err != nil {
|
||||
log.Errorln(err.Error())
|
||||
return false
|
||||
}
|
||||
nbd.GetNBDManager().ReleaseNbddev(d.nbdDev)
|
||||
d.nbdDev = ""
|
||||
d.partitions = d.partitions[len(d.partitions):]
|
||||
return true
|
||||
return d.disconnect()
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (d *SKVMGuestDisk) disconnect() bool {
|
||||
_, err := procutils.NewCommand(qemutils.GetQemuNbd(), "-d", d.nbdDev).Run()
|
||||
if err != nil {
|
||||
log.Errorln(err.Error())
|
||||
return false
|
||||
}
|
||||
nbd.GetNBDManager().ReleaseNbddev(d.nbdDev)
|
||||
d.nbdDev = ""
|
||||
d.partitions = d.partitions[len(d.partitions):]
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
func (d *SKVMGuestDisk) DetectIsUEFISupport(rootfs fsdriver.IRootFsDriver) bool {
|
||||
for i := 0; i < len(d.partitions); i++ {
|
||||
if d.partitions[i].IsMounted() {
|
||||
|
||||
@@ -370,7 +370,7 @@ func (self *SImage) saveSuccess(userCred mcclient.TokenCredential, msg string) {
|
||||
|
||||
func (self *SImage) saveFailed(userCred mcclient.TokenCredential, msg string) {
|
||||
log.Errorf(msg)
|
||||
self.SetStatus(userCred, api.IMAGE_STATUS_QUEUED, msg)
|
||||
self.SetStatus(userCred, api.IMAGE_STATUS_KILLED, msg)
|
||||
db.OpsLog.LogEvent(self, db.ACT_SAVE_FAIL, msg, userCred)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/cronman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
|
||||
"yunion.io/x/onecloud/pkg/hostman/storageman/nbd"
|
||||
"yunion.io/x/onecloud/pkg/image/models"
|
||||
"yunion.io/x/onecloud/pkg/image/options"
|
||||
_ "yunion.io/x/onecloud/pkg/image/tasks"
|
||||
@@ -103,6 +104,8 @@ func StartService() {
|
||||
|
||||
go models.CheckImages()
|
||||
|
||||
nbd.Init() // init nbd module for image probe
|
||||
|
||||
cron := cronman.GetCronJobManager(true)
|
||||
cron.AddJob1("CleanPendingDeleteImages", time.Duration(options.Options.PendingDeleteCheckSeconds)*time.Second, models.ImageManager.CleanPendingDeleteImages)
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ func (self *ImageProbeTask) StartImageProbe(ctx context.Context, image *models.S
|
||||
func (self *ImageProbeTask) doProbe(ctx context.Context, image *models.SImage) error {
|
||||
diskPath := image.GetPath("")
|
||||
kvmDisk := storageman.NewKVMGuestDisk(diskPath)
|
||||
defer kvmDisk.Disconnect()
|
||||
if !kvmDisk.Connect() {
|
||||
defer kvmDisk.DisconnectWithoutLvm()
|
||||
if !kvmDisk.ConnectWithoutDetectLvm() {
|
||||
return fmt.Errorf("Disk connector failed to connect image")
|
||||
}
|
||||
|
||||
@@ -144,10 +144,10 @@ type sImageInfo struct {
|
||||
func (self *ImageProbeTask) getImageInfo(kvmDisk *storageman.SKVMGuestDisk, rootfs fsdriver.IRootFsDriver) *sImageInfo {
|
||||
partition := rootfs.GetPartition()
|
||||
return &sImageInfo{
|
||||
osInfo: rootfs.GetReleaseInfo(partition),
|
||||
OsType: rootfs.GetOs(),
|
||||
IsUEFISupport: kvmDisk.DetectIsUEFISupport(rootfs),
|
||||
IsLVMPartition: kvmDisk.IsLVMPartition(),
|
||||
osInfo: rootfs.GetReleaseInfo(partition),
|
||||
OsType: rootfs.GetOs(),
|
||||
IsUEFISupport: kvmDisk.DetectIsUEFISupport(rootfs),
|
||||
// IsLVMPartition: kvmDisk.IsLVMPartition(),
|
||||
IsReadonly: partition.IsReadonly(),
|
||||
PhysicalPartitionType: partition.GetPhysicalPartitionType(),
|
||||
IsInstalledCloudInit: rootfs.IsCloudinitInstall(),
|
||||
@@ -155,7 +155,7 @@ func (self *ImageProbeTask) getImageInfo(kvmDisk *storageman.SKVMGuestDisk, root
|
||||
}
|
||||
|
||||
func (self *ImageProbeTask) OnProbeFailed(ctx context.Context, image *models.SImage, reason string) {
|
||||
log.Infof("Image %s Probe Failed ...", image.Name)
|
||||
log.Infof("Image %s Probe Failed: %s", image.Name, reason)
|
||||
db.OpsLog.LogEvent(image, db.ACT_PROBE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithContext(ctx, image, logclient.ACT_IMAGE_PROBE, reason, self.UserCred, false)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user