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