diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 18dd7a4..f437d28 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -34,7 +34,12 @@ # Pooja Prasannakumar (kumarp20) # Prsanna Muthukumaraswamy (prablr79) # Trevor Dawe (tdawe) +# Luna Xu (xuluna) +# Peres Kereotubo (PeresKereotubo) +# Emily Kinuthia (EmilyKatdell) +# Kerry Kovacevic (KerryKovacevic) +# Evgeny Uglov (EvgenyUglov) # for all files: -* @kumarp20 @bpjain2004 @francis-nijay @harishp8889 @prablr79 @hoppea2 @tdawe @coulof @shaynafinocchiaro @sharmilarama @isaiasA1 @arnchiequ-dell @alikdell @atye @adamginna-dell @cbartoszDell @bogdanNovikovDell @Leonard-Dell @mareksuski-dell @mdutka-dell +* @kumarp20 @bpjain2004 @francis-nijay @harishp8889 @prablr79 @hoppea2 @tdawe @coulof @shaynafinocchiaro @sharmilarama @xuluna @PeresKereotubo @alikdell @atye @adamginna-dell @cbartoszDell @bogdanNovikovDell @Leonard-Dell @mareksuski-dell @mdutka-dell @EmilyKatdell @KerryKovacevic @EvgenyUglov diff --git a/gofsutil.go b/gofsutil.go index 0848b5d..b41a1c1 100644 --- a/gofsutil.go +++ b/gofsutil.go @@ -75,10 +75,8 @@ type FSinterface interface { FsInfo(ctx context.Context, path string) (int64, int64, int64, int64, int64, int64, error) } -var ( - // MultipathDevDiskByIDPrefix is a pathname prefix for items located in /dev/disk/by-id - MultipathDevDiskByIDPrefix = "/dev/disk/by-id/dm-uuid-mpath-3" -) +// MultipathDevDiskByIDPrefix is a pathname prefix for items located in /dev/disk/by-id +var MultipathDevDiskByIDPrefix = "/dev/disk/by-id/dm-uuid-mpath-3" var ( // ErrNotImplemented is returned when a platform does not implement @@ -111,8 +109,8 @@ func GetDiskFormat(ctx context.Context, disk string) (string, error) { func FormatAndMount( ctx context.Context, source, target, fsType string, - opts ...string) error { - + opts ...string, +) error { return fs.FormatAndMount(ctx, source, target, fsType, opts...) } @@ -120,8 +118,8 @@ func FormatAndMount( func Format( ctx context.Context, source, target, fsType string, - opts ...string) error { - + opts ...string, +) error { return fs.Format(ctx, source, target, fsType, opts...) } @@ -137,8 +135,8 @@ func Format( func Mount( ctx context.Context, source, target, fsType string, - opts ...string) error { - + opts ...string, +) error { return fs.Mount(ctx, source, target, fsType, opts...) } @@ -147,8 +145,8 @@ func Mount( func BindMount( ctx context.Context, source, target string, - opts ...string) error { - + opts ...string, +) error { return fs.BindMount(ctx, source, target, opts...) } @@ -171,7 +169,8 @@ func GetMpathNameFromDevice(ctx context.Context, device string) (string, error) func ResizeFS( ctx context.Context, volumePath, devicePath, ppathDevice, - mpathDevice, fsType string) error { + mpathDevice, fsType string, +) error { return fs.resizeFS(ctx, volumePath, devicePath, ppathDevice, mpathDevice, fsType) } @@ -182,13 +181,15 @@ func ResizeMultipath(ctx context.Context, deviceName string) error { // FindFSType fetches the filesystem type on mountpoint func FindFSType( - ctx context.Context, mountpoint string) (fsType string, err error) { + ctx context.Context, mountpoint string, +) (fsType string, err error) { return fs.findFSType(ctx, mountpoint) } // DeviceRescan rescan the device for size alterations func DeviceRescan(ctx context.Context, - devicePath string) error { + devicePath string, +) error { return fs.deviceRescan(ctx, devicePath) } @@ -217,7 +218,7 @@ func GetDevMounts(ctx context.Context, dev string) ([]Info, error) { // EvalSymlinks evaluates the provided path and updates it to remove // any symlinks in its structure, replacing them with the actual path // components. -func EvalSymlinks(ctx context.Context, symPath *string) error { +func EvalSymlinks(_ context.Context, symPath *string) error { realPath, err := filepath.EvalSymlinks(*symPath) if err != nil { return err diff --git a/gofsutil_fs.go b/gofsutil_fs.go index 1f36048..94bf4ec 100644 --- a/gofsutil_fs.go +++ b/gofsutil_fs.go @@ -21,7 +21,6 @@ import ( // FS provides many filesystem-specific functions, such as mount, format, etc. type FS struct { - // ScanEntry is the function used to process mount table entries. ScanEntry EntryScanFunc } @@ -35,8 +34,8 @@ func (fs *FS) GetDiskFormat(ctx context.Context, disk string) (string, error) { func (fs *FS) FormatAndMount( ctx context.Context, source, target, fsType string, - options ...string) error { - + options ...string, +) error { return fs.formatAndMount(ctx, source, target, fsType, options...) } @@ -44,8 +43,8 @@ func (fs *FS) FormatAndMount( func (fs *FS) Format( ctx context.Context, source, target, fsType string, - options ...string) error { - + options ...string, +) error { return fs.format(ctx, source, target, fsType, options...) } @@ -61,8 +60,8 @@ func (fs *FS) Format( func (fs *FS) Mount( ctx context.Context, source, target, fsType string, - options ...string) error { - + options ...string, +) error { return fs.mount(ctx, source, target, fsType, options...) } @@ -71,8 +70,8 @@ func (fs *FS) Mount( func (fs *FS) BindMount( ctx context.Context, source, target string, - options ...string) error { - + options ...string, +) error { if options == nil { options = []string{"bind"} } else { @@ -100,13 +99,15 @@ func (fs *FS) GetMpathNameFromDevice(ctx context.Context, device string) (string func (fs *FS) ResizeFS( ctx context.Context, volumePath, devicePath, ppathDevice, - mpathDevice, fsType string) error { + mpathDevice, fsType string, +) error { return fs.resizeFS(ctx, volumePath, devicePath, ppathDevice, mpathDevice, fsType) } // FindFSType fetches the filesystem type on mountpoint func (fs *FS) FindFSType( - ctx context.Context, mountpoint string) (fsType string, err error) { + ctx context.Context, mountpoint string, +) (fsType string, err error) { return fs.findFSType(ctx, mountpoint) } @@ -117,7 +118,8 @@ func (fs *FS) ResizeMultipath(ctx context.Context, deviceName string) error { // DeviceRescan rescan the device for size alterations func (fs *FS) DeviceRescan(ctx context.Context, - devicePath string) error { + devicePath string, +) error { return fs.deviceRescan(ctx, devicePath) } @@ -148,8 +150,8 @@ func (fs *FS) GetDevMounts(ctx context.Context, dev string) ([]Info, error) { // evaluated and returned as an absolute path without any symlinks. // Otherwise an empty string is returned. func (fs *FS) ValidateDevice( - ctx context.Context, source string) (string, error) { - + ctx context.Context, source string, +) (string, error) { return fs.validateDevice(ctx, source) } @@ -182,7 +184,7 @@ func (fs *FS) MultipathCommand(ctx context.Context, timeoutSeconds time.Duration // fsInfo linux returns (available bytes, byte capacity, byte usage, total inodes, inodes free, inode usage, error) // for the filesystem that path resides upon. -func (fs *FS) fsInfo(ctx context.Context, path string) (int64, int64, int64, int64, int64, int64, error) { +func (fs *FS) fsInfo(_ context.Context, path string) (int64, int64, int64, int64, int64, int64, error) { statfs := &unix.Statfs_t{} err := unix.Statfs(path, statfs) if err != nil { diff --git a/gofsutil_mock.go b/gofsutil_mock.go index f277612..1a02e5d 100644 --- a/gofsutil_mock.go +++ b/gofsutil_mock.go @@ -74,7 +74,7 @@ type mockfs struct { ScanEntry EntryScanFunc } -func (fs *mockfs) getDiskFormat(ctx context.Context, disk string) (string, error) { +func (fs *mockfs) getDiskFormat(_ context.Context, disk string) (string, error) { if GOFSMock.InduceGetDiskFormatError { GOFSMock.InduceMountError = false return "", errors.New("getDiskFormat induced error") @@ -91,7 +91,7 @@ func (fs *mockfs) getDiskFormat(ctx context.Context, disk string) (string, error return "", nil } -func (fs *mockfs) formatAndMount(ctx context.Context, source, target, fsType string, opts ...string) error { +func (fs *mockfs) formatAndMount(_ context.Context, source, target, fsType string, opts ...string) error { if GOFSMock.InduceBindMountError { GOFSMock.InduceMountError = false return errors.New("bindMount induced error") @@ -105,7 +105,7 @@ func (fs *mockfs) formatAndMount(ctx context.Context, source, target, fsType str return nil } -func (fs *mockfs) format(ctx context.Context, source, target, fsType string, opts ...string) error { +func (fs *mockfs) format(_ context.Context, source, target, fsType string, opts ...string) error { if GOFSMock.InduceFormatError { return errors.New("format induced error") } @@ -118,7 +118,7 @@ func (fs *mockfs) format(ctx context.Context, source, target, fsType string, opt return nil } -func (fs *mockfs) bindMount(ctx context.Context, source, target string, opts ...string) error { +func (fs *mockfs) bindMount(_ context.Context, source, target string, opts ...string) error { if GOFSMock.InduceBindMountError { return errors.New("bindMount induced error") } @@ -135,7 +135,7 @@ func (fs *mockfs) DeviceRescan(ctx context.Context, devicePath string) error { return fs.deviceRescan(ctx, devicePath) } -func (fs *mockfs) deviceRescan(ctx context.Context, devicePath string) error { +func (fs *mockfs) deviceRescan(_ context.Context, _ string) error { if GOFSMock.InduceDeviceRescanError { return errors.New("DeviceRescan induced error: Failed to rescan device") } @@ -146,7 +146,7 @@ func (fs *mockfs) ResizeFS(ctx context.Context, volumePath, devicePath, ppathDev return fs.resizeFS(ctx, volumePath, devicePath, ppathDevice, mpathDevice, fsType) } -func (fs *mockfs) resizeFS(ctx context.Context, volumePath, devicePath, ppathDevice, mpathDevice, fsType string) error { +func (fs *mockfs) resizeFS(_ context.Context, _, _, _, _, _ string) error { if GOFSMock.InduceResizeFSError { return errors.New("resizeFS induced error: Failed to resize device") } @@ -157,7 +157,7 @@ func (fs *mockfs) FindFSType(ctx context.Context, mountpoint string) (fsType str return fs.findFSType(ctx, mountpoint) } -func (fs *mockfs) findFSType(ctx context.Context, mountpoint string) (fsType string, err error) { +func (fs *mockfs) findFSType(_ context.Context, _ string) (fsType string, err error) { if GOFSMock.InduceFSTypeError { return "", errors.New("getMounts induced error: Failed to fetch filesystem as no mount info") } @@ -168,7 +168,7 @@ func (fs *mockfs) GetMountInfoFromDevice(ctx context.Context, devID string) (*De return fs.getMountInfoFromDevice(ctx, devID) } -func (fs *mockfs) getMountInfoFromDevice(ctx context.Context, devID string) (*DeviceMountInfo, error) { +func (fs *mockfs) getMountInfoFromDevice(_ context.Context, _ string) (*DeviceMountInfo, error) { if GOFSMock.InduceGetMountInfoFromDeviceError { return GOFSMockMountInfo, errors.New("getMounts induced error: Failed to find mount information") } @@ -185,7 +185,7 @@ func (fs *mockfs) GetMpathNameFromDevice(ctx context.Context, devID string) (str return fs.getMpathNameFromDevice(ctx, devID) } -func (fs *mockfs) getMpathNameFromDevice(ctx context.Context, devID string) (string, error) { +func (fs *mockfs) getMpathNameFromDevice(_ context.Context, _ string) (string, error) { if GOFSMock.InduceGetMpathNameFromDeviceError { return "", errors.New("getMpathNameFromDevice induced error: Failed to find mount information") } @@ -197,7 +197,7 @@ func (fs *mockfs) FsInfo(ctx context.Context, path string) (int64, int64, int64, return fs.fsInfo(ctx, path) } -func (fs *mockfs) fsInfo(ctx context.Context, path string) (int64, int64, int64, int64, int64, int64, error) { +func (fs *mockfs) fsInfo(_ context.Context, _ string) (int64, int64, int64, int64, int64, int64, error) { if GOFSMock.InduceFilesystemInfoError { return 0, 0, 0, 0, 0, 0, errors.New("filesystemInfo induced error: Failed to get fileystem stats") } @@ -208,27 +208,28 @@ func (fs *mockfs) ResizeMultipath(ctx context.Context, deviceName string) error return fs.resizeMultipath(ctx, deviceName) } -func (fs *mockfs) resizeMultipath(ctx context.Context, deviceName string) error { +func (fs *mockfs) resizeMultipath(_ context.Context, _ string) error { if GOFSMock.InduceResizeMultipathError { return errors.New("resize multipath induced error: Failed to resize multipath mount device") } return nil } -func (fs *mockfs) getMounts(ctx context.Context) ([]Info, error) { +func (fs *mockfs) getMounts(_ context.Context) ([]Info, error) { if GOFSMock.InduceGetMountsError { return GOFSMockMounts, errors.New("getMounts induced error") } return GOFSMockMounts, nil } -func (fs *mockfs) readProcMounts(ctx context.Context, - path string, - info bool) ([]Info, uint32, error) { +func (fs *mockfs) readProcMounts(_ context.Context, + _ string, + _ bool, +) ([]Info, uint32, error) { return nil, 0, errors.New("not implemented") } -func (fs *mockfs) mount(ctx context.Context, source, target, fsType string, opts ...string) error { +func (fs *mockfs) mount(_ context.Context, source, target, fsType string, opts ...string) error { if GOFSMock.InduceMountError { return errors.New("mount induced error") } @@ -250,7 +251,7 @@ func (fs *mockfs) mount(ctx context.Context, source, target, fsType string, opts return nil } -func (fs *mockfs) unmount(ctx context.Context, target string) error { +func (fs *mockfs) unmount(_ context.Context, target string) error { if GOFSMock.InduceUnmountError { return errors.New("unmount induced error") } @@ -263,7 +264,7 @@ func (fs *mockfs) unmount(ctx context.Context, target string) error { return nil } -func (fs *mockfs) getDevMounts(ctx context.Context, dev string) ([]Info, error) { +func (fs *mockfs) getDevMounts(_ context.Context, _ string) ([]Info, error) { if GOFSMock.InduceDevMountsError { return GOFSMockMounts, errors.New("dev mount induced error") } @@ -271,7 +272,8 @@ func (fs *mockfs) getDevMounts(ctx context.Context, dev string) ([]Info, error) } func (fs *mockfs) validateDevice( - ctx context.Context, source string) (string, error) { + _ context.Context, _ string, +) (string, error) { return "", errors.New("not implemented") } @@ -287,8 +289,8 @@ func (fs *mockfs) GetDiskFormat(ctx context.Context, disk string) (string, error func (fs *mockfs) FormatAndMount( ctx context.Context, source, target, fsType string, - options ...string) error { - + options ...string, +) error { return fs.formatAndMount(ctx, source, target, fsType, options...) } @@ -296,8 +298,8 @@ func (fs *mockfs) FormatAndMount( func (fs *mockfs) Format( ctx context.Context, source, target, fsType string, - options ...string) error { - + options ...string, +) error { return fs.format(ctx, source, target, fsType, options...) } @@ -313,8 +315,8 @@ func (fs *mockfs) Format( func (fs *mockfs) Mount( ctx context.Context, source, target, fsType string, - options ...string) error { - + options ...string, +) error { return fs.mount(ctx, source, target, fsType, options...) } @@ -323,8 +325,8 @@ func (fs *mockfs) Mount( func (fs *mockfs) BindMount( ctx context.Context, source, target string, - options ...string) error { - + options ...string, +) error { if options == nil { options = []string{"bind"} } else { @@ -365,14 +367,15 @@ func (fs *mockfs) GetDevMounts(ctx context.Context, dev string) ([]Info, error) // evaluated and returned as an absolute path without any symlinks. // Otherwise an empty string is returned. func (fs *mockfs) ValidateDevice( - ctx context.Context, source string) (string, error) { - + ctx context.Context, source string, +) (string, error) { return fs.validateDevice(ctx, source) } // wwnToDevicePath lookups a mock WWN (no prefix) to a device path. func (fs *mockfs) wwnToDevicePath( - ctx context.Context, wwn string) (string, string, error) { + _ context.Context, wwn string, +) (string, string, error) { if GOFSMockWWNToDevice == nil { GOFSMockWWNToDevice = make(map[string]string) } @@ -384,7 +387,8 @@ func (fs *mockfs) wwnToDevicePath( } func (fs *mockfs) WWNToDevicePath( - ctx context.Context, wwn string) (string, string, error) { + ctx context.Context, wwn string, +) (string, string, error) { return fs.wwnToDevicePath(ctx, wwn) } @@ -407,7 +411,7 @@ func (fs *mockfs) MultipathCommand(ctx context.Context, timeoutSeconds time.Dura // If targets are specified, only hosts who are related to the specified // iqn target(s) are rescanned. // If lun is specified, then the rescan is for that particular volume. -func (fs *mockfs) rescanSCSIHost(ctx context.Context, targets []string, lun string) error { +func (fs *mockfs) rescanSCSIHost(_ context.Context, _ []string, lun string) error { if GOFSMock.InduceRescanError { return errors.New("induced rescan error") } @@ -431,7 +435,7 @@ func (fs *mockfs) RemoveBlockDevice(ctx context.Context, blockDevicePath string) // removeBlockDevice removes a block device by getting the device name // from the last component of the blockDevicePath and then removing the // device by writing '1' to /sys/block{deviceName}/device/delete -func (fs *mockfs) removeBlockDevice(ctx context.Context, blockDevicePath string) error { +func (fs *mockfs) removeBlockDevice(_ context.Context, blockDevicePath string) error { fmt.Printf(">>>removeBlockDevice %s %#v", blockDevicePath, GOFSMockWWNToDevice) for key, value := range GOFSMockWWNToDevice { if value == blockDevicePath { @@ -465,7 +469,7 @@ func getDevice(path string) string { // Execute the multipath command with a timeout and various arguments. // Optionally a chroot directory can be specified for changing root directory. // This only works in a container or another environment where it can chroot to /noderoot. -func (fs *mockfs) multipathCommand(ctx context.Context, timeoutSeconds time.Duration, chroot string, arguments ...string) ([]byte, error) { +func (fs *mockfs) multipathCommand(_ context.Context, _ time.Duration, _ string, _ ...string) ([]byte, error) { if GOFSMock.InduceMultipathCommandError { return make([]byte, 0), errors.New("multipath command induced error") } @@ -481,7 +485,7 @@ func (fs *mockfs) TargetIPLUNToDevicePath(ctx context.Context, targetIP string, // TargetIPLUNToDevicePath returns the /dev/devxxx path when presented with an ISCSI target IP // and a LUN id. It returns the entry names in /dev/disk/by-path and their associated device paths, along with error. -func (fs *mockfs) targetIPLUNToDevicePath(ctx context.Context, targetIP string, lunID int) (map[string]string, error) { +func (fs *mockfs) targetIPLUNToDevicePath(_ context.Context, targetIP string, lunID int) (map[string]string, error) { result := make(map[string]string, 0) key := fmt.Sprintf("ip-%s:-lun-%d", targetIP, lunID) if GOFSMockTargetIPLUNToDevice == nil { @@ -500,7 +504,7 @@ func (fs *mockfs) GetFCHostPortWWNs(ctx context.Context) ([]string, error) { } // getFCHostPortWWNs returns the port WWN addresses of local FC adapters. -func (fs *mockfs) getFCHostPortWWNs(ctx context.Context) ([]string, error) { +func (fs *mockfs) getFCHostPortWWNs(_ context.Context) ([]string, error) { portWWNs := GOFSMockFCHostWWNs if GOFSMock.InduceFCHostWWNsError { return portWWNs, errors.New("induced error") @@ -514,7 +518,7 @@ func (fs *mockfs) IssueLIPToAllFCHosts(ctx context.Context) error { } // issueLIPToAllFCHosts issues the LIP command to all FC hosts. -func (fs *mockfs) issueLIPToAllFCHosts(ctx context.Context) error { +func (fs *mockfs) issueLIPToAllFCHosts(_ context.Context) error { if GOFSMock.InduceIssueLipError { return errors.New("induced error") } @@ -527,7 +531,7 @@ func (fs *mockfs) GetSysBlockDevicesForVolumeWWN(ctx context.Context, volumeWWN } // GetSysBlockDevicesForVolumeWWN given a volumeWWN will return a list of devices in /sys/block for that WWN (e.g. sdx, sdaa) -func (fs *mockfs) getSysBlockDevicesForVolumeWWN(ctx context.Context, volumeWWN string) ([]string, error) { +func (fs *mockfs) getSysBlockDevicesForVolumeWWN(_ context.Context, volumeWWN string) ([]string, error) { result := make([]string, 0) if GOFSMock.InduceGetSysBlockDevicesError { return result, errors.New("induced error") diff --git a/gofsutil_mount.go b/gofsutil_mount.go index 14a0c2e..55602da 100644 --- a/gofsutil_mount.go +++ b/gofsutil_mount.go @@ -122,10 +122,10 @@ func DefaultEntryScanFunc() EntryScanFunc { } func defaultEntryScanFunc( - ctx context.Context, + _ context.Context, entry Entry, - cache map[string]Entry) (info Info, valid bool, failed error) { - + cache map[string]Entry, +) (info Info, valid bool, failed error) { // Validate the mount table entry. validFSType, _ := regexp.MatchString( `(?i)^devtmpfs|(?:fuse\..*)|(?:nfs\d?)$`, entry.FSType) @@ -196,10 +196,10 @@ unbindable mount is unbindable func ReadProcMountsFrom( ctx context.Context, file io.Reader, - quick bool, + _ bool, expectedFields int, - scanEntry EntryScanFunc) ([]Info, uint32, error) { - + scanEntry EntryScanFunc, +) ([]Info, uint32, error) { if scanEntry == nil { scanEntry = defaultEntryScanFunc } @@ -266,10 +266,10 @@ func ReadProcMountsFrom( // // mount [-t $fsType] [-o $options] [$source] $target func MakeMountArgs( - ctx context.Context, + _ context.Context, source, target, fsType string, - opts ...string) []string { - + opts ...string, +) []string { args := []string{} if len(fsType) > 0 { args = append(args, "-t", fsType) diff --git a/gofsutil_mount_darwin.go b/gofsutil_mount_darwin.go index cfd8d0a..f833dff 100644 --- a/gofsutil_mount_darwin.go +++ b/gofsutil_mount_darwin.go @@ -30,7 +30,6 @@ var ( // getDiskFormat uses 'lsblk' to see if the given disk is unformated func (fs *FS) getDiskFormat(ctx context.Context, disk string) (string, error) { - mps, err := fs.getMounts(ctx) if err != nil { return "", err @@ -47,8 +46,8 @@ func (fs *FS) getDiskFormat(ctx context.Context, disk string) (string, error) { func (fs *FS) formatAndMount( ctx context.Context, source, target, fsType string, - opts ...string) error { - + opts ...string, +) error { return ErrNotImplemented } @@ -56,14 +55,13 @@ func (fs *FS) formatAndMount( func (fs *FS) format( ctx context.Context, source, target, fsType string, - opts ...string) error { - + opts ...string, +) error { return ErrNotImplemented } // getMounts returns a slice of all the mounted filesystems func (fs *FS) getMounts(ctx context.Context) ([]Info, error) { - out, err := exec.Command("mount").CombinedOutput() if err != nil { return nil, err @@ -113,14 +111,15 @@ func (fs *FS) getMounts(ctx context.Context) ([]Info, error) { // bindMount performs a bind mount func (fs *FS) bindMount( ctx context.Context, - source, target string, opts ...string) error { - + source, target string, opts ...string, +) error { return fs.doMount(ctx, "bindfs", source, target, "", opts...) } // readProcMounts is not implemented for darwin but defined for testing purposes func (fs *FS) readProcMounts(ctx context.Context, path string, - info bool) ([]Info, uint32, error) { + info bool, +) ([]Info, uint32, error) { return nil, 0, errors.New("not implemented") } diff --git a/gofsutil_mount_linux.go b/gofsutil_mount_linux.go index 8f21de6..d4086a2 100644 --- a/gofsutil_mount_linux.go +++ b/gofsutil_mount_linux.go @@ -34,13 +34,10 @@ const ( ppinqtool = "pp_inq" ) -var ( - bindRemountOpts = []string{"remount"} -) +var bindRemountOpts = []string{"remount"} // getDiskFormat uses 'lsblk' to see if the given disk is unformatted -func (fs *FS) getDiskFormat(ctx context.Context, disk string) (string, error) { - +func (fs *FS) getDiskFormat(_ context.Context, disk string) (string, error) { path := filepath.Clean(disk) if err := validatePath(path); err != nil { return "", err @@ -90,8 +87,8 @@ const RequestID = "RequestID" func (fs *FS) formatAndMount( ctx context.Context, source, target, fsType string, - opts ...string) error { - + opts ...string, +) error { err := fs.validateMountArgs(source, target, fsType, opts...) if err != nil { return err @@ -222,8 +219,8 @@ func (fs *FS) formatAndMount( func (fs *FS) format( ctx context.Context, source, target, fsType string, - opts ...string) error { - + opts ...string, +) error { err := fs.validateMountArgs(source, target, fsType, opts...) if err != nil { return err @@ -281,8 +278,8 @@ func (fs *FS) format( func (fs *FS) bindMount( ctx context.Context, source, target string, - opts ...string) error { - + opts ...string, +) error { err := fs.doMount(ctx, "mount", source, target, "", "bind") if err != nil { return err @@ -309,7 +306,7 @@ func (fs *FS) isLsblkNew() (bool, error) { } if s, err := strconv.ParseFloat(subMatchMap["vers"], 64); err == nil { fmt.Println(s) - if s > 2.30 { //need to check exact version + if s > 2.30 { // need to check exact version lsblkNew = true } } @@ -317,8 +314,8 @@ func (fs *FS) isLsblkNew() (bool, error) { } func (fs *FS) getMpathNameFromDevice( - ctx context.Context, device string) (string, error) { - + _ context.Context, device string, +) (string, error) { path := filepath.Clean(device) if err := validatePath(path); err != nil { return "", err @@ -348,7 +345,8 @@ func (fs *FS) getMpathNameFromDevice( } func (fs *FS) getNativeDevicesFromPpath( - ctx context.Context, ppath string) ([]string, error) { + ctx context.Context, ppath string, +) ([]string, error) { log.Infof("powerpath - trying to find native devices for ppath: %s", ppath) var devices []string var deviceWWN string @@ -390,8 +388,8 @@ func (fs *FS) getNativeDevicesFromPpath( // getMountInfoFromDevice gets mount info for the given device // It first checks the existence of powerpath device, if not then checks for multipath, if not then checks for single device. func (fs *FS) getMountInfoFromDevice( - ctx context.Context, devID string) (*DeviceMountInfo, error) { - + ctx context.Context, devID string, +) (*DeviceMountInfo, error) { path := filepath.Clean(devID) if err := validatePath(path); err != nil { return nil, err @@ -481,8 +479,8 @@ func (fs *FS) getMountInfoFromDevice( } else if mpath != "" { mountInfo.MPathName = strings.Split(mpath, "\"")[1] } else { - //In case the mpath device is of the form /dev/mapper/3600601xxxxxxx - //we check if TYPE is "mpath" then we pick the first mapper device name from NAME + // In case the mpath device is of the form /dev/mapper/3600601xxxxxxx + // we check if TYPE is "mpath" then we pick the first mapper device name from NAME for _, deviceInfo := range strings.Split(output, "\n") { deviceType := deviceTypeRegx.FindString(deviceInfo) if deviceType != "" { @@ -499,7 +497,8 @@ func (fs *FS) getMountInfoFromDevice( // FindFSType fetches the filesystem type on mountpoint func (fs *FS) findFSType( - ctx context.Context, mountpoint string) (fsType string, err error) { + _ context.Context, mountpoint string, +) (fsType string, err error) { path := filepath.Clean(mountpoint) if err := validatePath(path); err != nil { return "", fmt.Errorf("Failed to validate path: %s error %v", mountpoint, err) @@ -515,7 +514,7 @@ func (fs *FS) findFSType( return } -func (fs *FS) resizeMultipath(ctx context.Context, deviceName string) error { +func (fs *FS) resizeMultipath(_ context.Context, deviceName string) error { path := filepath.Clean(deviceName) if err := validatePath(path); err != nil { return fmt.Errorf("Failed to validate path: %s error %v", deviceName, err) @@ -532,17 +531,16 @@ func (fs *FS) resizeMultipath(ctx context.Context, deviceName string) error { return nil } -//resizeFS expands the filesystem to the new size of underlying device -//For XFS filesystem needs filesystem mount point -//For EXT4 needs devicepath -//For EXT3 needs devicepath -//For multipath device, fs resize needs "/device/mapper/mpathname" -//For powerpath device, fs resize needs "/dev/emcpowera" - +// resizeFS expands the filesystem to the new size of underlying device +// For XFS filesystem needs filesystem mount point +// For EXT4 needs devicepath +// For EXT3 needs devicepath +// For multipath device, fs resize needs "/device/mapper/mpathname" +// For powerpath device, fs resize needs "/dev/emcpowera" func (fs *FS) resizeFS( ctx context.Context, mountpoint, - devicePath, ppathDevice, mpathDevice, fsType string) error { - + devicePath, ppathDevice, mpathDevice, fsType string, +) error { if ppathDevice != "" { devicePath = "/dev/" + ppathDevice err := reReadPartitionTable(ctx, devicePath) @@ -570,7 +568,7 @@ func (fs *FS) resizeFS( } // reReadPartitionTable re-read the partition table of the pseudo device. -func reReadPartitionTable(ctx context.Context, devicePath string) error { +func reReadPartitionTable(_ context.Context, devicePath string) error { path := filepath.Clean(devicePath) if err := validatePath(path); err != nil { return fmt.Errorf("Failed to validate path: %s error %v", devicePath, err) @@ -616,8 +614,9 @@ func (fs *FS) expandXfs(volumePath string) error { } // DeviceRescan rescan the device for size alterations -func (fs *FS) deviceRescan(ctx context.Context, - devicePath string) error { +func (fs *FS) deviceRescan(_ context.Context, + devicePath string, +) error { path := filepath.Clean(devicePath) if err := validatePath(path); err != nil { return err @@ -673,16 +672,14 @@ func (fs *FS) getMounts(ctx context.Context) ([]Info, error) { func (fs *FS) readProcMounts( ctx context.Context, path string, - info bool) ([]Info, uint32, error) { + info bool, +) ([]Info, uint32, error) { file, err := os.Open(filepath.Clean(path)) if err != nil { return nil, 0, err } defer func() error { - if err := file.Close(); err != nil { - return err - } - return nil + return file.Close() }() return ReadProcMountsFrom(ctx, file, !info, ProcMountsFields, fs.ScanEntry) } diff --git a/gofsutil_mount_scanentry_test.go b/gofsutil_mount_scanentry_test.go index 18736c8..b23e1fd 100644 --- a/gofsutil_mount_scanentry_test.go +++ b/gofsutil_mount_scanentry_test.go @@ -23,7 +23,7 @@ import ( ) func newTestEntryScanFunc(t *testing.T) gofsutil.EntryScanFunc { - //return gofsutil.DefaultEntryScanFunc() + // return gofsutil.DefaultEntryScanFunc() return (&testEntryScanFunc{t}).scan } @@ -32,11 +32,11 @@ type testEntryScanFunc struct { } func (p *testEntryScanFunc) scan( - ctx context.Context, + _ context.Context, entry gofsutil.Entry, cache map[string]gofsutil.Entry) ( - info gofsutil.Info, valid bool, failed error) { - + info gofsutil.Info, valid bool, failed error, +) { // p.t.Logf("root=%s\tmountPoint=%s\t"+ // "fsType=%s\tmountSource=%s\tmountOpts=%v", // root, mountPoint, fsType, mountSource, mountOpts) @@ -81,7 +81,6 @@ func (p *testEntryScanFunc) scan( } func TestReadProcMountsFrom(t *testing.T) { - mountInfos, _, err := gofsutil.ReadProcMountsFrom( context.TODO(), strings.NewReader(procMountInfoData), diff --git a/gofsutil_mount_unix.go b/gofsutil_mount_unix.go index 2fdbbd1..1f74acb 100644 --- a/gofsutil_mount_unix.go +++ b/gofsutil_mount_unix.go @@ -41,8 +41,8 @@ import ( func (fs *FS) mount( ctx context.Context, source, target, fsType string, - opts ...string) error { - + opts ...string, +) error { // All Linux distributes should support bind mounts. if opts, ok := fs.isBind(ctx, opts...); ok { return fs.bindMount(ctx, source, target, opts...) @@ -52,7 +52,6 @@ func (fs *FS) mount( // validateMountArgs validates the arguments for mount operation. func (fs *FS) validateMountArgs(source, target, fsType string, opts ...string) error { - sourcePath := filepath.Clean(source) targetPath := filepath.Clean(target) @@ -70,19 +69,15 @@ func (fs *FS) validateMountArgs(source, target, fsType string, opts ...string) e } } - if err := validateMountOptions(opts...); err != nil { - return err - } - - return nil + return validateMountOptions(opts...) } // doMount runs the mount command. func (fs *FS) doMount( ctx context.Context, mntCmd, source, target, fsType string, - opts ...string) error { - + opts ...string, +) error { if err := fs.validateMountArgs(source, target, fsType, opts...); err != nil { return err } @@ -99,7 +94,7 @@ func (fs *FS) doMount( buf, err := exec.Command(mntCmd, mountArgs...).CombinedOutput() if err != nil { out := string(buf) - //check is explicitly placed for PowerScale driver only + // check is explicitly placed for PowerScale driver only if !(strings.Contains(args, "/ifs") && (strings.Contains(strings.ToLower(out), "access denied by server while mounting") || strings.Contains(strings.ToLower(out), "no such file or directory"))) { log.WithFields(f).WithField("output", out).WithError( err).Error("mount Failed") @@ -112,7 +107,7 @@ func (fs *FS) doMount( } // unmount unmounts the target. -func (fs *FS) unmount(ctx context.Context, target string) error { +func (fs *FS) unmount(_ context.Context, target string) error { f := log.Fields{ "path": target, "cmd": "umount", @@ -140,7 +135,7 @@ func (fs *FS) unmount(ctx context.Context, target string) error { // // The returned options will be "bind", "remount", and the provided // list of options. -func (fs *FS) isBind(ctx context.Context, opts ...string) ([]string, bool) { +func (fs *FS) isBind(_ context.Context, opts ...string) ([]string, bool) { bind := false remountOpts := append([]string(nil), bindRemountOpts...) @@ -161,7 +156,6 @@ func (fs *FS) isBind(ctx context.Context, opts ...string) ([]string, bool) { // getDevMounts returns a slice of all mounts for dev func (fs *FS) getDevMounts(ctx context.Context, dev string) ([]Info, error) { - allMnts, err := fs.getMounts(ctx) if err != nil { return nil, err @@ -178,8 +172,8 @@ func (fs *FS) getDevMounts(ctx context.Context, dev string) ([]Info, error) { } func (fs *FS) validateDevice( - ctx context.Context, source string) (string, error) { - + ctx context.Context, source string, +) (string, error) { if _, err := os.Lstat(source); err != nil { return "", err } @@ -205,8 +199,8 @@ func (fs *FS) validateDevice( // and returns a) the symlink path in /dev/disk/by-id and // b) the corresponding device entry in /dev. func (fs *FS) wwnToDevicePath( - ctx context.Context, wwn string) (string, string, error) { - + _ context.Context, wwn string, +) (string, string, error) { // Look for multipath device. symlinkPath := fmt.Sprintf("%s%s", MultipathDevDiskByIDPrefix, wwn) devPath, err := os.Readlink(symlinkPath) @@ -228,7 +222,7 @@ func (fs *FS) wwnToDevicePath( } // targetIPLUNToDevicePath returns all the /dev/disk/by-path entries for a give targetIP and lunID -func (fs *FS) targetIPLUNToDevicePath(ctx context.Context, targetIP string, lunID int) (map[string]string, error) { +func (fs *FS) targetIPLUNToDevicePath(_ context.Context, targetIP string, lunID int) (map[string]string, error) { result := make(map[string]string, 0) bypathdir := "/dev/disk/by-path" entries, err := os.ReadDir(bypathdir) @@ -280,7 +274,7 @@ func (td *targetdev) String() string { // If targets are specified, only hosts who are related to the specified // iqn target(s) are rescanned. // If lun is specified, then the rescan is for that particular volume. -func (fs *FS) rescanSCSIHost(ctx context.Context, targets []string, lun string) error { +func (fs *FS) rescanSCSIHost(_ context.Context, targets []string, lun string) error { var err error // If no lun is specifed, the "-" character is a wildcard that will update all LUNs. if lun == "" { @@ -315,7 +309,7 @@ func (fs *FS) rescanSCSIHost(ctx context.Context, targets []string, lun string) scanfile := fmt.Sprintf("%s/%s/scan", hostsdir, entry.host) scanstring := fmt.Sprintf("%s %s %s", entry.channel, entry.target, lun) log.Printf("rescanning %s with: "+scanstring, scanfile) - f, err := os.OpenFile(filepath.Clean(scanfile), os.O_APPEND|os.O_WRONLY, 0200) + f, err := os.OpenFile(filepath.Clean(scanfile), os.O_APPEND|os.O_WRONLY, 0o200) if err != nil { log.WithFields(log.Fields{"file": scanfile, "error": err}).Error("Failed to open scanfile") continue @@ -347,7 +341,7 @@ func (fs *FS) rescanSCSIHost(ctx context.Context, targets []string, lun string) scanfile := fmt.Sprintf("%s/%s/scan", hostsdir, host.Name()) scanstring := fmt.Sprintf("- - %s", lun) log.Printf("rescanning %s with: "+scanstring, scanfile) - f, err := os.OpenFile(filepath.Clean(scanfile), os.O_APPEND|os.O_WRONLY, 0200) + f, err := os.OpenFile(filepath.Clean(scanfile), os.O_APPEND|os.O_WRONLY, 0o200) if err != nil { log.WithFields(log.Fields{"file": scanfile, "error": err}).Error("Failed to open scanfile") continue @@ -506,7 +500,7 @@ func splitTargets(targets []string) ([]string, []string) { // removeBlockDevice removes a block device by getting the device name // from the last component of the blockDevicePath and then removing the // device by writing '1' to /sys/block{deviceName}/device/delete -func (fs *FS) removeBlockDevice(ctx context.Context, blockDevicePath string) error { +func (fs *FS) removeBlockDevice(_ context.Context, blockDevicePath string) error { // Here we want to remove /sys/block/{deviceName} by writing a 1 to // /sys/block{deviceName}/device/delete devicePathComponents := strings.Split(blockDevicePath, "/") @@ -522,7 +516,7 @@ func (fs *FS) removeBlockDevice(ctx context.Context, blockDevicePath string) err return fmt.Errorf("Device %s is in blocked state", deviceName) } blockDeletePath := fmt.Sprintf("/sys/block/%s/device/delete", deviceName) - f, err := os.OpenFile(filepath.Clean(blockDeletePath), os.O_APPEND|os.O_WRONLY, 0200) + f, err := os.OpenFile(filepath.Clean(blockDeletePath), os.O_APPEND|os.O_WRONLY, 0o200) if err != nil { log.WithField("BlockDeletePath", blockDeletePath).Error("Could not open delete block device delete path") return err @@ -578,7 +572,7 @@ func (fs *FS) multipathCommand(ctx context.Context, timeoutSeconds time.Duration } // getFCHostPortWWNs returns the port WWN addresses of local FC adapters. -func (fs *FS) getFCHostPortWWNs(ctx context.Context) ([]string, error) { +func (fs *FS) getFCHostPortWWNs(_ context.Context) ([]string, error) { portWWNs := make([]string, 0) // Read the directory entries for fc_remote_ports fcHostsDir := "/sys/class/fc_host" @@ -605,7 +599,7 @@ func (fs *FS) getFCHostPortWWNs(ctx context.Context) ([]string, error) { } // issueLIPToAllFCHosts issues the LIP command to all FC hosts. -func (fs *FS) issueLIPToAllFCHosts(ctx context.Context) error { +func (fs *FS) issueLIPToAllFCHosts(_ context.Context) error { var savedError error // Read the directory entries for fc_remote_ports fcHostsDir := "/sys/class/fc_host" @@ -623,7 +617,7 @@ func (fs *FS) issueLIPToAllFCHosts(ctx context.Context) error { lipFile := fmt.Sprintf("%s/%s/issue_lip", fcHostsDir, hostEntry.Name()) lipString := fmt.Sprintf("%s", "1") log.Printf("issuing lip command %s to %s", lipString, lipFile) - f, err := os.OpenFile(filepath.Clean(lipFile), os.O_APPEND|os.O_WRONLY, 0200) + f, err := os.OpenFile(filepath.Clean(lipFile), os.O_APPEND|os.O_WRONLY, 0o200) if err != nil { log.Error("Could not open issue_lip file at: " + lipFile) continue @@ -641,7 +635,7 @@ func (fs *FS) issueLIPToAllFCHosts(ctx context.Context) error { } // getSysBlockDevicesForVolumeWWN given a volumeWWN will return a list of devices in /sys/block for that WWN (e.g. sdx, sdaa) -func (fs *FS) getSysBlockDevicesForVolumeWWN(ctx context.Context, volumeWWN string) ([]string, error) { +func (fs *FS) getSysBlockDevicesForVolumeWWN(_ context.Context, volumeWWN string) ([]string, error) { start := time.Now() result := make([]string, 0) sysBlockDir := "/sys/block" diff --git a/gofsutil_mount_windows.go b/gofsutil_mount_windows.go index 204760b..c5691ce 100644 --- a/gofsutil_mount_windows.go +++ b/gofsutil_mount_windows.go @@ -43,9 +43,11 @@ func (fs *FS) resizeFS(ctx context.Context, volumePath, devicePath, ppathDevice, // findFSType fetches the filesystem type on mountpoint func (fs *FS) findFSType( - ctx context.Context, mountpoint string) (fsType string, err error) { + ctx context.Context, mountpoint string, +) (fsType string, err error) { return "", errors.New("not implemented") } + func (fs *FS) getMountInfoFromDevice(ctx context.Context, devID string) (*DeviceMountInfo, error) { return nil, errors.New("not implemented") } @@ -60,18 +62,19 @@ func (fs *FS) resizeMultipath(ctx context.Context, deviceName string) error { // DeviceRescan rescan the device for size alterations func (fs *FS) deviceRescan(ctx context.Context, - devicePath string) error { + devicePath string, +) error { return errors.New("not implemented") } func (fs *FS) getMounts(ctx context.Context) ([]Info, error) { - return info, errors.New("not implemented") } func (fs *FS) readProcMounts(ctx context.Context, path string, - info bool) ([]Info, uint32, error) { + info bool, +) ([]Info, uint32, error) { return nil, 0, errors.New("not implemented") } @@ -89,12 +92,14 @@ func (fs *FS) getDevMounts(ctx context.Context, dev string) ([]Info, error) { } func (fs *FS) validateDevice( - ctx context.Context, source string) (string, error) { + ctx context.Context, source string, +) (string, error) { return "", errors.New("not implemented") } func (fs *FS) wwnToDevicePath( - ctx context.Context, wwn string) (string, string, error) { + ctx context.Context, wwn string, +) (string, string, error) { return "", "", errors.New("not implemented") } diff --git a/gofsutil_removeduplicates_test.go b/gofsutil_removeduplicates_test.go index 319d947..495c887 100644 --- a/gofsutil_removeduplicates_test.go +++ b/gofsutil_removeduplicates_test.go @@ -150,7 +150,8 @@ func benchmarkRemoveDuplicates(b *testing.B, f rdf, d []string) { } var benchRemoveDupesData = []string{ - "a", "b", "b", "c", "cat", "", "cat2", "dog", "dog", "z", ""} + "a", "b", "b", "c", "cat", "", "cat2", "dog", "dog", "z", "", +} type rdf func([]string) []string diff --git a/gofsutil_utils_test.go b/gofsutil_utils_test.go index 64b82d7..4032be4 100644 --- a/gofsutil_utils_test.go +++ b/gofsutil_utils_test.go @@ -53,7 +53,6 @@ func TestValidatePath(t *testing.T) { } } } - }) } } @@ -105,7 +104,6 @@ func TestValidateFsType(t *testing.T) { } } } - }) } }