s3-messages: only include messages.h where needed.
[samba.git] / source3 / profile / profile.c
index fe03bc04a390bd0cd9484cb62d43d1dd178a132a..f081e1bbd7855c93f035a54e5119968f85b87696 100644 (file)
@@ -6,7 +6,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 
 #include "includes.h"
+#include "librpc/gen_ndr/messaging.h"
+#include "messages.h"
 
 #ifdef WITH_PROFILE
 #define IPC_PERMS ((S_IRUSR | S_IWUSR) | S_IRGRP | S_IROTH)
 
 #ifdef WITH_PROFILE
 static int shm_id;
-static BOOL read_only;
-#if defined(HAVE_CLOCK_GETTIME)
-clockid_t __profile_clock;
-BOOL have_profiling_clock = False;
-#endif
+static bool read_only;
 #endif
 
 struct profile_header *profile_h;
 struct profile_stats *profile_p;
 
-BOOL do_profile_flag = False;
-BOOL do_profile_times = False;
+bool do_profile_flag = False;
+bool do_profile_times = False;
 
 /****************************************************************************
-receive a set profile level message
+Set a profiling level.
 ****************************************************************************/
-void profile_message(int msg_type, struct process_id src, void *buf, size_t len)
+void set_profile_level(int level, struct server_id src)
 {
-        int level;
-
-       memcpy(&level, buf, sizeof(int));
 #ifdef WITH_PROFILE
        switch (level) {
        case 0:         /* turn off profiling */
@@ -64,19 +58,6 @@ void profile_message(int msg_type, struct process_id src, void *buf, size_t len)
                         (int)procid_to_pid(&src)));
                break;
        case 2:         /* turn on complete profiling */
