diff --git a/pkg/drivers/posix/posix/posix.go b/pkg/drivers/posix/posix/posix.go index c6b8acbd..3d292396 100644 --- a/pkg/drivers/posix/posix/posix.go +++ b/pkg/drivers/posix/posix/posix.go @@ -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 } diff --git a/pkg/models/file_param.go b/pkg/models/file_param.go index 9691f827..40ffab92 100644 --- a/pkg/models/file_param.go +++ b/pkg/models/file_param.go @@ -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 diff --git a/pkg/tasks/task_paste_cloud.go b/pkg/tasks/task_paste_cloud.go index d1a3fdd6..2be4ba07 100644 --- a/pkg/tasks/task_paste_cloud.go +++ b/pkg/tasks/task_paste_cloud.go @@ -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 diff --git a/pkg/tasks/task_paste_download.go b/pkg/tasks/task_paste_download.go index 2b57223e..b5fb7f1f 100644 --- a/pkg/tasks/task_paste_download.go +++ b/pkg/tasks/task_paste_download.go @@ -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 } diff --git a/pkg/tasks/task_paste_posix.go b/pkg/tasks/task_paste_posix.go index 1a642a8e..7364b741 100644 --- a/pkg/tasks/task_paste_posix.go +++ b/pkg/tasks/task_paste_posix.go @@ -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 } diff --git a/pkg/tasks/task_paste_sync.go b/pkg/tasks/task_paste_sync.go index c4bd6fdf..e535d0fa 100644 --- a/pkg/tasks/task_paste_sync.go +++ b/pkg/tasks/task_paste_sync.go @@ -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