diff --git a/cmd/server-rlimit.go b/cmd/server-rlimit.go index 52d4b0d73..5a42bcf3a 100644 --- a/cmd/server-rlimit.go +++ b/cmd/server-rlimit.go @@ -21,7 +21,7 @@ import ( "runtime" "runtime/debug" - "github.com/minio/minio/internal/kernel" + "github.com/minio/madmin-go/kernel" "github.com/minio/minio/internal/logger" "github.com/minio/pkg/sys" ) diff --git a/go.mod b/go.mod index 7a1ad7b33..bd9d60f94 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/minio/dperf v0.4.2 github.com/minio/highwayhash v1.0.2 github.com/minio/kes v0.20.0 - github.com/minio/madmin-go v1.4.13 + github.com/minio/madmin-go v1.4.15 github.com/minio/minio-go/v7 v7.0.34 github.com/minio/pkg v1.3.0 github.com/minio/selfupdate v0.5.0 @@ -72,6 +72,7 @@ require ( github.com/rs/cors v1.7.0 github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417 github.com/secure-io/sio-go v0.3.1 + github.com/shirou/gopsutil v3.21.11+incompatible github.com/shirou/gopsutil/v3 v3.22.6 github.com/streadway/amqp v1.0.0 github.com/tinylib/msgp v1.1.7-0.20211026165309-e818a1881b0e diff --git a/go.sum b/go.sum index 8d8f3d522..8714791e2 100644 --- a/go.sum +++ b/go.sum @@ -622,8 +622,8 @@ github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLT github.com/minio/kes v0.20.0 h1:1tyC51Rr8zTregTESuT/QN/iebNMX7B9t7d3xLNMEpE= github.com/minio/kes v0.20.0/go.mod h1:3FW1BQkMGQW78yhy+69tUq5bdcf5rnXJizyeKB9a/tc= github.com/minio/madmin-go v1.3.5/go.mod h1:vGKGboQgGIWx4DuDUaXixjlIEZOCIp6ivJkQoiVaACc= -github.com/minio/madmin-go v1.4.13 h1:ga0vCrafxflxSb8nBnG+FIiu7MMM++6fVVZh+Ej+xzo= -github.com/minio/madmin-go v1.4.13/go.mod h1:ez87VmMtsxP7DRxjKJKD4RDNW+nhO2QF9KSzwxBDQ98= +github.com/minio/madmin-go v1.4.15 h1:1uqNMLa2ZhU05FIxPW8bUmZ5Orbs+6Tmj5B2LFJsdRI= +github.com/minio/madmin-go v1.4.15/go.mod h1:ez87VmMtsxP7DRxjKJKD4RDNW+nhO2QF9KSzwxBDQ98= github.com/minio/mc v0.0.0-20220805080128-351d021b924b h1:ikMXncKqNE/0acH6us6yy3v+gJBP7nGv/3Rc9F7vRio= github.com/minio/mc v0.0.0-20220805080128-351d021b924b/go.mod h1:YUXIqqgGfFknByv0eeJSMBQl/WGuEN0XkpW68/ghBm0= github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw= @@ -804,6 +804,8 @@ github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/secure-io/sio-go v0.3.1 h1:dNvY9awjabXTYGsTF1PiCySl9Ltofk9GA3VdWlo7rRc= github.com/secure-io/sio-go v0.3.1/go.mod h1:+xbkjDzPjwh4Axd07pRKSNriS9SCiYksWnZqdnfpQxs= +github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= +github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil/v3 v3.21.6/go.mod h1:JfVbDpIBLVzT8oKbvMg9P3wEIMDDpVn+LwHTKj0ST88= github.com/shirou/gopsutil/v3 v3.22.6 h1:FnHOFOh+cYAM0C30P+zysPISzlknLC5Z1G4EAElznfQ= github.com/shirou/gopsutil/v3 v3.22.6/go.mod h1:EdIubSnZhbAvBS1yJ7Xi+AShB/hxwLHOMz4MCYz7yMs= diff --git a/internal/kernel/kernel.go b/internal/kernel/kernel.go deleted file mode 100644 index d74419602..000000000 --- a/internal/kernel/kernel.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) 2015-2022 MinIO, Inc. -// -// This file is part of MinIO Object Storage stack -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -//go:build linux -// +build linux - -package kernel - -import ( - "fmt" - "io/ioutil" - "regexp" - "strconv" - "strings" - "syscall" -) - -var versionRegex = regexp.MustCompile(`^(\d+)\.(\d+).(\d+).*$`) - -// VersionFromRelease converts a release string with format -// 4.4.2[-1] to a kernel version number in LINUX_VERSION_CODE format. -// That is, for kernel "a.b.c", the version number will be (a<<16 + b<<8 + c) -func VersionFromRelease(releaseString string) (uint32, error) { - versionParts := versionRegex.FindStringSubmatch(releaseString) - if len(versionParts) != 4 { - return 0, fmt.Errorf("got invalid release version %q (expected format '4.3.2-1')", releaseString) - } - major, err := strconv.Atoi(versionParts[1]) - if err != nil { - return 0, err - } - - minor, err := strconv.Atoi(versionParts[2]) - if err != nil { - return 0, err - } - - patch, err := strconv.Atoi(versionParts[3]) - if err != nil { - return 0, err - } - return Version(major, minor, patch), nil -} - -// Version implements KERNEL_VERSION equivalent macro -// #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + ((c) > 255 ? 255 : (c))) -func Version(major, minor, patch int) uint32 { - if patch > 255 { - patch = 255 - } - out := major<<16 + minor<<8 + patch - return uint32(out) -} - -func currentVersionUname() (uint32, error) { - var buf syscall.Utsname - if err := syscall.Uname(&buf); err != nil { - return 0, err - } - releaseString := strings.Trim(utsnameStr(buf.Release[:]), "\x00") - return VersionFromRelease(releaseString) -} - -func currentVersionUbuntu() (uint32, error) { - procVersion, err := ioutil.ReadFile("/proc/version_signature") - if err != nil { - return 0, err - } - var u1, u2, releaseString string - _, err = fmt.Sscanf(string(procVersion), "%s %s %s", &u1, &u2, &releaseString) - if err != nil { - return 0, err - } - return VersionFromRelease(releaseString) -} - -var debianVersionRegex = regexp.MustCompile(`.* SMP Debian (\d+\.\d+.\d+-\d+)(?:\+[[:alnum:]]*)?.*`) - -func parseDebianVersion(str string) (uint32, error) { - match := debianVersionRegex.FindStringSubmatch(str) - if len(match) != 2 { - return 0, fmt.Errorf("failed to parse kernel version from /proc/version: %s", str) - } - return VersionFromRelease(match[1]) -} - -func currentVersionDebian() (uint32, error) { - procVersion, err := ioutil.ReadFile("/proc/version") - if err != nil { - return 0, fmt.Errorf("error reading /proc/version: %s", err) - } - - return parseDebianVersion(string(procVersion)) -} - -// CurrentVersion returns the current kernel version in -// LINUX_VERSION_CODE format (see VersionFromRelease()) -func CurrentVersion() (uint32, error) { - // We need extra checks for Debian and Ubuntu as they modify - // the kernel version patch number for compatibility with - // out-of-tree modules. Linux perf tools do the same for Ubuntu - // systems: https://github.com/torvalds/linux/commit/d18acd15c - // - // See also: - // https://kernel-team.pages.debian.net/kernel-handbook/ch-versions.html - // https://wiki.ubuntu.com/Kernel/FAQ - version, err := currentVersionUbuntu() - if err == nil { - return version, nil - } - version, err = currentVersionDebian() - if err == nil { - return version, nil - } - return currentVersionUname() -} diff --git a/internal/kernel/kernel_other.go b/internal/kernel/kernel_other.go deleted file mode 100644 index 998cff7f7..000000000 --- a/internal/kernel/kernel_other.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2015-2022 MinIO, Inc. -// -// This file is part of MinIO Object Storage stack -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -//go:build !linux -// +build !linux - -package kernel - -// VersionFromRelease only implemented on Linux. -func VersionFromRelease(_ string) (uint32, error) { - return 0, nil -} - -// Version only implemented on Linux. -func Version(_, _, _ int) uint32 { - return 0 -} - -// CurrentVersion only implemented on Linux. -func CurrentVersion() (uint32, error) { - return 0, nil -} diff --git a/internal/kernel/kernel_test.go b/internal/kernel/kernel_test.go deleted file mode 100644 index fa60b598c..000000000 --- a/internal/kernel/kernel_test.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) 2015-2022 MinIO, Inc. -// -// This file is part of MinIO Object Storage stack -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -//go:build linux -// +build linux - -package kernel - -import "testing" - -var testData = []struct { - success bool - releaseString string - kernelVersion uint32 -}{ - {true, "4.1.2-3", 262402}, - {true, "4.8.14-200.fc24.x86_64", 264206}, - {true, "4.1.2-3foo", 262402}, - {true, "4.1.2foo-1", 262402}, - {true, "4.1.2-rkt-v1", 262402}, - {true, "4.1.2rkt-v1", 262402}, - {true, "4.1.2-3 foo", 262402}, - {true, "3.10.0-1062.el7.x86_64", 199168}, - {true, "3.0.0", 196608}, - {true, "2.6.32", 132640}, - {true, "5.13.0-30-generic", 331008}, - {true, "5.10.0-1052-oem", 330240}, - {false, "foo 4.1.2-3", 0}, - {true, "4.1.2", 262402}, - {false, ".4.1.2", 0}, - {false, "4.1.", 0}, - {false, "4.1", 0}, -} - -func TestVersionFromRelease(t *testing.T) { - for _, test := range testData { - version, err := VersionFromRelease(test.releaseString) - if err != nil && test.success { - t.Errorf("expected %q to success: %s", test.releaseString, err) - } else if err == nil && !test.success { - t.Errorf("expected %q to fail", test.releaseString) - } - if version != test.kernelVersion { - t.Errorf("expected kernel version %d, got %d", test.kernelVersion, version) - } - } -} - -func TestParseDebianVersion(t *testing.T) { - for _, tc := range []struct { - success bool - releaseString string - kernelVersion uint32 - }{ - // 4.9.168 - {true, "Linux version 4.9.0-9-amd64 (debian-kernel@lists.debian.org) (gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1) ) #1 SMP Debian 4.9.168-1+deb9u3 (2019-06-16)", 264616}, - // 4.9.88 - {true, "Linux ip-10-0-75-49 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64 GNU/Linux", 264536}, - // 3.0.4 - {true, "Linux version 3.16.0-9-amd64 (debian-kernel@lists.debian.org) (gcc version 4.9.2 (Debian 4.9.2-10+deb8u2) ) #1 SMP Debian 3.16.68-1 (2019-05-22)", 200772}, - // Invalid - {false, "Linux version 4.9.125-linuxkit (root@659b6d51c354) (gcc version 6.4.0 (Alpine 6.4.0) ) #1 SMP Fri Sep 7 08:20:28 UTC 2018", 0}, - } { - version, err := parseDebianVersion(tc.releaseString) - if err != nil && tc.success { - t.Errorf("expected %q to success: %s", tc.releaseString, err) - } else if err == nil && !tc.success { - t.Errorf("expected %q to fail", tc.releaseString) - } - if version != tc.kernelVersion { - t.Errorf("expected kernel version %d, got %d", tc.kernelVersion, version) - } - } -} diff --git a/internal/kernel/kernel_utsname_int8.go b/internal/kernel/kernel_utsname_int8.go deleted file mode 100644 index 1c7855117..000000000 --- a/internal/kernel/kernel_utsname_int8.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2015-2022 MinIO, Inc. -// -// This file is part of MinIO Object Storage stack -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -//go:build (linux && 386) || (linux && amd64) || (linux && arm64) || (linux && mips64) || (linux && mips) -// +build linux,386 linux,amd64 linux,arm64 linux,mips64 linux,mips - -package kernel - -func utsnameStr(in []int8) string { - out := make([]byte, 0, len(in)) - for i := 0; i < len(in); i++ { - if in[i] == 0x00 { - break - } - out = append(out, byte(in[i])) - } - return string(out) -} diff --git a/internal/kernel/kernel_utsname_uint8.go b/internal/kernel/kernel_utsname_uint8.go deleted file mode 100644 index 5b019d8da..000000000 --- a/internal/kernel/kernel_utsname_uint8.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2015-2022 MinIO, Inc. -// -// This file is part of MinIO Object Storage stack -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -//go:build (linux && arm) || (linux && ppc64) || (linux && ppc64le) || (linux && s390x) || (linux && riscv64) -// +build linux,arm linux,ppc64 linux,ppc64le linux,s390x linux,riscv64 - -package kernel - -func utsnameStr(in []uint8) string { - out := make([]byte, 0, len(in)) - for i := 0; i < len(in); i++ { - if in[i] == 0x00 { - break - } - out = append(out, byte(in[i])) - } - return string(out) -}