Normalize Windows volume GUID fsinfo mountpoints (#1319)

This commit is contained in:
rcourtman 2026-03-27 14:04:58 +00:00
parent fe66af273e
commit b5629fb1df
2 changed files with 45 additions and 2 deletions

View file

@ -1460,8 +1460,8 @@ func (fs *VMFileSystem) UnmarshalJSON(data []byte) error {
fs.Name = raw.Name
fs.Type = raw.Type
fs.Mountpoint = raw.Mountpoint
if fs.Mountpoint == "" {
if normalized, ok := normalizeWindowsDriveMountpoint(raw.Name); ok {
if normalized, ok := normalizeWindowsDriveMountpoint(raw.Name); ok {
if fs.Mountpoint == "" || isWindowsVolumeGUIDMountpoint(fs.Mountpoint) {
fs.Mountpoint = normalized
}
}
@ -1490,6 +1490,11 @@ func normalizeWindowsDriveMountpoint(value string) (string, bool) {
}
}
func isWindowsVolumeGUIDMountpoint(value string) bool {
value = strings.TrimSpace(strings.ToLower(value))
return strings.HasPrefix(value, `\\?\volume{`) && strings.HasSuffix(value, `}\`)
}
func parseUint64Flexible(value interface{}) (uint64, error) {
switch v := value.(type) {
case nil:

View file

@ -131,6 +131,44 @@ func TestClientVMFSInfoParsingWindowsNameMountpointFallback(t *testing.T) {
}
}
func TestClientVMFSInfoParsingWindowsVolumeGUIDMountpointFallback(t *testing.T) {
client := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api2/json/nodes/node1/qemu/100/agent/get-fsinfo":
writeJSON(t, w, map[string]interface{}{
"data": map[string]interface{}{
"result": []map[string]interface{}{
{
"name": "C:\\",
"type": "ntfs",
"mountpoint": "\\\\?\\Volume{1234-5678}\\",
"total-bytes": 500,
"used-bytes": 200,
},
},
},
})
default:
http.NotFound(w, r)
}
})
ctx := context.Background()
filesystems, err := client.GetVMFSInfo(ctx, "node1", 100)
if err != nil {
t.Fatalf("GetVMFSInfo error: %v", err)
}
if len(filesystems) != 1 {
t.Fatalf("expected 1 filesystem, got %d", len(filesystems))
}
if filesystems[0].Mountpoint != "C:\\" {
t.Fatalf("expected windows drive-letter mountpoint fallback, got %q", filesystems[0].Mountpoint)
}
if filesystems[0].Disk != "C:" {
t.Fatalf("expected windows drive disk, got %q", filesystems[0].Disk)
}
}
func TestClientVMFSInfoObjectResult(t *testing.T) {
client := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {