Skip to content

Commit

Permalink
CP-46863 Dump Multipath Status from Storage Manager
Browse files Browse the repository at this point in the history
Signed-off-by: Lunfan Zhang <Lunfan.Zhang@cloud.com>
  • Loading branch information
LunfanZhang authored and MarkSymsCtx committed Jan 11, 2024
1 parent df24f36 commit 04958e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
20 changes: 15 additions & 5 deletions drivers/mpathcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import re
import xs_errors
import mpath_cli
import json

supported = ['iscsi', 'lvmoiscsi', 'rawhba', 'lvmohba', 'ocfsohba', 'ocfsoiscsi', 'netapp', 'lvmofcoe', 'gfs2']

Expand All @@ -29,6 +30,8 @@
LOCK_NS2 = "mpathcount2"

MAPPER_DIR = "/dev/mapper"
MPATHS_DIR = "/dev/shm"
MPATH_FILE_NAME = "/dev/shm/mpath_status"
match_bySCSIid = False
mpath_enabled = True
SCSIid = 'NOTSUPPLIED'
Expand Down Expand Up @@ -113,7 +116,8 @@ def get_root_dev_major():
# @entry: string representing previous value
# @remove: callback to remove key
# @add: callback to add key/value pair
def update_config(key, SCSIid, entry, remove, add):
# @mpath_status: map to record multipath status
def update_config(key, SCSIid, entry, remove, add, mpath_status=None):
path = os.path.join(MAPPER_DIR, SCSIid)
util.SMlog("MPATH: Updating entry for [%s], current: %s" % (SCSIid, entry))
if os.path.exists(path):
Expand All @@ -136,6 +140,8 @@ def update_config(key, SCSIid, entry, remove, add):
add('multipathed', 'true')
add(key, str(newentry))
util.SMlog("MPATH: Set val: %s" % str(newentry))
if mpath_status != None:
mpath_status.update({str(key): f"{count}/{max}"})
else:
util.SMlog('MPATH: device %s gone' % (SCSIid))
remove('multipathed')
Expand Down Expand Up @@ -175,7 +181,7 @@ def check_root_disk(config, maps, remove, add):
update_config(key, i, config[key], remove, add)


def check_devconfig(devconfig, sm_config, config, remove, add):
def check_devconfig(devconfig, sm_config, config, remove, add, mpath_status=None):
SCSIidlist = get_SCSIidlist(devconfig, sm_config)
if not len(SCSIidlist):
return
Expand All @@ -189,9 +195,9 @@ def check_devconfig(devconfig, sm_config, config, remove, add):
remove('multipathed')
else:
if key not in config:
update_config(key, i, "", remove, add)
update_config(key, i, "", remove, add, mpath_status)
else:
update_config(key, i, config[key], remove, add)
update_config(key, i, config[key], remove, add, mpath_status)

if __name__ == '__main__':
try:
Expand Down Expand Up @@ -232,6 +238,7 @@ def _add(key, val):
mpc_exit(session, -1)

try:
mpath_status = {}
for pbd in pbds:
def remove(key):
session.xenapi.PBD.remove_from_other_config(pbd, key)
Expand All @@ -246,7 +253,10 @@ def add(key, val):
if srtype in supported:
devconfig = record["device_config"]
sm_config = session.xenapi.SR.get_sm_config(SR)
check_devconfig(devconfig, sm_config, config, remove, add)
check_devconfig(devconfig, sm_config, config, remove, add, mpath_status)
mpath_status = mpath_status if mpath_enabled else {}
util.atomicFileWrite(MPATH_FILE_NAME, MPATHS_DIR, json.dumps(mpath_status))
os.chmod(MPATH_FILE_NAME, 0o0644)
except:
util.SMlog("MPATH: Failure updating db. %s" % sys.exc_info())
mpc_exit(session, -1)
Expand Down
1 change: 1 addition & 0 deletions systemd/mpathcount.service
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ After=xapi-init-complete.target
StandardInput=socket
StandardOutput=null
StandardError=journal
ExecStartPre=/bin/bash -c 'if [ ! -f "/dev/shm/mpath_status" ]; then /opt/xensource/sm/mpathcount.py; fi'
ExecStart=/usr/bin/sh -c '. /etc/xensource-inventory; while dd of=/dev/null bs=4096 count=1 status=none conv=noerror; do /opt/xensource/sm/mpathcount.py; done'
Restart=always
2 changes: 1 addition & 1 deletion tests/test_mpathcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def remove(key):
print("del {}".format(key))
del store[key]

def fake_update_config(k, s, v, a, t):
def fake_update_config(k, s, v, a, t, p):
store[k] = v

update_config.side_effect = fake_update_config
Expand Down

0 comments on commit 04958e7

Please sign in to comment.