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