diff options
author | Michael Hofmann <michael.hofmann@bitgestalt.com> | 2020-01-08 16:29:59 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2020-01-08 16:29:59 +0300 |
commit | 18a4ef91bb1534bd3d806bc5e93390f2e9f01d73 (patch) | |
tree | 788ab20a42990426d7b28a4963f1444ade808a79 /internal | |
parent | 31f3fc2737095747ea76434b425c68dec453c515 (diff) |
Fix DiskStatistics on OpenBSD.
DiskStatistics in internal/service/server uses unix.Statfs to determine
available storage space. Since the fields of unix.Statfs_t on OpenBSD
have different names than on other Unices, a platform-specific
implementation is necessary.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/service/server/disk_stats.go | 19 | ||||
-rw-r--r-- | internal/service/server/storage_status_openbsd.go | 25 | ||||
-rw-r--r-- | internal/service/server/storage_status_unix.go | 27 |
3 files changed, 52 insertions, 19 deletions
diff --git a/internal/service/server/disk_stats.go b/internal/service/server/disk_stats.go index f4f6b09a3..bd696d0ef 100644 --- a/internal/service/server/disk_stats.go +++ b/internal/service/server/disk_stats.go @@ -6,7 +6,6 @@ import ( "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" - "golang.org/x/sys/unix" ) func (s *server) DiskStatistics(ctx context.Context, _ *gitalypb.DiskStatisticsRequest) (*gitalypb.DiskStatisticsResponse, error) { @@ -26,21 +25,3 @@ func (s *server) DiskStatistics(ctx context.Context, _ *gitalypb.DiskStatisticsR StorageStatuses: results, }, nil } - -func getStorageStatus(shard config.Storage) (*gitalypb.DiskStatisticsResponse_StorageStatus, error) { - var stats unix.Statfs_t - err := unix.Statfs(shard.Path, &stats) - if err != nil { - return nil, err - } - - // Redundant conversions to handle differences between unix families - available := int64(stats.Bavail) * int64(stats.Bsize) - used := (int64(stats.Blocks) - int64(stats.Bfree)) * int64(stats.Bsize) - - return &gitalypb.DiskStatisticsResponse_StorageStatus{ - StorageName: shard.Name, - Available: available, - Used: used, - }, nil -} diff --git a/internal/service/server/storage_status_openbsd.go b/internal/service/server/storage_status_openbsd.go new file mode 100644 index 000000000..dbac1e036 --- /dev/null +++ b/internal/service/server/storage_status_openbsd.go @@ -0,0 +1,25 @@ +package server + +import ( + "gitlab.com/gitlab-org/gitaly/internal/config" + "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" + "golang.org/x/sys/unix" +) + +func getStorageStatus(shard config.Storage) (*gitalypb.DiskStatisticsResponse_StorageStatus, error) { + var stats unix.Statfs_t + err := unix.Statfs(shard.Path, &stats) + if err != nil { + return nil, err + } + + // Redundant conversions to handle differences between unix families + available := int64(stats.F_bavail) * int64(stats.F_bsize) + used := (int64(stats.F_blocks) - int64(stats.F_bfree)) * int64(stats.F_bsize) + + return &gitalypb.DiskStatisticsResponse_StorageStatus{ + StorageName: shard.Name, + Available: available, + Used: used, + }, nil +} diff --git a/internal/service/server/storage_status_unix.go b/internal/service/server/storage_status_unix.go new file mode 100644 index 000000000..f5b63fc31 --- /dev/null +++ b/internal/service/server/storage_status_unix.go @@ -0,0 +1,27 @@ +// +build !openbsd + +package server + +import ( + "gitlab.com/gitlab-org/gitaly/internal/config" + "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" + "golang.org/x/sys/unix" +) + +func getStorageStatus(shard config.Storage) (*gitalypb.DiskStatisticsResponse_StorageStatus, error) { + var stats unix.Statfs_t + err := unix.Statfs(shard.Path, &stats) + if err != nil { + return nil, err + } + + // Redundant conversions to handle differences between unix families + available := int64(stats.Bavail) * int64(stats.Bsize) + used := (int64(stats.Blocks) - int64(stats.Bfree)) * int64(stats.Bsize) + + return &gitalypb.DiskStatisticsResponse_StorageStatus{ + StorageName: shard.Name, + Available: available, + Used: used, + }, nil +} |