Whamcloud - gitweb
c23ce18840ef18e7edb222917ddac793ae350131
[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 LPROC_SEQ_FOPS_RO(osp_syn_changes);
121
122 static int osp_max_rpcs_in_flight_seq_show(struct seq_file *m, void *data)
123 {
124         struct obd_device       *dev = m->private;
125         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
126
127         if (osp == NULL)
128                 return -EINVAL;
129
130         return seq_printf(m, "%u\n", osp->opd_syn_max_rpc_in_flight);
131 }
132
133 static ssize_t
134 osp_max_rpcs_in_flight_seq_write(struct file *file, const char *buffer,
135                                 size_t count, loff_t *off)
136 {
137         struct seq_file         *m = file->private_data;
138         struct obd_device       *dev = m->private;
139         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
140         int                      val, rc;
141
142         if (osp == NULL)
143                 return -EINVAL;
144
145         rc = lprocfs_write_helper(buffer, count, &val);
146         if (rc)
147                 return rc;
148
149         if (val < 1)
150                 return -ERANGE;
151
152         osp->opd_syn_max_rpc_in_flight = val;
153         return count;
154 }
155 LPROC_SEQ_FOPS(osp_max_rpcs_in_flight);
156
157 static int osp_max_rpcs_in_prog_seq_show(struct seq_file *m, void *data)
158 {
159         struct obd_device       *dev = m->private;
160         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
161
162         if (osp == NULL)
163                 return -EINVAL;
164
165         return seq_printf(m, "%u\n", osp->opd_syn_max_rpc_in_progress);
166 }
167
168 static ssize_t
169 osp_max_rpcs_in_prog_seq_write(struct file *file, const char *buffer,
170                                 size_t count, loff_t *off)
171 {
172         struct seq_file         *m = file->private_data;
173         struct obd_device       *dev = m->private;
174         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
175         int                      val, rc;
176
177         if (osp == NULL)
178                 return -EINVAL;
179
180         rc = lprocfs_write_helper(buffer, count, &val);
181         if (rc)
182                 return rc;
183
184         if (val < 1)
185                 return -ERANGE;
186
187         osp->opd_syn_max_rpc_in_progress = val;
188
189         return count;
190 }
191 LPROC_SEQ_FOPS(osp_max_rpcs_in_prog);
192
193 static int osp_create_count_seq_show(struct seq_file *m, void *data)
194 {
195         struct obd_device *obd = m->private;
196         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
197
198         if (osp == NULL || osp->opd_pre == NULL)
199                 return 0;
200
201         return seq_printf(m, "%d\n", osp->opd_pre_grow_count);
202 }
203
204 static ssize_t
205 osp_create_count_seq_write(struct file *file, const char *buffer,
206                                 size_t count, loff_t *off)
207 {
208         struct seq_file         *m = file->private_data;
209         struct obd_device       *obd = m->private;
210         struct osp_device       *osp = lu2osp_dev(obd->obd_lu_dev);
211         int                      val, rc, i;
212
213         if (osp == NULL || osp->opd_pre == NULL)
214                 return 0;
215
216         rc = lprocfs_write_helper(buffer, count, &val);
217         if (rc)
218                 return rc;
219
220         /* The MDT ALWAYS needs to limit the precreate count to
221          * OST_MAX_PRECREATE, and the constant cannot be changed
222          * because it is a value shared between the OSP and OST
223          * that is the maximum possible number of objects that will
224          * ever be handled by MDT->OST recovery processing.
225          *
226          * If the OST ever gets a request to delete more orphans,
227          * this implies that something has gone badly on the MDT
228          * and the OST will refuse to delete so much data from the
229          * filesystem as a safety measure. */
230         if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
231                 return -ERANGE;
232         if (val > osp->opd_pre_max_grow_count)
233                 return -ERANGE;
234
235         for (i = 1; (i << 1) <= val; i <<= 1)
236                 ;
237         osp->opd_pre_grow_count = i;
238
239         return count;
240 }
241 LPROC_SEQ_FOPS(osp_create_count);
242
243 static int osp_max_create_count_seq_show(struct seq_file *m, void *data)
244 {
245         struct obd_device *obd = m->private;
246         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
247
248         if (osp == NULL || osp->opd_pre == NULL)
249                 return 0;
250
251         return seq_printf(m, "%d\n", osp->opd_pre_max_grow_count);
252 }
253
254 static ssize_t
255 osp_max_create_count_seq_write(struct file *file, const char *buffer,
256                                 size_t count, loff_t *off)
257 {
258         struct seq_file         *m = file->private_data;
259         struct obd_device       *obd = m->private;
260         struct osp_device       *osp = lu2osp_dev(obd->obd_lu_dev);
261         int                      val, rc;
262
263         if (osp == NULL || osp->opd_pre == NULL)
264                 return 0;
265
266         rc = lprocfs_write_helper(buffer, count, &val);
267         if (rc)
268                 return rc;
269
270         if (val < 0)
271                 return -ERANGE;
272         if (val > OST_MAX_PRECREATE)
273                 return -ERANGE;
274
275         if (osp->opd_pre_grow_count > val)
276                 osp->opd_pre_grow_count = val;
277
278         osp->opd_pre_max_grow_count = val;
279
280         return count;
281 }
282 LPROC_SEQ_FOPS(osp_max_create_count);
283
284 static int osp_prealloc_next_id_seq_show(struct seq_file *m, void *data)
285 {
286         struct obd_device *obd = m->private;
287         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
288
289         if (osp == NULL || osp->opd_pre == NULL)
290                 return 0;
291
292         return seq_printf(m, "%u\n", fid_oid(&osp->opd_pre_used_fid) + 1);
293 }
294 LPROC_SEQ_FOPS_RO(osp_prealloc_next_id);
295
296 static int osp_prealloc_last_id_seq_show(struct seq_file *m, void *data)
297 {
298         struct obd_device *obd = m->private;
299         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
300
301         if (osp == NULL || osp->opd_pre == NULL)
302                 return 0;
303
304         return seq_printf(m, "%u\n", fid_oid(&osp->opd_pre_last_created_fid));
305 }
306 LPROC_SEQ_FOPS_RO(osp_prealloc_last_id);
307
308 static int osp_prealloc_next_seq_seq_show(struct seq_file *m, void *data)
309 {
310         struct obd_device *obd = m->private;
311         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
312
313         if (osp == NULL || osp->opd_pre == NULL)
314                 return 0;
315
316         return seq_printf(m, LPX64"\n", fid_seq(&osp->opd_pre_used_fid));
317 }
318 LPROC_SEQ_FOPS_RO(osp_prealloc_next_seq);
319
320 static int osp_prealloc_last_seq_seq_show(struct seq_file *m, void *data)
321 {
322         struct obd_device *obd = m->private;
323         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
324
325         if (osp == NULL || osp->opd_pre == NULL)
326                 return 0;
327
328         return seq_printf(m, LPX64"\n",
329                         fid_seq(&osp->opd_pre_last_created_fid));
330 }
331 LPROC_SEQ_FOPS_RO(osp_prealloc_last_seq);
332
333 static int osp_prealloc_reserved_seq_show(struct seq_file *m, void *data)
334 {
335         struct obd_device *obd = m->private;
336         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
337
338         if (osp == NULL || osp->opd_pre == NULL)
339                 return 0;
340
341         return seq_printf(m, LPU64"\n", osp->opd_pre_reserved);
342 }
343 LPROC_SEQ_FOPS_RO(osp_prealloc_reserved);
344
345 static int osp_maxage_seq_show(struct seq_file *m, void *data)
346 {
347         struct obd_device       *dev = m->private;
348         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
349
350         if (osp == NULL)
351                 return -EINVAL;
352
353         return seq_printf(m, "%u\n", osp->opd_statfs_maxage);
354 }
355
356 static ssize_t
357 osp_maxage_seq_write(struct file *file, const char *buffer,
358                         size_t count, loff_t *off)
359 {
360         struct seq_file         *m = file->private_data;
361         struct obd_device       *dev = m->private;
362         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
363         int                      val, rc;
364
365         if (osp == NULL)
366                 return -EINVAL;
367
368         rc = lprocfs_write_helper(buffer, count, &val);
369         if (rc)
370                 return rc;
371
372         if (val < 1)
373                 return -ERANGE;
374
375         osp->opd_statfs_maxage = val;
376
377         return count;
378 }
379 LPROC_SEQ_FOPS(osp_maxage);
380
381 static int osp_pre_status_seq_show(struct seq_file *m, void *data)
382 {
383         struct obd_device       *dev = m->private;
384         struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
385
386         if (osp == NULL || osp->opd_pre == NULL)
387                 return -EINVAL;
388
389         return seq_printf(m, "%d\n", osp->opd_pre_status);
390 }
391 LPROC_SEQ_FOPS_RO(osp_pre_status);
392
393 static int osp_destroys_in_flight_seq_show(struct seq_file *m, void *data)
394 {
395         struct obd_device *dev = m->private;
396         struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
397
398         if (osp == NULL)
399                 return -EINVAL;
400
401         /*
402          * This counter used to determine if OST has space returned.
403          * Now we need to wait for the following:
404          * - sync changes are zero - no llog records
405          * - sync in progress are zero - no RPCs in flight
406          */
407         return seq_printf(m, "%lu\n",
408                           osp->opd_syn_rpc_in_progress + osp->opd_syn_changes);
409 }
410 LPROC_SEQ_FOPS_RO(osp_destroys_in_flight);
411
412 static int osp_old_sync_processed_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         return seq_printf(m, "%d\n", osp->opd_syn_prev_done);
421 }
422 LPROC_SEQ_FOPS_RO(osp_old_sync_processed);
423
424 static int
425 osp_lfsck_max_rpcs_in_flight_seq_show(struct seq_file *m, void *data)
426 {
427         struct obd_device *dev = m->private;
428         __u32 max;
429
430         max = obd_get_max_rpcs_in_flight(&dev->u.cli);
431         return seq_printf(m, "%u\n", max);
432 }
433
434 static ssize_t
435 osp_lfsck_max_rpcs_in_flight_seq_write(struct file *file,
436                                        const char __user *buffer,
437                                        size_t count, loff_t *off)
438 {
439         struct seq_file   *m = file->private_data;
440         struct obd_device *dev = m->private;
441         int val;
442         int rc;
443
444         rc = lprocfs_write_helper(buffer, count, &val);
445         if (rc == 0)
446                 rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
447
448         if (rc != 0)
449                 count = rc;
450
451         return count;
452 }
453 LPROC_SEQ_FOPS(osp_lfsck_max_rpcs_in_flight);
454
455 LPROC_SEQ_FOPS_WO_TYPE(osp, ping);
456 LPROC_SEQ_FOPS_RO_TYPE(osp, uuid);
457 LPROC_SEQ_FOPS_RO_TYPE(osp, connect_flags);
458 LPROC_SEQ_FOPS_RO_TYPE(osp, server_uuid);
459 LPROC_SEQ_FOPS_RO_TYPE(osp, conn_uuid);
460
461 static int osp_max_pages_per_rpc_seq_show(struct seq_file *m, void *v)
462 {
463         return lprocfs_obd_max_pages_per_rpc_seq_show(m, m->private);
464 }
465 LPROC_SEQ_FOPS_RO(osp_max_pages_per_rpc);
466 LPROC_SEQ_FOPS_RO_TYPE(osp, timeouts);
467
468 LPROC_SEQ_FOPS_RW_TYPE(osp, import);
469 LPROC_SEQ_FOPS_RO_TYPE(osp, state);
470
471 static struct lprocfs_seq_vars lprocfs_osp_obd_vars[] = {
472         { .name =       "uuid",
473           .fops =       &osp_uuid_fops                  },
474         { .name =       "ping",
475           .fops =       &osp_ping_fops,
476           .proc_mode =  0222                            },
477         { .name =       "connect_flags",
478           .fops =       &osp_connect_flags_fops         },
479         { .name =       "ost_server_uuid",
480           .fops =       &osp_server_uuid_fops           },
481         { .name =       "ost_conn_uuid",
482           .fops =       &osp_conn_uuid_fops             },
483         { .name =       "active",
484           .fops =       &osp_active_fops                },
485         { .name =       "max_rpcs_in_flight",
486           .fops =       &osp_max_rpcs_in_flight_fops    },
487         { .name =       "max_rpcs_in_progress",
488           .fops =       &osp_max_rpcs_in_prog_fops      },
489         { .name =       "create_count",
490           .fops =       &osp_create_count_fops          },
491         { .name =       "max_create_count",
492           .fops =       &osp_max_create_count_fops      },
493         { .name =       "prealloc_next_id",
494           .fops =       &osp_prealloc_next_id_fops      },
495         { .name =       "prealloc_next_seq",
496           .fops =       &osp_prealloc_next_seq_fops     },
497         { .name =       "prealloc_last_id",
498           .fops =       &osp_prealloc_last_id_fops      },
499         { .name =       "prealloc_last_seq",
500           .fops =       &osp_prealloc_last_seq_fops     },
501         { .name =       "prealloc_reserved",
502           .fops =       &osp_prealloc_reserved_fops     },
503         { .name =       "timeouts",
504           .fops =       &osp_timeouts_fops              },
505         { .name =       "import",
506           .fops =       &osp_import_fops                },
507         { .name =       "state",
508           .fops =       &osp_state_fops                 },
509         { .name =       "maxage",
510           .fops =       &osp_maxage_fops                },
511         { .name =       "prealloc_status",
512           .fops =       &osp_pre_status_fops            },
513         { .name =       "sync_changes",
514           .fops =       &osp_syn_changes_fops           },
515         { .name =       "sync_in_flight",
516           .fops =       &osp_syn_in_flight_fops         },
517         { .name =       "sync_in_progress",
518           .fops =       &osp_syn_in_prog_fops           },
519         { .name =       "old_sync_processed",
520           .fops =       &osp_old_sync_processed_fops    },
521
522         /* for compatibility reasons */
523         { .name =       "destroys_in_flight",
524           .fops =       &osp_destroys_in_flight_fops            },
525         { .name =       "lfsck_max_rpcs_in_flight",
526           .fops =       &osp_lfsck_max_rpcs_in_flight_fops      },
527         { 0 }
528 };
529
530 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_blksize);
531 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_kbytestotal);
532 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_kbytesfree);
533 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_kbytesavail);
534 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_filestotal);
535 LPROC_SEQ_FOPS_RO_TYPE(osp, dt_filesfree);
536
537 static struct lprocfs_seq_vars lprocfs_osp_osd_vars[] = {
538         { .name =       "blocksize",
539           .fops =       &osp_dt_blksize_fops            },
540         { .name =       "kbytestotal",
541           .fops =       &osp_dt_kbytestotal_fops        },
542         { .name =       "kbytesfree",
543           .fops =       &osp_dt_kbytesfree_fops         },
544         { .name =       "kbytesavail",
545           .fops =       &osp_dt_kbytesavail_fops        },
546         { .name =       "filestotal",
547           .fops =       &osp_dt_filestotal_fops         },
548         { .name =       "filesfree",
549           .fops =       &osp_dt_filesfree_fops          },
550         { 0 }
551 };
552
553 void osp_lprocfs_init(struct osp_device *osp)
554 {
555         struct obd_device       *obd = osp->opd_obd;
556         struct proc_dir_entry   *osc_proc_dir = NULL;
557         struct obd_type         *type;
558         int                      rc;
559
560         obd->obd_vars = lprocfs_osp_obd_vars;
561         if (lprocfs_seq_obd_setup(obd) != 0)
562                 return;
563
564         rc = lprocfs_seq_add_vars(obd->obd_proc_entry, lprocfs_osp_osd_vars,
565                                   &osp->opd_dt_dev);
566         if (rc) {
567                 CERROR("%s: can't register in lprocfs, rc %d\n",
568                        obd->obd_name, rc);
569                 return;
570         }
571
572         ptlrpc_lprocfs_register_obd(obd);
573
574         if (osp->opd_connect_mdt || !strstr(obd->obd_name, "osc"))
575                 return;
576
577         /* If the real OSC is present which is the case for setups
578          * with both server and clients on the same node then use
579          * the OSC's proc root */
580         type = class_search_type(LUSTRE_OSC_NAME);
581         if (type != NULL && type->typ_procroot != NULL)
582                 osc_proc_dir = type->typ_procroot;
583         else
584                 osc_proc_dir = obd->obd_type->typ_procsym;
585
586         if (osc_proc_dir == NULL)
587                 return;
588
589         /* for compatibility we link old procfs's OSC entries to osp ones */
590         osp->opd_symlink = lprocfs_add_symlink(obd->obd_name, osc_proc_dir,
591                                                "../osp/%s", obd->obd_name);
592         if (osp->opd_symlink == NULL)
593                 CERROR("could not register OSC symlink for "
594                        "/proc/fs/lustre/osp/%s.", obd->obd_name);
595 }
596
597 #endif /* LPROCFS */
598