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_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, "%u\n",
295 fid_oid(&osp->opd_pre_used_fid) + 1);
298 static int osp_rd_prealloc_last_id(char *page, char **start, off_t off,
299 int count, int *eof, void *data)
301 struct obd_device *obd = data;
302 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
307 return snprintf(page, count, "%u\n",
308 fid_oid(&osp->opd_pre_last_created_fid));
311 static int osp_rd_prealloc_next_seq(char *page, char **start, off_t off,
312 int count, int *eof, void *data)
314 struct obd_device *obd = data;
315 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
320 return snprintf(page, count, LPX64"\n",
321 fid_seq(&osp->opd_pre_used_fid));
324 static int osp_rd_prealloc_last_seq(char *page, char **start, off_t off,
325 int count, int *eof, void *data)
327 struct obd_device *obd = data;
328 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
333 return snprintf(page, count, LPX64"\n",
334 fid_seq(&osp->opd_pre_last_created_fid));
337 static int osp_rd_prealloc_reserved(char *page, char **start, off_t off,
338 int count, int *eof, void *data)
340 struct obd_device *obd = data;
341 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
346 return snprintf(page, count, LPU64"\n", osp->opd_pre_reserved);
349 static int osp_rd_maxage(char *page, char **start, off_t off,
350 int count, int *eof, void *data)
352 struct obd_device *dev = data;
353 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
359 rc = snprintf(page, count, "%u\n", osp->opd_statfs_maxage);
363 static int osp_wr_maxage(struct file *file, const char *buffer,
364 unsigned long count, void *data)
366 struct obd_device *dev = data;
367 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
373 rc = lprocfs_write_helper(buffer, count, &val);
380 osp->opd_statfs_maxage = val;
385 static int osp_rd_pre_status(char *page, char **start, off_t off,
386 int count, int *eof, void *data)
388 struct obd_device *dev = data;
389 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
395 rc = snprintf(page, count, "%d\n", osp->opd_pre_status);
399 static int osp_rd_destroys_in_flight(char *page, char **start, off_t off,
400 int count, int *eof, void *data)
402 struct obd_device *dev = data;
403 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
409 * This counter used to determine if OST has space returned.
410 * Now we need to wait for the following:
411 * - sync changes are zero - no llog records
412 * - sync in progress are zero - no RPCs in flight
414 return snprintf(page, count, "%lu\n",
415 osp->opd_syn_rpc_in_progress + osp->opd_syn_changes);
418 static int osp_rd_old_sync_processed(char *page, char **start, off_t off,
419 int count, int *eof, void *data)
421 struct obd_device *dev = data;
422 struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
428 rc = snprintf(page, count, "%d\n", osp->opd_syn_prev_done);
432 static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
433 { "uuid", lprocfs_rd_uuid, 0, 0 },
434 { "ping", 0, lprocfs_wr_ping, 0, 0, 0222 },
435 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
436 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
437 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
438 { "active", osp_rd_active, osp_wr_active, 0 },
439 { "max_rpcs_in_flight", osp_rd_max_rpcs_in_flight,
440 osp_wr_max_rpcs_in_flight, 0 },
441 { "max_rpcs_in_progress", osp_rd_max_rpcs_in_prog,
442 osp_wr_max_rpcs_in_prog, 0 },
443 { "create_count", osp_rd_create_count,
444 osp_wr_create_count, 0 },
445 { "max_create_count", osp_rd_max_create_count,
446 osp_wr_max_create_count, 0 },
447 { "prealloc_next_id", osp_rd_prealloc_next_id, 0, 0 },
448 { "prealloc_next_seq", osp_rd_prealloc_next_seq, 0, 0 },
449 { "prealloc_last_id", osp_rd_prealloc_last_id, 0, 0 },
450 { "prealloc_last_seq", osp_rd_prealloc_last_seq, 0, 0 },
451 { "prealloc_reserved", osp_rd_prealloc_reserved, 0, 0 },
452 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
453 { "import", lprocfs_rd_import, lprocfs_wr_import, 0 },
454 { "state", lprocfs_rd_state, 0, 0 },
455 { "maxage", osp_rd_maxage, osp_wr_maxage, 0 },
456 { "prealloc_status", osp_rd_pre_status, 0, 0 },
457 { "sync_changes", osp_rd_syn_changes, 0, 0 },
458 { "sync_in_flight", osp_rd_syn_in_flight, 0, 0 },
459 { "sync_in_progress", osp_rd_syn_in_prog, 0, 0 },
460 { "old_sync_processed", osp_rd_old_sync_processed, 0, 0 },
462 /* for compatibility reasons */
463 { "destroys_in_flight", osp_rd_destroys_in_flight, 0, 0 },
467 static struct lprocfs_vars lprocfs_osp_osd_vars[] = {
468 { "blocksize", lprocfs_dt_rd_blksize, 0, 0 },
469 { "kbytestotal", lprocfs_dt_rd_kbytestotal, 0, 0 },
470 { "kbytesfree", lprocfs_dt_rd_kbytesfree, 0, 0 },
471 { "kbytesavail", lprocfs_dt_rd_kbytesavail, 0, 0 },
472 { "filestotal", lprocfs_dt_rd_filestotal, 0, 0 },
473 { "filesfree", lprocfs_dt_rd_filesfree, 0, 0 },
477 static struct lprocfs_vars lprocfs_osp_module_vars[] = {
478 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
482 void lprocfs_osp_init_vars(struct lprocfs_static_vars *lvars)
484 lvars->module_vars = lprocfs_osp_module_vars;
485 lvars->obd_vars = lprocfs_osp_obd_vars;
488 void osp_lprocfs_init(struct osp_device *osp)
490 struct obd_device *obd = osp->opd_obd;
491 struct proc_dir_entry *osc_proc_dir;
494 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
495 obd->obd_type->typ_procroot,
496 lprocfs_osp_osd_vars,
498 if (IS_ERR(obd->obd_proc_entry)) {
499 CERROR("%s: can't register in lprocfs: %ld\n",
500 obd->obd_name, PTR_ERR(obd->obd_proc_entry));
501 obd->obd_proc_entry = NULL;
505 rc = lprocfs_add_vars(obd->obd_proc_entry, lprocfs_osp_obd_vars, obd);
507 CERROR("%s: can't register in lprocfs: %ld\n",
508 obd->obd_name, PTR_ERR(obd->obd_proc_entry));
512 ptlrpc_lprocfs_register_obd(obd);
514 /* for compatibility we link old procfs's OSC entries to osp ones */
515 if (!osp->opd_connect_mdt) {
516 osc_proc_dir = lprocfs_srch(proc_lustre_root, "osc");
518 cfs_proc_dir_entry_t *symlink = NULL;
521 OBD_ALLOC(name, strlen(obd->obd_name) + 1);
525 strcpy(name, obd->obd_name);
526 if (strstr(name, "osc"))
527 symlink = lprocfs_add_symlink(name,
528 osc_proc_dir, "../osp/%s",
530 OBD_FREE(name, strlen(obd->obd_name) + 1);
531 osp->opd_symlink = symlink;