github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/pkg/smart/diskinfo.go (about) 1 /* 2 Copyright 2018 The OpenEBS Authors. 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 http://www.apache.org/licenses/LICENSE-2.0 7 Unless required by applicable law or agreed to in writing, software 8 distributed under the License is distributed on an "AS IS" BASIS, 9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 See the License for the specific language governing permissions and 11 limitations under the License. 12 */ 13 14 package smart 15 16 import ( 17 "fmt" 18 ) 19 20 // SCSIBasicDiskInfo returns all the available disk details for a particular disk device 21 func (I *Identifier) SCSIBasicDiskInfo() (DiskAttr, map[string]error) { 22 diskDetail := DiskAttr{} 23 // Collector will be used to collect errors in a string to error map 24 collector := NewErrorCollector() 25 26 // Before getting disk details, check if the necessary conditions to get 27 // disk details are fulfilled or not such as device path is given or not, 28 // binary permissions are set or not, bus type is supported or not, etc 29 if err := isConditionSatisfied(I.DevPath); err != nil { 30 collector.Collect(errorCheckConditions, err) 31 return diskDetail, collector.Error() 32 } 33 // Check the type of SCSI device, if it is ATA or something else.. 34 // based on which the dev interface is returned 35 d, err := detectSCSIType(I.DevPath) 36 if collector.Collect(DetectSCSITypeErr, err) { 37 return diskDetail, collector.Error() 38 } 39 defer d.Close() 40 41 // Get all the available disk details in the form of struct and errors if any (in form of map) 42 diskDetail, errorMap := d.getBasicDiskInfo() 43 44 return diskDetail, errorMap 45 } 46 47 // SCSIBasicDiskInfoByAttrName returns disk details(disk attributes and their values such as vendor,serialno,etc) of a disk 48 func (I *Identifier) SCSIBasicDiskInfoByAttrName(attrName string) (string, error) { 49 var AttrDetail string 50 // Before getting disk details, check if the necessary conditions to get 51 // disk details are fulfilled or not 52 if err := isConditionSatisfied(I.DevPath); err != nil { 53 return "", err 54 } 55 56 // Check if any attribute is given or not 57 if attrName == "" { 58 return "", fmt.Errorf("no attribute name specified to get the value") 59 } 60 61 // Check the type of SCSI device, if it is ATA or something else.. 62 // based on which the dev interface is returned 63 d, err := detectSCSIType(I.DevPath) 64 if err != nil { 65 return "", fmt.Errorf("error in detecting type of SCSI device, Error: %+v", err) 66 } 67 defer d.Close() 68 69 // Get the value of a particular disk attribute 70 AttrDetail, err = d.getBasicDiskInfoByAttr(attrName) 71 if err != nil { 72 return AttrDetail, fmt.Errorf("error getting %q of disk having devpath %q, error: %+v", attrName, I.DevPath, err) 73 } 74 return AttrDetail, nil 75 }