Whamcloud - gitweb
f91571963c189f54769d30b14b2e8477f0f6ebbc
[fs/lustre-release.git] / lustre / osp / lproc_osp.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * lustre/osp/lproc_osp.c
32  *
33  * Lustre OST Proxy Device (OSP), procfs functions
34  *
35  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
36  */
37
38 #define DEBUG_SUBSYSTEM S_CLASS
39
40 #include "osp_internal.h"
41
42 /**
43  * Show OSP active status
44  *
45  * \param[in] m         seq_file handle
46  * \param[in] data      unused for single entry
47  * \retval              0 on success
48  * \retval              negative number on error
49  */
50 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
51                            char *buf)
52 {
53         struct dt_device *dt = container_of(kobj, struct dt_device,
54                                             dd_kobj);
55         struct lu_device *lu = dt2lu_dev(dt);
56         struct obd_device *obd = lu->ld_obd;
57         struct obd_import *imp;
58         int rc;
59
60         with_imp_locked(obd, imp, rc)
61                 rc = sprintf(buf, "%d\n", !imp->imp_deactive);
62         return rc;
63 }
64
65 /**
66  * Activate/Deactivate OSP
67  *
68  * \param[in] file      proc file
69  * \param[in] buffer    string, which is "1" or "0" to activate/deactivate OSP
70  * \param[in] count     \a buffer length
71  * \param[in] off       unused for single entry
72  * \retval              \a count on success
73  * \retval              negative number on error
74  */
75 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
76                             const char *buffer, size_t count)
77 {
78         struct dt_device *dt = container_of(kobj, struct dt_device,
79                                             dd_kobj);
80         struct lu_device *lu = dt2lu_dev(dt);
81         struct obd_device *obd = lu->ld_obd;
82         struct obd_import *imp, *imp0;
83         bool val;
84         int rc;
85
86         rc = kstrtobool(buffer, &val);
87         if (rc)
88                 return rc;
89
90         with_imp_locked(obd, imp0, rc)
91                 imp = class_import_get(imp0);
92         if (rc)
93                 return rc;
94         /* opposite senses */
95         if (imp->imp_deactive == val)
96                 rc = ptlrpc_set_import_active(imp, val);
97         else
98                 CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
99                        (unsigned int)val);
100
101         class_import_put(imp);
102
103         return rc ?: count;
104 }
105 LUSTRE_RW_ATTR(active);
106
107 /**
108  * Show number of RPCs in flight
109  *
110  * \param[in] m         seq_file handle
111  * \param[in] data      unused for single entry
112  * \retval              0 on success
113  * \retval              negative number on error
114  */
115 static ssize_t sync_in_flight_show(struct kobject *kobj,
116                                    struct attribute *attr,
117                                    char *buf)
118 {
119         struct dt_device *dt = container_of(kobj, struct dt_device,
120                                             dd_kobj);
121         struct osp_device *osp = dt2osp_dev(dt);
122
123         return sprintf(buf, "%u\n", atomic_read(&osp->opd_sync_rpcs_in_flight));
124 }
125 LUSTRE_RO_ATTR(sync_in_flight);
126
127 /**
128  * Show number of RPCs in processing (including uncommitted by OST)
129  *
130  * \param[in] m         seq_file handle
131  * \param[in] data      unused for single entry
132  * \retval              0 on success
133  * \retval              negative number on error
134  */
135 static ssize_t sync_in_progress_show(struct kobject *kobj,
136                                      struct attribute *attr,
137                                      char *buf)
138 {
139         struct dt_device *dt = container_of(kobj, struct dt_device,
140                                             dd_kobj);
141         struct osp_device *osp = dt2osp_dev(dt);
142
143         return sprintf(buf, "%u\n", atomic_read(&osp->opd_sync_rpcs_in_progress));
144 }
145 LUSTRE_RO_ATTR(sync_in_progress);
146
147 /**
148  * Show number of changes to sync
149  *
150  * \param[in] m         seq_file handle
151  * \param[in] data      unused for single entry
152  * \retval              0 on success
153  * \retval              negative number on error
154  */
155 static ssize_t sync_changes_show(struct kobject *kobj,
156                                  struct attribute *attr,
157                                  char *buf)
158 {
159         struct dt_device *dt = container_of(kobj, struct dt_device,
160                                             dd_kobj);
161         struct osp_device *osp = dt2osp_dev(dt);
162
163         return sprintf(buf, "%u\n", atomic_read(&osp->opd_sync_changes));
164 }
165
166 /**
167  * Sync changes
168  *
169  * \param[in] file      proc file
170  * \param[in] buffer    unused because any input will do
171  * \param[in] count     \a buffer length
172  * \param[in] off       unused for single entry
173  * \retval              \a count on success
174  * \retval              negative number on error
175  */
176 static ssize_t sync_changes_store(struct kobject *kobj, struct attribute *attr,
177                                   const char *buffer, size_t count)
178 {
179         struct dt_device *dt = container_of(kobj, struct dt_device,
180                                             dd_kobj);
181         struct osp_device *osp = dt2osp_dev(dt);
182         struct lu_env env;
183         int rc;
184
185         rc = lu_env_init(&env, LCT_LOCAL);
186         if (rc != 0)
187                 return rc;
188
189         rc = dt_sync(&env, &osp->opd_dt_dev);
190         lu_env_fini(&env);
191
192         return rc == 0 ? count : rc;
193 }
194 LUSTRE_RW_ATTR(sync_changes);
195
196 /**
197  * Show maximum number of RPCs in flight allowed
198  *
199  * \param[in] m         seq_file handle
200  * \param[in] data      unused for single entry
201  * \retval              0 on success
202  * \retval              negative number on error
203  */
204 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
205                                        struct attribute *attr,
206                                        char *buf)
207 {
208         struct dt_device *dt = container_of(kobj, struct dt_device,
209                                             dd_kobj);
210         struct osp_device *osp = dt2osp_dev(dt);
211
212         return sprintf(buf, "%u\n", osp->opd_sync_max_rpcs_in_flight);
213 }
214
215 /**
216  * Change maximum number of RPCs in flight allowed
217  *
218  * \param[in] file      proc file
219  * \param[in] buffer    string which represents maximum number
220  * \param[in] count     \a buffer length
221  * \param[in] off       unused for single entry
222  * \retval              \a count on success
223  * \retval              negative number on error
224  */
225 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
226                                         struct attribute *attr,
227                                         const char *buffer,
228                                         size_t count)
229 {
230         struct dt_device *dt = container_of(kobj, struct dt_device,
231                                             dd_kobj);
232         struct osp_device *osp = dt2osp_dev(dt);
233         unsigned int val;
234         int rc;
235
236         rc = kstrtouint(buffer, 0, &val);
237         if (rc)
238                 return rc;
239
240         if (val == 0)
241                 return -ERANGE;
242
243         osp->opd_sync_max_rpcs_in_flight = val;
244         return count;
245 }
246 LUSTRE_RW_ATTR(max_rpcs_in_flight);
247
248 /**
249  * Show maximum number of RPCs in processing allowed
250  *
251  * \param[in] m         seq_file handle
252  * \param[in] data      unused
253  * \retval              0 on success
254  * \retval              negative number on error
255  */
256 static ssize_t max_rpcs_in_progress_show(struct kobject *kobj,
257                                          struct attribute *attr,
258                                          char *buf)
259 {
260         struct dt_device *dt = container_of(kobj, struct dt_device,
261                                             dd_kobj);
262         struct osp_device *osp = dt2osp_dev(dt);
263
264         return sprintf(buf, "%u\n", osp->opd_sync_max_rpcs_in_progress);
265 }
266
267 /**
268  * Change maximum number of RPCs in processing allowed
269  *
270  * \param[in] file      proc file
271  * \param[in] buffer    string which represents maximum number
272  * \param[in] count     \a buffer length
273  * \param[in] off       unused for single entry
274  * \retval              \a count on success
275  * \retval              negative number on error
276  */
277 static ssize_t max_rpcs_in_progress_store(struct kobject *kobj,
278                                           struct attribute *attr,
279                                           const char *buffer,
280                                           size_t count)
281 {
282         struct dt_device *dt = container_of(kobj, struct dt_device,
283                                             dd_kobj);
284         struct osp_device *osp = dt2osp_dev(dt);
285         unsigned int val;
286         int rc;
287
288         rc = kstrtouint(buffer, 0, &val);
289         if (rc)
290                 return rc;
291
292         if (val == 0)
293                 return -ERANGE;
294
295         osp->opd_sync_max_rpcs_in_progress = val;
296
297         return count;
298 }
299 LUSTRE_RW_ATTR(max_rpcs_in_progress);
300
301 /**
302  * Show number of objects to precreate next time
303  *
304  * \param[in] m         seq_file handle
305  * \param[in] data      unused for single entry
306  * \retval              0 on success
307  * \retval              negative number on error
308  */
309 static ssize_t create_count_show(struct kobject *kobj,
310                                  struct attribute *attr,
311                                  char *buf)
312 {
313         struct dt_device *dt = container_of(kobj, struct dt_device,
314                                             dd_kobj);
315         struct osp_device *osp = dt2osp_dev(dt);
316
317         if (!osp->opd_pre)
318                 return -EINVAL;
319
320         return sprintf(buf, "%d\n", osp->opd_pre_create_count);
321 }
322
323 /**
324  * Change number of objects to precreate next time
325  *
326  * \param[in] file      proc file
327  * \param[in] buffer    string which represents number of objects to precreate
328  * \param[in] count     \a buffer length
329  * \param[in] off       unused for single entry
330  * \retval              \a count on success
331  * \retval              negative number on error
332  */
333 static ssize_t create_count_store(struct kobject *kobj, struct attribute *attr,
334                                   const char *buffer, size_t count)
335 {
336         struct dt_device *dt = container_of(kobj, struct dt_device,
337                                             dd_kobj);
338         struct osp_device *osp = dt2osp_dev(dt);
339         unsigned int val;
340         int rc;
341
342         if (!osp->opd_pre)
343                 return -EINVAL;
344
345         rc = kstrtouint(buffer, 0, &val);
346         if (rc)
347                 return rc;
348
349         /* The MDT ALWAYS needs to limit the precreate count to
350          * OST_MAX_PRECREATE, and the constant cannot be changed
351          * because it is a value shared between the OSP and OST
352          * that is the maximum possible number of objects that will
353          * ever be handled by MDT->OST recovery processing.
354          *
355          * The OSP enforces the pre_create_count to amaximum of
356          * one half of opd_pre_max_create_count.
357          *
358          * If the OST ever gets a request to delete more orphans,
359          * this implies that something has gone badly on the MDT
360          * and the OST will refuse to delete so much data from the
361          * filesystem as a safety measure.
362          */
363         if (val < OST_MIN_PRECREATE)
364                 return -ERANGE;
365         if (val > osp->opd_pre_max_create_count / 2)
366                 val = osp->opd_pre_max_create_count / 2;
367
368         /* set to largest value <= 32, 64, 128 or a multiple of 256 */
369         if (val > 256)
370                 osp->opd_pre_create_count = val & 0xffffff00;
371         else
372                 osp->opd_pre_create_count = rounddown_pow_of_two(val);
373
374         return count;
375 }
376 LUSTRE_RW_ATTR(create_count);
377
378 /**
379  * Show maximum number of objects to precreate
380  *
381  * \param[in] m         seq_file handle
382  * \param[in] data      unused for single entry
383  * \retval              0 on success
384  * \retval              negative number on error
385  */
386 static ssize_t max_create_count_show(struct kobject *kobj,
387                                      struct attribute *attr,
388                                      char *buf)
389 {
390         struct dt_device *dt = container_of(kobj, struct dt_device,
391                                             dd_kobj);
392         struct osp_device *osp = dt2osp_dev(dt);
393
394         if (!osp->opd_pre)
395                 return -EINVAL;
396
397         return sprintf(buf, "%d\n", osp->opd_pre_max_create_count);
398 }
399
400 /**
401  * Change maximum number of objects to precreate
402  *
403  * \param[in] file      proc file
404  * \param[in] buffer    string which represents maximum number
405  * \param[in] count     \a buffer length
406  * \param[in] off       unused for single entry
407  * \retval              \a count on success
408  * \retval              negative number on error
409  */
410 static ssize_t max_create_count_store(struct kobject *kobj,
411                                       struct attribute *attr,
412                                       const char *buffer, size_t count)
413 {
414         struct dt_device *dt = container_of(kobj, struct dt_device,
415                                             dd_kobj);
416         struct osp_device *osp = dt2osp_dev(dt);
417         unsigned int val;
418         int rc;
419
420         if (!osp->opd_pre)
421                 return -EINVAL;
422
423         rc = kstrtouint(buffer, 0, &val);
424         if (rc)
425                 return rc;
426
427         if (val && (val < OST_MIN_PRECREATE ||
428                     val > OST_MAX_PRECREATE))
429                 return -ERANGE;
430
431         if (osp->opd_pre_create_count > val)
432                 osp->opd_pre_create_count = val;
433
434         /* Can be 0 after setting max_create_count to 0 */
435         if (osp->opd_pre_create_count == 0 && val != 0)
436                 osp->opd_pre_create_count = OST_MIN_PRECREATE;
437
438         osp->opd_pre_max_create_count = val;
439
440         return count;
441 }
442 LUSTRE_RW_ATTR(max_create_count);
443
444 /**
445  * Show last id to assign in creation
446  *
447  * \param[in] m         seq_file handle
448  * \param[in] data      unused for single entry
449  * \retval              0 on success
450  * \retval              negative number on error
451  */
452 static ssize_t prealloc_next_id_show(struct kobject *kobj,
453                                      struct attribute *attr,
454                                      char *buf)
455 {
456         struct dt_device *dt = container_of(kobj, struct dt_device,
457                                             dd_kobj);
458         struct osp_device *osp = dt2osp_dev(dt);
459         struct lu_fid *fid;
460         u64 id;
461
462         if (!osp->opd_pre)
463                 return -EINVAL;
464
465         fid = &osp->opd_pre_used_fid;
466         if (fid_is_idif(fid)) {
467                 id = fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid));
468                 id++;
469         } else {
470                 id = unlikely(fid_oid(fid) == LUSTRE_DATA_SEQ_MAX_WIDTH) ?
471                         1 : fid_oid(fid) + 1;
472         }
473
474         return sprintf(buf, "%llu\n", id);
475 }
476 LUSTRE_RO_ATTR(prealloc_next_id);
477
478 /**
479  * Show last created id OST reported
480  *
481  * \param[in] m         seq_file handle
482  * \param[in] data      unused for single entry
483  * \retval              0 on success
484  * \retval              negative number on error
485  */
486
487 static ssize_t prealloc_last_id_show(struct kobject *kobj,
488                                      struct attribute *attr,
489                                      char *buf)
490 {
491         struct dt_device *dt = container_of(kobj, struct dt_device,
492                                             dd_kobj);
493         struct osp_device *osp = dt2osp_dev(dt);
494         struct lu_fid *fid;
495         u64 id;
496
497         if (!osp->opd_pre)
498                 return -EINVAL;
499
500         fid = &osp->opd_pre_last_created_fid;
501         id = fid_is_idif(fid) ?
502                          fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid)) :
503                          fid_oid(fid);
504
505         return sprintf(buf, "%llu\n", id);
506 }
507 LUSTRE_RO_ATTR(prealloc_last_id);
508
509 /**
510  * Show next FID sequence to precreate
511  *
512  * \param[in] m         seq_file handle
513  * \param[in] data      unused for single entry
514  * \retval              0 on success
515  * \retval              negative number on error
516  */
517 static ssize_t prealloc_next_seq_show(struct kobject *kobj,
518                                       struct attribute *attr,
519                                       char *buf)
520 {
521         struct dt_device *dt = container_of(kobj, struct dt_device,
522                                             dd_kobj);
523         struct osp_device *osp = dt2osp_dev(dt);
524         struct lu_fid *fid;
525
526         if (!osp->opd_pre)
527                 return -EINVAL;
528
529         fid = &osp->opd_pre_used_fid;
530         return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
531                        fid_seq(fid) & (~0xffff) : fid_seq(fid));
532 }
533 LUSTRE_RO_ATTR(prealloc_next_seq);
534
535 /**
536  * Show last created FID sequence OST reported
537  *
538  * \param[in] m         seq_file handle
539  * \param[in] data      unused for single entry
540  * \retval              0 on success
541  * \retval              negative number on error
542  */
543 static ssize_t prealloc_last_seq_show(struct kobject *kobj,
544                                       struct attribute *attr,
545                                       char *buf)
546 {
547         struct dt_device *dt = container_of(kobj, struct dt_device,
548                                             dd_kobj);
549         struct osp_device *osp = dt2osp_dev(dt);
550         struct lu_fid *fid;
551
552         if (!osp->opd_pre)
553                 return -EINVAL;
554
555         fid = &osp->opd_pre_last_created_fid;
556         return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
557                        fid_seq(fid) & (~0xffff) : fid_seq(fid));
558 }
559 LUSTRE_RO_ATTR(prealloc_last_seq);
560
561 /**
562  * Show the number of ids reserved by declare
563  *
564  * \param[in] m         seq_file handle
565  * \param[in] data      unused for single entry
566  * \retval              0 on success
567  * \retval              negative number on error
568  */
569 static ssize_t prealloc_reserved_show(struct kobject *kobj,
570                                       struct attribute *attr,
571                                       char *buf)
572 {
573         struct dt_device *dt = container_of(kobj, struct dt_device,
574                                             dd_kobj);
575         struct osp_device *osp = dt2osp_dev(dt);
576
577         if (!osp->opd_pre)
578                 return -EINVAL;
579
580         return sprintf(buf, "%llu\n", osp->opd_pre_reserved);
581 }
582 LUSTRE_RO_ATTR(prealloc_reserved);
583
584 /**
585  * Show interval (in seconds) to update statfs data
586  *
587  * \param[in] m         seq_file handle
588  * \param[in] data      unused for single entry
589  * \retval              0 on success
590  * \retval              negative number on error
591  */
592 static ssize_t maxage_show(struct kobject *kobj,
593                            struct attribute *attr,
594                            char *buf)
595 {
596         struct dt_device *dt = container_of(kobj, struct dt_device,
597                                             dd_kobj);
598         struct osp_device *osp = dt2osp_dev(dt);
599
600         return sprintf(buf, "%lld\n", osp->opd_statfs_maxage);
601 }
602
603 /**
604  * Change interval to update statfs data
605  *
606  * \param[in] file      proc file
607  * \param[in] buffer    string which represents statfs interval (in seconds)
608  * \param[in] count     \a buffer length
609  * \param[in] off       unused for single entry
610  * \retval              \a count on success
611  * \retval              negative number on error
612  */
613 static ssize_t maxage_store(struct kobject *kobj, struct attribute *attr,
614                             const char *buffer, size_t count)
615 {
616         struct dt_device *dt = container_of(kobj, struct dt_device,
617                                             dd_kobj);
618         struct osp_device *osp = dt2osp_dev(dt);
619         unsigned int val;
620         int rc;
621
622         rc = kstrtouint(buffer, 0, &val);
623         if (rc)
624                 return rc;
625
626         if (val == 0)
627                 return -ERANGE;
628
629         osp->opd_statfs_maxage = val;
630
631         return count;
632 }
633 LUSTRE_RW_ATTR(maxage);
634
635 /**
636  * Show current precreation status: output 0 means success, otherwise negative
637  * number is printed
638  *
639  * \param[in] m         seq_file handle
640  * \param[in] data      unused for single entry
641  * \retval              0 on success
642  * \retval              negative number on error
643  */
644 static ssize_t prealloc_status_show(struct kobject *kobj,
645                                     struct attribute *attr,
646                                     char *buf)
647 {
648         struct dt_device *dt = container_of(kobj, struct dt_device,
649                                             dd_kobj);
650         struct osp_device *osp = dt2osp_dev(dt);
651
652         if (!osp->opd_pre)
653                 return -EINVAL;
654
655         return sprintf(buf, "%d\n", osp->opd_pre_status);
656 }
657 LUSTRE_RO_ATTR(prealloc_status);
658
659 /**
660  * Show the number of RPCs in processing (including uncommitted by OST) plus
661  * changes to sync, i.e. this is the total number of changes OST needs to apply
662  * and commit.
663  *
664  * This counter is used to determine if OST has space returned. A zero value
665  * indicates that OST storage space consumed by destroyed objects has been freed
666  * on disk, the associated llog records have been cleared, and no synchronous
667  * RPC are being processed.
668  *
669  * \param[in] m         seq_file handle
670  * \param[in] data      unused for single entry
671  * \retval              0 on success
672  * \retval              negative number on error
673  */
674 static ssize_t destroys_in_flight_show(struct kobject *kobj,
675                                        struct attribute *attr,
676                                        char *buf)
677 {
678         struct dt_device *dt = container_of(kobj, struct dt_device,
679                                             dd_kobj);
680         struct osp_device *osp = dt2osp_dev(dt);
681
682         return sprintf(buf, "%u\n",
683                        atomic_read(&osp->opd_sync_rpcs_in_progress) +
684                        atomic_read(&osp->opd_sync_changes));
685 }
686 LUSTRE_RO_ATTR(destroys_in_flight);
687
688 /**
689  * Show changes synced from previous mount
690  *
691  * \param[in] m         seq_file handle
692  * \param[in] data      unused for single entry
693  * \retval              0 on success
694  * \retval              negative number on error
695  */
696 static ssize_t old_sync_processed_show(struct kobject *kobj,
697                                        struct attribute *attr,
698                                        char *buf)
699 {
700         struct dt_device *dt = container_of(kobj, struct dt_device,
701                                             dd_kobj);
702         struct osp_device *osp = dt2osp_dev(dt);
703
704         return sprintf(buf, "%d\n", osp->opd_sync_prev_done);
705 }
706 LUSTRE_RO_ATTR(old_sync_processed);
707
708 /**
709  * Show maximum number of RPCs in flight
710  *
711  * \param[in] m         seq_file handle
712  * \param[in] data      unused for single entry
713  * \retval              0 on success
714  * \retval              negative number on error
715  */
716 static ssize_t lfsck_max_rpcs_in_flight_show(struct kobject *kobj,
717                                              struct attribute *attr,
718                                              char *buf)
719 {
720         struct dt_device *dt = container_of(kobj, struct dt_device,
721                                             dd_kobj);
722         struct lu_device *lu = dt2lu_dev(dt);
723         struct obd_device *obd = lu->ld_obd;
724         u32 max;
725
726         max = obd_get_max_rpcs_in_flight(&obd->u.cli);
727         return sprintf(buf, "%u\n", max);
728 }
729
730 /**
731  * Change maximum number of RPCs in flight
732  *
733  * \param[in] file      proc file
734  * \param[in] buffer    string which represents maximum number of RPCs in flight
735  * \param[in] count     \a buffer length
736  * \param[in] off       unused for single entry
737  * \retval              \a count on success
738  * \retval              negative number on error
739  */
740 static ssize_t lfsck_max_rpcs_in_flight_store(struct kobject *kobj,
741                                               struct attribute *attr,
742                                               const char *buffer,
743                                               size_t count)
744 {
745         struct dt_device *dt = container_of(kobj, struct dt_device,
746                                             dd_kobj);
747         struct lu_device *lu = dt2lu_dev(dt);
748         struct obd_device *obd = lu->ld_obd;
749         unsigned int val;
750         int rc;
751
752         rc = kstrtouint(buffer, 0, &val);
753         if (rc)
754                 return rc;
755
756         rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
757         return rc ? rc : count;
758 }
759 LUSTRE_RW_ATTR(lfsck_max_rpcs_in_flight);
760
761 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
762                   char *buffer)
763 {
764         struct dt_device *dt = container_of(kobj, struct dt_device,
765                                             dd_kobj);
766         struct lu_device *lu = dt2lu_dev(dt);
767         struct obd_device *obd = lu->ld_obd;
768         int rc;
769
770         rc = ptlrpc_obd_ping(obd);
771
772         return rc;
773 }
774 LUSTRE_RO_ATTR(ping);
775
776 ssize_t osp_conn_uuid_show(struct kobject *kobj, struct attribute *attr,
777                            char *buf)
778 {
779         struct dt_device *dt = container_of(kobj, struct dt_device,
780                                             dd_kobj);
781         struct lu_device *lu = dt2lu_dev(dt);
782         struct obd_device *obd = lu->ld_obd;
783         struct obd_import *imp;
784         struct ptlrpc_connection *conn;
785         ssize_t count;
786
787         with_imp_locked(obd, imp, count) {
788                 conn = imp->imp_connection;
789                 if (conn)
790                         count = sprintf(buf, "%s\n", conn->c_remote_uuid.uuid);
791                 else
792                         count = sprintf(buf, "%s\n", "<none>");
793         }
794
795         return count;
796 }
797
798 LUSTRE_ATTR(ost_conn_uuid, 0444, osp_conn_uuid_show, NULL);
799 LUSTRE_ATTR(mdt_conn_uuid, 0444, osp_conn_uuid_show, NULL);
800
801 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, connect_flags);
802 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, server_uuid);
803 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, timeouts);
804
805 LDEBUGFS_SEQ_FOPS_RW_TYPE(osp, import);
806 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, state);
807
808 /**
809  * Show high watermark (in megabytes). If available free space at OST is grater
810  * than high watermark and object allocation for OST is disabled, enable it.
811  *
812  * \param[in] m         seq_file handle
813  * \param[in] data      unused for single entry
814  * \retval              0 on success
815  * \retval              negative number on error
816  */
817 static int osp_reserved_mb_high_seq_show(struct seq_file *m, void *data)
818 {
819         struct obd_device       *dev = m->private;
820         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
821
822         if (osp == NULL)
823                 return -EINVAL;
824
825         seq_printf(m, "%u\n", osp->opd_reserved_mb_high);
826         return 0;
827 }
828
829 /**
830  * Change high watermark
831  *
832  * \param[in] file      proc file
833  * \param[in] buffer    string which represents new value (in megabytes)
834  * \param[in] count     \a buffer length
835  * \param[in] off       unused for single entry
836  * \retval              \a count on success
837  * \retval              negative number on error
838  */
839 static ssize_t
840 osp_reserved_mb_high_seq_write(struct file *file, const char __user *buffer,
841                         size_t count, loff_t *off)
842 {
843         struct seq_file         *m = file->private_data;
844         struct obd_device       *dev = m->private;
845         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
846         char kernbuf[22] = "";
847         u64 val;
848         int                     rc;
849
850         if (osp == NULL || osp->opd_pre == NULL)
851                 return -EINVAL;
852
853         if (count >= sizeof(kernbuf))
854                 return -EINVAL;
855
856         if (copy_from_user(kernbuf, buffer, count))
857                 return -EFAULT;
858         kernbuf[count] = 0;
859
860         rc = sysfs_memparse(kernbuf, count, &val, "MiB");
861         if (rc < 0)
862                 return rc;
863         val >>= 20;
864         if (val < 1)
865                 return -ERANGE;
866
867         spin_lock(&osp->opd_pre_lock);
868         osp->opd_reserved_mb_high = val;
869         if (val <= osp->opd_reserved_mb_low)
870                 osp->opd_reserved_mb_low = val - 1;
871         spin_unlock(&osp->opd_pre_lock);
872
873         return count;
874 }
875 LDEBUGFS_SEQ_FOPS(osp_reserved_mb_high);
876
877 /**
878  * Show low watermark (in megabytes). If available free space at OST is less
879  * than low watermark, object allocation for OST is disabled.
880  *
881  * \param[in] m         seq_file handle
882  * \param[in] data      unused for single entry
883  * \retval              0 on success
884  * \retval              negative number on error
885  */
886 static int osp_reserved_mb_low_seq_show(struct seq_file *m, void *data)
887 {
888         struct obd_device       *dev = m->private;
889         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
890
891         if (osp == NULL)
892                 return -EINVAL;
893
894         seq_printf(m, "%u\n", osp->opd_reserved_mb_low);
895         return 0;
896 }
897
898 /**
899  * Change low watermark
900  *
901  * \param[in] file      proc file
902  * \param[in] buffer    string which represents new value (in megabytes)
903  * \param[in] count     \a buffer length
904  * \param[in] off       unused for single entry
905  * \retval              \a count on success
906  * \retval              negative number on error
907  */
908 static ssize_t
909 osp_reserved_mb_low_seq_write(struct file *file, const char __user *buffer,
910                         size_t count, loff_t *off)
911 {
912         struct seq_file         *m = file->private_data;
913         struct obd_device       *dev = m->private;
914         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
915         char kernbuf[22] = "";
916         u64 val;
917         int                     rc;
918
919         if (osp == NULL || osp->opd_pre == NULL)
920                 return -EINVAL;
921
922         if (count >= sizeof(kernbuf))
923                 return -EINVAL;
924
925         if (copy_from_user(kernbuf, buffer, count))
926                 return -EFAULT;
927         kernbuf[count] = 0;
928
929         rc = sysfs_memparse(kernbuf, count, &val, "MiB");
930         if (rc < 0)
931                 return rc;
932         val >>= 20;
933
934         spin_lock(&osp->opd_pre_lock);
935         osp->opd_reserved_mb_low = val;
936         if (val >= osp->opd_reserved_mb_high)
937                 osp->opd_reserved_mb_high = val + 1;
938         spin_unlock(&osp->opd_pre_lock);
939
940         return count;
941 }
942 LDEBUGFS_SEQ_FOPS(osp_reserved_mb_low);
943
944 static ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
945                                 const char *buffer, size_t count)
946 {
947         struct dt_device *dt = container_of(kobj, struct dt_device,
948                                             dd_kobj);
949         struct lu_env env;
950         int rc;
951
952         rc = lu_env_init(&env, LCT_LOCAL);
953         if (rc)
954                 return rc;
955
956         rc = dt_sync(&env, dt);
957         lu_env_fini(&env);
958
959         return rc == 0 ? count : rc;
960 }
961 LUSTRE_WO_ATTR(force_sync);
962
963 static struct ldebugfs_vars ldebugfs_osp_obd_vars[] = {
964         { .name =       "connect_flags",
965           .fops =       &osp_connect_flags_fops         },
966         { .name =       "ost_server_uuid",
967           .fops =       &osp_server_uuid_fops           },
968         { .name =       "timeouts",
969           .fops =       &osp_timeouts_fops              },
970         { .name =       "import",
971           .fops =       &osp_import_fops                },
972         { .name =       "state",
973           .fops =       &osp_state_fops                 },
974         { .name =       "reserved_mb_high",
975           .fops =       &osp_reserved_mb_high_fops      },
976         { .name =       "reserved_mb_low",
977           .fops =       &osp_reserved_mb_low_fops       },
978         { NULL }
979 };
980
981 static struct ldebugfs_vars ldebugfs_osp_md_vars[] = {
982         { .name =       "connect_flags",
983           .fops =       &osp_connect_flags_fops         },
984         { .name =       "mdt_server_uuid",
985           .fops =       &osp_server_uuid_fops           },
986         { .name =       "timeouts",
987           .fops =       &osp_timeouts_fops              },
988         { .name =       "import",
989           .fops =       &osp_import_fops                },
990         { .name =       "state",
991           .fops =       &osp_state_fops                 },
992         { NULL }
993 };
994
995 static struct attribute *osp_obd_attrs[] = {
996         /* First two for compatiability reasons */
997         &lustre_attr_lfsck_max_rpcs_in_flight.attr,
998         &lustre_attr_destroys_in_flight.attr,
999         &lustre_attr_active.attr,
1000         &lustre_attr_max_rpcs_in_flight.attr,
1001         &lustre_attr_max_rpcs_in_progress.attr,
1002         &lustre_attr_maxage.attr,
1003         &lustre_attr_ost_conn_uuid.attr,
1004         &lustre_attr_ping.attr,
1005         &lustre_attr_prealloc_status.attr,
1006         &lustre_attr_prealloc_next_id.attr,
1007         &lustre_attr_prealloc_last_id.attr,
1008         &lustre_attr_prealloc_next_seq.attr,
1009         &lustre_attr_prealloc_last_seq.attr,
1010         &lustre_attr_prealloc_reserved.attr,
1011         &lustre_attr_sync_in_flight.attr,
1012         &lustre_attr_sync_in_progress.attr,
1013         &lustre_attr_sync_changes.attr,
1014         &lustre_attr_force_sync.attr,
1015         &lustre_attr_old_sync_processed.attr,
1016         &lustre_attr_create_count.attr,
1017         &lustre_attr_max_create_count.attr,
1018         NULL,
1019 };
1020
1021 static struct attribute *osp_md_attrs[] = {
1022         /* First two for compatiability reasons */
1023         &lustre_attr_lfsck_max_rpcs_in_flight.attr,
1024         &lustre_attr_destroys_in_flight.attr,
1025         &lustre_attr_active.attr,
1026         &lustre_attr_max_rpcs_in_flight.attr,
1027         &lustre_attr_max_rpcs_in_progress.attr,
1028         &lustre_attr_maxage.attr,
1029         &lustre_attr_mdt_conn_uuid.attr,
1030         &lustre_attr_ping.attr,
1031         &lustre_attr_prealloc_status.attr,
1032         NULL,
1033 };
1034
1035 void osp_tunables_fini(struct osp_device *osp)
1036 {
1037         struct obd_device *obd = osp->opd_obd;
1038         struct kobject *osc;
1039
1040         osc = kset_find_obj(lustre_kset, "osc");
1041         if (osc) {
1042                 sysfs_remove_link(osc, obd->obd_name);
1043                 kobject_put(osc);
1044         }
1045
1046         debugfs_remove_recursive(osp->opd_debugfs);
1047         osp->opd_debugfs = NULL;
1048
1049         ptlrpc_lprocfs_unregister_obd(obd);
1050
1051         debugfs_remove_recursive(obd->obd_debugfs_entry);
1052         obd->obd_debugfs_entry = NULL;
1053
1054         dt_tunables_fini(&osp->opd_dt_dev);
1055 }
1056
1057 /**
1058  * Initialize OSP sysfs / debugfs
1059  *
1060  * param[in] osp        OSP device
1061  */
1062 void osp_tunables_init(struct osp_device *osp)
1063 {
1064         struct obd_device *obd = osp->opd_obd;
1065         struct kobject *osc;
1066         int rc;
1067
1068         if (osp->opd_connect_mdt) {
1069                 osp->opd_dt_dev.dd_ktype.default_attrs = osp_md_attrs;
1070                 obd->obd_debugfs_vars = ldebugfs_osp_md_vars;
1071         } else {
1072                 osp->opd_dt_dev.dd_ktype.default_attrs = osp_obd_attrs;
1073                 obd->obd_debugfs_vars = ldebugfs_osp_obd_vars;
1074         }
1075
1076         rc = dt_tunables_init(&osp->opd_dt_dev, obd->obd_type, obd->obd_name,
1077                               NULL);
1078         if (rc) {
1079                 CERROR("%s: failed to setup DT tunables: %d\n",
1080                        obd->obd_name, rc);
1081                 return;
1082         }
1083
1084         /* Since we register the obd device with ptlrpc / sptlrpc we
1085          * have to register debugfs with obd_device
1086          */
1087         obd->obd_debugfs_entry = debugfs_create_dir(
1088                 obd->obd_name, obd->obd_type->typ_debugfs_entry);
1089         ldebugfs_add_vars(obd->obd_debugfs_entry, obd->obd_debugfs_vars, obd);
1090
1091         sptlrpc_lprocfs_cliobd_attach(obd);
1092         ptlrpc_lprocfs_register_obd(obd);
1093
1094         if (osp->opd_connect_mdt || !strstr(obd->obd_name, "osc"))
1095                 return;
1096
1097         /* If the real OSC is present which is the case for setups
1098          * with both server and clients on the same node then use
1099          * the OSC's proc root
1100          */
1101         osc = kset_find_obj(lustre_kset, "osc");
1102         if (osc) {
1103                 rc = sysfs_create_link(osc, &osp->opd_dt_dev.dd_kobj,
1104                                        obd->obd_name);
1105                 kobject_put(osc);
1106         }
1107
1108         osp->opd_debugfs = ldebugfs_add_symlink(obd->obd_name, "osc",
1109                                                 "../osp/%s", obd->obd_name);
1110         if (!osp->opd_debugfs)
1111                 CERROR("%s: failed to create OSC debugfs symlink\n",
1112                        obd->obd_name);
1113 }