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