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