Whamcloud - gitweb
LU-9325 obd: replace lprocfs_str_to_s64
[fs/lustre-release.git] / lustre / mdc / lproc_mdc.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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32 #define DEBUG_SUBSYSTEM S_CLASS
33
34 #include <linux/version.h>
35 #include <linux/vfs.h>
36 #include <obd_class.h>
37 #include <lprocfs_status.h>
38 #include <lustre_osc.h>
39 #include <cl_object.h>
40
41 #include "mdc_internal.h"
42
43 #ifdef CONFIG_PROC_FS
44 static int mdc_active_seq_show(struct seq_file *m, void *v)
45 {
46         struct obd_device *dev = m->private;
47
48         LPROCFS_CLIMP_CHECK(dev);
49         seq_printf(m, "%d\n", !dev->u.cli.cl_import->imp_deactive);
50         LPROCFS_CLIMP_EXIT(dev);
51         return 0;
52 }
53
54 static ssize_t mdc_active_seq_write(struct file *file,
55                                     const char __user *buffer,
56                                     size_t count, loff_t *off)
57 {
58         struct obd_device *dev;
59         bool val;
60         int rc;
61
62         dev = ((struct seq_file *)file->private_data)->private;
63         rc = kstrtobool_from_user(buffer, count, &val);
64         if (rc)
65                 return rc;
66
67         /* opposite senses */
68         if (dev->u.cli.cl_import->imp_deactive == val)
69                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
70         else
71                 CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
72                        val);
73
74         return count;
75 }
76 LPROC_SEQ_FOPS(mdc_active);
77
78 static int mdc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
79 {
80         struct obd_device *dev = m->private;
81         struct client_obd *cli = &dev->u.cli;
82         long val;
83         int mult;
84
85         spin_lock(&cli->cl_loi_list_lock);
86         val = cli->cl_dirty_max_pages;
87         spin_unlock(&cli->cl_loi_list_lock);
88
89         mult = 1 << (20 - PAGE_SHIFT);
90         return lprocfs_seq_read_frac_helper(m, val, mult);
91 }
92
93 static ssize_t mdc_max_dirty_mb_seq_write(struct file *file,
94                                           const char __user *buffer,
95                                           size_t count, loff_t *off)
96 {
97         struct seq_file *sfl = file->private_data;
98         struct obd_device *dev = sfl->private;
99         struct client_obd *cli = &dev->u.cli;
100         __s64 pages_number;
101         int rc;
102
103         rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
104         if (rc)
105                 return rc;
106
107         pages_number >>= PAGE_SHIFT;
108
109         if (pages_number <= 0 ||
110             pages_number >= OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_SHIFT) ||
111             pages_number > totalram_pages / 4) /* 1/4 of RAM */
112                 return -ERANGE;
113
114         spin_lock(&cli->cl_loi_list_lock);
115         cli->cl_dirty_max_pages = pages_number;
116         osc_wake_cache_waiters(cli);
117         spin_unlock(&cli->cl_loi_list_lock);
118
119         return count;
120 }
121 LPROC_SEQ_FOPS(mdc_max_dirty_mb);
122
123 static int mdc_cached_mb_seq_show(struct seq_file *m, void *v)
124 {
125         struct obd_device *dev = m->private;
126         struct client_obd *cli = &dev->u.cli;
127         int shift = 20 - PAGE_SHIFT;
128
129         seq_printf(m, "used_mb: %ld\n"
130                    "busy_cnt: %ld\n"
131                    "reclaim: %llu\n",
132                    (atomic_long_read(&cli->cl_lru_in_list) +
133                     atomic_long_read(&cli->cl_lru_busy)) >> shift,
134                     atomic_long_read(&cli->cl_lru_busy),
135                    cli->cl_lru_reclaim);
136
137         return 0;
138 }
139
140 /* shrink the number of caching pages to a specific number */
141 static ssize_t
142 mdc_cached_mb_seq_write(struct file *file, const char __user *buffer,
143                         size_t count, loff_t *off)
144 {
145         struct seq_file *sfl = file->private_data;
146         struct obd_device *dev = sfl->private;
147         struct client_obd *cli = &dev->u.cli;
148         __s64 pages_number;
149         long rc;
150         char kernbuf[128];
151
152         if (count >= sizeof(kernbuf))
153                 return -EINVAL;
154
155         if (copy_from_user(kernbuf, buffer, count))
156                 return -EFAULT;
157         kernbuf[count] = 0;
158
159         buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
160                   kernbuf;
161         rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
162         if (rc)
163                 return rc;
164
165         pages_number >>= PAGE_SHIFT;
166
167         if (pages_number < 0)
168                 return -ERANGE;
169
170         rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
171         if (rc > 0) {
172                 struct lu_env *env;
173                 __u16 refcheck;
174
175                 env = cl_env_get(&refcheck);
176                 if (!IS_ERR(env)) {
177                         (void)osc_lru_shrink(env, cli, rc, true);
178                         cl_env_put(env, &refcheck);
179                 }
180         }
181
182         return count;
183 }
184 LPROC_SEQ_FOPS(mdc_cached_mb);
185
186 static int mdc_contention_seconds_seq_show(struct seq_file *m, void *v)
187 {
188         struct obd_device *obd = m->private;
189         struct osc_device *od  = obd2osc_dev(obd);
190
191         seq_printf(m, "%lld\n", od->od_contention_time);
192         return 0;
193 }
194
195 static ssize_t mdc_contention_seconds_seq_write(struct file *file,
196                                                 const char __user *buffer,
197                                                 size_t count, loff_t *off)
198 {
199         struct seq_file *sfl = file->private_data;
200         struct obd_device *obd = sfl->private;
201         struct osc_device *od  = obd2osc_dev(obd);
202         time64_t val;
203         int rc;
204
205         rc = kstrtoll_from_user(buffer, count, 0, &val);
206         if (rc)
207                 return rc;
208
209         od->od_contention_time = val;
210
211         return count;
212 }
213 LPROC_SEQ_FOPS(mdc_contention_seconds);
214
215 static int mdc_unstable_stats_seq_show(struct seq_file *m, void *v)
216 {
217         struct obd_device *dev = m->private;
218         struct client_obd *cli = &dev->u.cli;
219         long pages;
220         int mb;
221
222         pages = atomic_long_read(&cli->cl_unstable_count);
223         mb    = (pages * PAGE_SIZE) >> 20;
224
225         seq_printf(m, "unstable_pages: %20ld\n"
226                    "unstable_mb:              %10d\n", pages, mb);
227         return 0;
228 }
229 LPROC_SEQ_FOPS_RO(mdc_unstable_stats);
230
231 static int mdc_max_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
232 {
233         struct obd_device *dev = m->private;
234         __u32 max;
235
236         max = obd_get_max_rpcs_in_flight(&dev->u.cli);
237         seq_printf(m, "%u\n", max);
238
239         return 0;
240 }
241
242 static ssize_t mdc_max_rpcs_in_flight_seq_write(struct file *file,
243                                                 const char __user *buffer,
244                                                 size_t count, loff_t *off)
245 {
246         struct obd_device *dev;
247         unsigned int val;
248         int rc;
249
250         dev = ((struct seq_file *)file->private_data)->private;
251         rc = kstrtouint_from_user(buffer, count, 0, &val);
252         if (rc)
253                 return rc;
254
255         rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
256         if (rc)
257                 return rc;
258
259         return count;
260 }
261 LPROC_SEQ_FOPS(mdc_max_rpcs_in_flight);
262
263 static int mdc_max_mod_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
264 {
265         struct obd_device *dev = m->private;
266         __u16 max;
267
268         max = obd_get_max_mod_rpcs_in_flight(&dev->u.cli);
269         seq_printf(m, "%hu\n", max);
270
271         return 0;
272 }
273
274 static ssize_t mdc_max_mod_rpcs_in_flight_seq_write(struct file *file,
275                                                     const char __user *buffer,
276                                                     size_t count, loff_t *off)
277 {
278         struct obd_device *dev;
279         u16 val;
280         int rc;
281
282         dev =  ((struct seq_file *)file->private_data)->private;
283         rc = kstrtou16_from_user(buffer, count, 0, &val);
284         if (rc)
285                 return rc;
286
287         rc = obd_set_max_mod_rpcs_in_flight(&dev->u.cli, val);
288         if (rc)
289                 count = rc;
290
291         return count;
292 }
293 LPROC_SEQ_FOPS(mdc_max_mod_rpcs_in_flight);
294
295 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
296                                        const char __user *buf,
297                                        size_t len, loff_t *off)
298 {
299         struct seq_file *seq = file->private_data;
300         struct obd_device *dev = seq->private;
301         struct client_obd *cli = &dev->u.cli;
302
303         lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
304
305         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
306         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
307         lprocfs_oh_clear(&cli->cl_read_page_hist);
308         lprocfs_oh_clear(&cli->cl_write_page_hist);
309         lprocfs_oh_clear(&cli->cl_read_offset_hist);
310         lprocfs_oh_clear(&cli->cl_write_offset_hist);
311
312         return len;
313 }
314
315 #define pct(a, b) (b ? a * 100 / b : 0)
316 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
317 {
318         struct obd_device *dev = seq->private;
319         struct client_obd *cli = &dev->u.cli;
320         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
321         int i;
322
323         obd_mod_rpc_stats_seq_show(&dev->u.cli, seq);
324
325         spin_lock(&cli->cl_loi_list_lock);
326
327         seq_printf(seq, "\nread RPCs in flight:  %d\n",
328                    cli->cl_r_in_flight);
329         seq_printf(seq, "write RPCs in flight: %d\n",
330                    cli->cl_w_in_flight);
331         seq_printf(seq, "pending write pages:  %d\n",
332                    atomic_read(&cli->cl_pending_w_pages));
333         seq_printf(seq, "pending read pages:   %d\n",
334                    atomic_read(&cli->cl_pending_r_pages));
335
336         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
337         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
338         seq_printf(seq, "       rpcs   %% cum %%\n");
339
340         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
341         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
342
343         read_cum = 0;
344         write_cum = 0;
345         for (i = 0; i < OBD_HIST_MAX; i++) {
346                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
347                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
348
349                 read_cum += r;
350                 write_cum += w;
351                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
352                            1 << i, r, pct(r, read_tot),
353                            pct(read_cum, read_tot), w,
354                            pct(w, write_tot),
355                            pct(write_cum, write_tot));
356                 if (read_cum == read_tot && write_cum == write_tot)
357                         break;
358         }
359
360         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
361         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
362         seq_printf(seq, "       rpcs   %% cum %%\n");
363
364         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
365         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
366
367         read_cum = 0;
368         write_cum = 0;
369         for (i = 0; i < OBD_HIST_MAX; i++) {
370                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
371                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
372
373                 read_cum += r;
374                 write_cum += w;
375                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
376                            i, r, pct(r, read_tot), pct(read_cum, read_tot), w,
377                            pct(w, write_tot), pct(write_cum, write_tot));
378                 if (read_cum == read_tot && write_cum == write_tot)
379                         break;
380         }
381
382         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
383         seq_printf(seq, "offset                rpcs   %% cum %% |");
384         seq_printf(seq, "       rpcs   %% cum %%\n");
385
386         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
387         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
388
389         read_cum = 0;
390         write_cum = 0;
391         for (i = 0; i < OBD_HIST_MAX; i++) {
392                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
393                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
394
395                 read_cum += r;
396                 write_cum += w;
397                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
398                            (i == 0) ? 0 : 1 << (i - 1),
399                            r, pct(r, read_tot), pct(read_cum, read_tot),
400                            w, pct(w, write_tot), pct(write_cum, write_tot));
401                 if (read_cum == read_tot && write_cum == write_tot)
402                         break;
403         }
404         spin_unlock(&cli->cl_loi_list_lock);
405
406         return 0;
407 }
408 #undef pct
409 LPROC_SEQ_FOPS(mdc_rpc_stats);
410
411 static int mdc_stats_seq_show(struct seq_file *seq, void *v)
412 {
413         struct timespec64 now;
414         struct obd_device *dev = seq->private;
415         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
416
417         ktime_get_real_ts64(&now);
418
419         seq_printf(seq, "snapshot_time:         %lld.%09lu (secs.nsecs)\n",
420                    (s64)now.tv_sec, now.tv_nsec);
421         seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
422                    stats->os_lockless_writes);
423         seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
424                    stats->os_lockless_reads);
425         seq_printf(seq, "lockless_truncate\t\t%llu\n",
426                    stats->os_lockless_truncates);
427         return 0;
428 }
429
430 static ssize_t mdc_stats_seq_write(struct file *file,
431                                    const char __user *buf,
432                                    size_t len, loff_t *off)
433 {
434         struct seq_file *seq = file->private_data;
435         struct obd_device *dev = seq->private;
436         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
437
438         memset(stats, 0, sizeof(*stats));
439         return len;
440 }
441 LPROC_SEQ_FOPS(mdc_stats);
442
443 LPROC_SEQ_FOPS_WR_ONLY(mdc, ping);
444
445 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
446 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
447 LPROC_SEQ_FOPS_RO_TYPE(mdc, conn_uuid);
448 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
449 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
450 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
451 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
452 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
453
454 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
455         { .name =       "ping",
456           .fops =       &mdc_ping_fops,
457           .proc_mode =  0222                    },
458         { .name =       "connect_flags",
459           .fops =       &mdc_connect_flags_fops },
460         { .name =       "mds_server_uuid",
461           .fops =       &mdc_server_uuid_fops   },
462         { .name =       "mds_conn_uuid",
463           .fops =       &mdc_conn_uuid_fops     },
464         { .name =       "max_pages_per_rpc",
465           .fops =       &mdc_obd_max_pages_per_rpc_fops },
466         { .name =       "max_rpcs_in_flight",
467           .fops =       &mdc_max_rpcs_in_flight_fops    },
468         { .name =       "max_mod_rpcs_in_flight",
469           .fops =       &mdc_max_mod_rpcs_in_flight_fops },
470         { .name =       "max_dirty_mb",
471           .fops =       &mdc_max_dirty_mb_fops          },
472         { .name =       "mdc_cached_mb",
473           .fops =       &mdc_cached_mb_fops             },
474         { .name =       "timeouts",
475           .fops =       &mdc_timeouts_fops              },
476         { .name =       "contention_seconds",
477           .fops =       &mdc_contention_seconds_fops    },
478         { .name =       "import",
479           .fops =       &mdc_import_fops                },
480         { .name =       "state",
481           .fops =       &mdc_state_fops                 },
482         { .name =       "pinger_recov",
483           .fops =       &mdc_pinger_recov_fops          },
484         { .name =       "rpc_stats",
485           .fops =       &mdc_rpc_stats_fops             },
486         { .name =       "active",
487           .fops =       &mdc_active_fops                },
488         { .name =       "unstable_stats",
489           .fops =       &mdc_unstable_stats_fops        },
490         { .name =       "mdc_stats",
491           .fops =       &mdc_stats_fops                 },
492         { NULL }
493 };
494
495 #endif /* CONFIG_PROC_FS */