Skip to content

Commit

Permalink
sysinfo: print file system of datadir
Browse files Browse the repository at this point in the history
fixes #3098

Signed-off-by: Natanael Copa <[email protected]>
  • Loading branch information
ncopa committed Jun 19, 2024
1 parent fe2ce2f commit 8e4eb5c
Show file tree
Hide file tree
Showing 4 changed files with 269 additions and 0 deletions.
37 changes: 37 additions & 0 deletions internal/pkg/sysinfo/probes/filesystem.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2024 k0s authors
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 probes

import (
"fmt"
)

// AssertFileSystem asserts a minimum amount of free disk space.
func AssertFileSystem(parent ParentProbe, fsPath string) {
parent.Set("filesystem:"+fsPath, func(path ProbePath, current Probe) Probe {
return &assertFileSystem{path, fsPath}
})
}

type assertFileSystem struct {
path ProbePath
fsPath string
}

func (a *assertFileSystem) desc() ProbeDesc {
return NewProbeDesc(fmt.Sprintf("File system of %s", a.fsPath), a.path)
}
208 changes: 208 additions & 0 deletions internal/pkg/sysinfo/probes/filesystem_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/*
Copyright 2024 k0s authors
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 probes

import (
"os"
"path"

"golang.org/x/sys/unix"
)

func (a *assertFileSystem) Probe(reporter Reporter) error {
var stat unix.Statfs_t
for p := a.fsPath; ; {
if err := unix.Statfs(p, &stat); err != nil {
if os.IsNotExist(err) {
if parent := path.Dir(p); parent != p {
p = parent
continue
}
}
return reporter.Error(a.desc(), err)
}
a.fsPath = p
break
}

var fs string
// https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/uapi/linux/magic.h
switch stat.Type {
case unix.AAFS_MAGIC:
fs = "aafs" // 0x5a3c69f0
case unix.ADFS_SUPER_MAGIC:
fs = "adfs" // 0xadf5
case unix.AFFS_SUPER_MAGIC:
fs = "affs" // 0xadff
case unix.AFS_FS_MAGIC:
fs = "afs_fs" // 0x6b414653
case unix.AFS_SUPER_MAGIC:
fs = "afs" // 0x5346414f
case unix.ANON_INODE_FS_MAGIC:
fs = "anon_inode_fs" // 0x9041934
case unix.AUTOFS_SUPER_MAGIC:
fs = "autofs" // 0x187
case unix.BDEVFS_MAGIC:
fs = "bdevfs" // 0x62646576
case unix.BINDERFS_SUPER_MAGIC:
fs = "binderfs" // 0x6c6f6f70
case unix.BINFMTFS_MAGIC:
fs = "binfmtfs" // 0x42494e4d
case unix.BPF_FS_MAGIC:

Check failure on line 65 in internal/pkg/sysinfo/probes/filesystem_linux.go

View workflow job for this annotation

GitHub Actions / Smoke test on armv7/arm64 (arm)

unix.BPF_FS_MAGIC (untyped int constant 3405662737) overflows int32
fs = "bpf_fs" // 0xcafe4a11
case unix.BTRFS_SUPER_MAGIC:

Check failure on line 67 in internal/pkg/sysinfo/probes/filesystem_linux.go

View workflow job for this annotation

GitHub Actions / Smoke test on armv7/arm64 (arm)

unix.BTRFS_SUPER_MAGIC (untyped int constant 2435016766) overflows int32
fs = "btrfs" // 0x9123683e
case unix.BTRFS_TEST_MAGIC:
fs = "btrfs_test" // 0x73727279
case unix.CEPH_SUPER_MAGIC:
fs = "ceph" // 0xc36400
case unix.CGROUP2_SUPER_MAGIC:
fs = "cgroup2" // 0x63677270
case unix.CGROUP_SUPER_MAGIC:
fs = "cgroup" // 0x27e0eb
case unix.CIFS_SUPER_MAGIC:

Check failure on line 77 in internal/pkg/sysinfo/probes/filesystem_linux.go

View workflow job for this annotation

GitHub Actions / Smoke test on armv7/arm64 (arm)

unix.CIFS_SUPER_MAGIC (untyped int constant 4283649346) overflows int32
fs = "cifs" // 0xff534d42
case unix.CODA_SUPER_MAGIC:
fs = "coda" // 0x73757245
case unix.CRAMFS_MAGIC:
fs = "cramfs" // 0x28cd3d45
case unix.DAXFS_MAGIC:
fs = "daxfs" // 0x64646178
case unix.DEBUGFS_MAGIC:
fs = "debugfs" // 0x64626720
case unix.DEVMEM_MAGIC:
fs = "devmem" // 0x454d444d
case unix.DEVPTS_SUPER_MAGIC:
fs = "devpts" // 0x1cd1
case unix.DMA_BUF_MAGIC:
fs = "dma_buf" // 0x444d4142
case unix.ECRYPTFS_SUPER_MAGIC:
fs = "ecryptfs" // 0xf15f
case unix.EFIVARFS_MAGIC:

Check failure on line 95 in internal/pkg/sysinfo/probes/filesystem_linux.go

View workflow job for this annotation

GitHub Actions / Smoke test on armv7/arm64 (arm)

unix.EFIVARFS_MAGIC (untyped int constant 3730735588) overflows int32
fs = "efivarfs" // 0xde5e81e4
case unix.EFS_SUPER_MAGIC:
fs = "efs" // 0x414a53
case unix.EROFS_SUPER_MAGIC_V1:

Check failure on line 99 in internal/pkg/sysinfo/probes/filesystem_linux.go

View workflow job for this annotation

GitHub Actions / Smoke test on armv7/arm64 (arm)

unix.EROFS_SUPER_MAGIC_V1 (untyped int constant 3774210530) overflows int32
fs = "erofs v1" // 0xe0f5e1e2
case unix.EXFAT_SUPER_MAGIC:
fs = "exfat" // 0x2011bab0
case unix.EXT4_SUPER_MAGIC: // includes ext2 and ext3
fs = "ext4" // 0xef53
case unix.F2FS_SUPER_MAGIC:

Check failure on line 105 in internal/pkg/sysinfo/probes/filesystem_linux.go

View workflow job for this annotation

GitHub Actions / Smoke test on armv7/arm64 (arm)

unix.F2FS_SUPER_MAGIC (untyped int constant 4076150800) overflows int32
fs = "f2fs" // 0xf2f52010
case unix.FUSE_SUPER_MAGIC:
fs = "fuse" // 0x65735546
case unix.FUTEXFS_SUPER_MAGIC:
fs = "futexfs" // 0xbad1dea
case unix.HOSTFS_SUPER_MAGIC:
fs = "hostfs" // 0xc0ffee
case unix.HPFS_SUPER_MAGIC:

Check failure on line 113 in internal/pkg/sysinfo/probes/filesystem_linux.go

View workflow job for this annotation

GitHub Actions / Smoke test on armv7/arm64 (arm)

unix.HPFS_SUPER_MAGIC (untyped int constant 4187351113) overflows int32
fs = "hpfs" // 0xf995e849
case unix.HUGETLBFS_MAGIC:

Check failure on line 115 in internal/pkg/sysinfo/probes/filesystem_linux.go

View workflow job for this annotation

GitHub Actions / Smoke test on armv7/arm64 (arm)

unix.HUGETLBFS_MAGIC (untyped int constant 2508478710) overflows int32
fs = "hugetlbfs" // 0x958458f6
case unix.ISOFS_SUPER_MAGIC:
fs = "isofs" // 0x9660
case unix.JFFS2_SUPER_MAGIC:
fs = "jffs2" // 0x72b6
case unix.MINIX2_SUPER_MAGIC:
fs = "minix v2" // 0x2468
case unix.MINIX2_SUPER_MAGIC2:
fs = "minix v2 (30 char names)" // 0x2478
case unix.MINIX3_SUPER_MAGIC:
fs = "minix v3" // 0x4d5a
case unix.MINIX_SUPER_MAGIC:
fs = "minix" // 0x137f
case unix.MINIX_SUPER_MAGIC2:
fs = "minix (30 char names)" // 0x138f
case unix.MSDOS_SUPER_MAGIC:
fs = "msdos" // 0x4d44
case unix.MTD_INODE_FS_MAGIC:
fs = "mtd_inode_fs" // 0x11307854
case unix.NCP_SUPER_MAGIC:
fs = "ncp" // 0x564c
case unix.NFS_SUPER_MAGIC:
fs = "nfs" // 0x6969
case unix.NILFS_SUPER_MAGIC:
fs = "nilfs" // 0x3434
case unix.NSFS_MAGIC:
fs = "nsfs" // 0x6e736673
case unix.OCFS2_SUPER_MAGIC:
fs = "ocfs2" // 0x7461636f
case unix.OPENPROM_SUPER_MAGIC:
fs = "openprom" // 0x9fa1
case unix.OVERLAYFS_SUPER_MAGIC:
fs = "overlayfs" // 0x794c7630
case unix.PID_FS_MAGIC:
fs = "pid_fs" // 0x50494446
case unix.PIPEFS_MAGIC:
fs = "pipefs" // 0x50495045
case unix.PROC_SUPER_MAGIC:
fs = "proc" // 0x9fa0
case unix.PSTOREFS_MAGIC:
fs = "pstorefs" // 0x6165676c
case unix.QNX4_SUPER_MAGIC:
fs = "qnx4" // 0x2f
case unix.QNX6_SUPER_MAGIC:
fs = "qnx6" // 0x68191122
case unix.RAMFS_MAGIC:

Check failure on line 161 in internal/pkg/sysinfo/probes/filesystem_linux.go

View workflow job for this annotation

GitHub Actions / Smoke test on armv7/arm64 (arm)

unix.RAMFS_MAGIC (untyped int constant 2240043254) overflows int32
fs = "ramfs" // 0x858458f6
case unix.RDTGROUP_SUPER_MAGIC:
fs = "rdtgroup" // 0x7655821
case unix.REISERFS_SUPER_MAGIC:
fs = "reiserfs" // 0x52654973
case unix.SECRETMEM_MAGIC:
fs = "secretmem" // 0x5345434d
case unix.SECURITYFS_MAGIC:
fs = "securityfs" // 0x73636673
case unix.SELINUX_MAGIC:

Check failure on line 171 in internal/pkg/sysinfo/probes/filesystem_linux.go

View workflow job for this annotation

GitHub Actions / Smoke test on armv7/arm64 (arm)

unix.SELINUX_MAGIC (untyped int constant 4185718668) overflows int32
fs = "selinux" // 0xf97cff8c
case unix.SMACK_MAGIC:
fs = "smack" // 0x43415d53
case unix.SMB2_SUPER_MAGIC:
fs = "smb2" // 0xfe534d42
case unix.SMB_SUPER_MAGIC:
fs = "smb" // 0x517b
case unix.SOCKFS_MAGIC:
fs = "sockfs" // 0x534f434b
case unix.SQUASHFS_MAGIC:
fs = "squashfs" // 0x73717368
case unix.STACK_END_MAGIC:
fs = "stack_end" // 0x57ac6e9d
case unix.SYSFS_MAGIC:
fs = "sysfs" // 0x62656572
case unix.TMPFS_MAGIC:
fs = "tmpfs" // 0x1021994
case unix.TRACEFS_MAGIC:
fs = "tracefs" // 0x74726163
case unix.UDF_SUPER_MAGIC:
fs = "udf" // 0x15013346
case unix.USBDEVICE_SUPER_MAGIC:
fs = "usbdevice" // 0x9fa2
case unix.V9FS_MAGIC:
fs = "v9fs" // 0x1021997
case unix.XENFS_SUPER_MAGIC:
fs = "xenfs" // 0xabba1974
case unix.XFS_SUPER_MAGIC:
fs = "xfs" // 0x58465342
case unix.ZONEFS_MAGIC:
fs = "zonefs" // 0x5a4f4653
default:
return reporter.Warn(a.desc(), StringProp(fs), "unknown")
}

return reporter.Pass(a.desc(), StringProp(fs))
}
23 changes: 23 additions & 0 deletions internal/pkg/sysinfo/probes/filesystem_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//go:build !linux

/*
Copyright 2024 k0s authors
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 probes

func (a *assertFileSystem) Probe(reporter Reporter) error {
return reporter.Warn(a.desc(), probeUnsupported("Filesystem detection unsupported on this platform"), "")
}
1 change: 1 addition & 0 deletions internal/pkg/sysinfo/sysinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (s *K0sSysinfoSpec) NewSysinfoProbes() probes.Probes {
if s.WorkerRoleEnabled {
minFreeDiskSpace = minFreeDiskSpace + 1300*probes.Mi
}
probes.AssertFileSystem(p, s.DataDir)
probes.AssertFreeDiskSpace(p, s.DataDir, minFreeDiskSpace)
probes.RequireNameResolution(p, net.LookupIP, "localhost")

Expand Down

0 comments on commit 8e4eb5c

Please sign in to comment.