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 <dprotaso@gmail.com>
This commit is contained in:
dave 2017-11-15 21:26:52 -05:00
parent 10bae91564
commit 86f254850d

View File

@ -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)