From 4f679da756bdf8ef10f5c08fac59a69ae9d921b4 Mon Sep 17 00:00:00 2001 From: fs185143 Date: Wed, 2 Oct 2024 15:23:54 +0000 Subject: [PATCH] moved SectorSize const to fs.go in procfs package Signed-off-by: fs185143 --- blockdevice/stats.go | 19 ++++++++++--------- btrfs/get.go | 3 ++- fs.go | 10 ++++++++-- internal/fs/fs.go | 4 ---- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/blockdevice/stats.go b/blockdevice/stats.go index b1598d81..1bee6d64 100644 --- a/blockdevice/stats.go +++ b/blockdevice/stats.go @@ -21,7 +21,8 @@ import ( "os" "strings" - filesystem "github.com/prometheus/procfs/internal/fs" + "github.com/prometheus/procfs" + "github.com/prometheus/procfs/internal/fs" "github.com/prometheus/procfs/internal/util" ) @@ -221,30 +222,30 @@ const ( // FS represents the pseudo-filesystems proc and sys, which provides an // interface to kernel data structures. type FS struct { - proc *filesystem.FS - sys *filesystem.FS + proc *fs.FS + sys *fs.FS } // NewDefaultFS returns a new blockdevice fs using the default mountPoints for proc and sys. // It will error if either of these mount points can't be read. func NewDefaultFS() (FS, error) { - return NewFS(filesystem.DefaultProcMountPoint, filesystem.DefaultSysMountPoint) + return NewFS(fs.DefaultProcMountPoint, fs.DefaultSysMountPoint) } // NewFS returns a new blockdevice fs using the given mountPoints for proc and sys. // It will error if either of these mount points can't be read. func NewFS(procMountPoint string, sysMountPoint string) (FS, error) { if strings.TrimSpace(procMountPoint) == "" { - procMountPoint = filesystem.DefaultProcMountPoint + procMountPoint = fs.DefaultProcMountPoint } - procfs, err := filesystem.NewFS(procMountPoint) + procfs, err := fs.NewFS(procMountPoint) if err != nil { return FS{}, err } if strings.TrimSpace(sysMountPoint) == "" { - sysMountPoint = filesystem.DefaultSysMountPoint + sysMountPoint = fs.DefaultSysMountPoint } - sysfs, err := filesystem.NewFS(sysMountPoint) + sysfs, err := fs.NewFS(sysMountPoint) if err != nil { return FS{}, err } @@ -489,7 +490,7 @@ func (fs FS) SysBlockDeviceSize(device string) (uint64, error) { if err != nil { return 0, err } - return filesystem.SectorSize * size, nil + return procfs.SectorSize * size, nil } // SysBlockDeviceIO returns stats for the block device io counters diff --git a/btrfs/get.go b/btrfs/get.go index ac9c205c..4fce6212 100644 --- a/btrfs/get.go +++ b/btrfs/get.go @@ -22,6 +22,7 @@ import ( "strconv" "strings" + "github.com/prometheus/procfs" "github.com/prometheus/procfs/internal/fs" "github.com/prometheus/procfs/internal/util" ) @@ -208,7 +209,7 @@ func (r *reader) readDeviceInfo(d string) map[string]*Device { info := make(map[string]*Device, len(devs)) for _, n := range devs { info[n] = &Device{ - Size: fs.SectorSize * r.readValue("devices/"+n+"/size"), + Size: procfs.SectorSize * r.readValue("devices/"+n+"/size"), } } diff --git a/fs.go b/fs.go index 4980c875..9bdaccc7 100644 --- a/fs.go +++ b/fs.go @@ -24,8 +24,14 @@ type FS struct { isReal bool } -// DefaultMountPoint is the common mount point of the proc filesystem. -const DefaultMountPoint = fs.DefaultProcMountPoint +const ( + // DefaultMountPoint is the common mount point of the proc filesystem. + DefaultMountPoint = fs.DefaultProcMountPoint + + // SectorSize represents the size of a sector in bytes. + // It is specific to Linux block I/O operations. + SectorSize = 512 +) // NewDefaultFS returns a new proc FS mounted under the default proc mountPoint. // It will error if the mount point directory can't be read or is a file. diff --git a/internal/fs/fs.go b/internal/fs/fs.go index a98c700f..3a43e839 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -31,10 +31,6 @@ const ( // DefaultSelinuxMountPoint is the common mount point of the selinuxfs. DefaultSelinuxMountPoint = "/sys/fs/selinux" - - // SectorSize represents the size of a sector in bytes. - // It is specific to Linux block I/O operations. - SectorSize = 512 ) // FS represents a pseudo-filesystem, normally /proc or /sys, which provides an