Whamcloud - gitweb
LU-1146 build: batch update copyright messages
[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  * Copyright (c) 2012, Whamcloud, Inc.
33  */
34 /*
35  * This file is part of Lustre, http://www.lustre.org/
36  * Lustre is a trademark of Sun Microsystems, Inc.
37  */
38 #define DEBUG_SUBSYSTEM S_CLASS
39
40 #include <linux/version.h>
41 #include <asm/statfs.h>
42 #include <obd.h>
43 #include <obd_class.h>
44 #include <lprocfs_status.h>
45 #include "mds_internal.h"
46
47 #ifdef LPROCFS
48 static int lprocfs_mds_rd_evictostnids(char *page, char **start, off_t off,
49                                        int count, int *eof, void *data)
50 {
51         struct obd_device* obd = (struct obd_device *)data;
52
53         LASSERT(obd != NULL);
54
55         return snprintf(page, count, "%d\n", obd->u.mds.mds_evict_ost_nids);
56 }
57
58 static int lprocfs_mds_wr_evictostnids(struct file *file, const char *buffer,
59                                        unsigned long count, void *data)
60 {
61         struct obd_device *obd = data;
62         int val, rc;
63
64         rc = lprocfs_write_helper(buffer, count, &val);
65         if (rc)
66                 return rc;
67
68         obd->u.mds.mds_evict_ost_nids = !!val;
69
70         return count;
71 }
72
73 #define BUFLEN (UUID_MAX + 4)
74
75 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
76                                        unsigned long count, void *data)
77 {
78         struct ptlrpc_request_set *set;
79         struct obd_device         *obd = data;
80         struct mds_obd            *mds = &obd->u.mds;
81         char                      *kbuf;
82         char                      *tmpbuf;
83         int                        rc;
84
85         OBD_ALLOC(kbuf, BUFLEN);
86         if (kbuf == NULL)
87                 return -ENOMEM;
88
89         /*
90          * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
91          * bytes into kbuf, to ensure that the string is NUL-terminated.
92          * UUID_MAX should include a trailing NUL already.
93          */
94         if (cfs_copy_from_user(kbuf, buffer,
95                                min_t(unsigned long, BUFLEN - 1, count))) {
96                 count = -EFAULT;
97                 goto out;
98         }
99         tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
100
101         if (strncmp(tmpbuf, "nid:", 4) != 0) {
102                 count = lprocfs_wr_evict_client(file, buffer, count, data);
103                 goto out;
104         }
105
106         set = ptlrpc_prep_set();
107         if (set == NULL) {
108                 count = -ENOMEM;
109                 goto out;
110         }
111
112         if (obd->u.mds.mds_evict_ost_nids) {
113                 rc = obd_set_info_async(mds->mds_lov_exp,
114                                         sizeof(KEY_EVICT_BY_NID),
115                                         KEY_EVICT_BY_NID, strlen(tmpbuf + 4) + 1,
116                                         tmpbuf + 4, set);
117                 if (rc)
118                         CERROR("Failed to evict nid %s from OSTs: rc %d\n",
119                                tmpbuf + 4, rc);
120
121                 ptlrpc_check_set(NULL, set);
122         }
123
124         /* See the comments in function lprocfs_wr_evict_client()
125          * in ptlrpc/lproc_ptlrpc.c for details. - jay */
126         class_incref(obd, __FUNCTION__, cfs_current());
127         LPROCFS_EXIT();
128
129         obd_export_evict_by_nid(obd, tmpbuf + 4);
130
131
132         rc = ptlrpc_set_wait(set);
133         if (rc)
134                 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
135                        rc);
136
137         LPROCFS_ENTRY();
138         class_decref(obd,  __FUNCTION__, cfs_current());
139
140         ptlrpc_set_destroy(set);
141 out:
142         OBD_FREE(kbuf, BUFLEN);
143         return count;
144 }
145
146 #undef BUFLEN
147
148 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
149                                  unsigned long count, void *data)
150 {
151         struct obd_device *obd = data;
152         struct mds_obd *mds = &obd->u.mds;
153         char kernbuf[20], *end;
154         unsigned long diff = 0;
155
156         if (count > (sizeof(kernbuf) - 1))
157                 return -EINVAL;
158
159         if (cfs_copy_from_user(kernbuf, buffer, count))
160                 return -EFAULT;
161
162         kernbuf[count] = '\0';
163
164         diff = simple_strtoul(kernbuf, &end, 0);
165         if (kernbuf == end)
166                 return -EINVAL;
167
168         mds->mds_atime_diff = diff;
169         return count;
170 }
171
172 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
173                                  int count, int *eof, void *data)
174 {
175         struct obd_device *obd = data;
176         struct mds_obd *mds = &obd->u.mds;
177
178         *eof = 1;
179         return snprintf(page, count, "%lu\n", mds->mds_atime_diff);
180 }
181
182 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
183         { "uuid",            lprocfs_rd_uuid,        0, 0 },
184         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
185         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
186         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
187         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
188         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
189         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
190         { "fstype",          lprocfs_rd_fstype,      0, 0 },
191         { "mntdev",          lprocfs_obd_rd_mntdev,  0, 0 },
192         { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
193         { "hash_stats",      lprocfs_obd_rd_hash,    0, 0 },
194         { "evict_client",    0,                lprocfs_mds_wr_evict_client, 0 },
195         { "evict_ost_nids",  lprocfs_mds_rd_evictostnids,
196                                                lprocfs_mds_wr_evictostnids, 0 },
197         { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
198         { "atime_diff",      lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
199         { 0 }
200 };
201
202 struct lprocfs_vars lprocfs_mds_module_vars[] = {
203         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
204         { 0 }
205 };
206
207 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
208         { "uuid",         lprocfs_rd_uuid,        0, 0 },
209         { 0 }
210 };
211
212 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars)
213 {
214     lvars->module_vars = lprocfs_mds_module_vars;
215     lvars->obd_vars = lprocfs_mds_obd_vars;
216 }
217
218 #endif