Skip to content

Commit 8a0c6f1

Browse files
committed
LVM COW in progress (to squash)
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.fr>
1 parent 270df04 commit 8a0c6f1

File tree

15 files changed

+338
-397
lines changed

15 files changed

+338
-397
lines changed

drivers/LVHDSR.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import lvutil
2929
import lvmcache
3030
import vhdutil
31-
import lvhdutil
3231
import scsiutil
3332
import lock
3433
import os
@@ -41,6 +40,7 @@
4140
from journaler import Journaler
4241
from refcounter import RefCounter
4342
from ipc import IPCFlag
43+
from lvmcowutil import LV_PREFIX, NS_PREFIX_LVM, VG_LOCATION, VG_PREFIX
4444
from lvmanager import LVActivator
4545
from vditype import VdiType
4646
import XenAPI # pylint: disable=import-error
@@ -55,7 +55,7 @@
5555
import glob
5656
from constants import CBTLOG_TAG
5757
from fairlock import Fairlock
58-
DEV_MAPPER_ROOT = os.path.join('/dev/mapper', lvhdutil.VG_PREFIX)
58+
DEV_MAPPER_ROOT = os.path.join('/dev/mapper', VG_PREFIX)
5959

6060
geneology: Dict[str, List[str]] = {}
6161
CAPABILITIES = ["SR_PROBE", "SR_UPDATE", "SR_TRIM",
@@ -559,7 +559,7 @@ def delete(self, uuid) -> None:
559559

560560
self._removeMetadataVolume()
561561
self.lvmCache.refresh()
562-
if len(lvhdutil.getLVInfo(self.lvmCache)) > 0:
562+
if len(LvmCowUtil.getVolumeInfo(self.lvmCache)) > 0:
563563
raise xs_errors.XenError('SRNotEmpty')
564564

565565
if not success:
@@ -596,7 +596,7 @@ def attach(self, uuid) -> None:
596596

597597
# Test Legacy Mode Flag and update if VHD volumes exist
598598
if self.isMaster and self.legacyMode:
599-
vdiInfo = lvhdutil.getVDIInfo(self.lvmCache)
599+
vdiInfo = LvmCowUtil.getVDIInfo(self.lvmCache)
600600
for uuid, info in vdiInfo.items():
601601
if VdiType.isCowImage(info.vdiType):
602602
self.legacyMode = False
@@ -858,8 +858,8 @@ def _updateStats(self, uuid, virtAllocDelta):
858858
@deviceCheck
859859
def probe(self) -> str:
860860
return lvutil.srlist_toxml(
861-
lvutil.scan_srlist(lvhdutil.VG_PREFIX, self.dconf['device']),
862-
lvhdutil.VG_PREFIX,
861+
lvutil.scan_srlist(VG_PREFIX, self.dconf['device']),
862+
VG_PREFIX,
863863
('metadata' in self.srcmd.params['sr_sm_config'] and \
864864
self.srcmd.params['sr_sm_config']['metadata'] == 'true'))
865865

@@ -869,7 +869,7 @@ def vdi(self, uuid) -> VDI.VDI:
869869

870870
def _loadvdis(self):
871871
self.virtual_allocation = 0
872-
self.vdiInfo = lvhdutil.getVDIInfo(self.lvmCache)
872+
self.vdiInfo = LvmCowUtil.getVDIInfo(self.lvmCache)
873873
self.allVDIs = {}
874874

875875
for uuid, info in self.vdiInfo.items():
@@ -927,7 +927,7 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
927927
we're still in the context of the failed snapshot operation since the
928928
VBD is paused for the duration of the operation"""
929929
util.SMlog("*** INTERRUPTED CLONE OP: for %s (%s)" % (origUuid, jval))
930-
lvs = lvhdutil.getLVInfo(self.lvmCache)
930+
lvs = LvmCowUtil.getVolumeInfo(self.lvmCache)
931931
baseUuid, clonUuid = jval.split("_")
932932

933933
cowutil = None # TODO
@@ -951,7 +951,7 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
951951
self._undoCloneOp(lvs, origUuid, baseUuid, clonUuid)
952952
return
953953

954-
vdis = lvhdutil.getVDIInfo(self.lvmCache)
954+
vdis = LvmCowUtil.getVDIInfo(self.lvmCache)
955955
if vdis[origUuid].scanError or (clonUuid and vdis[clonUuid].scanError):
956956
util.SMlog("One or both leaves invalid => revert")
957957
self._undoCloneOp(lvs, origUuid, baseUuid, clonUuid)
@@ -1001,7 +1001,7 @@ def _undoCloneOp(self, lvs, origUuid, baseUuid, clonUuid):
10011001
if VdiType.isCowImage(base.vdiType):
10021002
self.lvActivator.activate(baseUuid, base.name, False)
10031003
origRefcountNormal = 1
1004-
cow_info = cowutil.getInfo(basePath, lvhdutil.extractUuid, False)
1004+
cow_info = cowutil.getInfo(basePath, LvmCowUtil.extractUuid, False)
10051005
if cow_info.hidden:
10061006
cowutil.setHidden(basePath, False)
10071007
elif base.hidden:
@@ -1020,7 +1020,7 @@ def _undoCloneOp(self, lvs, origUuid, baseUuid, clonUuid):
10201020
# inflate the parent to fully-allocated size
10211021
if VdiType.isCowImage(base.vdiType):
10221022
fullSize = lvmcowutil.calcVolumeSize(vhdInfo.sizeVirt)
1023-
lvmcowutil.inflate(self.journaler, self.uuid, baseUuid, fullSize)
1023+
lvmcowutil.inflate(self.journaler, self.uuid, baseUuid, base.vdiType, fullSize)
10241024

10251025
# rename back
10261026
origLV = lvhdutil.LV_PREFIX[base.vdiType] + origUuid
@@ -1037,7 +1037,7 @@ def _undoCloneOp(self, lvs, origUuid, baseUuid, clonUuid):
10371037

10381038
# update LVM metadata on slaves
10391039
slaves = util.get_slaves_attached_on(self.session, [origUuid])
1040-
lvhdutil.lvRefreshOnSlaves(self.session, self.uuid, self.vgname,
1040+
LvmCowUtil.refreshVolumeOnSlaves(self.session, self.uuid, self.vgname,
10411041
origLV, origUuid, slaves)
10421042

10431043
util.SMlog("*** INTERRUPTED CLONE OP: rollback success")
@@ -1193,8 +1193,9 @@ def _undoAllInflateJournals(self):
11931193
if vdi.readonly:
11941194
self.lvmCache.setReadonly(vdi.lvname, True)
11951195
if "true" == self.session.xenapi.SR.get_shared(self.sr_ref):
1196-
lvhdutil.lvRefreshOnAllSlaves(self.session, self.uuid,
1197-
self.vgname, vdi.lvname, uuid)
1196+
LvmCowUtil.refreshVolumeOnAllSlaves(
1197+
self.session, self.uuid, self.vgname, vdi.lvname, uuid
1198+
)
11981199
self.journaler.remove(lvhdutil.JRN_INFLATE, uuid)
11991200
delattr(self, "vdiInfo")
12001201
delattr(self, "allVDIs")
@@ -1224,12 +1225,11 @@ def _undoAllVHDJournals(self):
12241225
# Attempt to reclaim unused space
12251226

12261227

1227-
vhdInfo = cowutil.getInfo(vdi.path, lvhdutil.extractUuid, False)
1228+
vhdInfo = cowutil.getInfo(vdi.path, LvmCowUtil.extractUuid, False)
12281229
NewSize = lvmcowutil.calcVolumeSize(vhdInfo.sizeVirt)
12291230
if NewSize < fullSize:
1230-
lvhdutil.deflate(self.lvmCache, vdi.lvname, int(NewSize))
1231-
lvhdutil.lvRefreshOnAllSlaves(self.session, self.uuid,
1232-
self.vgname, vdi.lvname, uuid)
1231+
lvmcowutil.deflate(self.lvmCache, vdi.lvname, int(NewSize))
1232+
LvmCowUtil.refreshVolumeOnAllSlaves(self.session, self.uuid, self.vgname, vdi.lvname, uuid)
12331233
self.lvmCache.remove(jlvName)
12341234
delattr(self, "vdiInfo")
12351235
delattr(self, "allVDIs")
@@ -1880,7 +1880,7 @@ def _createSnap(self, snapUuid, snapSizeLV, isNew):
18801880
self.sr.lvActivator.add(snapUuid, snapLV, False)
18811881
parentRaw = (self.vdi_type == VdiType.RAW)
18821882
self._cowutil.snapshot(snapPath, self.path, parentRaw, cowutil.getPreallocationVirtSize())
1883-
snapParent = self._cowutil.getParent(snapPath, lvhdutil.extractUuid)
1883+
snapParent = self._cowutil.getParent(snapPath, LvmCowUtil.extractUuid)
18841884

18851885
snapVDI = LVHDVDI(self.sr, snapUuid)
18861886
snapVDI.read_only = False
@@ -2106,7 +2106,7 @@ def _determineType(self):
21062106
# when doing attach_from_config, the VG won't be there yet
21072107
return False
21082108

2109-
lvs = lvhdutil.getLVInfo(self.sr.lvmCache)
2109+
lvs = LvmCowUtil.getVolumeInfo(self.sr.lvmCache)
21102110
if lvs.get(self.uuid):
21112111
self._initFromLVInfo(lvs[self.uuid])
21122112
return True
@@ -2120,7 +2120,7 @@ def _loadThis(self):
21202120
self.sr.lvActivator.activate(self.uuid, self.lvname, False)
21212121
return
21222122
try:
2123-
lvs = lvhdutil.getLVInfo(self.sr.lvmCache, self.lvname)
2123+
lvs = LvmCowUtil.getVolumeInfo(self.sr.lvmCache, self.lvname)
21242124
except util.CommandException as e:
21252125
raise xs_errors.XenError('VDIUnavailable',
21262126
opterr='%s (LV scan error)' % os.strerror(abs(e.code)))
@@ -2129,7 +2129,7 @@ def _loadThis(self):
21292129
self._initFromLVInfo(lvs[self.uuid])
21302130
if VdiType.isCowImage(self.vdi_type):
21312131
self.sr.lvActivator.activate(self.uuid, self.lvname, False)
2132-
vhdInfo = self._cowutil.getInfo(self.path, lvhdutil.extractUuid, False)
2132+
vhdInfo = self._cowutil.getInfo(self.path, LvmCowUtil.extractUuid, False)
21332133
if not vhdInfo:
21342134
raise xs_errors.XenError('VDIUnavailable', \
21352135
opterr='getVHDInfo failed')
@@ -2146,7 +2146,7 @@ def _chainSetActive(self, active, binary, persistent=False):
21462146
vdiList = {self.uuid: self.lvname}
21472147
if VdiType.isCowImage(self.vdi_type):
21482148
vdiList = vhdutil.getParentChain(self.lvname,
2149-
lvhdutil.extractUuid, self.sr.vgname)
2149+
LvmCowUtil.extractUuid, self.sr.vgname)
21502150
for uuid, lvName in vdiList.items():
21512151
binaryParam = binary
21522152
if uuid != self.uuid:
@@ -2181,10 +2181,9 @@ def _prepareThin(self, attach):
21812181
if self.sr.isMaster:
21822182
# the master can prepare the VDI locally
21832183
if attach:
2184-
lvhdutil.attachThin(self.sr.journaler, self.sr.uuid, self.uuid)
2184+
self.lvcowutil.attachThin(self.sr.journaler, self.sr.uuid, self.uuid, self.vdi_type)
21852185
else:
2186-
lvhdutil.detachThin(self.session, self.sr.lvmCache,
2187-
self.sr.uuid, self.uuid)
2186+
self.lvcowutil.detachThin(self.session, self.sr.lvmCache, self.sr.uuid, self.uuid, self.vdi_type)
21882187
else:
21892188
fn = "attach"
21902189
if not attach:

drivers/blktap2.py

Lines changed: 2 additions & 2 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 lvmcowutil
5151

5252
import VDI as sm
5353

@@ -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

drivers/cleanup.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from time import monotonic as _time
5353

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

5758
try:
@@ -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-
self.lvmcowutil.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()
@@ -1249,7 +1250,7 @@ def deflate(self):
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)
@@ -1478,7 +1479,7 @@ def _setSizeVirt(self, size) -> None:
14781479
self._activate()
14791480
jFile = self.lvmcowutil.createResizeJournal(self.sr.lvmCache, self.uuid)
14801481
try:
1481-
lvhdutil.setSizeVirt(self.sr.journaler, self.sr.uuid, self.uuid, size, jFile)
1482+
self.lvmcowutil.setSizeVirt(self.sr.journaler, self.sr.uuid, self.uuid, self.vdi_type, size, jFile)
14821483
finally:
14831484
self.lvmcowutil.destroyResizeJournal(self.sr.lvmCache, self.uuid)
14841485

@@ -2879,8 +2880,8 @@ class LVHDSR(SR):
28792880

28802881
def __init__(self, uuid, xapi, createLock, force):
28812882
SR.__init__(self, uuid, xapi, createLock, force)
2882-
self.vgName = "%s%s" % (lvhdutil.VG_PREFIX, self.uuid)
2883-
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)
28842885

28852886
sr_ref = self.xapi.session.xenapi.SR.get_by_uuid(self.uuid)
28862887
other_conf = self.xapi.session.xenapi.SR.get_other_config(sr_ref)
@@ -2957,7 +2958,7 @@ def _scan(self, force):
29572958
for i in range(SR.SCAN_RETRY_ATTEMPTS):
29582959
error = False
29592960
self.lvmCache.refresh()
2960-
vdis = lvhdutil.getVDIInfo(self.lvmCache)
2961+
vdis = LvmCowUtil.getVDIInfo(self.lvmCache)
29612962
for uuid, vdiInfo in vdis.items():
29622963
if vdiInfo.scanError:
29632964
error = True
@@ -3193,7 +3194,7 @@ def _updateSlavesOnResize(self, vdi) -> None:
31933194
if not slaves:
31943195
util.SMlog("Update-on-resize: %s not attached on any slave" % vdi)
31953196
return
3196-
lvhdutil.lvRefreshOnSlaves(self.xapi.session, self.uuid, self.vgName,
3197+
LvmCowUtil.refreshVolumeOnSlaves(self.xapi.session, self.uuid, self.vgName,
31973198
vdi.fileName, vdi.uuid, slaves)
31983199

31993200

drivers/lvhd-thin

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import sys
2222
import XenAPIPlugin
2323
sys.path.append("/opt/xensource/sm/")
24+
import lvmcowutil
2425
import util
25-
import lvhdutil
2626
from lvmcache import LVMCache
2727
from journaler import Journaler
2828
import lvutil
@@ -33,11 +33,11 @@ def attach(session, args):
3333
os.environ['LVM_SYSTEM_DIR'] = lvutil.MASTER_LVM_CONF
3434
srUuid = args["srUuid"]
3535
vdiUuid = args["vdiUuid"]
36-
vgName = "%s%s" % (lvhdutil.VG_PREFIX, srUuid)
36+
vgName = "%s%s" % (lvmcowutil.VG_PREFIX, srUuid)
3737
lvmCache = LVMCache(vgName)
3838
journaler = Journaler(lvmCache)
3939
try:
40-
lvhdutil.attachThin(journaler, srUuid, vdiUuid)
40+
lvcowutil.attachThin(journaler, srUuid, vdiUuid, vdiType)
4141
return str(True)
4242
except Exception as e:
4343
util.logException("lvhd-thin:attach %s" % e)
@@ -48,10 +48,10 @@ def detach(session, args):
4848
os.environ['LVM_SYSTEM_DIR'] = lvutil.MASTER_LVM_CONF
4949
srUuid = args["srUuid"]
5050
vdiUuid = args["vdiUuid"]
51-
vgName = "%s%s" % (lvhdutil.VG_PREFIX, srUuid)
51+
vgName = "%s%s" % (lvmcowutil.VG_PREFIX, srUuid)
5252
lvmCache = LVMCache(vgName)
5353
try:
54-
lvhdutil.detachThin(session, lvmCache, args["srUuid"], args["vdiUuid"])
54+
lvcowutil.detachThin(session, lvmCache, srUuid, vdiUuid, vdiType)
5555
return str(True)
5656
except Exception as e:
5757
util.logException("lvhd-thin:detach %s" % e)

0 commit comments

Comments
 (0)