Skip to content

Commit 42779c1

Browse files
committed
Always store image-format in sm-config
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.tech>
1 parent b70fcd5 commit 42779c1

5 files changed

Lines changed: 21 additions & 4 deletions

File tree

drivers/FileSR.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
import time
3434
import glob
3535
from uuid import uuid4
36-
from cowutil import CowImageInfo, CowUtil, ImageFormat, getCowUtil, getVdiTypeFromImageFormat
36+
from cowutil import \
37+
CowImageInfo, CowUtil, ImageFormat, getCowUtil, getImageStringFromVdiType, getVdiTypeFromImageFormat
3738
from vditype import VdiType, VdiTypeExtension, VDI_COW_TYPES, VDI_TYPE_TO_EXTENSION
3839
import xmlrpc.client
3940
import XenAPI # pylint: disable=import-error
@@ -622,7 +623,11 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
622623
st = util.ioretry(lambda: os.stat(self.path))
623624
self.utilisation = int(st.st_size)
624625
if self.vdi_type == VdiType.RAW:
626+
# Legacy code.
625627
self.sm_config = {"type": self.PARAM_RAW}
628+
if not hasattr(self, 'sm_config'):
629+
self.sm_config = {}
630+
self.sm_config = {"image-format": getImageStringFromVdiType(self.vdi_type)}
626631

627632
self._db_introduce()
628633
self.sr._update(self.sr.uuid, self.size)

drivers/LVMSR.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from refcounter import RefCounter
4141
from ipc import IPCFlag
4242
from constants import NS_PREFIX_LVM, VG_LOCATION, VG_PREFIX
43-
from cowutil import CowUtil, getCowUtil, getVdiTypeFromImageFormat
43+
from cowutil import CowUtil, getCowUtil, getImageStringFromVdiType, getVdiTypeFromImageFormat
4444
from lvmcowutil import LV_PREFIX, LvmCowUtil
4545
from lvmanager import LVActivator
4646
from vditype import VdiType
@@ -1432,6 +1432,7 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
14321432

14331433
self.utilisation = lvSize
14341434
self.sm_config["vdi_type"] = self.vdi_type
1435+
self.sm_config["image-format"] = getImageStringFromVdiType(self.vdi_type)
14351436

14361437
if not self.sr.legacyMode:
14371438
LVMMetadataHandler(self.sr.mdpath).ensureSpaceIsAvailableForVdis(1)

drivers/LinstorSR.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import xmlrpc.client
5757
import xs_errors
5858

59-
from cowutil import CowUtil, getVdiTypeFromImageFormat
59+
from cowutil import CowUtil, getImageStringFromVdiType, getVdiTypeFromImageFormat
6060
from srmetadata import \
6161
NAME_LABEL_TAG, NAME_DESCRIPTION_TAG, IS_A_SNAPSHOT_TAG, SNAPSHOT_OF_TAG, \
6262
TYPE_TAG, VDI_TYPE_TAG, READ_ONLY_TAG, SNAPSHOT_TIME_TAG, \
@@ -1726,6 +1726,7 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
17261726

17271727
self.utilisation = volume_info.allocated_size
17281728
self.sm_config['vdi_type'] = self.vdi_type
1729+
self.sm_config['image-format'] = getImageStringFromVdiType(self.vdi_type)
17291730

17301731
self.ref = self._db_introduce()
17311732
self.sr._update_stats(self.size)

drivers/SR.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
import os
2929
import traceback
3030

31-
from cowutil import ImageFormat, getCowUtilFromImageFormat, getVdiTypeFromImageFormat, parseImageFormats
31+
from cowutil import \
32+
ImageFormat, getCowUtilFromImageFormat, getImageStringFromVdiType, getVdiTypeFromImageFormat, parseImageFormats
3233
from vditype import VdiType
3334

3435
MOUNT_BASE = '/var/run/sr-mount'
@@ -555,6 +556,12 @@ def __init__(self, sr):
555556
util.SMlog("missing config for vdi: %s" % vdi.location)
556557
vdi.sm_config = {}
557558

559+
if "image-format" not in vdi.sm_config:
560+
try:
561+
vdi.sm_config["image-format"] = getImageStringFromVdiType(vdi.vdi_type)
562+
except:
563+
pass # No image format for this VDI type.
564+
558565
vdi._override_sm_config(vdi.sm_config)
559566

560567
self.__sm_records[vdi.location] = vdi

drivers/cowutil.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ def getImageFormatFromVdiType(vdi_type: str) -> ImageFormat:
306306

307307
assert False, f"Unsupported vdi type: {vdi_type}"
308308

309+
def getImageStringFromVdiType(vdi_type: str) -> str:
310+
return IMAGE_FORMAT_TO_STR[getImageFormatFromVdiType(vdi_type)]
311+
309312
def getVdiTypeFromImageFormat(image_format: ImageFormat) -> str:
310313
if image_format == ImageFormat.RAW:
311314
return VdiType.RAW

0 commit comments

Comments
 (0)