staging: lustre: fix coding style of function's pointer
[pandora-kernel.git] / drivers / staging / lustre / lustre / lvfs / lvfs_lib.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/lvfs/lvfs_lib.c
37  *
38  * Lustre filesystem abstraction routines
39  *
40  * Author: Andreas Dilger <adilger@clusterfs.com>
41  */
42 #include <linux/module.h>
43 #include "../include/lustre_lib.h"
44 #include "../include/lprocfs_status.h"
45
46 void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, long amount)
47 {
48         struct lprocfs_counter          *percpu_cntr;
49         struct lprocfs_counter_header   *header;
50         int                             smp_id;
51         unsigned long                   flags = 0;
52
53         if (stats == NULL)
54                 return;
55
56         /* With per-client stats, statistics are allocated only for
57          * single CPU area, so the smp_id should be 0 always. */
58         smp_id = lprocfs_stats_lock(stats, LPROCFS_GET_SMP_ID, &flags);
59         if (smp_id < 0)
60                 return;
61
62         header = &stats->ls_cnt_header[idx];
63         percpu_cntr = lprocfs_stats_counter_get(stats, smp_id, idx);
64         percpu_cntr->lc_count++;
65
66         if (header->lc_config & LPROCFS_CNTR_AVGMINMAX) {
67                 /*
68                  * lprocfs_counter_add() can be called in interrupt context,
69                  * as memory allocation could trigger memory shrinker call
70                  * ldlm_pool_shrink(), which calls lprocfs_counter_add().
71                  * LU-1727.
72                  *
73                  * Only obd_memory uses LPROCFS_STATS_FLAG_IRQ_SAFE
74                  * flag, because it needs accurate counting lest memory leak
75                  * check reports error.
76                  */
77                 if (in_interrupt() &&
78                     (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
79                         percpu_cntr->lc_sum_irq += amount;
80                 else
81                         percpu_cntr->lc_sum += amount;
82
83                 if (header->lc_config & LPROCFS_CNTR_STDDEV)
84                         percpu_cntr->lc_sumsquare += (__s64)amount * amount;
85                 if (amount < percpu_cntr->lc_min)
86                         percpu_cntr->lc_min = amount;
87                 if (amount > percpu_cntr->lc_max)
88                         percpu_cntr->lc_max = amount;
89         }
90         lprocfs_stats_unlock(stats, LPROCFS_GET_SMP_ID, &flags);
91 }
92 EXPORT_SYMBOL(lprocfs_counter_add);
93
94 void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx, long amount)
95 {
96         struct lprocfs_counter          *percpu_cntr;
97         struct lprocfs_counter_header   *header;
98         int                             smp_id;
99         unsigned long                   flags = 0;
100
101         if (stats == NULL)
102                 return;
103
104         /* With per-client stats, statistics are allocated only for
105          * single CPU area, so the smp_id should be 0 always. */
106         smp_id = lprocfs_stats_lock(stats, LPROCFS_GET_SMP_ID, &flags);
107         if (smp_id < 0)
108                 return;
109
110         header = &stats->ls_cnt_header[idx];
111         percpu_cntr = lprocfs_stats_counter_get(stats, smp_id, idx);
112         if (header->lc_config & LPROCFS_CNTR_AVGMINMAX) {
113                 /*
114                  * Sometimes we use RCU callbacks to free memory which calls
115                  * lprocfs_counter_sub(), and RCU callbacks may execute in
116                  * softirq context - right now that's the only case we're in
117                  * softirq context here, use separate counter for that.
118                  * bz20650.
119                  *
120                  * Only obd_memory uses LPROCFS_STATS_FLAG_IRQ_SAFE
121                  * flag, because it needs accurate counting lest memory leak
122                  * check reports error.
123                  */
124                 if (in_interrupt() &&
125                     (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
126                         percpu_cntr->lc_sum_irq -= amount;
127                 else
128                         percpu_cntr->lc_sum -= amount;
129         }
130         lprocfs_stats_unlock(stats, LPROCFS_GET_SMP_ID, &flags);
131 }
132 EXPORT_SYMBOL(lprocfs_counter_sub);
133
134 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
135 {
136         struct lprocfs_counter  *cntr;
137         unsigned int            percpusize;
138         int                     rc = -ENOMEM;
139         unsigned long           flags = 0;
140         int                     i;
141
142         LASSERT(stats->ls_percpu[cpuid] == NULL);
143         LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
144
145         percpusize = lprocfs_stats_counter_size(stats);
146         LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
147         if (stats->ls_percpu[cpuid] != NULL) {
148                 rc = 0;
149                 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
150                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
151                                 spin_lock_irqsave(&stats->ls_lock, flags);
152                         else
153                                 spin_lock(&stats->ls_lock);
154                         if (stats->ls_biggest_alloc_num <= cpuid)
155                                 stats->ls_biggest_alloc_num = cpuid + 1;
156                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
157                                 spin_unlock_irqrestore(&stats->ls_lock, flags);
158                         else
159                                 spin_unlock(&stats->ls_lock);
160                 }
161                 /* initialize the ls_percpu[cpuid] non-zero counter */
162                 for (i = 0; i < stats->ls_num; ++i) {
163                         cntr = lprocfs_stats_counter_get(stats, cpuid, i);
164                         cntr->lc_min = LC_MIN_INIT;
165                 }
166         }
167
168         return rc;
169 }
170 EXPORT_SYMBOL(lprocfs_stats_alloc_one);