From 86f254850d4a80bfa0e7ea53766b505c654660bc Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 15 Nov 2017 21:26:52 -0500 Subject: [PATCH] After partitioning we now retry the stat prior to formatting When waiting for devices to refresh a stat can fail with the error message 'stat: /dev/vda1: stat: no such file or directory'. This was observered with empty raw disks (*.img) that was being created by the moby/hyperkit go library. This commit restores the previous logic of refreshing with mdev instead of returning an error. Signed-off-by: dave protasowski --- pkg/format/format.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/format/format.go b/pkg/format/format.go index c967ecb22..713975555 100644 --- a/pkg/format/format.go +++ b/pkg/format/format.go @@ -100,13 +100,15 @@ func refreshDevicesAndWaitFor(awaitedDevice string) error { exec.Command("mdev", "-s").Run() // wait for device - var done bool + var ( + done bool + err error + stat os.FileInfo + ) + for i := 0; i < timeout; i++ { - stat, err := os.Stat(awaitedDevice) - if err != nil { - return err - } - if isBlockDevice(&stat) { + stat, err = os.Stat(awaitedDevice) + if err == nil && isBlockDevice(&stat) { done = true break } @@ -114,7 +116,11 @@ func refreshDevicesAndWaitFor(awaitedDevice string) error { exec.Command("mdev", "-s").Run() } if !done { - return fmt.Errorf("Error waiting for device %s", awaitedDevice) + var statMsg string + if err != nil { + statMsg = fmt.Sprintf(" - stat returned: %v", err) + } + return fmt.Errorf("Failed to find block device %s%s", awaitedDevice, statMsg) } // even after the device appears we still have a race time.Sleep(1 * time.Second)