4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osp/lproc_osp.c
38 * Lustre OST Proxy Device, procfs functions
40 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
43 #define DEBUG_SUBSYSTEM S_CLASS
45 #include "osp_internal.h"
48 static int osp_active_seq_show(struct seq_file *m, void *data)
50 struct obd_device *dev = m->private;
53 LPROCFS_CLIMP_CHECK(dev);
54 rc = seq_printf(m, "%d\n", !dev->u.cli.cl_import->imp_deactive);
55 LPROCFS_CLIMP_EXIT(dev);
60 osp_active_seq_write(struct file *file, const char *buffer,
61 size_t count, loff_t *off)
63 struct seq_file *m = file->private_data;
64 struct obd_device *dev = m->private;
67 rc = lprocfs_write_helper(buffer, count, &val);
70 if (val < 0 || val > 1)
73 LPROCFS_CLIMP_CHECK(dev);
75 if (dev->u.cli.cl_import->imp_deactive == val)
76 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
78 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n",
81 LPROCFS_CLIMP_EXIT(dev);
84 LPROC_SEQ_FOPS(osp_active);
86 static int osp_syn_in_flight_seq_show(struct seq_file *m, void *data)
88 struct obd_device *dev = m->private;
89 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
94 return seq_printf(m, "%u\n", osp->opd_syn_rpc_in_flight);
96 LPROC_SEQ_FOPS_RO(osp_syn_in_flight);
98 static int osp_syn_in_prog_seq_show(struct seq_file *m, void *data)
100 struct obd_device *dev = m->private;
101 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
106 return seq_printf(m, "%u\n", osp->opd_syn_rpc_in_progress);
108 LPROC_SEQ_FOPS_RO(osp_syn_in_prog);
110 static int osp_syn_changes_seq_show(struct seq_file *m, void *data)
112 struct obd_device *dev = m->private;
113 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
118 return seq_printf(m, "%lu\n", osp->opd_syn_changes);
121 static ssize_t osp_syn_changes_seq_write(struct file *file, const char *buffer,
122 size_t count, loff_t *off)
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);
130 rc = lu_env_init(&env, LCT_LOCAL);
134 rc = dt_sync(&env, &osp->opd_dt_dev);
137 return rc == 0 ? count : rc;
139 LPROC_SEQ_FOPS(osp_syn_changes);
141 static int osp_max_rpcs_in_flight_seq_show(struct seq_file *m, void *data)
143 struct obd_device *dev = m->private;
144 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
149 return seq_printf(m, "%u\n", osp->opd_syn_max_rpc_in_flight);
153 osp_max_rpcs_in_flight_seq_write(struct file *file, const char *buffer,
154 size_t count, loff_t *off)
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);
164 rc = lprocfs_write_helper(buffer, count, &val);
171 osp->opd_syn_max_rpc_in_flight = val;
174 LPROC_SEQ_FOPS(osp_max_rpcs_in_flight);
176 static int osp_max_rpcs_in_prog_seq_show(struct seq_file *m, void *data)
178 struct obd_device *dev = m->private;
179 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
184 return seq_printf(m, "%u\n", osp->opd_syn_max_rpc_in_progress);
188 osp_max_rpcs_in_prog_seq_write(struct file *file, const char *buffer,
189 size_t count, loff_t *off)
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);
199 rc = lprocfs_write_helper(buffer, count, &val);
206 osp->opd_syn_max_rpc_in_progress = val;
210 LPROC_SEQ_FOPS(osp_max_rpcs_in_prog);
212 static int osp_create_count_seq_show(struct seq_file *m, void *data)
214 struct obd_device *obd = m->private;
215 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
217 if (osp == NULL || osp->opd_pre == NULL)
220 return seq_printf(m, "%d\n", osp->opd_pre_grow_count);
224 osp_create_count_seq_write(struct file *file, const char *buffer,
225 size_t count, loff_t *off)
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);
232 if (osp == NULL || osp->opd_pre == NULL)
235 rc = lprocfs_write_helper(buffer, count, &val);
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.
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)
251 if (val > osp->opd_pre_max_grow_count)
254 for (i = 1; (i << 1) <= val; i <<= 1)
256 osp->opd_pre_grow_count = i;
260 LPROC_SEQ_FOPS(osp_create_count);
262 static int osp_max_create_count_seq_show(struct seq_file *m, void *data)
264 struct obd_device *obd = m->private;
265 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
267 if (osp == NULL || osp->opd_pre == NULL)
270 return seq_printf(m, "%d\n", osp->opd_pre_max_grow_count);
274 osp_max_create_count_seq_write(struct file *file, const char *buffer,
275 size_t count, loff_t *off)
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);
282 if (osp == NULL || osp->opd_pre == NULL)
285 rc = lprocfs_write_helper(buffer, count, &val);
291 if (val > OST_MAX_PRECREATE)
294 if (osp->opd_pre_grow_count > val)
295 osp->opd_pre_grow_count = val;
297 osp->opd_pre_max_grow_count = val;
301 LPROC_SEQ_FOPS(osp_max_create_count);
303 static int osp_prealloc_next_id_seq_show(struct seq_file *m, void *data)
305 struct obd_device *obd = m->private;
306 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
308 if (osp == NULL || osp->opd_pre == NULL)
311 return seq_printf(m, "%u\n", fid_oid(&osp->opd_pre_used_fid) + 1);
313 LPROC_SEQ_FOPS_RO(osp_prealloc_next_id);
315 static int osp_prealloc_last_id_seq_show(struct seq_file *m, void *data)
317 struct obd_device *obd = m->private;
318 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
320 if (osp == NULL || osp->opd_pre == NULL)
323 return seq_printf(m, "%u\n", fid_oid(&osp->opd_pre_last_created_fid));
325 LPROC_SEQ_FOPS_RO(osp_prealloc_last_id);
327 static int osp_prealloc_next_seq_seq_show(struct seq_file *m, void *data)
329 struct obd_device *obd = m->private;
330 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
332 if (osp == NULL || osp->opd_pre == NULL)
335 return seq_printf(m, LPX64"\n", fid_seq(&osp->opd_pre_used_fid));
337 LPROC_SEQ_FOPS_RO(osp_prealloc_next_seq);
339 static int osp_prealloc_last_seq_seq_show(struct seq_file *m, void *data)
341 struct obd_device *obd = m->private;
342 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
344 if (osp == NULL || osp->opd_pre == NULL)
347 return seq_printf(m, LPX64"\n",
348 fid_seq(&osp->opd_pre_last_created_fid));
350 LPROC_SEQ_FOPS_RO(osp_prealloc_last_seq);
352 static int osp_prealloc_reserved_seq_show(struct seq_file *m, void *data)
354 struct obd_device *obd = m->private;
355 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
357 if (osp == NULL || osp->opd_pre == NULL)
360 return seq_printf(m, LPU64"\n", osp->opd_pre_reserved);
362 LPROC_SEQ_FOPS_RO(osp_prealloc_reserved);
364 static int osp_maxage_seq_show(struct seq_file *m, void *data)
366 struct obd_device *dev = m->private;
367 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
372 return seq_printf(m, "%u\n", osp->opd_statfs_maxage);
376 osp_maxage_seq_write(struct file *file, const char *buffer,
377 size_t count, loff_t *off)
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);
387 rc = lprocfs_write_helper(buffer, count, &val);
394 osp->opd_statfs_maxage = val;
398 LPROC_SEQ_FOPS(osp_maxage);
400 static int osp_pre_status_seq_show(struct seq_file *m, void *data)
402 struct obd_device *dev = m->private;
403 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
405 if (osp == NULL || osp->opd_pre == NULL)
408 return seq_printf(m, "%d\n", osp->opd_pre_status);
410 LPROC_SEQ_FOPS_RO(osp_pre_status);
412 static int osp_destroys_in_flight_seq_show(struct seq_file *m, void *data)
414 struct obd_device *dev = m->private;
415 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
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
426 return seq_printf(m, "%lu\n",
427 osp->opd_syn_rpc_in_progress + osp->opd_syn_changes);
429 LPROC_SEQ_FOPS_RO(osp_destroys_in_flight);
431 static int osp_old_sync_processed_seq_show(struct seq_file *m, void *data)
433 struct obd_device *dev = m->private;
434 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
439 return seq_printf(m, "%d\n", osp->opd_syn_prev_done);
441 LPROC_SEQ_FOPS_RO(osp_old_sync_processed);
444 osp_lfsck_max_rpcs_in_flight_seq_show(struct seq_file *m, void *data)
446 struct obd_device *dev = m->private;
449 max = obd_get_max_rpcs_in_flight(&dev->u.cli);
450 return seq_printf(m, "%u\n", max);
454 osp_lfsck_max_rpcs_in_flight_seq_write(struct file *file,
455 const char __user *buffer,
456 size_t count, loff_t *off)
458 struct seq_file *m = file->private_data;
459 struct obd_device *dev = m->private;
463 rc = lprocfs_write_helper(buffer, count, &val);
465 rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
472 LPROC_SEQ_FOPS(osp_lfsck_max_rpcs_in_flight);
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);
480 static int osp_max_pages_per_rpc_seq_show(struct seq_file *m, void *v)
482 return lprocfs_obd_max_pages_per_rpc_seq_show(m, m->private);
484 LPROC_SEQ_FOPS_RO(osp_max_pages_per_rpc);
485 LPROC_SEQ_FOPS_RO_TYPE(osp, timeouts);
487 LPROC_SEQ_FOPS_RW_TYPE(osp, import);
488 LPROC_SEQ_FOPS_RO_TYPE(osp, state);
490 static struct lprocfs_seq_vars lprocfs_osp_obd_vars[] = {
492 .fops = &osp_uuid_fops },
494 .fops = &osp_ping_fops,
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 },
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 },
525 .fops = &osp_import_fops },
527 .fops = &osp_state_fops },
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 },
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 },
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);
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 },
572 void osp_lprocfs_init(struct osp_device *osp)
574 struct obd_device *obd = osp->opd_obd;
575 struct proc_dir_entry *osc_proc_dir = NULL;
576 struct obd_type *type;
579 obd->obd_vars = lprocfs_osp_obd_vars;
580 if (lprocfs_seq_obd_setup(obd) != 0)
583 rc = lprocfs_seq_add_vars(obd->obd_proc_entry, lprocfs_osp_osd_vars,
586 CERROR("%s: can't register in lprocfs, rc %d\n",
591 ptlrpc_lprocfs_register_obd(obd);
593 if (osp->opd_connect_mdt || !strstr(obd->obd_name, "osc"))
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;
603 osc_proc_dir = obd->obd_type->typ_procsym;
605 if (osc_proc_dir == NULL)
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);