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