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 17, 2024
1 parent 7f91d37 commit 97f94f3
Show file tree
Hide file tree
Showing 4 changed files with 193 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)
}
132 changes: 132 additions & 0 deletions internal/pkg/sysinfo/probes/filesystem_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
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 {
// https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/uapi/linux/magic.h
fsTypes := map[int64]string{
0xadf5: "adfs",
0xadff: "affs",
0x5346414f: "afs",
0x0187: "autofs",
0x00c36400: "ceph",
0x73757245: "coda",
0x28cd3d45: "cramfs",
0x453dcd28: "cramfs (wrong endian)",
0x64626720: "debugfs",
0x73636673: "securityfs",
0xf97cff8c: "selinux",
0x43415d53: "smack",
0x858458f6: "ramfs",
0x01021994: "tmpfs",
0x958458f6: "hugetlbfs",
0x73717368: "squashfs",
0xf15f: "ecryptfs",
0x414a53: "efs",
0xe0f5e1e2: "erofs v1",
0xabba1974: "xenfs",
0xef53: "ext4",
0x9123683e: "btrfs",
0x3434: "nilfs",
0xf2f52010: "f2fs",
0xf995e849: "hpfs",
0x9660: "isofs",
0x72b6: "jffs2",
0x58465342: "xfs",
0x6165676c: "pstore",
0xde5e81e4: "efivarfs",
0x00c0ffee: "hostfs",
0x794c7630: "overlayfs",
0x65735546: "fuse",
0xca451a4e: "bcachefs",
0x137f: "minix",
0x138f: "minix (30 char names)",
0x2468: "minix v2",
0x2478: "minix v2 (30 char names)",
0x4d5a: "minix v3",
0x4d44: "msdos",
0x2011bab0: "exfat",
0x564c: "ncp",
0x6969: "nfs",
0x7461636f: "ocfs2",
0x9fa1: "openprom",
0x002f: "qnx4",
0x68191122: "qnx6",
0x6b414653: "afs",
0x52654973: "reiserfs",
0x517b: "smb",
0xff534d42: "cifs",
0xfe534d42: "smb2",
0x27e0eb: "cgroup",
0x63677270: "cgroup2",
0x7655821: "rdtgroup",
0x57ac6e9d: "stack_end",
0x74726163: "tracefs",
0x01021997: "v9fs",
0x62646576: "bdevfs",
0x64646178: "daxfs",
0x42494e4d: "binfmtfs",
0x1cd1: "devpts",
0x6c6f6f70: "binderfs",
0xbad1dea: "futexfs",
0x50495045: "pipefs",
0x9fa0: "proc",
0x534f434b: "sockfs",
0x62656572: "sysfs",
0x9fa2: "usbdevice",
0x11307854: "mtd_inode_fs",
0x09041934: "anon_inode_fs",
0x73727279: "btrfs_test",
0x6e736673: "nsfs",
0xcafe4a11: "bpf_fs",
0x5a3c69f0: "aafs",
0x5a4f4653: "zonefs",
0x15013346: "udf",
0x444d4142: "dma_buf",
0x454d444d: "devmem",
0x5345434d: "secretmem",
0x50494446: "pid_fs",
}

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)
}

break
}

fs, found := fsTypes[stat.Type]

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

View workflow job for this annotation

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

cannot use stat.Type (variable of type int32) as int64 value in map index
if !found {
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 @@ -71,6 +71,7 @@ func (s *K0sSysinfoSpec) NewSysinfoProbes() probes.Probes {
minFreeDiskSpace = minFreeDiskSpace + 1300*probes.Mi
}
probes.AssertFreeDiskSpace(p, s.DataDir, minFreeDiskSpace)
probes.AssertFileSystem(p, s.DataDir)
probes.RequireNameResolution(p, net.LookupIP, "localhost")

s.addHostSpecificProbes(p)
Expand Down

0 comments on commit 97f94f3

Please sign in to comment.