Skip to content

Commit

Permalink
fix(LargeBlock): remove all loop devices
Browse files Browse the repository at this point in the history
Changed get_loopdev_from_device to list all loop device linked to a
device
It allows to remove all loop if multiple were created.

Signed-off-by: Damien Thenot <[email protected]>
  • Loading branch information
Nambrok committed Mar 15, 2024
1 parent 3c86892 commit ea0ae24
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drivers/LargeBlockSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,25 @@ def delete_loopdev(self, dev, new_path):

if loopdev != None:
try:
cmd = ["losetup", "-d", loopdev] # Remove the loop device
util.pread2(cmd)
for lp in loopdev:
cmd = ["losetup", "-d", lp] # Remove the loop device
util.pread2(cmd)
except SR.SROSError:
util.SMlog("Couldn't removed losetup device {}".format(loopdev))
else:
xs_errors.XenError("LargeBlockNoLosetup", opterr="Couldn't find loop device for {}".format(dev))

def get_loopdev_from_device(self, device):
lpdevs = []
output = util.pread2(["losetup", "--list"]).rstrip()
if output:
for line in output.split("\n"):
line = line.split()
loopdev = line[0]
dev = line[5]
if device in dev:
return loopdev
return None
lpdevs.append(loopdev)
return lpdevs

def is_vg_connection_correct(self):
output = util.pread2(["vgs", "--noheadings", "-o", "vg_name,devices", self.vgname]).split()
Expand Down

0 comments on commit ea0ae24

Please sign in to comment.