Whamcloud - gitweb
LU-17662 osd-zfs: Support for ZFS 2.2.3
[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 enable_page_cache_shrink_show(struct kobject *kobj,
367                                              struct attribute *attr,
368                                              char *buf)
369 {
370         return scnprintf(buf, PAGE_SIZE, "%d\n", osc_page_cache_shrink_enabled);
371 }
372
373 static ssize_t enable_page_cache_shrink_store(struct kobject *kobj,
374                                               struct attribute *attr,
375                                               const char *buffer,
376                                               size_t count)
377 {
378         bool val;
379         int rc;
380
381         rc = kstrtobool(buffer, &val);
382         if (rc)
383                 return rc;
384
385         osc_page_cache_shrink_enabled = val;
386         return count;
387 }
388 LUSTRE_RW_ATTR(enable_page_cache_shrink);
389
390 static ssize_t checksums_show(struct kobject *kobj,
391                               struct attribute *attr,
392                               char *buf)
393 {
394         struct obd_device *obd = container_of(kobj, struct obd_device,
395                                               obd_kset.kobj);
396
397         return scnprintf(buf, PAGE_SIZE, "%d\n", !!obd->u.cli.cl_checksum);
398 }
399
400 static ssize_t checksums_store(struct kobject *kobj,
401                                struct attribute *attr,
402                                const char *buffer,
403                                size_t count)
404 {
405         struct obd_device *obd = container_of(kobj, struct obd_device,
406                                               obd_kset.kobj);
407         bool val;
408         int rc;
409
410         rc = kstrtobool(buffer, &val);
411         if (rc)
412                 return rc;
413
414         obd->u.cli.cl_checksum = val;
415
416         return count;
417 }
418 LUSTRE_RW_ATTR(checksums);
419
420 DECLARE_CKSUM_NAME;
421
422 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
423 {
424         struct obd_device *obd = m->private;
425         int i;
426
427         if (obd == NULL)
428                 return 0;
429
430         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
431                 if ((BIT(i) & obd->u.cli.cl_supp_cksum_types) == 0)
432                         continue;
433                 if (obd->u.cli.cl_cksum_type == BIT(i))
434                         seq_printf(m, "[%s] ", cksum_name[i]);
435                 else
436                         seq_printf(m, "%s ", cksum_name[i]);
437         }
438         seq_puts(m, "\n");
439
440         return 0;
441 }
442
443 static ssize_t osc_checksum_type_seq_write(struct file *file,
444                                            const char __user *buffer,
445                                            size_t count, loff_t *off)
446 {
447         struct seq_file *m = file->private_data;
448         struct obd_device *obd = m->private;
449         char kernbuf[10];
450         int rc = -EINVAL;
451         int i;
452
453         if (obd == NULL)
454                 return 0;
455
456         if (count > sizeof(kernbuf) - 1)
457                 return -EINVAL;
458         if (copy_from_user(kernbuf, buffer, count))
459                 return -EFAULT;
460
461         if (count > 0 && kernbuf[count - 1] == '\n')
462                 kernbuf[count - 1] = '\0';
463         else
464                 kernbuf[count] = '\0';
465
466         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
467                 if (strcasecmp(kernbuf, cksum_name[i]) == 0) {
468                         obd->u.cli.cl_preferred_cksum_type = BIT(i);
469                         if (obd->u.cli.cl_supp_cksum_types & BIT(i)) {
470                                 obd->u.cli.cl_cksum_type = BIT(i);
471                                 rc = count;
472                         } else {
473                                 rc = -EOPNOTSUPP;
474                         }
475                         break;
476                 }
477         }
478         return rc;
479 }
480 LPROC_SEQ_FOPS(osc_checksum_type);
481
482 static ssize_t resend_count_show(struct kobject *kobj,
483                                  struct attribute *attr,
484                                  char *buf)
485 {
486         struct obd_device *obd = container_of(kobj, struct obd_device,
487                                               obd_kset.kobj);
488
489         return sprintf(buf, "%u\n", atomic_read(&obd->u.cli.cl_resends));
490 }
491
492 static ssize_t resend_count_store(struct kobject *kobj,
493                                   struct attribute *attr,
494                                   const char *buffer,
495                                   size_t count)
496 {
497         struct obd_device *obd = container_of(kobj, struct obd_device,
498                                               obd_kset.kobj);
499         unsigned int val;
500         int rc;
501
502         rc = kstrtouint(buffer, 10, &val);
503         if (rc)
504                 return rc;
505
506         atomic_set(&obd->u.cli.cl_resends, val);
507
508         return count;
509 }
510 LUSTRE_RW_ATTR(resend_count);
511
512 static ssize_t checksum_dump_show(struct kobject *kobj,
513                                   struct attribute *attr,
514                                   char *buf)
515 {
516         struct obd_device *obd = container_of(kobj, struct obd_device,
517                                               obd_kset.kobj);
518
519         return scnprintf(buf, PAGE_SIZE, "%d\n", !!obd->u.cli.cl_checksum_dump);
520 }
521
522 static ssize_t checksum_dump_store(struct kobject *kobj,
523                                    struct attribute *attr,
524                                    const char *buffer,
525                                    size_t count)
526 {
527         struct obd_device *obd = container_of(kobj, struct obd_device,
528                                               obd_kset.kobj);
529         bool val;
530         int rc;
531
532         rc = kstrtobool(buffer, &val);
533         if (rc)
534                 return rc;
535
536         obd->u.cli.cl_checksum_dump = val;
537
538         return count;
539 }
540 LUSTRE_RW_ATTR(checksum_dump);
541
542 static ssize_t destroys_in_flight_show(struct kobject *kobj,
543                                        struct attribute *attr,
544                                        char *buf)
545 {
546         struct obd_device *obd = container_of(kobj, struct obd_device,
547                                               obd_kset.kobj);
548
549         return sprintf(buf, "%u\n",
550                        atomic_read(&obd->u.cli.cl_destroy_in_flight));
551 }
552 LUSTRE_RO_ATTR(destroys_in_flight);
553
554 LPROC_SEQ_FOPS_RW_TYPE(osc, obd_max_pages_per_rpc);
555
556 LUSTRE_RW_ATTR(short_io_bytes);
557
558 #ifdef CONFIG_PROC_FS
559 static int osc_unstable_stats_seq_show(struct seq_file *m, void *v)
560 {
561         struct obd_device *obd = m->private;
562         struct client_obd *cli = &obd->u.cli;
563         long pages;
564         int mb;
565
566         pages = atomic_long_read(&cli->cl_unstable_count);
567         mb    = (pages * PAGE_SIZE) >> 20;
568
569         seq_printf(m, "unstable_pages: %20ld\n"
570                    "unstable_mb:              %10d\n",
571                    pages, mb);
572         return 0;
573 }
574 LPROC_SEQ_FOPS_RO(osc_unstable_stats);
575
576 static ssize_t idle_timeout_show(struct kobject *kobj, struct attribute *attr,
577                                  char *buf)
578 {
579         struct obd_device *obd = container_of(kobj, struct obd_device,
580                                               obd_kset.kobj);
581         struct obd_import *imp;
582         int ret;
583
584         with_imp_locked(obd, imp, ret)
585                 ret = sprintf(buf, "%u\n", imp->imp_idle_timeout);
586
587         return ret;
588 }
589
590 static ssize_t idle_timeout_store(struct kobject *kobj, struct attribute *attr,
591                                   const char *buffer, size_t count)
592 {
593         struct obd_device *obd = container_of(kobj, struct obd_device,
594                                               obd_kset.kobj);
595         struct obd_import *imp;
596         struct ptlrpc_request *req;
597         unsigned int idle_debug = 0;
598         unsigned int val;
599         int rc;
600
601         if (strncmp(buffer, "debug", 5) == 0) {
602                 idle_debug = D_CONSOLE;
603         } else if (strncmp(buffer, "nodebug", 6) == 0) {
604                 idle_debug = D_HA;
605         } else {
606                 rc = kstrtouint(buffer, 10, &val);
607                 if (rc)
608                         return rc;
609
610                 if (val > CONNECTION_SWITCH_MAX)
611                         return -ERANGE;
612         }
613
614         with_imp_locked(obd, imp, rc) {
615                 if (idle_debug) {
616                         imp->imp_idle_debug = idle_debug;
617                 } else {
618                         if (!val) {
619                                 /* initiate the connection if it's in IDLE state */
620                                 req = ptlrpc_request_alloc(imp,
621                                                            &RQF_OST_STATFS);
622                                 if (req != NULL)
623                                         ptlrpc_req_finished(req);
624                         }
625                         imp->imp_idle_timeout = val;
626                 }
627         }
628
629         return count;
630 }
631 LUSTRE_RW_ATTR(idle_timeout);
632
633 static ssize_t idle_connect_store(struct kobject *kobj, struct attribute *attr,
634                                   const char *buffer, size_t count)
635 {
636         struct obd_device *obd = container_of(kobj, struct obd_device,
637                                               obd_kset.kobj);
638         struct obd_import *imp;
639         struct ptlrpc_request *req;
640         int rc;
641
642         with_imp_locked(obd, imp, rc) {
643                 /* to initiate the connection if it's in IDLE state */
644                 req = ptlrpc_request_alloc(imp, &RQF_OST_STATFS);
645                 if (req)
646                         ptlrpc_req_finished(req);
647                 ptlrpc_pinger_force(imp);
648         }
649
650         return rc ?: count;
651 }
652 LUSTRE_WO_ATTR(idle_connect);
653
654 static ssize_t grant_shrink_show(struct kobject *kobj, struct attribute *attr,
655                                  char *buf)
656 {
657         struct obd_device *obd = container_of(kobj, struct obd_device,
658                                               obd_kset.kobj);
659         struct obd_import *imp;
660         ssize_t len;
661
662         with_imp_locked(obd, imp, len)
663                 len = scnprintf(buf, PAGE_SIZE, "%d\n",
664                                 !imp->imp_grant_shrink_disabled &&
665                                 OCD_HAS_FLAG(&imp->imp_connect_data,
666                                              GRANT_SHRINK));
667
668         return len;
669 }
670
671 static ssize_t grant_shrink_store(struct kobject *kobj, struct attribute *attr,
672                                   const char *buffer, size_t count)
673 {
674         struct obd_device *obd = container_of(kobj, struct obd_device,
675                                               obd_kset.kobj);
676         struct obd_import *imp;
677         bool val;
678         int rc;
679
680         if (obd == NULL)
681                 return 0;
682
683         rc = kstrtobool(buffer, &val);
684         if (rc)
685                 return rc;
686
687         with_imp_locked(obd, imp, rc) {
688                 spin_lock(&imp->imp_lock);
689                 imp->imp_grant_shrink_disabled = !val;
690                 spin_unlock(&imp->imp_lock);
691         }
692
693         return rc ?: count;
694 }
695 LUSTRE_RW_ATTR(grant_shrink);
696
697 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
698 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
699 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
700 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
701
702 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
703 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
704
705 struct lprocfs_vars lprocfs_osc_obd_vars[] = {
706         { .name =       "connect_flags",
707           .fops =       &osc_connect_flags_fops         },
708         { .name =       "ost_server_uuid",
709           .fops =       &osc_server_uuid_fops           },
710         { .name =       "max_pages_per_rpc",
711           .fops =       &osc_obd_max_pages_per_rpc_fops },
712         { .name =       "osc_cached_mb",
713           .fops =       &osc_cached_mb_fops             },
714         { .name =       "cur_grant_bytes",
715           .fops =       &osc_cur_grant_bytes_fops       },
716         { .name =       "checksum_type",
717           .fops =       &osc_checksum_type_fops         },
718         { .name =       "timeouts",
719           .fops =       &osc_timeouts_fops              },
720         { .name =       "import",
721           .fops =       &osc_import_fops                },
722         { .name =       "state",
723           .fops =       &osc_state_fops                 },
724         { .name =       "pinger_recov",
725           .fops =       &osc_pinger_recov_fops          },
726         { .name =       "unstable_stats",
727           .fops =       &osc_unstable_stats_fops        },
728         { NULL }
729 };
730
731 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
732 {
733         struct obd_device *obd = seq->private;
734         struct client_obd *cli = &obd->u.cli;
735         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
736         int i;
737
738         spin_lock(&cli->cl_loi_list_lock);
739
740         lprocfs_stats_header(seq, ktime_get_real(), cli->cl_stats_init, 25,
741                              ":", true, "");
742         seq_printf(seq, "read RPCs in flight:  %d\n",
743                    cli->cl_r_in_flight);
744         seq_printf(seq, "write RPCs in flight: %d\n",
745                    cli->cl_w_in_flight);
746         seq_printf(seq, "pending write pages:  %d\n",
747                    atomic_read(&cli->cl_pending_w_pages));
748         seq_printf(seq, "pending read pages:   %d\n",
749                    atomic_read(&cli->cl_pending_r_pages));
750
751         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
752         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
753         seq_printf(seq, "       rpcs   %% cum %%\n");
754
755         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
756         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
757
758         read_cum = 0;
759         write_cum = 0;
760         for (i = 0; i < OBD_HIST_MAX; i++) {
761                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
762                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
763
764                 read_cum += r;
765                 write_cum += w;
766                 seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
767                            1 << i, r, pct(r, read_tot),
768                            pct(read_cum, read_tot), w,
769                            pct(w, write_tot),
770                            pct(write_cum, write_tot));
771                 if (read_cum == read_tot && write_cum == write_tot)
772                         break;
773         }
774
775         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
776         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
777         seq_printf(seq, "       rpcs   %% cum %%\n");
778
779         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
780         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
781
782         read_cum = 0;
783         write_cum = 0;
784         for (i = 1; i < OBD_HIST_MAX; i++) {
785                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
786                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
787                 read_cum += r;
788                 write_cum += w;
789                 seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
790                            i, r, pct(r, read_tot),
791                            pct(read_cum, read_tot), w,
792                            pct(w, write_tot),
793                            pct(write_cum, write_tot));
794                 if (read_cum == read_tot && write_cum == write_tot)
795                         break;
796         }
797
798         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
799         seq_printf(seq, "offset                rpcs   %% cum %% |");
800         seq_printf(seq, "       rpcs   %% cum %%\n");
801
802         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
803         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
804
805         read_cum = 0;
806         write_cum = 0;
807         for (i = 0; i < OBD_HIST_MAX; i++) {
808                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
809                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
810                 read_cum += r;
811                 write_cum += w;
812                 seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
813                            (i == 0) ? 0 : 1 << (i - 1),
814                            r, pct(r, read_tot), pct(read_cum, read_tot),
815                            w, pct(w, write_tot), pct(write_cum, write_tot));
816                 if (read_cum == read_tot && write_cum == write_tot)
817                         break;
818         }
819
820         spin_unlock(&cli->cl_loi_list_lock);
821
822         return 0;
823 }
824
825 static ssize_t osc_rpc_stats_seq_write(struct file *file,
826                                        const char __user *buf,
827                                        size_t len, loff_t *off)
828 {
829         struct seq_file *seq = file->private_data;
830         struct obd_device *obd = seq->private;
831         struct client_obd *cli = &obd->u.cli;
832
833         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
834         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
835         lprocfs_oh_clear(&cli->cl_read_page_hist);
836         lprocfs_oh_clear(&cli->cl_write_page_hist);
837         lprocfs_oh_clear(&cli->cl_read_offset_hist);
838         lprocfs_oh_clear(&cli->cl_write_offset_hist);
839         cli->cl_stats_init = ktime_get_real();
840
841         return len;
842 }
843 LPROC_SEQ_FOPS(osc_rpc_stats);
844
845 static int osc_stats_seq_show(struct seq_file *seq, void *v)
846 {
847         struct obd_device *obd = seq->private;
848         struct osc_stats *stats = &obd2osc_dev(obd)->osc_stats;
849
850         lprocfs_stats_header(seq, ktime_get_real(), stats->os_init, 25, ":",
851                              true, "");
852         seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
853                    stats->os_lockless_writes);
854         seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
855                    stats->os_lockless_reads);
856         return 0;
857 }
858
859 static ssize_t osc_stats_seq_write(struct file *file,
860                                    const char __user *buf,
861                                    size_t len, loff_t *off)
862 {
863         struct seq_file *seq = file->private_data;
864         struct obd_device *obd = seq->private;
865         struct osc_stats *stats = &obd2osc_dev(obd)->osc_stats;
866
867         memset(stats, 0, sizeof(*stats));
868         stats->os_init = ktime_get_real();
869
870         return len;
871 }
872
873 LPROC_SEQ_FOPS(osc_stats);
874
875 static int lprocfs_osc_attach_seqstat(struct obd_device *obd)
876 {
877         int rc;
878
879         rc = lprocfs_seq_create(obd->obd_proc_entry, "osc_stats", 0644,
880                                 &osc_stats_fops, obd);
881         if (rc == 0)
882                 rc = lprocfs_obd_seq_create(obd, "rpc_stats", 0644,
883                                             &osc_rpc_stats_fops, obd);
884
885         return rc;
886 }
887 #endif /* CONFIG_PROC_FS */
888
889 LUSTRE_OBD_UINT_PARAM_ATTR(at_min);
890 LUSTRE_OBD_UINT_PARAM_ATTR(at_max);
891 LUSTRE_OBD_UINT_PARAM_ATTR(at_history);
892 LUSTRE_OBD_UINT_PARAM_ATTR(ldlm_enqueue_min);
893
894 static struct attribute *osc_attrs[] = {
895         &lustre_attr_active.attr,
896         &lustre_attr_enable_page_cache_shrink.attr,
897         &lustre_attr_checksums.attr,
898         &lustre_attr_checksum_dump.attr,
899         &lustre_attr_cur_dirty_bytes.attr,
900         &lustre_attr_cur_lost_grant_bytes.attr,
901         &lustre_attr_cur_dirty_grant_bytes.attr,
902         &lustre_attr_destroys_in_flight.attr,
903         &lustre_attr_grant_shrink_interval.attr,
904         &lustre_attr_max_dirty_mb.attr,
905         &lustre_attr_max_rpcs_in_flight.attr,
906         &lustre_attr_short_io_bytes.attr,
907         &lustre_attr_resend_count.attr,
908         &lustre_attr_ost_conn_uuid.attr,
909         &lustre_attr_conn_uuid.attr,
910         &lustre_attr_ping.attr,
911         &lustre_attr_idle_timeout.attr,
912         &lustre_attr_idle_connect.attr,
913         &lustre_attr_grant_shrink.attr,
914         &lustre_attr_at_max.attr,
915         &lustre_attr_at_min.attr,
916         &lustre_attr_at_history.attr,
917         &lustre_attr_ldlm_enqueue_min.attr,
918         NULL,
919 };
920
921 KOBJ_ATTRIBUTE_GROUPS(osc); /* creates osc_groups */
922
923 int osc_tunables_init(struct obd_device *obd)
924 {
925         int rc;
926
927         obd->obd_vars = lprocfs_osc_obd_vars;
928         obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(osc);
929         rc = lprocfs_obd_setup(obd, false);
930         if (rc)
931                 return rc;
932 #ifdef CONFIG_PROC_FS
933         /* If the basic OSC proc tree construction succeeded then
934          * lets do the rest.
935          */
936         rc = lprocfs_osc_attach_seqstat(obd);
937         if (rc)
938                 goto obd_cleanup;
939
940 #endif /* CONFIG_PROC_FS */
941         rc = sptlrpc_lprocfs_cliobd_attach(obd);
942         if (rc)
943                 goto obd_cleanup;
944
945         ptlrpc_lprocfs_register_obd(obd);
946 obd_cleanup:
947         if (rc)
948                 lprocfs_obd_cleanup(obd);
949         return rc;
950 }