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
6 changes: 3 additions & 3 deletions pkg/drivers/posix/posix/posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,11 @@ func (s *PosixStorage) UploadLink(fileUploadArg *models.FileUploadArgs) ([]byte,
return nil, err
}
} else if fileUploadArg.FileParam.FileType == common.External {
uri, err := fileUploadArg.FileParam.GetResourceUri()
diskCheckPath, err := fileUploadArg.FileParam.GetDiskCheckPath()
if err != nil {
return nil, err
return nil, fmt.Errorf("get disk check path error: %v", err)
}
_, err = common.CheckDiskSpace(uri, fileUploadArg.TotalSize, false)
_, err = common.CheckDiskSpace(diskCheckPath, fileUploadArg.TotalSize, false)
if err != nil {
return nil, err
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/models/file_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,23 @@ func (r *FileParam) IsSystem() bool {
return r.FileType == common.Drive || r.FileType == common.Cache || r.FileType == common.Data
}

// GetDiskCheckPath returns the filesystem path for disk usage checking.
// For external mounted disks, it appends the disk name (first component of Path)
// to the base URI so that statfs can identify the correct mount point.
func (r *FileParam) GetDiskCheckPath() (string, error) {
uri, err := r.GetResourceUri()
if err != nil {
return "", err
}
if r.FileType == common.External && r.Path != "" {
parts := strings.SplitN(strings.TrimPrefix(r.Path, "/"), "/", 2)
if parts[0] != "" {
return filepath.Join(uri, parts[0]), nil
}
}
return uri, nil
}

func (r *FileParam) IsFile() (string, bool) {
if r.Path == "" || r.Path == "/" || strings.HasSuffix(r.Path, "/") {
return "", false
Expand Down
6 changes: 5 additions & 1 deletion pkg/tasks/task_paste_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ func (t *Task) DownloadFromCloud() error {
return err
}

posixSize, err := common.CheckDiskSpace(dstUri, cloudSize, true)
diskCheckPath, err := dst.GetDiskCheckPath()
if err != nil {
return fmt.Errorf("get disk check path error: %v", err)
}
posixSize, err := common.CheckDiskSpace(diskCheckPath, cloudSize, dst.IsSystem())
if err != nil {
klog.Errorf("get posix free space size error: %v", err)
return err
Expand Down
6 changes: 5 additions & 1 deletion pkg/tasks/task_paste_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ func (t *Task) DownloadFromFiles() error {
klog.Errorf("[Task] Id: %s, dst uri found error: %v", t.id, err)
return err
}
localSpace, err := common.CheckDiskSpace(dstUri, totalSize, dst.IsSystem()) // no sync dst but external here, IsSystem() is enough and precise
diskCheckPath, err := dst.GetDiskCheckPath()
if err != nil {
return fmt.Errorf("get disk check path error: %v", err)
}
localSpace, err := common.CheckDiskSpace(diskCheckPath, totalSize, dst.IsSystem()) // no sync dst but external here, IsSystem() is enough and precise
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/tasks/task_paste_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ func (t *Task) Rsync() error {
klog.Infof("[Task] Id: %s, srcPath: %s, dstUri: %s, srcMeta: %s", t.id, srcPath, dstUri, common.ToJson(pathMeta))

// check free space
dstFree, err := common.CheckDiskSpace(dstUri, pathMeta.Size, dst.IsSystem()) // no sync dst but external here, IsSystem() is enough and precise
diskCheckPath, err := dst.GetDiskCheckPath()
if err != nil {
return fmt.Errorf("get disk check path error: %v", err)
}
dstFree, err := common.CheckDiskSpace(diskCheckPath, pathMeta.Size, dst.IsSystem()) // no sync dst but external here, IsSystem() is enough and precise
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/tasks/task_paste_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ func (t *Task) DownloadFromSync() error {
return err
}

dstUri, err := dst.GetResourceUri()
diskCheckPath, err := dst.GetDiskCheckPath()
if err != nil {
return err
return fmt.Errorf("get disk check path error: %v", err)
}
dstSize, err := common.CheckDiskSpace(dstUri, srcTotalSize, true)
dstSize, err := common.CheckDiskSpace(diskCheckPath, srcTotalSize, dst.IsSystem())
if err != nil {
klog.Errorf("get posix free space size error: %v", err)
return err
Expand Down
Loading