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