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