Whamcloud - gitweb
LU-8726 osd-ldiskfs: bypass read for benchmarking
[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, 2016, 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 #ifdef CONFIG_PROC_FS
44 /**
45  * Show OSP active status
46  *
47  * \param[in] m         seq_file handle
48  * \param[in] data      unused for single entry
49  * \retval              0 on success
50  * \retval              negative number on error
51  */
52 static int osp_active_seq_show(struct seq_file *m, void *data)
53 {
54         struct obd_device       *dev = m->private;
55
56         LPROCFS_CLIMP_CHECK(dev);
57         seq_printf(m, "%d\n", !dev->u.cli.cl_import->imp_deactive);
58         LPROCFS_CLIMP_EXIT(dev);
59         return 0;
60 }
61
62 /**
63  * Activate/Deactivate OSP
64  *
65  * \param[in] file      proc file
66  * \param[in] buffer    string, which is "1" or "0" to activate/deactivate OSP
67  * \param[in] count     \a buffer length
68  * \param[in] off       unused for single entry
69  * \retval              \a count on success
70  * \retval              negative number on error
71  */
72 static ssize_t
73 osp_active_seq_write(struct file *file, const char __user *buffer,
74                         size_t count, loff_t *off)
75 {
76         struct seq_file *m = file->private_data;
77         struct obd_device *dev = m->private;
78         int rc;
79         __s64 val;
80
81         rc = lprocfs_str_to_s64(buffer, count, &val);
82         if (rc)
83                 return rc;
84         if (val < 0 || val > 1)
85                 return -ERANGE;
86
87         LPROCFS_CLIMP_CHECK(dev);
88         /* opposite senses */
89         if (dev->u.cli.cl_import->imp_deactive == val)
90                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
91         else
92                 CDEBUG(D_CONFIG, "activate %lld: ignoring repeat request\n",
93                        val);
94
95         LPROCFS_CLIMP_EXIT(dev);
96         return count;
97 }
98 LPROC_SEQ_FOPS(osp_active);
99
100 /**
101  * Show number of RPCs in flight
102  *
103  * \param[in] m         seq_file handle
104  * \param[in] data      unused for single entry
105  * \retval              0 on success
106  * \retval              negative number on error
107  */
108 static int osp_syn_in_flight_seq_show(struct seq_file *m, void *data)
109 {
110         struct obd_device       *dev = m->private;
111         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
112
113         if (osp == NULL)
114                 return -EINVAL;
115
116         seq_printf(m, "%u\n", atomic_read(&osp->opd_syn_rpc_in_flight));
117         return 0;
118 }
119 LPROC_SEQ_FOPS_RO(osp_syn_in_flight);
120
121 /**
122  * Show number of RPCs in processing (including uncommitted by OST)
123  *
124  * \param[in] m         seq_file handle
125  * \param[in] data      unused for single entry
126  * \retval              0 on success
127  * \retval              negative number on error
128  */
129 static int osp_syn_in_prog_seq_show(struct seq_file *m, void *data)
130 {
131         struct obd_device       *dev = m->private;
132         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
133
134         if (osp == NULL)
135                 return -EINVAL;
136
137         seq_printf(m, "%u\n", atomic_read(&osp->opd_syn_rpc_in_progress));
138         return 0;
139 }
140 LPROC_SEQ_FOPS_RO(osp_syn_in_prog);
141
142 /**
143  * Show number of changes to sync
144  *
145  * \param[in] m         seq_file handle
146  * \param[in] data      unused for single entry
147  * \retval              0 on success
148  * \retval              negative number on error
149  */
150 static int osp_syn_changes_seq_show(struct seq_file *m, void *data)
151 {
152         struct obd_device       *dev = m->private;
153         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
154
155         if (osp == NULL)
156                 return -EINVAL;
157
158         seq_printf(m, "%u\n", atomic_read(&osp->opd_syn_changes));
159         return 0;
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 osp_syn_changes_seq_write(struct file *file,
173                                          const char __user *buffer,
174                                          size_t count, loff_t *off)
175 {
176         struct seq_file         *m      = file->private_data;
177         struct obd_device       *dev    = m->private;
178         struct osp_device       *osp    = lu2osp_dev(dev->obd_lu_dev);
179         struct lu_env            env;
180         int                      rc;
181
182         rc = lu_env_init(&env, LCT_LOCAL);
183         if (rc != 0)
184                 return rc;
185
186         rc = dt_sync(&env, &osp->opd_dt_dev);
187         lu_env_fini(&env);
188
189         return rc == 0 ? count : rc;
190 }
191 LPROC_SEQ_FOPS(osp_syn_changes);
192
193 /**
194  * Show maximum number of RPCs in flight allowed
195  *
196  * \param[in] m         seq_file handle
197  * \param[in] data      unused for single entry
198  * \retval              0 on success
199  * \retval              negative number on error
200  */
201 static int osp_max_rpcs_in_flight_seq_show(struct seq_file *m, void *data)
202 {
203         struct obd_device       *dev = m->private;
204         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
205
206         if (osp == NULL)
207                 return -EINVAL;
208
209         seq_printf(m, "%u\n", osp->opd_syn_max_rpc_in_flight);
210         return 0;
211 }
212
213 /**
214  * Change maximum number of RPCs in flight allowed
215  *
216  * \param[in] file      proc file
217  * \param[in] buffer    string which represents maximum number
218  * \param[in] count     \a buffer length
219  * \param[in] off       unused for single entry
220  * \retval              \a count on success
221  * \retval              negative number on error
222  */
223 static ssize_t
224 osp_max_rpcs_in_flight_seq_write(struct file *file, const char __user *buffer,
225                                 size_t count, loff_t *off)
226 {
227         struct seq_file *m = file->private_data;
228         struct obd_device *dev = m->private;
229         struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
230         int rc;
231         __s64 val;
232
233         if (osp == NULL)
234                 return -EINVAL;
235
236         rc = lprocfs_str_to_s64(buffer, count, &val);
237         if (rc)
238                 return rc;
239
240         if (val < 1 || val > INT_MAX)
241                 return -ERANGE;
242
243         osp->opd_syn_max_rpc_in_flight = val;
244         return count;
245 }
246 LPROC_SEQ_FOPS(osp_max_rpcs_in_flight);
247
248 /**
249  * Show maximum number of RPCs in processing allowed
250  *
251  * \param[in] m         seq_file handle
252  * \param[in] data      unused
253  * \retval              0 on success
254  * \retval              negative number on error
255  */
256 static int osp_max_rpcs_in_prog_seq_show(struct seq_file *m, void *data)
257 {
258         struct obd_device       *dev = m->private;
259         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
260
261         if (osp == NULL)
262                 return -EINVAL;
263
264         seq_printf(m, "%u\n", osp->opd_syn_max_rpc_in_progress);
265         return 0;
266 }
267
268 /**
269  * Change maximum number of RPCs in processing allowed
270  *
271  * \param[in] file      proc file
272  * \param[in] buffer    string which represents maximum number
273  * \param[in] count     \a buffer length
274  * \param[in] off       unused for single entry
275  * \retval              \a count on success
276  * \retval              negative number on error
277  */
278 static ssize_t
279 osp_max_rpcs_in_prog_seq_write(struct file *file, const char __user *buffer,
280                                 size_t count, loff_t *off)
281 {
282         struct seq_file *m = file->private_data;
283         struct obd_device *dev = m->private;
284         struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
285         int rc;
286         __s64 val;
287
288         if (osp == NULL)
289                 return -EINVAL;
290
291         rc = lprocfs_str_to_s64(buffer, count, &val);
292         if (rc)
293                 return rc;
294
295         if (val < 1 || val > INT_MAX)
296                 return -ERANGE;
297
298         osp->opd_syn_max_rpc_in_progress = val;
299
300         return count;
301 }
302 LPROC_SEQ_FOPS(osp_max_rpcs_in_prog);
303
304 /**
305  * Show number of objects to precreate next time
306  *
307  * \param[in] m         seq_file handle
308  * \param[in] data      unused for single entry
309  * \retval              0 on success
310  * \retval              negative number on error
311  */
312 static int osp_create_count_seq_show(struct seq_file *m, void *data)
313 {
314         struct obd_device *obd = m->private;
315         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
316
317         if (osp == NULL || osp->opd_pre == NULL)
318                 return 0;
319
320         seq_printf(m, "%d\n", osp->opd_pre_create_count);
321         return 0;
322 }
323
324 /**
325  * Change number of objects to precreate next time
326  *
327  * \param[in] file      proc file
328  * \param[in] buffer    string which represents number of objects to precreate
329  * \param[in] count     \a buffer length
330  * \param[in] off       unused for single entry
331  * \retval              \a count on success
332  * \retval              negative number on error
333  */
334 static ssize_t
335 osp_create_count_seq_write(struct file *file, const char __user *buffer,
336                                 size_t count, loff_t *off)
337 {
338         struct seq_file *m = file->private_data;
339         struct obd_device *obd = m->private;
340         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
341         int rc, i;
342         __s64 val;
343
344         if (osp == NULL || osp->opd_pre == NULL)
345                 return 0;
346
347         rc = lprocfs_str_to_s64(buffer, count, &val);
348         if (rc)
349                 return rc;
350
351         /* The MDT ALWAYS needs to limit the precreate count to
352          * OST_MAX_PRECREATE, and the constant cannot be changed
353          * because it is a value shared between the OSP and OST
354          * that is the maximum possible number of objects that will
355          * ever be handled by MDT->OST recovery processing.
356          *
357          * If the OST ever gets a request to delete more orphans,
358          * this implies that something has gone badly on the MDT
359          * and the OST will refuse to delete so much data from the
360          * filesystem as a safety measure. */
361         if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
362                 return -ERANGE;
363         if (val > osp->opd_pre_max_create_count)
364                 return -ERANGE;
365
366         for (i = 1; (i << 1) <= val; i <<= 1)
367                 ;
368         osp->opd_pre_create_count = i;
369
370         return count;
371 }
372 LPROC_SEQ_FOPS(osp_create_count);
373
374 /**
375  * Show maximum number of objects to precreate
376  *
377  * \param[in] m         seq_file handle
378  * \param[in] data      unused for single entry
379  * \retval              0 on success
380  * \retval              negative number on error
381  */
382 static int osp_max_create_count_seq_show(struct seq_file *m, void *data)
383 {
384         struct obd_device *obd = m->private;
385         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
386
387         if (osp == NULL || osp->opd_pre == NULL)
388                 return 0;
389
390         seq_printf(m, "%d\n", osp->opd_pre_max_create_count);
391         return 0;
392 }
393
394 /**
395  * Change maximum number of objects to precreate
396  *
397  * \param[in] file      proc file
398  * \param[in] buffer    string which represents maximum number
399  * \param[in] count     \a buffer length
400  * \param[in] off       unused for single entry
401  * \retval              \a count on success
402  * \retval              negative number on error
403  */
404 static ssize_t
405 osp_max_create_count_seq_write(struct file *file, const char __user *buffer,
406                                 size_t count, loff_t *off)
407 {
408         struct seq_file *m = file->private_data;
409         struct obd_device *obd = m->private;
410         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
411         int rc;
412         __s64 val;
413
414         if (osp == NULL || osp->opd_pre == NULL)
415                 return 0;
416
417         rc = lprocfs_str_to_s64(buffer, count, &val);
418         if (rc)
419                 return rc;
420
421         if (val < 0 || val > INT_MAX)
422                 return -ERANGE;
423         if (val > OST_MAX_PRECREATE)
424                 return -ERANGE;
425
426         if (osp->opd_pre_create_count > val)
427                 osp->opd_pre_create_count = val;
428
429         osp->opd_pre_max_create_count = val;
430
431         return count;
432 }
433 LPROC_SEQ_FOPS(osp_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 int osp_prealloc_next_id_seq_show(struct seq_file *m, void *data)
444 {
445         struct obd_device *obd = m->private;
446         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
447
448         if (osp == NULL || osp->opd_pre == NULL)
449                 return 0;
450
451         seq_printf(m, "%u\n", fid_oid(&osp->opd_pre_used_fid) + 1);
452         return 0;
453 }
454 LPROC_SEQ_FOPS_RO(osp_prealloc_next_id);
455
456 /**
457  * Show last created id OST reported
458  *
459  * \param[in] m         seq_file handle
460  * \param[in] data      unused for single entry
461  * \retval              0 on success
462  * \retval              negative number on error
463  */
464 static int osp_prealloc_last_id_seq_show(struct seq_file *m, void *data)
465 {
466         struct obd_device *obd = m->private;
467         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
468
469         if (osp == NULL || osp->opd_pre == NULL)
470                 return 0;
471
472         seq_printf(m, "%u\n", fid_oid(&osp->opd_pre_last_created_fid));
473         return 0;
474 }
475 LPROC_SEQ_FOPS_RO(osp_prealloc_last_id);
476
477 /**
478  * Show next FID sequence to precreate
479  *
480  * \param[in] m         seq_file handle
481  * \param[in] data      unused for single entry
482  * \retval              0 on success
483  * \retval              negative number on error
484  */
485 static int osp_prealloc_next_seq_seq_show(struct seq_file *m, void *data)
486 {
487         struct obd_device *obd = m->private;
488         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
489
490         if (osp == NULL || osp->opd_pre == NULL)
491                 return 0;
492
493         seq_printf(m, "%#llx\n", fid_seq(&osp->opd_pre_used_fid));
494         return 0;
495 }
496 LPROC_SEQ_FOPS_RO(osp_prealloc_next_seq);
497
498 /**
499  * Show last created FID sequence OST reported
500  *
501  * \param[in] m         seq_file handle
502  * \param[in] data      unused for single entry
503  * \retval              0 on success
504  * \retval              negative number on error
505  */
506 static int osp_prealloc_last_seq_seq_show(struct seq_file *m, void *data)
507 {
508         struct obd_device *obd = m->private;
509         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
510
511         if (osp == NULL || osp->opd_pre == NULL)
512                 return 0;
513
514         seq_printf(m, "%#llx\n",
515                    fid_seq(&osp->opd_pre_last_created_fid));
516         return 0;
517 }
518 LPROC_SEQ_FOPS_RO(osp_prealloc_last_seq);
519
520 /**
521  * Show the number of ids reserved by declare
522  *
523  * \param[in] m         seq_file handle
524  * \param[in] data      unused for single entry
525  * \retval              0 on success
526  * \retval              negative number on error
527  */
528 static int osp_prealloc_reserved_seq_show(struct seq_file *m, void *data)
529 {
530         struct obd_device *obd = m->private;
531         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
532
533         if (osp == NULL || osp->opd_pre == NULL)
534                 return 0;
535
536         seq_printf(m, "%llu\n", osp->opd_pre_reserved);
537         return 0;
538 }
539 LPROC_SEQ_FOPS_RO(osp_prealloc_reserved);
540
541 /**
542  * Show interval (in seconds) to update statfs data
543  *
544  * \param[in] m         seq_file handle
545  * \param[in] data      unused for single entry
546  * \retval              0 on success
547  * \retval              negative number on error
548  */
549 static int osp_maxage_seq_show(struct seq_file *m, void *data)
550 {
551         struct obd_device       *dev = m->private;
552         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
553
554         if (osp == NULL)
555                 return -EINVAL;
556
557         seq_printf(m, "%u\n", osp->opd_statfs_maxage);
558         return 0;
559 }
560
561 /**
562  * Change interval to update statfs data
563  *
564  * \param[in] file      proc file
565  * \param[in] buffer    string which represents statfs interval (in seconds)
566  * \param[in] count     \a buffer length
567  * \param[in] off       unused for single entry
568  * \retval              \a count on success
569  * \retval              negative number on error
570  */
571 static ssize_t
572 osp_maxage_seq_write(struct file *file, const char __user *buffer,
573                         size_t count, loff_t *off)
574 {
575         struct seq_file *m = file->private_data;
576         struct obd_device *dev = m->private;
577         struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
578         int rc;
579         __s64 val;
580
581         if (osp == NULL)
582                 return -EINVAL;
583
584         rc = lprocfs_str_to_s64(buffer, count, &val);
585         if (rc)
586                 return rc;
587
588         if (val < 1 || val > INT_MAX)
589                 return -ERANGE;
590
591         osp->opd_statfs_maxage = val;
592
593         return count;
594 }
595 LPROC_SEQ_FOPS(osp_maxage);
596
597 /**
598  * Show current precreation status: output 0 means success, otherwise negative
599  * number is printed
600  *
601  * \param[in] m         seq_file handle
602  * \param[in] data      unused for single entry
603  * \retval              0 on success
604  * \retval              negative number on error
605  */
606 static int osp_pre_status_seq_show(struct seq_file *m, void *data)
607 {
608         struct obd_device       *dev = m->private;
609         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
610
611         if (osp == NULL || osp->opd_pre == NULL)
612                 return -EINVAL;
613
614         seq_printf(m, "%d\n", osp->opd_pre_status);
615         return 0;
616 }
617 LPROC_SEQ_FOPS_RO(osp_pre_status);
618
619 /**
620  * Show the number of RPCs in processing (including uncommitted by OST) plus
621  * changes to sync, i.e. this is the total number of changes OST needs to apply
622  * and commit.
623  *
624  * This counter is used to determine if OST has space returned. A zero value
625  * indicates that OST storage space consumed by destroyed objects has been freed
626  * on disk, the associated llog records have been cleared, and no synchronous
627  * RPC are being processed.
628  *
629  * \param[in] m         seq_file handle
630  * \param[in] data      unused for single entry
631  * \retval              0 on success
632  * \retval              negative number on error
633  */
634 static int osp_destroys_in_flight_seq_show(struct seq_file *m, void *data)
635 {
636         struct obd_device *dev = m->private;
637         struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
638
639         if (osp == NULL)
640                 return -EINVAL;
641
642         seq_printf(m, "%u\n",
643                    atomic_read(&osp->opd_syn_rpc_in_progress) +
644                    atomic_read(&osp->opd_syn_changes));
645         return 0;
646 }
647 LPROC_SEQ_FOPS_RO(osp_destroys_in_flight);
648
649 /**
650  * Show changes synced from previous mount
651  *
652  * \param[in] m         seq_file handle
653  * \param[in] data      unused for single entry
654  * \retval              0 on success
655  * \retval              negative number on error
656  */
657 static int osp_old_sync_processed_seq_show(struct seq_file *m, void *data)
658 {
659         struct obd_device       *dev = m->private;
660         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
661
662         if (osp == NULL)
663                 return -EINVAL;
664
665         seq_printf(m, "%d\n", osp->opd_syn_prev_done);
666         return 0;
667 }
668 LPROC_SEQ_FOPS_RO(osp_old_sync_processed);
669
670 /**
671  * Show maximum number of RPCs in flight
672  *
673  * \param[in] m         seq_file handle
674  * \param[in] data      unused for single entry
675  * \retval              0 on success
676  * \retval              negative number on error
677  */
678 static int
679 osp_lfsck_max_rpcs_in_flight_seq_show(struct seq_file *m, void *data)
680 {
681         struct obd_device *dev = m->private;
682         __u32 max;
683
684         max = obd_get_max_rpcs_in_flight(&dev->u.cli);
685         seq_printf(m, "%u\n", max);
686         return 0;
687 }
688
689 /**
690  * Change maximum number of RPCs in flight
691  *
692  * \param[in] file      proc file
693  * \param[in] buffer    string which represents maximum number of RPCs in flight
694  * \param[in] count     \a buffer length
695  * \param[in] off       unused for single entry
696  * \retval              \a count on success
697  * \retval              negative number on error
698  */
699 static ssize_t
700 osp_lfsck_max_rpcs_in_flight_seq_write(struct file *file,
701                                        const char __user *buffer,
702                                        size_t count, loff_t *off)
703 {
704         struct seq_file   *m = file->private_data;
705         struct obd_device *dev = m->private;
706         __s64 val;
707         int rc;
708
709         rc = lprocfs_str_to_s64(buffer, count, &val);
710         if (rc == 0) {
711                 if (val < 0)
712                         return -ERANGE;
713
714                 rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
715         } else {
716                 count = rc;
717         }
718
719         return count;
720 }
721 LPROC_SEQ_FOPS(osp_lfsck_max_rpcs_in_flight);
722
723 LPROC_SEQ_FOPS_WO_TYPE(osp, ping);
724 LPROC_SEQ_FOPS_RO_TYPE(osp, uuid);
725 LPROC_SEQ_FOPS_RO_TYPE(osp, connect_flags);
726 LPROC_SEQ_FOPS_RO_TYPE(osp, server_uuid);
727 LPROC_SEQ_FOPS_RO_TYPE(osp, conn_uuid);
728
729 /**
730  * Show maximum pages per bulk RPC
731  *
732  * \param[in] m         seq_file handle
733  * \param[in] data      unused for single entry
734  * \retval              0 on success
735  * \retval              negative number on error
736  */
737 static int osp_max_pages_per_rpc_seq_show(struct seq_file *m, void *v)
738 {
739         return lprocfs_obd_max_pages_per_rpc_seq_show(m, m->private);
740 }
741 LPROC_SEQ_FOPS_RO(osp_max_pages_per_rpc);
742 LPROC_SEQ_FOPS_RO_TYPE(osp, timeouts);
743
744 LPROC_SEQ_FOPS_RW_TYPE(osp, import);
745 LPROC_SEQ_FOPS_RO_TYPE(osp, state);
746
747 /**
748  * Show high watermark (in megabytes). If available free space at OST is grater
749  * than high watermark and object allocation for OST is disabled, enable it.
750  *
751  * \param[in] m         seq_file handle
752  * \param[in] data      unused for single entry
753  * \retval              0 on success
754  * \retval              negative number on error
755  */
756 static int osp_reserved_mb_high_seq_show(struct seq_file *m, void *data)
757 {
758         struct obd_device       *dev = m->private;
759         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
760
761         if (osp == NULL)
762                 return -EINVAL;
763
764         seq_printf(m, "%u\n", osp->opd_reserved_mb_high);
765         return 0;
766 }
767
768 /**
769  * Change high watermark
770  *
771  * \param[in] file      proc file
772  * \param[in] buffer    string which represents new value (in megabytes)
773  * \param[in] count     \a buffer length
774  * \param[in] off       unused for single entry
775  * \retval              \a count on success
776  * \retval              negative number on error
777  */
778 static ssize_t
779 osp_reserved_mb_high_seq_write(struct file *file, const char __user *buffer,
780                         size_t count, loff_t *off)
781 {
782         struct seq_file         *m = file->private_data;
783         struct obd_device       *dev = m->private;
784         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
785         __s64                   val;
786         int                     rc;
787
788         if (osp == NULL)
789                 return -EINVAL;
790
791         rc = lprocfs_str_with_units_to_s64(buffer, count, &val, 'M');
792         if (rc)
793                 return rc;
794         val >>= 20;
795         if (val < 1)
796                 return -ERANGE;
797
798         spin_lock(&osp->opd_pre_lock);
799         osp->opd_reserved_mb_high = val;
800         if (val <= osp->opd_reserved_mb_low)
801                 osp->opd_reserved_mb_low = val - 1;
802         spin_unlock(&osp->opd_pre_lock);
803
804         return count;
805 }
806 LPROC_SEQ_FOPS(osp_reserved_mb_high);
807
808 /**
809  * Show low watermark (in megabytes). If available free space at OST is less
810  * than low watermark, object allocation for OST is disabled.
811  *
812  * \param[in] m         seq_file handle
813  * \param[in] data      unused for single entry
814  * \retval              0 on success
815  * \retval              negative number on error
816  */
817 static int osp_reserved_mb_low_seq_show(struct seq_file *m, void *data)
818 {
819         struct obd_device       *dev = m->private;
820         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
821
822         if (osp == NULL)
823                 return -EINVAL;
824
825         seq_printf(m, "%u\n", osp->opd_reserved_mb_low);
826         return 0;
827 }
828
829 /**
830  * Change low watermark
831  *
832  * \param[in] file      proc file
833  * \param[in] buffer    string which represents new value (in megabytes)
834  * \param[in] count     \a buffer length
835  * \param[in] off       unused for single entry
836  * \retval              \a count on success
837  * \retval              negative number on error
838  */
839 static ssize_t
840 osp_reserved_mb_low_seq_write(struct file *file, const char __user *buffer,
841                         size_t count, loff_t *off)
842 {
843         struct seq_file         *m = file->private_data;
844         struct obd_device       *dev = m->private;
845         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
846         __s64                   val;
847         int                     rc;
848
849         if (osp == NULL)
850                 return -EINVAL;
851
852         rc = lprocfs_str_with_units_to_s64(buffer, count, &val, 'M');
853         if (rc)
854                 return rc;
855         val >>= 20;
856
857         spin_lock(&osp->opd_pre_lock);
858         osp->opd_reserved_mb_low = val;
859         if (val >= osp->opd_reserved_mb_high)
860                 osp->opd_reserved_mb_high = val + 1;
861         spin_unlock(&osp->opd_pre_lock);
862
863         return count;
864 }
865 LPROC_SEQ_FOPS(osp_reserved_mb_low);
866
867 static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
868         { .name =       "uuid",
869           .fops =       &osp_uuid_fops                  },
870         { .name =       "ping",
871           .fops =       &osp_ping_fops,
872           .proc_mode =  0222                            },
873         { .name =       "connect_flags",
874           .fops =       &osp_connect_flags_fops         },
875         { .name =       "ost_server_uuid",
876           .fops =       &osp_server_uuid_fops           },
877         { .name =       "ost_conn_uuid",
878           .fops =       &osp_conn_uuid_fops             },
879         { .name =       "active",
880           .fops =       &osp_active_fops                },
881         { .name =       "max_rpcs_in_flight",
882           .fops =       &osp_max_rpcs_in_flight_fops    },
883         { .name =       "max_rpcs_in_progress",
884           .fops =       &osp_max_rpcs_in_prog_fops      },
885         { .name =       "create_count",
886           .fops =       &osp_create_count_fops          },
887         { .name =       "max_create_count",
888           .fops =       &osp_max_create_count_fops      },
889         { .name =       "prealloc_next_id",
890           .fops =       &osp_prealloc_next_id_fops      },
891         { .name =       "prealloc_next_seq",
892           .fops =       &osp_prealloc_next_seq_fops     },
893         { .name =       "prealloc_last_id",
894           .fops =       &osp_prealloc_last_id_fops      },
895         { .name =       "prealloc_last_seq",
896           .fops =       &osp_prealloc_last_seq_fops     },
897         { .name =       "prealloc_reserved",
898           .fops =       &osp_prealloc_reserved_fops     },
899         { .name =       "timeouts",
900           .fops =       &osp_timeouts_fops              },
901         { .name =       "import",
902           .fops =       &osp_import_fops                },
903         { .name =       "state",
904           .fops =       &osp_state_fops                 },
905         { .name =       "maxage",
906           .fops =       &osp_maxage_fops                },
907         { .name =       "prealloc_status",
908           .fops =       &osp_pre_status_fops            },
909         { .name =       "sync_changes",
910           .fops =       &osp_syn_changes_fops           },
911         { .name =       "sync_in_flight",
912           .fops =       &osp_syn_in_flight_fops         },
913         { .name =       "sync_in_progress",
914           .fops =       &osp_syn_in_prog_fops           },
915         { .name =       "old_sync_processed",
916           .fops =       &osp_old_sync_processed_fops    },
917         { .name =       "reserved_mb_high",
918           .fops =       &osp_reserved_mb_high_fops      },
919         { .name =       "reserved_mb_low",
920           .fops =       &osp_reserved_mb_low_fops       },
921
922         /* for compatibility reasons */
923         { .name =       "destroys_in_flight",
924           .fops =       &osp_destroys_in_flight_fops            },
925         { .name =       "lfsck_max_rpcs_in_flight",
926           .fops =       &osp_lfsck_max_rpcs_in_flight_fops      },
927         { NULL }
928 };
929
930 static struct lprocfs_vars lprocfs_osp_md_vars[] = {
931         { .name =       "uuid",
932           .fops =       &osp_uuid_fops                  },
933         { .name =       "ping",
934           .fops =       &osp_ping_fops,
935           .proc_mode =  0222                            },
936         { .name =       "connect_flags",
937           .fops =       &osp_connect_flags_fops         },
938         { .name =       "mdt_server_uuid",
939           .fops =       &osp_server_uuid_fops           },
940         { .name =       "mdt_conn_uuid",
941           .fops =       &osp_conn_uuid_fops             },
942         { .name =       "active",
943           .fops =       &osp_active_fops                },
944         { .name =       "max_rpcs_in_flight",
945           .fops =       &osp_max_rpcs_in_flight_fops    },
946         { .name =       "max_rpcs_in_progress",
947           .fops =       &osp_max_rpcs_in_prog_fops      },
948         { .name =       "timeouts",
949           .fops =       &osp_timeouts_fops              },
950         { .name =       "import",
951           .fops =       &osp_import_fops                },
952         { .name =       "state",
953           .fops =       &osp_state_fops                 },
954         { .name =       "maxage",
955           .fops =       &osp_maxage_fops                },
956         { .name =       "prealloc_status",
957           .fops =       &osp_pre_status_fops            },
958
959         /* for compatibility reasons */
960         { .name =       "destroys_in_flight",
961           .fops =       &osp_destroys_in_flight_fops            },
962         { .name =       "lfsck_max_rpcs_in_flight",
963           .fops =       &osp_lfsck_max_rpcs_in_flight_fops      },
964         { NULL }
965 };
966
967 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_blksize);
968 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_kbytestotal);
969 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_kbytesfree);
970 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_kbytesavail);
971 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_filestotal);
972 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_filesfree);
973
974 static struct lprocfs_vars lprocfs_osp_osd_vars[] = {
975         { .name =       "blocksize",
976           .fops =       &osp_dt_blksize_fops            },
977         { .name =       "kbytestotal",
978           .fops =       &osp_dt_kbytestotal_fops        },
979         { .name =       "kbytesfree",
980           .fops =       &osp_dt_kbytesfree_fops         },
981         { .name =       "kbytesavail",
982           .fops =       &osp_dt_kbytesavail_fops        },
983         { .name =       "filestotal",
984           .fops =       &osp_dt_filestotal_fops         },
985         { .name =       "filesfree",
986           .fops =       &osp_dt_filesfree_fops          },
987         { NULL }
988 };
989
990 /**
991  * Initialize OSP lprocfs
992  *
993  * param[in] osp        OSP device
994  */
995 void osp_lprocfs_init(struct osp_device *osp)
996 {
997         struct obd_device       *obd = osp->opd_obd;
998         struct proc_dir_entry   *osc_proc_dir = NULL;
999         struct obd_type         *type;
1000         int                      rc;
1001
1002         if (osp->opd_connect_mdt)
1003                 obd->obd_vars = lprocfs_osp_md_vars;
1004         else
1005                 obd->obd_vars = lprocfs_osp_obd_vars;
1006         if (lprocfs_obd_setup(obd) != 0)
1007                 return;
1008
1009         rc = lprocfs_add_vars(obd->obd_proc_entry, lprocfs_osp_osd_vars,
1010                               &osp->opd_dt_dev);
1011         if (rc) {
1012                 CERROR("%s: can't register in lprocfs, rc %d\n",
1013                        obd->obd_name, rc);
1014                 return;
1015         }
1016
1017         sptlrpc_lprocfs_cliobd_attach(obd);
1018         ptlrpc_lprocfs_register_obd(obd);
1019
1020         if (osp->opd_connect_mdt || !strstr(obd->obd_name, "osc"))
1021                 return;
1022
1023         /* If the real OSC is present which is the case for setups
1024          * with both server and clients on the same node then use
1025          * the OSC's proc root */
1026         type = class_search_type(LUSTRE_OSC_NAME);
1027         if (type != NULL && type->typ_procroot != NULL)
1028                 osc_proc_dir = type->typ_procroot;
1029         else
1030                 osc_proc_dir = obd->obd_type->typ_procsym;
1031
1032         if (osc_proc_dir == NULL)
1033                 return;
1034
1035         /* for compatibility we link old procfs's OSC entries to osp ones */
1036         osp->opd_symlink = lprocfs_add_symlink(obd->obd_name, osc_proc_dir,
1037                                                "../osp/%s", obd->obd_name);
1038         if (osp->opd_symlink == NULL)
1039                 CERROR("cannot create OSC symlink for /proc/fs/lustre/osp/%s\n",
1040                        obd->obd_name);
1041 }
1042
1043 #endif /* CONFIG_PROC_FS */
1044