mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Automatic merge from release/2.6.0 -> release/2.7.0
* commit '842af422f9572bb80cffae3e0982fe92e14c2de7': fix online resize task fix deploy bugs
This commit is contained in:
@@ -723,7 +723,12 @@ func (self *SDisk) PerformResize(ctx context.Context, userCred mcclient.TokenCre
|
||||
if err := QuotaManager.CheckSetPendingQuota(ctx, userCred, userCred.GetProjectId(), &pendingUsage); err != nil {
|
||||
return nil, httperrors.NewOutOfQuotaError(err.Error())
|
||||
}
|
||||
return nil, self.StartDiskResizeTask(ctx, userCred, int64(sizeMb), "", &pendingUsage, nil)
|
||||
|
||||
guests := self.GetGuests()
|
||||
if len(guests) != 1 {
|
||||
return nil, httperrors.NewBadRequestError("Cann't resize disk when attach to mutil guest")
|
||||
}
|
||||
return nil, self.StartDiskResizeTask(ctx, userCred, int64(sizeMb), "", &pendingUsage, &guests[0])
|
||||
}
|
||||
|
||||
func (self *SDisk) GetIStorage() (cloudprovider.ICloudStorage, error) {
|
||||
|
||||
@@ -104,10 +104,11 @@ const (
|
||||
VM_SYNC_CONFIG = "sync_config"
|
||||
VM_SYNC_FAIL = "sync_fail"
|
||||
|
||||
VM_RESIZE_DISK = "resize_disk"
|
||||
VM_START_SAVE_DISK = "start_save_disk"
|
||||
VM_SAVE_DISK = "save_disk"
|
||||
VM_SAVE_DISK_FAILED = "save_disk_failed"
|
||||
VM_RESIZE_DISK = "resize_disk"
|
||||
VM_RESIZE_DISK_FAILED = "resize_disk_fail"
|
||||
VM_START_SAVE_DISK = "start_save_disk"
|
||||
VM_SAVE_DISK = "save_disk"
|
||||
VM_SAVE_DISK_FAILED = "save_disk_failed"
|
||||
|
||||
VM_RESTORING_SNAPSHOT = "restoring_snapshot"
|
||||
VM_RESTORE_DISK = "restore_disk"
|
||||
|
||||
@@ -48,16 +48,14 @@ func (self *DiskResizeTask) OnInit(ctx context.Context, obj db.IStandaloneModel,
|
||||
|
||||
disk.SetStatus(self.GetUserCred(), models.DISK_START_RESIZE, "")
|
||||
if masterGuest == nil {
|
||||
for _, guest := range disk.GetGuests() {
|
||||
guest.SetStatus(self.GetUserCred(), models.VM_RESIZE_DISK, "")
|
||||
}
|
||||
masterGuest.SetStatus(self.GetUserCred(), models.VM_RESIZE_DISK, "")
|
||||
}
|
||||
self.StartResizeDisk(ctx, host, storage, disk, masterGuest)
|
||||
}
|
||||
|
||||
func (self *DiskResizeTask) StartResizeDisk(ctx context.Context, host *models.SHost, storage *models.SStorage, disk *models.SDisk, guest *models.SGuest) {
|
||||
log.Infof("Resizing disk on host %s ...", host.GetName())
|
||||
self.SetStage("on_disk_resize_complete", nil)
|
||||
self.SetStage("OnDiskResizeComplete", nil)
|
||||
sizeMb, _ := self.GetParams().Int("size")
|
||||
if err := host.GetHostDriver().RequestResizeDiskOnHost(ctx, host, storage, disk, guest, sizeMb, self); err != nil {
|
||||
log.Errorf("request_resize_disk_on_host: %v", err)
|
||||
@@ -108,6 +106,21 @@ func (self *DiskResizeTask) OnDiskResizeComplete(ctx context.Context, disk *mode
|
||||
self.CleanHostSchedCache(disk)
|
||||
db.OpsLog.LogEvent(disk, db.ACT_RESIZE, disk.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, disk, logclient.ACT_RESIZE, nil, self.UserCred, true)
|
||||
self.OnDiskResized(ctx, disk)
|
||||
}
|
||||
|
||||
func (self *DiskResizeTask) OnDiskResized(ctx context.Context, disk *models.SDisk) {
|
||||
guestId, _ := self.Params.GetString("guest_id")
|
||||
if len(guestId) > 0 {
|
||||
self.SetStage("TaskComplete", nil)
|
||||
masterGuest := models.GuestManager.FetchGuestById(guestId)
|
||||
masterGuest.StartSyncTask(ctx, self.UserCred, false, self.GetId())
|
||||
} else {
|
||||
self.TaskComplete(ctx, disk, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *DiskResizeTask) TaskComplete(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, disk.GetShortDesc(ctx))
|
||||
self.finalReleasePendingUsage(ctx)
|
||||
}
|
||||
@@ -116,5 +129,10 @@ func (self *DiskResizeTask) OnDiskResizeCompleteFailed(ctx context.Context, disk
|
||||
disk.SetDiskReady(ctx, self.GetUserCred(), data.String())
|
||||
db.OpsLog.LogEvent(disk, db.ACT_RESIZE_FAIL, disk.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, disk, logclient.ACT_RESIZE, data.String(), self.UserCred, false)
|
||||
guestId, _ := self.Params.GetString("guest_id")
|
||||
if len(guestId) > 0 {
|
||||
masterGuest := models.GuestManager.FetchGuestById(guestId)
|
||||
masterGuest.SetStatus(self.UserCred, models.VM_RESIZE_DISK_FAILED, data.String())
|
||||
}
|
||||
self.SetStageFailed(ctx, data.String())
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
@@ -174,11 +175,13 @@ func diskDelete(ctx context.Context, storage storageman.IStorage, diskId string,
|
||||
}
|
||||
|
||||
func diskResize(ctx context.Context, storage storageman.IStorage, diskId string, disk storageman.IDisk, body jsonutils.JSONObject) (interface{}, error) {
|
||||
log.Errorln(body.String())
|
||||
diskInfo, err := body.Get("disk")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewMissingParameterError("disk")
|
||||
}
|
||||
serverId, _ := diskInfo.GetString("server_id")
|
||||
log.Errorln(serverId, guestman.GetGuestManager().Status(serverId))
|
||||
if len(serverId) > 0 && guestman.GetGuestManager().Status(serverId) == "running" {
|
||||
sizeMb, _ := diskInfo.Int("size")
|
||||
return guestman.GetGuestManager().OnlineResizeDisk(ctx, serverId, diskId, sizeMb)
|
||||
|
||||
@@ -181,6 +181,7 @@ func (l *sLinuxRootFs) DeployFstabScripts(rootFs IDiskPartition, disks []jsonuti
|
||||
var rec string
|
||||
var modeRwxOwner = syscall.S_IRUSR | syscall.S_IWUSR | syscall.S_IXUSR
|
||||
var fstab = fstabutils.FSTabFile(string(fstabcont))
|
||||
fstab.RemoveDevices(len(disks))
|
||||
|
||||
for i := 1; i < len(disks); i++ {
|
||||
diskId, err := disks[i].GetString("disk_id")
|
||||
@@ -190,25 +191,27 @@ func (l *sLinuxRootFs) DeployFstabScripts(rootFs IDiskPartition, disks []jsonuti
|
||||
dev := fmt.Sprintf("UUID=%s", diskId)
|
||||
if !fstab.IsExists(dev) {
|
||||
fs, _ := disks[i].GetString("fs")
|
||||
if fs == "swap" {
|
||||
rec = fmt.Sprintf("%s none %s sw 0 0", dev, fs)
|
||||
} else {
|
||||
mtPath, _ := disks[i].GetString("mountpoint")
|
||||
if len(mtPath) == 0 {
|
||||
mtPath = "/data"
|
||||
if dataDiskIdx > 0 {
|
||||
mtPath += fmt.Sprintf("%d", dataDiskIdx)
|
||||
if len(fs) > 0 {
|
||||
if fs == "swap" {
|
||||
rec = fmt.Sprintf("%s none %s sw 0 0", dev, fs)
|
||||
} else {
|
||||
mtPath, _ := disks[i].GetString("mountpoint")
|
||||
if len(mtPath) == 0 {
|
||||
mtPath = "/data"
|
||||
if dataDiskIdx > 0 {
|
||||
mtPath += fmt.Sprintf("%d", dataDiskIdx)
|
||||
}
|
||||
dataDiskIdx += 1
|
||||
}
|
||||
dataDiskIdx += 1
|
||||
}
|
||||
rec = fmt.Sprintf("%s %s %s defaults 2 2", dev, mtPath, fs)
|
||||
if !l.rootFs.Exists(mtPath, false) {
|
||||
if err := l.rootFs.Mkdir(mtPath, modeRwxOwner, false); err != nil {
|
||||
return err
|
||||
rec = fmt.Sprintf("%s %s %s defaults 2 2", dev, mtPath, fs)
|
||||
if !l.rootFs.Exists(mtPath, false) {
|
||||
if err := l.rootFs.Mkdir(mtPath, modeRwxOwner, false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
fstab.AddFsrec(rec)
|
||||
}
|
||||
fstab.AddFsrec(rec)
|
||||
}
|
||||
}
|
||||
cf := fstab.ToConf()
|
||||
|
||||
@@ -431,3 +431,31 @@ func (w *SWindowsRootFs) deploySetupCompleteScripts(uname, passwd string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *SWindowsRootFs) DeployFstabScripts(rootFs IDiskPartition, disks []jsonutils.JSONObject) error {
|
||||
if len(disks) == 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
bootScript := strings.Join([]string{
|
||||
`set MOUNT_DISK_SCRIPT=%SystemRoot%\mountdisk.bat`,
|
||||
`if exist %MOUNT_DISK_SCRIPT% (`,
|
||||
` call %MOUNT_DISK_SCRIPT%`,
|
||||
` del %MOUNT_DISK_SCRIPT%`,
|
||||
`)`,
|
||||
}, "\r\n")
|
||||
w.appendGuestBootScript(bootScript)
|
||||
logPath := w.guestDebugLogPath
|
||||
mountScript := strings.Join([]string{
|
||||
w.MakeGuestDebugCmd("mount disk step 1"),
|
||||
`cscript %SystemRoot%\mountdisk.js --debug ` + logPath,
|
||||
`del %SystemRoot%\mountdisk.js`,
|
||||
w.MakeGuestDebugCmd("mount disk step 2"),
|
||||
}, "\r\n")
|
||||
|
||||
if w.putGuestScriptContents("/windows/mountdisk.bat", mountScript) != nil {
|
||||
return nil
|
||||
}
|
||||
w.putGuestScriptContents("/windows/mountdisk.js", WinScriptMountDisk)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ type SKVMGuestInstance struct {
|
||||
Monitor monitor.Monitor
|
||||
manager *SGuestManager
|
||||
|
||||
startupTask *SGuestResumeTask
|
||||
mirrorJobSuccCount *int
|
||||
startupTask *SGuestResumeTask
|
||||
}
|
||||
|
||||
func NewKVMGuestInstance(id string, manager *SGuestManager) *SKVMGuestInstance {
|
||||
@@ -349,14 +348,11 @@ func (s *SKVMGuestInstance) onReceiveQMPEvent(event *monitor.Event) {
|
||||
if itype, ok := event.Data["type"]; ok {
|
||||
stype, _ := itype.(string)
|
||||
if stype == "mirror" {
|
||||
if s.mirrorJobSuccCount != nil {
|
||||
*s.mirrorJobSuccCount += 1
|
||||
} else {
|
||||
s.mirrorJobSuccCount = new(int)
|
||||
*s.mirrorJobSuccCount = 1
|
||||
}
|
||||
if *s.mirrorJobSuccCount >= s.DiskCount() {
|
||||
hostutils.UpdateServerStatus(context.Background(), s.GetId(), "running")
|
||||
if s.IsMirrorJobSucc() {
|
||||
_, err := hostutils.UpdateServerStatus(context.Background(), s.GetId(), "running")
|
||||
if err != nil {
|
||||
log.Errorln("onReceiveQMPEvent update server status error: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user