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