Whamcloud - gitweb
b=21420 Add mds/mgs stats to HEAD
[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 (c) 2002, 2010, Oracle and/or its affiliates. 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_evictostnids(char *page, char **start, off_t off,
47                                        int count, int *eof, void *data)
48 {
49         struct obd_device* obd = (struct obd_device *)data;
50
51         LASSERT(obd != NULL);
52
53         return snprintf(page, count, "%d\n", obd->u.mds.mds_evict_ost_nids);
54 }
55
56 static int lprocfs_mds_wr_evictostnids(struct file *file, const char *buffer,
57                                        unsigned long count, void *data)
58 {
59         struct obd_device *obd = data;
60         int val, rc;
61
62         rc = lprocfs_write_helper(buffer, count, &val);
63         if (rc)
64                 return rc;
65
66         obd->u.mds.mds_evict_ost_nids = !!val;
67
68         return count;
69 }
70
71 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
72                                        unsigned long count, void *data)
73 {
74         struct obd_device *obd = data;
75         struct mds_obd *mds = &obd->u.mds;
76         char tmpbuf[sizeof(struct obd_uuid)];
77         struct ptlrpc_request_set *set;
78         int rc;
79
80         sscanf(buffer, "%40s", tmpbuf);
81
82         if (strncmp(tmpbuf, "nid:", 4) != 0)
83                 return lprocfs_wr_evict_client(file, buffer, count, data);
84
85         set = ptlrpc_prep_set();
86         if (!set)
87                 return -ENOMEM;
88
89         if (obd->u.mds.mds_evict_ost_nids) {
90                 rc = obd_set_info_async(mds->mds_lov_exp,
91                                         sizeof(KEY_EVICT_BY_NID),
92                                         KEY_EVICT_BY_NID, strlen(tmpbuf + 4) + 1,
93                                         tmpbuf + 4, set);
94                 if (rc)
95                         CERROR("Failed to evict nid %s from OSTs: rc %d\n",
96                                tmpbuf + 4, rc);
97
98                 ptlrpc_check_set(NULL, set);
99         }
100
101         /* See the comments in function lprocfs_wr_evict_client()
102          * in ptlrpc/lproc_ptlrpc.c for details. - jay */
103         class_incref(obd, __FUNCTION__, cfs_current());
104         LPROCFS_EXIT();
105
106         obd_export_evict_by_nid(obd, tmpbuf+4);
107
108
109         rc = ptlrpc_set_wait(set);
110         if (rc)
111                 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
112                        rc);
113
114         LPROCFS_ENTRY();
115         class_decref(obd,  __FUNCTION__, cfs_current());
116
117         ptlrpc_set_destroy(set);
118         return count;
119 }
120
121 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
122                                  unsigned long count, void *data)
123 {
124         struct obd_device *obd = data;
125         struct mds_obd *mds = &obd->u.mds;
126         char kernbuf[20], *end;
127         unsigned long diff = 0;
128
129         if (count > (sizeof(kernbuf) - 1))
130                 return -EINVAL;
131
132         if (cfs_copy_from_user(kernbuf, buffer, count))
133                 return -EFAULT;
134
135         kernbuf[count] = '\0';
136
137         diff = simple_strtoul(kernbuf, &end, 0);
138         if (kernbuf == end)
139                 return -EINVAL;
140
141         mds->mds_atime_diff = diff;
142         return count;
143 }
144
145 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
146                                  int count, int *eof, void *data)
147 {
148         struct obd_device *obd = data;
149         struct mds_obd *mds = &obd->u.mds;
150
151         *eof = 1;
152         return snprintf(page, count, "%lu\n", mds->mds_atime_diff);
153 }
154
155 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
156         { "uuid",            lprocfs_rd_uuid,        0, 0 },
157         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
158         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
159         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
160         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
161         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
162         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
163         { "fstype",          lprocfs_rd_fstype,      0, 0 },
164         { "mntdev",          lprocfs_obd_rd_mntdev,  0, 0 },
165         { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
166         { "hash_stats",      lprocfs_obd_rd_hash,    0, 0 },
167         { "evict_client",    0,                lprocfs_mds_wr_evict_client, 0 },
168         { "evict_ost_nids",  lprocfs_mds_rd_evictostnids,
169                                                lprocfs_mds_wr_evictostnids, 0 },
170         { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
171         { "atime_diff",      lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
172         { 0 }
173 };
174
175 struct lprocfs_vars lprocfs_mds_module_vars[] = {
176         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
177         { 0 }
178 };
179
180 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
181         { "uuid",         lprocfs_rd_uuid,        0, 0 },
182         { 0 }
183 };
184
185 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars)
186 {
187     lvars->module_vars = lprocfs_mds_module_vars;
188     lvars->obd_vars = lprocfs_mds_obd_vars;
189 }
190
191 #endif