cifs-utils: smbinfo: add gettconinfo command
Subsystems (2)
PATCH 1/1 cifs-utils: smbinfo: add gettconinfo command
As a follow up on the patch on Linux: de4eceab578e ("smb3: allow dumping session and tcon id to improve stats analysis and debugging") [1]
Add gettconinfo command to dump both the TCON Id and Session Id of a given SMB mount; to help with correlation in cases when multiple mounts are to the same share.
Example run:
``` ./smbinfo gettconinfo /mnt/smb_share TCON Id: 0x1 Session Id: 0xa40000000001 ```
[1] https://github.com/torvalds/linux/commit/de4eceab578ead12a71e5b5588a57e142bbe8ceb
--- smbinfo | 29 +++++++++++++++++++++++++++++ smbinfo.rst | 2 ++ 2 files changed, 31 insertions(+)
smbinfo +29 -0
@@ -35,6 +35,7 @@ CIFS_QUERY_INFO = 0xc018cf07 CIFS_ENUMERATE_SNAPSHOTS = 0x800ccf06 CIFS_DUMP_KEY = 0xc03acf08 CIFS_DUMP_FULL_KEY = 0xc011cf0a +CIFS_GET_TCON_INFO = 0x800ccf0c # large enough input buffer length INPUT_BUFFER_LENGTH = 16384
@@ -289,6 +290,10 @@ def main(): sap.add_argument("file") sap.set_defaults(func=cmd_keys) + sap = subp.add_parser("gettconinfo", help="Prints TCON Id and Session Id for a cifs file") + sap.add_argument("file") + sap.set_defaults(func=cmd_gettconinfo) + # parse arguments args = ap.parse_args()
@@ -876,5 +881,29 @@ def cmd_keys(args): print("ServerIn Key: %s"%bytes_to_hex(kd.server_in_key)) print("ServerOut key: %s"%bytes_to_hex(kd.server_out_key)) +class SmbMntTconInfoStruct: + def __init__(self): + self.tid = 0 + self.session_id = 0 + + def ioctl(self, fd): + buf = bytearray() + buf.extend(struct.pack("=IQ", self.tid, self.session_id)) + fcntl.ioctl(fd, CIFS_GET_TCON_INFO, buf, True) + (self.tid, self.session_id) = struct.unpack_from('=IQ', buf, 0) + +def cmd_gettconinfo(args): + fd = os.open(args.file, os.O_RDONLY) + tcon = SmbMntTconInfoStruct() + + try: + tcon.ioctl(fd) + except Exception as e: + print("syscall failed: %s"%e) + return False + + print("TCON Id: 0x%x"%tcon.tid) + print("Session Id: 0x%x"%tcon.session_id) + if __name__ == '__main__': main()
smbinfo.rst +2 -0
@@ -96,6 +96,8 @@ COMMAND the SMB3 traffic of this mount can be decryped e.g. via wireshark (requires root). +`gettconinfo`: Prints both the TCON Id and Session Id for a cifs file. + ***** NOTES *****
Signature · 1 line
2.34.1
Pavel,
looks good - I checked it out and tested it. It can be helpful in debugging server logs to have this information (about the tree id and session id for a particular mount)
Can add my Tested-by and or Reviewed-by if you want
Quoted 96 lines · Anthony Nandaa
As a follow up on the patch on Linux:
de4eceab578e("smb3: allow dumping session and tcon id to improve stats analysis and debugging") [1]Add
gettconinfocommand to dump both the TCON Id and Session Id of a given SMB mount; to help with correlation in cases when multiple mounts are to the same share.Example run:
``` ./smbinfo gettconinfo /mnt/smb_share TCON Id: 0x1 Session Id: 0xa40000000001 ```[1] https://github.com/torvalds/linux/commit/de4eceab578ead12a71e5b5588a57e142bbe8ceb
Cc Pavel Shilovsky <[email protected]>Cc Steve French <[email protected]>Signed-off-by Anthony Nandaa <[email protected]>--- smbinfo | 29 +++++++++++++++++++++++++++++ smbinfo.rst | 2 ++ 2 files changed, 31 insertions(+)smbinfo +29
-0@@ -35,6 +35,7 @@ CIFS_QUERY_INFO = 0xc018cf07 CIFS_ENUMERATE_SNAPSHOTS = 0x800ccf06 CIFS_DUMP_KEY = 0xc03acf08 CIFS_DUMP_FULL_KEY = 0xc011cf0a +CIFS_GET_TCON_INFO = 0x800ccf0c # large enough input buffer length INPUT_BUFFER_LENGTH = 16384@@ -289,6 +290,10 @@ def main(): sap.add_argument("file") sap.set_defaults(func=cmd_keys) + sap = subp.add_parser("gettconinfo", help="Prints TCON Id and Session Id for a cifs file") + sap.add_argument("file") + sap.set_defaults(func=cmd_gettconinfo) + # parse arguments args = ap.parse_args()@@ -876,5 +881,29 @@ def cmd_keys(args): print("ServerIn Key: %s"%bytes_to_hex(kd.server_in_key)) print("ServerOut key: %s"%bytes_to_hex(kd.server_out_key)) +class SmbMntTconInfoStruct: + def __init__(self): + self.tid = 0 + self.session_id = 0 + + def ioctl(self, fd): + buf = bytearray() + buf.extend(struct.pack("=IQ", self.tid, self.session_id)) + fcntl.ioctl(fd, CIFS_GET_TCON_INFO, buf, True) + (self.tid, self.session_id) = struct.unpack_from('=IQ', buf, 0) + +def cmd_gettconinfo(args): + fd = os.open(args.file, os.O_RDONLY) + tcon = SmbMntTconInfoStruct() + + try: + tcon.ioctl(fd) + except Exception as e: + print("syscall failed: %s"%e) + return False + + print("TCON Id: 0x%x"%tcon.tid) + print("Session Id: 0x%x"%tcon.session_id) + if __name__ == '__main__': main()smbinfo.rst +2
-1@@ -96,6 +96,8 @@ COMMAND the SMB3 traffic of this mount can be decryped e.g. via wireshark (requires root). +`gettconinfo`: Prints both the TCON Id and Session Id for a cifs file. + ***** NOTES ***** --2.34.1
Signature · 3 lines
Thanks, Steve