]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: init per-share profile counters
authorShachar Sharon <ssharon@redhat.com>
Mon, 28 Apr 2025 12:11:06 +0000 (15:11 +0300)
committerAnoop C S <anoopcs@samba.org>
Mon, 23 Jun 2025 13:04:31 +0000 (13:04 +0000)
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 <ssharon@redhat.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/smbd/smb2_service.c

index 7d2418873997ae49c36de43ec394bc65fb156637..c9daae2aa1c3bc45c84fe445819bff1e432a8368 100644 (file)
@@ -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))  {