Whamcloud - gitweb
b=15936 Unified target cleanups v2
[fs/lustre-release.git] / lustre / mds / lproc_mds.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #define DEBUG_SUBSYSTEM S_CLASS
37
38 #include <linux/version.h>
39 #include <asm/statfs.h>
40 #include <obd.h>
41 #include <obd_class.h>
42 #include <lprocfs_status.h>
43 #include "mds_internal.h"
44
45 #ifdef LPROCFS
46 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
47                                  int *eof, void *data)
48 {
49         struct obd_device* obd = (struct obd_device *)data;
50
51         LASSERT(obd != NULL);
52         LASSERT(obd->u.obt.obt_vfsmnt->mnt_devname);
53         *eof = 1;
54
55         return snprintf(page, count, "%s\n",obd->u.obt.obt_vfsmnt->mnt_devname);
56 }
57
58 static int lprocfs_mds_rd_evictostnids(char *page, char **start, off_t off,
59                                        int count, int *eof, void *data)
60 {
61         struct obd_device* obd = (struct obd_device *)data;
62
63         LASSERT(obd != NULL);
64
65         return snprintf(page, count, "%d\n", obd->u.mds.mds_evict_ost_nids);
66 }
67
68 static int lprocfs_mds_wr_evictostnids(struct file *file, const char *buffer,
69                                        unsigned long count, void *data)
70 {
71         struct obd_device *obd = data;
72         int val, rc;
73
74         rc = lprocfs_write_helper(buffer, count, &val);
75         if (rc)
76                 return rc;
77
78         obd->u.mds.mds_evict_ost_nids = !!val;
79
80         return count;
81 }
82
83 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
84                                        unsigned long count, void *data)
85 {
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;
90         int rc;
91
92         sscanf(buffer, "%40s", tmpbuf);
93
94         if (strncmp(tmpbuf, "nid:", 4) != 0)
95                 return lprocfs_wr_evict_client(file, buffer, count, data);
96
97         set = ptlrpc_prep_set();
98         if (!set)
99                 return -ENOMEM;
100
101         if (obd->u.mds.mds_evict_ost_nids) {
102                 rc = obd_set_info_async(mds->mds_lov_exp,
103                                         sizeof(KEY_EVICT_BY_NID),
104                                         KEY_EVICT_BY_NID, strlen(tmpbuf + 4) + 1,
105                                         tmpbuf + 4, set);
106                 if (rc)
107                         CERROR("Failed to evict nid %s from OSTs: rc %d\n",
108                                tmpbuf + 4, rc);
109
110                 ptlrpc_check_set(NULL, set);
111         }
112
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());
116         LPROCFS_EXIT();
117
118         obd_export_evict_by_nid(obd, tmpbuf+4);
119
120
121         rc = ptlrpc_set_wait(set);
122         if (rc)
123                 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
124                        rc);
125
126         LPROCFS_ENTRY();
127         class_decref(obd,  __FUNCTION__, cfs_current());
128
129         ptlrpc_set_destroy(set);
130         return count;
131 }
132
133 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
134                                  unsigned long count, void *data)
135 {
136         struct obd_device *obd = data;
137         struct mds_obd *mds = &obd->u.mds;
138         char kernbuf[20], *end;
139         unsigned long diff = 0;
140
141         if (count > (sizeof(kernbuf) - 1))
142                 return -EINVAL;
143
144         if (cfs_copy_from_user(kernbuf, buffer, count))
145                 return -EFAULT;
146
147         kernbuf[count] = '\0';
148
149         diff = simple_strtoul(kernbuf, &end, 0);
150         if (kernbuf == end)
151                 return -EINVAL;
152
153         mds->mds_atime_diff = diff;
154         return count;
155 }
156
157 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
158                                  int count, int *eof, void *data)
159 {
160         struct obd_device *obd = data;
161         struct mds_obd *mds = &obd->u.mds;
162
163         *eof = 1;
164         return snprintf(page, count, "%lu\n", mds->mds_atime_diff);
165 }
166
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 },
184         { 0 }
185 };
186
187 struct lprocfs_vars lprocfs_mds_module_vars[] = {
188         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
189         { 0 }
190 };
191
192 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
193         { "uuid",         lprocfs_rd_uuid,        0, 0 },
194         { 0 }
195 };
196
197 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
198         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
199         { 0 }
200 };
201
202 void mds_counter_incr(struct obd_export *exp, int opcode)
203 {
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);
208
209 }
210
211 void mds_stats_counter_init(struct lprocfs_stats *stats)
212 {
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");
223 }
224
225 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars)
226 {
227     lvars->module_vars = lprocfs_mds_module_vars;
228     lvars->obd_vars = lprocfs_mds_obd_vars;
229 }
230
231 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
232 {
233     lvars->module_vars = lprocfs_mdt_module_vars;
234     lvars->obd_vars = lprocfs_mdt_obd_vars;
235 }
236 #endif