Skip to content

Commit b70adf4

Browse files
committed
refactor(constants.py): move VG_LOCATION, VG_PREFIX and NS_PREFIX_LVM
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.fr>
1 parent c608c08 commit b70adf4

12 files changed

Lines changed: 69 additions & 45 deletions

drivers/LVMSR.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from journaler import Journaler
4242
from refcounter import RefCounter
4343
from ipc import IPCFlag
44+
from constants import NS_PREFIX_LVM, VG_LOCATION, VG_PREFIX
4445
from lvmanager import LVActivator
4546
from vditype import VdiType
4647
import XenAPI # pylint: disable=import-error
@@ -55,7 +56,7 @@
5556
import glob
5657
from constants import CBTLOG_TAG
5758
from fairlock import Fairlock
58-
DEV_MAPPER_ROOT = os.path.join('/dev/mapper', lvhdutil.VG_PREFIX)
59+
DEV_MAPPER_ROOT = os.path.join('/dev/mapper', VG_PREFIX)
5960

6061
geneology: Dict[str, List[str]] = {}
6162
CAPABILITIES = ["SR_PROBE", "SR_UPDATE", "SR_TRIM",
@@ -162,8 +163,8 @@ def load(self, sr_uuid) -> None:
162163
self.lock = lock.Lock(lock.LOCK_TYPE_SR, self.uuid)
163164
self.sr_vditype = SR.DEFAULT_TAP
164165
self.uuid = sr_uuid
165-
self.vgname = lvhdutil.VG_PREFIX + self.uuid
166-
self.path = os.path.join(lvhdutil.VG_LOCATION, self.vgname)
166+
self.vgname = VG_PREFIX + self.uuid
167+
self.path = os.path.join(VG_LOCATION, self.vgname)
167168
self.mdpath = os.path.join(self.path, self.MDVOLUME_NAME)
168169
self.provision = self.PROVISIONING_DEFAULT
169170

@@ -860,8 +861,8 @@ def _updateStats(self, uuid, virtAllocDelta):
860861
@deviceCheck
861862
def probe(self) -> str:
862863
return lvutil.srlist_toxml(
863-
lvutil.scan_srlist(lvhdutil.VG_PREFIX, self.dconf['device']),
864-
lvhdutil.VG_PREFIX,
864+
lvutil.scan_srlist(VG_PREFIX, self.dconf['device']),
865+
VG_PREFIX,
865866
('metadata' in self.srcmd.params['sr_sm_config'] and \
866867
self.srcmd.params['sr_sm_config']['metadata'] == 'true'))
867868

@@ -990,7 +991,7 @@ def _undoCloneOp(self, lvs, origUuid, baseUuid, clonUuid):
990991
if base.readonly:
991992
self.lvmCache.setReadonly(base.name, False)
992993

993-
ns = lvhdutil.NS_PREFIX_LVM + self.uuid
994+
ns = NS_PREFIX_LVM + self.uuid
994995
origRefcountBinary = RefCounter.check(origUuid, ns)[1]
995996
origRefcountNormal = 0
996997

@@ -1248,7 +1249,7 @@ def _updateSlavesOnClone(self, hostRefs, origOldLV, origLV,
12481249
"action1": "refresh",
12491250
"lvName1": origLV,
12501251
"action2": "activate",
1251-
"ns2": lvhdutil.NS_PREFIX_LVM + self.uuid,
1252+
"ns2": NS_PREFIX_LVM + self.uuid,
12521253
"lvName2": baseLV,
12531254
"uuid2": baseUuid}
12541255

@@ -1288,7 +1289,7 @@ def _updateSlavesOnRemove(self, hostRefs, baseUuid, baseLV):
12881289
args = {"vgName": self.vgname,
12891290
"action1": "cleanupLockAndRefcount",
12901291
"uuid1": baseUuid,
1291-
"ns1": lvhdutil.NS_PREFIX_LVM + self.uuid}
1292+
"ns1": NS_PREFIX_LVM + self.uuid}
12921293

12931294
masterRef = util.get_this_host_ref(self.session)
12941295
for hostRef in hostRefs:
@@ -1303,11 +1304,11 @@ def _updateSlavesOnRemove(self, hostRefs, baseUuid, baseLV):
13031304

