Skip to content

Commit

Permalink
fix(LargeBlock): Renamed variables and functions
Browse files Browse the repository at this point in the history
Changed driver description

Signed-off-by: Damien Thenot <[email protected]>
  • Loading branch information
Nambrok committed Feb 23, 2024
1 parent 1bed854 commit ea0160d
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions drivers/LargeBlockSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,42 @@

DRIVER_INFO = {
'name': 'Large Block SR',
'description': 'SR plugin which represents disks as VHD files stored on a local EXT4 filesystem, created inside an LVM volume',
'description': 'SR plugin which emulates a 512 bytes disk on top of a 4KiB device then create a EXT SR',
'vendor': 'Vates',
'copyright': '(C) 2024 Vates',
'driver_version': '1.0',
'required_api_version': '1.0',
'capabilities': CAPABILITIES,
'configuration': CONFIGURATION
}

DRIVER_CONFIG = {"ATTACH_FROM_CONFIG_WITH_TAPDISK": True}

}

class LargeBlockSR(EXTSR.EXTSR):
"""Emulating 512b drives for EXT storage repository"""

DRIVER_TYPE = "largeblock"
SECTOR_SIZE = 512
LOOP_SECTOR_SIZE = 512

@staticmethod
def handles(srtype):
return srtype == LargeBlockSR.DRIVER_TYPE

def attach(self, sr_uuid):
self.override_device()
self.create_emulated_device()
super(LargeBlockSR, self).attach(sr_uuid)

def detach(self, sr_uuid):
super(LargeBlockSR, self).detach(sr_uuid)
self.remove_device()
self.destroy_emulated_device()

@deviceCheck
def create(self, sr_uuid, size):
#TODO: Need to check blocksize of the device before accepting to create a SR.
self.override_device()
self.create_emulated_device()
super(LargeBlockSR, self).create(sr_uuid, size)
self.remove_device()
self.destroy_emulated_device()

def create_loopdev(self, dev, new_path):
cmd = ["losetup", "-f", "-v", "--show", "--sector-size", str(self.SECTOR_SIZE), dev]
cmd = ["losetup", "-f", "-v", "--show", "--sector-size", str(self.LOOP_SECTOR_SIZE), dev]
self.loopdev = util.pread2(cmd).rstrip()
new_path = pathlib.Path(new_path)

Expand Down Expand Up @@ -104,24 +101,24 @@ def get_loopdev_from_device(self, device):
return loopdev
return None

def get_new_path(self, dev):
return "{dev}.{bs}".format(dev=dev, bs=self.SECTOR_SIZE)
def get_emulated_device_path(self, dev):
return "{dev}.{bs}".format(dev=dev, bs=self.LOOP_SECTOR_SIZE)

def override_device(self):
def create_emulated_device(self):
devices = self.dconf["device"].split(",")
emulated_devices = []
for dev in devices:
new_path = self.get_new_path(dev)
new_path = self.get_emulated_device_path(dev)
self.create_loopdev(dev, new_path)
emulated_devices.append(new_path)

emulated_devices = ",".join(emulated_devices)
self.dconf["device"] = emulated_devices

def remove_device(self):
def destroy_emulated_device(self):
devices = self.dconf["device"].split(",")
for dev in devices:
new_path = self.get_new_path(dev)
new_path = self.get_emulated_device_path(dev)
self.delete_loopdev(dev, new_path)

if __name__ == '__main__':
Expand Down

0 comments on commit ea0160d

Please sign in to comment.