mirror of
https://github.com/minio/minio.git
synced 2025-02-03 09:55:59 -05:00
Merge pull request #132 from harshavardhana/pr_out_add_linux_scsi_disk_detection_and_attribute_mapping
This commit is contained in:
commit
c58d22977a
1
pkgs/scsi/.gitignore
vendored
Normal file
1
pkgs/scsi/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
scsi
|
64
pkgs/scsi/constants.go
Normal file
64
pkgs/scsi/constants.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// !build linux,amd64
|
||||||
|
|
||||||
|
package scsi
|
||||||
|
|
||||||
|
var (
|
||||||
|
// From 2.6.x kernel onwards, no need to support procfs
|
||||||
|
SYSFSROOT = "/sys"
|
||||||
|
SYSFS_SCSI_DEVICES = "/sys/bus/scsi/devices/"
|
||||||
|
SYSFS_BLOCK = "/block/"
|
||||||
|
SYSFS_CLASS_SCSI_DEVICES = "/sys/class/scsi_device/"
|
||||||
|
UDEV = "/dev/"
|
||||||
|
DEV_DISK_BYID_DIR = "/dev/disk/by-id"
|
||||||
|
)
|
||||||
|
|
||||||
|
var SCSI_DEVICE_TYPES = []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",
|
||||||
|
}
|
96
pkgs/scsi/scsi.go
Normal file
96
pkgs/scsi/scsi.go
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// !build linux,amd64
|
||||||
|
|
||||||
|
package scsi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"io/ioutil"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NOTE : supporting virtio based scsi devices
|
||||||
|
// is out of scope for this implementation
|
||||||
|
|
||||||
|
type _Scsi struct {
|
||||||
|
device string
|
||||||
|
attrMap map[string][]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
type Devices struct {
|
||||||
|
List []_Scsi
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Devices) Get() error {
|
||||||
|
var scsidevices []string
|
||||||
|
var scsiAttrList []string
|
||||||
|
|
||||||
|
sysfs := path.Join(SYSFS_SCSI_DEVICES)
|
||||||
|
sysFiles, err := ioutil.ReadDir(sysfs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
scsidevices = filterdevices(sysFiles)
|
||||||
|
if len(scsidevices) == 0 {
|
||||||
|
return errors.New("No scsi devices found on the system")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, scsi := range scsidevices {
|
||||||
|
var _scsi _Scsi
|
||||||
|
scsiAttrPath := path.Join(sysfs, scsi, "/")
|
||||||
|
scsiAttrs, err := ioutil.ReadDir(scsiAttrPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
scsiBlockPath := path.Join(sysfs, scsi, SYSFS_BLOCK)
|
||||||
|
scsidevList, err := ioutil.ReadDir(scsiBlockPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(scsidevList) > 1 {
|
||||||
|
return errors.New("Scsi address points to multiple block devices")
|
||||||
|
}
|
||||||
|
|
||||||
|
_scsi.device = 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 errors.New("No scsi attributes found")
|
||||||
|
}
|
||||||
|
attrMap := getattrs(scsiAttrPath, scsiAttrList)
|
||||||
|
_scsi.attrMap = attrMap
|
||||||
|
d.List = append(d.List, _scsi)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
20
pkgs/scsi/scsi_test.go
Normal file
20
pkgs/scsi/scsi_test.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// !build linux,amd64
|
||||||
|
package scsi
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MySuite struct{}
|
||||||
|
|
||||||
|
var _ = Suite(&MySuite{})
|
||||||
|
|
||||||
|
func Test(t *testing.T) { TestingT(t) }
|
||||||
|
|
||||||
|
func (s *MySuite) TestSCSI(c *C) {
|
||||||
|
var d Devices
|
||||||
|
err := d.Get()
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(len(d.List), Equals, 1)
|
||||||
|
}
|
48
pkgs/scsi/utils.go
Normal file
48
pkgs/scsi/utils.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// !build linux,amd64
|
||||||
|
|
||||||
|
package scsi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getattrs(scsiAttrPath string, scsiAttrList []string) map[string][]byte {
|
||||||
|
attrMap := make(map[string][]byte)
|
||||||
|
for _, attr := range scsiAttrList {
|
||||||
|
value, _ := ioutil.ReadFile(path.Join(scsiAttrPath, attr))
|
||||||
|
attrMap[attr] = value
|
||||||
|
}
|
||||||
|
return attrMap
|
||||||
|
}
|
||||||
|
|
||||||
|
func filterdevices(files []os.FileInfo) (scsidevices []string) {
|
||||||
|
for _, fi := range files {
|
||||||
|
if strings.Contains(fi.Name(), "host") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.Contains(fi.Name(), "target") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
scsidevices = append(scsidevices, fi.Name())
|
||||||
|
}
|
||||||
|
return scsidevices
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user