From 904577f90ef4cc75ec24c5ced86082adc87a91bc Mon Sep 17 00:00:00 2001 From: Shachar Sharon Date: Mon, 28 Apr 2025 15:11:06 +0300 Subject: [PATCH] smbd: init per-share profile counters When per-share profile counters are enabled, setup/teardown the profiling entry for specific 'snum' before/after VFS connect/disconnect. Signed-off-by: Shachar Sharon Reviewed-by: Volker Lendecke Reviewed-by: Anoop C S --- source3/smbd/smb2_service.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source3/smbd/smb2_service.c b/source3/smbd/smb2_service.c index 7d241887399..c9daae2aa1c 100644 --- a/source3/smbd/smb2_service.c +++ b/source3/smbd/smb2_service.c @@ -493,6 +493,7 @@ NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn, fstring dev; int ret; bool on_err_call_dis_hook = false; + bool on_err_call_profile_unref = false; uid_t effuid; gid_t effgid; NTSTATUS status; @@ -615,6 +616,14 @@ NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn, goto err_root_exit; } + /* Initialize per-share profiling */ + if (lp_smbd_profiling_share(snum)) { + smbprofile_persvc_mkref(snum, + lp_const_servicename(snum), + sconn->remote_hostname); + on_err_call_profile_unref = true; + } + /* ROOT Activities: */ /* explicitly check widelinks here so that we can correctly warn * in the logs. */ @@ -860,6 +869,9 @@ NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn, /* Call VFS disconnect hook */ SMB_VFS_DISCONNECT(conn); } + if (on_err_call_profile_unref) { + smbprofile_persvc_unref(snum); + } return status; } @@ -926,6 +938,11 @@ void close_cnum(connection_struct *conn, /* Call VFS disconnect hook */ SMB_VFS_DISCONNECT(conn); + /* Cleanup per-share profiling */ + if (lp_smbd_profiling_share(SNUM(conn))) { + smbprofile_persvc_unref(SNUM(conn)); + } + /* execute any "postexec = " line */ if (*lp_postexec(talloc_tos(), lp_sub, SNUM(conn)) && change_to_user_and_service(conn, vuid)) { -- 2.47.2