Skip to content

Commit 6d43ff0

Browse files
committed
feat(SR): support QCOW2 format
Signed-off-by: Ronan Abhamon <[email protected]>
1 parent c7159c5 commit 6d43ff0

20 files changed

+66
-40
lines changed

drivers/CephFSSR.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
]
5656

5757
DRIVER_INFO = {
58-
'name': 'CephFS VHD',
59-
'description': 'SR plugin which stores disks as VHD files on a CephFS storage',
58+
'name': 'CephFS VHD and QCOW2',
59+
'description': 'SR plugin which stores disks as VHD and QCOW2 files on a CephFS storage',
6060
'vendor': 'Vates SAS',
6161
'copyright': '(C) 2020 Vates SAS',
6262
'driver_version': '1.0',

drivers/EXTSR.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
CONFIGURATION = [['device', 'local device path (required) (e.g. /dev/sda3)']]
4444

4545
DRIVER_INFO = {
46-
'name': 'Local EXT4 VHD',
47-
'description': 'SR plugin which represents disks as VHD files stored on a local EXT4 filesystem, created inside an LVM volume',
46+
'name': 'Local EXT4 VHD and QCOW2',
47+
'description': 'SR plugin which represents disks as VHD and QCOW2 files stored on a local EXT4 filesystem, created inside an LVM volume',
4848
'vendor': 'Citrix Systems Inc',
4949
'copyright': '(C) 2008 Citrix Systems Inc',
5050
'driver_version': '1.0',

drivers/FileSR.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@
4848

4949
CONFIGURATION = [
5050
['location', 'local directory path (required)'],
51-
['preferred-image-formats', 'list of preferred image formats to use (default: VHD)']
51+
['preferred-image-formats', 'list of preferred image formats to use (default: VHD,QCOW2)']
5252
]
5353

5454
DRIVER_INFO = {
55-
'name': 'Local Path VHD',
56-
'description': 'SR plugin which represents disks as VHD files stored on a local path',
55+
'name': 'Local Path VHD and QCOW2',
56+
'description': 'SR plugin which represents disks as VHD and QCOW2 files stored on a local path',
5757
'vendor': 'Citrix Systems Inc',
5858
'copyright': '(C) 2008 Citrix Systems Inc',
5959
'driver_version': '1.0',
@@ -102,7 +102,7 @@ def __init__(self, srcmd, sr_uuid):
102102
def load(self, sr_uuid) -> None:
103103
self.ops_exclusive = OPS_EXCLUSIVE
104104
self.lock = lock.Lock(lock.LOCK_TYPE_SR, self.uuid)
105-
self.sr_vditype = VdiType.VHD
105+
self.sr_vditype = SR.DEFAULT_TAP
106106
if 'location' not in self.dconf or not self.dconf['location']:
107107
raise xs_errors.XenError('ConfigLocationMissing')
108108
self.remotepath = self.dconf['location']
@@ -439,16 +439,20 @@ def _check_hardlinks(self) -> bool:
439439
class FileVDI(VDI.VDI):
440440
PARAM_RAW = "raw"
441441
PARAM_VHD = "vhd"
442+
PARAM_QCOW2 = "qcow2"
442443
VDI_TYPE = {
443444
PARAM_RAW: VdiType.RAW,
444-
PARAM_VHD: VdiType.VHD
445+
PARAM_VHD: VdiType.VHD,
446+
PARAM_QCOW2: VdiType.QCOW2
445447
}
446448

447449
def _find_path_with_retries(self, vdi_uuid, maxretry=5, period=2.0):
448450
raw_path = os.path.join(self.sr.path, "%s.%s" % \
449451
(vdi_uuid, self.PARAM_RAW))
450452
vhd_path = os.path.join(self.sr.path, "%s.%s" % \
451453
(vdi_uuid, self.PARAM_VHD))
454+
qcow2_path = os.path.join(self.sr.path, "%s.%s" % \
455+
(vdi_uuid, self.PARAM_QCOW2))
452456
cbt_path = os.path.join(self.sr.path, "%s.%s" %
453457
(vdi_uuid, CBTLOG_TAG))
454458
found = False
@@ -459,6 +463,10 @@ def _find_path_with_retries(self, vdi_uuid, maxretry=5, period=2.0):
459463
self.vdi_type = VdiType.VHD
460464
self.path = vhd_path
461465
found = True
466+
elif util.ioretry(lambda: util.pathexists(qcow2_path)):
467+
self.vdi_type = VdiType.QCOW2
468+
self.path = qcow2_path
469+
found = True
462470
elif util.ioretry(lambda: util.pathexists(raw_path)):
463471
self.vdi_type = VdiType.RAW
464472
self.path = raw_path

drivers/GlusterFSSR.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
]
5050

5151
DRIVER_INFO = {
52-
'name': 'GlusterFS VHD',
53-
'description': 'SR plugin which stores disks as VHD files on a GlusterFS storage',
52+
'name': 'GlusterFS VHD and QCOW2',
53+
'description': 'SR plugin which stores disks as VHD and QCOW2 files on a GlusterFS storage',
5454
'vendor': 'Vates SAS',
5555
'copyright': '(C) 2020 Vates SAS',
5656
'driver_version': '1.0',

drivers/LVMSR.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# along with this program; if not, write to the Free Software Foundation, Inc.,
1616
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717
#
18-
# LVMSR: VHD on LVM storage repository
18+
# LVMSR: VHD and QCOW2 on LVM storage repository
1919
#
2020

2121
from sm_typing import Dict, List, override
@@ -68,8 +68,8 @@
6868
CONFIGURATION = [['device', 'local device path (required) (e.g. /dev/sda3)']]
6969

7070
DRIVER_INFO = {
71-
'name': 'Local VHD on LVM',
72-
'description': 'SR plugin which represents disks as VHD disks on ' + \
71+
'name': 'Local VHD and QCOW2 on LVM',
72+
'description': 'SR plugin which represents disks as VHD and QCOW2 disks on ' + \
7373
'Logical Volumes within a locally-attached Volume Group',
7474
'vendor': 'XenSource Inc',
7575
'copyright': '(C) 2008 XenSource Inc',
@@ -81,7 +81,8 @@
8181

8282
CREATE_PARAM_TYPES = {
8383
"raw": VdiType.RAW,
84-
"vhd": VdiType.VHD
84+
"vhd": VdiType.VHD,
85+
"qcow2": VdiType.QCOW2
8586
}
8687

8788
OPS_EXCLUSIVE = [

drivers/LVMoFCoESR.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
DRIVER_INFO = {
4444
'name': 'LVM over FCoE',
45-
'description': 'SR plugin which represents disks as VHDs on Logical \
45+
'description': 'SR plugin which represents disks as VHDs and QCOW2s on Logical \
4646
Volumes within a Volume Group created on a FCoE LUN',
4747
'vendor': 'Citrix Systems Inc',
4848
'copyright': '(C) 2015 Citrix Systems Inc',

drivers/LVMoHBASR.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
DRIVER_INFO = {
5050
'name': 'LVM over FC',
51-
'description': 'SR plugin which represents disks as VHDs on Logical Volumes within a Volume Group created on an HBA LUN, e.g. hardware-based iSCSI or FC support',
51+
'description': 'SR plugin which represents disks as VHDs and QCOW2s on Logical Volumes within a Volume Group created on an HBA LUN, e.g. hardware-based iSCSI or FC support',
5252
'vendor': 'Citrix Systems Inc',
5353
'copyright': '(C) 2008 Citrix Systems Inc',
5454
'driver_version': '1.0',

drivers/LinstorSR.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
# These values represents the types given on the command line.
9292
CREATE_PARAM_TYPES = {
9393
"raw": VdiType.RAW,
94-
"vhd": VdiType.VHD
94+
"vhd": VdiType.VHD,
95+
"qcow2": VdiType.QCOW2
9596
}
9697

9798
# ==============================================================================

drivers/MooseFSSR.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
]
5555

5656
DRIVER_INFO = {
57-
'name': 'MooseFS VHD',
58-
'description': 'SR plugin which stores disks as VHD files on a MooseFS storage',
57+
'name': 'MooseFS VHD and QCOW2',
58+
'description': 'SR plugin which stores disks as VHD and QCOW2 files on a MooseFS storage',
5959
'vendor': 'Tappest sp. z o.o.',
6060
'copyright': '(C) 2021 Tappest sp. z o.o.',
6161
'driver_version': '1.0',

drivers/NFSSR.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
nfs.NFS_VERSION]
4848

4949
DRIVER_INFO = {
50-
'name': 'NFS VHD',
51-
'description': 'SR plugin which stores disks as VHD files on a remote NFS filesystem',
50+
'name': 'NFS VHD and QCOW2',
51+
'description': 'SR plugin which stores disks as VHD and QCOW2 files on a remote NFS filesystem',
5252
'vendor': 'Citrix Systems Inc',
5353
'copyright': '(C) 2008 Citrix Systems Inc',
5454
'driver_version': '1.0',

drivers/SMBSR.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
['password', 'The password to be used during SMB authentication']]
4545

4646
DRIVER_INFO = {
47-
'name': 'SMB VHD',
48-
'description': 'SR plugin which stores disks as VHD files on a remote SMB filesystem',
47+
'name': 'SMB VHD and QCOW2',
48+
'description': 'SR plugin which stores disks as VHD and QCOW2 files on a remote SMB filesystem',
4949
'vendor': 'Citrix Systems Inc',
5050
'copyright': '(C) 2015 Citrix Systems Inc',
5151
'driver_version': '1.0',

drivers/SR.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
from vditype import VdiType
3333

3434
MOUNT_BASE = '/var/run/sr-mount'
35-
DEFAULT_TAP = "vhd"
35+
DEFAULT_TAP = "vhd,qcow2"
3636
MASTER_LVM_CONF = '/etc/lvm/master'
3737

3838
# LUN per VDI key for XenCenter
3939
LUNPERVDI = "LUNperVDI"
4040

41-
DEFAULT_IMAGE_FORMATS = [ImageFormat.VHD]
41+
DEFAULT_IMAGE_FORMATS = [ImageFormat.VHD, ImageFormat.QCOW2]
4242

4343

4444

drivers/XFSSR.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
CONFIGURATION = [['device', 'local device path (required) (e.g. /dev/sda3)']]
4545

4646
DRIVER_INFO = {
47-
'name': 'Local XFS VHD',
48-
'description': 'SR plugin which represents disks as VHD files stored on a local XFS filesystem, created inside an LVM volume',
47+
'name': 'Local XFS VHD and QCOW2',
48+
'description': 'SR plugin which represents disks as VHD and QCOW2 files stored on a local XFS filesystem, created inside an LVM volume',
4949
'vendor': 'Vates SAS',
5050
'copyright': '(C) 2019 Vates SAS',
5151
'driver_version': '1.0',

drivers/ZFSSR.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
]
4949

5050
DRIVER_INFO = {
51-
'name': 'Local ZFS VHD',
51+
'name': 'Local ZFS VHD and QCOW2',
5252
'description':
53-
'SR plugin which represents disks as VHD files stored on a ZFS disk',
53+
'SR plugin which represents disks as VHD and QCOW2 files stored on a ZFS disk',
5454
'vendor': 'Vates SAS',
5555
'copyright': '(C) 2020 Vates SAS',
5656
'driver_version': '1.0',

drivers/blktap2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def get_tapdisk(self):
669669

670670
class Tapdisk(object):
671671

672-
TYPES = ['aio', 'vhd']
672+
TYPES = ['aio', 'vhd', 'qcow2']
673673

674674
def __init__(self, pid, minor, _type, path, state):
675675
self.pid = pid
@@ -1091,6 +1091,7 @@ def _tap_type(vdi_type):
10911091
return {
10921092
'raw': 'aio',
10931093
'vhd': 'vhd',
1094+
'qcow2': 'qcow2',
10941095
'iso': 'aio', # for ISO SR
10951096
'aio': 'aio', # for LVHD
10961097
'file': 'aio',
@@ -1121,7 +1122,8 @@ def __str__(self) -> str:
11211122
'aio': 'tap', # for LVM raw nodes
11221123
'iso': 'tap', # for ISOSR
11231124
'file': 'tap',
1124-
'vhd': 'tap'}
1125+
'vhd': 'tap',
1126+
'qcow2': 'tap'}
11251127

11261128
def tap_wanted(self):
11271129
# 1. Let the target vdi_type decide
@@ -1178,8 +1180,6 @@ def deactivate(self, sr_uuid, vdi_uuid):
11781180

11791181
def get_vdi_type(self):
11801182
_type = self.vdi.vdi_type
1181-
if not _type:
1182-
_type = self.vdi.sr.sr_vditype
11831183
if not _type:
11841184
raise VDI.UnexpectedVDIType(_type, self.vdi)
11851185
return _type

drivers/cowutil.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
class ImageFormat(IntEnum):
3434
RAW = 1
3535
VHD = 2 | IMAGE_FORMAT_COW_FLAG
36+
QCOW2 = 3 | IMAGE_FORMAT_COW_FLAG
3637

3738
IMAGE_FORMAT_TO_STR: Final = {
3839
ImageFormat.RAW: "raw",
39-
ImageFormat.VHD: "vhd"
40+
ImageFormat.VHD: "vhd",
41+
ImageFormat.QCOW2: "qcow2"
4042
}
4143

4244
STR_TO_IMAGE_FORMAT: Final = {v: k for k, v in IMAGE_FORMAT_TO_STR.items()}
@@ -303,6 +305,8 @@ def getImageFormatFromVdiType(vdi_type: str) -> ImageFormat:
303305
return ImageFormat.RAW
304306
if vdi_type == VdiType.VHD:
305307
return ImageFormat.VHD
308+
if vdi_type == VdiType.QCOW2:
309+
return ImageFormat.QCOW2
306310

307311
assert False, f"Unsupported vdi type: {vdi_type}"
308312

@@ -311,6 +315,8 @@ def getVdiTypeFromImageFormat(image_format: ImageFormat) -> str:
311315
return VdiType.RAW
312316
if image_format == ImageFormat.VHD:
313317
return VdiType.VHD
318+
if image_format == ImageFormat.QCOW2:
319+
return VdiType.QCOW2
314320

315321
assert False, f"Unsupported image format: {IMAGE_FORMAT_TO_STR[image_format]}"
316322

drivers/lvmcowutil.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717

1818
"""
19-
Helper functions for LVMSR. This module knows about RAW and VHD VDI's that live in LV's.
19+
Helper functions for LVMSR. This module knows about RAW, VHD and QCOW2 VDI's that live in LV's.
2020
"""
2121

2222
from sm_typing import Dict, Final, List, Optional, Tuple, cast
@@ -43,7 +43,8 @@
4343

4444
LV_PREFIX: Final = {
4545
VdiType.RAW: "LV-",
46-
VdiType.VHD: "VHD-"
46+
VdiType.VHD: "VHD-",
47+
VdiType.QCOW2: "QCOW2-"
4748
}
4849

4950
LV_PREFIX_TO_VDI_TYPE: Final = {v: k for k, v in LV_PREFIX.items()}
@@ -269,7 +270,7 @@ def getVolumeInfo(cls, lvmCache: LVMCache, lvName: Optional[str] = None) -> Dict
269270
@classmethod
270271
def getVDIInfo(cls, lvmCache: LVMCache) -> Dict[str, VDIInfo]:
271272
"""
272-
Load VDI info (both LV and if the VDI is not raw, VHD info).
273+
Load VDI info (both LV and if the VDI is not raw, VHD/QCOW2 info).
273274
"""
274275
vdis: Dict[str, VDIInfo] = {}
275276
lvs = cls.getVolumeInfo(lvmCache)

drivers/srmetadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def findMetadataVDI(self):
338338
# snapshot_of, if snapshot status is true
339339
# snapshot time
340340
# type (system, user or metadata etc)
341-
# vdi_type: raw or vhd
341+
# vdi_type: raw, vhd or qcow2
342342
# read_only
343343
# location
344344
# managed

drivers/vditype.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
class VdiType(object):
2121
RAW = "aio"
2222
VHD = "vhd"
23+
QCOW2 = "qcow2"
2324
ISO = "iso"
2425
FILE = "file"
2526
CBTLOG = "cbtlog"
@@ -32,15 +33,17 @@ def isCowImage(cls, vdi_type) -> bool:
3233
class VdiTypeExtension(object):
3334
RAW = ".raw"
3435
VHD = ".vhd"
36+
QCOW2 = ".qcow2"
3537
ISO = ".iso"
3638
FILE = ".file"
3739
CBTLOG = ".cbtlog"
3840

39-
VDI_COW_TYPES: Final = (VdiType.VHD, )
41+
VDI_COW_TYPES: Final = (VdiType.VHD, VdiType.QCOW2)
4042

4143
VDI_TYPE_TO_EXTENSION: Final = {
4244
VdiType.RAW: VdiTypeExtension.RAW,
4345
VdiType.VHD: VdiTypeExtension.VHD,
46+
VdiType.QCOW2: VdiTypeExtension.QCOW2,
4447
VdiType.ISO: VdiTypeExtension.ISO,
4548
VdiType.FILE: VdiTypeExtension.FILE,
4649
VdiType.CBTLOG: VdiTypeExtension.CBTLOG

tests/test_LVMSR.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,14 @@ def test_clone_success(self, mock_xenapi, mock_lock):
368368
False,
369369
False, # AIO
370370
True, # VHD
371+
False, # QCOW2
371372
False,
372373
True,
373374
True,
374375
False,
375376
False, # AIO
376377
True, # VHD
378+
False, # QCOW2
377379
False,
378380
True,
379381
False,
@@ -422,12 +424,14 @@ def test_snapshot_attached_success(self, mock_xenapi, mock_lock):
422424
False,
423425
False, # AIO
424426
True, # VHD
427+
False, # QCOW2
425428
False,
426429
True,
427430
True,
428431
False,
429432
False, # AIO
430433
True, # VHD
434+
False, # QCOW2
431435
False,
432436
True,
433437
False,
@@ -479,12 +483,14 @@ def test_snapshot_attached_cbt_success(self, mock_xenapi, mock_lock):
479483
False,
480484
False, # AIO
481485
True, # VHD
486+
False, # QCOW2
482487
False,
483488
True,
484489
True,
485490
False,
486491
False, # AIO
487492
True, # VHD
493+
False, # QCOW2
488494
False,
489495
True,
490496
False,

0 commit comments

Comments
 (0)