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, 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_rd_active(char *page, char **start, off_t off,
49 int count, int *eof, void *data)
51 struct obd_device *dev = data;
54 LPROCFS_CLIMP_CHECK(dev);
55 rc = snprintf(page, count, "%d\n",
56 !dev->u.cli.cl_import->imp_deactive);
57 LPROCFS_CLIMP_EXIT(dev);
61 static int osp_wr_active(struct file *file, const char *buffer,
62 unsigned long count, void *data)
64 struct obd_device *dev = data;
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);
85 static int osp_rd_syn_in_flight(char *page, char **start, off_t off,
86 int count, int *eof, void *data)
88 struct obd_device *dev = data;
89 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
95 rc = snprintf(page, count, "%u\n", osp->opd_syn_rpc_in_flight);
99 static int osp_rd_syn_in_prog(char *page, char **start, off_t off, int count,
100 int *eof, void *data)
102 struct obd_device *dev = data;
103 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
109 rc = snprintf(page, count, "%u\n", osp->opd_syn_rpc_in_progress);
113 static int osp_rd_syn_changes(char *page, char **start, off_t off,
114 int count, int *eof, void *data)
116 struct obd_device *dev = data;
117 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
123 rc = snprintf(page, count, "%lu\n", osp->opd_syn_changes);
127 static int osp_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
128 int count, int *eof, void *data)
130 struct obd_device *dev = data;
131 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
137 rc = snprintf(page, count, "%u\n", osp->opd_syn_max_rpc_in_flight);
141 static int osp_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
142 unsigned long count, void *data)
144 struct obd_device *dev = data;
145 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
151 rc = lprocfs_write_helper(buffer, count, &val);
158 osp->opd_syn_max_rpc_in_flight = val;
162 static int osp_rd_max_rpcs_in_prog(char *page, char **start, off_t off,
163 int count, int *eof, void *data)
165 struct obd_device *dev = data;
166 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
172 rc = snprintf(page, count, "%u\n", osp->opd_syn_max_rpc_in_progress);
176 static int osp_wr_max_rpcs_in_prog(struct file *file, const char *buffer,
177 unsigned long count, void *data)
179 struct obd_device *dev = data;
180 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
186 rc = lprocfs_write_helper(buffer, count, &val);
193 osp->opd_syn_max_rpc_in_progress = val;
198 static int osp_rd_create_count(char *page, char **start, off_t off, int count,
199 int *eof, void *data)
201 struct obd_device *obd = data;
202 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
207 return snprintf(page, count, "%d\n", osp->opd_pre_grow_count);
210 static int osp_wr_create_count(struct file *file, const char *buffer,
211 unsigned long count, void *data)
213 struct obd_device *obd = data;
214 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
220 rc = lprocfs_write_helper(buffer, count, &val);
224 /* The MDT ALWAYS needs to limit the precreate count to
225 * OST_MAX_PRECREATE, and the constant cannot be changed
226 * because it is a value shared between the OSP and OST
227 * that is the maximum possible number of objects that will
228 * ever be handled by MDT->OST recovery processing.
230 * If the OST ever gets a request to delete more orphans,
231 * this implies that something has gone badly on the MDT
232 * and the OST will refuse to delete so much data from the
233 * filesystem as a safety measure. */
234 if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
236 if (val > osp->opd_pre_max_grow_count)
239 for (i = 1; (i << 1) <= val; i <<= 1)
241 osp->opd_pre_grow_count = i;
246 static int osp_rd_max_create_count(char *page, char **start, off_t off,
247 int count, int *eof, void *data)
249 struct obd_device *obd = data;
250 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
255 return snprintf(page, count, "%d\n", osp->opd_pre_max_grow_count);
258 static int osp_wr_max_create_count(struct file *file, const char *buffer,
259 unsigned long count, void *data)
261 struct obd_device *obd = data;
262 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
268 rc = lprocfs_write_helper(buffer, count, &val);
274 if (val > OST_MAX_PRECREATE)
277 if (osp->opd_pre_grow_count > val)
278 osp->opd_pre_grow_count = val;
280 osp->opd_pre_max_grow_count = val;
285 static int osp_rd_prealloc_next_id(char *page, char **start, off_t off,
286 int count, int *eof, void *data)
288 struct obd_device *obd = data;
289 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
294 return snprintf(page, count, LPU64"\n", osp->opd_pre_used_id + 1);
297 static int osp_rd_prealloc_last_id(char *page, char **start, off_t off,
298 int count, int *eof, void *data)
300 struct obd_device *obd = data;
301 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
306 return snprintf(page, count, LPU64"\n", osp->opd_pre_last_created);
309 static int osp_rd_prealloc_reserved(char *page, char **start, off_t off,
310 int count, int *eof, void *data)
312 struct obd_device *obd = data;
313 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
318 return snprintf(page, count, LPU64"\n", osp->opd_pre_reserved);
321 static int osp_rd_maxage(char *page, char **start, off_t off,
322 int count, int *eof, void *data)
324 struct obd_device *dev = data;
325 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
331 rc = snprintf(page, count, "%u\n", osp->opd_statfs_maxage);
335 static int osp_wr_maxage(struct file *file, const char *buffer,
336 unsigned long count, void *data)
338 struct obd_device *dev = data;
339 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
345 rc = lprocfs_write_helper(buffer, count, &val);
352 osp->opd_statfs_maxage = val;
357 static int osp_rd_pre_status(char *page, char **start, off_t off,
358 int count, int *eof, void *data)
360 struct obd_device *dev = data;
361 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
367 rc = snprintf(page, count, "%d\n", osp->opd_pre_status);
371 static int osp_rd_destroys_in_flight(char *page, char **start, off_t off,
372 int count, int *eof, void *data)
374 struct obd_device *dev = data;
375 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
378 * This counter used to determine if OST has space returned.
379 * Now we need to wait for the following:
380 * - sync changes are zero - no llog records
381 * - sync in progress are zero - no RPCs in flight
383 return snprintf(page, count, "%lu\n",
384 osp->opd_syn_rpc_in_progress + osp->opd_syn_changes);
387 static int osp_rd_old_sync_processed(char *page, char **start, off_t off,
388 int count, int *eof, void *data)
390 struct obd_device *dev = data;
391 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
397 rc = snprintf(page, count, "%d\n", osp->opd_syn_prev_done);
401 static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
402 { "uuid", lprocfs_rd_uuid, 0, 0 },
403 { "ping", 0, lprocfs_wr_ping, 0, 0, 0222 },
404 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
405 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
406 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
407 { "active", osp_rd_active, osp_wr_active, 0 },
408 { "max_rpcs_in_flight", osp_rd_max_rpcs_in_flight,
409 osp_wr_max_rpcs_in_flight, 0 },
410 { "max_rpcs_in_progress", osp_rd_max_rpcs_in_prog,
411 osp_wr_max_rpcs_in_prog, 0 },
412 { "create_count", osp_rd_create_count,
413 osp_wr_create_count, 0 },
414 { "max_create_count", osp_rd_max_create_count,
415 osp_wr_max_create_count, 0 },
416 { "prealloc_next_id", osp_rd_prealloc_next_id, 0, 0 },
417 { "prealloc_last_id", osp_rd_prealloc_last_id, 0, 0 },
418 { "prealloc_reserved", osp_rd_prealloc_reserved, 0, 0 },
419 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
420 { "import", lprocfs_rd_import, lprocfs_wr_import, 0 },
421 { "state", lprocfs_rd_state, 0, 0 },
422 { "maxage", osp_rd_maxage, osp_wr_maxage, 0 },
423 { "prealloc_status", osp_rd_pre_status, 0, 0 },
424 { "sync_changes", osp_rd_syn_changes, 0, 0 },
425 { "sync_in_flight", osp_rd_syn_in_flight, 0, 0 },
426 { "sync_in_progress", osp_rd_syn_in_prog, 0, 0 },
427 { "old_sync_processed", osp_rd_old_sync_processed, 0, 0 },
429 /* for compatibility reasons */
430 { "destroys_in_flight", osp_rd_destroys_in_flight, 0, 0 },
434 static struct lprocfs_vars lprocfs_osp_osd_vars[] = {
435 { "blocksize", lprocfs_osd_rd_blksize, 0, 0 },
436 { "kbytestotal", lprocfs_osd_rd_kbytestotal, 0, 0 },
437 { "kbytesfree", lprocfs_osd_rd_kbytesfree, 0, 0 },
438 { "kbytesavail", lprocfs_osd_rd_kbytesavail, 0, 0 },
439 { "filestotal", lprocfs_osd_rd_filestotal, 0, 0 },
440 { "filesfree", lprocfs_osd_rd_filesfree, 0, 0 },
444 static struct lprocfs_vars lprocfs_osp_module_vars[] = {
445 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
449 void lprocfs_osp_init_vars(struct lprocfs_static_vars *lvars)
451 lvars->module_vars = lprocfs_osp_module_vars;
452 lvars->obd_vars = lprocfs_osp_obd_vars;
455 void osp_lprocfs_init(struct osp_device *osp)
457 struct obd_device *obd = osp->opd_obd;
458 struct proc_dir_entry *osc_proc_dir;
461 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
462 obd->obd_type->typ_procroot,
463 lprocfs_osp_osd_vars,
465 if (IS_ERR(obd->obd_proc_entry)) {
466 CERROR("%s: can't register in lprocfs: %ld\n",
467 obd->obd_name, PTR_ERR(obd->obd_proc_entry));
468 obd->obd_proc_entry = NULL;
472 rc = lprocfs_add_vars(obd->obd_proc_entry, lprocfs_osp_obd_vars, obd);
474 CERROR("%s: can't register in lprocfs: %ld\n",
475 obd->obd_name, PTR_ERR(obd->obd_proc_entry));
479 ptlrpc_lprocfs_register_obd(obd);
481 /* for compatibility we link old procfs's OSC entries to osp ones */
482 if (!osp->opd_connect_mdt) {
483 osc_proc_dir = lprocfs_srch(proc_lustre_root, "osc");
485 cfs_proc_dir_entry_t *symlink = NULL;
488 OBD_ALLOC(name, strlen(obd->obd_name) + 1);
492 strcpy(name, obd->obd_name);
493 if (strstr(name, "osc"))
494 symlink = lprocfs_add_symlink(name,
495 osc_proc_dir, "../osp/%s",
497 OBD_FREE(name, strlen(obd->obd_name) + 1);
498 osp->opd_symlink = symlink;