diff --git a/server/disk_avail.go b/server/disk_avail.go index b879330e850..e27c1a71cc1 100644 --- a/server/disk_avail.go +++ b/server/disk_avail.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !windows && !openbsd && !netbsd && !wasm +//go:build !windows && !openbsd && !netbsd && !wasm && !illumos && !solaris package server diff --git a/server/disk_avail_illumos.go b/server/disk_avail_illumos.go new file mode 100644 index 00000000000..7707bae3593 --- /dev/null +++ b/server/disk_avail_illumos.go @@ -0,0 +1,37 @@ +// Copyright 2025 The NATS Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build illumos || solaris + +package server + +import ( + "golang.org/x/sys/unix" + "os" +) + +func diskAvailable(storeDir string) int64 { + var ba int64 + if _, err := os.Stat(storeDir); os.IsNotExist(err) { + os.MkdirAll(storeDir, defaultDirPerms) + } + var fs unix.Statvfs_t + if err := unix.Statvfs(storeDir, &fs); err == nil { + // Estimate 75% of available storage. + ba = int64(uint64(fs.Bavail) * uint64(fs.Frsize) / 4 * 3) + } else { + // Used 1TB default as a guess if all else fails. + ba = JetStreamMaxStoreDefault + } + return ba +} diff --git a/server/sysmem/mem_wasm.go b/server/sysmem/mem_unsupported.go similarity index 93% rename from server/sysmem/mem_wasm.go rename to server/sysmem/mem_unsupported.go index bde3586e56f..bfa32fc2cfc 100644 --- a/server/sysmem/mem_wasm.go +++ b/server/sysmem/mem_unsupported.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build wasm +//go:build illumos || solaris || wasm || zos package sysmem diff --git a/server/sysmem/mem_zos.go b/server/sysmem/mem_zos.go deleted file mode 100644 index f8db5c5c77d..00000000000 --- a/server/sysmem/mem_zos.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2022-2025 The NATS Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build zos - -package sysmem - -func Memory() int64 { - // TODO: We don't know the system memory - return 0 -}