diff --git a/pkg/os/scsi/constants_linux.go b/pkg/os/scsi/constants_linux.go deleted file mode 100644 index 044506f2..00000000 --- a/pkg/os/scsi/constants_linux.go +++ /dev/null @@ -1,66 +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. - */ - -// !build linux,amd64 - -package scsi - -// From 2.6.x kernel onwards, no need to support procfs -var ( - SysfsScsiDevices = "/sys/bus/scsi/devices/" - SysfsBlock = "/sys/block/" - SysfsClassBlock = "/sys/class/block/" - SysfsClassScsiDevices = "/sys/class/scsi_device/" - Udev = "/dev/" - Mountinfo = "/proc/self/mountinfo" - DevDiskByIDDir = "/dev/disk/by-id" -) - -// ScsiDeviceTypes - non exhaustive list of all the device types in linux -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", -} diff --git a/pkg/os/scsi/errors.go b/pkg/os/scsi/errors.go deleted file mode 100644 index 6b118fe1..00000000 --- a/pkg/os/scsi/errors.go +++ /dev/null @@ -1,66 +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 - -// NoPartitionAttributesFound - no partition attributes found -type NoPartitionAttributesFound struct{} - -func (e NoPartitionAttributesFound) Error() string { - return "No Partition Attributes Found" -} - -// NoDiskAttributesFound - no disk attributes found -type NoDiskAttributesFound struct{} - -func (e NoDiskAttributesFound) Error() string { - return "No Disk Attributes Found" -} - -// NoDiskQueueAttributesFound - no disk queue attributes found -type NoDiskQueueAttributesFound struct{} - -func (e NoDiskQueueAttributesFound) Error() string { - return "No Disk Queue Attributes Found" -} - -// NoDevicesFoundOnSystem - no scsi disks found on a given system -type NoDevicesFoundOnSystem struct{} - -func (e NoDevicesFoundOnSystem) Error() string { - return "No scsi devices found on the system" -} - -// AddressPointsToMultipleBlockDevices - scsi address points to multiple block devices -type AddressPointsToMultipleBlockDevices struct{} - -func (e AddressPointsToMultipleBlockDevices) Error() string { - return "Scsi address points to multiple block devices" -} - -// NoAttributesFound - no disk scsi attributes found -type NoAttributesFound struct{} - -func (e NoAttributesFound) Error() string { - return "No Scsi Attributes Found" -} - -// CorruptedMountInfo - mount info corrupted -type CorruptedMountInfo struct{} - -func (e CorruptedMountInfo) Error() string { - return "mount info corrupted" -} diff --git a/pkg/os/scsi/scsi_linux.go b/pkg/os/scsi/scsi_linux.go deleted file mode 100644 index 3f26c945..00000000 --- a/pkg/os/scsi/scsi_linux.go +++ /dev/null @@ -1,291 +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. - */ - -// !build linux,amd64 - -package scsi - -import ( - "bufio" - "io" - "io/ioutil" - "os" - "path" - "strings" -) - -// NOTE : supporting virtio based scsi devices -// is out of scope for this implementation - -var optFields = []string{ - "shared:", - "master:", - "propagate_from:", - "unbindable", -} - -// Devices - list of all scsi disks -type Devices struct { - List []Disk - Mountinfo []map[string]string -} - -// Disk - struct which carries per disk name, scsi and disk attributes -type Disk struct { - Name string - Partitions []Partition - Scsiattrmap map[string][]byte - Diskattrmap map[string][]byte -} - -// Partition - struct which carries per partition name, and its attributes -type Partition struct { - Name string - Partitionattrmap map[string][]byte -} - -// getPartitionAttrs - populates all the partition related attributes -func (p *Partition) getPartitionAttrs(part string) error { - var partitionAttrsList []string - p.Name = path.Join(Udev, part) - sysfsBlockClassDev := path.Join(SysfsClassBlock, part) - partitionFiles, err := ioutil.ReadDir(sysfsBlockClassDev) - if err != nil { - return err - } - for _, f := range partitionFiles { - if f.IsDir() { - continue - } - if !f.Mode().IsRegular() { - continue - } - // Skip, not readable, write-only - if f.Mode().Perm() == 128 { - continue - } - partitionAttrsList = append(partitionAttrsList, f.Name()) - if len(partitionAttrsList) == 0 { - return NoPartitionAttributesFound{} - } - } - p.Partitionattrmap = getattrs(sysfsBlockClassDev, partitionAttrsList) - return nil -} - -func (d *Disk) getDiskAttrList(scsiFiles []os.FileInfo, disk string) (diskAttrsList []string, err error) { - for _, sf := range scsiFiles { - if sf.IsDir() { - if strings.Contains(sf.Name(), disk) { - var p = Partition{} - if err := p.getPartitionAttrs(sf.Name()); err != nil { - return nil, err - } - d.Partitions = append(d.Partitions, p) - } - continue - } - // Skip symlinks - if !sf.Mode().IsRegular() { - continue - } - // Skip, not readable, write-only - if sf.Mode().Perm() == 128 { - continue - } - diskAttrsList = append(diskAttrsList, sf.Name()) - } - return diskAttrsList, nil -} - -func (d *Disk) getDiskQueueAttrsList(scsiQueueFiles []os.FileInfo) (diskQueueAttrsList []string, err error) { - for _, sf := range scsiQueueFiles { - if sf.IsDir() { - continue - } - // Skip symlinks - if !sf.Mode().IsRegular() { - continue - } - // Skip, not readable, write-only - if sf.Mode().Perm() == 128 { - continue - } - diskQueueAttrsList = append(diskQueueAttrsList, sf.Name()) - } - return diskQueueAttrsList, nil -} - -// getDiskAttrs - populates all the disk related attributes -func (d *Disk) getDiskAttrs(disk string) error { - var diskAttrsList []string - var diskQueueAttrsList []string - aggrAttrMap := make(map[string][]byte) - - sysfsBlockDev := path.Join(SysfsBlock, disk) - sysfsBlockDevQueue := path.Join(sysfsBlockDev, "/queue") - - scsiFiles, err := ioutil.ReadDir(sysfsBlockDev) - if err != nil { - return err - } - - scsiQueueFiles, err := ioutil.ReadDir(sysfsBlockDevQueue) - if err != nil { - return err - } - - diskAttrsList, err = d.getDiskAttrList(scsiFiles, disk) - if err != nil { - return err - } - - diskQueueAttrsList, err = d.getDiskQueueAttrsList(scsiQueueFiles) - if err != nil { - return err - } - - if len(diskAttrsList) == 0 { - return NoDiskAttributesFound{} - } - - if len(diskQueueAttrsList) == 0 { - return NoDiskQueueAttributesFound{} - } - - diskAttrMap := getattrs(sysfsBlockDev, diskAttrsList) - diskQueueAttrMap := getattrs(sysfsBlockDevQueue, diskQueueAttrsList) - - for k, v := range diskAttrMap { - aggrAttrMap[k] = v - } - - for k, v := range diskQueueAttrMap { - aggrAttrMap[k] = v - } - d.Diskattrmap = aggrAttrMap - return nil -} - -// getMountInfo - populates all mount points on the disk -func (d *Devices) getMountInfo() error { - fl, err := os.Open(Mountinfo) - defer fl.Close() - if err != nil { - return err - } - reader := bufio.NewReader(fl) - for err == nil { - var line string - line, err = reader.ReadString('\n') - if err != nil { - break - } - splits := strings.Fields(line) - if len(splits) > 11 { - return CorruptedMountInfo{} - } - mount := make(map[string]string) - mount["mountID"] = splits[0] - mount["parentID"] = splits[1] - mount["majorminor"] = splits[2] - mount["root"] = splits[3] - mount["mountPoint"] = splits[4] - mount["mountOptions"] = splits[5] - if len(splits) <= 10 { - mount["separator"] = splits[6] - mount["fsType"] = splits[7] - mount["mountSource"] = splits[8] - mount["superBlockOptions"] = splits[9] - } else if len(splits) == 11 { - mount["optFields"] = splits[6] - mount["separator"] = splits[7] - mount["fsType"] = splits[8] - mount["mountSource"] = splits[9] - mount["superBlockOptions"] = splits[10] - } - d.Mountinfo = append(d.Mountinfo, mount) - } - if err != io.EOF { - return err - } - return nil -} - -// Get - get queries local system and populates all the attributes -func (d *Devices) Get() error { - var scsidevices []string - var scsiAttrList []string - - sysFiles, err := ioutil.ReadDir(SysfsScsiDevices) - if err != nil { - return err - } - - scsidevices = filterdevices(sysFiles) - if len(scsidevices) == 0 { - return NoDevicesFoundOnSystem{} - } - - if err := d.getMountInfo(); err != nil { - return err - } - for _, scsi := range scsidevices { - var _scsi Disk - scsiAttrPath := path.Join(SysfsScsiDevices, scsi, "/") - scsiAttrs, err := ioutil.ReadDir(scsiAttrPath) - if err != nil { - return err - } - scsiBlockPath := path.Join(SysfsScsiDevices, scsi, "/block") - scsidevList, err := ioutil.ReadDir(scsiBlockPath) - if err != nil { - return err - } - - if len(scsidevList) > 1 { - return AddressPointsToMultipleBlockDevices{} - } - - _scsi.Name = path.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 NoAttributesFound{} - } - _scsi.Scsiattrmap = getattrs(scsiAttrPath, scsiAttrList) - err = _scsi.getDiskAttrs(scsidevList[0].Name()) - if err != nil { - return err - } - d.List = append(d.List, _scsi) - } - return nil -} diff --git a/pkg/os/scsi/scsi_linux_test.go b/pkg/os/scsi/scsi_linux_test.go deleted file mode 100644 index b7c312df..00000000 --- a/pkg/os/scsi/scsi_linux_test.go +++ /dev/null @@ -1,40 +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. - */ - -// !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) - - c.Assert(len(d.List[0].Scsiattrmap), Not(Equals), 0) - c.Assert(len(d.List[0].Diskattrmap), Not(Equals), 0) -} diff --git a/pkg/os/scsi/utils_linux.go b/pkg/os/scsi/utils_linux.go deleted file mode 100644 index 5b2383d1..00000000 --- a/pkg/os/scsi/utils_linux.go +++ /dev/null @@ -1,48 +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. - */ - -// !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 -}