Skip to content

Commit

Permalink
fix(probe): close open fd after exclusive open (#450)
Browse files Browse the repository at this point in the history
NDM was keeping a file descriptor open after an exclusive open, causing other applications to receive a resource busy error.

Signed-off-by: Akhil Mohan <[email protected]>
  • Loading branch information
akhilerm authored Jul 8, 2020
1 parent c250388 commit 017b755
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelogs/unreleased/450-akhilerm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix bug of having an open file descriptor in NDM causing applications to receive resource busy error.
3 changes: 2 additions & 1 deletion cmd/ndm_daemonset/probe/usedbyprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,14 @@ func getBlockDeviceZFSPartition(bd blockdevice.BlockDevice) (string, bool) {
// isBlockDeviceInUseByKernel tries to open the device exclusively to check if the device is
// being held by some process. eg: If kernel zfs uses the disk, the open will fail
func isBlockDeviceInUseByKernel(path string) (bool, error) {
_, err := os.OpenFile(path, os.O_EXCL, 0444)
f, err := os.OpenFile(path, os.O_EXCL, 0444)

if errors.Is(err, syscall.EBUSY) {
return true, nil
}
if err != nil {
return false, err
}
defer f.Close()
return false, nil
}

0 comments on commit 017b755

Please sign in to comment.