Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / obdclass / lprocfs_status.c
index 9afb4dd..608af88 100644 (file)
@@ -116,6 +116,21 @@ int lprocfs_add_simple(struct proc_dir_entry *root, char *name,
         return 0;
 }
 
+struct proc_dir_entry *lprocfs_add_symlink(const char *name,
+                        struct proc_dir_entry *parent, const char *dest)
+{
+        struct proc_dir_entry *entry;
+
+        if (parent == NULL || dest == NULL)
+                return NULL;
+
+        entry = proc_symlink(name, parent, dest);
+        if (entry == NULL)
+                CERROR("LprocFS: Could not create symbolic link from %s to %s",
+                        name, dest);
+        return entry;
+}
+
 static ssize_t lprocfs_fops_read(struct file *f, char __user *buf,
                                  size_t size, loff_t *ppos)
 {
@@ -319,6 +334,12 @@ void lprocfs_remove(struct proc_dir_entry **rooth)
         }
 }
 
+void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
+{
+        LASSERT(parent != NULL);
+        remove_proc_entry(name, parent);
+}
+
 struct proc_dir_entry *lprocfs_register(const char *name,
                                         struct proc_dir_entry *parent,
                                         struct lprocfs_vars *list, void *data)
@@ -737,9 +758,8 @@ struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
                                           enum lprocfs_stats_flags flags)
 {
         struct lprocfs_stats *stats;
-        struct lprocfs_percpu *percpu;
         unsigned int percpusize;
-        unsigned int i;
+        unsigned int i, j;
         unsigned int num_cpu;
 
         if (num == 0)
@@ -762,12 +782,20 @@ struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
                 stats->ls_flags = 0;
         }
 
-        percpusize = offsetof(typeof(*percpu), lp_cntr[num]);
+        percpusize = offsetof(struct lprocfs_percpu, lp_cntr[num]);
         if (num_cpu > 1)
                 percpusize = L1_CACHE_ALIGN(percpusize);
 
-        stats->ls_percpu_size = num_cpu * percpusize;
-        OBD_ALLOC(stats->ls_percpu[0], stats->ls_percpu_size);
+        for (i = 0; i < num_cpu; i++) {
+                OBD_ALLOC(stats->ls_percpu[i], percpusize);
+                if (stats->ls_percpu[i] == NULL) {
+                        for (j = 0; j < i; j++) {
+                                OBD_FREE(stats->ls_percpu[j], percpusize);
+                                stats->ls_percpu[j] = NULL;
+                        }
+                        break;
+                }
+        }
         if (stats->ls_percpu[0] == NULL) {
                 OBD_FREE(stats, offsetof(typeof(*stats),
                                          ls_percpu[num_cpu]));
@@ -775,10 +803,6 @@ struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
         }
 
         stats->ls_num = num;
-        for (i = 1; i < num_cpu; i++)
-                stats->ls_percpu[i] = (void *)(stats->ls_percpu[i - 1]) +
-                        percpusize;
-
         return stats;
 }
 
@@ -786,6 +810,8 @@ void lprocfs_free_stats(struct lprocfs_stats **statsh)
 {
         struct lprocfs_stats *stats = *statsh;
         unsigned int num_cpu;
+        unsigned int percpusize;
+        unsigned int i;
 
         if (stats == NULL || stats->ls_num == 0)
                 return;
@@ -796,7 +822,11 @@ void lprocfs_free_stats(struct lprocfs_stats **statsh)
         else
                 num_cpu = num_possible_cpus();
 
-        OBD_FREE(stats->ls_percpu[0], stats->ls_percpu_size);
+        percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
+        if (num_cpu > 1)
+                percpusize = L1_CACHE_ALIGN(percpusize);
+        for (i = 0; i < num_cpu; i++)
+                OBD_FREE(stats->ls_percpu[i], percpusize);
         OBD_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_cpu]));
 }
 
