Whamcloud - gitweb
LU-14838 osc: Remove lockless truncate
[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 (strcmp(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 static ssize_t contention_seconds_show(struct kobject *kobj,
322                                        struct attribute *attr,
323                                        char *buf)
324 {
325         struct obd_device *obd = container_of(kobj, struct obd_device,
326                                               obd_kset.kobj);
327         struct osc_device *od = obd2osc_dev(obd);
328
329         return sprintf(buf, "%lld\n", od->od_contention_time);
330 }
331
332 static ssize_t contention_seconds_store(struct kobject *kobj,
333                                         struct attribute *attr,
334                                         const char *buffer,
335                                         size_t count)
336 {
337         struct obd_device *obd = container_of(kobj, struct obd_device,
338                                               obd_kset.kobj);
339         struct osc_device *od = obd2osc_dev(obd);
340         time64_t val;
341         int rc;
342
343         rc = kstrtoll(buffer, 0, &val);
344         if (rc)
345                 return rc;
346
347         od->od_contention_time = val;
348
349         return count;
350 }
351 LUSTRE_RW_ATTR(contention_seconds);
352
353 LUSTRE_ATTR(mds_conn_uuid, 0444, conn_uuid_show, NULL);
354 LUSTRE_RO_ATTR(conn_uuid);
355
356 LUSTRE_RW_ATTR(ping);
357
358 static int mdc_cached_mb_seq_show(struct seq_file *m, void *v)
359 {
360         struct obd_device *obd = m->private;
361         struct client_obd *cli = &obd->u.cli;
362         int shift = 20 - PAGE_SHIFT;
363
364         seq_printf(m, "used_mb: %ld\n"
365                    "busy_cnt: %ld\n"
366                    "reclaim: %llu\n",
367                    (atomic_long_read(&cli->cl_lru_in_list) +
368                     atomic_long_read(&cli->cl_lru_busy)) >> shift,
369                     atomic_long_read(&cli->cl_lru_busy),
370                    cli->cl_lru_reclaim);
371
372         return 0;
373 }
374
375 /* shrink the number of caching pages to a specific number */
376 static ssize_t
377 mdc_cached_mb_seq_write(struct file *file, const char __user *buffer,
378                         size_t count, loff_t *off)
379 {
380         struct seq_file *sfl = file->private_data;
381         struct obd_device *obd = sfl->private;
382         struct client_obd *cli = &obd->u.cli;
383         u64 pages_number;
384         const char *tmp;
385         long rc;
386         char kernbuf[128];
387
388         if (count >= sizeof(kernbuf))
389                 return -EINVAL;
390
391         if (copy_from_user(kernbuf, buffer, count))
392                 return -EFAULT;
393         kernbuf[count] = 0;
394
395         tmp = lprocfs_find_named_value(kernbuf, "used_mb:", &count);
396         rc = sysfs_memparse(tmp, count, &pages_number, "MiB");
397         if (rc < 0)
398                 return rc;
399
400         pages_number >>= PAGE_SHIFT;
401
402         rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
403         if (rc > 0) {
404                 struct lu_env *env;
405                 __u16 refcheck;
406
407                 env = cl_env_get(&refcheck);
408                 if (!IS_ERR(env)) {
409                         (void)osc_lru_shrink(env, cli, rc, true);
410                         cl_env_put(env, &refcheck);
411                 }
412         }
413
414         return count;
415 }
416 LPROC_SEQ_FOPS(mdc_cached_mb);
417
418 static int mdc_unstable_stats_seq_show(struct seq_file *m, void *v)
419 {
420         struct obd_device *obd = m->private;
421         struct client_obd *cli = &obd->u.cli;
422         long pages;
423         int mb;
424
425         pages = atomic_long_read(&cli->cl_unstable_count);
426         mb    = (pages * PAGE_SIZE) >> 20;
427
428         seq_printf(m, "unstable_pages: %20ld\n"
429                    "unstable_mb:              %10d\n", pages, mb);
430         return 0;
431 }
432 LPROC_SEQ_FOPS_RO(mdc_unstable_stats);
433
434 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
435                                        const char __user *buf,
436                                        size_t len, loff_t *off)
437 {
438         struct seq_file *seq = file->private_data;
439         struct obd_device *obd = seq->private;
440         struct client_obd *cli = &obd->u.cli;
441
442         lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
443
444         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
445         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
446         lprocfs_oh_clear(&cli->cl_read_page_hist);
447         lprocfs_oh_clear(&cli->cl_write_page_hist);
448         lprocfs_oh_clear(&cli->cl_read_offset_hist);
449         lprocfs_oh_clear(&cli->cl_write_offset_hist);
450
451         return len;
452 }
453
454 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
455 {
456         struct obd_device *obd = seq->private;
457         struct client_obd *cli = &obd->u.cli;
458         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
459         int i;
460
461         obd_mod_rpc_stats_seq_show(cli, seq);
462
463         spin_lock(&cli->cl_loi_list_lock);
464
465         seq_printf(seq, "\nread RPCs in flight:  %d\n",
466                    cli->cl_r_in_flight);
467         seq_printf(seq, "write RPCs in flight: %d\n",
468                    cli->cl_w_in_flight);
469         seq_printf(seq, "pending write pages:  %d\n",
470                    atomic_read(&cli->cl_pending_w_pages));
471         seq_printf(seq, "pending read pages:   %d\n",
472                    atomic_read(&cli->cl_pending_r_pages));
473
474         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
475         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
476         seq_printf(seq, "       rpcs   %% cum %%\n");
477
478         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
479         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
480
481         read_cum = 0;
482         write_cum = 0;
483         for (i = 0; i < OBD_HIST_MAX; i++) {
484                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
485                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
486
487                 read_cum += r;
488                 write_cum += w;
489                 seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
490                            1 << i, r, pct(r, read_tot),
491                            pct(read_cum, read_tot), w,
492                            pct(w, write_tot),
493                            pct(write_cum, write_tot));
494                 if (read_cum == read_tot && write_cum == write_tot)
495                         break;
496         }
497
498         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
499         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
500         seq_printf(seq, "       rpcs   %% cum %%\n");
501
502         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
503         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
504
505         read_cum = 0;
506         write_cum = 0;
507         for (i = 1; i < OBD_HIST_MAX; i++) {
508                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
509                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
510
511                 read_cum += r;
512                 write_cum += w;
513                 seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
514                            i, r, pct(r, read_tot), pct(read_cum, read_tot), w,
515                            pct(w, write_tot), pct(write_cum, write_tot));
516                 if (read_cum == read_tot && write_cum == write_tot)
517                         break;
518         }
519
520         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
521         seq_printf(seq, "offset                rpcs   %% cum %% |");
522         seq_printf(seq, "       rpcs   %% cum %%\n");
523
524         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
525         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
526
527         read_cum = 0;
528         write_cum = 0;
529         for (i = 0; i < OBD_HIST_MAX; i++) {
530                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
531                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
532
533                 read_cum += r;
534                 write_cum += w;
535                 seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
536                            (i == 0) ? 0 : 1 << (i - 1),
537                            r, pct(r, read_tot), pct(read_cum, read_tot),
538                            w, pct(w, write_tot), pct(write_cum, write_tot));
539                 if (read_cum == read_tot && write_cum == write_tot)
540                         break;
541         }
542         spin_unlock(&cli->cl_loi_list_lock);
543
544         return 0;
545 }
546 LPROC_SEQ_FOPS(mdc_rpc_stats);
547
548 static int mdc_stats_seq_show(struct seq_file *seq, void *v)
549 {
550         struct timespec64 now;
551         struct obd_device *obd = seq->private;
552         struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
553
554         ktime_get_real_ts64(&now);
555
556         seq_printf(seq, "snapshot_time:         %lld.%09lu (secs.nsecs)\n",
557                    (s64)now.tv_sec, now.tv_nsec);
558         seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
559                    stats->os_lockless_writes);
560         seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
561                    stats->os_lockless_reads);
562         return 0;
563 }
564
565 static ssize_t mdc_stats_seq_write(struct file *file,
566                                    const char __user *buf,
567                                    size_t len, loff_t *off)
568 {
569         struct seq_file *seq = file->private_data;
570         struct obd_device *obd = seq->private;
571         struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
572
573         memset(stats, 0, sizeof(*stats));
574         return len;
575 }
576 LPROC_SEQ_FOPS(mdc_stats);
577
578 static int mdc_dom_min_repsize_seq_show(struct seq_file *m, void *v)
579 {
580         struct obd_device *obd = m->private;
581
582         seq_printf(m, "%u\n", obd->u.cli.cl_dom_min_inline_repsize);
583
584         return 0;
585 }
586
587 static ssize_t mdc_dom_min_repsize_seq_write(struct file *file,
588                                              const char __user *buffer,
589                                              size_t count, loff_t *off)
590 {
591         struct seq_file *m = file->private_data;
592         struct obd_device *obd = m->private;
593         unsigned int val;
594         int rc;
595
596         rc = kstrtouint_from_user(buffer, count, 0, &val);
597         if (rc)
598                 return rc;
599
600         if (val > MDC_DOM_MAX_INLINE_REPSIZE)
601                 return -ERANGE;
602
603         obd->u.cli.cl_dom_min_inline_repsize = val;
604         return count;
605 }
606 LPROC_SEQ_FOPS(mdc_dom_min_repsize);
607
608 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
609 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
610 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
611 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
612 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
613 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
614 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
615
616 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
617         { .name =       "connect_flags",
618           .fops =       &mdc_connect_flags_fops },
619         { .name =       "mds_server_uuid",
620           .fops =       &mdc_server_uuid_fops   },
621         { .name =       "max_pages_per_rpc",
622           .fops =       &mdc_obd_max_pages_per_rpc_fops },
623         { .name =       "max_dirty_mb",
624           .fops =       &mdc_max_dirty_mb_fops          },
625         { .name =       "mdc_cached_mb",
626           .fops =       &mdc_cached_mb_fops             },
627         { .name =       "checksum_type",
628           .fops =       &mdc_checksum_type_fops         },
629         { .name =       "timeouts",
630           .fops =       &mdc_timeouts_fops              },
631         { .name =       "import",
632           .fops =       &mdc_import_fops                },
633         { .name =       "state",
634           .fops =       &mdc_state_fops                 },
635         { .name =       "pinger_recov",
636           .fops =       &mdc_pinger_recov_fops          },
637         { .name =       "rpc_stats",
638           .fops =       &mdc_rpc_stats_fops             },
639         { .name =       "unstable_stats",
640           .fops =       &mdc_unstable_stats_fops        },
641         { .name =       "mdc_stats",
642           .fops =       &mdc_stats_fops                 },
643         { .name =       "mdc_dom_min_repsize",
644           .fops =       &mdc_dom_min_repsize_fops       },
645         { NULL }
646 };
647
648 static struct attribute *mdc_attrs[] = {
649         &lustre_attr_active.attr,
650         &lustre_attr_checksums.attr,
651         &lustre_attr_checksum_dump.attr,
652         &lustre_attr_max_rpcs_in_flight.attr,
653         &lustre_attr_max_mod_rpcs_in_flight.attr,
654         &lustre_attr_contention_seconds.attr,
655         &lustre_attr_mds_conn_uuid.attr,
656         &lustre_attr_conn_uuid.attr,
657         &lustre_attr_ping.attr,
658         NULL,
659 };
660
661 int mdc_tunables_init(struct obd_device *obd)
662 {
663         int rc;
664
665         obd->obd_ktype.default_attrs = mdc_attrs;
666         obd->obd_vars = lprocfs_mdc_obd_vars;
667
668         rc = lprocfs_obd_setup(obd, false);
669         if (rc)
670                 goto out_failed;
671 #ifdef CONFIG_PROC_FS
672         rc = lprocfs_alloc_md_stats(obd, 0);
673         if (rc) {
674                 lprocfs_obd_cleanup(obd);
675                 goto out_failed;
676         }
677 #endif
678         rc = sptlrpc_lprocfs_cliobd_attach(obd);
679         if (rc) {
680 #ifdef CONFIG_PROC_FS
681                 lprocfs_free_md_stats(obd);
682 #endif
683                 lprocfs_obd_cleanup(obd);
684                 goto out_failed;
685         }
686         ptlrpc_lprocfs_register_obd(obd);
687
688 out_failed:
689         return rc;
690 }