Skip to content

Commit

Permalink
VM: Handle not found file descriptor (#14479)
Browse files Browse the repository at this point in the history
This simply adds a check for whether a file descriptor with the provided
name exists and return an error if it doesn't.
The motivation for this was the fact that we found out we were using
mismatched names for block devices file descriptors on create/removal,
which caused removal to not take effect (refer to
#14461 (comment)).
This will be fixed by #14461 and
then this PR can be merged to detect future instances of this same
problem.
  • Loading branch information
tomponline authored Nov 22, 2024
2 parents 729c819 + cbffaf1 commit e49b748
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lxd/instance/drivers/qmp/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ func (m *Monitor) RemoveFDFromFDSet(name string) error {
return fmt.Errorf("Failed to query fd sets: %w", err)
}

found := false

for _, fdSet := range resp.Return {
for _, fd := range fdSet.FDs {
fields := strings.SplitN(fd.Opaque, ":", 2)
Expand All @@ -237,6 +239,8 @@ func (m *Monitor) RemoveFDFromFDSet(name string) error {
}

if opaque == name {
found = true

args := map[string]any{
"fdset-id": fdSet.ID,
}
Expand All @@ -249,6 +253,11 @@ func (m *Monitor) RemoveFDFromFDSet(name string) error {
}
}

// Return an error if no fd matched the provided name.
if !found {
return api.StatusErrorf(http.StatusNotFound, "No fd with name %q", name)
}

return nil
}

Expand Down

0 comments on commit e49b748

Please sign in to comment.