Whamcloud - gitweb
796a68d3b21ed5144dab12d253ca61923fa5a1fb
[fs/lustre-release.git] / lustre / mdc / lproc_mdc.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31 #define DEBUG_SUBSYSTEM S_CLASS
32
33 #include <linux/vfs.h>
34 #include <obd_class.h>
35 #include <obd_cksum.h>
36 #include <lprocfs_status.h>
37 #include <lustre_osc.h>
38 #include <cl_object.h>
39 #include "mdc_internal.h"
40
41 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
42                            char *buf)
43 {
44         struct obd_device *obd = container_of(kobj, struct obd_device,
45                                               obd_kset.kobj);
46         struct obd_import *imp;
47         ssize_t len;
48
49         with_imp_locked(obd, imp, len)
50                 len = sprintf(buf, "%d\n", !imp->imp_deactive);
51         return len;
52 }
53
54 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
55                             const char *buffer, size_t count)
56 {
57         struct obd_device *obd = container_of(kobj, struct obd_device,
58                                               obd_kset.kobj);
59         struct obd_import *imp, *imp0;
60         bool val;
61         int rc;
62
63         rc = kstrtobool(buffer, &val);
64         if (rc)
65                 return rc;
66
67         with_imp_locked(obd, imp0, rc)
68                 imp = class_import_get(imp0);
69         if (rc)
70                 return rc;
71         /* opposite senses */
72         if (imp->imp_deactive == val)
73                 rc = ptlrpc_set_import_active(imp, val);
74         else
75                 CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
76                        val);
77         class_import_put(imp);
78         return rc ?: count;
79 }
80 LUSTRE_RW_ATTR(active);
81
82 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
83                                        struct attribute *attr,
84                                        char *buf)
85 {
86         struct obd_device *obd = container_of(kobj, struct obd_device,
87                                               obd_kset.kobj);
88         ssize_t len;
89         u32 max;
90
91         max = obd_get_max_rpcs_in_flight(&obd->u.cli);
92         len = sprintf(buf, "%u\n", max);
93
94         return len;
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         unsigned int val;
105         int rc;
106
107         rc = kstrtouint(buffer, 10, &val);
108         if (rc)
109                 return rc;
110
111         rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
112         if (rc)
113                 count = rc;
114
115         return count;
116 }
117 LUSTRE_RW_ATTR(max_rpcs_in_flight);
118
119 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
120                                            struct attribute *attr,
121                                            char *buf)
122 {
123         struct obd_device *obd = container_of(kobj, struct obd_device,
124                                               obd_kset.kobj);
125         u16 max;
126
127         max = obd_get_max_mod_rpcs_in_flight(&obd->u.cli);
128         return sprintf(buf, "%hu\n", max);
129 }
130
131 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
132                                             struct attribute *attr,
133                                             const char *buffer,
134                                             size_t count)
135 {
136         struct obd_device *obd = container_of(kobj, struct obd_device,
137                                               obd_kset.kobj);
138         u16 val;
139         int rc;
140
141         rc = kstrtou16(buffer, 10, &val);
142         if (rc)
143                 return rc;
144
145         rc = obd_set_max_mod_rpcs_in_flight(&obd->u.cli, val);
146         if (rc)
147                 count = rc;
148
149         return count;
150 }
151 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
152
153 static int mdc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
154 {
155         struct obd_device *obd = m->private;
156         struct client_obd *cli = &obd->u.cli;
157
158         seq_printf(m, "%lu\n", PAGES_TO_MiB(cli->cl_dirty_max_pages));
159         return 0;
160 }
161
162 static ssize_t mdc_max_dirty_mb_seq_write(struct file *file,
163                                           const char __user *buffer,
164                                           size_t count, loff_t *off)
165 {
166         struct seq_file *sfl = file->private_data;
167         struct obd_device *obd = sfl->private;
168         struct client_obd *cli = &obd->u.cli;
169         char kernbuf[22] = "";
170         u64 pages_number;
171         int rc;
172
173         if (count >= sizeof(kernbuf))
174                 return -EINVAL;
175
176         if (copy_from_user(kernbuf, buffer, count))
177                 return -EFAULT;
178         kernbuf[count] = 0;
179
180         rc = sysfs_memparse(kernbuf, count, &pages_number, "MiB");
181         if (rc < 0)
182                 return rc;
183
184         /* MB -> pages */
185         pages_number = round_up(pages_number, 1024 * 1024) >> PAGE_SHIFT;
186         if (pages_number <= 0 ||
187             pages_number >= MiB_TO_PAGES(OSC_MAX_DIRTY_MB_MAX) ||
188             pages_number > cfs_totalram_pages() / 4) /* 1/4 of RAM */
189                 return -ERANGE;
190
191         spin_lock(&cli->cl_loi_list_lock);
192         cli->cl_dirty_max_pages = pages_number;
193         osc_wake_cache_waiters(cli);
194         spin_unlock(&cli->cl_loi_list_lock);
195
196         return count;
197 }
198 LPROC_SEQ_FOPS(mdc_max_dirty_mb);
199
200 DECLARE_CKSUM_NAME;
201
202 static int mdc_checksum_type_seq_show(struct seq_file *m, void *v)
203 {
204         struct obd_device *obd = m->private;
205         int i;
206
207         if (obd == NULL)
208                 return 0;
209
210         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
211                 if ((BIT(i) & obd->u.cli.cl_supp_cksum_types) == 0)
212                         continue;
213                 if (obd->u.cli.cl_cksum_type == BIT(i))
214                         seq_printf(m, "[%s] ", cksum_name[i]);
215                 else
216                         seq_printf(m, "%s ", cksum_name[i]);
217         }
218         seq_puts(m, "\n");
219
220         return 0;
221 }
222
223 static ssize_t mdc_checksum_type_seq_write(struct file *file,
224                                            const char __user *buffer,
225                                            size_t count, loff_t *off)
226 {
227         struct seq_file *m = file->private_data;
228         struct obd_device *obd = m->private;
229         char kernbuf[10];
230         int rc = -EINVAL;
231         int i;
232
233         if (obd == NULL)
234                 return 0;
235
236         if (count > sizeof(kernbuf) - 1)
237                 return -EINVAL;
238         if (copy_from_user(kernbuf, buffer, count))
239                 return -EFAULT;
240
241         if (count > 0 && kernbuf[count - 1] == '\n')
242                 kernbuf[count - 1] = '\0';
243         else
244                 kernbuf[count] = '\0';
245
246         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
247                 if (strcasecmp(kernbuf, cksum_name[i]) == 0) {
248                         obd->u.cli.cl_preferred_cksum_type = BIT(i);
249                         if (obd->u.cli.cl_supp_cksum_types & BIT(i)) {
250                                 obd->u.cli.cl_cksum_type = BIT(i);
251                                 rc = count;
252                         } else {
253                                 rc = -ENOTSUPP;
254                         }
255                         break;
256                 }
257         }
258
259         return rc;
260 }
261 LPROC_SEQ_FOPS(mdc_checksum_type);
262
263 static ssize_t checksums_show(struct kobject *kobj,
264                               struct attribute *attr, char *buf)
265 {
266         struct obd_device *obd = container_of(kobj, struct obd_device,
267                                               obd_kset.kobj);
268
269         return scnprintf(buf, PAGE_SIZE, "%d\n", !!obd->u.cli.cl_checksum);
270 }
271
272 static ssize_t checksums_store(struct kobject *kobj,
273                                struct attribute *attr,
274                                const char *buffer,
275                                size_t count)
276 {
277         struct obd_device *obd = container_of(kobj, struct obd_device,
278                                               obd_kset.kobj);
279         bool val;
280         int rc;
281
282         rc = kstrtobool(buffer, &val);
283         if (rc)
284                 return rc;
285
286         obd->u.cli.cl_checksum = val;
287
288         return count;
289 }
290 LUSTRE_RW_ATTR(checksums);
291
292 static ssize_t checksum_dump_show(struct kobject *kobj,
293                                   struct attribute *attr, char *buf)
294 {
295         struct obd_device *obd = container_of(kobj, struct obd_device,
296                                               obd_kset.kobj);
297
298         return scnprintf(buf, PAGE_SIZE, "%d\n", !!obd->u.cli.cl_checksum_dump);
299 }
300
301 static ssize_t checksum_dump_store(struct kobject *kobj,
302                                    struct attribute *attr,
303                                    const char *buffer,
304                                    size_t count)
305 {
306         struct obd_device *obd = container_of(kobj, struct obd_device,
307                                               obd_kset.kobj);
308         bool val;
309         int rc;
310
311         rc = kstrtobool(buffer, &val);
312         if (rc)
313                 return rc;
314
315         obd->u.cli.cl_checksum_dump = val;
316
317         return count;
318 }
319 LUSTRE_RW_ATTR(checksum_dump);
320
321 LUSTRE_ATTR(mds_conn_uuid, 0444, conn_uuid_show, NULL);
322 LUSTRE_RO_ATTR(conn_uuid);
323
324 LUSTRE_RW_ATTR(ping);
325
326 static int mdc_cached_mb_seq_show(struct seq_file *m, void *v)
327 {
328         struct obd_device *obd = m->private;
329         struct client_obd *cli = &obd->u.cli;
330         int shift = 20 - PAGE_SHIFT;
331
332         seq_printf(m, "used_mb: %ld\n"
333                    "busy_cnt: %ld\n"
334                    "reclaim: %llu\n",
335                    (atomic_long_read(&cli->cl_lru_in_list) +
336                     atomic_long_read(&cli->cl_lru_busy)) >> shift,
337                     atomic_long_read(&cli->cl_lru_busy),
338                    cli->cl_lru_reclaim);
339
340         return 0;
341 }
342
343 /* shrink the number of caching pages to a specific number */
344 static ssize_t
345 mdc_cached_mb_seq_write(struct file *file, const char __user *buffer,
346                         size_t count, loff_t *off)
347 {
348         struct seq_file *sfl = file->private_data;
349         struct obd_device *obd = sfl->private;
350         struct client_obd *cli = &obd->u.cli;
351         u64 pages_number;
352         const char *tmp;
353         long rc;
354         char kernbuf[128];
355
356         if (count >= sizeof(kernbuf))
357                 return -EINVAL;
358
359         if (copy_from_user(kernbuf, buffer, count))
360                 return -EFAULT;
361         kernbuf[count] = 0;
362
363         tmp = lprocfs_find_named_value(kernbuf, "used_mb:", &count);
364         rc = sysfs_memparse(tmp, count, &pages_number, "MiB");
365         if (rc < 0)
366                 return rc;
367
368         pages_number >>= PAGE_SHIFT;
369
370         rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
371         if (rc > 0) {
372                 struct lu_env *env;
373                 __u16 refcheck;
374
375                 env = cl_env_get(&refcheck);
376                 if (!IS_ERR(env)) {
377                         (void)osc_lru_shrink(env, cli, rc, true);
378                         cl_env_put(env, &refcheck);
379                 }
380         }
381
382         return count;
383 }
384 LPROC_SEQ_FOPS(mdc_cached_mb);
385
386 static int mdc_unstable_stats_seq_show(struct seq_file *m, void *v)
387 {
388         struct obd_device *obd = m->private;
389         struct client_obd *cli = &obd->u.cli;
390         long pages;
391         int mb;
392
393         pages = atomic_long_read(&cli->cl_unstable_count);
394         mb    = (pages * PAGE_SIZE) >> 20;
395
396         seq_printf(m, "unstable_pages: %20ld\n"
397                    "unstable_mb:              %10d\n", pages, mb);
398         return 0;
399 }
400 LPROC_SEQ_FOPS_RO(mdc_unstable_stats);
401
402 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
403                                        const char __user *buf,
404                                        size_t len, loff_t *off)
405 {
406         struct seq_file *seq = file->private_data;
407         struct obd_device *obd = seq->private;
408         struct client_obd *cli = &obd->u.cli;
409
410         lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
411
412         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
413         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
414         lprocfs_oh_clear(&cli->cl_read_page_hist);
415         lprocfs_oh_clear(&cli->cl_write_page_hist);
416         lprocfs_oh_clear(&cli->cl_read_offset_hist);
417         lprocfs_oh_clear(&cli->cl_write_offset_hist);
418
419         return len;
420 }
421
422 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
423 {
424         struct obd_device *obd = seq->private;
425         struct client_obd *cli = &obd->u.cli;
426         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
427         int i;
428
429         obd_mod_rpc_stats_seq_show(cli, seq);
430
431         spin_lock(&cli->cl_loi_list_lock);
432
433         seq_printf(seq, "\nread RPCs in flight:  %d\n",
434                    cli->cl_r_in_flight);
435         seq_printf(seq, "write RPCs in flight: %d\n",
436                    cli->cl_w_in_flight);
437         seq_printf(seq, "pending write pages:  %d\n",
438                    atomic_read(&cli->cl_pending_w_pages));
439         seq_printf(seq, "pending read pages:   %d\n",
440                    atomic_read(&cli->cl_pending_r_pages));
441
442         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
443         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
444         seq_printf(seq, "       rpcs   %% cum %%\n");
445
446         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
447         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
448
449         read_cum = 0;
450         write_cum = 0;
451         for (i = 0; i < OBD_HIST_MAX; i++) {
452                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
453                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
454
455                 read_cum += r;
456                 write_cum += w;
457                 seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
458                            1 << i, r, pct(r, read_tot),
459                            pct(read_cum, read_tot), w,
460                            pct(w, write_tot),
461                            pct(write_cum, write_tot));
462                 if (read_cum == read_tot && write_cum == write_tot)
463                         break;
464         }
465
466         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
467         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
468         seq_printf(seq, "       rpcs   %% cum %%\n");
469
470         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
471         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
472
473         read_cum = 0;
474         write_cum = 0;
475         for (i = 1; i < OBD_HIST_MAX; i++) {
476                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
477                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
478
479                 read_cum += r;
480                 write_cum += w;
481                 seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
482                            i, r, pct(r, read_tot), pct(read_cum, read_tot), w,
483                            pct(w, write_tot), pct(write_cum, write_tot));
484                 if (read_cum == read_tot && write_cum == write_tot)
485                         break;
486         }
487
488         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
489         seq_printf(seq, "offset                rpcs   %% cum %% |");
490         seq_printf(seq, "       rpcs   %% cum %%\n");
491
492         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
493         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
494
495         read_cum = 0;
496         write_cum = 0;
497         for (i = 0; i < OBD_HIST_MAX; i++) {
498                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
499                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
500
501                 read_cum += r;
502                 write_cum += w;
503                 seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
504                            (i == 0) ? 0 : 1 << (i - 1),
505                            r, pct(r, read_tot), pct(read_cum, read_tot),
506                            w, pct(w, write_tot), pct(write_cum, write_tot));
507                 if (read_cum == read_tot && write_cum == write_tot)
508                         break;
509         }
510         spin_unlock(&cli->cl_loi_list_lock);
511
512         return 0;
513 }
514 LPROC_SEQ_FOPS(mdc_rpc_stats);
515
516 static int mdc_stats_seq_show(struct seq_file *seq, void *v)
517 {
518         struct timespec64 now;
519         struct obd_device *obd = seq->private;
520         struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
521
522         ktime_get_real_ts64(&now);
523
524         seq_printf(seq, "snapshot_time:         %lld.%09lu (secs.nsecs)\n",
525                    (s64)now.tv_sec, now.tv_nsec);
526         seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
527                    stats->os_lockless_writes);
528         seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
529                    stats->os_lockless_reads);
530         return 0;
531 }
532
533 static ssize_t mdc_stats_seq_write(struct file *file,
534                                    const char __user *buf,
535                                    size_t len, loff_t *off)
536 {
537         struct seq_file *seq = file->private_data;
538         struct obd_device *obd = seq->private;
539         struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
540
541         memset(stats, 0, sizeof(*stats));
542         return len;
543 }
544 LPROC_SEQ_FOPS(mdc_stats);
545
546 static int mdc_dom_min_repsize_seq_show(struct seq_file *m, void *v)
547 {
548         struct obd_device *obd = m->private;
549
550         seq_printf(m, "%u\n", obd->u.cli.cl_dom_min_inline_repsize);
551
552         return 0;
553 }
554
555 static ssize_t mdc_dom_min_repsize_seq_write(struct file *file,
556                                              const char __user *buffer,
557                                              size_t count, loff_t *off)
558 {
559         struct seq_file *m = file->private_data;
560         struct obd_device *obd = m->private;
561         unsigned int val;
562         int rc;
563
564         rc = kstrtouint_from_user(buffer, count, 0, &val);
565         if (rc)
566                 return rc;
567
568         if (val > MDC_DOM_MAX_INLINE_REPSIZE)
569                 return -ERANGE;
570
571         obd->u.cli.cl_dom_min_inline_repsize = val;
572         return count;
573 }
574 LPROC_SEQ_FOPS(mdc_dom_min_repsize);
575
576 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
577 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
578 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
579 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
580 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
581 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
582 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
583
584 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
585         { .name =       "connect_flags",
586           .fops =       &mdc_connect_flags_fops },
587         { .name =       "mds_server_uuid",
588           .fops =       &mdc_server_uuid_fops   },
589         { .name =       "max_pages_per_rpc",
590           .fops =       &mdc_obd_max_pages_per_rpc_fops },
591         { .name =       "max_dirty_mb",
592           .fops =       &mdc_max_dirty_mb_fops          },
593         { .name =       "mdc_cached_mb",
594           .fops =       &mdc_cached_mb_fops             },
595         { .name =       "checksum_type",
596           .fops =       &mdc_checksum_type_fops         },
597         { .name =       "timeouts",
598           .fops =       &mdc_timeouts_fops              },
599         { .name =       "import",
600           .fops =       &mdc_import_fops                },
601         { .name =       "state",
602           .fops =       &mdc_state_fops                 },
603         { .name =       "pinger_recov",
604           .fops =       &mdc_pinger_recov_fops          },
605         { .name =       "rpc_stats",
606           .fops =       &mdc_rpc_stats_fops             },
607         { .name =       "unstable_stats",
608           .fops =       &mdc_unstable_stats_fops        },
609         { .name =       "mdc_stats",
610           .fops =       &mdc_stats_fops                 },
611         { .name =       "mdc_dom_min_repsize",
612           .fops =       &mdc_dom_min_repsize_fops       },
613         { NULL }
614 };
615
616 static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj,
617                                          struct attribute *attr,
618                                          char *buf)
619 {
620         struct obd_device *obd = container_of(kobj, struct obd_device,
621                                               obd_kset.kobj);
622         struct client_obd *cli = &obd->u.cli;
623
624         return scnprintf(buf, PAGE_SIZE, "%lu\n", cli->cl_lost_grant);
625 }
626 LUSTRE_RO_ATTR(cur_lost_grant_bytes);
627
628 static ssize_t cur_dirty_grant_bytes_show(struct kobject *kobj,
629                                           struct attribute *attr,
630                                           char *buf)
631 {
632         struct obd_device *obd = container_of(kobj, struct obd_device,
633                                               obd_kset.kobj);
634         struct client_obd *cli = &obd->u.cli;
635
636         return scnprintf(buf, PAGE_SIZE, "%lu\n", cli->cl_dirty_grant);
637 }
638 LUSTRE_RO_ATTR(cur_dirty_grant_bytes);
639
640 static ssize_t grant_shrink_show(struct kobject *kobj, struct attribute *attr,
641                                  char *buf)
642 {
643         struct obd_device *obd = container_of(kobj, struct obd_device,
644                                               obd_kset.kobj);
645         struct obd_import *imp;
646         ssize_t len;
647
648         with_imp_locked(obd, imp, len)
649                 len = scnprintf(buf, PAGE_SIZE, "%d\n",
650                                 !imp->imp_grant_shrink_disabled &&
651                                 OCD_HAS_FLAG(&imp->imp_connect_data,
652                                              GRANT_SHRINK));
653
654         return len;
655 }
656
657 static ssize_t grant_shrink_store(struct kobject *kobj, struct attribute *attr,
658                                   const char *buffer, size_t count)
659 {
660         struct obd_device *obd = container_of(kobj, struct obd_device,
661                                               obd_kset.kobj);
662         struct obd_import *imp;
663         bool val;
664         int rc;
665
666         if (obd == NULL)
667                 return 0;
668
669         rc = kstrtobool(buffer, &val);
670         if (rc)
671                 return rc;
672
673         with_imp_locked(obd, imp, rc) {
674                 spin_lock(&imp->imp_lock);
675                 imp->imp_grant_shrink_disabled = !val;
676                 spin_unlock(&imp->imp_lock);
677         }
678
679         return rc ?: count;
680 }
681 LUSTRE_RW_ATTR(grant_shrink);
682
683 static ssize_t grant_shrink_interval_show(struct kobject *kobj,
684                                           struct attribute *attr,
685                                           char *buf)
686 {
687         struct obd_device *obd = container_of(kobj, struct obd_device,
688                                               obd_kset.kobj);
689
690         return sprintf(buf, "%lld\n", obd->u.cli.cl_grant_shrink_interval);
691 }
692
693 static ssize_t grant_shrink_interval_store(struct kobject *kobj,
694                                            struct attribute *attr,
695                                            const char *buffer,
696                                            size_t count)
697 {
698         struct obd_device *obd = container_of(kobj, struct obd_device,
699                                               obd_kset.kobj);
700         unsigned int val;
701         int rc;
702
703         rc = kstrtouint(buffer, 0, &val);
704         if (rc)
705                 return rc;
706
707         if (val == 0)
708                 return -ERANGE;
709
710         obd->u.cli.cl_grant_shrink_interval = val;
711         osc_update_next_shrink(&obd->u.cli);
712         osc_schedule_grant_work();
713
714         return count;
715 }
716 LUSTRE_RW_ATTR(grant_shrink_interval);
717
718 static struct attribute *mdc_attrs[] = {
719         &lustre_attr_active.attr,
720         &lustre_attr_checksums.attr,
721         &lustre_attr_checksum_dump.attr,
722         &lustre_attr_max_rpcs_in_flight.attr,
723         &lustre_attr_max_mod_rpcs_in_flight.attr,
724         &lustre_attr_mds_conn_uuid.attr,
725         &lustre_attr_conn_uuid.attr,
726         &lustre_attr_ping.attr,
727         &lustre_attr_grant_shrink.attr,
728         &lustre_attr_grant_shrink_interval.attr,
729         &lustre_attr_cur_lost_grant_bytes.attr,
730         &lustre_attr_cur_dirty_grant_bytes.attr,
731         NULL,
732 };
733
734 int mdc_tunables_init(struct obd_device *obd)
735 {
736         int rc;
737
738         obd->obd_ktype.default_attrs = mdc_attrs;
739         obd->obd_vars = lprocfs_mdc_obd_vars;
740
741         rc = lprocfs_obd_setup(obd, false);
742         if (rc)
743                 goto out_failed;
744 #ifdef CONFIG_PROC_FS
745         rc = lprocfs_alloc_md_stats(obd, 0);
746         if (rc) {
747                 lprocfs_obd_cleanup(obd);
748                 goto out_failed;
749         }
750 #endif
751         rc = sptlrpc_lprocfs_cliobd_attach(obd);
752         if (rc) {
753 #ifdef CONFIG_PROC_FS
754                 lprocfs_free_md_stats(obd);
755 #endif
756                 lprocfs_obd_cleanup(obd);
757                 goto out_failed;
758         }
759         ptlrpc_lprocfs_register_obd(obd);
760
761 out_failed:
762         return rc;
763 }