Whamcloud - gitweb
2865fbd94fb20b49e217985d44f2bb13f1e4cfb4
[fs/lustre-release.git] / lustre / mdd / mdd_lproc.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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * lustre/mdd/mdd_lproc.c
32  *
33  * Lustre Metadata Server (mdd) routines
34  *
35  * Author: Wang Di <wangdi@clusterfs.com>
36  */
37
38 #define DEBUG_SUBSYSTEM S_MDS
39
40 #include <obd.h>
41 #include <obd_class.h>
42 #include <obd_support.h>
43 #include <lprocfs_status.h>
44 #include <libcfs/libcfs_string.h>
45 #include "mdd_internal.h"
46
47 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
48                          char *buf)
49 {
50         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
51                                               mdd_kobj);
52         struct obd_device *obd = mdd2obd_dev(mdd);
53
54         return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
55 }
56 LUSTRE_RO_ATTR(uuid);
57
58 static ssize_t atime_diff_show(struct kobject *kobj, struct attribute *attr,
59                                char *buf)
60 {
61         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
62                                               mdd_kobj);
63
64         return sprintf(buf, "%lld\n", mdd->mdd_atime_diff);
65 }
66
67 static ssize_t atime_diff_store(struct kobject *kobj,
68                                 struct attribute *attr,
69                                 const char *buffer, size_t count)
70 {
71         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
72                                               mdd_kobj);
73         time64_t diff = 0;
74         int rc;
75
76         rc = kstrtoll(buffer, 10, &diff);
77         if (rc)
78                 return rc;
79
80         mdd->mdd_atime_diff = diff;
81         return count;
82 }
83 LUSTRE_RW_ATTR(atime_diff);
84
85 /**** changelogs ****/
86 static int mdd_changelog_mask_seq_show(struct seq_file *m, void *data)
87 {
88         struct mdd_device *mdd = m->private;
89         int i = 0;
90
91         while (i < CL_LAST) {
92                 if (mdd->mdd_cl.mc_mask & BIT(i))
93                         seq_printf(m, "%s ", changelog_type2str(i));
94                 i++;
95         }
96         seq_putc(m, '\n');
97         return 0;
98 }
99
100 static ssize_t
101 mdd_changelog_mask_seq_write(struct file *file, const char __user *buffer,
102                              size_t count, loff_t *off)
103 {
104         struct seq_file *m = file->private_data;
105         struct mdd_device *mdd = m->private;
106         char *kernbuf;
107         int rc;
108         ENTRY;
109
110         if (count >= PAGE_SIZE)
111                 RETURN(-EINVAL);
112         OBD_ALLOC(kernbuf, PAGE_SIZE);
113         if (kernbuf == NULL)
114                 RETURN(-ENOMEM);
115         if (copy_from_user(kernbuf, buffer, count))
116                 GOTO(out, rc = -EFAULT);
117         kernbuf[count] = 0;
118
119         rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
120                           CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
121         if (rc == 0)
122                 rc = count;
123 out:
124         OBD_FREE(kernbuf, PAGE_SIZE);
125         return rc;
126 }
127 LDEBUGFS_SEQ_FOPS(mdd_changelog_mask);
128
129 static int lprocfs_changelog_users_cb(const struct lu_env *env,
130                                       struct llog_handle *llh,
131                                       struct llog_rec_hdr *hdr, void *data)
132 {
133         struct llog_changelog_user_rec *rec;
134         struct seq_file *m = data;
135
136         LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
137
138         rec = (struct llog_changelog_user_rec *)hdr;
139
140         seq_printf(m, CHANGELOG_USER_PREFIX"%-3d %llu (%u)\n",
141                    rec->cur_id, rec->cur_endrec, (__u32)get_seconds() -
142                                                  rec->cur_time);
143         return 0;
144 }
145
146 static int mdd_changelog_users_seq_show(struct seq_file *m, void *data)
147 {
148         struct lu_env            env;
149         struct mdd_device       *mdd = m->private;
150         struct llog_ctxt        *ctxt;
151         __u64                    cur;
152         int                      rc;
153
154         ctxt = llog_get_context(mdd2obd_dev(mdd),
155                                 LLOG_CHANGELOG_USER_ORIG_CTXT);
156         if (ctxt == NULL)
157                 return -ENXIO;
158         LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
159
160         rc = lu_env_init(&env, LCT_LOCAL);
161         if (rc) {
162                 llog_ctxt_put(ctxt);
163                 return rc;
164         }
165
166         spin_lock(&mdd->mdd_cl.mc_lock);
167         cur = mdd->mdd_cl.mc_index;
168         spin_unlock(&mdd->mdd_cl.mc_lock);
169
170         seq_printf(m, "current index: %llu\n", cur);
171         seq_printf(m, "%-5s %s %s\n", "ID", "index", "(idle seconds)");
172
173         llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb,
174                          m, 0, 0);
175
176         lu_env_fini(&env);
177         llog_ctxt_put(ctxt);
178         return 0;
179 }
180 LDEBUGFS_SEQ_FOPS_RO(mdd_changelog_users);
181
182 static int mdd_changelog_size_ctxt(const struct lu_env *env,
183                                    struct mdd_device *mdd,
184                                    int index, __u64 *val)
185 {
186         struct llog_ctxt        *ctxt;
187
188         ctxt = llog_get_context(mdd2obd_dev(mdd),
189                                 index);
190         if (ctxt == NULL)
191                 return -ENXIO;
192
193         if (!(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) {
194                 CERROR("%s: ChangeLog has wrong flags: rc = %d\n",
195                        ctxt->loc_obd->obd_name, -EINVAL);
196                 llog_ctxt_put(ctxt);
197                 return -EINVAL;
198         }
199
200         *val += llog_cat_size(env, ctxt->loc_handle);
201
202         llog_ctxt_put(ctxt);
203
204         return 0;
205 }
206
207 static ssize_t changelog_size_show(struct kobject *kobj,
208                                    struct attribute *attr,
209                                    char *buf)
210 {
211         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
212                                               mdd_kobj);
213         struct lu_env env;
214         u64 tmp = 0;
215         int rc;
216
217         rc = lu_env_init(&env, LCT_LOCAL);
218         if (rc)
219                 return rc;
220
221         rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_ORIG_CTXT, &tmp);
222         if (rc) {
223                 lu_env_fini(&env);
224                 return rc;
225         }
226
227         rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_USER_ORIG_CTXT,
228                                      &tmp);
229
230         rc = sprintf(buf, "%llu\n", tmp);
231         lu_env_fini(&env);
232         return rc;
233 }
234 LUSTRE_RO_ATTR(changelog_size);
235
236 static ssize_t changelog_gc_show(struct kobject *kobj,
237                                  struct attribute *attr,
238                                  char *buf)
239 {
240         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
241                                               mdd_kobj);
242
243         return sprintf(buf, "%u\n", mdd->mdd_changelog_gc);
244 }
245
246 static ssize_t changelog_gc_store(struct kobject *kobj,
247                                   struct attribute *attr,
248                                   const char *buffer, size_t count)
249 {
250         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
251                                               mdd_kobj);
252         bool val;
253         int rc;
254
255         rc = kstrtobool(buffer, &val);
256         if (rc)
257                 return rc;
258
259         mdd->mdd_changelog_gc = val;
260
261         return count;
262 }
263 LUSTRE_RW_ATTR(changelog_gc);
264
265 static ssize_t changelog_max_idle_time_show(struct kobject *kobj,
266                                             struct attribute *attr,
267                                             char *buf)
268 {
269         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
270                                               mdd_kobj);
271
272         return sprintf(buf, "%lld\n", mdd->mdd_changelog_max_idle_time);
273 }
274
275 static ssize_t changelog_max_idle_time_store(struct kobject *kobj,
276                                              struct attribute *attr,
277                                              const char *buffer, size_t count)
278 {
279         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
280                                               mdd_kobj);
281         time64_t val;
282         int rc;
283
284         rc = kstrtoll(buffer, 10, &val);
285         if (rc)
286                 return rc;
287
288         /* as it sounds reasonable, do not allow a user to be idle since
289          * more than about 68 years, this will allow to use 32bits
290          * timestamps for comparison
291          */
292         if (val < 1 || val > INT_MAX)
293                 return -ERANGE;
294
295         mdd->mdd_changelog_max_idle_time = val;
296
297         return count;
298 }
299 LUSTRE_RW_ATTR(changelog_max_idle_time);
300
301 static ssize_t changelog_max_idle_indexes_show(struct kobject *kobj,
302                                                struct attribute *attr,
303                                                char *buf)
304 {
305         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
306                                               mdd_kobj);
307
308         return sprintf(buf, "%lu\n", mdd->mdd_changelog_max_idle_indexes);
309 }
310
311 static ssize_t changelog_max_idle_indexes_store(struct kobject *kobj,
312                                                 struct attribute *attr,
313                                                 const char *buffer,
314                                                 size_t count)
315 {
316         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
317                                               mdd_kobj);
318         unsigned long val;
319         int rc;
320
321         LASSERT(mdd != NULL);
322         rc = kstrtoul(buffer, 0, &val);
323         if (rc)
324                 return rc;
325
326         /* XXX may need to limit/check with reasonable elapsed/idle indexes */
327         /* XXX may better allow to specify a % of full ChangeLogs */
328
329         mdd->mdd_changelog_max_idle_indexes = val;
330
331         return count;
332 }
333 LUSTRE_RW_ATTR(changelog_max_idle_indexes);
334
335 static ssize_t changelog_min_gc_interval_show(struct kobject *kobj,
336                                               struct attribute *attr,
337                                               char *buf)
338 {
339         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
340                                               mdd_kobj);
341
342         return sprintf(buf, "%lld\n", mdd->mdd_changelog_min_gc_interval);
343 }
344
345 static ssize_t changelog_min_gc_interval_store(struct kobject *kobj,
346                                                struct attribute *attr,
347                                                const char *buffer,
348                                                size_t count)
349 {
350         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
351                                               mdd_kobj);
352         time64_t val;
353         int rc;
354
355         rc = kstrtoll(buffer, 10, &val);
356         if (rc)
357                 return rc;
358
359         /* XXX may need to limit with reasonable elapsed/interval times */
360         if (val < 1)
361                 return -ERANGE;
362
363         mdd->mdd_changelog_min_gc_interval = val;
364
365         return count;
366 }
367 LUSTRE_RW_ATTR(changelog_min_gc_interval);
368
369 static ssize_t changelog_min_free_cat_entries_show(struct kobject *kobj,
370                                                    struct attribute *attr,
371                                                    char *buf)
372 {
373         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
374                                               mdd_kobj);
375
376         return sprintf(buf, "%u\n", mdd->mdd_changelog_min_free_cat_entries);
377 }
378
379 static ssize_t changelog_min_free_cat_entries_store(struct kobject *kobj,
380                                                     struct attribute *attr,
381                                                     const char *buffer,
382                                                     size_t count)
383 {
384         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
385                                               mdd_kobj);
386         unsigned int val;
387         int rc;
388
389         rc = kstrtouint(buffer, 10, &val);
390         if (rc)
391                 return rc;
392
393         /* XXX may need to limit with more reasonable number of free entries */
394         if (val < 1)
395                 return -ERANGE;
396
397         mdd->mdd_changelog_min_free_cat_entries = val;
398
399         return count;
400 }
401 LUSTRE_RW_ATTR(changelog_min_free_cat_entries);
402
403 static ssize_t changelog_deniednext_show(struct kobject *kobj,
404                                          struct attribute *attr,
405                                          char *buf)
406 {
407         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
408                                               mdd_kobj);
409
410         return sprintf(buf, "%u\n", mdd->mdd_cl.mc_deniednext);
411 }
412
413 static ssize_t changelog_deniednext_store(struct kobject *kobj,
414                                           struct attribute *attr,
415                                           const char *buffer,
416                                           size_t count)
417 {
418         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
419                                               mdd_kobj);
420         unsigned int time = 0;
421         int rc;
422
423         rc = kstrtouint(buffer, 0, &time);
424         if (rc)
425                 return rc;
426
427         mdd->mdd_cl.mc_deniednext = time;
428         return count;
429 }
430 LUSTRE_RW_ATTR(changelog_deniednext);
431
432 static ssize_t sync_permission_show(struct kobject *kobj,
433                                     struct attribute *attr, char *buf)
434 {
435         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
436                                               mdd_kobj);
437
438         return sprintf(buf, "%d\n", mdd->mdd_sync_permission);
439 }
440
441 static ssize_t sync_permission_store(struct kobject *kobj,
442                                      struct attribute *attr,
443                                      const char *buffer, size_t count)
444 {
445         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
446                                               mdd_kobj);
447         bool val;
448         int rc;
449
450         rc = kstrtobool(buffer, &val);
451         if (rc)
452                 return rc;
453
454         mdd->mdd_sync_permission = val;
455
456         return count;
457 }
458 LUSTRE_RW_ATTR(sync_permission);
459
460 static ssize_t lfsck_speed_limit_show(struct kobject *kobj,
461                                       struct attribute *attr, char *buf)
462 {
463         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
464                                               mdd_kobj);
465
466         return lfsck_get_speed(buf, mdd->mdd_bottom);
467 }
468
469 static ssize_t lfsck_speed_limit_store(struct kobject *kobj,
470                                        struct attribute *attr,
471                                        const char *buffer, size_t count)
472 {
473         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
474                                               mdd_kobj);
475         unsigned int val;
476         int rc;
477
478         rc = kstrtouint(buffer, 10, &val);
479         if (rc != 0)
480                 return rc;
481
482         rc = lfsck_set_speed(mdd->mdd_bottom, val);
483         return rc != 0 ? rc : count;
484 }
485 LUSTRE_RW_ATTR(lfsck_speed_limit);
486
487 static ssize_t lfsck_async_windows_show(struct kobject *kobj,
488                                         struct attribute *attr, char *buf)
489 {
490         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
491                                               mdd_kobj);
492
493         return lfsck_get_windows(buf, mdd->mdd_bottom);
494 }
495
496 static ssize_t lfsck_async_windows_store(struct kobject *kobj,
497                                          struct attribute *attr,
498                                          const char *buffer, size_t count)
499 {
500         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
501                                               mdd_kobj);
502         unsigned int val;
503         int rc;
504
505         rc = kstrtouint(buffer, 10, &val);
506         if (rc)
507                 return rc;
508
509         rc = lfsck_set_windows(mdd->mdd_bottom, val);
510
511         return rc != 0 ? rc : count;
512 }
513 LUSTRE_RW_ATTR(lfsck_async_windows);
514
515 static int mdd_lfsck_namespace_seq_show(struct seq_file *m, void *data)
516 {
517         struct mdd_device *mdd = m->private;
518
519         LASSERT(mdd != NULL);
520
521         return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_NAMESPACE);
522 }
523 LDEBUGFS_SEQ_FOPS_RO(mdd_lfsck_namespace);
524
525 static int mdd_lfsck_layout_seq_show(struct seq_file *m, void *data)
526 {
527         struct mdd_device *mdd = m->private;
528
529         LASSERT(mdd != NULL);
530
531         return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_LAYOUT);
532 }
533 LDEBUGFS_SEQ_FOPS_RO(mdd_lfsck_layout);
534
535 /**
536  * Show default number of stripes for O_APPEND files.
537  *
538  * \param[in] m         seq file
539  * \param[in] v         unused for single entry
540  *
541  * \retval 0            on success,
542  * \retval negative     error code if failed
543  */
544 static ssize_t append_stripe_count_show(struct kobject *kobj,
545                                         struct attribute *attr, char *buf)
546 {
547         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
548                                               mdd_kobj);
549
550         return scnprintf(buf, PAGE_SIZE, "%d\n", mdd->mdd_append_stripe_count);
551 }
552
553 /**
554  * Set default number of stripes for O_APPEND files.
555  *
556  * \param[in] file      proc file
557  * \param[in] buffer    string containing the default number of stripes
558  *                      for new files
559  * \param[in] count     @buffer length
560  * \param[in] off       unused for single entry
561  *
562  * \retval @count       on success
563  * \retval negative     error code otherwise
564  */
565 static ssize_t append_stripe_count_store(struct kobject *kobj,
566                                          struct attribute *attr,
567                                          const char *buffer, size_t count)
568 {
569         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
570                                               mdd_kobj);
571         int stripe_count;
572         int rc;
573
574         rc = kstrtoint(buffer, 0, &stripe_count);
575         if (rc)
576                 return rc;
577
578         if (stripe_count < -1)
579                 return -ERANGE;
580
581         mdd->mdd_append_stripe_count = stripe_count;
582
583         return count;
584 }
585 LUSTRE_RW_ATTR(append_stripe_count);
586
587 /**
588  * Show default OST pool for O_APPEND files.
589  *
590  * \param[in] kobject   proc object
591  * \param[in] attribute proc attribute
592  * \param[in] buf       output buffer
593  *
594  * \retval 0            on success,
595  * \retval negative     error code if failed
596  */
597 static ssize_t append_pool_show(struct kobject *kobj,
598                                 struct attribute *attr, char *buf)
599 {
600         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
601                                               mdd_kobj);
602
603         return scnprintf(buf, PAGE_SIZE, "%s\n", mdd->mdd_append_pool);
604 }
605
606 /**
607  * Set default OST pool for O_APPEND files.
608  *
609  * \param[in] kobject   proc object
610  * \param[in] attribute proc attribute
611  * \param[in] buffer    user inputted pool name
612  * \param[in] count     @buffer length
613  *
614  * \retval @count       on success
615  * \retval negative     error code otherwise
616  */
617 static ssize_t append_pool_store(struct kobject *kobj, struct attribute *attr,
618                                  const char *buffer, size_t count)
619 {
620         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
621                                               mdd_kobj);
622
623         if (!count || count > LOV_MAXPOOLNAME + 1)
624                 return -EINVAL;
625
626         /* clear previous value */
627         memset(mdd->mdd_append_pool, 0, LOV_MAXPOOLNAME + 1);
628
629         /* entering "none" clears the pool, otherwise copy the new pool */
630         if (strncmp("none", buffer, 4)) {
631                 memcpy(mdd->mdd_append_pool, buffer, count);
632
633                 /* Trim the trailing '\n' if any */
634                 if (mdd->mdd_append_pool[count - 1] == '\n') {
635                         /* Don't echo just a newline */
636                         if (count == 1)
637                                 return -EINVAL;
638                         mdd->mdd_append_pool[count - 1] = 0;
639                 }
640         }
641
642         return count;
643 }
644 LUSTRE_RW_ATTR(append_pool);
645
646 static struct ldebugfs_vars ldebugfs_mdd_obd_vars[] = {
647         { .name =       "changelog_mask",
648           .fops =       &mdd_changelog_mask_fops        },
649         { .name =       "changelog_users",
650           .fops =       &mdd_changelog_users_fops       },
651         { .name =       "lfsck_namespace",
652           .fops =       &mdd_lfsck_namespace_fops       },
653         { .name =       "lfsck_layout",
654           .fops =       &mdd_lfsck_layout_fops          },
655         { NULL }
656 };
657
658 static struct attribute *mdd_attrs[] = {
659         &lustre_attr_uuid.attr,
660         &lustre_attr_atime_diff.attr,
661         &lustre_attr_changelog_size.attr,
662         &lustre_attr_changelog_gc.attr,
663         &lustre_attr_changelog_max_idle_time.attr,
664         &lustre_attr_changelog_max_idle_indexes.attr,
665         &lustre_attr_changelog_min_gc_interval.attr,
666         &lustre_attr_changelog_min_free_cat_entries.attr,
667         &lustre_attr_changelog_deniednext.attr,
668         &lustre_attr_lfsck_async_windows.attr,
669         &lustre_attr_lfsck_speed_limit.attr,
670         &lustre_attr_sync_permission.attr,
671         &lustre_attr_append_stripe_count.attr,
672         &lustre_attr_append_pool.attr,
673         NULL,
674 };
675
676 static void mdd_sysfs_release(struct kobject *kobj)
677 {
678         struct mdd_device *mdd = container_of(kobj, struct mdd_device,
679                                               mdd_kobj);
680         struct obd_device *obd = mdd2obd_dev(mdd);
681
682         debugfs_remove_recursive(obd->obd_debugfs_entry);
683         obd->obd_debugfs_entry = NULL;
684
685         complete(&mdd->mdd_kobj_unregister);
686 }
687
688 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
689 {
690         struct obd_device *obd = mdd2obd_dev(mdd);
691         struct obd_type *type;
692         int rc;
693
694         ENTRY;
695         /* at the moment there is no linkage between lu_type
696          * and obd_type, so we lookup obd_type this way
697          */
698         type = class_search_type(LUSTRE_MDD_NAME);
699
700         LASSERT(name != NULL);
701         LASSERT(type != NULL);
702         LASSERT(obd  != NULL);
703
704         /* put reference taken by class_search_type */
705         kobject_put(&type->typ_kobj);
706
707         mdd->mdd_ktype.default_attrs = mdd_attrs;
708         mdd->mdd_ktype.release = mdd_sysfs_release;
709         mdd->mdd_ktype.sysfs_ops = &lustre_sysfs_ops;
710
711         init_completion(&mdd->mdd_kobj_unregister);
712         rc = kobject_init_and_add(&mdd->mdd_kobj, &mdd->mdd_ktype,
713                                   &type->typ_kobj, "%s", name);
714         if (rc)
715                 return rc;
716
717         /* Find the type procroot and add the proc entry for this device */
718         obd->obd_debugfs_vars = ldebugfs_mdd_obd_vars;
719         obd->obd_debugfs_entry = debugfs_create_dir(name,
720                                                      type->typ_debugfs_entry);
721         ldebugfs_add_vars(obd->obd_debugfs_entry, obd->obd_debugfs_vars, mdd);
722
723         RETURN(rc);
724 }
725
726 void mdd_procfs_fini(struct mdd_device *mdd)
727 {
728         kobject_put(&mdd->mdd_kobj);
729         wait_for_completion(&mdd->mdd_kobj_unregister);
730 }