Whamcloud - gitweb
merge with HEAD.
[fs/lustre-release.git] / libcfs / libcfs / tracefile.c
index 5530832..6913c44 100644 (file)
@@ -150,8 +150,9 @@ static struct trace_page *trace_get_tage_try(struct trace_cpu_data *tcd,
                 } else {
                         tage = tage_alloc(CFS_ALLOC_ATOMIC);
                         if (tage == NULL) {
-                                printk(KERN_WARNING
-                                       "failure to allocate a tage (%ld)\n",
+                                if (printk_ratelimit())
+                                        printk(KERN_WARNING
+                                               "cannot allocate a tage (%ld)\n",
                                        tcd->tcd_cur_pages);
                                 return NULL;
                         }
@@ -189,13 +190,14 @@ static void tcd_shrink(struct trace_cpu_data *tcd)
 
         if (printk_ratelimit())
                 printk(KERN_WARNING "debug daemon buffer overflowed; "
-                       "discarding 10%% of pages (%d of %ld)\n", 
+                       "discarding 10%% of pages (%d of %ld)\n",
                        pgcount + 1, tcd->tcd_cur_pages);
 
         CFS_INIT_LIST_HEAD(&pc.pc_pages);
         spin_lock_init(&pc.pc_lock);
 
-        list_for_each_entry_safe(tage, tmp, &tcd->tcd_pages, linkage) {
+        cfs_list_for_each_entry_safe_typed(tage, tmp, &tcd->tcd_pages,
+                                           struct trace_page, linkage) {
                 if (pgcount-- == 0)
                         break;
 
@@ -238,7 +240,7 @@ static struct trace_page *trace_get_tage(struct trace_cpu_data *tcd,
 int libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls, int subsys, int mask,
                        const char *file, const char *fn, const int line,
                        const char *format1, va_list args,
-                       const char *format2, ...)                      
+                       const char *format2, ...)
 {
         struct trace_cpu_data   *tcd = NULL;
         struct ptldebug_header   header;
@@ -283,7 +285,7 @@ int libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls, int subsys, int mask,
          * _without_ terminating NULL.
          * if needed is to small for this format.
          */
-        for (i=0;i<2;i++) {
+        for (i = 0; i < 2; i++) {
                 tage = trace_get_tage(tcd, needed + known_size + 1);
                 if (tage == NULL) {
                         if (needed + known_size > CFS_PAGE_SIZE)
@@ -294,7 +296,8 @@ int libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls, int subsys, int mask,
                         goto console;
                 }
 
-                string_buf = (char *)cfs_page_address(tage->page)+tage->used+known_size;
+                string_buf = (char *)cfs_page_address(tage->page) +
+                                        tage->used + known_size;
 
                 max_nob = CFS_PAGE_SIZE - tage->used - known_size;
                 if (max_nob <= 0) {
@@ -311,26 +314,26 @@ int libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls, int subsys, int mask,
                         needed = vsnprintf(string_buf, max_nob, format1, ap);
                         va_end(ap);
                 }
-               
 
                 if (format2) {
                        remain = max_nob - needed;
                         if (remain < 0)
                                 remain = 0;
-               
+
                         va_start(ap, format2);
-                        needed += vsnprintf(string_buf+needed, remain, format2, ap);
+                        needed += vsnprintf(string_buf + needed, remain,
+                                            format2, ap);
                         va_end(ap);
                 }
 
                 if (needed < max_nob) /* well. printing ok.. */
                         break;
         }
-       
+
         if (*(string_buf+needed-1) != '\n')
                 printk(KERN_INFO "format at %s:%d:%s doesn't end in newline\n",
                        file, line, fn);
-       
+
         header.ph_len = known_size + needed;
         debug_buf = (char *)cfs_page_address(tage->page) + tage->used;
 
@@ -448,6 +451,7 @@ libcfs_assertion_failed(const char *expr, const char *file,
 {
         libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line,
                          "ASSERTION(%s) failed\n", expr);
+        /* cfs_enter_debugger(); */
         lbug_with_loc(file, func, line);
 }
 EXPORT_SYMBOL(libcfs_assertion_failed);
@@ -536,7 +540,8 @@ static void put_pages_back_on_cpu(void *info)
         tcd_for_each_type_lock(tcd, i) {
                 cur_head = tcd->tcd_pages.next;
 
-                list_for_each_entry_safe(tage, tmp, &pc->pc_pages, linkage) {
+                cfs_list_for_each_entry_safe_typed(tage, tmp, &pc->pc_pages,
+                                                   struct trace_page, linkage) {
 
                         __LASSERT_TAGE_INVARIANT(tage);
 
@@ -567,7 +572,8 @@ static void put_pages_on_tcd_daemon_list(struct page_collection *pc,
         struct trace_page *tmp;
 
         spin_lock(&pc->pc_lock);
-        list_for_each_entry_safe(tage, tmp, &pc->pc_pages, linkage) {
+        cfs_list_for_each_entry_safe_typed(tage, tmp, &pc->pc_pages,
+                                           struct trace_page, linkage) {
 
                 __LASSERT_TAGE_INVARIANT(tage);
 
@@ -618,7 +624,8 @@ void trace_debug_print(void)
 
         pc.pc_want_daemon_pages = 1;
         collect_pages(&pc);
-        list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) {
+        cfs_list_for_each_entry_safe_typed(tage, tmp, &pc.pc_pages,
+                                           struct trace_page, linkage) {
                 char *p, *file, *fn;
                 cfs_page_t *page;
 
@@ -635,7 +642,7 @@ void trace_debug_print(void)
                         p += strlen(file) + 1;
                         fn = p;
                         p += strlen(fn) + 1;
-                        len = hdr->ph_len - (p - (char *)hdr);
+                        len = hdr->ph_len - (int)(p - (char *)hdr);
 
                         print_to_console(hdr, D_EMERG, p, len, file, fn);
 
@@ -679,7 +686,8 @@ int tracefile_dump_all_pages(char *filename)
         /* ok, for now, just write the pages.  in the future we'll be building
          * iobufs with the pages and calling generic_direct_IO */
         CFS_MMSPACE_OPEN;
-        list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) {
+        cfs_list_for_each_entry_safe_typed(tage, tmp, &pc.pc_pages,
+                                           struct trace_page, linkage) {
 
                 __LASSERT_TAGE_INVARIANT(tage);
 
@@ -716,7 +724,8 @@ void trace_flush_pages(void)
 
         pc.pc_want_daemon_pages = 1;
         collect_pages(&pc);
-        list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) {
+        cfs_list_for_each_entry_safe_typed(tage, tmp, &pc.pc_pages,
+                                           struct trace_page, linkage) {
 
                 __LASSERT_TAGE_INVARIANT(tage);
 
@@ -729,11 +738,11 @@ int trace_copyin_string(char *knl_buffer, int knl_buffer_nob,
                         const char *usr_buffer, int usr_buffer_nob)
 {
         int    nob;
-        
+
         if (usr_buffer_nob > knl_buffer_nob)
                 return -EOVERFLOW;
-        
-        if (copy_from_user((void *)knl_buffer, 
+
+        if (copy_from_user((void *)knl_buffer,
                            (void *)usr_buffer, usr_buffer_nob))
                 return -EFAULT;
 
@@ -759,17 +768,17 @@ int trace_copyout_string(char *usr_buffer, int usr_buffer_nob,
          * copied out string - usually "\n", for /proc entries and "" (i.e. a
          * terminating zero byte) for sysctl entries */
         int   nob = strlen(knl_buffer);
-        
+
         if (nob > usr_buffer_nob)
                 nob = usr_buffer_nob;
-        
+
         if (copy_to_user(usr_buffer, knl_buffer, nob))
                 return -EFAULT;
-        
+
         if (append != NULL && nob < usr_buffer_nob) {
                 if (copy_to_user(usr_buffer + nob, append, 1))
                         return -EFAULT;
-                
+
                 nob++;
         }
 
@@ -780,7 +789,7 @@ int trace_allocate_string_buffer(char **str, int nob)
 {
         if (nob > 2 * CFS_PAGE_SIZE)            /* string must be "sensible" */
                 return -EINVAL;
-        
+
         *str = cfs_alloc(nob, CFS_ALLOC_STD | CFS_ALLOC_ZERO);
         if (*str == NULL)
                 return -ENOMEM;
@@ -822,7 +831,7 @@ out:
 int trace_daemon_command(char *str)
 {
         int       rc = 0;
-        
+
        tracefile_write_lock();
 
        if (strcmp(str, "stop") == 0) {
@@ -881,7 +890,7 @@ int trace_set_debug_mb(int mb)
         int pages;
         int limit = trace_max_debug_mb();
         struct trace_cpu_data *tcd;
-        
+
        if (mb < num_possible_cpus())
                return -EINVAL;
 
@@ -922,7 +931,7 @@ int trace_get_debug_mb(void)
         int j;
         struct trace_cpu_data *tcd;
         int total_pages = 0;
-        
+
         tracefile_read_lock();
 
         tcd_for_each(tcd, i, j)
@@ -996,14 +1005,15 @@ static int tracefiled(void *arg)
                 hdr = cfs_page_address(tage->page);
                 hdr->ph_flags |= PH_FLAG_FIRST_RECORD;
 
-                list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) {
+                cfs_list_for_each_entry_safe_typed(tage, tmp, &pc.pc_pages,
+                                                   struct trace_page, linkage) {
                         static loff_t f_pos;
 
                         __LASSERT_TAGE_INVARIANT(tage);
 
                         if (f_pos >= (off_t)tracefile_size)
                                 f_pos = 0;
-                        else if (f_pos > cfs_filp_size(filp))
+                        else if (f_pos > (off_t)cfs_filp_size(filp))
                                 f_pos = cfs_filp_size(filp);
 
                         rc = cfs_filp_write(filp, cfs_page_address(tage->page),
@@ -1104,7 +1114,8 @@ static void trace_cleanup_on_cpu(void *info)
         tcd_for_each_type_lock(tcd, i) {
                 tcd->tcd_shutting_down = 1;
 
-                list_for_each_entry_safe(tage, tmp, &tcd->tcd_pages, linkage) {
+                cfs_list_for_each_entry_safe_typed(tage, tmp, &tcd->tcd_pages,
+                                                   struct trace_page, linkage) {
                         __LASSERT_TAGE_INVARIANT(tage);
 
                         list_del(&tage->linkage);