13041305
def _cleanup(self, skipLockCleanup=False):
13051306
"""delete stale refcounter, flag, and lock files"""
1306-
RefCounter.resetAll(lvhdutil.NS_PREFIX_LVM + self.uuid)
1307+
RefCounter.resetAll(NS_PREFIX_LVM + self.uuid)
13071308
IPCFlag(self.uuid).clearAll()
13081309
if not skipLockCleanup:
13091310
lock.Lock.cleanupAll(self.uuid)
1310-
lock.Lock.cleanupAll(lvhdutil.NS_PREFIX_LVM + self.uuid)
1311+
lock.Lock.cleanupAll(NS_PREFIX_LVM + self.uuid)
13111312

13121313
def _prepareTestMode(self):
13131314
util.SMlog("Test mode: %s" % self.testMode)
@@ -1469,7 +1470,7 @@ def delete(self, sr_uuid, vdi_uuid, data_only=False) -> None:
14691470

14701471
try:
14711472
self.sr.lvmCache.remove(self.lvname)
1472-
self.sr.lock.cleanup(vdi_uuid, lvhdutil.NS_PREFIX_LVM + sr_uuid)
1473+
self.sr.lock.cleanup(vdi_uuid, NS_PREFIX_LVM + sr_uuid)
14731474
self.sr.lock.cleanupAll(vdi_uuid)
14741475
except xs_errors.SRException as e:
14751476
util.SMlog(
@@ -1786,7 +1787,7 @@ def _snapshot(self, snapType, cloneOp=False, cbtlog=None, cbt_consistency=None):
17861787
baseLV = lvhdutil.LV_PREFIX[self.vdi_type] + baseUuid
17871788
self.sr.lvmCache.rename(self.lvname, baseLV)
17881789
self.sr.lvActivator.replace(self.uuid, baseUuid, baseLV, False)
1789-
RefCounter.set(baseUuid, 1, 0, lvhdutil.NS_PREFIX_LVM + self.sr.uuid)
1790+
RefCounter.set(baseUuid, 1, 0, NS_PREFIX_LVM + self.sr.uuid)
17901791
self.uuid = baseUuid
17911792
self.lvname = baseLV
17921793
self.path = os.path.join(self.sr.path, baseLV)
@@ -1861,7 +1862,7 @@ def _createSnap(self, snapUuid, snapSizeLV, isNew):
18611862
self.sr.lvmCache.create(snapLV, int(snapSizeLV))
18621863
util.fistpoint.activate("LVHDRT_clone_vdi_after_lvcreate", self.sr.uuid)
18631864
if isNew:
1864-
RefCounter.set(snapUuid, 1, 0, lvhdutil.NS_PREFIX_LVM + self.sr.uuid)
1865+
RefCounter.set(snapUuid, 1, 0, NS_PREFIX_LVM + self.sr.uuid)
18651866
self.sr.lvActivator.add(snapUuid, snapLV, False)
18661867
parentRaw = (self.vdi_type == VdiType.RAW)
18671868
vhdutil.snapshot(snapPath, self.path, parentRaw, lvhdutil.MSIZE_MB)
@@ -1898,7 +1899,7 @@ def _finishSnapshot(self, snapVDI, snapVDI2, hostRefs, cloneOp=False, snapType=N
18981899
(not snapVDI2 or snap2Parent != self.uuid):
18991900
util.SMlog("%s != %s != %s => deleting unused base %s" % \
19001901
(snapParent, self.uuid, snap2Parent, self.lvname))
1901-
RefCounter.put(self.uuid, False, lvhdutil.NS_PREFIX_LVM + self.sr.uuid)
1902+
RefCounter.put(self.uuid, False, NS_PREFIX_LVM + self.sr.uuid)
19021903
self.sr.lvmCache.remove(self.lvname)
19031904
self.sr.lvActivator.remove(self.uuid, False)
19041905
if hostRefs:
@@ -1921,7 +1922,7 @@ def _finishSnapshot(self, snapVDI, snapVDI2, hostRefs, cloneOp=False, snapType=N
19211922
# cannot affect the VDIs here because they cannot possibly be
19221923
# involved in coalescing at this point, and at the relinkSkip step
19231924
# that activates the children, which takes the SR lock.)
1924-
ns = lvhdutil.NS_PREFIX_LVM + self.sr.uuid
1925+
ns = NS_PREFIX_LVM + self.sr.uuid
19251926
(cnt, bcnt) = RefCounter.check(snapVDI.uuid, ns)
19261927
RefCounter.set(self.uuid, bcnt + 1, 0, ns)
19271928

@@ -2128,7 +2129,7 @@ def _loadThis(self):
21282129
def _chainSetActive(self, active, binary, persistent=False):
21292130
if binary:
21302131
(count, bcount) = RefCounter.checkLocked(self.uuid,
2131-
lvhdutil.NS_PREFIX_LVM + self.sr.uuid)
2132+
NS_PREFIX_LVM + self.sr.uuid)
21322133
if (active and bcount > 0) or (not active and bcount == 0):
21332134
return # this is a redundant activation/deactivation call
21342135

drivers/blktap2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import xs_errors
4242
import XenAPI # pylint: disable=import-error
4343
import scsiutil
44+
from constants import NS_PREFIX_LVM
4445
from syslog import openlog, syslog
4546
from stat import * # S_ISBLK(), ...
4647
from vditype import VdiType
@@ -1672,7 +1673,7 @@ def _activate_locked(self, sr_uuid, vdi_uuid, options):
16721673
if hasattr(self.target.vdi.sr, 'DRIVER_TYPE') and \
16731674
self.target.vdi.sr.DRIVER_TYPE == 'lvhd' and \
16741675
VdiType.isCowImage(vdi_type):
1675-
lock = Lock("lvchange-p", lvhdutil.NS_PREFIX_LVM + sr_uuid)
1676+
lock = Lock("lvchange-p", NS_PREFIX_LVM + sr_uuid)
16761677
lock.acquire()
16771678

16781679
# When we attach a static VDI for HA, we cannot communicate with

drivers/cleanup.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
from time import monotonic as _time
5454
from vditype import VdiType, VdiTypeExtension, VDI_TYPE_TO_EXTENSION
5555

56+
from constants import NS_PREFIX_LVM, VG_LOCATION, VG_PREFIX
57+
5658
try:
5759
from linstorjournaler import LinstorJournaler
5860
from linstorvhdutil import LinstorVhdUtil
@@ -782,7 +784,7 @@ def rename(self, uuid) -> None:
782784

783785
def delete(self) -> None:
784786
"Physically delete the VDI"
785-
lock.Lock.cleanup(self.uuid, lvhdutil.NS_PREFIX_LVM + self.sr.uuid)
787+
lock.Lock.cleanup(self.uuid, NS_PREFIX_LVM + self.sr.uuid)
786788
lock.Lock.cleanupAll(self.uuid)
787789
self._clear()
788790

@@ -1317,7 +1319,7 @@ def rename(self, uuid) -> None:
13171319
if self.sr.lvActivator.get(oldUuid, False):
13181320
self.sr.lvActivator.replace(oldUuid, self.uuid, self.fileName, False)
13191321

1320-
ns = lvhdutil.NS_PREFIX_LVM + self.sr.uuid
1322+
ns = NS_PREFIX_LVM + self.sr.uuid
13211323
(cnt, bcnt) = RefCounter.check(oldUuid, ns)
13221324
RefCounter.set(self.uuid, cnt, bcnt, ns)
13231325
RefCounter.reset(oldUuid, ns)
@@ -1333,7 +1335,7 @@ def delete(self) -> None:
13331335
self.sr.forgetVDI(self.uuid)
13341336
finally:
13351337
self.sr.unlock()
1336-
RefCounter.reset(self.uuid, lvhdutil.NS_PREFIX_LVM + self.sr.uuid)
1338+
RefCounter.reset(self.uuid, NS_PREFIX_LVM + self.sr.uuid)
13371339
VDI.delete(self)
13381340

13391341
@override
@@ -3043,8 +3045,8 @@ class LVMSR(SR):
30433045

30443046
def __init__(self, uuid, xapi, createLock, force):
30453047
SR.__init__(self, uuid, xapi, createLock, force)
3046-
self.vgName = "%s%s" % (lvhdutil.VG_PREFIX, self.uuid)
3047-
self.path = os.path.join(lvhdutil.VG_LOCATION, self.vgName)
3048+
self.vgName = "%s%s" % (VG_PREFIX, self.uuid)
3049+
self.path = os.path.join(VG_LOCATION, self.vgName)
30483050

30493051
sr_ref = self.xapi.session.xenapi.SR.get_by_uuid(self.uuid)
30503052
other_conf = self.xapi.session.xenapi.SR.get_other_config(sr_ref)
@@ -3170,7 +3172,7 @@ def _updateNode(self, vdi) -> None:
31703172
# this node is really the parent node) - minus 1 if it is online (since
31713173
# non-leaf nodes increment their normal counts when they are online and
31723174
# we are now a leaf, storing that 1 in the binary refcount).
3173-
ns = lvhdutil.NS_PREFIX_LVM + self.uuid
3175+
ns = NS_PREFIX_LVM + self.uuid
31743176
cCnt, cBcnt = RefCounter.check(vdi.uuid, ns)
31753177
pCnt, pBcnt = RefCounter.check(vdi.parent.uuid, ns)
31763178
pCnt = pCnt - cBcnt
@@ -3236,7 +3238,7 @@ def _undoInterruptedCoalesceLeaf(self, childUuid, parentUuid):
32363238
# refcount (best effort - assume that it had succeeded if the
32373239
# second rename succeeded; if not, this adjustment will be wrong,
32383240
# leading to a non-deactivation of the LV)
3239-
ns = lvhdutil.NS_PREFIX_LVM + self.uuid
3241+
ns = NS_PREFIX_LVM + self.uuid
32403242
cCnt, cBcnt = RefCounter.check(child.uuid, ns)
32413243
pCnt, pBcnt = RefCounter.check(parent.uuid, ns)
32423244
pCnt = pCnt + cBcnt
@@ -3283,7 +3285,7 @@ def _checkSlaves(self, vdi):
32833285
"lvName1": vdi.fileName,
32843286
"action2": "cleanupLockAndRefcount",
32853287
"uuid2": vdi.uuid,
3286-
"ns2": lvhdutil.NS_PREFIX_LVM + self.uuid}
3288+
"ns2": NS_PREFIX_LVM + self.uuid}
32873289
onlineHosts = self.xapi.getOnlineHosts()
32883290
abortFlag = IPCFlag(self.uuid)
32893291
for pbdRecord in self.xapi.getAttachedPBDs():
@@ -3341,7 +3343,7 @@ def _updateSlavesOnRename(self, vdi, oldNameLV, origParentUuid) -> None:
33413343
"lvName2": vdi.fileName,
33423344
"action3": "cleanupLockAndRefcount",
33433345
"uuid3": origParentUuid,
3344-
"ns3": lvhdutil.NS_PREFIX_LVM + self.uuid}
3346+
"ns3": NS_PREFIX_LVM + self.uuid}
33453347
for slave in slaves:
33463348
Util.log("Updating %s to %s on slave %s" % \
33473349
(oldNameLV, vdi.fileName,
@@ -4123,7 +4125,7 @@ def debug(sr_uuid, cmd, vdi_uuid):
41234125
vdi._activate()
41244126
print("VDI file: %s" % vdi.path)
41254127
if cmd == "deactivate":
4126-
ns = lvhdutil.NS_PREFIX_LVM + sr.uuid
4128+
ns = NS_PREFIX_LVM + sr.uuid
41274129
sr.lvmCache.deactivate(ns, vdi.uuid, vdi.fileName, False)
41284130
if cmd == "inflate":
41294131
vdi.inflateFully()

drivers/constants.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
from sm_typing import Final
2+
13
EXT_PREFIX = 'XSLocalEXT-'
24
CBT_BLOCK_SIZE = (64 * 1024)
35
CBTLOG_TAG = "cbtlog"
46
CBT_UTIL = "/usr/sbin/cbt-util"
7+
8+
VG_LOCATION: Final = "/dev"
9+
VG_PREFIX: Final = "VG_XenStorage-"
10+
11+
# Ref counting for VDI's: we need a ref count for LV activation/deactivation
12+
# on the master.
13+
NS_PREFIX_LVM: Final = "lvm-"

drivers/lvhd-thin

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ from journaler import Journaler
2828
import lvutil
2929
import os
3030

31+
from constants import VG_PREFIX
32+
3133
def attach(session, args):
3234
if util.is_master(session):
3335
os.environ['LVM_SYSTEM_DIR'] = lvutil.MASTER_LVM_CONF
3436
srUuid = args["srUuid"]
3537
vdiUuid = args["vdiUuid"]
36-
vgName = "%s%s" % (lvhdutil.VG_PREFIX, srUuid)
38+
vgName = "%s%s" % (VG_PREFIX, srUuid)
3739
lvmCache = LVMCache(vgName)
3840
journaler = Journaler(lvmCache)
3941
try:
@@ -48,7 +50,7 @@ def detach(session, args):
4850
os.environ['LVM_SYSTEM_DIR'] = lvutil.MASTER_LVM_CONF
4951
srUuid = args["srUuid"]
5052
vdiUuid = args["vdiUuid"]
51-
vgName = "%s%s" % (lvhdutil.VG_PREFIX, srUuid)
53+
vgName = "%s%s" % (VG_PREFIX, srUuid)
5254
lvmCache = LVMCache(vgName)
5355
try:
5456
lvhdutil.detachThin(session, lvmCache, args["srUuid"], args["vdiUuid"])

drivers/lvmanager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import util
2121
import lvhdutil
2222

23+
from constants import NS_PREFIX_LVM
2324

2425
class LVManagerException(util.SMException):
2526
pass
@@ -42,7 +43,7 @@ class LVActivator:
4243
PERSISTENT = True
4344

4445
def __init__(self, srUuid, lvmCache):
45-
self.ns = lvhdutil.NS_PREFIX_LVM + srUuid
46+
self.ns = NS_PREFIX_LVM + srUuid
4647
self.lvmCache = lvmCache
4748
self.lvActivations = dict()
4849
self.openFiles = dict()

drivers/lvmcache.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import util
2121
import lvutil
2222
import lvhdutil
23+
24+
from constants import NS_PREFIX_LVM
2325
from lock import Lock
2426
from refcounter import RefCounter
2527

@@ -226,7 +228,7 @@ def setReadonly(self, lvName, readonly):
226228
path = self._getPath(lvName)
227229
if self.lvs[lvName].readonly != readonly:
228230
uuids = util.findall_uuid(path)
229-
ns = lvhdutil.NS_PREFIX_LVM + uuids[0]
231+
ns = NS_PREFIX_LVM + uuids[0]
230232
# Taking this lock is needed to avoid a race condition
231233
# with tap-ctl open (which is now taking the same lock)
232234
lock = Lock("lvchange-p", ns)

drivers/lvutil.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
import util
2828
import xs_errors
2929
import xml.dom.minidom
30-
from lvhdutil import VG_LOCATION, VG_PREFIX
31-
from constants import EXT_PREFIX
30+
from constants import EXT_PREFIX, VG_LOCATION, VG_PREFIX
3231
import lvmcache
3332
import srmetadata
3433

drivers/tapdisk-pause

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import XenAPI
2828
import lvhdutil
2929
import vhdutil
3030
import lvmcache
31+
32+
from constants import NS_PREFIX_LVM, VG_PREFIX
3133
from vditype import VdiType
3234

3335
try:
@@ -209,8 +211,8 @@ class Tapdisk:
209211
return str(False)
210212
if self.activate_parents:
211213
util.SMlog("Activating parents of %s" % self.vdi_uuid)
212-
vg_name = lvhdutil.VG_PREFIX + self.sr_uuid
213-
ns = lvhdutil.NS_PREFIX_LVM + self.sr_uuid
214+
vg_name = VG_PREFIX + self.sr_uuid
215+
ns = NS_PREFIX_LVM + self.sr_uuid
214216
lvm_cache = lvmcache.LVMCache(vg_name)
215217
lv_name = lvhdutil.LV_PREFIX[VdiType.VHD] + self.vdi_uuid
216218
vdi_list = vhdutil.getParentChain(lv_name,

drivers/trim_util.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import vhdutil
2626
import lvutil
2727

28+
from constants import VG_LOCATION, VG_PREFIX
29+
2830
TRIM_LV_TAG = "_trim_lv"
2931
TRIM_CAP = "SR_TRIM"
3032
LOCK_RETRY_ATTEMPTS = 3
@@ -37,11 +39,11 @@
3739

3840

3941
def _vg_by_sr_uuid(sr_uuid):
40-
return lvhdutil.VG_PREFIX + sr_uuid
42+
return VG_PREFIX + sr_uuid
4143

4244

4345
def _lvpath_by_vg_lv_name(vg_name, lv_name):
44-
return os.path.join(lvhdutil.VG_LOCATION, vg_name, lv_name)
46+
return os.path.join(VG_LOCATION, vg_name, lv_name)
4547

4648

4749
def to_xml(d):

0 commit comments

Comments
 (0)