Skip to content

Commit 74bffc1

Browse files
committed
LVM COW in progress
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.fr>
1 parent 5157e13 commit 74bffc1

25 files changed

+635
-580
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ SM_LIBS += vhdutil
3939
SM_LIBS += linstorjournaler
4040
SM_LIBS += linstorvhdutil
4141
SM_LIBS += linstorvolumemanager
42-
SM_LIBS += lvhdutil # TODO: Split
42+
SM_LIBS += lvmcowutil
4343
SM_LIBS += cifutils
4444
SM_LIBS += xs_errors
4545
SM_LIBS += nfs

drivers/02-vhdcleanup

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
. /etc/init.d/functions
2222

2323
CLEANUP_SCRIPT="/opt/xensource/sm/cleanup.py"
24-
LVHD_UTIL_SCRIPT="/opt/xensource/sm/lvhdutil.py"
24+
LVM_COW_UTIL_SCRIPT="/opt/xensource/sm/lvmcowutil.py"
2525

2626
start() {
2727
echo -n $"Fixing refcounts on new master: "
@@ -31,7 +31,7 @@ start() {
3131
srUuids=`xe sr-list type=$type params=uuid --minimal | sed "s/,/ /g"`
3232
for uuid in $srUuids; do
3333
echo -n "Fixing $type"
34-
python $LVHD_UTIL_SCRIPT fixrefcounts $uuid
34+
python $LVM_COW_UTIL_SCRIPT fixrefcounts $uuid
3535
done
3636
done
3737
echo -n $"OK"

drivers/LVMSR.py

Lines changed: 86 additions & 80 deletions
Large diffs are not rendered by default.

drivers/LinstorSR.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@ def _create_snapshot(self, snap_uuid, snap_of_uuid=None):
22932293
# 2. Write the snapshot content.
22942294
is_raw = (self.vdi_type == VdiType.RAW)
22952295
self._cowutil.snapshot(
2296-
snap_path, self.path, is_raw, self.MAX_METADATA_VIRT_SIZE
2296+
snap_path, self.path, is_raw, cowutil.getPreallocationSizeVirt()
22972297
)
22982298

22992299
# 3. Get snapshot parent.

drivers/VDI.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import xmlrpc.client
2323
import xs_errors
2424
import util
25-
import vhdutil
2625
import cbtutil
2726
import os
2827
import base64

drivers/blktap2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@
4343
import scsiutil
4444
from syslog import openlog, syslog
4545
from stat import * # S_ISBLK(), ...
46+
from lvmcowutil import NS_PREFIX_LVM
4647
from vditype import VdiType
4748
import nfs
4849

4950
import resetvdis
50-
import lvhdutil
5151

5252
import VDI as sm
5353

@@ -1117,7 +1117,7 @@ def __str__(self) -> str:
11171117

11181118
VDI_PLUG_TYPE = {'phy': 'phy', # for NETAPP
11191119
'raw': 'phy',
1120-
'aio': 'tap', # for LVHD raw nodes
1120+
'aio': 'tap', # for LVM raw nodes
11211121
'iso': 'tap', # for ISOSR
11221122
'file': 'tap',
11231123
'vhd': 'tap',
@@ -1672,7 +1672,7 @@ def _activate_locked(self, sr_uuid, vdi_uuid, options):
16721672
if hasattr(self.target.vdi.sr, 'DRIVER_TYPE') and \
16731673
self.target.vdi.sr.DRIVER_TYPE == 'lvhd' and \
16741674
VdiType.isCowImage(vdi_type):
1675-
lock = Lock("lvchange-p", lvhdutil.NS_PREFIX_LVM + sr_uuid)
1675+
lock = Lock("lvchange-p", NS_PREFIX_LVM + sr_uuid)
16761676
lock.acquire()
16771677

16781678
# When we attach a static VDI for HA, we cannot communicate with
@@ -1975,7 +1975,7 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
19751975
os.unlink(local_leaf_path)
19761976
try:
19771977
self._cowutil.snapshot(local_leaf_path, read_cache_path, False,
1978-
msize=leaf_size // 1024 // 1024, checkEmpty=False)
1978+
msize=leaf_size, checkEmpty=False)
19791979
except util.CommandException as e:
19801980
util.SMlog("Error creating leaf cache: %s" % e)
19811981
self.alert_no_cache(session, vdi_uuid, local_sr_uuid, e.code)

drivers/cbtutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# along with this program; if not, write to the Free Software Foundation, Inc.,
1515
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1616
#
17-
# Helper functions pertaining to VHD operations
17+
# Helper functions pertaining to COW image operations
1818
#
1919

2020
import util

drivers/cleanup.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import XenAPI # pylint: disable=import-error
3838
import util
3939
import lvutil
40-
import lvhdutil
40+
import lvmcowutil
4141
import lvmcache
4242
import journaler
4343
import fjournaler
@@ -52,6 +52,7 @@
5252
from time import monotonic as _time
5353

5454
from cowutil import CowUtil, getCowUtil
55+
from lvmcowutil import LV_PREFIX, NS_PREFIX_LVM, VG_LOCATION, VG_PREFIX
5556
from vditype import VdiType, VdiTypeExtension, VDI_COW_TYPES, VDI_TYPE_TO_EXTENSION
5657

5758
try:
@@ -767,7 +768,7 @@ def rename(self, uuid) -> None:
767768

768769
def delete(self) -> None:
769770
"Physically delete the VDI"
770-
lock.Lock.cleanup(self.uuid, lvhdutil.NS_PREFIX_LVM + self.sr.uuid)
771+
lock.Lock.cleanup(self.uuid, NS_PREFIX_LVM + self.sr.uuid)
771772
lock.Lock.cleanupAll(self.uuid)
772773
self._clear()
773774

@@ -1023,7 +1024,7 @@ def _tagChildrenForRelink(self):
10231024
child._tagChildrenForRelink()
10241025

10251026
def _loadInfoParent(self):
1026-
ret = self.cowutil.getParent(self.path, lvhdutil.extractUuid)
1027+
ret = self.cowutil.getParent(self.path, LvmCowUtil.extractUuid)
10271028
if ret:
10281029
self.parentUuid = ret
10291030

@@ -1225,7 +1226,7 @@ def load(self, info=None) -> None:
12251226

12261227
@staticmethod
12271228
def extractUuid(path):
1228-
return lvhdutil.extractUuid(path)
1229+
return LvmCowUtil.extractUuid(path)
12291230

12301231
def inflate(self, size):
12311232
"""inflate the LV containing the VHD to 'size'"""
@@ -1234,7 +1235,7 @@ def inflate(self, size):
12341235
self._activate()
12351236
self.sr.lock()
12361237
try:
1237-
lvhdutil.inflate(self.sr.journaler, self.sr.uuid, self.uuid, size)
1238+
self.lvmcowutil.inflate(self.sr.journaler, self.sr.uuid, self.uuid, self.vdi_type, size)
12381239
util.fistpoint.activate("LVHDRT_inflating_the_parent", self.sr.uuid)
12391240
finally:
12401241
self.sr.unlock()
@@ -1243,21 +1244,21 @@ def inflate(self, size):
12431244
self._sizeAllocated = -1
12441245

12451246
def deflate(self):
1246-
"""deflate the LV containing the VHD to minimum"""
1247+
"""deflate the LV containing the image to minimum"""
12471248
if not VdiType.isCowImage(self.vdi_type):
12481249
return
12491250
self._activate()
12501251
self.sr.lock()
12511252
try:
1252-
lvhdutil.deflate(self.sr.lvmCache, self.fileName, self.getSizePhys())
1253+
self.lvmcowutil.deflate(self.sr.lvmCache, self.fileName, self.getSizePhys())
12531254
finally:
12541255
self.sr.unlock()
12551256
self.sizeLV = self.sr.lvmCache.getSize(self.fileName)
12561257
self._sizePhys = -1
12571258
self._sizeAllocated = -1
12581259

12591260
def inflateFully(self):
1260-
self.inflate(lvhdutil.calcSizeVHDLV(self.sizeVirt))
1261+
self.inflate(self.lvmcowutil.calcVolumeSize(self.sizeVirt))
12611262

12621263
def inflateParentForCoalesce(self):
12631264
"""Inflate the parent only as much as needed for the purposes of
@@ -1280,15 +1281,15 @@ def rename(self, uuid) -> None:
12801281
oldUuid = self.uuid
12811282
oldLVName = self.fileName
12821283
VDI.rename(self, uuid)
1283-
self.fileName = lvhdutil.LV_PREFIX[self.vdi_type] + self.uuid
1284+
self.fileName = LV_PREFIX[self.vdi_type] + self.uuid
12841285
self.path = os.path.join(self.sr.path, self.fileName)
12851286
assert(not self.sr.lvmCache.checkLV(self.fileName))
12861287

12871288
self.sr.lvmCache.rename(oldLVName, self.fileName)
12881289
if self.sr.lvActivator.get(oldUuid, False):
12891290
self.sr.lvActivator.replace(oldUuid, self.uuid, self.fileName, False)
12901291

1291-
ns = lvhdutil.NS_PREFIX_LVM + self.sr.uuid
1292+
ns = NS_PREFIX_LVM + self.sr.uuid
12921293
(cnt, bcnt) = RefCounter.check(oldUuid, ns)
12931294
RefCounter.set(self.uuid, cnt, bcnt, ns)
12941295
RefCounter.reset(oldUuid, ns)
@@ -1304,7 +1305,7 @@ def delete(self) -> None:
13041305
self.sr.forgetVDI(self.uuid)
13051306
finally:
13061307
self.sr.unlock()
1307-
RefCounter.reset(self.uuid, lvhdutil.NS_PREFIX_LVM + self.sr.uuid)
1308+
RefCounter.reset(self.uuid, NS_PREFIX_LVM + self.sr.uuid)
13081309
VDI.delete(self)
13091310

13101311
@override
@@ -1476,12 +1477,11 @@ def _setSizeVirt(self, size) -> None:
14761477
subtree are guaranteed to be unplugged (and remain so for the duration
14771478
of the operation): this operation is only safe for offline VHDs"""
14781479
self._activate()
1479-
jFile = lvhdutil.createVHDJournalLV(self.sr.lvmCache, self.uuid, self.cowutil.getResizeJournalSize())
1480+
jFile = self.lvmcowutil.createResizeJournal(self.sr.lvmCache, self.uuid)
14801481
try:
1481-
lvhdutil.setSizeVirt(self.sr.journaler, self.sr.uuid, self.uuid,
1482-
size, jFile)
1482+
self.lvmcowutil.setSizeVirt(self.sr.journaler, self.sr.uuid, self.uuid, self.vdi_type, size, jFile)
14831483
finally:
1484-
lvhdutil.deleteVHDJournalLV(self.sr.lvmCache, self.uuid)
1484+
self.lvmcowutil.destroyResizeJournal(self.sr.lvmCache, self.uuid)
14851485

14861486
@override
14871487
def _queryVHDBlocks(self) -> bytes:
@@ -1492,7 +1492,7 @@ def _queryVHDBlocks(self) -> bytes:
14921492
def _calcExtraSpaceForCoalescing(self) -> int:
14931493
if not VdiType.isCowImage(self.parent.vdi_type):
14941494
return 0 # raw parents are never deflated in the first place
1495-
sizeCoalesced = lvhdutil.calcSizeVHDLV(self._getCoalescedSizeData())
1495+
sizeCoalesced = self.lvmcowutil.calcVolumeSize(self._getCoalescedSizeData())
14961496
Util.log("Coalesced size = %s" % Util.num2str(sizeCoalesced))
14971497
return sizeCoalesced - self.parent.sizeLV
14981498

@@ -1501,13 +1501,13 @@ def _calcExtraSpaceForLeafCoalescing(self) -> int:
15011501
"""How much extra space in the SR will be required to
15021502
[live-]leaf-coalesce this VDI"""
15031503
# we can deflate the leaf to minimize the space requirements
1504-
deflateDiff = self.sizeLV - lvhdutil.calcSizeLV(self.getSizePhys())
1504+
deflateDiff = self.sizeLV - lvutil.calcSizeLV(self.getSizePhys())
15051505
return self._calcExtraSpaceForCoalescing() - deflateDiff
15061506

15071507
@override
15081508
def _calcExtraSpaceForSnapshotCoalescing(self) -> int:
15091509
return self._calcExtraSpaceForCoalescing() + \
1510-
lvhdutil.calcSizeLV(self.getSizePhys())
1510+
lvutil.calcSizeLV(self.getSizePhys())
15111511

15121512

15131513
class LinstorVDI(VDI):
@@ -2880,8 +2880,8 @@ class LVMSR(SR):
28802880

28812881
def __init__(self, uuid, xapi, createLock, force):
28822882
SR.__init__(self, uuid, xapi, createLock, force)
2883-
self.vgName = "%s%s" % (lvhdutil.VG_PREFIX, self.uuid)
2884-
self.path = os.path.join(lvhdutil.VG_LOCATION, self.vgName)
2883+
self.vgName = "%s%s" % (VG_PREFIX, self.uuid)
2884+
self.path = os.path.join(VG_LOCATION, self.vgName)
28852885

28862886
sr_ref = self.xapi.session.xenapi.SR.get_by_uuid(self.uuid)
28872887
other_conf = self.xapi.session.xenapi.SR.get_other_config(sr_ref)
@@ -2958,7 +2958,7 @@ def _scan(self, force):
29582958
for i in range(SR.SCAN_RETRY_ATTEMPTS):
29592959
error = False
29602960
self.lvmCache.refresh()
2961-
vdis = lvhdutil.getVDIInfo(self.lvmCache)
2961+
vdis = LvmCowUtil.getVDIInfo(self.lvmCache)
29622962
for uuid, vdiInfo in vdis.items():
29632963
if vdiInfo.scanError:
29642964
error = True
@@ -3007,7 +3007,7 @@ def _updateNode(self, vdi) -> None:
30073007
# this node is really the parent node) - minus 1 if it is online (since
30083008
# non-leaf nodes increment their normal counts when they are online and
30093009
# we are now a leaf, storing that 1 in the binary refcount).
3010-
ns = lvhdutil.NS_PREFIX_LVM + self.uuid
3010+
ns = NS_PREFIX_LVM + self.uuid
30113011
cCnt, cBcnt = RefCounter.check(vdi.uuid, ns)
30123012
pCnt, pBcnt = RefCounter.check(vdi.parent.uuid, ns)
30133013
pCnt = pCnt - cBcnt
@@ -3023,17 +3023,17 @@ def _finishCoalesceLeaf(self, parent) -> None:
30233023

30243024
@override
30253025
def _calcExtraSpaceNeeded(self, child, parent) -> int:
3026-
return lvhdutil.calcSizeVHDLV(parent.sizeVirt) - parent.sizeLV
3026+
return parent.lvmcowutil.calcVolumeSize(parent.sizeVirt) - parent.sizeLV
30273027

30283028
@override
30293029
def _handleInterruptedCoalesceLeaf(self) -> None:
30303030
entries = self.journaler.getAll(VDI.JRN_LEAF)
30313031
for uuid, parentUuid in entries.items():
3032-
childLV = lvhdutil.LV_PREFIX[VdiType.VHD] + uuid
3033-
tmpChildLV = lvhdutil.LV_PREFIX[VdiType.VHD] + \
3032+
childLV = LV_PREFIX[VdiType.VHD] + uuid
3033+
tmpChildLV = LV_PREFIX[VdiType.VHD] + \
30343034
self.TMP_RENAME_PREFIX + uuid
3035-
parentLV1 = lvhdutil.LV_PREFIX[VdiType.VHD] + parentUuid
3036-
parentLV2 = lvhdutil.LV_PREFIX[VdiType.RAW] + parentUuid
3035+
parentLV1 = LV_PREFIX[VdiType.VHD] + parentUuid
3036+
parentLV2 = LV_PREFIX[VdiType.RAW] + parentUuid
30373037
parentPresent = (self.lvmCache.checkLV(parentLV1) or \
30383038
self.lvmCache.checkLV(parentLV2))
30393039
if parentPresent or self.lvmCache.checkLV(tmpChildLV):
@@ -3073,7 +3073,7 @@ def _undoInterruptedCoalesceLeaf(self, childUuid, parentUuid):
30733073
# refcount (best effort - assume that it had succeeded if the
30743074
# second rename succeeded; if not, this adjustment will be wrong,
30753075
# leading to a non-deactivation of the LV)
3076-
ns = lvhdutil.NS_PREFIX_LVM + self.uuid
3076+
ns = NS_PREFIX_LVM + self.uuid
30773077
cCnt, cBcnt = RefCounter.check(child.uuid, ns)
30783078
pCnt, pBcnt = RefCounter.check(parent.uuid, ns)
30793079
pCnt = pCnt + cBcnt
@@ -3120,7 +3120,7 @@ def _checkSlaves(self, vdi):
31203120
"lvName1": vdi.fileName,
31213121
"action2": "cleanupLockAndRefcount",
31223122
"uuid2": vdi.uuid,
3123-
"ns2": lvhdutil.NS_PREFIX_LVM + self.uuid}
3123+
"ns2": NS_PREFIX_LVM + self.uuid}
31243124
onlineHosts = self.xapi.getOnlineHosts()
31253125
abortFlag = IPCFlag(self.uuid)
31263126
for pbdRecord in self.xapi.getAttachedPBDs():
@@ -3145,7 +3145,7 @@ def _updateSlavesOnUndoLeafCoalesce(self, parent, child) -> None:
31453145
child)
31463146
return
31473147

