Whamcloud - gitweb
LU-9855 lustre: replace LPROCFS_CLIMP_CHECK()
[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  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/osp/lproc_osp.c
33  *
34  * Lustre OST Proxy Device (OSP), procfs functions
35  *
36  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
37  */
38
39 #define DEBUG_SUBSYSTEM S_CLASS
40
41 #include "osp_internal.h"
42
43 /**
44  * Show OSP active status
45  *
46  * \param[in] m         seq_file handle
47  * \param[in] data      unused for single entry
48  * \retval              0 on success
49  * \retval              negative number on error
50  */
51 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
52                            char *buf)
53 {
54         struct dt_device *dt = container_of(kobj, struct dt_device,
55                                             dd_kobj);
56         struct lu_device *lu = dt2lu_dev(dt);
57         struct obd_device *obd = lu->ld_obd;
58         struct obd_import *imp;
59         int rc;
60
61         with_imp_locked(obd, imp, rc)
62                 rc = sprintf(buf, "%d\n", !imp->imp_deactive);
63         return rc;
64 }
65
66 /**
67  * Activate/Deactivate OSP
68  *
69  * \param[in] file      proc file
70  * \param[in] buffer    string, which is "1" or "0" to activate/deactivate OSP
71  * \param[in] count     \a buffer length
72  * \param[in] off       unused for single entry
73  * \retval              \a count on success
74  * \retval              negative number on error
75  */
76 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
77                             const char *buffer, size_t count)
78 {
79         struct dt_device *dt = container_of(kobj, struct dt_device,
80                                             dd_kobj);
81         struct lu_device *lu = dt2lu_dev(dt);
82         struct obd_device *obd = lu->ld_obd;
83         struct obd_import *imp;
84         bool val;
85         int rc;
86
87         rc = kstrtobool(buffer, &val);
88         if (rc)
89                 return rc;
90
91         with_imp_locked(obd, imp, rc) {
92                 /* opposite senses */
93                 if (obd->u.cli.cl_import->imp_deactive == val)
94                         rc = ptlrpc_set_import_active(imp, val);
95                 else
96                         CDEBUG(D_CONFIG,
97                                "activate %u: ignoring repeat request\n",
98                                (unsigned int)val);
99         }
100
101         return rc ?: count;
102 }
103 LUSTRE_RW_ATTR(active);
104
105 /**
106  * Show number of RPCs in flight
107  *
108  * \param[in] m         seq_file handle
109  * \param[in] data      unused for single entry
110  * \retval              0 on success
111  * \retval              negative number on error
112  */
113 static ssize_t sync_in_flight_show(struct kobject *kobj,
114                                    struct attribute *attr,
115                                    char *buf)
116 {
117         struct dt_device *dt = container_of(kobj, struct dt_device,
118                                             dd_kobj);
119         struct osp_device *osp = dt2osp_dev(dt);
120
121         return sprintf(buf, "%u\n", atomic_read(&osp->opd_sync_rpcs_in_flight));
122 }
123 LUSTRE_RO_ATTR(sync_in_flight);
124
125 /**
126  * Show number of RPCs in processing (including uncommitted by OST)
127  *
128  * \param[in] m         seq_file handle
129  * \param[in] data      unused for single entry
130  * \retval              0 on success
131  * \retval              negative number on error
132  */
133 static ssize_t sync_in_progress_show(struct kobject *kobj,
134                                      struct attribute *attr,
135                                      char *buf)
136 {
137         struct dt_device *dt = container_of(kobj, struct dt_device,
138                                             dd_kobj);
139         struct osp_device *osp = dt2osp_dev(dt);
140
141         return sprintf(buf, "%u\n", atomic_read(&osp->opd_sync_rpcs_in_progress));
142 }
143 LUSTRE_RO_ATTR(sync_in_progress);
144
145 /**
146  * Show number of changes to sync
147  *
148  * \param[in] m         seq_file handle
149  * \param[in] data      unused for single entry
150  * \retval              0 on success
151  * \retval              negative number on error
152  */
153 static ssize_t sync_changes_show(struct kobject *kobj,
154                                  struct attribute *attr,
155                                  char *buf)
156 {
157         struct dt_device *dt = container_of(kobj, struct dt_device,
158                                             dd_kobj);
159         struct osp_device *osp = dt2osp_dev(dt);
160
161         return sprintf(buf, "%u\n", atomic_read(&osp->opd_sync_changes));
162 }
163
164 /**
165  * Sync changes
166  *
167  * \param[in] file      proc file
168  * \param[in] buffer    unused because any input will do
169  * \param[in] count     \a buffer length
170  * \param[in] off       unused for single entry
171  * \retval              \a count on success
172  * \retval              negative number on error
173  */
174 static ssize_t sync_changes_store(struct kobject *kobj, struct attribute *attr,
175                                   const char *buffer, size_t count)
176 {
177         struct dt_device *dt = container_of(kobj, struct dt_device,
178                                             dd_kobj);
179         struct osp_device *osp = dt2osp_dev(dt);
180         struct lu_env env;
181         int rc;
182
183         rc = lu_env_init(&env, LCT_LOCAL);
184         if (rc != 0)
185                 return rc;
186
187         rc = dt_sync(&env, &osp->opd_dt_dev);
188         lu_env_fini(&env);
189
190         return rc == 0 ? count : rc;
191 }
192 LUSTRE_RW_ATTR(sync_changes);
193
194 /**
195  * Show maximum number of RPCs in flight allowed
196  *
197  * \param[in] m         seq_file handle
198  * \param[in] data      unused for single entry
199  * \retval              0 on success
200  * \retval              negative number on error
201  */
202 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
203                                        struct attribute *attr,
204                                        char *buf)
205 {
206         struct dt_device *dt = container_of(kobj, struct dt_device,
207                                             dd_kobj);
208         struct osp_device *osp = dt2osp_dev(dt);
209
210         return sprintf(buf, "%u\n", osp->opd_sync_max_rpcs_in_flight);
211 }
212
213 /**
214  * Change maximum number of RPCs in flight allowed
215  *
216  * \param[in] file      proc file
217  * \param[in] buffer    string which represents maximum number
218  * \param[in] count     \a buffer length
219  * \param[in] off       unused for single entry
220  * \retval              \a count on success
221  * \retval              negative number on error
222  */
223 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
224                                         struct attribute *attr,
225                                         const char *buffer,
226                                         size_t count)
227 {
228         struct dt_device *dt = container_of(kobj, struct dt_device,
229                                             dd_kobj);
230         struct osp_device *osp = dt2osp_dev(dt);
231         unsigned int val;
232         int rc;
233
234         rc = kstrtouint(buffer, 0, &val);
235         if (rc)
236                 return rc;
237
238         if (val == 0)
239                 return -ERANGE;
240
241         osp->opd_sync_max_rpcs_in_flight = val;
242         return count;
243 }
244 LUSTRE_RW_ATTR(max_rpcs_in_flight);
245
246 /**
247  * Show maximum number of RPCs in processing allowed
248  *
249  * \param[in] m         seq_file handle
250  * \param[in] data      unused
251  * \retval              0 on success
252  * \retval              negative number on error
253  */
254 static ssize_t max_rpcs_in_progress_show(struct kobject *kobj,
255                                          struct attribute *attr,
256                                          char *buf)
257 {
258         struct dt_device *dt = container_of(kobj, struct dt_device,
259                                             dd_kobj);
260         struct osp_device *osp = dt2osp_dev(dt);
261
262         return sprintf(buf, "%u\n", osp->opd_sync_max_rpcs_in_progress);
263 }
264
265 /**
266  * Change maximum number of RPCs in processing allowed
267  *
268  * \param[in] file      proc file
269  * \param[in] buffer    string which represents maximum number
270  * \param[in] count     \a buffer length
271  * \param[in] off       unused for single entry
272  * \retval              \a count on success
273  * \retval              negative number on error
274  */
275 static ssize_t max_rpcs_in_progress_store(struct kobject *kobj,
276                                           struct attribute *attr,
277                                           const char *buffer,
278                                           size_t count)
279 {
280         struct dt_device *dt = container_of(kobj, struct dt_device,
281                                             dd_kobj);
282         struct osp_device *osp = dt2osp_dev(dt);
283         unsigned int val;
284         int rc;
285
286         rc = kstrtouint(buffer, 0, &val);
287         if (rc)
288                 return rc;
289
290         if (val == 0)
291                 return -ERANGE;
292
293         osp->opd_sync_max_rpcs_in_progress = val;
294
295         return count;
296 }
297 LUSTRE_RW_ATTR(max_rpcs_in_progress);
298
299 /**
300  * Show number of objects to precreate next time
301  *
302  * \param[in] m         seq_file handle
303  * \param[in] data      unused for single entry
304  * \retval              0 on success
305  * \retval              negative number on error
306  */
307 static ssize_t create_count_show(struct kobject *kobj,
308                                  struct attribute *attr,
309                                  char *buf)
310 {
311         struct dt_device *dt = container_of(kobj, struct dt_device,
312                                             dd_kobj);
313         struct osp_device *osp = dt2osp_dev(dt);
314
315         if (!osp->opd_pre)
316                 return -EINVAL;
317
318         return sprintf(buf, "%d\n", osp->opd_pre_create_count);
319 }
320
321 /**
322  * Change number of objects to precreate next time
323  *
324  * \param[in] file      proc file
325  * \param[in] buffer    string which represents number of objects to precreate
326  * \param[in] count     \a buffer length
327  * \param[in] off       unused for single entry
328  * \retval              \a count on success
329  * \retval              negative number on error
330  */
331 static ssize_t create_count_store(struct kobject *kobj, struct attribute *attr,
332                                   const char *buffer, size_t count)
333 {
334         struct dt_device *dt = container_of(kobj, struct dt_device,
335                                             dd_kobj);
336         struct osp_device *osp = dt2osp_dev(dt);
337         unsigned int val;
338         int rc, i;
339
340         if (!osp->opd_pre)
341                 return -EINVAL;
342
343
344         rc = kstrtouint(buffer, 0, &val);
345         if (rc)
346                 return rc;
347
348         /* The MDT ALWAYS needs to limit the precreate count to
349          * OST_MAX_PRECREATE, and the constant cannot be changed
350          * because it is a value shared between the OSP and OST
351          * that is the maximum possible number of objects that will
352          * ever be handled by MDT->OST recovery processing.
353          *
354          * If the OST ever gets a request to delete more orphans,
355          * this implies that something has gone badly on the MDT
356          * and the OST will refuse to delete so much data from the
357          * filesystem as a safety measure. */
358         if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
359                 return -ERANGE;
360         if (val > osp->opd_pre_max_create_count)
361                 return -ERANGE;
362
363         for (i = 1; (i << 1) <= val; i <<= 1)
364                 ;
365         osp->opd_pre_create_count = i;
366
367         return count;
368 }
369 LUSTRE_RW_ATTR(create_count);
370
371 /**
372  * Show maximum number of objects to precreate
373  *
374  * \param[in] m         seq_file handle
375  * \param[in] data      unused for single entry
376  * \retval              0 on success
377  * \retval              negative number on error
378  */
379 static ssize_t max_create_count_show(struct kobject *kobj,
380                                      struct attribute *attr,
381                                      char *buf)
382 {
383         struct dt_device *dt = container_of(kobj, struct dt_device,
384                                             dd_kobj);
385         struct osp_device *osp = dt2osp_dev(dt);
386
387         if (!osp->opd_pre)
388                 return -EINVAL;
389
390         return sprintf(buf, "%d\n", osp->opd_pre_max_create_count);
391 }
392
393 /**
394  * Change maximum number of objects to precreate
395  *
396  * \param[in] file      proc file
397  * \param[in] buffer    string which represents maximum number
398  * \param[in] count     \a buffer length
399  * \param[in] off       unused for single entry
400  * \retval              \a count on success
401  * \retval              negative number on error
402  */
403 static ssize_t max_create_count_store(struct kobject *kobj,
404                                       struct attribute *attr,
405                                       const char *buffer, size_t count)
406 {
407         struct dt_device *dt = container_of(kobj, struct dt_device,
408                                             dd_kobj);
409         struct osp_device *osp = dt2osp_dev(dt);
410         unsigned int val;
411         int rc;
412
413         if (!osp->opd_pre)
414                 return -EINVAL;
415
416         rc = kstrtouint(buffer, 0, &val);
417         if (rc)
418                 return rc;
419
420         if (val && (val < OST_MIN_PRECREATE ||
421                     val > OST_MAX_PRECREATE))
422                 return -ERANGE;
423
424         if (osp->opd_pre_create_count > val)
425                 osp->opd_pre_create_count = val;
426
427         /* Can be 0 after setting max_create_count to 0 */
428         if (osp->opd_pre_create_count == 0 && val != 0)
429                 osp->opd_pre_create_count = OST_MIN_PRECREATE;
430
431         osp->opd_pre_max_create_count = val;
432
433         return count;
434 }
435 LUSTRE_RW_ATTR(max_create_count);
436
437 /**
438  * Show last id to assign in creation
439  *
440  * \param[in] m         seq_file handle
441  * \param[in] data      unused for single entry
442  * \retval              0 on success
443  * \retval              negative number on error
444  */
445 static ssize_t prealloc_next_id_show(struct kobject *kobj,
446                                      struct attribute *attr,
447                                      char *buf)
448 {
449         struct dt_device *dt = container_of(kobj, struct dt_device,
450                                             dd_kobj);
451         struct osp_device *osp = dt2osp_dev(dt);
452         struct lu_fid *fid;
453         u64 id;
454
455         if (!osp->opd_pre)
456                 return -EINVAL;
457
458         fid = &osp->opd_pre_used_fid;
459         if (fid_is_idif(fid)) {
460                 id = fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid));
461                 id++;
462         } else {
463                 id = unlikely(fid_oid(fid) == LUSTRE_DATA_SEQ_MAX_WIDTH) ?
464                         1 : fid_oid(fid) + 1;
465         }
466
467         return sprintf(buf, "%llu\n", id);
468 }
469 LUSTRE_RO_ATTR(prealloc_next_id);
470
471 /**
472  * Show last created id OST reported
473  *
474  * \param[in] m         seq_file handle
475  * \param[in] data      unused for single entry
476  * \retval              0 on success
477  * \retval              negative number on error
478  */
479
480 static ssize_t prealloc_last_id_show(struct kobject *kobj,
481                                      struct attribute *attr,
482                                      char *buf)
483 {
484         struct dt_device *dt = container_of(kobj, struct dt_device,
485                                             dd_kobj);
486         struct osp_device *osp = dt2osp_dev(dt);
487         struct lu_fid *fid;
488         u64 id;
489
490         if (!osp->opd_pre)
491                 return -EINVAL;
492
493         fid = &osp->opd_pre_last_created_fid;
494         id = fid_is_idif(fid) ?
495                          fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid)) :
496                          fid_oid(fid);
497
498         return sprintf(buf, "%llu\n", id);
499 }
500 LUSTRE_RO_ATTR(prealloc_last_id);
501
502 /**
503  * Show next FID sequence to precreate
504  *
505  * \param[in] m         seq_file handle
506  * \param[in] data      unused for single entry
507  * \retval              0 on success
508  * \retval              negative number on error
509  */
510 static ssize_t prealloc_next_seq_show(struct kobject *kobj,
511                                       struct attribute *attr,
512                                       char *buf)
513 {
514         struct dt_device *dt = container_of(kobj, struct dt_device,
515                                             dd_kobj);
516         struct osp_device *osp = dt2osp_dev(dt);
517         struct lu_fid *fid;
518
519         if (!osp->opd_pre)
520                 return -EINVAL;
521
522         fid = &osp->opd_pre_used_fid;
523         return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
524                        fid_seq(fid) & (~0xffff) : fid_seq(fid));
525 }
526 LUSTRE_RO_ATTR(prealloc_next_seq);
527
528 /**
529  * Show last created FID sequence OST reported
530  *
531  * \param[in] m         seq_file handle
532  * \param[in] data      unused for single entry
533  * \retval              0 on success
534  * \retval              negative number on error
535  */
536 static ssize_t prealloc_last_seq_show(struct kobject *kobj,
537                                       struct attribute *attr,
538                                       char *buf)
539 {
540         struct dt_device *dt = container_of(kobj, struct dt_device,
541                                             dd_kobj);
542         struct osp_device *osp = dt2osp_dev(dt);
543         struct lu_fid *fid;
544
545         if (!osp->opd_pre)
546                 return -EINVAL;
547
548         fid = &osp->opd_pre_last_created_fid;
549         return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
550                        fid_seq(fid) & (~0xffff) : fid_seq(fid));
551 }
552 LUSTRE_RO_ATTR(prealloc_last_seq);
553
554 /**
555  * Show the number of ids reserved by declare
556  *
557  * \param[in] m         seq_file handle
558  * \param[in] data      unused for single entry
559  * \retval              0 on success
560  * \retval              negative number on error
561  */
562 static ssize_t prealloc_reserved_show(struct kobject *kobj,
563                                       struct attribute *attr,
564                                       char *buf)
565 {
566         struct dt_device *dt = container_of(kobj, struct dt_device,
567                                             dd_kobj);
568         struct osp_device *osp = dt2osp_dev(dt);
569
570         if (!osp->opd_pre)
571                 return -EINVAL;
572
573         return sprintf(buf, "%llu\n", osp->opd_pre_reserved);
574 }
575 LUSTRE_RO_ATTR(prealloc_reserved);
576
577 /**
578  * Show interval (in seconds) to update statfs data
579  *
580  * \param[in] m         seq_file handle
581  * \param[in] data      unused for single entry
582  * \retval              0 on success
583  * \retval              negative number on error
584  */
585 static ssize_t maxage_show(struct kobject *kobj,
586                            struct attribute *attr,
587                            char *buf)
588 {
589         struct dt_device *dt = container_of(kobj, struct dt_device,
590                                             dd_kobj);
591         struct osp_device *osp = dt2osp_dev(dt);
592
593         return sprintf(buf, "%lld\n", osp->opd_statfs_maxage);
594 }
595
596 /**
597  * Change interval to update statfs data
598  *
599  * \param[in] file      proc file
600  * \param[in] buffer    string which represents statfs interval (in seconds)
601  * \param[in] count     \a buffer length
602  * \param[in] off       unused for single entry
603  * \retval              \a count on success
604  * \retval              negative number on error
605  */
606 static ssize_t maxage_store(struct kobject *kobj, struct attribute *attr,
607                             const char *buffer, size_t count)
608 {
609         struct dt_device *dt = container_of(kobj, struct dt_device,
610                                             dd_kobj);
611         struct osp_device *osp = dt2osp_dev(dt);
612         unsigned int val;
613         int rc;
614
615         rc = kstrtouint(buffer, 0, &val);
616         if (rc)
617                 return rc;
618
619         if (val == 0)
620                 return -ERANGE;
621
622         osp->opd_statfs_maxage = val;
623
624         return count;
625 }
626 LUSTRE_RW_ATTR(maxage);
627
628 /**
629  * Show current precreation status: output 0 means success, otherwise negative
630  * number is printed
631  *
632  * \param[in] m         seq_file handle
633  * \param[in] data      unused for single entry
634  * \retval              0 on success
635  * \retval              negative number on error
636  */
637 static ssize_t prealloc_status_show(struct kobject *kobj,
638                                     struct attribute *attr,
639                                     char *buf)
640 {
641         struct dt_device *dt = container_of(kobj, struct dt_device,
642                                             dd_kobj);
643         struct osp_device *osp = dt2osp_dev(dt);
644
645         if (!osp->opd_pre)
646                 return -EINVAL;
647
648         return sprintf(buf, "%d\n", osp->opd_pre_status);
649 }
650 LUSTRE_RO_ATTR(prealloc_status);
651
652 /**
653  * Show the number of RPCs in processing (including uncommitted by OST) plus
654  * changes to sync, i.e. this is the total number of changes OST needs to apply
655  * and commit.
656  *
657  * This counter is used to determine if OST has space returned. A zero value
658  * indicates that OST storage space consumed by destroyed objects has been freed
659  * on disk, the associated llog records have been cleared, and no synchronous
660  * RPC are being processed.
661  *
662  * \param[in] m         seq_file handle
663  * \param[in] data      unused for single entry
664  * \retval              0 on success
665  * \retval              negative number on error
666  */
667 static ssize_t destroys_in_flight_show(struct kobject *kobj,
668                                        struct attribute *attr,
669                                        char *buf)
670 {
671         struct dt_device *dt = container_of(kobj, struct dt_device,
672                                             dd_kobj);
673         struct osp_device *osp = dt2osp_dev(dt);
674
675         return sprintf(buf, "%u\n",
676                        atomic_read(&osp->opd_sync_rpcs_in_progress) +
677                        atomic_read(&osp->opd_sync_changes));
678 }
679 LUSTRE_RO_ATTR(destroys_in_flight);
680
681 /**
682  * Show changes synced from previous mount
683  *
684  * \param[in] m         seq_file handle
685  * \param[in] data      unused for single entry
686  * \retval              0 on success
687  * \retval              negative number on error
688  */
689 static ssize_t old_sync_processed_show(struct kobject *kobj,
690                                        struct attribute *attr,
691                                        char *buf)
692 {
693         struct dt_device *dt = container_of(kobj, struct dt_device,
694                                             dd_kobj);
695         struct osp_device *osp = dt2osp_dev(dt);
696
697         return sprintf(buf, "%d\n", osp->opd_sync_prev_done);
698 }
699 LUSTRE_RO_ATTR(old_sync_processed);
700
701 /**
702  * Show maximum number of RPCs in flight
703  *
704  * \param[in] m         seq_file handle
705  * \param[in] data      unused for single entry
706  * \retval              0 on success
707  * \retval              negative number on error
708  */
709 static ssize_t lfsck_max_rpcs_in_flight_show(struct kobject *kobj,
710                                              struct attribute *attr,
711                                              char *buf)
712 {
713         struct dt_device *dt = container_of(kobj, struct dt_device,
714                                             dd_kobj);
715         struct lu_device *lu = dt2lu_dev(dt);
716         struct obd_device *obd = lu->ld_obd;
717         u32 max;
718
719         max = obd_get_max_rpcs_in_flight(&obd->u.cli);
720         return sprintf(buf, "%u\n", max);
721 }
722
723 /**
724  * Change maximum number of RPCs in flight
725  *
726  * \param[in] file      proc file
727  * \param[in] buffer    string which represents maximum number of RPCs in flight
728  * \param[in] count     \a buffer length
729  * \param[in] off       unused for single entry
730  * \retval              \a count on success
731  * \retval              negative number on error
732  */
733 static ssize_t lfsck_max_rpcs_in_flight_store(struct kobject *kobj,
734                                               struct attribute *attr,
735                                               const char *buffer,
736                                               size_t count)
737 {
738         struct dt_device *dt = container_of(kobj, struct dt_device,
739                                             dd_kobj);
740         struct lu_device *lu = dt2lu_dev(dt);
741         struct obd_device *obd = lu->ld_obd;
742         unsigned int val;
743         int rc;
744
745         rc = kstrtouint(buffer, 0, &val);
746         if (rc)
747                 return rc;
748
749         rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
750         return rc ? rc : count;
751 }
752 LUSTRE_RW_ATTR(lfsck_max_rpcs_in_flight);
753
754 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
755                   char *buffer)
756 {
757         struct dt_device *dt = container_of(kobj, struct dt_device,
758                                             dd_kobj);
759         struct lu_device *lu = dt2lu_dev(dt);
760         struct obd_device *obd = lu->ld_obd;
761         struct obd_import *imp;
762         int rc;
763
764         with_imp_locked(obd, imp, rc)
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 LPROC_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 lprocfs_vars lprocfs_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 lprocfs_vars lprocfs_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_vars = lprocfs_osp_md_vars;
1066         } else {
1067                 osp->opd_dt_dev.dd_ktype.default_attrs = osp_obd_attrs;
1068                 obd->obd_vars = lprocfs_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 = ldebugfs_register(obd->obd_name,
1083                                                    obd->obd_type->typ_debugfs_entry,
1084                                                    obd->obd_vars, obd);
1085         if (IS_ERR_OR_NULL(obd->obd_debugfs_entry)) {
1086                 rc = obd->obd_debugfs_entry ? PTR_ERR(obd->obd_debugfs_entry)
1087                                             : -ENOMEM;
1088                 CERROR("%s: error %d setting up debugfs\n",
1089                        obd->obd_name, rc);
1090                 obd->obd_debugfs_entry = NULL;
1091                 dt_tunables_fini(&osp->opd_dt_dev);
1092                 return;
1093         }
1094
1095         sptlrpc_lprocfs_cliobd_attach(obd);
1096         ptlrpc_lprocfs_register_obd(obd);
1097
1098         if (osp->opd_connect_mdt || !strstr(obd->obd_name, "osc"))
1099                 return;
1100
1101         /* If the real OSC is present which is the case for setups
1102          * with both server and clients on the same node then use
1103          * the OSC's proc root
1104          */
1105         osc = kset_find_obj(lustre_kset, "osc");
1106         if (osc) {
1107                 rc = sysfs_create_link(osc, &osp->opd_dt_dev.dd_kobj,
1108                                        obd->obd_name);
1109                 kobject_put(osc);
1110         }
1111
1112         osp->opd_debugfs = ldebugfs_add_symlink(obd->obd_name, "osc",
1113                                                 "../osp/%s", obd->obd_name);
1114         if (!osp->opd_debugfs)
1115                 CERROR("%s: failed to create OSC debugfs symlink\n",
1116                        obd->obd_name);
1117 }