Skip to content

Commit

Permalink
wait for the device to be created
Browse files Browse the repository at this point in the history
Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 committed Feb 18, 2021
1 parent 9310c31 commit bc4563d
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions pkg/zfs/zfs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"path/filepath"

"fmt"
"os"
"time"

"strings"

Expand Down Expand Up @@ -824,6 +826,24 @@ func DestoryBackup(bkp *apis.ZFSBackup) error {
return err
}

// getDevice wait for the device to be created andd returns the devpath
func getDevice(volume string) (string, error) {
device := ZFSDevPath + volume
// device should be created within 5 seconds
timeout := time.After(5 * time.Second)
for {
select {
case <-timeout:
return "", fmt.Errorf("zfs: not able to get the device: %s", device)
default:
if _, err := os.Stat(device); err == nil {
return device, nil
}
}
time.Sleep(1 * time.Second)
}
}

// CreateRestore creates the restore
func CreateRestore(rstr *apis.ZFSRestore) error {
if len(rstr.VolSpec.PoolName) == 0 {
Expand Down Expand Up @@ -858,11 +878,17 @@ func CreateRestore(rstr *apis.ZFSRestore) error {
* so that we can mount it.
*/
if rstr.VolSpec.FsType == "xfs" {
device := ZFSDevPath + volume
device, err := getDevice(volume)
if err != nil {
return err
}
return xfs.GenerateUUID(device)
}
if rstr.VolSpec.FsType == "btrfs" {
device := ZFSDevPath + volume
device, err := getDevice(volume)
if err != nil {
return err
}
return btrfs.GenerateUUID(device)
}

Expand Down

0 comments on commit bc4563d

Please sign in to comment.