mirror of
https://github.com/minio/minio.git
synced 2024-12-23 21:55:53 -05:00
Remove scsi non portable code, instead "donut make" implements functionality to instantiate a donut
This commit is contained in:
parent
49c705da99
commit
4498662c16
2
Makefile
2
Makefile
@ -34,7 +34,7 @@ cyclo:
|
||||
gomake-all: getdeps verifiers
|
||||
@echo "Installing minio:"
|
||||
@go run make.go -install
|
||||
@go run cmd/mkdonut/make.go -install
|
||||
@go run cmd/donut/make.go -install
|
||||
|
||||
release: getdeps verifiers
|
||||
@echo "Installing minio:"
|
||||
|
1
cmd/donut/.gitignore
vendored
Normal file
1
cmd/donut/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
donut
|
@ -39,6 +39,28 @@ var flags = []cli.Flag{
|
||||
Usage: "print debug information",
|
||||
},
|
||||
}
|
||||
var commands = []cli.Command{
|
||||
{
|
||||
Name: "make",
|
||||
Description: "make a donut",
|
||||
Action: runMkdonut,
|
||||
CustomHelpTemplate: `NAME:
|
||||
donut {{.Name}} - {{.Description}}
|
||||
|
||||
USAGE:
|
||||
donut {{.Name}} DONUTNAME [DISKS...]
|
||||
|
||||
EXAMPLES:
|
||||
1. Make a donut with 4 exports
|
||||
$ donut {{.Name}} mongodb-backup /mnt/export1 /mnt/export2 /mnt/export3 /mnt/export4
|
||||
|
||||
2. Make a donut with 16 exports
|
||||
$ donut {{.Name}} operational-data /mnt/export1 /mnt/export2 /mnt/export3 /mnt/export4 /mnt/export5 \
|
||||
/mnt/export6 /mnt/export7 /mnt/export8 /mnt/export9 /mnt/export10 /mnt/export11 \
|
||||
/mnt/export12 /mnt/export13 /mnt/export14 /mnt/export15 /mnt/export16
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Check for the environment early on and gracefuly report.
|
||||
@ -76,8 +98,7 @@ func getSystemData() map[string]string {
|
||||
|
||||
func runMkdonut(c *cli.Context) {
|
||||
if !c.Args().Present() || c.Args().First() == "help" {
|
||||
cli.ShowAppHelp(c)
|
||||
os.Exit(1)
|
||||
cli.ShowCommandHelpAndExit(c, "make", 1)
|
||||
}
|
||||
donutName := c.Args().First()
|
||||
if c.Args().First() != "" {
|
||||
@ -109,7 +130,7 @@ func runMkdonut(c *cli.Context) {
|
||||
// keep it in exact order as it was specified, do not try to sort disks
|
||||
donutConfig.NodeDiskMap[hostname] = disks
|
||||
// default cache is unlimited
|
||||
donutConfig.MaxSize = 0
|
||||
donutConfig.MaxSize = 512000000
|
||||
|
||||
if err := donut.SaveConfig(donutConfig); err != nil {
|
||||
Fatalln(err)
|
||||
@ -129,11 +150,12 @@ func main() {
|
||||
// set up app
|
||||
app := cli.NewApp()
|
||||
app.Action = runMkdonut
|
||||
app.Name = "mkdonut"
|
||||
app.Version = Version
|
||||
app.Name = "donut"
|
||||
app.Version = getVersion()
|
||||
app.Compiled = getVersion()
|
||||
app.Author = "Minio.io"
|
||||
app.Usage = "Make a donut"
|
||||
app.Usage = "Donut maker"
|
||||
app.Commands = commands
|
||||
app.Flags = flags
|
||||
app.Before = func(c *cli.Context) error {
|
||||
if c.GlobalBool("debug") {
|
||||
@ -146,15 +168,6 @@ func main() {
|
||||
|
||||
USAGE:
|
||||
{{.Name}} {{if .Flags}}[global flags] {{end}}command{{if .Flags}} [command flags]{{end}} [arguments...]
|
||||
|
||||
EXAMPLES:
|
||||
1. Create a donut with four disks
|
||||
$ {{.Name}} donuttest /mnt/export1 /mnt/export2 /mnt/export3 /mnt/export4
|
||||
|
||||
2. Create a donut with sixteen disks
|
||||
$ {{.Name}} donut-16 /mnt/export1 /mnt/export2 /mnt/export3 /mnt/export4 /mnt/export5 \
|
||||
/mnt/export6 /mnt/export7 /mnt/export8 /mnt/export9 /mnt/export10 /mnt/export11 \
|
||||
/mnt/export12 /mnt/export13 /mnt/export14 /mnt/export15 /mnt/export16
|
||||
{{if .Flags}}
|
||||
GLOBAL FLAGS:
|
||||
{{range .Flags}}{{.}}
|
@ -85,17 +85,17 @@ func (c command) String() string {
|
||||
return message
|
||||
}
|
||||
|
||||
func runMkdonutInstall() {
|
||||
mkdonutInstall := command{exec.Command("godep", "go", "install", "-a", "github.com/minio/minio/cmd/mkdonut"), &bytes.Buffer{}, &bytes.Buffer{}}
|
||||
mkdonutInstallErr := mkdonutInstall.runCommand()
|
||||
if mkdonutInstallErr != nil {
|
||||
fmt.Println(mkdonutInstall)
|
||||
func runDonutInstall() {
|
||||
donutInstall := command{exec.Command("godep", "go", "install", "-a", "github.com/minio/minio/cmd/donut"), &bytes.Buffer{}, &bytes.Buffer{}}
|
||||
donutInstallErr := donutInstall.runCommand()
|
||||
if donutInstallErr != nil {
|
||||
fmt.Println(donutInstall)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Print(mkdonutInstall)
|
||||
fmt.Print(donutInstall)
|
||||
}
|
||||
|
||||
func runMkdonutRelease() {
|
||||
func runDonutRelease() {
|
||||
t := time.Now().UTC()
|
||||
date := t.Format(time.RFC3339Nano)
|
||||
version := Version{Date: date}
|
||||
@ -108,14 +108,14 @@ func runMkdonutRelease() {
|
||||
|
||||
func main() {
|
||||
releaseFlag := flag.Bool("release", false, "make a release")
|
||||
installFlag := flag.Bool("install", false, "install mkdonut")
|
||||
installFlag := flag.Bool("install", false, "install donut")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if *releaseFlag {
|
||||
runMkdonutRelease()
|
||||
runDonutRelease()
|
||||
}
|
||||
if *installFlag {
|
||||
runMkdonutInstall()
|
||||
runDonutInstall()
|
||||
}
|
||||
}
|
1
cmd/mkdonut/.gitignore
vendored
1
cmd/mkdonut/.gitignore
vendored
@ -1 +0,0 @@
|
||||
mkdonut
|
@ -105,12 +105,6 @@ func runController(c *cli.Context) {
|
||||
cli.ShowCommandHelpAndExit(c, "controller", 1) // last argument is exit code
|
||||
}
|
||||
switch c.Args().First() {
|
||||
case "disks":
|
||||
disks, err := controller.GetDisks(c.Args().Tail().First())
|
||||
if err != nil {
|
||||
Fatalln(err)
|
||||
}
|
||||
Println(string(disks))
|
||||
case "mem":
|
||||
memstats, err := controller.GetMemStats(c.Args().Tail().First())
|
||||
if err != nil {
|
||||
|
@ -32,28 +32,6 @@ func closeResp(resp *http.Response) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetDisks get disks info of the server at given url
|
||||
func GetDisks(url string) ([]byte, error) {
|
||||
op := RPCOps{
|
||||
Method: "DiskInfo.Get",
|
||||
Request: rpc.Args{Request: ""},
|
||||
}
|
||||
req, err := NewRequest(url, op, http.DefaultTransport)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
resp, err := req.Do()
|
||||
defer closeResp(resp)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
var reply rpc.DiskInfoReply
|
||||
if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
return json.MarshalIndent(reply, "", "\t")
|
||||
}
|
||||
|
||||
// GetMemStats get memory status of the server at given url
|
||||
func GetMemStats(url string) ([]byte, error) {
|
||||
op := RPCOps{
|
||||
|
@ -114,7 +114,6 @@ func getRPCHandler() http.Handler {
|
||||
s.RegisterService(new(rpc.VersionService), "Version")
|
||||
s.RegisterService(new(rpc.SysInfoService), "SysInfo")
|
||||
s.RegisterService(new(rpc.MemStatsService), "MemStats")
|
||||
s.RegisterService(new(rpc.DiskInfoService), "DiskInfo")
|
||||
s.RegisterService(new(rpc.DonutService), "Donut")
|
||||
s.RegisterService(new(rpc.AuthService), "Auth")
|
||||
// Add new RPC services here
|
||||
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Minimalist Object Storage, (C) 2015 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 rpc
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
"github.com/minio/minio/pkg/utils/scsi"
|
||||
)
|
||||
|
||||
// DiskInfoService disk info service
|
||||
type DiskInfoService struct{}
|
||||
|
||||
// DiskInfoReply disk info reply for disk info service
|
||||
type DiskInfoReply struct {
|
||||
Hostname string `json:"hostname"`
|
||||
Mounts map[string]scsi.Mountinfo `json:"mounts"`
|
||||
Disks []string `json:"disks"`
|
||||
DiskAttributes map[string]scsi.Attributes `json:"-"` // for the time being not unmarshalling this
|
||||
}
|
||||
|
||||
func setDiskInfoReply(sis *DiskInfoReply) error {
|
||||
var err error
|
||||
sis.Hostname, err = os.Hostname()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
mounts, err := scsi.GetMountInfo()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
sis.Mounts = make(map[string]scsi.Mountinfo)
|
||||
sis.Mounts = mounts
|
||||
|
||||
disks, err := scsi.GetDisks()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
sis.DiskAttributes = make(map[string]scsi.Attributes)
|
||||
|
||||
for k, v := range disks {
|
||||
sis.Disks = append(sis.Disks, k)
|
||||
sis.DiskAttributes[k] = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get method
|
||||
func (s *DiskInfoService) Get(r *http.Request, args *Args, reply *DiskInfoReply) error {
|
||||
return setDiskInfoReply(reply)
|
||||
}
|
@ -43,25 +43,6 @@ func (s *MyRPCSuite) TearDownSuite(c *C) {
|
||||
testRPCServer.Close()
|
||||
}
|
||||
|
||||
func (s *MyRPCSuite) TestDiskInfo(c *C) {
|
||||
op := controller.RPCOps{
|
||||
Method: "DiskInfo.Get",
|
||||
Request: rpc.Args{Request: ""},
|
||||
}
|
||||
req, err := controller.NewRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(req.Get("Content-Type"), Equals, "application/json")
|
||||
resp, err := req.Do()
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(resp.StatusCode, Equals, http.StatusOK)
|
||||
|
||||
var reply rpc.DiskInfoReply
|
||||
err = jsonrpc.DecodeClientResponse(resp.Body, &reply)
|
||||
c.Assert(err, IsNil)
|
||||
resp.Body.Close()
|
||||
c.Assert(reply, Not(DeepEquals), rpc.DiskInfoReply{})
|
||||
}
|
||||
|
||||
func (s *MyRPCSuite) TestMemStats(c *C) {
|
||||
op := controller.RPCOps{
|
||||
Method: "MemStats.Get",
|
||||
|
@ -1,66 +0,0 @@
|
||||
// +build linux,amd64
|
||||
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 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 scsi
|
||||
|
||||
// System sysfs constants
|
||||
const (
|
||||
// From 2.6.x kernel onwards, no need to support procfs
|
||||
sysFSROOT = "/sys"
|
||||
sysFSDEVICES = "/sys/bus/scsi/devices"
|
||||
sysFSBLOCK = "/block"
|
||||
sysFSCLASSSCSIDEVICES = "/sys/class/scsi_device"
|
||||
udev = "/dev"
|
||||
devDISKBYID = "/dev/disk/by-id"
|
||||
)
|
||||
|
||||
// ScsiDEVICETYPES list of various scsi devices
|
||||
var ScsiDEVICETYPES = []string{
|
||||
"disk",
|
||||
"tape",
|
||||
"printer",
|
||||
"process",
|
||||
"worm",
|
||||
"cd/dvd",
|
||||
"scanner",
|
||||
"optical",
|
||||
"mediumx",
|
||||
"comms",
|
||||
"(0xa)",
|
||||
"(0xb)",
|
||||
"storage",
|
||||
"enclosu",
|
||||
"sim disk",
|
||||
"optical rd",
|
||||
"bridge",
|
||||
"osd",
|
||||
"adi",
|
||||
"sec man",
|
||||
"zbc",
|
||||
"(0x15)",
|
||||
"(0x16)",
|
||||
"(0x17)",
|
||||
"(0x18)",
|
||||
"(0x19)",
|
||||
"(0x1a)",
|
||||
"(0x1b)",
|
||||
"(0x1c)",
|
||||
"(0x1e)",
|
||||
"wlun",
|
||||
"no dev",
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
// +build linux
|
||||
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 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 scsi
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
var supportedFSType = map[string]bool{
|
||||
"ext4": true,
|
||||
"xfs": true,
|
||||
"ext3": true,
|
||||
"btrfs": true,
|
||||
"tmpfs": true,
|
||||
"nfs": true,
|
||||
}
|
||||
|
||||
func isSupportedType(t string) bool {
|
||||
_, ok := supportedFSType[t]
|
||||
return ok
|
||||
}
|
||||
|
||||
// GetMountInfo - get mount info map
|
||||
func GetMountInfo() (map[string]Mountinfo, error) {
|
||||
f, err := os.Open("/etc/mtab")
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
mntEnt := make(map[string]Mountinfo)
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
mtabEnt := strings.Split(scanner.Text(), " ")
|
||||
mntInfo := Mountinfo{}
|
||||
if len(mtabEnt) == 6 {
|
||||
var err error
|
||||
if !isSupportedType(mtabEnt[2]) {
|
||||
continue
|
||||
}
|
||||
mntInfo.FSName, err = filepath.EvalSymlinks(mtabEnt[0])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
mntInfo.Dir = mtabEnt[1]
|
||||
mntInfo.Type = mtabEnt[2]
|
||||
mntInfo.Opts = mtabEnt[3]
|
||||
mntInfo.Freq, err = strconv.Atoi(mtabEnt[4])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
mntInfo.Passno, err = strconv.Atoi(mtabEnt[5])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
mntEnt[mntInfo.FSName] = mntInfo
|
||||
}
|
||||
}
|
||||
return mntEnt, nil
|
||||
}
|
||||
|
||||
// IsUsable provides a comprehensive way of knowing if the provided mountPath is mounted and writable
|
||||
func IsUsable(mountPath string) (bool, error) {
|
||||
mntpoint, err := os.Stat(mountPath)
|
||||
if err != nil {
|
||||
return false, iodine.New(err, nil)
|
||||
}
|
||||
parent, err := os.Stat(filepath.Join(mountPath, ".."))
|
||||
if err != nil {
|
||||
return false, iodine.New(err, nil)
|
||||
}
|
||||
mntpointSt := mntpoint.Sys().(*syscall.Stat_t)
|
||||
parentSt := parent.Sys().(*syscall.Stat_t)
|
||||
|
||||
if mntpointSt.Dev == parentSt.Dev {
|
||||
return false, iodine.New(errors.New("not mounted"), nil)
|
||||
}
|
||||
testFile, err := ioutil.TempFile(mountPath, "writetest-")
|
||||
if err != nil {
|
||||
return false, iodine.New(err, nil)
|
||||
}
|
||||
testFileName := testFile.Name()
|
||||
// close the file, to avoid leaky fd's
|
||||
testFile.Close()
|
||||
if err := os.Remove(testFileName); err != nil {
|
||||
return false, iodine.New(err, nil)
|
||||
}
|
||||
return true, nil
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 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 scsi
|
||||
|
||||
// GetMountInfo - get mount info map
|
||||
func GetMountInfo() (map[string]Mountinfo, error) {
|
||||
// Stub implementation; returns an empty map
|
||||
return make(map[string]Mountinfo), nil
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 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 scsi
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Attributes Scsi device attributes
|
||||
type Attributes map[string]string
|
||||
|
||||
// Disks is a list of scsis disks and attributes
|
||||
type Disks map[string]Attributes
|
||||
|
||||
// Mountinfo container to capture /etc/mtab mount structure
|
||||
type Mountinfo struct {
|
||||
FSName string /* name of mounted filesystem */
|
||||
Dir string /* filesystem path prefix */
|
||||
Type string /* mount type (see mntent.h) */
|
||||
Opts string /* mount options (see mntent.h) */
|
||||
Freq int /* dump frequency in days */
|
||||
Passno int /* pass number on parallel fsck */
|
||||
}
|
||||
|
||||
func getattrs(scsiAttrPath string, scsiAttrList []string) map[string]string {
|
||||
attrMap := make(map[string]string)
|
||||
for _, attr := range scsiAttrList {
|
||||
value, _ := ioutil.ReadFile(path.Join(scsiAttrPath, attr))
|
||||
attrMap[attr] = strings.Trim(string(value[:]), "\n") // remove odd newlines
|
||||
}
|
||||
return attrMap
|
||||
}
|
||||
|
||||
func filterdisks(files []os.FileInfo) (scsidisks []string) {
|
||||
for _, fi := range files {
|
||||
if strings.Contains(fi.Name(), "host") {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(fi.Name(), "target") {
|
||||
continue
|
||||
}
|
||||
scsidisks = append(scsidisks, fi.Name())
|
||||
}
|
||||
return scsidisks
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
// +build linux,amd64
|
||||
|
||||
/*
|
||||
* Minimalist Object Storage, (C) 2015 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 scsi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// NOTE : supporting virtio based scsi devices is out of scope for this implementation
|
||||
|
||||
// Get get disk scsi params
|
||||
func (d Disks) Get(disk string) Attributes {
|
||||
return d[disk]
|
||||
}
|
||||
|
||||
// Len return len of total disks
|
||||
func (d Disks) Len() int {
|
||||
return len(d)
|
||||
}
|
||||
|
||||
// GetDisks - get system devices list
|
||||
func GetDisks() (Disks, error) {
|
||||
var scsidevices []string
|
||||
var scsiAttrList []string
|
||||
d := Disks{}
|
||||
|
||||
sysFiles, err := ioutil.ReadDir(sysFSDEVICES)
|
||||
if err != nil {
|
||||
// may be an amazon instance, ignore this
|
||||
return Disks{}, nil
|
||||
}
|
||||
|
||||
scsidevices = filterdisks(sysFiles)
|
||||
if len(scsidevices) == 0 {
|
||||
// may be a docker instance, ignore this
|
||||
return Disks{}, nil
|
||||
}
|
||||
|
||||
for _, s := range scsidevices {
|
||||
scsiAttrPath := filepath.Join(sysFSDEVICES, s)
|
||||
scsiAttrs, err := ioutil.ReadDir(scsiAttrPath)
|
||||
if err != nil {
|
||||
return Disks{}, iodine.New(err, nil)
|
||||
}
|
||||
scsiBlockPath := filepath.Join(sysFSDEVICES, s, sysFSBLOCK)
|
||||
scsidevList, err := ioutil.ReadDir(scsiBlockPath)
|
||||
if err != nil {
|
||||
return Disks{}, iodine.New(err, nil)
|
||||
}
|
||||
if len(scsidevList) > 1 {
|
||||
return Disks{}, iodine.New(errors.New("Scsi address points to multiple block devices"), nil)
|
||||
}
|
||||
device := filepath.Join(udev, scsidevList[0].Name())
|
||||
for _, sa := range scsiAttrs {
|
||||
// Skip directories
|
||||
if sa.IsDir() {
|
||||
continue
|
||||
}
|
||||
// Skip symlinks
|
||||
if !sa.Mode().IsRegular() {
|
||||
continue
|
||||
}
|
||||
// Skip, not readable, write-only
|
||||
if sa.Mode().Perm() == 128 {
|
||||
continue
|
||||
}
|
||||
scsiAttrList = append(scsiAttrList, sa.Name())
|
||||
}
|
||||
|
||||
if len(scsiAttrList) == 0 {
|
||||
return Disks{}, iodine.New(errors.New("No scsi attributes found"), nil)
|
||||
}
|
||||
d[device] = getattrs(scsiAttrPath, scsiAttrList)
|
||||
}
|
||||
return d, nil
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Minimalist Object Storage, (C) 2015 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 scsi
|
||||
|
||||
// GetDisks - get system devices list
|
||||
func GetDisks() (Disks, error) {
|
||||
// Stub implementation; returns empty disk information
|
||||
return Disks{}, nil
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Minimalist Object Storage, (C) 2015 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 scsi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/minio/check"
|
||||
)
|
||||
|
||||
type MySuite struct{}
|
||||
|
||||
var _ = Suite(&MySuite{})
|
||||
|
||||
func Test(t *testing.T) { TestingT(t) }
|
||||
|
||||
func (s *MySuite) TestSCSI(c *C) {
|
||||
_, err := GetDisks()
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestMountInfo(c *C) {
|
||||
_, err := GetMountInfo()
|
||||
c.Assert(err, IsNil)
|
||||
}
|
Loading…
Reference in New Issue
Block a user