@@ -814,7 +844,7 @@ void lprocfs_clear_stats(struct lprocfs_stats *stats)
                         atomic_inc(&percpu_cntr->lc_cntl.la_entry);
                         percpu_cntr->lc_count = 0;
                         percpu_cntr->lc_sum = 0;
-                        percpu_cntr->lc_min = ~(__u64)0;
+                        percpu_cntr->lc_min = LC_MIN_INIT;
                         percpu_cntr->lc_max = 0;
                         percpu_cntr->lc_sumsquare = 0;
                         atomic_inc(&percpu_cntr->lc_cntl.la_exit);
@@ -860,7 +890,7 @@ static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
 {
        struct lprocfs_stats *stats = p->private;
        struct lprocfs_counter  *cntr = v;
-       struct lprocfs_counter  t, ret = { .lc_min = ~(__u64)0 };
+       struct lprocfs_counter  t, ret = { .lc_min = LC_MIN_INIT };
        int i, idx, rc;
        unsigned int num_cpu;
 
@@ -902,18 +932,18 @@ static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
                ret.lc_sumsquare += t.lc_sumsquare;
        }
 
-       rc = seq_printf(p, "%-25s "LPU64" samples [%s]", cntr->lc_name,
+       rc = seq_printf(p, "%-25s "LPD64" samples [%s]", cntr->lc_name,
                        ret.lc_count, cntr->lc_units);
        if (rc < 0)
                goto out;
 
        if ((cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) && (ret.lc_count > 0)) {
-               rc = seq_printf(p, " "LPU64" "LPU64" "LPU64,
+               rc = seq_printf(p, " "LPD64" "LPD64" "LPD64,
                                ret.lc_min, ret.lc_max, ret.lc_sum);
                if (rc < 0)
                        goto out;
                if (cntr->lc_config & LPROCFS_CNTR_STDDEV)
-                       rc = seq_printf(p, " "LPU64, ret.lc_sumsquare);
+                       rc = seq_printf(p, " "LPD64, ret.lc_sumsquare);
                if (rc < 0)
                        goto out;
        }
@@ -985,7 +1015,7 @@ void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
                 c->lc_config = conf;
                 c->lc_count = 0;
                 c->lc_sum = 0;
-                c->lc_min = ~(__u64)0;
+                c->lc_min = LC_MIN_INIT;
                 c->lc_max = 0;
                 c->lc_name = name;
                 c->lc_units = units;
@@ -1334,8 +1364,8 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid)
                 GOTO(destroy_new, rc = 0);
         }
         /* not found - create */
-        tmp->nid_proc = proc_mkdir(libcfs_nid2str(*nid),
-                                   obd->obd_proc_exports_entry);
+        tmp->nid_proc = lprocfs_register(libcfs_nid2str(*nid),
+                                         obd->obd_proc_exports_entry, NULL, NULL);
         if (!tmp->nid_proc) {
                 CERROR("Error making export directory for"
                        " nid %s\n", libcfs_nid2str(*nid));
@@ -1745,10 +1775,12 @@ EXPORT_SYMBOL(lprocfs_obd_wr_recovery_maxtime);
 EXPORT_SYMBOL(lprocfs_register);
 EXPORT_SYMBOL(lprocfs_srch);
 EXPORT_SYMBOL(lprocfs_remove);
+EXPORT_SYMBOL(lprocfs_remove_proc_entry);
 EXPORT_SYMBOL(lprocfs_add_vars);
 EXPORT_SYMBOL(lprocfs_obd_setup);
 EXPORT_SYMBOL(lprocfs_obd_cleanup);
 EXPORT_SYMBOL(lprocfs_add_simple);
+EXPORT_SYMBOL(lprocfs_add_symlink);
 EXPORT_SYMBOL(lprocfs_free_per_client_stats);
 EXPORT_SYMBOL(lprocfs_alloc_stats);
 EXPORT_SYMBOL(lprocfs_free_stats);