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