mirror of
https://github.com/goharbor/harbor
synced 2025-04-09 18:49:19 +00:00
Merge pull request #5695 from cd1989/macos-volume-capacity
Fix volume capacity when run in MacOS
This commit is contained in:
commit
93a073ff64
|
@ -17,7 +17,7 @@ package imagestorage
|
||||||
// GlobalDriver is a global image storage driver
|
// GlobalDriver is a global image storage driver
|
||||||
var GlobalDriver Driver
|
var GlobalDriver Driver
|
||||||
|
|
||||||
// Capacity holds information about capaticy of image storage
|
// Capacity holds information about capacity of image storage
|
||||||
type Capacity struct {
|
type Capacity struct {
|
||||||
// total size(byte)
|
// total size(byte)
|
||||||
Total uint64 `json:"total"`
|
Total uint64 `json:"total"`
|
||||||
|
|
|
@ -16,6 +16,7 @@ package filesystem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
storage "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage"
|
storage "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage"
|
||||||
|
@ -56,8 +57,23 @@ func (d *driver) Cap() (*storage.Capacity, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When container is run in MacOS, `bsize` obtained by `statfs` syscall is not the fundamental block size,
|
||||||
|
// but the `iosize` (optimal transfer block size) instead, it's usually 1024 times larger than the `bsize`.
|
||||||
|
// for example `4096 * 1024`. To get the correct block size, we should use `frsize`. But `frsize` isn't
|
||||||
|
// guaranteed to be supported everywhere, so we need to check whether it's supported before use it.
|
||||||
|
// For more details, please refer to: https://github.com/docker/for-mac/issues/2136
|
||||||
|
bSize := uint64(stat.Bsize)
|
||||||
|
field := reflect.ValueOf(&stat).Elem().FieldByName("Frsize")
|
||||||
|
if field.IsValid() {
|
||||||
|
if field.Kind() == reflect.Uint64 {
|
||||||
|
bSize = field.Uint()
|
||||||
|
} else {
|
||||||
|
bSize = uint64(field.Int())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &storage.Capacity{
|
return &storage.Capacity{
|
||||||
Total: stat.Blocks * uint64(stat.Bsize),
|
Total: stat.Blocks * bSize,
|
||||||
Free: stat.Bavail * uint64(stat.Bsize),
|
Free: stat.Bavail * bSize,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user