Skip to content

Commit

Permalink
fix(LargeBlock): Fix destroying device in create
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Nambrok committed Feb 29, 2024
1 parent 7fc163c commit d575990
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
21 changes: 15 additions & 6 deletions drivers/LargeBlockSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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):
Expand All @@ -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")
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions drivers/XE_SR_ERRORCODES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -947,4 +947,16 @@
<description>LINSTOR SR delete error</description>
<value>5007</value>
</code>

<code>
<name>LargeBlockSymlinkExist</name>
<description>Symlink already exist</description>
<value>5008</value>
</code>

<code>
<name>LargeBlockNoLosetup</name>
<description>Couldn't find loop device</description>
<value>5009</value>
</code>
</SM-errorcodes>

0 comments on commit d575990

Please sign in to comment.