3148-
tmpName = lvhdutil.LV_PREFIX[VdiType.VHD] + \
3148+
tmpName = LV_PREFIX[VdiType.VHD] + \
31493149
self.TMP_RENAME_PREFIX + child.uuid
31503150
args = {"vgName": self.vgName,
31513151
"action1": "deactivateNoRefcount",
@@ -3178,7 +3178,7 @@ def _updateSlavesOnRename(self, vdi, oldNameLV, origParentUuid) -> None:
31783178
"lvName2": vdi.fileName,
31793179
"action3": "cleanupLockAndRefcount",
31803180
"uuid3": origParentUuid,
3181-
"ns3": lvhdutil.NS_PREFIX_LVM + self.uuid}
3181+
"ns3": NS_PREFIX_LVM + self.uuid}
31823182
for slave in slaves:
31833183
Util.log("Updating %s to %s on slave %s" % \
31843184
(oldNameLV, vdi.fileName,
@@ -3194,7 +3194,7 @@ def _updateSlavesOnResize(self, vdi) -> None:
31943194
if not slaves:
31953195
util.SMlog("Update-on-resize: %s not attached on any slave" % vdi)
31963196
return
3197-
lvhdutil.lvRefreshOnSlaves(self.xapi.session, self.uuid, self.vgName,
3197+
LvmCowUtil.refreshVolumeOnSlaves(self.xapi.session, self.uuid, self.vgName,
31983198
vdi.fileName, vdi.uuid, slaves)
31993199

32003200

@@ -3973,7 +3973,7 @@ def debug(sr_uuid, cmd, vdi_uuid):
39733973
vdi._activate()
39743974
print("VDI file: %s" % vdi.path)
39753975
if cmd == "deactivate":
3976-
ns = lvhdutil.NS_PREFIX_LVM + sr.uuid
3976+
ns = NS_PREFIX_LVM + sr.uuid
39773977
sr.lvmCache.deactivate(ns, vdi.uuid, vdi.fileName, False)
39783978
if cmd == "inflate":
39793979
vdi.inflateFully()

drivers/cowutil.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ImageFormat(IntEnum):
4141
ImageFormat.QCOW2: "qcow2"
4242
}
4343

44-
STR_TO_IMAGE_FORMAT = {v: k for k, v in IMAGE_FORMAT_TO_STR.items()}
44+
STR_TO_IMAGE_FORMAT: Final = {v: k for k, v in IMAGE_FORMAT_TO_STR.items()}
4545

4646
# ------------------------------------------------------------------------------
4747

@@ -99,7 +99,11 @@ def getBlockSize(self, path: str) -> int:
9999
pass
100100

101101
@abstractmethod
102-
def getFooterSize(self, path: str) -> int:
102+
def getFooterSize(self) -> int:
103+
pass
104+
105+
@abstractmethod
106+
def getDefaultPreallocationSizeVirt(self) -> int:
103107
pass
104108

105109
@abstractmethod

0 commit comments

Comments
 (0)