1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_CLASS
38 #include <linux/version.h>
39 #include <asm/statfs.h>
41 #include <obd_class.h>
42 #include <lprocfs_status.h>
43 #include "mds_internal.h"
46 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
49 struct obd_device* obd = (struct obd_device *)data;
52 LASSERT(obd->u.mds.mds_vfsmnt->mnt_devname);
55 return snprintf(page, count, "%s\n",obd->u.mds.mds_vfsmnt->mnt_devname);
58 static int lprocfs_mds_rd_evictostnids(char *page, char **start, off_t off,
59 int count, int *eof, void *data)
61 struct obd_device* obd = (struct obd_device *)data;
65 return snprintf(page, count, "%d\n", obd->u.mds.mds_evict_ost_nids);
68 static int lprocfs_mds_wr_evictostnids(struct file *file, const char *buffer,
69 unsigned long count, void *data)
71 struct obd_device *obd = data;
74 rc = lprocfs_write_helper(buffer, count, &val);
78 obd->u.mds.mds_evict_ost_nids = !!val;
83 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
84 unsigned long count, void *data)
86 struct obd_device *obd = data;
87 struct mds_obd *mds = &obd->u.mds;
88 char tmpbuf[sizeof(struct obd_uuid)];
89 struct ptlrpc_request_set *set;
92 sscanf(buffer, "%40s", tmpbuf);
94 if (strncmp(tmpbuf, "nid:", 4) != 0)
95 return lprocfs_wr_evict_client(file, buffer, count, data);
97 set = ptlrpc_prep_set();
101 if (obd->u.mds.mds_evict_ost_nids) {
102 rc = obd_set_info_async(mds->mds_osc_exp,
103 sizeof(KEY_EVICT_BY_NID),
104 KEY_EVICT_BY_NID, strlen(tmpbuf + 4) + 1,
107 CERROR("Failed to evict nid %s from OSTs: rc %d\n",
110 ptlrpc_check_set(NULL, set);
113 /* See the comments in function lprocfs_wr_evict_client()
114 * in ptlrpc/lproc_ptlrpc.c for details. - jay */
115 class_incref(obd, __FUNCTION__, cfs_current());
118 obd_export_evict_by_nid(obd, tmpbuf+4);
121 rc = ptlrpc_set_wait(set);
123 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
127 class_decref(obd, __FUNCTION__, cfs_current());
129 ptlrpc_set_destroy(set);
133 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
134 unsigned long count, void *data)
136 struct obd_device *obd = data;
137 struct mds_obd *mds = &obd->u.mds;
138 char kernbuf[20], *end;
139 unsigned long diff = 0;
141 if (count > (sizeof(kernbuf) - 1))
144 if (copy_from_user(kernbuf, buffer, count))
147 kernbuf[count] = '\0';
149 diff = simple_strtoul(kernbuf, &end, 0);
153 mds->mds_atime_diff = diff;
157 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
158 int count, int *eof, void *data)
160 struct obd_device *obd = data;
161 struct mds_obd *mds = &obd->u.mds;
164 return snprintf(page, count, "%lu\n", mds->mds_atime_diff);
167 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
168 { "uuid", lprocfs_rd_uuid, 0, 0 },
169 { "blocksize", lprocfs_rd_blksize, 0, 0 },
170 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
171 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
172 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
173 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
174 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
175 { "fstype", lprocfs_rd_fstype, 0, 0 },
176 { "mntdev", lprocfs_mds_rd_mntdev, 0, 0 },
177 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
178 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
179 { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
180 { "evict_ost_nids", lprocfs_mds_rd_evictostnids,
181 lprocfs_mds_wr_evictostnids, 0 },
182 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
183 { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
187 struct lprocfs_vars lprocfs_mds_module_vars[] = {
188 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
192 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
193 { "uuid", lprocfs_rd_uuid, 0, 0 },
197 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
198 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
202 void mds_counter_incr(struct obd_export *exp, int opcode)
204 if (exp->exp_obd && exp->exp_obd->obd_stats)
205 lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
206 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
207 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
211 void mds_stats_counter_init(struct lprocfs_stats *stats)
213 lprocfs_counter_init(stats, LPROC_MDS_OPEN, 0, "open", "reqs");
214 lprocfs_counter_init(stats, LPROC_MDS_CLOSE, 0, "close", "reqs");
215 lprocfs_counter_init(stats, LPROC_MDS_MKNOD, 0, "mknod", "reqs");
216 lprocfs_counter_init(stats, LPROC_MDS_LINK, 0, "link", "reqs");
217 lprocfs_counter_init(stats, LPROC_MDS_UNLINK, 0, "unlink", "reqs");
218 lprocfs_counter_init(stats, LPROC_MDS_MKDIR, 0, "mkdir", "reqs");
219 lprocfs_counter_init(stats, LPROC_MDS_RMDIR, 0, "rmdir", "reqs");
220 lprocfs_counter_init(stats, LPROC_MDS_RENAME, 0, "rename", "reqs");
221 lprocfs_counter_init(stats, LPROC_MDS_GETXATTR, 0, "getxattr", "reqs");
222 lprocfs_counter_init(stats, LPROC_MDS_SETXATTR, 0, "setxattr", "reqs");
225 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars)
227 lvars->module_vars = lprocfs_mds_module_vars;
228 lvars->obd_vars = lprocfs_mds_obd_vars;
231 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
233 lvars->module_vars = lprocfs_mdt_module_vars;
234 lvars->obd_vars = lprocfs_mdt_obd_vars;