Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hofmann <michael.hofmann@bitgestalt.com>2020-01-08 16:29:59 +0300
committerJacob Vosmaer <jacob@gitlab.com>2020-01-08 16:29:59 +0300
commit18a4ef91bb1534bd3d806bc5e93390f2e9f01d73 (patch)
tree788ab20a42990426d7b28a4963f1444ade808a79
parent31f3fc2737095747ea76434b425c68dec453c515 (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.
-rw-r--r--changelogs/unreleased/fix-disk-stats-openbsd.yml5
-rw-r--r--internal/service/server/disk_stats.go19
-rw-r--r--internal/service/server/storage_status_openbsd.go25
-rw-r--r--internal/service/server/storage_status_unix.go27
4 files changed, 57 insertions, 19 deletions
diff --git a/changelogs/unreleased/fix-disk-stats-openbsd.yml b/changelogs/unreleased/fix-disk-stats-openbsd.yml
new file mode 100644
index 000000000..406fdb51c
--- /dev/null
+++ b/changelogs/unreleased/fix-disk-stats-openbsd.yml
@@ -0,0 +1,5 @@
+---
+title: Fix DiskStatistics on OpenBSD
+merge_request: 1728
+author: bitgestalt
+type: fixed
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
+}