[Ocfs2-tools-devel] [PATCH 1/1] odump.py: Teach it to interpret the latest ocfs2 dissector output for query_node_info and query_regions
Jie Liu
jeff.liu at oracle.com
Mon Jan 17 00:03:04 PST 2011
The dissector output was improved. The odump script can now handle the
new output.
Signed-off-by: Jie Liu <jeff.liu at oracle.com>
---
ADDONS/odump.py | 133 ++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 112 insertions(+), 21 deletions(-)
diff --git a/ADDONS/odump.py b/ADDONS/odump.py
index 287cf0b..9c62815 100755
--- a/ADDONS/odump.py
+++ b/ADDONS/odump.py
@@ -27,14 +27,15 @@ TYPE = {
'Exit Domain' : 'ExitDomn', 'Master Requery' : 'MstrRqry', \
'Lock Request' : 'LockRqst', 'Recovery Data Done' : 'RecoData', \
'Begin Recovery' : 'BegnReco', 'Finalize Recovery' : 'FinzReco', \
-'FS Vote' : 'FSVoteXX', 'FS Response' : 'FSRespns', \
-'Unknown' : 'UnknownX'
+'FS Vote' : 'FSVoteXX', 'FS Response' : 'FSRespns', \
+'Query Region' : 'QryRegXX', 'Query Node Info' : 'QryNodeF', \
+'Unknown' : 'UnknownX',
}
TYPE_ABB = ('MSRT', 'MSG1', 'ASRT', 'CRLK', 'CNLK', 'PROX', \
'UNLK', 'MSG2', 'DREF', 'MIRQ', 'MIGR', 'QRYJ', \
'ASRJ', 'CANJ', 'EXTD', 'MSRY', 'LKRT', 'REDD', \
- 'REBG', 'REFN')
+ 'REBG', 'REFN', 'QRGN', 'QRNI')
NAME_IN_SHORT = lambda x, y: y in x.keys() and x[y] or 'None'
@@ -54,12 +55,12 @@ def getEthHeader(msg, fmtstr=FRAME_FMT + TIME_FMT + IP_FMT):
try:
frame_str, time_str, ip_str = [m.strip() for m in msg \
- if m.startswith('Frame') \
- or m.strip().startswith('Arrival Time') \
+ if m.startswith('Frame') \
+ or m.strip().startswith('Arrival Time') \
or m.startswith('Internet Protocol')]
except ValueError:
raise("Ethernet header")
-
+
m = re.match(FRAME_REGEX, frame_str)
frame = m and m.group(1) or ''
@@ -73,7 +74,7 @@ def getEthHeader(msg, fmtstr=FRAME_FMT + TIME_FMT + IP_FMT):
ethstr = fmtstr % (frame, t[1], t[2], t[0], atime[0][3], ip[0], ip[1])
except ValueError:
ethstr = ''
-
+
return ethstr
MAGIC_FMT = '%s '
@@ -95,7 +96,7 @@ def getOCFS2Header(msg, fmtstr=MAGIC_FMT + TYPE_FMT + SYS_FMT + STATUS_FMT + KEY
try:
magic_str, type_str, sys_str, status_str, key_str = [m.strip() for m in msg \
- if m.strip().startswith('Magic') \
+ if m.strip().startswith('Magic') \
or m.strip().startswith('Type') \
or m.strip().startswith('Sys Status') \
or m.strip().startswith('Status') \
@@ -325,7 +326,7 @@ def ProxyASTMsg(odict, fmtstr=COOKIE_FMT + FLAGS_FMT + \
ast = odict['AST Type'][0].split('(')[0].strip()
else:
ast = ' '
-
+
if odict.has_key('Blocked'):
blktype = odict['Blocked'][0].split('(')[0].strip()
else:
@@ -358,7 +359,7 @@ def QueryJoinMsg(odict, fmtstr=NODEIDX_FMT + DOMAIN_FMT):
def ExitDomainMsg(odict, fmtstr=NODEIDX_FMT):
''' returns node_idx '''
-
+
if odict.has_key('Node'):
nodeidx = odict['Node'][0].strip()
else:
@@ -554,7 +555,7 @@ def DerefLockresMsg(odict, fmtstr=NODEIDX_FMT + NAME_FMT):
str = fmtstr % (nodeidx, name)
return str
-
+
def FinalizeRecoveryMsg(odict, fmtstr=NODEIDX_FMT + DNODE_FMT + FLAGS_FMT):
''' node_idx; dead_node; flags '''
if odict.has_key('Node'):
@@ -576,6 +577,95 @@ def FinalizeRecoveryMsg(odict, fmtstr=NODEIDX_FMT + DNODE_FMT + FLAGS_FMT):
return str
+NUM_REGIONS_FMT='Total(%s) '
+REGIONS_FMT='<%s> '
+def QueryRegionMsg(odict, fmtstr=NODEIDX_FMT + NUM_REGIONS_FMT + DOMAIN_FMT + REGIONS_FMT):
+ '''Node: 92
+ Num Regions: 2
+ Domain Namelen: 32
+ Domain Name: CB637503B1A746DEB3D63656E16FA41B
+ Region1: 77D95EF51C0149D2823674FCC162CF8B
+ Region2: DCDA2845177F4D59A0F2DCD8DE507CC3
+ '''
+
+ if odict.has_key('Node'):
+ nodeidx = odict['Node'][0].strip()
+ else:
+ nodeidx = ' '
+
+ if odict.has_key('Num Regions'):
+ num_regions = odict['Num Regions'][0].strip()
+ else:
+ num_regions = ' '
+
+ if odict.has_key('Domain Name'):
+ domain = odict['Domain Name'][0].strip()
+ else:
+ domain = ' '
+
+ regions = ''
+ for i in xrange(1, int(num_regions) + 1):
+ region_index = "Region%d" % i
+ if odict.has_key(region_index):
+ regions += '[' + (':'.join([l.strip() for l in odict[region_index]])) + ']'
+ if i < int(num_regions):
+ #FIXME! add two blank spaces or just one?
+ regions += ' '
+ else:
+ break
+ else:
+ regions += "Oops! %s regions expected but only %d captured" % (num_regions, i - 1)
+
+ str = fmtstr % (nodeidx, num_regions, domain, regions)
+ return str
+
+NUM_NODES_FMT='Total(%s) '
+NODES_FMT='<%s> '
+def QueryNodeInfoMsg(odict, fmtstr=NODEIDX_FMT + NUM_NODES_FMT + DOMAIN_FMT + NODES_FMT):
+ '''
+ Node: 92
+ Num Nodes: 100
+ Domain Namelen: 32
+ Domain Name: CB637503B1A746DEB3D63656E16FA41B
+ Node1: 10.196.73.1:7777
+ Node2: 10.196.73.2:7777
+ Node3: 10.196.73.3:7777
+ ...
+ ..
+ Node100: 10.196.73.100:7777
+ '''
+
+ if odict.has_key('Node'):
+ nodeidx = odict['Node'][0].strip()
+ else:
+ nodeidx = ' '
+
+ if odict.has_key('Num Nodes'):
+ num_nodes = odict['Num Nodes'][0].strip()
+ else:
+ num_nodes = ' '
+
+ if odict.has_key('Domain Name'):
+ domain = odict['Domain Name'][0].strip()
+ else:
+ domain = ' '
+
+ nodes = ''
+ for i in xrange(1, int(num_nodes) + 1):
+ node_index = "Node%d" % i
+ if odict.has_key(node_index):
+ nodes += '[' + (':'.join([l.strip() for l in odict[node_index]])) + ']'
+ if i < int(num_nodes):
+ #FIXME! add two blank spaces or just one?
+ nodes += ' '
+ else:
+ break
+ else:
+ nodes += "Oops! %s regions expected but only %d captured" % (num_nodes, i - 1)
+
+ str = fmtstr % (nodeidx, num_nodes, domain, nodes)
+ return str
+
def Unused2Msg(odict, fmtstr=' '):
return 'Unused2 Message'
@@ -592,8 +682,8 @@ def option_parse():
''' options parser '''
usage_str = 'Usage: %prog [-f <tcpdump capture file>] [-o <outfile>] [-t <type>] [-v] \n' \
- ' or: cat ocfs2_log_file | %prog [-t <type>] [-v] >> file \n' \
- 'Parse standard input to FILE, and also to standard output. \n' \
+ ' or: cat ocfs2_log_file | %prog [-t <type>] [-v] >> file \n' \
+ 'Parse standard input to FILE, and also to standard output. \n' \
'message type present, only the specified kind of o2net message will be parsing.\n\n' \
'Type: \n ' \
+ '\n '.join([value + ' => ' + key for key, value in TYPE.items()])
@@ -606,13 +696,13 @@ def option_parse():
default=None,
)
- p.add_option('-o', '--output',
+ p.add_option('-o', '--output',
dest='output',
help="Output file (defaults to stdout)",
default=None,
)
- p.add_option('-t', '--type',
+ p.add_option('-t', '--type',
dest='type',
help="O2NET message type (defaults to all message types)",
default="all",
@@ -624,7 +714,7 @@ def option_parse():
default=False,
action='store_true',
)
-
+
options, args = p.parse_args()
return options.file, options.output, options.type, options.verbose
@@ -652,13 +742,13 @@ def getfh(srcfile, dstfile):
def main(srcfile, dstfile, o2type, verbose):
packets = []
- while True:
+ while True:
line = sfp.readline()
# EOF
if not line and not packets:
break
- # append list until new line
+ # append list until new line
if line and line != '\n':
packets.append(line)
continue
@@ -670,7 +760,7 @@ def main(srcfile, dstfile, o2type, verbose):
is_valid = 1
break
i = i + 1
-
+
# skip this packet if no "ocfs2" found
if is_valid == 0:
ethstr = getEthHeader(packets)
@@ -684,7 +774,7 @@ def main(srcfile, dstfile, o2type, verbose):
ethstr = getEthHeader(ethmsg)
- # parsing ocfs2
+ # parsing ocfs2
ocfs2dict = getOCFS2Header(ocfs2msg)
try:
magic, type = ocfs2dict['magic'], ocfs2dict['type']
@@ -727,6 +817,7 @@ def main(srcfile, dstfile, o2type, verbose):
o2header = ocfs2dict['o2header']
except KeyError:
o2header = ' '
+
msgstr = ''.join([ethstr, o2header, o2msgstr, '\n'])
if verbose: print msgstr
@@ -744,5 +835,5 @@ if __name__ == '__main__':
srcfile, dstfile, o2msgtype, verbose = option_parse()
sfp, dfp = getfh(srcfile, dstfile)
-
+
main(sfp, dfp, o2msgtype, verbose)
--
1.5.4.3
More information about the Ocfs2-tools-devel
mailing list