Skip to content

Commit

Permalink
Fix generation of match keys for response MADs
Browse files Browse the repository at this point in the history
The spec is actually pretty clear here, it should be the mgmtClass and
TID.

There is still a bit of a mess here, for umad we can only check the lower
32 bits of the TID, since the upper are not known, while for vmad we need
to check all the bits.
  • Loading branch information
jgunthorpe committed Aug 28, 2014
1 parent 2e5d049 commit f45054a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
34 changes: 17 additions & 17 deletions rdma/madtransactor.py
Expand Up @@ -112,24 +112,24 @@ def _get_new_TID(self):

@staticmethod
def _get_match_key(buf):
"""Return a tuple that represents the 'key' for MAD buf.
If two keys match then they are the same transaction."""
# baseVersion,mgmtClass,classVersion method transactionID[31:0],attributeID
"""Return an integer that represents the 'key' for MAD buf.
If two keys match then they are the same transaction.
The result is mgmtClass || transactionID[31:0], see
C13-19.1.1"""
# FIXME: vmad needs to test all 64 bits.
if isinstance(buf,bytearray):
return (bytes(buf[0:2]),buf[3],bytes(buf[12:18]));
return (buf[0:2],ord(buf[3]),buf[12:18]);

@staticmethod
def _get_reply_match_key(buf):
"""Return a tuple that represents the 'key' for response to MAD buf.
If two keys match then they are the same transaction."""
# baseVersion,mgmtClass,classVersion method transactionID[31:0],attributeID
x = MADTransactor._get_match_key(buf)
# Hmmm, I wonder if this should live someplace else?
if x[1] == IBA.MAD_METHOD_SET:
return (x[0],IBA.MAD_METHOD_GET_RESP,x[2]);
else:
return (x[0],x[1] | IBA.MAD_METHOD_RESPONSE,x[2]);
return ((buf[1] << 32) |
(buf[12] << 24) |
(buf[13] << 16) |
(buf[14] << 8) |
(buf[15] << 0));
return ((ord(buf[1]) << 32) |
(ord(buf[12]) << 24) |
(ord(buf[13]) << 16) |
(ord(buf[14]) << 8) |
(ord(buf[15]) << 0));

_get_reply_match_key = _get_match_key;

@staticmethod
def get_request_match_key(buf):
Expand Down
10 changes: 8 additions & 2 deletions rdma/umad.py
Expand Up @@ -295,8 +295,14 @@ def _gen_error(self,buf,path):
MAD. I consider this to be a bug in the kernel, but we fix it here
by constructing an error MAD."""
buf = copy.copy(buf);
rmatch = self._get_reply_match_key(buf);
buf[3] = rmatch[1];

meth = buf[3];
if meth == IBA.MAD_METHOD_SET:
meth = IBA.MAD_METHOD_GET_RESP;
else:
meth = meth | IBA.MAD_METHOD_RESPONSE;
buf[3] = meth;

buf[4] = 0;
buf[5] = IBA.MAD_STATUS_INVALID_ATTR_OR_MODIFIER; # Guessing.
path = path.copy();
Expand Down

0 comments on commit f45054a

Please sign in to comment.