Fix build issues on BSDs in pkg/cpu (#7116)

Also add a cross compile script to test always cross
compilation for some well known platforms and architectures
, we support out of box compilation of these platforms even
if we don't make an official release build.

This script is to avoid regressions in this area when we
add platform dependent code.
master
Harshavardhana 6 years ago committed by Nitish Tiwari
parent 5353edcc38
commit 8e0910ab3e
  1. 2
      .travis.yml
  2. 3
      Makefile
  3. 35
      buildscripts/cross-compile.sh
  4. 2
      cmd/bitrot.go
  5. 3
      cmd/erasure.go
  6. 2
      cmd/posix.go
  7. 9
      pkg/cpu/counter_linux.go
  8. 7
      pkg/cpu/counter_other.go
  9. 30
      pkg/cpu/counter_windows.go

@ -23,6 +23,8 @@ matrix:
- diff -au <(gofmt -s -d cmd) <(printf "") - diff -au <(gofmt -s -d cmd) <(printf "")
- diff -au <(gofmt -s -d pkg) <(printf "") - diff -au <(gofmt -s -d pkg) <(printf "")
- for d in $(go list ./... | grep -v browser); do CGO_ENABLED=1 go test -v -race --timeout 15m "$d"; done - for d in $(go list ./... | grep -v browser); do CGO_ENABLED=1 go test -v -race --timeout 15m "$d"; done
- make verifiers
- make crosscompile
- make verify - make verify
- make coverage - make coverage
- cd browser && yarn && yarn test && cd .. - cd browser && yarn && yarn test && cd ..

@ -19,6 +19,9 @@ getdeps:
@echo "Installing misspell" && go get -u github.com/client9/misspell/cmd/misspell @echo "Installing misspell" && go get -u github.com/client9/misspell/cmd/misspell
@echo "Installing ineffassign" && go get -u github.com/gordonklaus/ineffassign @echo "Installing ineffassign" && go get -u github.com/gordonklaus/ineffassign
crosscompile:
@(env bash $(PWD)/buildscripts/cross-compile.sh)
verifiers: getdeps vet fmt lint cyclo deadcode spelling verifiers: getdeps vet fmt lint cyclo deadcode spelling
vet: vet:

@ -0,0 +1,35 @@
#!/bin/bash
# Enable tracing if set.
[ -n "$BASH_XTRACEFD" ] && set -ex
function _init() {
## All binaries are static make sure to disable CGO.
export CGO_ENABLED=0
## List of architectures and OS to test coss compilation.
SUPPORTED_OSARCH="linux/ppc64le linux/arm64 linux/s390x darwin/amd64 freebsd/amd64"
}
function _build_and_sign() {
local osarch=$1
IFS=/ read -r -a arr <<<"$osarch"
os="${arr[0]}"
arch="${arr[1]}"
package=$(go list -f '{{.ImportPath}}')
printf -- "--> %15s:%s\n" "${osarch}" "${package}"
# Go build to build the binary.
export GOOS=$os
export GOARCH=$arch
go build -tags kqueue -o /dev/null
}
function main() {
echo "Testing builds for OS/Arch: ${SUPPORTED_OSARCH}"
for each_osarch in ${SUPPORTED_OSARCH}; do
_build_and_sign "${each_osarch}"
done
}
_init && main "$@"

@ -39,7 +39,7 @@ const (
SHA256 BitrotAlgorithm = 1 + iota SHA256 BitrotAlgorithm = 1 + iota
// HighwayHash256 represents the HighwayHash-256 hash function // HighwayHash256 represents the HighwayHash-256 hash function
HighwayHash256 HighwayHash256
// HighwayHash256 represents the Streaming HighwayHash-256 hash function // HighwayHash256S represents the Streaming HighwayHash-256 hash function
HighwayHash256S HighwayHash256S
// BLAKE2b512 represents the BLAKE2b-512 hash function // BLAKE2b512 represents the BLAKE2b-512 hash function
BLAKE2b512 BLAKE2b512

@ -93,10 +93,12 @@ func (e *Erasure) DecodeDataAndParityBlocks(ctx context.Context, data [][]byte)
return nil return nil
} }
// ShardSize - returns actual shared size from erasure blockSize.
func (e *Erasure) ShardSize() int64 { func (e *Erasure) ShardSize() int64 {
return ceilFrac(e.blockSize, int64(e.dataBlocks)) return ceilFrac(e.blockSize, int64(e.dataBlocks))
} }
// ShardFileSize - returns final erasure size from original size.
func (e *Erasure) ShardFileSize(totalLength int64) int64 { func (e *Erasure) ShardFileSize(totalLength int64) int64 {
if totalLength == 0 { if totalLength == 0 {
return 0 return 0
@ -107,6 +109,7 @@ func (e *Erasure) ShardFileSize(totalLength int64) int64 {
return numShards*e.ShardSize() + lastShardSize return numShards*e.ShardSize() + lastShardSize
} }
// ShardFileTillOffset - returns the effectiv eoffset where erasure reading begins.
func (e *Erasure) ShardFileTillOffset(startOffset, length, totalLength int64) int64 { func (e *Erasure) ShardFileTillOffset(startOffset, length, totalLength int64) int64 {
shardSize := e.ShardSize() shardSize := e.ShardSize()
shardFileSize := e.ShardFileSize(totalLength) shardFileSize := e.ShardFileSize(totalLength)

@ -1015,7 +1015,7 @@ func (s *posix) ReadFileStream(volume, path string, offset, length int64) (io.Re
if _, err = file.Seek(offset, io.SeekStart); err != nil { if _, err = file.Seek(offset, io.SeekStart); err != nil {
return nil, err return nil, err
} }
return &posixLimitedReader{io.LimitedReader{file, length}}, nil return &posixLimitedReader{io.LimitedReader{R: file, N: length}}, nil
} }
// CreateFile - creates the file. // CreateFile - creates the file.

@ -20,12 +20,8 @@ import (
"syscall" "syscall"
"time" "time"
"unsafe" "unsafe"
)
const ( "golang.org/x/sys/unix"
// ProcessClock corresponds to the High-resolution per-process
// timer from the CPU represented in stdlib as CLOCK_PROCESS_CPUTIME_ID
processClock = 2
) )
func newCounter() (counter, error) { func newCounter() (counter, error) {
@ -34,7 +30,8 @@ func newCounter() (counter, error) {
func (c counter) now() time.Time { func (c counter) now() time.Time {
var ts syscall.Timespec var ts syscall.Timespec
syscall.Syscall(syscall.SYS_CLOCK_GETTIME, processClock, uintptr(unsafe.Pointer(&ts)), 0) // Retrieve Per-process CPU-time clock
syscall.Syscall(syscall.SYS_CLOCK_GETTIME, unix.CLOCK_PROCESS_CPUTIME_ID, uintptr(unsafe.Pointer(&ts)), 0)
sec, nsec := ts.Unix() sec, nsec := ts.Unix()
return time.Unix(sec, nsec) return time.Unix(sec, nsec)
} }

@ -1,3 +1,5 @@
// +build darwin freebsd openbsd netbsd dragonfly windows
/* /*
* Minio Cloud Storage, (C) 2019 Minio, Inc. * Minio Cloud Storage, (C) 2019 Minio, Inc.
* *
@ -17,12 +19,13 @@
package cpu package cpu
import ( import (
"errors" "fmt"
"runtime"
"time" "time"
) )
func newCounter() (counter, error) { func newCounter() (counter, error) {
return counter{}, errors.New("cpu metrics not implemented for darwin platform") return counter{}, fmt.Errorf("cpu metrics not implemented for %s platform", runtime.GOOS)
} }
func (c counter) now() time.Time { func (c counter) now() time.Time {

@ -1,30 +0,0 @@
/*
* Minio Cloud Storage, (C) 2019 Minio, Inc.
*
* 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.
*/
package cpu
import (
"errors"
"time"
)
func newCounter() (counter, error) {
return counter{}, errors.New("cpu metrics not implemented for windows platform")
}
func (c counter) now() time.Time {
return time.Time{}
}
Loading…
Cancel
Save