Skip to content

Commit

Permalink
Fix issues when csi met device busy
Browse files Browse the repository at this point in the history
Signed-off-by: Libin Zhang <[email protected]>
  • Loading branch information
Libin Zhang authored and Libin Zhang committed Nov 17, 2023
1 parent 08b8de3 commit b679c2b
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions pkg/node/provisioners/utilwrappers/partition_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"os/exec"
"strings"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
Expand All @@ -31,13 +30,6 @@ import (
"github.com/dell/csi-baremetal/pkg/metrics"
)

const (
// NumberOfRetriesToObtainPartName how many retries to obtain partition name
NumberOfRetriesToObtainPartName = 5
// SleepBetweenRetriesToObtainPartName default timeout between retries to obtain partition name
SleepBetweenRetriesToObtainPartName = 3 * time.Second
)

// PartitionOperations is a high-level interface
// that encapsulates all low-level operations with partitions on node
type PartitionOperations interface {
Expand Down Expand Up @@ -173,31 +165,23 @@ func (d *PartitionOperationsImpl) SearchPartName(device, partUUID string) (strin
var (
partName string
err error
errStr string
)

// get partition name
for i := 0; i < NumberOfRetriesToObtainPartName; i++ {
// sync partition table
_, errStr, err := d.SyncPartitionTable(device)
if err != nil {
if _, ok := err.(*exec.ExitError); ok &&
strings.Contains(errStr, "Device or resource busy") {
ll.Warningf("Unable to sync partition table for device %s: %v due to device is busy", device, err)
} else {
// log and ignore error
ll.Errorf("Unable to sync partition table for device %s: %v", device, err)
return "", err
}
}
// sleep first to avoid issues with lsblk caching
time.Sleep(SleepBetweenRetriesToObtainPartName)
partName, err = d.GetPartitionNameByUUID(device, partUUID)
if err != nil {
ll.Warningf("Unable to find part name: %v. Sleep and retry...", err)
continue
// sync partition table
_, errStr, err = d.SyncPartitionTable(device)
if err != nil {
if _, ok := err.(*exec.ExitError); ok &&
strings.Contains(errStr, "Device or resource busy") {
ll.Warningf("Unable to sync partition table for device %s: %v due to device is busy", device, err)
} else {
// log and ignore error
ll.Errorf("Unable to sync partition table for device %s: %v", device, err)
return "", err
}
break
}
partName, err = d.GetPartitionNameByUUID(device, partUUID)

// partition not found
if partName == "" {
Expand Down

0 comments on commit b679c2b

Please sign in to comment.