diff --git a/drivers/LargeBlockSR.py b/drivers/LargeBlockSR.py index b079bd2f..dff5f6a7 100644 --- a/drivers/LargeBlockSR.py +++ b/drivers/LargeBlockSR.py @@ -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): @@ -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() @@ -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))