Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/hostman/storageman/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func DoInstancePackBackup(ctx context.Context, backupInfo SStoragePackInstanceBa
} else {
finalPackageFileName = fmt.Sprintf("%s-%d.tar", backupInfo.PackageName, tried)
}
exists, err := backupStorage.IsBackupInstanceExists(finalPackageFileName)
exists, _, err := backupStorage.IsBackupInstanceExists(finalPackageFileName)
if err != nil {
return "", errors.Wrap(err, "IsBackupInstanceExists")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/hostman/storageman/backupstorage/backup_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type IBackupStorage interface {
// 删除备份
RemoveBackup(ctx context.Context, backupId string) error
// 备份是否存在
IsBackupExists(backupId string) (bool, error)
IsBackupExists(backupId string) (bool, string, error)

// 从指定路径拷贝主机备份文件到备份存储
SaveBackupInstanceFrom(ctx context.Context, srcFilename string, bakcupInstanceId string) error
Expand All @@ -43,7 +43,7 @@ type IBackupStorage interface {
// 删除备份
RemoveBackupInstance(ctx context.Context, backupInstanceId string) error
// 备份是否存在
IsBackupInstanceExists(backupInstanceId string) (bool, error)
IsBackupInstanceExists(backupInstanceId string) (bool, string, error)

// ConvertTo(destPath string, format qemuimgfmt.TImageFormat, backupId string) error
// ConvertFrom(srcPath string, format qemuimgfmt.TImageFormat, backupId string) (int, error)
Expand Down
19 changes: 11 additions & 8 deletions pkg/hostman/storageman/backupstorage/nfs/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,31 +194,34 @@ func (s *SNFSBackupStorage) removeFile(ctx context.Context, id string, getPathFu
return nil
}

func (s *SNFSBackupStorage) IsBackupExists(backupId string) (bool, error) {
func (s *SNFSBackupStorage) IsBackupExists(backupId string) (bool, string, error) {
return s.isFileExists(backupId, s.getBackupDiskPath)
}

func (s *SNFSBackupStorage) IsBackupInstanceExists(backupId string) (bool, error) {
func (s *SNFSBackupStorage) IsBackupInstanceExists(backupId string) (bool, string, error) {
return s.isFileExists(backupId, s.getBackupInstancePath)
}

func (s *SNFSBackupStorage) isFileExists(id string, getPathFunc func(id string) string) (bool, error) {
func (s *SNFSBackupStorage) isFileExists(id string, getPathFunc func(id string) string) (bool, string, error) {
err := s.checkAndMount()
if err != nil {
return false, errors.Wrap(err, "unable to checkAndMount")
if errors.Cause(err) == ErrorBackupStorageOffline {
return false, err.Error(), nil
}
return false, "", errors.Wrap(err, "unable to checkAndMount")
}
defer s.unMount()

filename := getPathFunc(id)
return fileutils2.Exists(filename), nil
return fileutils2.Exists(filename), "", nil
}

func (s *SNFSBackupStorage) IsOnline() (bool, string, error) {
err := s.checkAndMount()
if errors.Cause(err) == ErrorBackupStorageOffline {
return false, err.Error(), nil
}
if err != nil {
if errors.Cause(err) == ErrorBackupStorageOffline {
return false, err.Error(), nil
}
return false, "", err
}
s.unMount()
Expand Down
14 changes: 7 additions & 7 deletions pkg/hostman/storageman/backupstorage/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,27 +178,27 @@ func (s *SObjectBackupStorage) removeObject(ctx context.Context, id string, getK
return nil
}

func (s *SObjectBackupStorage) IsBackupExists(backupId string) (bool, error) {
func (s *SObjectBackupStorage) IsBackupExists(backupId string) (bool, string, error) {
return s.isObjectExists(backupId, s.getBackupKey)
}

func (s *SObjectBackupStorage) IsBackupInstanceExists(backupId string) (bool, error) {
func (s *SObjectBackupStorage) IsBackupInstanceExists(backupId string) (bool, string, error) {
return s.isObjectExists(backupId, s.getBackupInstanceKey)
}

func (s *SObjectBackupStorage) isObjectExists(id string, getKeyFunc func(string) string) (bool, error) {
func (s *SObjectBackupStorage) isObjectExists(id string, getKeyFunc func(string) string) (bool, string, error) {
bucket, err := s.getBucket()
if err != nil {
return false, errors.Wrap(err, "getBucket")
return false, "", errors.Wrap(err, "getBucket")
}
_, err = cloudprovider.GetIObject(bucket, getKeyFunc(id))
if err != nil {
if errors.Cause(err) == errors.ErrNotFound {
return false, nil
return false, "", nil
}
return false, errors.Wrap(err, "GetIObject")
return false, "", errors.Wrap(err, "GetIObject")
}
return true, nil
return true, "", nil
}

func (s *SObjectBackupStorage) IsOnline() (bool, string, error) {
Expand Down
12 changes: 7 additions & 5 deletions pkg/hostman/storageman/storagehandler/storagehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func storageSyncBackup(ctx context.Context, w http.ResponseWriter, r *http.Reque
hostutils.Response(ctx, w, err)
return
}
exist, err := backupStorage.IsBackupExists(backupId)
exist, reason, err := backupStorage.IsBackupExists(backupId)
if err != nil {
hostutils.Response(ctx, w, err)
return
Expand All @@ -287,11 +287,13 @@ func storageSyncBackup(ctx context.Context, w http.ResponseWriter, r *http.Reque
)
if exist {
status = compute.BACKUP_EXIST
} else if !exist && err == nil {
status = compute.BACKUP_NOT_EXIST
} else {
log.Errorf("fetch snapshot exist failed %s", err)
status = compute.BACKUP_STATUS_UNKNOWN
if len(reason) == 0 {
status = compute.BACKUP_NOT_EXIST
} else {
log.Errorf("fetch snapshot exist failed reason:%s", reason)
status = compute.BACKUP_STATUS_UNKNOWN
}
}
ret.Set("status", jsonutils.NewString(status))
hostutils.Response(ctx, w, ret)
Expand Down