-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
node: Announce capacity via the attributes
It is done automatically (as a sum of existing space on every file system available on the configured shards) but can be overwritten if `Capacity` attribute is provided via the application configuration. Closes #602. Signed-off-by: Pavel Karpy <[email protected]>
- Loading branch information
Showing
5 changed files
with
106 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//go:build !windows | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func totalBytes(paths []string) (uint64, error) { | ||
var stat unix.Statfs_t | ||
var total uint64 // bytes | ||
fsIDMap := make(map[unix.Fsid]struct{}) | ||
|
||
for _, path := range paths { | ||
err := unix.Statfs(path, &stat) | ||
if err != nil { | ||
return 0, fmt.Errorf("get FS stat by '%s' path: %w", path, err) | ||
} | ||
|
||
if _, handled := fsIDMap[stat.Fsid]; handled { | ||
continue | ||
} | ||
|
||
total += stat.Blocks * uint64(stat.Bsize) | ||
fsIDMap[stat.Fsid] = struct{}{} | ||
} | ||
|
||
return total, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//go:build windows | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func totalBytes(paths []string) (uint64, error) { | ||
var total uint64 // bytes | ||
diskMap := make(map[string]struct{}, len(paths)) | ||
|
||
for _, path := range paths { | ||
disk := filepath.VolumeName(path) | ||
if _, handled := diskMap[disk]; handled { | ||
continue | ||
} | ||
|
||
var availB uint64 | ||
var totalB uint64 | ||
var freeTotalB uint64 | ||
var pathP = windows.StringToUTF16Ptr(path) | ||
|
||
err := windows.GetDiskFreeSpaceEx(pathP, &availB, &totalB, &freeTotalB) | ||
if err != nil { | ||
return 0, fmt.Errorf("get disk stat by '%s' path: %w", path, err) | ||
} | ||
|
||
total += totalB | ||
diskMap[disk] = struct{}{} | ||
} | ||
|
||
return total, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters