s3: added per-client statistics to onefs perfcount module
authorScott Urban <scott.urban@isilon.com>
Sat, 28 Mar 2009 00:33:26 +0000 (17:33 -0700)
committerSteven Danneman <steven.danneman@isilon.com>
Sat, 28 Mar 2009 00:33:26 +0000 (17:33 -0700)
* we now track, uid, remote ip, and local ip per CIFS operation
* removed perfcount_set_client() from perfcount interface as it's
  unecessary

source3/include/smb_perfcount.h
source3/modules/perfcount_onefs.c
source3/modules/perfcount_test.c

index 01a539d508c2db84286041818251965c143ad955..9c83147d04204e081e5e3454890c98c5be4fade7 100644 (file)
@@ -37,8 +37,6 @@ struct smb_perfcount_handlers {
                                         uint64_t in_bytes);
        void (*perfcount_set_msglen_out) (struct smb_perfcount_data *pcd,
                                          uint64_t out_bytes);
-       void (*perfcount_set_client) (struct smb_perfcount_data *pcd, uid_t uid,
-                                     const char *user, const char *domain);
        void (*perfcount_copy_context) (struct smb_perfcount_data *pcd,
                                        struct smb_perfcount_data *new_pcd);
        void (*perfcount_defer_op) (struct smb_perfcount_data *pcd,
@@ -88,12 +86,6 @@ void smb_init_perfcount_data(struct smb_perfcount_data *pcd);
            (_pcd_)->handlers->perfcount_set_msglen_out((_pcd_), (_out_));\
     } while (0)
 
-#define SMB_PERFCOUNT_SET_CLIENT(_pcd_,_uid_, _user_, _domain_) \
-    do {if((_pcd_) && (_pcd_)->handlers) \
-           (_pcd_)->handlers->perfcount_set_client((_pcd_), (_uid_), \
-              (_user_), (_domain_)); \
-    } while (0)
-
 #define SMB_PERFCOUNT_COPY_CONTEXT(_pcd_, _new_pcd_) \
     do {if((_pcd_) && (_pcd_)->handlers) \
            (_pcd_)->handlers->perfcount_copy_context((_pcd_), (_new_pcd_)); \
index 9b35af699a665ecfcfbbf74d74d09e25ab6a3b08..066a7f1fe4458ee58404304e9493d3369814df3a 100644 (file)
 
 #include "includes.h"
 #include <sys/isi_stats_protocol.h>
+#include <sys/isi_stats_client.h>
 #include <sys/isi_stats_cifs.h>
 
+extern struct current_user current_user;
+
 struct onefs_op_counter {
        struct isp_op_delta iod;
        struct onefs_op_counter *next;
@@ -282,42 +285,64 @@ static void onefs_smb_statistics_defer_op(struct smb_perfcount_data *pcd,
                pcd->context = NULL;
 }
 
-static void onefs_smb_statistics_set_client(struct smb_perfcount_data *pcd,
-                                           uid_t uid, const char *user,
-                                           const char *domain)
-{
-       // not implemented...
-       return;
-}
-
 static void onefs_smb_statistics_end(struct smb_perfcount_data *pcd)
 {
        struct onefs_stats_context *ctxt = pcd->context;
        struct onefs_op_counter *tmp;
+       uint64_t uid;
+
+       static in_addr_t rem_addr = 0;
+       static in_addr_t loc_addr = 0;
 
         /* not enabled */
         if (pcd->context == NULL)
                 return;
 
+       uid = current_user.ut.uid ? current_user.ut.uid : ISC_UNKNOWN_CLIENT_ID;
+
+       /* get address info once, doesn't change for process */
+       if (rem_addr == 0) {
+               struct sockaddr_storage sa;
+               socklen_t sa_len;
+               int fd = smbd_server_fd();
+
+               sa_len = sizeof sa;
+               if (getpeername(fd, (struct sockaddr *)&sa, &sa_len) == 0 && 
+                   sa.ss_family == AF_INET)
+                       rem_addr = ((struct sockaddr_in *)&sa)->sin_addr.s_addr;
+               else
+                       rem_addr = ISC_MASKED_ADDR;
+
+               sa_len = sizeof sa;
+               if (getsockname(fd, (struct sockaddr *)&sa, &sa_len) == 0 &&
+                   sa.ss_family == AF_INET)
+                       loc_addr = ((struct sockaddr_in *)&sa)->sin_addr.s_addr;
+               else
+                       loc_addr = ISC_MASKED_ADDR;
+       }
+
        /*
         * bug here - we aren't getting the outlens right,
         * when dealing w/ chained requests.
         */
        for (tmp = ctxt->ops_chain; tmp; tmp = tmp->next) {
                tmp->iod.out_bytes = ctxt->iod.out_bytes;
+               isc_cookie_init(&tmp->iod.cookie, rem_addr, loc_addr, uid);
                ISP_OP_END(&tmp->iod);
 #ifdef ONEFS_PERF_DEBUG
-               DEBUG(0,("********  Finalized CHAIN op %s in:%llu, out:%llu\n",
-                       onefs_stat_debug(&tmp->iod),
+               DEBUG(0,("********  Finalized CHAIN op %s uid %llu in:%llu"
+                       ", out:%llu\n",
+                       onefs_stat_debug(&tmp->iod), uid,
                        tmp->iod.in_bytes, tmp->iod.out_bytes));
 #endif
                SAFE_FREE(tmp->prev);
        }
 
-        ISP_OP_END(&ctxt->iod);
+       isc_cookie_init(&ctxt->iod.cookie, rem_addr, loc_addr, uid);
+       ISP_OP_END(&ctxt->iod);
 #ifdef ONEFS_PERF_DEBUG
-       DEBUG(0,("********  Finalized op %s in:%llu, out:%llu\n",
-               onefs_stat_debug(&ctxt->iod),
+       DEBUG(0,("********  Finalized op %s uid %llu in:%llu, out:%llu\n",
+               onefs_stat_debug(&ctxt->iod), uid,
                ctxt->iod.in_bytes, ctxt->iod.out_bytes));
 #endif
 
@@ -338,7 +363,6 @@ static struct smb_perfcount_handlers onefs_pc_handlers = {
        onefs_smb_statistics_set_ioctl,
        onefs_smb_statistics_set_msglen_in,
        onefs_smb_statistics_set_msglen_out,
-       onefs_smb_statistics_set_client,
        onefs_smb_statistics_copy_context,
        onefs_smb_statistics_defer_op,
        onefs_smb_statistics_end
index 418d83ace571a3ccf7e6c6ede36694c695e4cd07..b72ac9f7b5c238a09d518822f5ee9f8bd991b376 100644 (file)
@@ -351,14 +351,6 @@ static void perfcount_test_defer_op(struct smb_perfcount_data *pcd,
        return;
 }
 
-static void perfcount_test_set_client(struct smb_perfcount_data *pcd,
-                                           uid_t uid, const char *user,
-                                           const char *domain)
-{
-       /* WIP */
-       return;
-}
-
 static void perfcount_test_end(struct smb_perfcount_data *pcd)
 {
        struct perfcount_test_context *ctxt =
@@ -382,7 +374,6 @@ static struct smb_perfcount_handlers perfcount_test_handlers = {
        perfcount_test_set_ioctl,
        perfcount_test_set_msglen_in,
        perfcount_test_set_msglen_out,
-       perfcount_test_set_client,
        perfcount_test_copy_context,
        perfcount_test_defer_op,
        perfcount_test_end