Whamcloud - gitweb
LU-5223 lmv: build master LMV EA dynamically build via readdir
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/osp/lproc_osp.c
37  *
38  * Lustre OST Proxy Device, procfs functions
39  *
40  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
41  */
42
43 #define DEBUG_SUBSYSTEM S_CLASS
44
45 #include "osp_internal.h"
46
47 #ifdef LPROCFS
48 static int osp_active_seq_show(struct seq_file *m, void *data)
49 {
50         struct obd_device       *dev = m->private;
51         int                      rc;
52
53         LPROCFS_CLIMP_CHECK(dev);
54         rc = seq_printf(m, "%d\n", !dev->u.cli.cl_import->imp_deactive);
55         LPROCFS_CLIMP_EXIT(dev);
56         return rc;
57 }
58
59 static ssize_t
60 osp_active_seq_write(struct file *file, const char *buffer,
61                         size_t count, loff_t *off)
62 {
63         struct seq_file   *m = file->private_data;
64         struct obd_device *dev = m->private;
65         int                val, rc;
66
67         rc = lprocfs_write_helper(buffer, count, &val);
68         if (rc)
69                 return rc;
70         if (val < 0 || val > 1)
71                 return -ERANGE;
72
73         LPROCFS_CLIMP_CHECK(dev);
74         /* opposite senses */
75         if (dev->u.cli.cl_import->imp_deactive == val)
76                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
77         else
78                 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n",
79                        val);
80
81         LPROCFS_CLIMP_EXIT(dev);
82         return count;
83 }
84 LPROC_SEQ_FOPS(osp_active);
85
86 static int osp_syn_in_flight_seq_show(struct seq_file *m, void *data)
87 {
88         struct obd_device       *dev = m->private;
89         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
90
91         if (osp == NULL)
92                 return -EINVAL;
93
94         return seq_printf(m, "%u\n", osp->opd_syn_rpc_in_flight);
95 }
96 LPROC_SEQ_FOPS_RO(osp_syn_in_flight);
97
98 static int osp_syn_in_prog_seq_show(struct seq_file *m, void *data)
99 {
100         struct obd_device       *dev = m->private;
101         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
102
103         if (osp == NULL)
104                 return -EINVAL;
105
106         return seq_printf(m, "%u\n", osp->opd_syn_rpc_in_progress);
107 }
108 LPROC_SEQ_FOPS_RO(osp_syn_in_prog);
109
110 static int osp_syn_changes_seq_show(struct seq_file *m, void *data)
111 {
112         struct obd_device       *dev = m->private;
113         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
114
115         if (osp == NULL)
116                 return -EINVAL;
117
118         return seq_printf(m, "%lu\n", osp->opd_syn_changes);
119 }
120
121 static ssize_t osp_syn_changes_seq_write(struct file *file, const char *buffer,
122                                          size_t count, loff_t *off)
123 {
124         struct seq_file         *m      = file->private_data;
125         struct obd_device       *dev    = m->private;
126         struct osp_device       *osp    = lu2osp_dev(dev->obd_lu_dev);
127         struct lu_env            env;
128         int                      rc;
129
130         rc = lu_env_init(&env, LCT_LOCAL);
131         if (rc != 0)
132                 return rc;
133
134         rc = dt_sync(&env, &osp->opd_dt_dev);
135         lu_env_fini(&env);
136
137         return rc == 0 ? count : rc;
138 }
139 LPROC_SEQ_FOPS(osp_syn_changes);
140
141 static int osp_max_rpcs_in_flight_seq_show(struct seq_file *m, void *data)
142 {
143         struct obd_device       *dev = m->private;
144         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
145
146         if (osp == NULL)
147                 return -EINVAL;
148
149         return seq_printf(m, "%u\n", osp->opd_syn_max_rpc_in_flight);
150 }
151
152 static ssize_t
153 osp_max_rpcs_in_flight_seq_write(struct file *file, const char *buffer,
154                                 size_t count, loff_t *off)
155 {
156         struct seq_file         *m = file->private_data;
157         struct obd_device       *dev = m->private;
158         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
159         int                      val, rc;
160
161         if (osp == NULL)
162                 return -EINVAL;
163
164         rc = lprocfs_write_helper(buffer, count, &val);
165         if (rc)
166                 return rc;
167
168         if (val < 1)
169                 return -ERANGE;
170
171         osp->opd_syn_max_rpc_in_flight = val;
172         return count;
173 }
174 LPROC_SEQ_FOPS(osp_max_rpcs_in_flight);
175
176 static int osp_max_rpcs_in_prog_seq_show(struct seq_file *m, void *data)
177 {
178         struct obd_device       *dev = m->private;
179         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
180
181         if (osp == NULL)
182                 return -EINVAL;
183
184         return seq_printf(m, "%u\n", osp->opd_syn_max_rpc_in_progress);
185 }
186
187 static ssize_t
188 osp_max_rpcs_in_prog_seq_write(struct file *file, const char *buffer,
189                                 size_t count, loff_t *off)
190 {
191         struct seq_file         *m = file->private_data;
192         struct obd_device       *dev = m->private;
193         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
194         int                      val, rc;
195
196         if (osp == NULL)
197                 return -EINVAL;
198
199         rc = lprocfs_write_helper(buffer, count, &val);
200         if (rc)
201                 return rc;
202
203         if (val < 1)
204                 return -ERANGE;
205
206         osp->opd_syn_max_rpc_in_progress = val;
207
208         return count;
209 }
210 LPROC_SEQ_FOPS(osp_max_rpcs_in_prog);
211
212 static int osp_create_count_seq_show(struct seq_file *m, void *data)
213 {
214         struct obd_device *obd = m->private;
215         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
216
217         if (osp == NULL || osp->opd_pre == NULL)
218                 return 0;
219
220         return seq_printf(m, "%d\n", osp->opd_pre_grow_count);
221 }
222
223 static ssize_t
224 osp_create_count_seq_write(struct file *file, const char *buffer,
225                                 size_t count, loff_t *off)
226 {
227         struct seq_file         *m = file->private_data;
228         struct obd_device       *obd = m->private;
229         struct osp_device       *osp = lu2osp_dev(obd->obd_lu_dev);
230         int                      val, rc, i;
231
232         if (osp == NULL || osp->opd_pre == NULL)
233                 return 0;
234
235         rc = lprocfs_write_helper(buffer, count, &val);
236         if (rc)
237                 return rc;
238
239         /* The MDT ALWAYS needs to limit the precreate count to
240          * OST_MAX_PRECREATE, and the constant cannot be changed
241          * because it is a value shared between the OSP and OST
242          * that is the maximum possible number of objects that will
243          * ever be handled by MDT->OST recovery processing.
244          *
245          * If the OST ever gets a request to delete more orphans,
246          * this implies that something has gone badly on the MDT
247          * and the OST will refuse to delete so much data from the
248          * filesystem as a safety measure. */
249         if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
250                 return -ERANGE;
251         if (val > osp->opd_pre_max_grow_count)
252                 return -ERANGE;
253
254         for (i = 1; (i << 1) <= val; i <<= 1)
255                 ;
256         osp->opd_pre_grow_count = i;
257
258         return count;
259 }
260 LPROC_SEQ_FOPS(osp_create_count);
261
262 static int osp_max_create_count_seq_show(struct seq_file *m, void *data)
263 {
264         struct obd_device *obd = m->private;
265         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
266
267         if (osp == NULL || osp->opd_pre == NULL)
268                 return 0;
269
270         return seq_printf(m, "%d\n", osp->opd_pre_max_grow_count);
271 }
272
273 static ssize_t
274 osp_max_create_count_seq_write(struct file *file, const char *buffer,
275                                 size_t count, loff_t *off)
276 {
277         struct seq_file         *m = file->private_data;
278         struct obd_device       *obd = m->private;
279         struct osp_device       *osp = lu2osp_dev(obd->obd_lu_dev);
280         int                      val, rc;
281
282         if (osp == NULL || osp->opd_pre == NULL)
283                 return 0;
284
285         rc = lprocfs_write_helper(buffer, count, &val);
286         if (rc)
287                 return rc;
288
289         if (val < 0)
290                 return -ERANGE;
291         if (val > OST_MAX_PRECREATE)
292                 return -ERANGE;
293
294         if (osp->opd_pre_grow_count > val)
295                 osp->opd_pre_grow_count = val;
296
297         osp->opd_pre_max_grow_count = val;
298
299         return count;
300 }
301 LPROC_SEQ_FOPS(osp_max_create_count);
302
303 static int osp_prealloc_next_id_seq_show(struct seq_file *m, void *data)
304 {
305         struct obd_device *obd = m->private;
306         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
307
308         if (osp == NULL || osp->opd_pre == NULL)
309                 return 0;
310
311         return seq_printf(m, "%u\n", fid_oid(&osp->opd_pre_used_fid) + 1);
312 }
313 LPROC_SEQ_FOPS_RO(osp_prealloc_next_id);
314
315 static int osp_prealloc_last_id_seq_show(struct seq_file *m, void *data)
316 {
317         struct obd_device *obd = m->private;
318         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
319
320         if (osp == NULL || osp->opd_pre == NULL)
321                 return 0;
322
323         return seq_printf(m, "%u\n", fid_oid(&osp->opd_pre_last_created_fid));
324 }
325 LPROC_SEQ_FOPS_RO(osp_prealloc_last_id);
326
327 static int osp_prealloc_next_seq_seq_show(struct seq_file *m, void *data)
328 {
329         struct obd_device *obd = m->private;
330         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
331
332         if (osp == NULL || osp->opd_pre == NULL)
333                 return 0;
334
335         return seq_printf(m, LPX64"\n", fid_seq(&osp->opd_pre_used_fid));
336 }
337 LPROC_SEQ_FOPS_RO(osp_prealloc_next_seq);
338
339 static int osp_prealloc_last_seq_seq_show(struct seq_file *m, void *data)
340 {
341         struct obd_device *obd = m->private;
342         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
343
344         if (osp == NULL || osp->opd_pre == NULL)
345                 return 0;
346
347         return seq_printf(m, LPX64"\n",
348                         fid_seq(&osp->opd_pre_last_created_fid));
349 }
350 LPROC_SEQ_FOPS_RO(osp_prealloc_last_seq);
351
352 static int osp_prealloc_reserved_seq_show(struct seq_file *m, void *data)
353 {
354         struct obd_device *obd = m->private;
355         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
356
357         if (osp == NULL || osp->opd_pre == NULL)
358                 return 0;
359
360         return seq_printf(m, LPU64"\n", osp->opd_pre_reserved);
361 }
362 LPROC_SEQ_FOPS_RO(osp_prealloc_reserved);
363
364 static int osp_maxage_seq_show(struct seq_file *m, void *data)
365 {
366         struct obd_device       *dev = m->private;
367         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
368
369         if (osp == NULL)
370                 return -EINVAL;
371
372         return seq_printf(m, "%u\n", osp->opd_statfs_maxage);
373 }
374
375 static ssize_t
376 osp_maxage_seq_write(struct file *file, const char *buffer,
377                         size_t count, loff_t *off)
378 {
379         struct seq_file         *m = file->private_data;
380         struct obd_device       *dev = m->private;
381         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
382         int                      val, rc;
383
384         if (osp == NULL)
385                 return -EINVAL;
386
387         rc = lprocfs_write_helper(buffer, count, &val);
388         if (rc)
389                 return rc;
390
391         if (val < 1)
392                 return -ERANGE;
393
394         osp->opd_statfs_maxage = val;
395
396         return count;
397 }
398 LPROC_SEQ_FOPS(osp_maxage);
399
400 static int osp_pre_status_seq_show(struct seq_file *m, void *data)
401 {
402         struct obd_device       *dev = m->private;
403         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
404
405         if (osp == NULL || osp->opd_pre == NULL)
406                 return -EINVAL;
407
408         return seq_printf(m, "%d\n", osp->opd_pre_status);
409 }
410 LPROC_SEQ_FOPS_RO(osp_pre_status);
411
412 static int osp_destroys_in_flight_seq_show(struct seq_file *m, void *data)
413 {
414         struct obd_device *dev = m->private;
415         struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
416
417         if (osp == NULL)
418                 return -EINVAL;
419
420         /*
421          * This counter used to determine if OST has space returned.
422          * Now we need to wait for the following:
423          * - sync changes are zero - no llog records
424          * - sync in progress are zero - no RPCs in flight
425          */
426         return seq_printf(m, "%lu\n",
427                           osp->opd_syn_rpc_in_progress + osp->opd_syn_changes);
428 }
429 LPROC_SEQ_FOPS_RO(osp_destroys_in_flight);
430
431 static int osp_old_sync_processed_seq_show(struct seq_file *m, void *data)
432 {
433         struct obd_device       *dev = m->private;
434         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
435
436         if (osp == NULL)
437                 return -EINVAL;
438
439         return seq_printf(m, "%d\n", osp->opd_syn_prev_done);
440 }
441 LPROC_SEQ_FOPS_RO(osp_old_sync_processed);
442
443 static int
444 osp_lfsck_max_rpcs_in_flight_seq_show(struct seq_file *m, void *data)
445 {
446         struct obd_device *dev = m->private;
447         __u32 max;
448
449         max = obd_get_max_rpcs_in_flight(&dev->u.cli);
450         return seq_printf(m, "%u\n", max);
451 }
452
453 static ssize_t
454 osp_lfsck_max_rpcs_in_flight_seq_write(struct file *file,
455                                        const char __user *buffer,
456                                        size_t count, loff_t *off)
457 {
458         struct seq_file   *m = file->private_data;
459         struct obd_device *dev = m->private;
460         int val;
461         int rc;
462
463         rc = lprocfs_write_helper(buffer, count, &val);
464         if (rc == 0)
465                 rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
466
467         if (rc != 0)
468                 count = rc;
469
470         return count;
471 }
472 LPROC_SEQ_FOPS(osp_lfsck_max_rpcs_in_flight);
473
474 LPROC_SEQ_FOPS_WO_TYPE(osp, ping);
475 LPROC_SEQ_FOPS_RO_TYPE(osp, uuid);
476 LPROC_SEQ_FOPS_RO_TYPE(osp, connect_flags);
477 LPROC_SEQ_FOPS_RO_TYPE(osp, server_uuid);
478 LPROC_SEQ_FOPS_RO_TYPE(osp, conn_uuid);
479
480 static int osp_max_pages_per_rpc_seq_show(struct seq_file *m, void *v)
481 {
482         return lprocfs_obd_max_pages_per_rpc_seq_show(m, m->private);
483 }
484 LPROC_SEQ_FOPS_RO(osp_max_pages_per_rpc);
485 LPROC_SEQ_FOPS_RO_TYPE(osp, timeouts);
486
487 LPROC_SEQ_FOPS_RW_TYPE(osp, import);
488 LPROC_SEQ_FOPS_RO_TYPE(osp, state);
489
490 static struct lprocfs_seq_vars lprocfs_osp_obd_vars[] = {
491         { .name =       "uuid",
492           .fops =       &osp_uuid_fops                  },
493         { .name =       "ping",
494           .fops =       &osp_ping_fops,
495           .proc_mode =  0222                            },
496         { .name =       "connect_flags",
497           .fops =       &osp_connect_flags_fops         },
498         { .name =       "ost_server_uuid",
499           .fops =       &osp_server_uuid_fops           },
500         { .name =       "ost_conn_uuid",
501           .fops =       &osp_conn_uuid_fops             },
502         { .name =       "active",
503           .fops =       &osp_active_fops                },
504         { .name =       "max_rpcs_in_flight",
505           .fops =       &osp_max_rpcs_in_flight_fops    },
506         { .name =       "max_rpcs_in_progress",
507           .fops =       &osp_max_rpcs_in_prog_fops      },
508         { .name =       "create_count",
509           .fops =       &osp_create_count_fops          },
510         { .name =       "max_create_count",
511           .fops =       &osp_max_create_count_fops      },
512         { .name =       "prealloc_next_id",
513           .fops =       &osp_prealloc_next_id_fops      },
514         { .name =       "prealloc_next_seq",
515           .fops =       &osp_prealloc_next_seq_fops     },
516         { .name =       "prealloc_last_id",
517           .fops =       &osp_prealloc_last_id_fops      },
518         { .name =       "prealloc_last_seq",
519           .fops =       &osp_prealloc_last_seq_fops     },
520         { .name =       "prealloc_reserved",
521           .fops =       &osp_prealloc_reserved_fops     },
522         { .name =       "timeouts",
523           .fops =       &osp_timeouts_fops              },
524         { .name =       "import",
525           .fops =       &osp_import_fops                },
526         { .name =       "state",
527           .fops =       &osp_state_fops                 },
528         { .name =       "maxage",
529           .fops =       &osp_maxage_fops                },
530         { .name =       "prealloc_status",
531           .fops =       &osp_pre_status_fops            },
532         { .name =       "sync_changes",
533           .fops =       &osp_syn_changes_fops           },
534         { .name =       "sync_in_flight",
535           .fops =       &osp_syn_in_flight_fops         },
536         { .name =       "sync_in_progress",
537           .fops =       &osp_syn_in_prog_fops           },
538         { .name =       "old_sync_processed",
539           .fops =       &osp_old_sync_processed_fops    },
540
541         /* for compatibility reasons */
542         { .name =       "destroys_in_flight",
543           .fops =       &osp_destroys_in_flight_fops            },
544         { .name =       "lfsck_max_rpcs_in_flight",
545           .fops =       &osp_lfsck_max_rpcs_in_flight_fops      },
546         { 0 }
547 };
548
549 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_blksize);
550 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_kbytestotal);
551 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_kbytesfree);
552 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_kbytesavail);
553 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_filestotal);
554 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_filesfree);
555
556 static struct lprocfs_seq_vars lprocfs_osp_osd_vars[] = {
557         { .name =       "blocksize",
558           .fops =       &osp_dt_blksize_fops            },
559         { .name =       "kbytestotal",
560           .fops =       &osp_dt_kbytestotal_fops        },
561         { .name =       "kbytesfree",
562           .fops =       &osp_dt_kbytesfree_fops         },
563         { .name =       "kbytesavail",
564           .fops =       &osp_dt_kbytesavail_fops        },
565         { .name =       "filestotal",
566           .fops =       &osp_dt_filestotal_fops         },
567         { .name =       "filesfree",
568           .fops =       &osp_dt_filesfree_fops          },
569         { 0 }
570 };
571
572 void osp_lprocfs_init(struct osp_device *osp)
573 {
574         struct obd_device       *obd = osp->opd_obd;
575         struct proc_dir_entry   *osc_proc_dir = NULL;
576         struct obd_type         *type;
577         int                      rc;
578
579         obd->obd_vars = lprocfs_osp_obd_vars;
580         if (lprocfs_seq_obd_setup(obd) != 0)
581                 return;
582
583         rc = lprocfs_seq_add_vars(obd->obd_proc_entry, lprocfs_osp_osd_vars,
584                                   &osp->opd_dt_dev);
585         if (rc) {
586                 CERROR("%s: can't register in lprocfs, rc %d\n",
587                        obd->obd_name, rc);
588                 return;
589         }
590
591         ptlrpc_lprocfs_register_obd(obd);
592
593         if (osp->opd_connect_mdt || !strstr(obd->obd_name, "osc"))
594                 return;
595
596         /* If the real OSC is present which is the case for setups
597          * with both server and clients on the same node then use
598          * the OSC's proc root */
599         type = class_search_type(LUSTRE_OSC_NAME);
600         if (type != NULL && type->typ_procroot != NULL)
601                 osc_proc_dir = type->typ_procroot;
602         else
603                 osc_proc_dir = obd->obd_type->typ_procsym;
604
605         if (osc_proc_dir == NULL)
606                 return;
607
608         /* for compatibility we link old procfs's OSC entries to osp ones */
609         osp->opd_symlink = lprocfs_add_symlink(obd->obd_name, osc_proc_dir,
610                                                "../osp/%s", obd->obd_name);
611         if (osp->opd_symlink == NULL)
612                 CERROR("could not register OSC symlink for "
613                        "/proc/fs/lustre/osp/%s.", obd->obd_name);
614 }
615
616 #endif /* LPROCFS */
617