From a883412ccc9bbd0cae5241153280bd2aa771dc1d Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 26 Jun 2017 09:14:24 -0700 Subject: [PATCH] Fix loop_wait (#1462150) The previous code used losetup --list -O to return the backing store associated with the loop device. This can fail due to losetup truncating the output filename if sysfs isn't setup. Instead of printing the full path it will truncate it to 64 characters with a * at the end. See util-linux lib/loopdev.c for the code that does this. This commit changes it to use the existing get_loop_name function, which uses losetup -j to lookup the loop device associated with the backing store which avoids the truncation problem. Resolves: rhbz#1462150 --- src/pylorax/imgutils.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pylorax/imgutils.py b/src/pylorax/imgutils.py index 4cf0370c..df530333 100644 --- a/src/pylorax/imgutils.py +++ b/src/pylorax/imgutils.py @@ -24,6 +24,7 @@ import os, tempfile from os.path import join, dirname from subprocess import Popen, PIPE, CalledProcessError import sys +import time import traceback import multiprocessing from time import sleep @@ -136,12 +137,16 @@ def loop_waitfor(loop_dev, outfile): """ for x in xrange(0,5): runcmd(["udevadm", "settle", "--timeout", "300"]) - buf = runcmd_output(["losetup", "--list", "-O", "BACK-FILE", loop_dev]) - lines = buf.splitlines() - if len(lines) < 2: - continue - if lines[1].strip() == outfile: + ## XXX Note that losetup --list output can be truncated to 64 bytes in some + ## situations. Don't use it to lookup backing file, go the other way + ## and lookup the loop for the backing file. See util-linux lib/loopdev.c + ## loopcxt_get_backing_file() + if get_loop_name(outfile) == os.path.basename(loop_dev): return + + # If this really is a race, give it some time to settle down + time.sleep(1) + raise RuntimeError("Unable to setup %s on %s" % (loop_dev, outfile)) def loop_attach(outfile):