Whamcloud - gitweb
LU-14487 modules: remove references to Sun Trademark.
[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, i;
341
342         if (!osp->opd_pre)
343                 return -EINVAL;
344
345
346         rc = kstrtouint(buffer, 0, &val);
347         if (rc)
348                 return rc;
349
350         /* The MDT ALWAYS needs to limit the precreate count to
351          * OST_MAX_PRECREATE, and the constant cannot be changed
352          * because it is a value shared between the OSP and OST
353          * that is the maximum possible number of objects that will
354          * ever be handled by MDT->OST recovery processing.
355          *
356          * If the OST ever gets a request to delete more orphans,
357          * this implies that something has gone badly on the MDT
358          * and the OST will refuse to delete so much data from the
359          * filesystem as a safety measure. */
360         if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
361                 return -ERANGE;
362         if (val > osp->opd_pre_max_create_count)
363                 return -ERANGE;
364
365         for (i = 1; (i << 1) <= val; i <<= 1)
366                 ;
367         osp->opd_pre_create_count = i;
368
369         return count;
370 }
371 LUSTRE_RW_ATTR(create_count);
372
373 /**
374  * Show maximum number of objects to precreate
375  *
376  * \param[in] m         seq_file handle
377  * \param[in] data      unused for single entry
378  * \retval              0 on success
379  * \retval              negative number on error
380  */
381 static ssize_t max_create_count_show(struct kobject *kobj,
382                                      struct attribute *attr,
383                                      char *buf)
384 {
385         struct dt_device *dt = container_of(kobj, struct dt_device,
386                                             dd_kobj);
387         struct osp_device *osp = dt2osp_dev(dt);
388
389         if (!osp->opd_pre)
390                 return -EINVAL;
391
392         return sprintf(buf, "%d\n", osp->opd_pre_max_create_count);
393 }
394
395 /**
396  * Change maximum number of objects to precreate
397  *
398  * \param[in] file      proc file
399  * \param[in] buffer    string which represents maximum number
400  * \param[in] count     \a buffer length
401  * \param[in] off       unused for single entry
402  * \retval              \a count on success
403  * \retval              negative number on error
404  */
405 static ssize_t max_create_count_store(struct kobject *kobj,
406                                       struct attribute *attr,
407                                       const char *buffer, size_t count)
408 {
409         struct dt_device *dt = container_of(kobj, struct dt_device,
410                                             dd_kobj);
411         struct osp_device *osp = dt2osp_dev(dt);
412         unsigned int val;
413         int rc;
414
415         if (!osp->opd_pre)
416                 return -EINVAL;
417
418         rc = kstrtouint(buffer, 0, &val);
419         if (rc)
420                 return rc;
421
422         if (val && (val < OST_MIN_PRECREATE ||
423                     val > OST_MAX_PRECREATE))
424                 return -ERANGE;
425
426         if (osp->opd_pre_create_count > val)
427                 osp->opd_pre_create_count = val;
428
429         /* Can be 0 after setting max_create_count to 0 */
430         if (osp->opd_pre_create_count == 0 && val != 0)
431                 osp->opd_pre_create_count = OST_MIN_PRECREATE;
432
433         osp->opd_pre_max_create_count = val;
434
435         return count;
436 }
437 LUSTRE_RW_ATTR(max_create_count);
438
439 /**
440  * Show last id to assign in creation
441  *
442  * \param[in] m         seq_file handle
443  * \param[in] data      unused for single entry
444  * \retval              0 on success
445  * \retval              negative number on error
446  */
447 static ssize_t prealloc_next_id_show(struct kobject *kobj,
448                                      struct attribute *attr,
449                                      char *buf)
450 {
451         struct dt_device *dt = container_of(kobj, struct dt_device,
452                                             dd_kobj);
453         struct osp_device *osp = dt2osp_dev(dt);
454         struct lu_fid *fid;
455         u64 id;
456
457         if (!osp->opd_pre)
458                 return -EINVAL;
459
460         fid = &osp->opd_pre_used_fid;
461         if (fid_is_idif(fid)) {
462                 id = fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid));
463                 id++;
464         } else {
465                 id = unlikely(fid_oid(fid) == LUSTRE_DATA_SEQ_MAX_WIDTH) ?
466                         1 : fid_oid(fid) + 1;
467         }
468
469         return sprintf(buf, "%llu\n", id);
470 }
471 LUSTRE_RO_ATTR(prealloc_next_id);
472
473 /**
474  * Show last created id OST reported
475  *
476  * \param[in] m         seq_file handle
477  * \param[in] data      unused for single entry
478  * \retval              0 on success
479  * \retval              negative number on error
480  */
481
482 static ssize_t prealloc_last_id_show(struct kobject *kobj,
483                                      struct attribute *attr,
484                                      char *buf)
485 {
486         struct dt_device *dt = container_of(kobj, struct dt_device,
487                                             dd_kobj);
488         struct osp_device *osp = dt2osp_dev(dt);
489         struct lu_fid *fid;
490         u64 id;
491
492         if (!osp->opd_pre)
493                 return -EINVAL;
494
495         fid = &osp->opd_pre_last_created_fid;
496         id = fid_is_idif(fid) ?
497                          fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid)) :
498                          fid_oid(fid);
499
500         return sprintf(buf, "%llu\n", id);
501 }
502 LUSTRE_RO_ATTR(prealloc_last_id);
503
504 /**
505  * Show next FID sequence to precreate
506  *
507  * \param[in] m         seq_file handle
508  * \param[in] data      unused for single entry
509  * \retval              0 on success
510  * \retval              negative number on error
511  */
512 static ssize_t prealloc_next_seq_show(struct kobject *kobj,
513                                       struct attribute *attr,
514                                       char *buf)
515 {
516         struct dt_device *dt = container_of(kobj, struct dt_device,
517                                             dd_kobj);
518         struct osp_device *osp = dt2osp_dev(dt);
519         struct lu_fid *fid;
520
521         if (!osp->opd_pre)
522                 return -EINVAL;
523
524         fid = &osp->opd_pre_used_fid;
525         return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
526                        fid_seq(fid) & (~0xffff) : fid_seq(fid));
527 }
528 LUSTRE_RO_ATTR(prealloc_next_seq);
529
530 /**
531  * Show last created FID sequence OST reported
532  *
533  * \param[in] m         seq_file handle
534  * \param[in] data      unused for single entry
535  * \retval              0 on success
536  * \retval              negative number on error
537  */
538 static ssize_t prealloc_last_seq_show(struct kobject *kobj,
539                                       struct attribute *attr,
540                                       char *buf)
541 {
542         struct dt_device *dt = container_of(kobj, struct dt_device,
543                                             dd_kobj);
544         struct osp_device *osp = dt2osp_dev(dt);
545         struct lu_fid *fid;
546
547         if (!osp->opd_pre)
548                 return -EINVAL;
549
550         fid = &osp->opd_pre_last_created_fid;
551         return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
552                        fid_seq(fid) & (~0xffff) : fid_seq(fid));
553 }
554 LUSTRE_RO_ATTR(prealloc_last_seq);
555
556 /**
557  * Show the number of ids reserved by declare
558  *
559  * \param[in] m         seq_file handle
560  * \param[in] data      unused for single entry
561  * \retval              0 on success
562  * \retval              negative number on error
563  */
564 static ssize_t prealloc_reserved_show(struct kobject *kobj,
565                                       struct attribute *attr,
566                                       char *buf)
567 {
568         struct dt_device *dt = container_of(kobj, struct dt_device,
569                                             dd_kobj);
570         struct osp_device *osp = dt2osp_dev(dt);
571
572         if (!osp->opd_pre)
573                 return -EINVAL;
574
575         return sprintf(buf, "%llu\n", osp->opd_pre_reserved);
576 }
577 LUSTRE_RO_ATTR(prealloc_reserved);
578
579 /**
580  * Show interval (in seconds) to update statfs data
581  *
582  * \param[in] m         seq_file handle
583  * \param[in] data      unused for single entry
584  * \retval              0 on success
585  * \retval              negative number on error
586  */
587 static ssize_t maxage_show(struct kobject *kobj,
588                            struct attribute *attr,
589                            char *buf)
590 {
591         struct dt_device *dt = container_of(kobj, struct dt_device,
592                                             dd_kobj);
593         struct osp_device *osp = dt2osp_dev(dt);
594
595         return sprintf(buf, "%lld\n", osp->opd_statfs_maxage);
596 }
597
598 /**
599  * Change interval to update statfs data
600  *
601  * \param[in] file      proc file
602  * \param[in] buffer    string which represents statfs interval (in seconds)
603  * \param[in] count     \a buffer length
604  * \param[in] off       unused for single entry
605  * \retval              \a count on success
606  * \retval              negative number on error
607  */
608 static ssize_t maxage_store(struct kobject *kobj, struct attribute *attr,
609                             const char *buffer, size_t count)
610 {
611         struct dt_device *dt = container_of(kobj, struct dt_device,
612                                             dd_kobj);
613         struct osp_device *osp = dt2osp_dev(dt);
614         unsigned int val;
615         int rc;
616
617         rc = kstrtouint(buffer, 0, &val);
618         if (rc)
619                 return rc;
620
621         if (val == 0)
622                 return -ERANGE;
623
624         osp->opd_statfs_maxage = val;
625
626         return count;
627 }
628 LUSTRE_RW_ATTR(maxage);
629
630 /**
631  * Show current precreation status: output 0 means success, otherwise negative
632  * number is printed
633  *
634  * \param[in] m         seq_file handle
635  * \param[in] data      unused for single entry
636  * \retval              0 on success
637  * \retval              negative number on error
638  */
639 static ssize_t prealloc_status_show(struct kobject *kobj,
640                                     struct attribute *attr,
641                                     char *buf)
642 {
643         struct dt_device *dt = container_of(kobj, struct dt_device,
644                                             dd_kobj);
645         struct osp_device *osp = dt2osp_dev(dt);
646
647         if (!osp->opd_pre)
648                 return -EINVAL;
649
650         return sprintf(buf, "%d\n", osp->opd_pre_status);
651 }
652 LUSTRE_RO_ATTR(prealloc_status);
653
654 /**
655  * Show the number of RPCs in processing (including uncommitted by OST) plus
656  * changes to sync, i.e. this is the total number of changes OST needs to apply
657  * and commit.
658  *
659  * This counter is used to determine if OST has space returned. A zero value
660  * indicates that OST storage space consumed by destroyed objects has been freed
661  * on disk, the associated llog records have been cleared, and no synchronous
662  * RPC are being processed.
663  *
664  * \param[in] m         seq_file handle
665  * \param[in] data      unused for single entry
666  * \retval              0 on success
667  * \retval              negative number on error
668  */
669 static ssize_t destroys_in_flight_show(struct kobject *kobj,
670                                        struct attribute *attr,
671                                        char *buf)
672 {
673         struct dt_device *dt = container_of(kobj, struct dt_device,
674                                             dd_kobj);
675         struct osp_device *osp = dt2osp_dev(dt);
676
677         return sprintf(buf, "%u\n",
678                        atomic_read(&osp->opd_sync_rpcs_in_progress) +
679                        atomic_read(&osp->opd_sync_changes));
680 }
681 LUSTRE_RO_ATTR(destroys_in_flight);
682
683 /**
684  * Show changes synced from previous mount
685  *
686  * \param[in] m         seq_file handle
687  * \param[in] data      unused for single entry
688  * \retval              0 on success
689  * \retval              negative number on error
690  */
691 static ssize_t old_sync_processed_show(struct kobject *kobj,
692                                        struct attribute *attr,
693                                        char *buf)
694 {
695         struct dt_device *dt = container_of(kobj, struct dt_device,
696                                             dd_kobj);
697         struct osp_device *osp = dt2osp_dev(dt);
698
699         return sprintf(buf, "%d\n", osp->opd_sync_prev_done);
700 }
701 LUSTRE_RO_ATTR(old_sync_processed);
702
703 /**
704  * Show maximum number of RPCs in flight
705  *
706  * \param[in] m         seq_file handle
707  * \param[in] data      unused for single entry
708  * \retval              0 on success
709  * \retval              negative number on error
710  */
711 static ssize_t lfsck_max_rpcs_in_flight_show(struct kobject *kobj,
712                                              struct attribute *attr,
713                                              char *buf)
714 {
715         struct dt_device *dt = container_of(kobj, struct dt_device,
716                                             dd_kobj);
717         struct lu_device *lu = dt2lu_dev(dt);
718         struct obd_device *obd = lu->ld_obd;
719         u32 max;
720
721         max = obd_get_max_rpcs_in_flight(&obd->u.cli);
722         return sprintf(buf, "%u\n", max);
723 }
724
725 /**
726  * Change maximum number of RPCs in flight
727  *
728  * \param[in] file      proc file
729  * \param[in] buffer    string which represents maximum number of RPCs in flight
730  * \param[in] count     \a buffer length
731  * \param[in] off       unused for single entry
732  * \retval              \a count on success
733  * \retval              negative number on error
734  */
735 static ssize_t lfsck_max_rpcs_in_flight_store(struct kobject *kobj,
736                                               struct attribute *attr,
737                                               const char *buffer,
738                                               size_t count)
739 {
740         struct dt_device *dt = container_of(kobj, struct dt_device,
741                                             dd_kobj);
742         struct lu_device *lu = dt2lu_dev(dt);
743         struct obd_device *obd = lu->ld_obd;
744         unsigned int val;
745         int rc;
746
747         rc = kstrtouint(buffer, 0, &val);
748         if (rc)
749                 return rc;
750
751         rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
752         return rc ? rc : count;
753 }
754 LUSTRE_RW_ATTR(lfsck_max_rpcs_in_flight);
755
756 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
757                   char *buffer)
758 {
759         struct dt_device *dt = container_of(kobj, struct dt_device,
760                                             dd_kobj);
761         struct lu_device *lu = dt2lu_dev(dt);
762         struct obd_device *obd = lu->ld_obd;
763         int rc;
764
765         rc = ptlrpc_obd_ping(obd);
766
767         return rc;
768 }
769 LUSTRE_RO_ATTR(ping);
770
771 ssize_t osp_conn_uuid_show(struct kobject *kobj, struct attribute *attr,
772                            char *buf)
773 {
774         struct dt_device *dt = container_of(kobj, struct dt_device,
775                                             dd_kobj);
776         struct lu_device *lu = dt2lu_dev(dt);
777         struct obd_device *obd = lu->ld_obd;
778         struct obd_import *imp;
779         struct ptlrpc_connection *conn;
780         ssize_t count;
781
782         with_imp_locked(obd, imp, count) {
783                 conn = imp->imp_connection;
784                 if (conn)
785                         count = sprintf(buf, "%s\n", conn->c_remote_uuid.uuid);
786                 else
787                         count = sprintf(buf, "%s\n", "<none>");
788         }
789
790         return count;
791 }
792
793 LUSTRE_ATTR(ost_conn_uuid, 0444, osp_conn_uuid_show, NULL);
794 LUSTRE_ATTR(mdt_conn_uuid, 0444, osp_conn_uuid_show, NULL);
795
796 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, connect_flags);
797 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, server_uuid);
798 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, timeouts);
799
800 LDEBUGFS_SEQ_FOPS_RW_TYPE(osp, import);
801 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, state);
802
803 /**
804  * Show high watermark (in megabytes). If available free space at OST is grater
805  * than high watermark and object allocation for OST is disabled, enable it.
806  *
807  * \param[in] m         seq_file handle
808  * \param[in] data      unused for single entry
809  * \retval              0 on success
810  * \retval              negative number on error
811  */
812 static int osp_reserved_mb_high_seq_show(struct seq_file *m, void *data)
813 {
814         struct obd_device       *dev = m->private;
815         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
816
817         if (osp == NULL)
818                 return -EINVAL;
819
820         seq_printf(m, "%u\n", osp->opd_reserved_mb_high);
821         return 0;
822 }
823
824 /**
825  * Change high watermark
826  *
827  * \param[in] file      proc file
828  * \param[in] buffer    string which represents new value (in megabytes)
829  * \param[in] count     \a buffer length
830  * \param[in] off       unused for single entry
831  * \retval              \a count on success
832  * \retval              negative number on error
833  */
834 static ssize_t
835 osp_reserved_mb_high_seq_write(struct file *file, const char __user *buffer,
836                         size_t count, loff_t *off)
837 {
838         struct seq_file         *m = file->private_data;
839         struct obd_device       *dev = m->private;
840         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
841         char kernbuf[22] = "";
842         u64 val;
843         int                     rc;
844
845         if (osp == NULL || osp->opd_pre == NULL)
846                 return -EINVAL;
847
848         if (count >= sizeof(kernbuf))
849                 return -EINVAL;
850
851         if (copy_from_user(kernbuf, buffer, count))
852                 return -EFAULT;
853         kernbuf[count] = 0;
854
855         rc = sysfs_memparse(kernbuf, count, &val, "MiB");
856         if (rc < 0)
857                 return rc;
858         val >>= 20;
859         if (val < 1)
860                 return -ERANGE;
861
862         spin_lock(&osp->opd_pre_lock);
863         osp->opd_reserved_mb_high = val;
864         if (val <= osp->opd_reserved_mb_low)
865                 osp->opd_reserved_mb_low = val - 1;
866         spin_unlock(&osp->opd_pre_lock);
867
868         return count;
869 }
870 LDEBUGFS_SEQ_FOPS(osp_reserved_mb_high);
871
872 /**
873  * Show low watermark (in megabytes). If available free space at OST is less
874  * than low watermark, object allocation for OST is disabled.
875  *
876  * \param[in] m         seq_file handle
877  * \param[in] data      unused for single entry
878  * \retval              0 on success
879  * \retval              negative number on error
880  */
881 static int osp_reserved_mb_low_seq_show(struct seq_file *m, void *data)
882 {
883         struct obd_device       *dev = m->private;
884         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
885
886         if (osp == NULL)
887                 return -EINVAL;
888
889         seq_printf(m, "%u\n", osp->opd_reserved_mb_low);
890         return 0;
891 }
892
893 /**
894  * Change low watermark
895  *
896  * \param[in] file      proc file
897  * \param[in] buffer    string which represents new value (in megabytes)
898  * \param[in] count     \a buffer length
899  * \param[in] off       unused for single entry
900  * \retval              \a count on success
901  * \retval              negative number on error
902  */
903 static ssize_t
904 osp_reserved_mb_low_seq_write(struct file *file, const char __user *buffer,
905                         size_t count, loff_t *off)
906 {
907         struct seq_file         *m = file->private_data;
908         struct obd_device       *dev = m->private;
909         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
910         char kernbuf[22] = "";
911         u64 val;
912         int                     rc;
913
914         if (osp == NULL || osp->opd_pre == NULL)
915                 return -EINVAL;
916
917         if (count >= sizeof(kernbuf))
918                 return -EINVAL;
919
920         if (copy_from_user(kernbuf, buffer, count))
921                 return -EFAULT;
922         kernbuf[count] = 0;
923
924         rc = sysfs_memparse(kernbuf, count, &val, "MiB");
925         if (rc < 0)
926                 return rc;
927         val >>= 20;
928
929         spin_lock(&osp->opd_pre_lock);
930         osp->opd_reserved_mb_low = val;
931         if (val >= osp->opd_reserved_mb_high)
932                 osp->opd_reserved_mb_high = val + 1;
933         spin_unlock(&osp->opd_pre_lock);
934
935         return count;
936 }
937 LDEBUGFS_SEQ_FOPS(osp_reserved_mb_low);
938
939 static ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
940                                 const char *buffer, size_t count)
941 {
942         struct dt_device *dt = container_of(kobj, struct dt_device,
943                                             dd_kobj);
944         struct lu_env env;
945         int rc;
946
947         rc = lu_env_init(&env, LCT_LOCAL);
948         if (rc)
949                 return rc;
950
951         rc = dt_sync(&env, dt);
952         lu_env_fini(&env);
953
954         return rc == 0 ? count : rc;
955 }
956 LUSTRE_WO_ATTR(force_sync);
957
958 static struct ldebugfs_vars ldebugfs_osp_obd_vars[] = {
959         { .name =       "connect_flags",
960           .fops =       &osp_connect_flags_fops         },
961         { .name =       "ost_server_uuid",
962           .fops =       &osp_server_uuid_fops           },
963         { .name =       "timeouts",
964           .fops =       &osp_timeouts_fops              },
965         { .name =       "import",
966           .fops =       &osp_import_fops                },
967         { .name =       "state",
968           .fops =       &osp_state_fops                 },
969         { .name =       "reserved_mb_high",
970           .fops =       &osp_reserved_mb_high_fops      },
971         { .name =       "reserved_mb_low",
972           .fops =       &osp_reserved_mb_low_fops       },
973         { NULL }
974 };
975
976 static struct ldebugfs_vars ldebugfs_osp_md_vars[] = {
977         { .name =       "connect_flags",
978           .fops =       &osp_connect_flags_fops         },
979         { .name =       "mdt_server_uuid",
980           .fops =       &osp_server_uuid_fops           },
981         { .name =       "timeouts",
982           .fops =       &osp_timeouts_fops              },
983         { .name =       "import",
984           .fops =       &osp_import_fops                },
985         { .name =       "state",
986           .fops =       &osp_state_fops                 },
987         { NULL }
988 };
989
990 static struct attribute *osp_obd_attrs[] = {
991         /* First two for compatiability reasons */
992         &lustre_attr_lfsck_max_rpcs_in_flight.attr,
993         &lustre_attr_destroys_in_flight.attr,
994         &lustre_attr_active.attr,
995         &lustre_attr_max_rpcs_in_flight.attr,
996         &lustre_attr_max_rpcs_in_progress.attr,
997         &lustre_attr_maxage.attr,
998         &lustre_attr_ost_conn_uuid.attr,
999         &lustre_attr_ping.attr,
1000         &lustre_attr_prealloc_status.attr,
1001         &lustre_attr_prealloc_next_id.attr,
1002         &lustre_attr_prealloc_last_id.attr,
1003         &lustre_attr_prealloc_next_seq.attr,
1004         &lustre_attr_prealloc_last_seq.attr,
1005         &lustre_attr_prealloc_reserved.attr,
1006         &lustre_attr_sync_in_flight.attr,
1007         &lustre_attr_sync_in_progress.attr,
1008         &lustre_attr_sync_changes.attr,
1009         &lustre_attr_force_sync.attr,
1010         &lustre_attr_old_sync_processed.attr,
1011         &lustre_attr_create_count.attr,
1012         &lustre_attr_max_create_count.attr,
1013         NULL,
1014 };
1015
1016 static struct attribute *osp_md_attrs[] = {
1017         /* First two for compatiability reasons */
1018         &lustre_attr_lfsck_max_rpcs_in_flight.attr,
1019         &lustre_attr_destroys_in_flight.attr,
1020         &lustre_attr_active.attr,
1021         &lustre_attr_max_rpcs_in_flight.attr,
1022         &lustre_attr_max_rpcs_in_progress.attr,
1023         &lustre_attr_maxage.attr,
1024         &lustre_attr_mdt_conn_uuid.attr,
1025         &lustre_attr_ping.attr,
1026         &lustre_attr_prealloc_status.attr,
1027         NULL,
1028 };
1029
1030 void osp_tunables_fini(struct osp_device *osp)
1031 {
1032         struct obd_device *obd = osp->opd_obd;
1033         struct kobject *osc;
1034
1035         osc = kset_find_obj(lustre_kset, "osc");
1036         if (osc) {
1037                 sysfs_remove_link(osc, obd->obd_name);
1038                 kobject_put(osc);
1039         }
1040
1041         debugfs_remove_recursive(osp->opd_debugfs);
1042         osp->opd_debugfs = NULL;
1043
1044         ptlrpc_lprocfs_unregister_obd(obd);
1045
1046         debugfs_remove_recursive(obd->obd_debugfs_entry);
1047         obd->obd_debugfs_entry = NULL;
1048
1049         dt_tunables_fini(&osp->opd_dt_dev);
1050 }
1051
1052 /**
1053  * Initialize OSP sysfs / debugfs
1054  *
1055  * param[in] osp        OSP device
1056  */
1057 void osp_tunables_init(struct osp_device *osp)
1058 {
1059         struct obd_device *obd = osp->opd_obd;
1060         struct kobject *osc;
1061         int rc;
1062
1063         if (osp->opd_connect_mdt) {
1064                 osp->opd_dt_dev.dd_ktype.default_attrs = osp_md_attrs;
1065                 obd->obd_debugfs_vars = ldebugfs_osp_md_vars;
1066         } else {
1067                 osp->opd_dt_dev.dd_ktype.default_attrs = osp_obd_attrs;
1068                 obd->obd_debugfs_vars = ldebugfs_osp_obd_vars;
1069         }
1070
1071         rc = dt_tunables_init(&osp->opd_dt_dev, obd->obd_type, obd->obd_name,
1072                               NULL);
1073         if (rc) {
1074                 CERROR("%s: failed to setup DT tunables: %d\n",
1075                        obd->obd_name, rc);
1076                 return;
1077         }
1078
1079         /* Since we register the obd device with ptlrpc / sptlrpc we
1080          * have to register debugfs with obd_device
1081          */
1082         obd->obd_debugfs_entry = debugfs_create_dir(
1083                 obd->obd_name, obd->obd_type->typ_debugfs_entry);
1084         ldebugfs_add_vars(obd->obd_debugfs_entry, obd->obd_debugfs_vars, obd);
1085
1086         sptlrpc_lprocfs_cliobd_attach(obd);
1087         ptlrpc_lprocfs_register_obd(obd);
1088
1089         if (osp->opd_connect_mdt || !strstr(obd->obd_name, "osc"))
1090                 return;
1091
1092         /* If the real OSC is present which is the case for setups
1093          * with both server and clients on the same node then use
1094          * the OSC's proc root
1095          */
1096         osc = kset_find_obj(lustre_kset, "osc");
1097         if (osc) {
1098                 rc = sysfs_create_link(osc, &osp->opd_dt_dev.dd_kobj,
1099                                        obd->obd_name);
1100                 kobject_put(osc);
1101         }
1102
1103         osp->opd_debugfs = ldebugfs_add_symlink(obd->obd_name, "osc",
1104                                                 "../osp/%s", obd->obd_name);
1105         if (!osp->opd_debugfs)
1106                 CERROR("%s: failed to create OSC debugfs symlink\n",
1107                        obd->obd_name);
1108 }