Skip to content

Commit

Permalink
fix(LargeBlockSR): fix sr-destroy
Browse files Browse the repository at this point in the history
Signed-off-by: Damien Thenot <[email protected]>
  • Loading branch information
Nambrok committed Mar 13, 2024
1 parent ef65e25 commit 0ead0df
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions drivers/LargeBlockSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,19 @@ class LargeBlockSR(EXTSR.EXTSR):
def handles(srtype):
return srtype == LargeBlockSR.DRIVER_TYPE

def load(self, sr_uuid):
super(LargeBlockSR, self).load(sr_uuid=sr_uuid)
self.is_deleting = False

def attach(self, sr_uuid):
self.create_emulated_device()
if not self.is_deleting:
self.create_emulated_device()
super(LargeBlockSR, self).attach(sr_uuid)

def detach(self, sr_uuid):
super(LargeBlockSR, self).detach(sr_uuid)
self.destroy_emulated_device()
if not self.is_deleting:
self.destroy_emulated_device()

@deviceCheck
def create(self, sr_uuid, size):
Expand All @@ -67,11 +73,22 @@ def create(self, sr_uuid, size):
try:
self.create_emulated_device()
super(LargeBlockSR, self).create(sr_uuid, size)
except Exception as e:
print(e)
finally:
self.destroy_emulated_device(old_devices)

def delete(self, sr_uuid):
old_devices = self.dconf["device"].split(",")

self.is_deleting = True
try:
self.create_emulated_device()
super(LargeBlockSR, self).delete(sr_uuid=sr_uuid)
except SR.SROSError as e:
util.SMlog(e)
finally:
self.destroy_emulated_device(old_devices)
self.is_deleting = False

def create_loopdev(self, dev, new_path):
cmd = ["losetup", "-f", "-v", "--show", "--sector-size", str(self.LOOP_SECTOR_SIZE), dev]
self.loopdev = util.pread2(cmd).rstrip()
Expand All @@ -90,8 +107,11 @@ def delete_loopdev(self, dev, new_path):
loopdev = self.get_loopdev_from_device(dev)

if loopdev != None:
cmd = ["losetup", "-d", loopdev] # Remove the loop device
util.pread2(cmd)
try:
cmd = ["losetup", "-d", loopdev] # 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))

Expand Down

0 comments on commit 0ead0df

Please sign in to comment.