Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csi: nil-check allocs for claim methods #7760

Merged
merged 2 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2144,22 +2144,26 @@ func (s *StateStore) CSIVolumeDenormalizePlugins(ws memdb.WatchSet, vol *structs
return vol, nil
}

// csiVolumeDenormalizeAllocs returns a CSIVolume with allocations
// CSIVolumeDenormalize returns a CSIVolume with allocations
func (s *StateStore) CSIVolumeDenormalize(ws memdb.WatchSet, vol *structs.CSIVolume) (*structs.CSIVolume, error) {
for id := range vol.ReadAllocs {
a, err := s.AllocByID(ws, id)
if err != nil {
return nil, err
}
vol.ReadAllocs[id] = a
if a != nil {
vol.ReadAllocs[id] = a
}
}

for id := range vol.WriteAllocs {
a, err := s.AllocByID(ws, id)
if err != nil {
return nil, err
}
vol.WriteAllocs[id] = a
if a != nil {
vol.WriteAllocs[id] = a
}
}

return vol, nil
Expand Down
9 changes: 9 additions & 0 deletions nomad/structs/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ func (v *CSIVolume) Claim(claim CSIVolumeClaimMode, alloc *Allocation) error {

// ClaimRead marks an allocation as using a volume read-only
func (v *CSIVolume) ClaimRead(alloc *Allocation) error {
if alloc == nil {
return fmt.Errorf("allocation missing")
}
if _, ok := v.ReadAllocs[alloc.ID]; ok {
return nil
}
Expand All @@ -385,6 +388,9 @@ func (v *CSIVolume) ClaimRead(alloc *Allocation) error {

// ClaimWrite marks an allocation as using a volume as a writer
func (v *CSIVolume) ClaimWrite(alloc *Allocation) error {
if alloc == nil {
return fmt.Errorf("allocation missing")
}
if _, ok := v.WriteAllocs[alloc.ID]; ok {
return nil
}
Expand All @@ -411,6 +417,9 @@ func (v *CSIVolume) ClaimWrite(alloc *Allocation) error {

// ClaimRelease is called when the allocation has terminated and already stopped using the volume
func (v *CSIVolume) ClaimRelease(alloc *Allocation) error {
if alloc == nil {
return fmt.Errorf("allocation missing")
}
delete(v.ReadAllocs, alloc.ID)
delete(v.WriteAllocs, alloc.ID)
return nil
Expand Down