From b0ec2e46d73f568b452392d8cf096d0d52cf3b1e Mon Sep 17 00:00:00 2001 From: sjmiller609 <7516283+sjmiller609@users.noreply.github.com> Date: Tue, 31 Mar 2026 16:01:27 +0000 Subject: [PATCH] Propagate saveClassID error and clear stale classid files saveClassID now returns an error instead of discarding it, so a failed write (e.g. disk full) surfaces immediately rather than silently losing the collision-resolved class ID. When no upload rate limiting is applied (classID empty), any stale classid file from a previous allocation is removed to prevent removeVMClass from targeting a wrong class. --- lib/network/allocate.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/network/allocate.go b/lib/network/allocate.go index 1ff06b0d..421d12c8 100644 --- a/lib/network/allocate.go +++ b/lib/network/allocate.go @@ -66,8 +66,13 @@ func (m *manager) CreateAllocation(ctx context.Context, req AllocateRequest) (*N m.recordTAPOperation(ctx, "create") // Persist assigned tc class ID so removal uses the correct ID after collisions. + // Clear any stale file when no rate limiting was applied. if classID != "" { - m.saveClassID(req.InstanceID, classID) + if err := m.saveClassID(req.InstanceID, classID); err != nil { + return nil, fmt.Errorf("save class ID: %w", err) + } + } else { + m.clearClassID(req.InstanceID) } log.InfoContext(ctx, "allocated network", @@ -128,8 +133,13 @@ func (m *manager) RecreateAllocation(ctx context.Context, instanceID string, dow m.recordTAPOperation(ctx, "create") // Persist assigned tc class ID so removal uses the correct ID after collisions. + // Clear any stale file when no rate limiting was applied. if classID != "" { - m.saveClassID(instanceID, classID) + if err := m.saveClassID(instanceID, classID); err != nil { + return fmt.Errorf("save class ID: %w", err) + } + } else { + m.clearClassID(instanceID) } log.InfoContext(ctx, "recreated network for restore", @@ -309,9 +319,13 @@ func generateMAC() (string, error) { } // saveClassID persists the tc class ID for an instance so it survives restarts. -func (m *manager) saveClassID(instanceID, classID string) { - path := m.paths.InstanceDir(instanceID) - _ = os.WriteFile(path+"/classid", []byte(classID), 0644) +func (m *manager) saveClassID(instanceID, classID string) error { + return os.WriteFile(m.paths.InstanceDir(instanceID)+"/classid", []byte(classID), 0644) +} + +// clearClassID removes any persisted tc class ID for an instance. +func (m *manager) clearClassID(instanceID string) { + _ = os.Remove(m.paths.InstanceDir(instanceID) + "/classid") } // loadClassID loads the persisted tc class ID for an instance.