summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrtkapiper <andy.piper@arcticwolf.com>2023-07-11 17:56:36 +0000
committerLars Wirzenius <liw@liw.fi>2023-07-14 13:15:26 +0000
commitf0d9ccccaaabba9bf0f53fee4bfbbf1ebb21d4ef (patch)
treee08ba1c87607bc4e115e7a439ea94009cd3b19f5
parentdb10875fe07da19641286f6ce398a8b55958ad80 (diff)
downloadvmdb2-f0d9ccccaaabba9bf0f53fee4bfbbf1ebb21d4ef.tar.gz
kpartx_plugin: create new loop device if required
Fix a kpartx plugin failure when no free loop devices are available: in this scenario, the `kpartx -asv` command can fail. To resolve this, `losetup -f --show <image-file>` is now executed first, which will to create a new loop device if required, before mapping the partitions using `kpartx`.
-rw-r--r--vmdb/plugins/kpartx_plugin.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/vmdb/plugins/kpartx_plugin.py b/vmdb/plugins/kpartx_plugin.py
index 36cf42f..baa4f54 100644
--- a/vmdb/plugins/kpartx_plugin.py
+++ b/vmdb/plugins/kpartx_plugin.py
@@ -39,7 +39,13 @@ class KpartxStepRunner(vmdb.StepRunnerInterface):
state.tags.set_dev(tag, dev)
def kpartx(self, device):
- output = vmdb.runcmd(["kpartx", "-asv", device]).decode("UTF-8")
+ # Allocate the loop device first -- creating one if required -- before
+ # mapping the partitions usign kpartx. This handles scenarios where no
+ # free loop devices are available.
+ loop_device = (
+ vmdb.runcmd(["losetup", "-f", "--show", device]).decode("UTF-8").strip()
+ )
+ output = vmdb.runcmd(["kpartx", "-usv", loop_device]).decode("UTF-8")
for line in output.splitlines():
words = line.split()
if words[0] == "add":