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