-
-#if defined(HAVE_CLOCK_GETTIME)
-               if (!have_profiling_clock) {
-                       do_profile_flag = True;
-                       do_profile_times = False;
-                       DEBUG(1,("INFO: Profiling counts turned ON from "
-                               "pid %d\n", (int)procid_to_pid(&src)));
-                       DEBUGADD(1,("INFO: Profiling times disabled "
-                               "due to lack of a suitable clock\n"));
-                       break;
-               }
-#endif
-
                do_profile_flag = True;
                do_profile_times = True;
                DEBUG(1,("INFO: Full profiling turned ON from pid %d\n",
@@ -93,11 +74,36 @@ void profile_message(int msg_type, struct process_id src, void *buf, size_t len)
 #endif /* WITH_PROFILE */
 }
 
+#ifdef WITH_PROFILE
+
+/****************************************************************************
+receive a set profile level message
+****************************************************************************/
+static void profile_message(struct messaging_context *msg_ctx,
+                           void *private_data,
+                           uint32_t msg_type,
+                           struct server_id src,
+                           DATA_BLOB *data)
+{
+        int level;
+
+       if (data->length != sizeof(level)) {
+               DEBUG(0, ("got invalid profile message\n"));
+               return;
+       }
+
+       memcpy(&level, data->data, sizeof(level));
+       set_profile_level(level, src);
+}
+
 /****************************************************************************
 receive a request profile level message
 ****************************************************************************/
-void reqprofile_message(int msg_type, struct process_id src,
-                       void *buf, size_t len)
+static void reqprofile_message(struct messaging_context *msg_ctx,
+                              void *private_data, 
+                              uint32_t msg_type, 
+                              struct server_id src,
+                              DATA_BLOB *data)
 {
         int level;
 
@@ -108,83 +114,19 @@ void reqprofile_message(int msg_type, struct process_id src,
 #endif
        DEBUG(1,("INFO: Received REQ_PROFILELEVEL message from PID %u\n",
                 (unsigned int)procid_to_pid(&src)));
-       message_send_pid(src, MSG_PROFILELEVEL, &level, sizeof(int), True);
+       messaging_send_buf(msg_ctx, src, MSG_PROFILELEVEL,
+                          (uint8 *)&level, sizeof(level));
 }
 
 /*******************************************************************
   open the profiling shared memory area
   ******************************************************************/
-#ifdef WITH_PROFILE
-
-#ifdef HAVE_CLOCK_GETTIME
-
-/* Find a clock. Just because the definition for a particular clock ID is
- * present doesn't mean the system actually supports it.
- */
-static void init_clock_gettime(void)
-{
-       struct timespec ts;
-
-       have_profiling_clock = False;
-
-#ifdef HAVE_CLOCK_PROCESS_CPUTIME_ID
-       /* CLOCK_PROCESS_CPUTIME_ID is sufficiently fast that the
-        * always profiling times is plausible. Unfortunately on Linux
-        * it is only accurate if we can guarantee we will not be scheduled
-        * scheduled onto a different CPU between samples. Until there is
-        * some way to set processor affinity, we can only use this on
-        * uniprocessors.
-        */
-       if (!this_is_smp()) {
-           if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == 0) {
-                   DEBUG(10, ("Using CLOCK_PROCESS_CPUTIME_ID "
-                               "for profile_clock\n"));
-                   __profile_clock = CLOCK_PROCESS_CPUTIME_ID;
-                   have_profiling_clock = True;
-           }
-       }
-#endif
-
-#ifdef HAVE_CLOCK_MONOTONIC
-       if (!have_profiling_clock &&
-           clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
-               DEBUG(10, ("Using CLOCK_MONOTONIC for profile_clock\n"));
-               __profile_clock = CLOCK_MONOTONIC;
-               have_profiling_clock = True;
-       }
-#endif
-
-#ifdef HAVE_CLOCK_REALTIME
-       /* POSIX says that CLOCK_REALTIME should be defined everywhere
-        * where we have clock_gettime...
-        */
-       if (!have_profiling_clock &&
-           clock_gettime(CLOCK_REALTIME, &ts) == 0) {
-               __profile_clock = CLOCK_REALTIME;
-               have_profiling_clock = True;
-
-               SMB_WARN(__profile_clock != CLOCK_REALTIME,
-                       ("forced to use a slow profiling clock"));
-       }
-
-#endif
-
-       SMB_WARN(have_profiling_clock == True,
-               ("could not find a working clock for profiling"));
-       return;
-}
-#endif
-
-BOOL profile_setup(BOOL rdonly)
+bool profile_setup(struct messaging_context *msg_ctx, bool rdonly)
 {
        struct shmid_ds shm_ds;
 
        read_only = rdonly;
 
-#ifdef HAVE_CLOCK_GETTIME
-       init_clock_gettime();
-#endif
-
  again:
        /* try to use an existing key */
        shm_id = shmget(PROF_SHMEM_KEY, 0, 0);
@@ -206,7 +148,7 @@ BOOL profile_setup(BOOL rdonly)
        
        profile_h = (struct profile_header *)shmat(shm_id, 0, 
                                                   read_only?SHM_RDONLY:0);
-       if ((long)profile_p == -1) {
+       if ((long)profile_h == -1) {
                DEBUG(0,("Can't attach to IPC area. Error was %s\n", 
                         strerror(errno)));
                return False;
@@ -230,7 +172,7 @@ BOOL profile_setup(BOOL rdonly)
 
        if (shm_ds.shm_segsz != sizeof(*profile_h)) {
                DEBUG(0,("WARNING: profile size is %d (expected %d). Deleting\n",
-                        (int)shm_ds.shm_segsz, sizeof(*profile_h)));
+                        (int)shm_ds.shm_segsz, (int)sizeof(*profile_h)));
                if (shmctl(shm_id, IPC_RMID, &shm_ds) == 0) {
                        goto again;
                } else {
@@ -246,8 +188,12 @@ BOOL profile_setup(BOOL rdonly)
        }
 
        profile_p = &profile_h->stats;
-       message_register(MSG_PROFILE, profile_message);
-       message_register(MSG_REQ_PROFILELEVEL, reqprofile_message);
+       if (msg_ctx != NULL) {
+               messaging_register(msg_ctx, NULL, MSG_PROFILE,
+                                  profile_message);
+               messaging_register(msg_ctx, NULL, MSG_REQ_PROFILELEVEL,
+                                  reqprofile_message);
+       }
        return True;
 }
 
@@ -265,6 +211,7 @@ BOOL profile_setup(BOOL rdonly)
            "syscall_rmdir",            /* PR_VALUE_SYSCALL_RMDIR */
            "syscall_closedir",         /* PR_VALUE_SYSCALL_CLOSEDIR */
            "syscall_open",             /* PR_VALUE_SYSCALL_OPEN */
+           "syscall_createfile",       /* PR_VALUE_SYSCALL_CREATEFILE */
            "syscall_close",            /* PR_VALUE_SYSCALL_CLOSE */
            "syscall_read",             /* PR_VALUE_SYSCALL_READ */
            "syscall_pread",            /* PR_VALUE_SYSCALL_PREAD */
@@ -272,7 +219,9 @@ BOOL profile_setup(BOOL rdonly)
            "syscall_pwrite",           /* PR_VALUE_SYSCALL_PWRITE */
            "syscall_lseek",            /* PR_VALUE_SYSCALL_LSEEK */
            "syscall_sendfile",         /* PR_VALUE_SYSCALL_SENDFILE */
+           "syscall_recvfile",         /* PR_VALUE_SYSCALL_RECVFILE */
            "syscall_rename",           /* PR_VALUE_SYSCALL_RENAME */
+           "syscall_rename_at",        /* PR_VALUE_SYSCALL_RENAME_AT */
            "syscall_fsync",            /* PR_VALUE_SYSCALL_FSYNC */
            "syscall_stat",             /* PR_VALUE_SYSCALL_STAT */
            "syscall_fstat",            /* PR_VALUE_SYSCALL_FSTAT */
@@ -284,10 +233,12 @@ BOOL profile_setup(BOOL rdonly)
            "syscall_fchown",           /* PR_VALUE_SYSCALL_FCHOWN */
            "syscall_chdir",            /* PR_VALUE_SYSCALL_CHDIR */
            "syscall_getwd",            /* PR_VALUE_SYSCALL_GETWD */
-           "syscall_utime",            /* PR_VALUE_SYSCALL_UTIME */
+           "syscall_ntimes",           /* PR_VALUE_SYSCALL_NTIMES */
            "syscall_ftruncate",        /* PR_VALUE_SYSCALL_FTRUNCATE */
+           "syscall_fallocate",        /* PR_VALUE_SYSCALL_FALLOCATE */
            "syscall_fcntl_lock",       /* PR_VALUE_SYSCALL_FCNTL_LOCK */
            "syscall_kernel_flock",     /* PR_VALUE_SYSCALL_KERNEL_FLOCK */
+           "syscall_linux_setlease",   /* PR_VALUE_SYSCALL_LINUX_SETLEASE */
            "syscall_fcntl_getlock",    /* PR_VALUE_SYSCALL_FCNTL_GETLOCK */
            "syscall_readlink",         /* PR_VALUE_SYSCALL_READLINK */
            "syscall_symlink",          /* PR_VALUE_SYSCALL_SYMLINK */
@@ -296,6 +247,11 @@ BOOL profile_setup(BOOL rdonly)
            "syscall_realpath",         /* PR_VALUE_SYSCALL_REALPATH */
            "syscall_get_quota",        /* PR_VALUE_SYSCALL_GET_QUOTA */
            "syscall_set_quota",        /* PR_VALUE_SYSCALL_SET_QUOTA */
+           "syscall_get_sd",           /* PR_VALUE_SYSCALL_GET_SD */
+           "syscall_set_sd",           /* PR_VALUE_SYSCALL_SET_SD */
+           "syscall_brl_lock",         /* PR_VALUE_SYSCALL_BRL_LOCK */
+           "syscall_brl_unlock",       /* PR_VALUE_SYSCALL_BRL_UNLOCK */
+           "syscall_brl_cancel",       /* PR_VALUE_SYSCALL_BRL_CANCEL */
            "SMBmkdir",         /* PR_VALUE_SMBMKDIR */
            "SMBrmdir",         /* PR_VALUE_SMBRMDIR */
            "SMBopen",          /* PR_VALUE_SMBOPEN */
@@ -399,7 +355,6 @@ BOOL profile_setup(BOOL rdonly)
            "NT_transact_set_user_quota",/* PR_VALUE_NT_TRANSACT_SET_USER_QUOTA */
            "get_nt_acl",               /* PR_VALUE_GET_NT_ACL */
            "fget_nt_acl",              /* PR_VALUE_FGET_NT_ACL */
-           "set_nt_acl",               /* PR_VALUE_SET_NT_ACL */
            "fset_nt_acl",              /* PR_VALUE_FSET_NT_ACL */
            "chmod_acl",                /* PR_VALUE_CHMOD_ACL */
            "fchmod_acl",               /* PR_VALUE_FCHMOD_ACL */
@@ -421,6 +376,25 @@ BOOL profile_setup(BOOL rdonly)
            "sync_browse_lists",        /* PR_VALUE_SYNC_BROWSE_LISTS */
            "run_elections",            /* PR_VALUE_RUN_ELECTIONS */
            "election",                 /* PR_VALUE_ELECTION */
+           "smb2_negprot",             /* PR_VALUE_SMB2_NEGPROT */
+           "smb2_sesssetup",           /* PR_VALUE_SMB2_SESSETUP */
+           "smb2_logoff",              /* PR_VALUE_SMB2_LOGOFF */
+           "smb2_tcon",                /* PR_VALUE_SMB2_TCON */
+           "smb2_tdis",                /* PR_VALUE_SMB2_TDIS */
+           "smb2_create",              /* PR_VALUE_SMB2_CREATE */
+           "smb2_close",               /* PR_VALUE_SMB2_CLOSE */
+           "smb2_flush",               /* PR_VALUE_SMB2_FLUSH */
+           "smb2_read",                /* PR_VALUE_SMB2_READ */
+           "smb2_write",               /* PR_VALUE_SMB2_WRITE */
+           "smb2_lock",                /* PR_VALUE_SMB2_LOCK */
+           "smb2_ioctl",               /* PR_VALUE_SMB2_IOCTL */
+           "smb2_cancel",              /* PR_VALUE_SMB2_CANCEL */
+           "smb2_keepalive",           /* PR_VALUE_SMB2_KEEPALIVE */
+           "smb2_find",                /* PR_VALUE_SMB2_FIND */
+           "smb2_notify",              /* PR_VALUE_SMB2_NOTIFY */
+           "smb2_getinfo",             /* PR_VALUE_SMB2_GETINFO */
+           "smb2_setinfo"              /* PR_VALUE_SMB2_SETINFO */
+           "smb2_break",               /* PR_VALUE_SMB2_BREAK */
            "" /* PR_VALUE_MAX */
        };