From d5759903823a58a1e49a5658bd21024c72e211ae Mon Sep 17 00:00:00 2001 From: Damien Thenot Date: Thu, 29 Feb 2024 14:46:34 +0100 Subject: [PATCH] fix(LargeBlock): Fix destroying device in create Creating a device would create the emulation then remove it using the self.dconf["device"] as input. But the create had replaced this by the emulated device. The removing would not find the correct device. Added a way to provide the device list for removing the emulation. Added errors types Signed-off-by: Damien Thenot --- drivers/LargeBlockSR.py | 21 +++++++++++++++------ drivers/XE_SR_ERRORCODES.xml | 12 ++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/drivers/LargeBlockSR.py b/drivers/LargeBlockSR.py index f1635ac5c..aeba0acd0 100644 --- a/drivers/LargeBlockSR.py +++ b/drivers/LargeBlockSR.py @@ -63,9 +63,14 @@ def detach(self, sr_uuid): @deviceCheck def create(self, sr_uuid, size): #TODO: Need to check blocksize of the device before accepting to create a SR. - self.create_emulated_device() - super(LargeBlockSR, self).create(sr_uuid, size) - self.destroy_emulated_device() + old_devices = self.dconf["device"].split(",") + 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 create_loopdev(self, dev, new_path): cmd = ["losetup", "-f", "-v", "--show", "--sector-size", str(self.LOOP_SECTOR_SIZE), dev] @@ -74,7 +79,7 @@ def create_loopdev(self, dev, new_path): try: os.symlink(self.loopdev, new_path) except FileExistsError as e: - raise xs_errors.XenError("SymlinkExist", opterr="Symlink {} couldn't be created".format(new_path)) + raise xs_errors.XenError("LargeBlockSymlinkExist", opterr="Symlink {} couldn't be created".format(new_path)) def delete_loopdev(self, dev, new_path): if os.path.exists(new_path) and os.path.islink(new_path): @@ -87,6 +92,8 @@ def delete_loopdev(self, dev, new_path): if loopdev != None: cmd = ["losetup", "-d", loopdev] # Remove the loop device util.pread2(cmd) + else: + xs_errors.XenError("LargeBlockNoLosetup", opterr="Couldn't find loop device for {}".format(dev)) def get_loopdev_from_device(self, device): output = util.pread2(["losetup", "--list"]).rstrip().split("\n") @@ -112,8 +119,10 @@ def create_emulated_device(self): emulated_devices = ",".join(emulated_devices) self.dconf["device"] = emulated_devices - def destroy_emulated_device(self): - devices = self.dconf["device"].split(",") + def destroy_emulated_device(self, devices=None): + if devices is None: + devices = self.dconf["device"].split(",") + for dev in devices: new_path = self.get_emulated_device_path(dev) self.delete_loopdev(dev, new_path) diff --git a/drivers/XE_SR_ERRORCODES.xml b/drivers/XE_SR_ERRORCODES.xml index 0dac0613a..235e3cc60 100755 --- a/drivers/XE_SR_ERRORCODES.xml +++ b/drivers/XE_SR_ERRORCODES.xml @@ -947,4 +947,16 @@ LINSTOR SR delete error 5007 + + + LargeBlockSymlinkExist + Symlink already exist + 5008 + + + + LargeBlockNoLosetup + Couldn't find loop device + 5009 +