Message ID | 20240705204352.975013-1-profnandaa@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | cifs-utils: smbinfo: add gettconinfo command | expand |
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 On Fri, Jul 5, 2024 at 3:44 PM Anthony Nandaa <profnandaa@gmail.com> wrote: > > 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 > > Cc: Pavel Shilovsky <pshilovsky@samba.org> > Cc: Steve French <stfrench@microsoft.com> > Signed-off-by: Anthony Nandaa <profnandaa@gmail.com> > --- > smbinfo | 29 +++++++++++++++++++++++++++++ > smbinfo.rst | 2 ++ > 2 files changed, 31 insertions(+) > > diff --git a/smbinfo b/smbinfo > index 73c5bb3..3467b0b 100755 > --- a/smbinfo > +++ b/smbinfo > @@ -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() > diff --git a/smbinfo.rst b/smbinfo.rst > index 1acf3c4..17270c5 100644 > --- a/smbinfo.rst > +++ b/smbinfo.rst > @@ -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 > >
diff --git a/smbinfo b/smbinfo index 73c5bb3..3467b0b 100755 --- a/smbinfo +++ b/smbinfo @@ -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() diff --git a/smbinfo.rst b/smbinfo.rst index 1acf3c4..17270c5 100644 --- a/smbinfo.rst +++ b/smbinfo.rst @@ -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 *****
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 Cc: Pavel Shilovsky <pshilovsky@samba.org> Cc: Steve French <stfrench@microsoft.com> Signed-off-by: Anthony Nandaa <profnandaa@gmail.com> --- smbinfo | 29 +++++++++++++++++++++++++++++ smbinfo.rst | 2 ++ 2 files changed, 31 insertions(+)