Skip to content

Commit

Permalink
DeviceManager: Return no error if the device not found while deleting
Browse files Browse the repository at this point in the history
Discussion on issue intel#413, raised a requirement that PMEM-CSI should handle the
DeleteVolume() call for volumes that the underlined device already deleted
manually by the admin.  So for such a volume we just ignore and return no error
in DeviceManager.DeleteVolume(). This also makes DeleteVolume() idempotent.
  • Loading branch information
avalluri committed Oct 18, 2019
1 parent 09497de commit c699513
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pkg/pmem-device-manager/pmd-lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pmdmanager

import (
"fmt"
"os"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -157,6 +158,11 @@ func (lvm *pmemLvm) DeleteDevice(name string, flush bool) error {
return err
}
if err := ClearDevice(device, flush); err != nil {
if os.IsNotExist(err) {
// Remove device from cache
delete(lvm.devices, name)
return nil
}
return err
}

Expand Down
13 changes: 10 additions & 3 deletions pkg/pmem-device-manager/pmd-ndctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pmdmanager

import (
"fmt"
"os"
"sync"

"github.com/intel/pmem-csi/pkg/ndctl"
Expand Down Expand Up @@ -143,12 +144,18 @@ func (pmem *pmemNdctl) DeleteDevice(name string, flush bool) error {

device, err := pmem.getDevice(name)
if err != nil {
return err
// Assume not found device as already deleted
// and return no error
return nil
}
err = ClearDevice(device, flush)
if err != nil {
if err := ClearDevice(device, flush); err != nil {
// Device might have already deleted
if os.IsNotExist(err) {
return nil
}
return err
}

return pmem.ctx.DestroyNamespaceByName(name)
}

Expand Down

0 comments on commit c699513

Please sign in to comment.