Whamcloud - gitweb
LU-8066 lod: replace class_process_proc_param()
[fs/lustre-release.git] / lustre / lod / lproc_lod.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  2008 Sun Microsystems, Inc. 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  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32 #define DEBUG_SUBSYSTEM S_CLASS
33
34 #include <lprocfs_status.h>
35 #include <obd_class.h>
36 #include <linux/seq_file.h>
37 #include "lod_internal.h"
38 #include <uapi/linux/lustre/lustre_param.h>
39
40 /*
41  * Notice, all the functions below (except for lod_procfs_init() and
42  * lod_procfs_fini()) are not supposed to be used directly. They are
43  * called by Linux kernel's procfs.
44  */
45
46 #ifdef CONFIG_PROC_FS
47
48 /**
49  * Show default stripe size.
50  *
51  * \param[in] m         seq file
52  * \param[in] v         unused for single entry
53  *
54  * \retval 0            on success
55  * \retval negative     error code if failed
56  */
57 static int lod_dom_stripesize_seq_show(struct seq_file *m, void *v)
58 {
59         struct obd_device *dev = m->private;
60         struct lod_device *lod;
61
62         LASSERT(dev != NULL);
63         lod = lu2lod_dev(dev->obd_lu_dev);
64         seq_printf(m, "%u\n", lod->lod_dom_max_stripesize);
65         return 0;
66 }
67
68 /**
69  * Set default stripe size.
70  *
71  * \param[in] file      proc file
72  * \param[in] buffer    string containing the maximum number of bytes stored in
73  *                      each object before moving to the next object in the
74  *                      layout (if any)
75  * \param[in] count     @buffer length
76  * \param[in] off       unused for single entry
77  *
78  * \retval @count       on success
79  * \retval negative     error code if failed
80  */
81 static ssize_t
82 lod_dom_stripesize_seq_write(struct file *file, const char __user *buffer,
83                               size_t count, loff_t *off)
84 {
85         struct seq_file *m = file->private_data;
86         struct obd_device *dev = m->private;
87         struct lod_device *lod;
88         s64 val;
89         int rc;
90
91         LASSERT(dev != NULL);
92         lod = lu2lod_dev(dev->obd_lu_dev);
93         rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
94         if (rc)
95                 return rc;
96         if (val < 0)
97                 return -ERANGE;
98
99         /* 1GB is the limit */
100         if (val > (1ULL << 30))
101                 return -ERANGE;
102         else if (val > 0) {
103                 if (val < LOV_MIN_STRIPE_SIZE) {
104                         LCONSOLE_INFO("Increasing provided stripe size to "
105                                       "a minimum value %u\n",
106                                       LOV_MIN_STRIPE_SIZE);
107                         val = LOV_MIN_STRIPE_SIZE;
108                 } else if (val & (LOV_MIN_STRIPE_SIZE - 1)) {
109                         val &= ~(LOV_MIN_STRIPE_SIZE - 1);
110                         LCONSOLE_WARN("Changing provided stripe size to %llu "
111                                       "(a multiple of minimum %u)\n",
112                                       val, LOV_MIN_STRIPE_SIZE);
113                 }
114         }
115
116         lod->lod_dom_max_stripesize = val;
117
118         return count;
119 }
120 LPROC_SEQ_FOPS(lod_dom_stripesize);
121
122 /**
123  * Show default stripe size.
124  *
125  * \param[in] m         seq file
126  * \param[in] v         unused for single entry
127  *
128  * \retval 0            on success
129  * \retval negative     error code if failed
130  */
131 static int lod_stripesize_seq_show(struct seq_file *m, void *v)
132 {
133         struct obd_device *dev = m->private;
134         struct lod_device *lod;
135
136         LASSERT(dev != NULL);
137         lod  = lu2lod_dev(dev->obd_lu_dev);
138         seq_printf(m, "%llu\n",
139                    lod->lod_desc.ld_default_stripe_size);
140         return 0;
141 }
142
143 /**
144  * Set default stripe size.
145  *
146  * \param[in] file      proc file
147  * \param[in] buffer    string containing the maximum number of bytes stored in
148  *                      each object before moving to the next object in the
149  *                      layout (if any)
150  * \param[in] count     @buffer length
151  * \param[in] off       unused for single entry
152  *
153  * \retval @count       on success
154  * \retval negative     error code if failed
155  */
156 static ssize_t
157 lod_stripesize_seq_write(struct file *file, const char __user *buffer,
158                          size_t count, loff_t *off)
159 {
160         struct seq_file *m = file->private_data;
161         struct obd_device *dev = m->private;
162         struct lod_device *lod;
163         s64 val;
164         int rc;
165
166         LASSERT(dev != NULL);
167         lod  = lu2lod_dev(dev->obd_lu_dev);
168         rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
169         if (rc)
170                 return rc;
171         if (val < 0)
172                 return -ERANGE;
173
174         lod_fix_desc_stripe_size(&val);
175         lod->lod_desc.ld_default_stripe_size = val;
176
177         return count;
178 }
179 LPROC_SEQ_FOPS(lod_stripesize);
180
181 /**
182  * Show default stripe offset.
183  *
184  * \param[in] m         seq file
185  * \param[in] v         unused for single entry
186  *
187  * \retval 0            on success
188  * \retval negative     error code if failed
189  */
190 static ssize_t stripeoffset_show(struct kobject *kobj, struct attribute *attr,
191                                  char *buf)
192 {
193         struct dt_device *dt = container_of(kobj, struct dt_device,
194                                             dd_kobj);
195         struct lod_device *lod = dt2lod_dev(dt);
196
197         return sprintf(buf, "%lld\n", lod->lod_desc.ld_default_stripe_offset);
198 }
199
200 /**
201  * Set default stripe offset.
202  *
203  * Usually contains -1 allowing Lustre to balance objects among OST
204  * otherwise may cause severe OST imbalance.
205  *
206  * \param[in] file      proc file
207  * \param[in] buffer    string describing starting OST index for new files
208  * \param[in] count     @buffer length
209  * \param[in] off       unused for single entry
210  *
211  * \retval @count       on success
212  * \retval negative     error code if failed
213  */
214 static ssize_t stripeoffset_store(struct kobject *kobj, struct attribute *attr,
215                                   const char *buffer, size_t count)
216 {
217         struct dt_device *dt = container_of(kobj, struct dt_device,
218                                             dd_kobj);
219         struct lod_device *lod = dt2lod_dev(dt);
220         long val;
221         int rc;
222
223         rc = kstrtol(buffer, 0, &val);
224         if (rc)
225                 return rc;
226
227         if (val < -1 || val > LOV_MAX_STRIPE_COUNT)
228                 return -ERANGE;
229
230         lod->lod_desc.ld_default_stripe_offset = val;
231
232         return count;
233 }
234 LUSTRE_RW_ATTR(stripeoffset);
235
236 /**
237  * Show default striping pattern (LOV_PATTERN_*).
238  *
239  * \param[in] m         seq file
240  * \param[in] v         unused for single entry
241  *
242  * \retval 0            on success
243  * \retval negative     error code if failed
244  */
245 static ssize_t stripetype_show(struct kobject *kobj, struct attribute *attr,
246                                char *buf)
247 {
248         struct dt_device *dt = container_of(kobj, struct dt_device,
249                                             dd_kobj);
250         struct lod_device *lod = dt2lod_dev(dt);
251
252         return sprintf(buf, "%u\n", lod->lod_desc.ld_pattern);
253 }
254
255 /**
256  * Set default striping pattern (a number, not a human-readable string).
257  *
258  * \param[in] file      proc file
259  * \param[in] buffer    string containing the default striping pattern for new
260  *                      files. This is an integer LOV_PATTERN_* value
261  * \param[in] count     @buffer length
262  * \param[in] off       unused for single entry
263  *
264  * \retval @count       on success
265  * \retval negative     error code if failed
266  */
267 static ssize_t stripetype_store(struct kobject *kobj, struct attribute *attr,
268                                 const char *buffer, size_t count)
269 {
270         struct dt_device *dt = container_of(kobj, struct dt_device,
271                                             dd_kobj);
272         struct lod_device *lod = dt2lod_dev(dt);
273         u32 pattern;
274         int rc;
275
276         rc = kstrtouint(buffer, 0, &pattern);
277         if (rc)
278                 return rc;
279
280         lod_fix_desc_pattern(&pattern);
281         lod->lod_desc.ld_pattern = pattern;
282
283         return count;
284 }
285 LUSTRE_RW_ATTR(stripetype);
286
287 /**
288  * Show default number of stripes.
289  *
290  * \param[in] m         seq file
291  * \param[in] v         unused for single entry
292  *
293  * \retval 0            on success,
294  * \retval negative     error code if failed
295  */
296 static ssize_t stripecount_show(struct kobject *kobj, struct attribute *attr,
297                                 char *buf)
298 {
299         struct dt_device *dt = container_of(kobj, struct dt_device,
300                                             dd_kobj);
301         struct lod_device *lod = dt2lod_dev(dt);
302
303         return sprintf(buf, "%d\n",
304                        (s16)(lod->lod_desc.ld_default_stripe_count + 1) - 1);
305 }
306
307 /**
308  * Set default number of stripes.
309  *
310  * \param[in] file      proc file
311  * \param[in] buffer    string containing the default number of stripes
312  *                      for new files
313  * \param[in] count     @buffer length
314  * \param[in] off       unused for single entry
315  *
316  * \retval @count       on success
317  * \retval negative     error code otherwise
318  */
319 static ssize_t stripecount_store(struct kobject *kobj, struct attribute *attr,
320                                   const char *buffer, size_t count)
321 {
322         struct dt_device *dt = container_of(kobj, struct dt_device,
323                                             dd_kobj);
324         struct lod_device *lod = dt2lod_dev(dt);
325         int stripe_count;
326         int rc;
327
328         rc = kstrtoint(buffer, 0, &stripe_count);
329         if (rc)
330                 return rc;
331
332         if (stripe_count < -1)
333                 return -ERANGE;
334
335         lod_fix_desc_stripe_count(&stripe_count);
336         lod->lod_desc.ld_default_stripe_count = stripe_count;
337
338         return count;
339 }
340 LUSTRE_RW_ATTR(stripecount);
341
342 /**
343  * Show number of targets.
344  *
345  * \param[in] m         seq file
346  * \param[in] v         unused for single entry
347  *
348  * \retval 0            on success
349  * \retval negative     error code if failed
350  */
351 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
352                            char *buf)
353 {
354         struct dt_device *dt = container_of(kobj, struct dt_device,
355                                             dd_kobj);
356         struct lod_device *lod = dt2lod_dev(dt);
357
358         return sprintf(buf, "%u\n", lod->lod_desc.ld_tgt_count);
359 }
360 LUSTRE_RO_ATTR(numobd);
361
362 /**
363  * Show number of active targets.
364  *
365  * \param[in] m         seq file
366  * \param[in] v         unused for single entry
367  *
368  * \retval 0            on success
369  * \retval negative     error code if failed
370  */
371 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
372                               char *buf)
373 {
374         struct dt_device *dt = container_of(kobj, struct dt_device,
375                                             dd_kobj);
376         struct lod_device *lod = dt2lod_dev(dt);
377
378         return sprintf(buf, "%u\n", lod->lod_desc.ld_active_tgt_count);
379 }
380 LUSTRE_RO_ATTR(activeobd);
381
382 /**
383  * Show UUID of LOD device.
384  *
385  * \param[in] m         seq file
386  * \param[in] v         unused for single entry
387  *
388  * \retval 0            on success
389  * \retval negative     error code if failed
390  */
391 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
392                               char *buf)
393 {
394         struct dt_device *dt = container_of(kobj, struct dt_device,
395                                             dd_kobj);
396         struct lod_device *lod = dt2lod_dev(dt);
397
398         return sprintf(buf, "%s\n", lod->lod_desc.ld_uuid.uuid);
399 }
400 LUSTRE_RO_ATTR(desc_uuid);
401
402 /**
403  * Show QoS priority parameter.
404  *
405  * The printed value is a percentage value (0-100%) indicating the priority
406  * of free space compared to performance. 0% means select OSTs equally
407  * regardless of their free space, 100% means select OSTs only by their free
408  * space even if it results in very imbalanced load on the OSTs.
409  *
410  * \param[in] m         seq file
411  * \param[in] v         unused for single entry
412  *
413  * \retval 0            on success
414  * \retval negative     error code if failed
415  */
416 static ssize_t qos_prio_free_show(struct kobject *kobj, struct attribute *attr,
417                                   char *buf)
418 {
419         struct dt_device *dt = container_of(kobj, struct dt_device,
420                                             dd_kobj);
421         struct lod_device *lod = dt2lod_dev(dt);
422
423         return sprintf(buf, "%d%%\n",
424                        (lod->lod_qos.lq_prio_free * 100 + 255) >> 8);
425 }
426
427 /**
428  * Set QoS free space priority parameter.
429  *
430  * Set the relative priority of free OST space compared to OST load when OSTs
431  * are space imbalanced.  See lod_qos_priofree_seq_show() for description of
432  * this parameter.  See lod_qos_thresholdrr_seq_write() and lq_threshold_rr to
433  * determine what constitutes "space imbalanced" OSTs.
434  *
435  * \param[in] file      proc file
436  * \param[in] buffer    string which contains the free space priority (0-100)
437  * \param[in] count     @buffer length
438  * \param[in] off       unused for single entry
439  *
440  * \retval @count       on success
441  * \retval negative     error code if failed
442  */
443 static ssize_t qos_prio_free_store(struct kobject *kobj, struct attribute *attr,
444                                    const char *buffer, size_t count)
445 {
446         struct dt_device *dt = container_of(kobj, struct dt_device,
447                                             dd_kobj);
448         struct lod_device *lod = dt2lod_dev(dt);
449         unsigned int val;
450         int rc;
451
452         rc = kstrtouint(buffer, 0, &val);
453         if (rc)
454                 return rc;
455
456         if (val > 100)
457                 return -EINVAL;
458         lod->lod_qos.lq_prio_free = (val << 8) / 100;
459         lod->lod_qos.lq_dirty = 1;
460         lod->lod_qos.lq_reset = 1;
461
462         return count;
463 }
464 LUSTRE_RW_ATTR(qos_prio_free);
465
466 /**
467  * Show threshold for "same space on all OSTs" rule.
468  *
469  * \param[in] m         seq file
470  * \param[in] v         unused for single entry
471  *
472  * \retval 0            on success
473  * \retval negative     error code if failed
474  */
475 static int lod_qos_thresholdrr_seq_show(struct seq_file *m, void *v)
476 {
477         struct obd_device *dev = m->private;
478         struct lod_device *lod;
479
480         LASSERT(dev != NULL);
481         lod = lu2lod_dev(dev->obd_lu_dev);
482         seq_printf(m, "%d%%\n",
483                    (lod->lod_qos.lq_threshold_rr * 100 + 255) >> 8);
484         return 0;
485 }
486
487 /**
488  * Set threshold for "same space on all OSTs" rule.
489  *
490  * This sets the maximum percentage difference of free space between the most
491  * full and most empty OST in the currently available OSTs. If this percentage
492  * is exceeded, use the QoS allocator to select OSTs based on their available
493  * space so that more full OSTs are chosen less often, otherwise use the
494  * round-robin allocator for efficiency and performance.
495
496  * \param[in] file      proc file
497  * \param[in] buffer    string containing percentage difference of free space
498  * \param[in] count     @buffer length
499  * \param[in] off       unused for single entry
500  *
501  * \retval @count       on success
502  * \retval negative     error code if failed
503  */
504 static ssize_t
505 lod_qos_thresholdrr_seq_write(struct file *file, const char __user *buffer,
506                               size_t count, loff_t *off)
507 {
508         struct seq_file *m = file->private_data;
509         struct obd_device *dev = m->private;
510         struct lod_device *lod;
511         int rc;
512         __s64 val;
513
514         LASSERT(dev != NULL);
515         lod = lu2lod_dev(dev->obd_lu_dev);
516
517         rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '%');
518         if (rc)
519                 return rc;
520
521         if (val > 100 || val < 0)
522                 return -EINVAL;
523
524         lod->lod_qos.lq_threshold_rr = (val << 8) / 100;
525         lod->lod_qos.lq_dirty = 1;
526
527         return count;
528 }
529 LPROC_SEQ_FOPS(lod_qos_thresholdrr);
530
531 /**
532  * Show expiration period used to refresh cached statfs data, which
533  * is used to implement QoS/RR striping allocation algorithm.
534  *
535  * \param[in] m         seq file
536  * \param[in] v         unused for single entry
537  *
538  * \retval 0            on success
539  * \retval negative     error code if failed
540  */
541 static ssize_t qos_maxage_show(struct kobject *kobj, struct attribute *attr,
542                                char *buf)
543 {
544         struct dt_device *dt = container_of(kobj, struct dt_device,
545                                             dd_kobj);
546         struct lod_device *lod = dt2lod_dev(dt);
547
548         return sprintf(buf, "%u Sec\n", lod->lod_desc.ld_qos_maxage);
549 }
550
551 /**
552  * Set expiration period used to refresh cached statfs data.
553  *
554  * \param[in] file      proc file
555  * \param[in] buffer    string contains maximum age of statfs data in seconds
556  * \param[in] count     @buffer length
557  * \param[in] off       unused for single entry
558  *
559  * \retval @count       on success
560  * \retval negative     error code if failed
561  */
562 static ssize_t qos_maxage_store(struct kobject *kobj, struct attribute *attr,
563                                 const char *buffer, size_t count)
564 {
565         struct dt_device *dt = container_of(kobj, struct dt_device,
566                                             dd_kobj);
567         struct lod_device *lod = dt2lod_dev(dt);
568         struct lustre_cfg_bufs bufs;
569         struct lu_device *next;
570         struct lustre_cfg *lcfg;
571         char str[32];
572         unsigned int i;
573         int rc;
574         u32 val;
575
576         rc = kstrtouint(buffer, 0, &val);
577         if (rc)
578                 return rc;
579
580         if (val <= 0)
581                 return -EINVAL;
582         lod->lod_desc.ld_qos_maxage = val;
583
584         /*
585          * propogate the value down to OSPs
586          */
587         lustre_cfg_bufs_reset(&bufs, NULL);
588         snprintf(str, 32, "%smaxage=%u", PARAM_OSP, val);
589         lustre_cfg_bufs_set_string(&bufs, 1, str);
590         OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
591         if (lcfg == NULL)
592                 return -ENOMEM;
593         lustre_cfg_init(lcfg, LCFG_PARAM, &bufs);
594
595         lod_getref(&lod->lod_ost_descs);
596         lod_foreach_ost(lod, i) {
597                 next = &OST_TGT(lod,i)->ltd_ost->dd_lu_dev;
598                 rc = next->ld_ops->ldo_process_config(NULL, next, lcfg);
599                 if (rc)
600                         CERROR("can't set maxage on #%d: %d\n", i, rc);
601         }
602         lod_putref(lod, &lod->lod_ost_descs);
603         OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
604
605         return count;
606 }
607 LUSTRE_RW_ATTR(qos_maxage);
608
609 static void *lod_osts_seq_start(struct seq_file *p, loff_t *pos)
610 {
611         struct obd_device *dev = p->private;
612         struct lod_device *lod;
613
614         LASSERT(dev != NULL);
615         lod = lu2lod_dev(dev->obd_lu_dev);
616
617         lod_getref(&lod->lod_ost_descs); /* released in lod_osts_seq_stop */
618         if (*pos >= lod->lod_ost_bitmap->size)
619                 return NULL;
620
621         *pos = find_next_bit(lod->lod_ost_bitmap->data,
622                                  lod->lod_ost_bitmap->size, *pos);
623         if (*pos < lod->lod_ost_bitmap->size)
624                 return OST_TGT(lod,*pos);
625         else
626                 return NULL;
627 }
628
629 static void lod_osts_seq_stop(struct seq_file *p, void *v)
630 {
631         struct obd_device *dev = p->private;
632         struct lod_device *lod;
633
634         LASSERT(dev != NULL);
635         lod = lu2lod_dev(dev->obd_lu_dev);
636         lod_putref(lod, &lod->lod_ost_descs);
637 }
638
639 static void *lod_osts_seq_next(struct seq_file *p, void *v, loff_t *pos)
640 {
641         struct obd_device *dev = p->private;
642         struct lod_device *lod = lu2lod_dev(dev->obd_lu_dev);
643
644         if (*pos >= lod->lod_ost_bitmap->size - 1)
645                 return NULL;
646
647         *pos = find_next_bit(lod->lod_ost_bitmap->data,
648                                  lod->lod_ost_bitmap->size, *pos + 1);
649         if (*pos < lod->lod_ost_bitmap->size)
650                 return OST_TGT(lod,*pos);
651         else
652                 return NULL;
653 }
654
655 /**
656  * Show active/inactive status for OST found by lod_osts_seq_next().
657  *
658  * \param[in] m         seq file
659  * \param[in] v         unused for single entry
660  *
661  * \retval 0            on success
662  * \retval negative     error code if failed
663  */
664 static int lod_osts_seq_show(struct seq_file *p, void *v)
665 {
666         struct obd_device   *obd = p->private;
667         struct lod_ost_desc *ost_desc = v;
668         struct lod_device   *lod;
669         int                  idx, rc, active;
670         struct dt_device    *next;
671         struct obd_statfs    sfs;
672
673         LASSERT(obd->obd_lu_dev);
674         lod = lu2lod_dev(obd->obd_lu_dev);
675
676         idx = ost_desc->ltd_index;
677         next = OST_TGT(lod,idx)->ltd_ost;
678         if (next == NULL)
679                 return -EINVAL;
680
681         /* XXX: should be non-NULL env, but it's very expensive */
682         active = 1;
683         rc = dt_statfs(NULL, next, &sfs);
684         if (rc == -ENOTCONN) {
685                 active = 0;
686                 rc = 0;
687         } else if (rc)
688                 return rc;
689
690         seq_printf(p, "%d: %s %sACTIVE\n", idx,
691                    obd_uuid2str(&ost_desc->ltd_uuid),
692                    active ? "" : "IN");
693         return 0;
694 }
695
696 static const struct seq_operations lod_osts_sops = {
697         .start  = lod_osts_seq_start,
698         .stop   = lod_osts_seq_stop,
699         .next   = lod_osts_seq_next,
700         .show   = lod_osts_seq_show,
701 };
702
703 static int lod_osts_seq_open(struct inode *inode, struct file *file)
704 {
705         struct seq_file *seq;
706         int rc;
707
708         rc = seq_open(file, &lod_osts_sops);
709         if (rc)
710                 return rc;
711
712         seq = file->private_data;
713         seq->private = PDE_DATA(inode);
714         return 0;
715 }
716
717 /**
718  * Show whether special failout mode for testing is enabled or not.
719  *
720  * \param[in] m         seq file
721  * \param[in] v         unused for single entry
722  *
723  * \retval 0            on success
724  * \retval negative     error code if failed
725  */
726 static ssize_t lmv_failout_show(struct kobject *kobj, struct attribute *attr,
727                                 char *buf)
728 {
729         struct dt_device *dt = container_of(kobj, struct dt_device,
730                                             dd_kobj);
731         struct lod_device *lod = dt2lod_dev(dt);
732
733         return sprintf(buf, "%d\n", lod->lod_lmv_failout ? 1 : 0);
734 }
735
736 /**
737  * Enable/disable a special failout mode for testing.
738  *
739  * This determines whether the LMV will try to continue processing a striped
740  * directory even if it has a (partly) corrupted entry in the master directory,
741  * or if it will abort upon finding a corrupted slave directory entry.
742  *
743  * \param[in] file      proc file
744  * \param[in] buffer    string: 0 or non-zero to disable or enable LMV failout
745  * \param[in] count     @buffer length
746  * \param[in] off       unused for single entry
747  *
748  * \retval @count       on success
749  * \retval negative     error code if failed
750  */
751 static ssize_t lmv_failout_store(struct kobject *kobj, struct attribute *attr,
752                                  const char *buffer, size_t count)
753 {
754         struct dt_device *dt = container_of(kobj, struct dt_device,
755                                             dd_kobj);
756         struct lod_device *lod = dt2lod_dev(dt);
757         bool val = 0;
758         int rc;
759
760         rc = kstrtobool(buffer, &val);
761         if (rc)
762                 return rc;
763
764         lod->lod_lmv_failout = val;
765
766         return count;
767 }
768 LUSTRE_RW_ATTR(lmv_failout);
769
770 static struct lprocfs_vars lprocfs_lod_obd_vars[] = {
771         { .name =       "stripesize",
772           .fops =       &lod_stripesize_fops    },
773         { .name =       "qos_threshold_rr",
774           .fops =       &lod_qos_thresholdrr_fops },
775         { .name =       "dom_stripesize",
776           .fops =       &lod_dom_stripesize_fops        },
777         { NULL }
778 };
779
780 static const struct file_operations lod_proc_target_fops = {
781         .owner   = THIS_MODULE,
782         .open    = lod_osts_seq_open,
783         .read    = seq_read,
784         .llseek  = seq_lseek,
785         .release = lprocfs_seq_release,
786 };
787
788 static struct attribute *lod_attrs[] = {
789         &lustre_attr_stripeoffset.attr,
790         &lustre_attr_stripecount.attr,
791         &lustre_attr_stripetype.attr,
792         &lustre_attr_activeobd.attr,
793         &lustre_attr_desc_uuid.attr,
794         &lustre_attr_lmv_failout.attr,
795         &lustre_attr_numobd.attr,
796         &lustre_attr_qos_maxage.attr,
797         &lustre_attr_qos_prio_free.attr,
798         NULL,
799 };
800
801 /**
802  * Initialize procfs entries for LOD.
803  *
804  * \param[in] lod       LOD device
805  *
806  * \retval 0            on success
807  * \retval negative     error code if failed
808  */
809 int lod_procfs_init(struct lod_device *lod)
810 {
811         struct obd_device *obd = lod2obd(lod);
812         struct proc_dir_entry *lov_proc_dir;
813         struct obd_type *type;
814         struct kobject *lov;
815         int rc;
816
817         lod->lod_dt_dev.dd_ktype.default_attrs = lod_attrs;
818         rc = dt_tunables_init(&lod->lod_dt_dev, obd->obd_type, obd->obd_name,
819                               NULL);
820         if (rc) {
821                 CERROR("%s: failed to setup DT tunables: %d\n",
822                        obd->obd_name, rc);
823                 RETURN(rc);
824         }
825
826         obd->obd_vars = lprocfs_lod_obd_vars;
827         obd->obd_proc_entry = lprocfs_register(obd->obd_name,
828                                                obd->obd_type->typ_procroot,
829                                                obd->obd_vars, obd);
830         if (IS_ERR(obd->obd_proc_entry)) {
831                 rc = PTR_ERR(obd->obd_proc_entry);
832                 CERROR("%s: error %d setting up lprocfs\n",
833                        obd->obd_name, rc);
834                 GOTO(out, rc);
835         }
836
837         rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
838                                 0444, &lod_proc_target_fops, obd);
839         if (rc) {
840                 CWARN("%s: Error adding the target_obd file %d\n",
841                       obd->obd_name, rc);
842                 GOTO(out, rc);
843         }
844
845         lod->lod_pool_proc_entry = lprocfs_register("pools",
846                                                     obd->obd_proc_entry,
847                                                     NULL, NULL);
848         if (IS_ERR(lod->lod_pool_proc_entry)) {
849                 rc = PTR_ERR(lod->lod_pool_proc_entry);
850                 lod->lod_pool_proc_entry = NULL;
851                 CWARN("%s: Failed to create pool proc file: %d\n",
852                       obd->obd_name, rc);
853                 GOTO(out, rc);
854         }
855
856         lov = kset_find_obj(lustre_kset, "lov");
857         if (lov) {
858                 rc = sysfs_create_link(lov, &lod->lod_dt_dev.dd_kobj,
859                                        obd->obd_name);
860                 kobject_put(lov);
861         }
862
863         lod->lod_debugfs = ldebugfs_add_symlink(obd->obd_name, "lov",
864                                                 "../lod/%s", obd->obd_name);
865         if (!lod->lod_debugfs)
866                 CERROR("%s: failed to create LOV debugfs symlink\n",
867                        obd->obd_name);
868
869         /* If the real LOV is present which is the case for setups
870          * with both server and clients on the same node then use
871          * the LOV's proc root */
872         type = class_search_type(LUSTRE_LOV_NAME);
873         if (type != NULL && type->typ_procroot != NULL)
874                 lov_proc_dir = type->typ_procroot;
875         else
876                 lov_proc_dir = obd->obd_type->typ_procsym;
877
878         if (lov_proc_dir == NULL)
879                 RETURN(0);
880
881         /* for compatibility we link old procfs's LOV entries to lod ones */
882         lod->lod_symlink = lprocfs_add_symlink(obd->obd_name, lov_proc_dir,
883                                                "../lod/%s", obd->obd_name);
884         if (lod->lod_symlink == NULL)
885                 CERROR("cannot create LOV symlink for /proc/fs/lustre/lod/%s\n",
886                        obd->obd_name);
887         RETURN(0);
888
889 out:
890         dt_tunables_fini(&lod->lod_dt_dev);
891
892         return rc;
893 }
894
895 /**
896  * Cleanup procfs entries registred for LOD.
897  *
898  * \param[in] lod       LOD device
899  */
900 void lod_procfs_fini(struct lod_device *lod)
901 {
902         struct obd_device *obd = lod2obd(lod);
903         struct kobject *lov;
904
905         if (lod->lod_symlink != NULL) {
906                 lprocfs_remove(&lod->lod_symlink);
907                 lod->lod_symlink = NULL;
908         }
909
910         lov = kset_find_obj(lustre_kset, "lov");
911         if (lov) {
912                 sysfs_remove_link(lov, obd->obd_name);
913                 kobject_put(lov);
914         }
915
916         if (!IS_ERR_OR_NULL(lod->lod_debugfs))
917                 ldebugfs_remove(&lod->lod_debugfs);
918
919         if (obd->obd_proc_entry) {
920                 lprocfs_remove(&obd->obd_proc_entry);
921                 obd->obd_proc_entry = NULL;
922         }
923
924         dt_tunables_fini(&lod->lod_dt_dev);
925 }
926
927 #endif /* CONFIG_PROC_FS */
928