mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 21:46:58 +02:00
build_library/disk_util: work around losetup bug
Retry losetup if it fails, up to 5 times with 5 seconds between retries.
This commit is contained in:
parent
5b8c706c70
commit
00d77d199a
@ -11,6 +11,7 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
# First sector we can use.
|
# First sector we can use.
|
||||||
@ -433,11 +434,22 @@ def FormatFat(part, device):
|
|||||||
def PartitionLoop(options, partition):
|
def PartitionLoop(options, partition):
|
||||||
"""Allocate (and automatically free) loop devices for a partition."""
|
"""Allocate (and automatically free) loop devices for a partition."""
|
||||||
|
|
||||||
|
for i in range(0,5):
|
||||||
|
try:
|
||||||
loop_dev = subprocess.check_output(['sudo', 'losetup',
|
loop_dev = subprocess.check_output(['sudo', 'losetup',
|
||||||
'--offset', str(partition['first_byte']),
|
'--offset', str(partition['first_byte']),
|
||||||
'--sizelimit', str(partition['bytes']),
|
'--sizelimit', str(partition['bytes']),
|
||||||
'--find', '--show', options.disk_image])
|
'--find', '--show', options.disk_image])
|
||||||
loop_dev = loop_dev.strip()
|
loop_dev = loop_dev.strip()
|
||||||
|
err = None
|
||||||
|
break
|
||||||
|
except subprocess.CalledProcessError as error:
|
||||||
|
print("Failed to set up loopback, attempt %d" % i)
|
||||||
|
err = error
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
if err is not None:
|
||||||
|
raise err
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield loop_dev
|
yield loop_dev
|
||||||
|
Loading…
Reference in New Issue
Block a user