v0.59.0: report backing device + capacity for a registry-sourced /disks row

Agent-view showed "—" device + no size for a raw (no-PVE-storage) drive because
the registry union row never set backing_device/total_bytes/used_bytes (Observe
drives get those from pvesm status). Resolve BackingDevice via ByUUIDDevicePath +
read capacity via statfsCapacity (build-tagged syscall.Statfs; no-op off-Linux).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-01 21:34:11 +02:00
parent b52680ab47
commit 5ff5f8e0ab
5 changed files with 57 additions and 1 deletions
+26
View File
@@ -0,0 +1,26 @@
//go:build linux
package localapi
import "syscall"
// statfsCapacity returns the total + used bytes of the filesystem mounted at path (Linux statvfs). A
// registry-sourced drive (no PVE storage) has no `pvesm status` usage, so /disks reads capacity here
// instead. ok=false on any error → the caller leaves the size fields zero.
func statfsCapacity(path string) (total, used int64, ok bool) {
var st syscall.Statfs_t
if err := syscall.Statfs(path, &st); err != nil {
return 0, 0, false
}
bs := int64(st.Bsize)
total = int64(st.Blocks) * bs
if total <= 0 {
return 0, 0, false
}
free := int64(st.Bfree) * bs
used = total - free
if used < 0 {
used = 0
}
return total, used, true
}
+6
View File
@@ -0,0 +1,6 @@
//go:build !linux
package localapi
// statfsCapacity is Linux-only (syscall.Statfs); on other platforms (dev builds) it reports nothing.
func statfsCapacity(string) (total, used int64, ok bool) { return 0, 0, false }
+12
View File
@@ -235,6 +235,18 @@ func (s *Server) handleDisks(w http.ResponseWriter, r *http.Request, vmid int) {
di.GuestPath = gp
di.BoundUnderParent = s.boundUnderParent(r.Context(), vmid, gp)
}
// A registry drive has no PVE `pvesm status` snapshot, so fill backing device + capacity
// from the host directly: resolve the device by fs-UUID, and statfs the mount for size —
// else the agent-view shows "—" for the device and no size bar.
if d.UUID != "" {
if dev, err := storage.ByUUIDDevicePath(d.UUID); err == nil {
di.BackingDevice = dev
}
}
if total, used, okc := statfsCapacity(d.MountPath); okc {
di.TotalBytes, di.UsedBytes = total, used
di.UsedFraction = float64(used) / float64(total)
}
out = append(out, di)
}
} else {