Whamcloud - gitweb
3be012949932581f5b578114e9061eeff3cc85cc
[fs/lustre-release.git] / lustre / osc / lproc_osc.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  */
31 #define DEBUG_SUBSYSTEM S_CLASS
32
33 #include <linux/version.h>
34 #include <asm/statfs.h>
35 #include <obd_cksum.h>
36 #include <obd_class.h>
37 #include <lprocfs_status.h>
38 #include <linux/seq_file.h>
39 #include <lustre_osc.h>
40
41 #include "osc_internal.h"
42
43 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
44                            char *buf)
45 {
46         struct obd_device *obd = container_of(kobj, struct obd_device,
47                                               obd_kset.kobj);
48         struct obd_import *imp;
49         int rc;
50
51         with_imp_locked(obd, imp, rc)
52                 rc = sprintf(buf, "%d\n", !imp->imp_deactive);
53
54         return rc;
55 }
56
57 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
58                             const char *buffer, size_t count)
59 {
60         struct obd_device *obd = container_of(kobj, struct obd_device,
61                                               obd_kset.kobj);
62         struct obd_import *imp, *imp0;
63         bool val;
64         int rc;
65
66         rc = kstrtobool(buffer, &val);
67         if (rc)
68                 return rc;
69
70         with_imp_locked(obd, imp0, rc)
71                 imp = class_import_get(imp0);
72         if (rc)
73                 return rc;
74         /* opposite senses */
75         if (imp->imp_deactive == val)
76                 rc = ptlrpc_set_import_active(imp, val);
77         else
78                 CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
79                        (unsigned int)val);
80         class_import_put(imp);
81
82         return rc ?: count;
83 }
84 LUSTRE_RW_ATTR(active);
85
86 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
87                                        struct attribute *attr,
88                                        char *buf)
89 {
90         struct obd_device *obd = container_of(kobj, struct obd_device,
91                                               obd_kset.kobj);
92         struct client_obd *cli = &obd->u.cli;
93
94         return  scnprintf(buf, PAGE_SIZE, "%u\n", cli->cl_max_rpcs_in_flight);
95 }
96
97 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
98                                         struct attribute *attr,
99                                         const char *buffer,
100                                         size_t count)
101 {
102         struct obd_device *obd = container_of(kobj, struct obd_device,
103                                               obd_kset.kobj);
104         struct client_obd *cli = &obd->u.cli;
105         int adding, added, req_count;
106         unsigned int val;
107         int rc;
108
109         rc = kstrtouint(buffer, 0, &val);
110         if (rc)
111                 return rc;
112
113         if (val == 0 || val > OSC_MAX_RIF_MAX)
114                 return -ERANGE;
115
116         adding = (int)val - cli->cl_max_rpcs_in_flight;
117         req_count = atomic_read(&osc_pool_req_count);
118         if (adding > 0 && req_count < osc_reqpool_maxreqcount) {
119                 /*
120                  * There might be some race which will cause over-limit
121                  * allocation, but it is fine.
122                  */
123                 if (req_count + adding > osc_reqpool_maxreqcount)
124                         adding = osc_reqpool_maxreqcount - req_count;
125
126                 added = osc_rq_pool->prp_populate(osc_rq_pool, adding);
127                 atomic_add(added, &osc_pool_req_count);
128         }
129
130         spin_lock(&cli->cl_loi_list_lock);
131         cli->cl_max_rpcs_in_flight = val;
132         client_adjust_max_dirty(cli);
133         spin_unlock(&cli->cl_loi_list_lock);
134
135         return count;
136 }
137 LUSTRE_RW_ATTR(max_rpcs_in_flight);
138
139 static ssize_t max_dirty_mb_show(struct kobject *kobj,
140                                  struct attribute *attr,
141                                  char *buf)
142 {
143         struct obd_device *obd = container_of(kobj, struct obd_device,
144                                               obd_kset.kobj);
145         struct client_obd *cli = &obd->u.cli;
146
147         return scnprintf(buf, PAGE_SIZE, "%lu\n",
148                          PAGES_TO_MiB(cli->cl_dirty_max_pages));
149 }
150
151 static ssize_t max_dirty_mb_store(struct kobject *kobj,
152                                   struct attribute *attr,
153                                   const char *buffer,
154                                   size_t count)
155 {
156         struct obd_device *obd = container_of(kobj, struct obd_device,
157                                               obd_kset.kobj);
158         struct client_obd *cli = &obd->u.cli;
159         unsigned long pages_number, max_dirty_mb;
160         int rc;
161
162         rc = kstrtoul(buffer, 10, &max_dirty_mb);
163         if (rc)
164                 return rc;
165
166         pages_number = MiB_TO_PAGES(max_dirty_mb);
167
168         if (pages_number >= MiB_TO_PAGES(OSC_MAX_DIRTY_MB_MAX) ||
169             pages_number > cfs_totalram_pages() / 4) /* 1/4 of RAM */
170                 return -ERANGE;
171
172         spin_lock(&cli->cl_loi_list_lock);
173         cli->cl_dirty_max_pages = pages_number;
174         osc_wake_cache_waiters(cli);
175         spin_unlock(&cli->cl_loi_list_lock);
176
177         return count;
178 }
179 LUSTRE_RW_ATTR(max_dirty_mb);
180
181 LUSTRE_ATTR(ost_conn_uuid, 0444, conn_uuid_show, NULL);
182 LUSTRE_RO_ATTR(conn_uuid);
183
184 LUSTRE_RW_ATTR(ping);
185
186 static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
187 {
188         struct obd_device *obd = m->private;
189         struct client_obd *cli = &obd->u.cli;
190         int shift = 20 - PAGE_SHIFT;
191
192         seq_printf(m, "used_mb: %ld\n"
193                    "busy_cnt: %ld\n"
194                    "reclaim: %llu\n",
195                    (atomic_long_read(&cli->cl_lru_in_list) +
196                     atomic_long_read(&cli->cl_lru_busy)) >> shift,
197                     atomic_long_read(&cli->cl_lru_busy),
198                    cli->cl_lru_reclaim);
199
200         return 0;
201 }
202
203 /* shrink the number of caching pages to a specific number */
204 static ssize_t osc_cached_mb_seq_write(struct file *file,
205                                        const char __user *buffer,
206                                        size_t count, loff_t *off)
207 {
208         struct seq_file *m = file->private_data;
209         struct obd_device *obd = m->private;
210         struct client_obd *cli = &obd->u.cli;
211         u64 pages_number;
212         const char *tmp;
213         long rc;
214         char kernbuf[128];
215
216         if (count >= sizeof(kernbuf))
217                 return -EINVAL;
218
219         if (copy_from_user(kernbuf, buffer, count))
220                 return -EFAULT;
221         kernbuf[count] = 0;
222
223         tmp = lprocfs_find_named_value(kernbuf, "used_mb:", &count);
224         rc = sysfs_memparse(tmp, count, &pages_number, "MiB");
225         if (rc < 0)
226                 return rc;
227
228         pages_number >>= PAGE_SHIFT;
229
230         rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
231         if (rc > 0) {
232                 struct lu_env *env;
233                 __u16 refcheck;
234
235                 env = cl_env_get(&refcheck);
236                 if (!IS_ERR(env)) {
237                         (void)osc_lru_shrink(env, cli, rc, true);
238                         cl_env_put(env, &refcheck);
239                 }
240         }
241
242         return count;
243 }
244
245 LPROC_SEQ_FOPS(osc_cached_mb);
246
247 static ssize_t cur_dirty_bytes_show(struct kobject *kobj,
248                                     struct attribute *attr,
249                                     char *buf)
250 {
251         struct obd_device *obd = container_of(kobj, struct obd_device,
252                                               obd_kset.kobj);
253         struct client_obd *cli = &obd->u.cli;
254
255         return scnprintf(buf, PAGE_SIZE, "%lu\n",
256                          cli->cl_dirty_pages << PAGE_SHIFT);
257 }
258 LUSTRE_RO_ATTR(cur_dirty_bytes);
259
260 static int osc_cur_grant_bytes_seq_show(struct seq_file *m, void *v)
261 {
262         struct obd_device *obd = m->private;
263         struct client_obd *cli = &obd->u.cli;
264
265         seq_printf(m, "%lu\n", cli->cl_avail_grant);
266         return 0;
267 }
268
269 static ssize_t osc_cur_grant_bytes_seq_write(struct file *file,
270                                              const char __user *buffer,
271                                              size_t count, loff_t *off)
272 {
273         struct seq_file *m = file->private_data;
274         struct obd_device *obd = m->private;
275         struct client_obd *cli = &obd->u.cli;
276         struct obd_import *imp;
277         char kernbuf[22] = "";
278         u64 val;
279         int rc;
280
281         if (obd == NULL)
282                 return 0;
283
284         if (count >= sizeof(kernbuf))
285                 return -EINVAL;
286
287         if (copy_from_user(kernbuf, buffer, count))
288                 return -EFAULT;
289         kernbuf[count] = 0;
290
291         rc = sysfs_memparse(kernbuf, count, &val, "MiB");
292         if (rc < 0)
293                 return rc;
294
295         /* this is only for shrinking grant */
296         if (val >= cli->cl_avail_grant)
297                 return 0;
298
299         with_imp_locked(obd, imp, rc)
300                 if (imp->imp_state == LUSTRE_IMP_FULL)
301                         rc = osc_shrink_grant_to_target(cli, val);
302
303         return rc ? rc : count;
304 }
305 LPROC_SEQ_FOPS(osc_cur_grant_bytes);
306
307 static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj,
308                                          struct attribute *attr,
309                                          char *buf)
310 {
311         struct obd_device *obd = container_of(kobj, struct obd_device,
312                                               obd_kset.kobj);
313         struct client_obd *cli = &obd->u.cli;
314
315         return scnprintf(buf, PAGE_SIZE, "%lu\n", cli->cl_lost_grant);
316 }
317 LUSTRE_RO_ATTR(cur_lost_grant_bytes);
318
319 static ssize_t cur_dirty_grant_bytes_show(struct kobject *kobj,
320                                           struct attribute *attr,
321                                           char *buf)
322 {
323         struct obd_device *obd = container_of(kobj, struct obd_device,
324                                               obd_kset.kobj);
325         struct client_obd *cli = &obd->u.cli;
326
327         return scnprintf(buf, PAGE_SIZE, "%lu\n", cli->cl_dirty_grant);
328 }
329 LUSTRE_RO_ATTR(cur_dirty_grant_bytes);
330
331 static ssize_t grant_shrink_interval_show(struct kobject *kobj,
332                                           struct attribute *attr,
333                                           char *buf)
334 {
335         struct obd_device *obd = container_of(kobj, struct obd_device,
336                                               obd_kset.kobj);
337
338         return sprintf(buf, "%lld\n", obd->u.cli.cl_grant_shrink_interval);
339 }
340
341 static ssize_t grant_shrink_interval_store(struct kobject *kobj,
342                                            struct attribute *attr,
343                                            const char *buffer,
344                                            size_t count)
345 {
346         struct obd_device *obd = container_of(kobj, struct obd_device,
347                                               obd_kset.kobj);
348         unsigned int val;
349         int rc;
350
351         rc = kstrtouint(buffer, 0, &val);
352         if (rc)
353                 return rc;
354
355         if (val == 0)
356                 return -ERANGE;
357
358         obd->u.cli.cl_grant_shrink_interval = val;
359         osc_update_next_shrink(&obd->u.cli);
360         osc_schedule_grant_work();
361
362         return count;
363 }
364 LUSTRE_RW_ATTR(grant_shrink_interval);
365
366 static ssize_t checksums_show(struct kobject *kobj,
367                               struct attribute *attr,
368                               char *buf)
369 {
370         struct obd_device *obd = container_of(kobj, struct obd_device,
371                                               obd_kset.kobj);
372
373         return scnprintf(buf, PAGE_SIZE, "%d\n", !!obd->u.cli.cl_checksum);
374 }
375
376 static ssize_t checksums_store(struct kobject *kobj,
377                                struct attribute *attr,
378                                const char *buffer,
379                                size_t count)
380 {
381         struct obd_device *obd = container_of(kobj, struct obd_device,
382                                               obd_kset.kobj);
383         bool val;
384         int rc;
385
386         rc = kstrtobool(buffer, &val);
387         if (rc)
388                 return rc;
389
390         obd->u.cli.cl_checksum = val;
391
392         return count;
393 }
394 LUSTRE_RW_ATTR(checksums);
395
396 DECLARE_CKSUM_NAME;
397
398 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
399 {
400         struct obd_device *obd = m->private;
401         int i;
402
403         if (obd == NULL)
404                 return 0;
405
406         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
407                 if ((BIT(i) & obd->u.cli.cl_supp_cksum_types) == 0)
408                         continue;
409                 if (obd->u.cli.cl_cksum_type == BIT(i))
410                         seq_printf(m, "[%s] ", cksum_name[i]);
411                 else
412                         seq_printf(m, "%s ", cksum_name[i]);
413         }
414         seq_puts(m, "\n");
415
416         return 0;
417 }
418
419 static ssize_t osc_checksum_type_seq_write(struct file *file,
420                                            const char __user *buffer,
421                                            size_t count, loff_t *off)
422 {
423         struct seq_file *m = file->private_data;
424         struct obd_device *obd = m->private;
425         char kernbuf[10];
426         int rc = -EINVAL;
427         int i;
428
429         if (obd == NULL)
430                 return 0;
431
432         if (count > sizeof(kernbuf) - 1)
433                 return -EINVAL;
434         if (copy_from_user(kernbuf, buffer, count))
435                 return -EFAULT;
436
437         if (count > 0 && kernbuf[count - 1] == '\n')
438                 kernbuf[count - 1] = '\0';
439         else
440                 kernbuf[count] = '\0';
441
442         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
443                 if (strcasecmp(kernbuf, cksum_name[i]) == 0) {
444                         obd->u.cli.cl_preferred_cksum_type = BIT(i);
445                         if (obd->u.cli.cl_supp_cksum_types & BIT(i)) {
446                                 obd->u.cli.cl_cksum_type = BIT(i);
447                                 rc = count;
448                         } else {
449                                 rc = -ENOTSUPP;
450                         }
451                         break;
452                 }
453         }
454         return rc;
455 }
456 LPROC_SEQ_FOPS(osc_checksum_type);
457
458 static ssize_t resend_count_show(struct kobject *kobj,
459                                  struct attribute *attr,
460                                  char *buf)
461 {
462         struct obd_device *obd = container_of(kobj, struct obd_device,
463                                               obd_kset.kobj);
464
465         return sprintf(buf, "%u\n", atomic_read(&obd->u.cli.cl_resends));
466 }
467
468 static ssize_t resend_count_store(struct kobject *kobj,
469                                   struct attribute *attr,
470                                   const char *buffer,
471                                   size_t count)
472 {
473         struct obd_device *obd = container_of(kobj, struct obd_device,
474                                               obd_kset.kobj);
475         unsigned int val;
476         int rc;
477
478         rc = kstrtouint(buffer, 10, &val);
479         if (rc)
480                 return rc;
481
482         atomic_set(&obd->u.cli.cl_resends, val);
483
484         return count;
485 }
486 LUSTRE_RW_ATTR(resend_count);
487
488 static ssize_t checksum_dump_show(struct kobject *kobj,
489                                   struct attribute *attr,
490                                   char *buf)
491 {
492         struct obd_device *obd = container_of(kobj, struct obd_device,
493                                               obd_kset.kobj);
494
495         return scnprintf(buf, PAGE_SIZE, "%d\n", !!obd->u.cli.cl_checksum_dump);
496 }
497
498 static ssize_t checksum_dump_store(struct kobject *kobj,
499                                    struct attribute *attr,
500                                    const char *buffer,
501                                    size_t count)
502 {
503         struct obd_device *obd = container_of(kobj, struct obd_device,
504                                               obd_kset.kobj);
505         bool val;
506         int rc;
507
508         rc = kstrtobool(buffer, &val);
509         if (rc)
510                 return rc;
511
512         obd->u.cli.cl_checksum_dump = val;
513
514         return count;
515 }
516 LUSTRE_RW_ATTR(checksum_dump);
517
518 static ssize_t destroys_in_flight_show(struct kobject *kobj,
519                                        struct attribute *attr,
520                                        char *buf)
521 {
522         struct obd_device *obd = container_of(kobj, struct obd_device,
523                                               obd_kset.kobj);
524
525         return sprintf(buf, "%u\n",
526                        atomic_read(&obd->u.cli.cl_destroy_in_flight));
527 }
528 LUSTRE_RO_ATTR(destroys_in_flight);
529
530 LPROC_SEQ_FOPS_RW_TYPE(osc, obd_max_pages_per_rpc);
531
532 LUSTRE_RW_ATTR(short_io_bytes);
533
534 #ifdef CONFIG_PROC_FS
535 static int osc_unstable_stats_seq_show(struct seq_file *m, void *v)
536 {
537         struct obd_device *obd = m->private;
538         struct client_obd *cli = &obd->u.cli;
539         long pages;
540         int mb;
541
542         pages = atomic_long_read(&cli->cl_unstable_count);
543         mb    = (pages * PAGE_SIZE) >> 20;
544
545         seq_printf(m, "unstable_pages: %20ld\n"
546                    "unstable_mb:              %10d\n",
547                    pages, mb);
548         return 0;
549 }
550 LPROC_SEQ_FOPS_RO(osc_unstable_stats);
551
552 static ssize_t idle_timeout_show(struct kobject *kobj, struct attribute *attr,
553                                  char *buf)
554 {
555         struct obd_device *obd = container_of(kobj, struct obd_device,
556                                               obd_kset.kobj);
557         struct obd_import *imp;
558         int ret;
559
560         with_imp_locked(obd, imp, ret)
561                 ret = sprintf(buf, "%u\n", imp->imp_idle_timeout);
562
563         return ret;
564 }
565
566 static ssize_t idle_timeout_store(struct kobject *kobj, struct attribute *attr,
567                                   const char *buffer, size_t count)
568 {
569         struct obd_device *obd = container_of(kobj, struct obd_device,
570                                               obd_kset.kobj);
571         struct obd_import *imp;
572         struct ptlrpc_request *req;
573         unsigned int idle_debug = 0;
574         unsigned int val;
575         int rc;
576
577         if (strncmp(buffer, "debug", 5) == 0) {
578                 idle_debug = D_CONSOLE;
579         } else if (strncmp(buffer, "nodebug", 6) == 0) {
580                 idle_debug = D_HA;
581         } else {
582                 rc = kstrtouint(buffer, 10, &val);
583                 if (rc)
584                         return rc;
585
586                 if (val > CONNECTION_SWITCH_MAX)
587                         return -ERANGE;
588         }
589
590         with_imp_locked(obd, imp, rc) {
591                 if (idle_debug) {
592                         imp->imp_idle_debug = idle_debug;
593                 } else {
594                         if (!val) {
595                                 /* initiate the connection if it's in IDLE state */
596                                 req = ptlrpc_request_alloc(imp,
597                                                            &RQF_OST_STATFS);
598                                 if (req != NULL)
599                                         ptlrpc_req_finished(req);
600                         }
601                         imp->imp_idle_timeout = val;
602                 }
603         }
604
605         return count;
606 }
607 LUSTRE_RW_ATTR(idle_timeout);
608
609 static ssize_t idle_connect_store(struct kobject *kobj, struct attribute *attr,
610                                   const char *buffer, size_t count)
611 {
612         struct obd_device *obd = container_of(kobj, struct obd_device,
613                                               obd_kset.kobj);
614         struct obd_import *imp;
615         struct ptlrpc_request *req;
616         int rc;
617
618         with_imp_locked(obd, imp, rc) {
619                 /* to initiate the connection if it's in IDLE state */
620                 req = ptlrpc_request_alloc(imp, &RQF_OST_STATFS);
621                 if (req)
622                         ptlrpc_req_finished(req);
623                 ptlrpc_pinger_force(imp);
624         }
625
626         return rc ?: count;
627 }
628 LUSTRE_WO_ATTR(idle_connect);
629
630 static ssize_t grant_shrink_show(struct kobject *kobj, struct attribute *attr,
631                                  char *buf)
632 {
633         struct obd_device *obd = container_of(kobj, struct obd_device,
634                                               obd_kset.kobj);
635         struct obd_import *imp;
636         ssize_t len;
637
638         with_imp_locked(obd, imp, len)
639                 len = scnprintf(buf, PAGE_SIZE, "%d\n",
640                                 !imp->imp_grant_shrink_disabled &&
641                                 OCD_HAS_FLAG(&imp->imp_connect_data,
642                                              GRANT_SHRINK));
643
644         return len;
645 }
646
647 static ssize_t grant_shrink_store(struct kobject *kobj, struct attribute *attr,
648                                   const char *buffer, size_t count)
649 {
650         struct obd_device *obd = container_of(kobj, struct obd_device,
651                                               obd_kset.kobj);
652         struct obd_import *imp;
653         bool val;
654         int rc;
655
656         if (obd == NULL)
657                 return 0;
658
659         rc = kstrtobool(buffer, &val);
660         if (rc)
661                 return rc;
662
663         with_imp_locked(obd, imp, rc) {
664                 spin_lock(&imp->imp_lock);
665                 imp->imp_grant_shrink_disabled = !val;
666                 spin_unlock(&imp->imp_lock);
667         }
668
669         return rc ?: count;
670 }
671 LUSTRE_RW_ATTR(grant_shrink);
672
673 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
674 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
675 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
676 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
677
678 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
679 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
680
681 struct lprocfs_vars lprocfs_osc_obd_vars[] = {
682         { .name =       "connect_flags",
683           .fops =       &osc_connect_flags_fops         },
684         { .name =       "ost_server_uuid",
685           .fops =       &osc_server_uuid_fops           },
686         { .name =       "max_pages_per_rpc",
687           .fops =       &osc_obd_max_pages_per_rpc_fops },
688         { .name =       "osc_cached_mb",
689           .fops =       &osc_cached_mb_fops             },
690         { .name =       "cur_grant_bytes",
691           .fops =       &osc_cur_grant_bytes_fops       },
692         { .name =       "checksum_type",
693           .fops =       &osc_checksum_type_fops         },
694         { .name =       "timeouts",
695           .fops =       &osc_timeouts_fops              },
696         { .name =       "import",
697           .fops =       &osc_import_fops                },
698         { .name =       "state",
699           .fops =       &osc_state_fops                 },
700         { .name =       "pinger_recov",
701           .fops =       &osc_pinger_recov_fops          },
702         { .name =       "unstable_stats",
703           .fops =       &osc_unstable_stats_fops        },
704         { NULL }
705 };
706
707 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
708 {
709         struct timespec64 now;
710         struct obd_device *obd = seq->private;
711         struct client_obd *cli = &obd->u.cli;
712         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
713         int i;
714
715         ktime_get_real_ts64(&now);
716
717         spin_lock(&cli->cl_loi_list_lock);
718
719         seq_printf(seq, "snapshot_time:         %lld.%09lu (secs.nsecs)\n",
720                    (s64)now.tv_sec, now.tv_nsec);
721         seq_printf(seq, "read RPCs in flight:  %d\n",
722                    cli->cl_r_in_flight);
723         seq_printf(seq, "write RPCs in flight: %d\n",
724                    cli->cl_w_in_flight);
725         seq_printf(seq, "pending write pages:  %d\n",
726                    atomic_read(&cli->cl_pending_w_pages));
727         seq_printf(seq, "pending read pages:   %d\n",
728                    atomic_read(&cli->cl_pending_r_pages));
729
730         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
731         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
732         seq_printf(seq, "       rpcs   %% cum %%\n");
733
734         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
735         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
736
737         read_cum = 0;
738         write_cum = 0;
739         for (i = 0; i < OBD_HIST_MAX; i++) {
740                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
741                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
742
743                 read_cum += r;
744                 write_cum += w;
745                 seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
746                            1 << i, r, pct(r, read_tot),
747                            pct(read_cum, read_tot), w,
748                            pct(w, write_tot),
749                            pct(write_cum, write_tot));
750                 if (read_cum == read_tot && write_cum == write_tot)
751                         break;
752         }
753
754         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
755         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
756         seq_printf(seq, "       rpcs   %% cum %%\n");
757
758         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
759         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
760
761         read_cum = 0;
762         write_cum = 0;
763         for (i = 1; i < OBD_HIST_MAX; i++) {
764                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
765                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
766                 read_cum += r;
767                 write_cum += w;
768                 seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
769                            i, r, pct(r, read_tot),
770                            pct(read_cum, read_tot), w,
771                            pct(w, write_tot),
772                            pct(write_cum, write_tot));
773                 if (read_cum == read_tot && write_cum == write_tot)
774                         break;
775         }
776
777         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
778         seq_printf(seq, "offset                rpcs   %% cum %% |");
779         seq_printf(seq, "       rpcs   %% cum %%\n");
780
781         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
782         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
783
784         read_cum = 0;
785         write_cum = 0;
786         for (i = 0; i < OBD_HIST_MAX; i++) {
787                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
788                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
789                 read_cum += r;
790                 write_cum += w;
791                 seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
792                            (i == 0) ? 0 : 1 << (i - 1),
793                            r, pct(r, read_tot), pct(read_cum, read_tot),
794                            w, pct(w, write_tot), pct(write_cum, write_tot));
795                 if (read_cum == read_tot && write_cum == write_tot)
796                         break;
797         }
798
799         spin_unlock(&cli->cl_loi_list_lock);
800
801         return 0;
802 }
803
804 static ssize_t osc_rpc_stats_seq_write(struct file *file,
805                                        const char __user *buf,
806                                        size_t len, loff_t *off)
807 {
808         struct seq_file *seq = file->private_data;
809         struct obd_device *obd = seq->private;
810         struct client_obd *cli = &obd->u.cli;
811
812         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
813         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
814         lprocfs_oh_clear(&cli->cl_read_page_hist);
815         lprocfs_oh_clear(&cli->cl_write_page_hist);
816         lprocfs_oh_clear(&cli->cl_read_offset_hist);
817         lprocfs_oh_clear(&cli->cl_write_offset_hist);
818
819         return len;
820 }
821 LPROC_SEQ_FOPS(osc_rpc_stats);
822
823 static int osc_stats_seq_show(struct seq_file *seq, void *v)
824 {
825         struct timespec64 now;
826         struct obd_device *obd = seq->private;
827         struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
828
829         ktime_get_real_ts64(&now);
830
831         seq_printf(seq, "snapshot_time:         %lld.%09lu (secs.nsecs)\n",
832                    (s64)now.tv_sec, now.tv_nsec);
833         seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
834                    stats->os_lockless_writes);
835         seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
836                    stats->os_lockless_reads);
837         return 0;
838 }
839
840 static ssize_t osc_stats_seq_write(struct file *file,
841                                    const char __user *buf,
842                                    size_t len, loff_t *off)
843 {
844         struct seq_file *seq = file->private_data;
845         struct obd_device *obd = seq->private;
846         struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
847
848         memset(stats, 0, sizeof(*stats));
849         return len;
850 }
851
852 LPROC_SEQ_FOPS(osc_stats);
853
854 int lprocfs_osc_attach_seqstat(struct obd_device *obd)
855 {
856         int rc;
857
858         rc = lprocfs_seq_create(obd->obd_proc_entry, "osc_stats", 0644,
859                                 &osc_stats_fops, obd);
860         if (rc == 0)
861                 rc = lprocfs_obd_seq_create(obd, "rpc_stats", 0644,
862                                             &osc_rpc_stats_fops, obd);
863
864         return rc;
865 }
866 #endif /* CONFIG_PROC_FS */
867
868 static struct attribute *osc_attrs[] = {
869         &lustre_attr_active.attr,
870         &lustre_attr_checksums.attr,
871         &lustre_attr_checksum_dump.attr,
872         &lustre_attr_cur_dirty_bytes.attr,
873         &lustre_attr_cur_lost_grant_bytes.attr,
874         &lustre_attr_cur_dirty_grant_bytes.attr,
875         &lustre_attr_destroys_in_flight.attr,
876         &lustre_attr_grant_shrink_interval.attr,
877         &lustre_attr_max_dirty_mb.attr,
878         &lustre_attr_max_rpcs_in_flight.attr,
879         &lustre_attr_short_io_bytes.attr,
880         &lustre_attr_resend_count.attr,
881         &lustre_attr_ost_conn_uuid.attr,
882         &lustre_attr_conn_uuid.attr,
883         &lustre_attr_ping.attr,
884         &lustre_attr_idle_timeout.attr,
885         &lustre_attr_idle_connect.attr,
886         &lustre_attr_grant_shrink.attr,
887         NULL,
888 };
889
890 int osc_tunables_init(struct obd_device *obd)
891 {
892         int rc;
893
894         obd->obd_vars = lprocfs_osc_obd_vars;
895         obd->obd_ktype.default_attrs = osc_attrs;
896         rc = lprocfs_obd_setup(obd, false);
897         if (rc)
898                 return rc;
899 #ifdef CONFIG_PROC_FS
900         /* If the basic OSC proc tree construction succeeded then
901          * lets do the rest.
902          */
903         rc = lprocfs_osc_attach_seqstat(obd);
904         if (rc)
905                 goto obd_cleanup;
906
907 #endif /* CONFIG_PROC_FS */
908         rc = sptlrpc_lprocfs_cliobd_attach(obd);
909         if (rc)
910                 goto obd_cleanup;
911
912         ptlrpc_lprocfs_register_obd(obd);
913 obd_cleanup:
914         if (rc)
915                 lprocfs_obd_cleanup(obd);
916         return rc;
917 }