Whamcloud - gitweb
LU-8066 obd: use correct names for conn_uuid
[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/vfs.h>
35 #include <obd_class.h>
36 #include <lprocfs_status.h>
37 #include <lustre_osc.h>
38 #include <cl_object.h>
39 #include "mdc_internal.h"
40
41 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
42                            char *buf)
43 {
44         struct obd_device *dev = container_of(kobj, struct obd_device,
45                                               obd_kset.kobj);
46         ssize_t len;
47
48         LPROCFS_CLIMP_CHECK(dev);
49         len = sprintf(buf, "%d\n", !dev->u.cli.cl_import->imp_deactive);
50         LPROCFS_CLIMP_EXIT(dev);
51         return len;
52 }
53
54 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
55                             const char *buffer, size_t count)
56 {
57         struct obd_device *dev = container_of(kobj, struct obd_device,
58                                               obd_kset.kobj);
59         bool val;
60         int rc;
61
62         rc = kstrtobool(buffer, &val);
63         if (rc)
64                 return rc;
65
66         /* opposite senses */
67         if (dev->u.cli.cl_import->imp_deactive == val)
68                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
69         else
70                 CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
71                        val);
72
73         return count;
74 }
75 LUSTRE_RW_ATTR(active);
76
77 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
78                                        struct attribute *attr,
79                                        char *buf)
80 {
81         struct obd_device *dev = container_of(kobj, struct obd_device,
82                                               obd_kset.kobj);
83         ssize_t len;
84         u32 max;
85
86         max = obd_get_max_rpcs_in_flight(&dev->u.cli);
87         len = sprintf(buf, "%u\n", max);
88
89         return len;
90 }
91
92 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
93                                         struct attribute *attr,
94                                         const char *buffer,
95                                         size_t count)
96 {
97         struct obd_device *dev = container_of(kobj, struct obd_device,
98                                               obd_kset.kobj);
99         unsigned int val;
100         int rc;
101
102         rc = kstrtouint(buffer, 10, &val);
103         if (rc)
104                 return rc;
105
106         rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
107         if (rc)
108                 count = rc;
109
110         return count;
111 }
112 LUSTRE_RW_ATTR(max_rpcs_in_flight);
113
114 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
115                                            struct attribute *attr,
116                                            char *buf)
117 {
118         struct obd_device *dev = container_of(kobj, struct obd_device,
119                                               obd_kset.kobj);
120         u16 max;
121
122         max = obd_get_max_mod_rpcs_in_flight(&dev->u.cli);
123         return sprintf(buf, "%hu\n", max);
124 }
125
126 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
127                                             struct attribute *attr,
128                                             const char *buffer,
129                                             size_t count)
130 {
131         struct obd_device *dev = container_of(kobj, struct obd_device,
132                                               obd_kset.kobj);
133         u16 val;
134         int rc;
135
136         rc = kstrtou16(buffer, 10, &val);
137         if (rc)
138                 return rc;
139
140         rc = obd_set_max_mod_rpcs_in_flight(&dev->u.cli, val);
141         if (rc)
142                 count = rc;
143
144         return count;
145 }
146 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
147
148 static int mdc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
149 {
150         struct obd_device *dev = m->private;
151         struct client_obd *cli = &dev->u.cli;
152         long val;
153         int mult;
154
155         spin_lock(&cli->cl_loi_list_lock);
156         val = cli->cl_dirty_max_pages;
157         spin_unlock(&cli->cl_loi_list_lock);
158
159         mult = 1 << (20 - PAGE_SHIFT);
160         return lprocfs_seq_read_frac_helper(m, val, mult);
161 }
162
163 static ssize_t mdc_max_dirty_mb_seq_write(struct file *file,
164                                           const char __user *buffer,
165                                           size_t count, loff_t *off)
166 {
167         struct seq_file *sfl = file->private_data;
168         struct obd_device *dev = sfl->private;
169         struct client_obd *cli = &dev->u.cli;
170         s64 pages_number;
171         int rc;
172
173         rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
174         if (rc)
175                 return rc;
176
177         pages_number >>= PAGE_SHIFT;
178
179         if (pages_number <= 0 ||
180             pages_number >= OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_SHIFT) ||
181             pages_number > totalram_pages / 4) /* 1/4 of RAM */
182                 return -ERANGE;
183
184         spin_lock(&cli->cl_loi_list_lock);
185         cli->cl_dirty_max_pages = pages_number;
186         osc_wake_cache_waiters(cli);
187         spin_unlock(&cli->cl_loi_list_lock);
188
189         return count;
190 }
191 LPROC_SEQ_FOPS(mdc_max_dirty_mb);
192
193 static ssize_t contention_seconds_show(struct kobject *kobj,
194                                        struct attribute *attr,
195                                        char *buf)
196 {
197         struct obd_device *obd = container_of(kobj, struct obd_device,
198                                               obd_kset.kobj);
199         struct osc_device *od = obd2osc_dev(obd);
200
201         return sprintf(buf, "%lld\n", od->od_contention_time);
202 }
203
204 static ssize_t contention_seconds_store(struct kobject *kobj,
205                                         struct attribute *attr,
206                                         const char *buffer,
207                                         size_t count)
208 {
209         struct obd_device *obd = container_of(kobj, struct obd_device,
210                                               obd_kset.kobj);
211         struct osc_device *od = obd2osc_dev(obd);
212         time64_t val;
213         int rc;
214
215         rc = kstrtoll(buffer, 0, &val);
216         if (rc)
217                 return rc;
218
219         od->od_contention_time = val;
220
221         return count;
222 }
223 LUSTRE_RW_ATTR(contention_seconds);
224
225 LUSTRE_ATTR(mds_conn_uuid, 0444, conn_uuid_show, NULL);
226 LUSTRE_RO_ATTR(conn_uuid);
227
228 LUSTRE_WO_ATTR(ping);
229
230 static int mdc_cached_mb_seq_show(struct seq_file *m, void *v)
231 {
232         struct obd_device *dev = m->private;
233         struct client_obd *cli = &dev->u.cli;
234         int shift = 20 - PAGE_SHIFT;
235
236         seq_printf(m, "used_mb: %ld\n"
237                    "busy_cnt: %ld\n"
238                    "reclaim: %llu\n",
239                    (atomic_long_read(&cli->cl_lru_in_list) +
240                     atomic_long_read(&cli->cl_lru_busy)) >> shift,
241                     atomic_long_read(&cli->cl_lru_busy),
242                    cli->cl_lru_reclaim);
243
244         return 0;
245 }
246
247 /* shrink the number of caching pages to a specific number */
248 static ssize_t
249 mdc_cached_mb_seq_write(struct file *file, const char __user *buffer,
250                         size_t count, loff_t *off)
251 {
252         struct seq_file *sfl = file->private_data;
253         struct obd_device *dev = sfl->private;
254         struct client_obd *cli = &dev->u.cli;
255         __s64 pages_number;
256         long rc;
257         char kernbuf[128];
258
259         if (count >= sizeof(kernbuf))
260                 return -EINVAL;
261
262         if (copy_from_user(kernbuf, buffer, count))
263                 return -EFAULT;
264         kernbuf[count] = 0;
265
266         buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
267                   kernbuf;
268         rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
269         if (rc)
270                 return rc;
271
272         pages_number >>= PAGE_SHIFT;
273
274         if (pages_number < 0)
275                 return -ERANGE;
276
277         rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
278         if (rc > 0) {
279                 struct lu_env *env;
280                 __u16 refcheck;
281
282                 env = cl_env_get(&refcheck);
283                 if (!IS_ERR(env)) {
284                         (void)osc_lru_shrink(env, cli, rc, true);
285                         cl_env_put(env, &refcheck);
286                 }
287         }
288
289         return count;
290 }
291 LPROC_SEQ_FOPS(mdc_cached_mb);
292
293 static int mdc_unstable_stats_seq_show(struct seq_file *m, void *v)
294 {
295         struct obd_device *dev = m->private;
296         struct client_obd *cli = &dev->u.cli;
297         long pages;
298         int mb;
299
300         pages = atomic_long_read(&cli->cl_unstable_count);
301         mb    = (pages * PAGE_SIZE) >> 20;
302
303         seq_printf(m, "unstable_pages: %20ld\n"
304                    "unstable_mb:              %10d\n", pages, mb);
305         return 0;
306 }
307 LPROC_SEQ_FOPS_RO(mdc_unstable_stats);
308
309 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
310                                        const char __user *buf,
311                                        size_t len, loff_t *off)
312 {
313         struct seq_file *seq = file->private_data;
314         struct obd_device *dev = seq->private;
315         struct client_obd *cli = &dev->u.cli;
316
317         lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
318
319         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
320         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
321         lprocfs_oh_clear(&cli->cl_read_page_hist);
322         lprocfs_oh_clear(&cli->cl_write_page_hist);
323         lprocfs_oh_clear(&cli->cl_read_offset_hist);
324         lprocfs_oh_clear(&cli->cl_write_offset_hist);
325
326         return len;
327 }
328
329 #define pct(a, b) (b ? a * 100 / b : 0)
330 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
331 {
332         struct obd_device *dev = seq->private;
333         struct client_obd *cli = &dev->u.cli;
334         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
335         int i;
336
337         obd_mod_rpc_stats_seq_show(&dev->u.cli, seq);
338
339         spin_lock(&cli->cl_loi_list_lock);
340
341         seq_printf(seq, "\nread RPCs in flight:  %d\n",
342                    cli->cl_r_in_flight);
343         seq_printf(seq, "write RPCs in flight: %d\n",
344                    cli->cl_w_in_flight);
345         seq_printf(seq, "pending write pages:  %d\n",
346                    atomic_read(&cli->cl_pending_w_pages));
347         seq_printf(seq, "pending read pages:   %d\n",
348                    atomic_read(&cli->cl_pending_r_pages));
349
350         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
351         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
352         seq_printf(seq, "       rpcs   %% cum %%\n");
353
354         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
355         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
356
357         read_cum = 0;
358         write_cum = 0;
359         for (i = 0; i < OBD_HIST_MAX; i++) {
360                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
361                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
362
363                 read_cum += r;
364                 write_cum += w;
365                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
366                            1 << i, r, pct(r, read_tot),
367                            pct(read_cum, read_tot), w,
368                            pct(w, write_tot),
369                            pct(write_cum, write_tot));
370                 if (read_cum == read_tot && write_cum == write_tot)
371                         break;
372         }
373
374         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
375         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
376         seq_printf(seq, "       rpcs   %% cum %%\n");
377
378         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
379         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
380
381         read_cum = 0;
382         write_cum = 0;
383         for (i = 0; i < OBD_HIST_MAX; i++) {
384                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
385                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
386
387                 read_cum += r;
388                 write_cum += w;
389                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
390                            i, r, pct(r, read_tot), pct(read_cum, read_tot), w,
391                            pct(w, write_tot), pct(write_cum, write_tot));
392                 if (read_cum == read_tot && write_cum == write_tot)
393                         break;
394         }
395
396         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
397         seq_printf(seq, "offset                rpcs   %% cum %% |");
398         seq_printf(seq, "       rpcs   %% cum %%\n");
399
400         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
401         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
402
403         read_cum = 0;
404         write_cum = 0;
405         for (i = 0; i < OBD_HIST_MAX; i++) {
406                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
407                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
408
409                 read_cum += r;
410                 write_cum += w;
411                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
412                            (i == 0) ? 0 : 1 << (i - 1),
413                            r, pct(r, read_tot), pct(read_cum, read_tot),
414                            w, pct(w, write_tot), pct(write_cum, write_tot));
415                 if (read_cum == read_tot && write_cum == write_tot)
416                         break;
417         }
418         spin_unlock(&cli->cl_loi_list_lock);
419
420         return 0;
421 }
422 #undef pct
423 LPROC_SEQ_FOPS(mdc_rpc_stats);
424
425 static int mdc_stats_seq_show(struct seq_file *seq, void *v)
426 {
427         struct timespec64 now;
428         struct obd_device *dev = seq->private;
429         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
430
431         ktime_get_real_ts64(&now);
432
433         seq_printf(seq, "snapshot_time:         %lld.%09lu (secs.nsecs)\n",
434                    (s64)now.tv_sec, now.tv_nsec);
435         seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
436                    stats->os_lockless_writes);
437         seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
438                    stats->os_lockless_reads);
439         seq_printf(seq, "lockless_truncate\t\t%llu\n",
440                    stats->os_lockless_truncates);
441         return 0;
442 }
443
444 static ssize_t mdc_stats_seq_write(struct file *file,
445                                    const char __user *buf,
446                                    size_t len, loff_t *off)
447 {
448         struct seq_file *seq = file->private_data;
449         struct obd_device *dev = seq->private;
450         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
451
452         memset(stats, 0, sizeof(*stats));
453         return len;
454 }
455 LPROC_SEQ_FOPS(mdc_stats);
456
457 static int mdc_dom_min_repsize_seq_show(struct seq_file *m, void *v)
458 {
459         struct obd_device *dev = m->private;
460
461         seq_printf(m, "%u\n", dev->u.cli.cl_dom_min_inline_repsize);
462
463         return 0;
464 }
465
466 static ssize_t mdc_dom_min_repsize_seq_write(struct file *file,
467                                              const char __user *buffer,
468                                              size_t count, loff_t *off)
469 {
470         struct obd_device *dev;
471         unsigned int val;
472         int rc;
473
474         dev =  ((struct seq_file *)file->private_data)->private;
475         rc = kstrtouint_from_user(buffer, count, 0, &val);
476         if (rc)
477                 return rc;
478
479         if (val > MDC_DOM_MAX_INLINE_REPSIZE)
480                 return -ERANGE;
481
482         dev->u.cli.cl_dom_min_inline_repsize = val;
483         return count;
484 }
485 LPROC_SEQ_FOPS(mdc_dom_min_repsize);
486
487 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
488 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
489 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
490 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
491 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
492 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
493 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
494
495 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
496         { .name =       "connect_flags",
497           .fops =       &mdc_connect_flags_fops },
498         { .name =       "mds_server_uuid",
499           .fops =       &mdc_server_uuid_fops   },
500         { .name =       "max_pages_per_rpc",
501           .fops =       &mdc_obd_max_pages_per_rpc_fops },
502         { .name =       "max_dirty_mb",
503           .fops =       &mdc_max_dirty_mb_fops          },
504         { .name =       "mdc_cached_mb",
505           .fops =       &mdc_cached_mb_fops             },
506         { .name =       "timeouts",
507           .fops =       &mdc_timeouts_fops              },
508         { .name =       "import",
509           .fops =       &mdc_import_fops                },
510         { .name =       "state",
511           .fops =       &mdc_state_fops                 },
512         { .name =       "pinger_recov",
513           .fops =       &mdc_pinger_recov_fops          },
514         { .name =       "rpc_stats",
515           .fops =       &mdc_rpc_stats_fops             },
516         { .name =       "unstable_stats",
517           .fops =       &mdc_unstable_stats_fops        },
518         { .name =       "mdc_stats",
519           .fops =       &mdc_stats_fops                 },
520         { .name =       "mdc_dom_min_repsize",
521           .fops =       &mdc_dom_min_repsize_fops       },
522         { NULL }
523 };
524
525 static struct attribute *mdc_attrs[] = {
526         &lustre_attr_active.attr,
527         &lustre_attr_max_rpcs_in_flight.attr,
528         &lustre_attr_max_mod_rpcs_in_flight.attr,
529         &lustre_attr_contention_seconds.attr,
530         &lustre_attr_mds_conn_uuid.attr,
531         &lustre_attr_conn_uuid.attr,
532         &lustre_attr_ping.attr,
533         NULL,
534 };
535
536 int mdc_tunables_init(struct obd_device *obd)
537 {
538         int rc;
539
540         obd->obd_ktype.default_attrs = mdc_attrs;
541         obd->obd_vars = lprocfs_mdc_obd_vars;
542
543         rc = lprocfs_obd_setup(obd, false);
544         if (rc)
545                 goto out_failed;
546 #ifdef CONFIG_PROC_FS
547         rc = lprocfs_alloc_md_stats(obd, 0);
548         if (rc) {
549                 lprocfs_obd_cleanup(obd);
550                 goto out_failed;
551         }
552 #endif
553         rc = sptlrpc_lprocfs_cliobd_attach(obd);
554         if (rc) {
555 #ifdef CONFIG_PROC_FS
556                 lprocfs_free_md_stats(obd);
557 #endif
558                 lprocfs_obd_cleanup(obd);
559                 goto out_failed;
560         }
561         ptlrpc_lprocfs_register_obd(obd);
562
563 out_failed:
564         return rc;
565 }