Whamcloud - gitweb
LU-1347 style: removes obsolete EXPORT_SYMTAB macros
[fs/lustre-release.git] / lustre / mds / lproc_mds.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Whamcloud, Inc.
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 #define BUFLEN (UUID_MAX + 4)
72
73 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
74                                        unsigned long count, void *data)
75 {
76         struct ptlrpc_request_set *set;
77         struct obd_device         *obd = data;
78         struct mds_obd            *mds = &obd->u.mds;
79         char                      *kbuf;
80         char                      *tmpbuf;
81         int                        rc;
82
83         OBD_ALLOC(kbuf, BUFLEN);
84         if (kbuf == NULL)
85                 return -ENOMEM;
86
87         /*
88          * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
89          * bytes into kbuf, to ensure that the string is NUL-terminated.
90          * UUID_MAX should include a trailing NUL already.
91          */
92         if (cfs_copy_from_user(kbuf, buffer,
93                                min_t(unsigned long, BUFLEN - 1, count))) {
94                 count = -EFAULT;
95                 goto out;
96         }
97         tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
98
99         if (strncmp(tmpbuf, "nid:", 4) != 0) {
100                 count = lprocfs_wr_evict_client(file, buffer, count, data);
101                 goto out;
102         }
103
104         set = ptlrpc_prep_set();
105         if (set == NULL) {
106                 count = -ENOMEM;
107                 goto out;
108         }
109
110         if (obd->u.mds.mds_evict_ost_nids) {
111                 rc = obd_set_info_async(NULL, mds->mds_lov_exp,
112                                         sizeof(KEY_EVICT_BY_NID),
113                                         KEY_EVICT_BY_NID, strlen(tmpbuf + 4) + 1,
114                                         tmpbuf + 4, set);
115                 if (rc)
116                         CERROR("Failed to evict nid %s from OSTs: rc %d\n",
117                                tmpbuf + 4, rc);
118
119                 ptlrpc_check_set(NULL, set);
120         }
121
122         /* See the comments in function lprocfs_wr_evict_client()
123          * in ptlrpc/lproc_ptlrpc.c for details. - jay */
124         class_incref(obd, __FUNCTION__, cfs_current());
125         LPROCFS_EXIT();
126
127         obd_export_evict_by_nid(obd, tmpbuf + 4);
128
129
130         rc = ptlrpc_set_wait(set);
131         if (rc)
132                 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
133                        rc);
134
135         LPROCFS_ENTRY();
136         class_decref(obd,  __FUNCTION__, cfs_current());
137
138         ptlrpc_set_destroy(set);
139 out:
140         OBD_FREE(kbuf, BUFLEN);
141         return count;
142 }
143
144 #undef BUFLEN
145
146 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
147                                  unsigned long count, void *data)
148 {
149         struct obd_device *obd = data;
150         struct mds_obd *mds = &obd->u.mds;
151         char kernbuf[20], *end;
152         unsigned long diff = 0;
153
154         if (count > (sizeof(kernbuf) - 1))
155                 return -EINVAL;
156
157         if (cfs_copy_from_user(kernbuf, buffer, count))
158                 return -EFAULT;
159
160         kernbuf[count] = '\0';
161
162         diff = simple_strtoul(kernbuf, &end, 0);
163         if (kernbuf == end)
164                 return -EINVAL;
165
166         mds->mds_atime_diff = diff;
167         return count;
168 }
169
170 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
171                                  int count, int *eof, void *data)
172 {
173         struct obd_device *obd = data;
174         struct mds_obd *mds = &obd->u.mds;
175
176         *eof = 1;
177         return snprintf(page, count, "%lu\n", mds->mds_atime_diff);
178 }
179
180 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
181         { "uuid",            lprocfs_rd_uuid,        0, 0 },
182         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
183         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
184         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
185         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
186         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
187         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
188         { "fstype",          lprocfs_rd_fstype,      0, 0 },
189         { "mntdev",          lprocfs_obd_rd_mntdev,  0, 0 },
190         { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
191         { "hash_stats",      lprocfs_obd_rd_hash,    0, 0 },
192         { "evict_client",    0,                lprocfs_mds_wr_evict_client, 0 },
193         { "evict_ost_nids",  lprocfs_mds_rd_evictostnids,
194                                                lprocfs_mds_wr_evictostnids, 0 },
195         { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
196         { "atime_diff",      lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
197         { 0 }
198 };
199
200 struct lprocfs_vars lprocfs_mds_module_vars[] = {
201         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
202         { 0 }
203 };
204
205 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
206         { "uuid",         lprocfs_rd_uuid,        0, 0 },
207         { 0 }
208 };
209
210 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars)
211 {
212     lvars->module_vars = lprocfs_mds_module_vars;
213     lvars->obd_vars = lprocfs_mds_obd_vars;
214 }
215
216 #endif