Whamcloud - gitweb
Branch b1_4_mountconf
[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  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
9  *   You may have signed or agreed to another license before downloading
10  *   this software.  If so, you are bound by the terms and conditions
11  *   of that agreement, and the following does not apply to you.  See the
12  *   LICENSE file included with this distribution for more information.
13  *
14  *   If you did not agree to a different license, then this copy of Lustre
15  *   is open source software; you can redistribute it and/or modify it
16  *   under the terms of version 2 of the GNU General Public License as
17  *   published by the Free Software Foundation.
18  *
19  *   In either case, Lustre is distributed in the hope that it will be
20  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   license text for more details.
23  *
24  */
25 #define DEBUG_SUBSYSTEM S_CLASS
26
27 #include <linux/version.h>
28 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
29 #include <asm/statfs.h>
30 #endif
31 #include <linux/obd.h>
32 #include <linux/obd_class.h>
33 #include <linux/lprocfs_status.h>
34 #include "mds_internal.h"
35
36 #ifdef LPROCFS
37 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
38                                  int *eof, void *data)
39 {
40         struct obd_device* obd = (struct obd_device *)data;
41
42         LASSERT(obd != NULL);
43         LASSERT(obd->u.mds.mds_vfsmnt->mnt_devname);
44         *eof = 1;
45
46         return snprintf(page, count, "%s\n",obd->u.mds.mds_vfsmnt->mnt_devname);
47 }
48
49 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
50                                        unsigned long count, void *data)
51 {
52         struct obd_device *obd = data;
53         struct mds_obd *mds = &obd->u.mds;
54         char tmpbuf[sizeof(struct obd_uuid)];
55         int rc;
56
57         sscanf(buffer, "%40s", tmpbuf);
58
59         if (strncmp(tmpbuf, "nid:", 4) != 0)
60                 return lprocfs_wr_evict_client(file, buffer, count, data);
61
62         obd_export_evict_by_nid(obd, tmpbuf+4);
63
64         rc = obd_set_info(mds->mds_osc_exp, strlen("evict_by_nid"),
65                           "evict_by_nid", strlen(tmpbuf + 4) + 1, tmpbuf + 4);
66         if (rc)
67                 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
68                        rc);
69
70         return count;
71 }
72
73 static int lprocfs_wr_group_info(struct file *file, const char *buffer,
74                                  unsigned long count, void *data)
75 {
76         struct obd_device *obd = data;
77         struct mds_obd *mds = &obd->u.mds;
78         struct mds_grp_downcall_data sparam, *param = &sparam;
79         int size = 0, rc = count;
80
81         if (count < sizeof(param)) {
82                 CERROR("%s: invalid data size %lu\n", obd->obd_name, count);
83                 return count;
84         }
85
86         if (copy_from_user(param, buffer, sizeof(*param)) ||
87             param->mgd_magic != MDS_GRP_DOWNCALL_MAGIC) {
88                 CERROR("%s: MDS group downcall bad params\n", obd->obd_name);
89                 return count;
90         }
91
92         if (param->mgd_ngroups > NGROUPS_MAX) {
93                 CWARN("%s: uid %u groups %d more than maximum %d\n",
94                       obd->obd_name, param->mgd_uid, param->mgd_ngroups,
95                       NGROUPS_MAX);
96                 param->mgd_ngroups = NGROUPS_MAX;
97         }
98
99         if (param->mgd_ngroups > 0) {
100                 size = offsetof(struct mds_grp_downcall_data,
101                                 mgd_groups[param->mgd_ngroups]);
102                 OBD_ALLOC(param, size);
103                 if (!param) {
104                         CERROR("%s: fail to alloc %d bytes for uid %u"
105                                " with %d groups\n", obd->obd_name, size,
106                                sparam.mgd_uid, sparam.mgd_ngroups);
107                         param = &sparam;
108                         param->mgd_ngroups = 0;
109                 } else if (copy_from_user(param, buffer, size)) {
110                         CERROR("%s: uid %u bad supplementary group data\n",
111                                obd->obd_name, sparam.mgd_uid);
112                         OBD_FREE(param, size);
113                         param = &sparam;
114                         param->mgd_ngroups = 0;
115                 }
116         }
117         rc = upcall_cache_downcall(mds->mds_group_hash, param->mgd_err,
118                                    param->mgd_uid, param->mgd_gid,
119                                    param->mgd_ngroups, param->mgd_groups);
120
121         if (param && param != &sparam)
122                 OBD_FREE(param, size);
123
124         return rc;
125 }
126
127 static int lprocfs_rd_group_expire(char *page, char **start, off_t off,
128                                    int count, int *eof, void *data)
129 {
130         struct obd_device *obd = data;
131
132         *eof = 1;
133         return snprintf(page, count, "%lu\n",
134                         obd->u.mds.mds_group_hash->uc_entry_expire / HZ);
135 }
136
137 static int lprocfs_wr_group_expire(struct file *file, const char *buffer,
138                                    unsigned long count, void *data)
139 {
140         struct obd_device *obd = data;
141         int val, rc;
142
143         rc = lprocfs_write_helper(buffer, count, &val);
144         if (rc)
145                 return rc;
146
147         if (val > 5)
148                 obd->u.mds.mds_group_hash->uc_entry_expire = val * HZ;
149         else
150                 CERROR("invalid expire time %u for group cache\n", val);
151
152         return count;
153 }
154
155 static int lprocfs_rd_group_acquire_expire(char *page, char **start, off_t off,
156                                            int count, int *eof, void *data)
157 {
158         struct obd_device *obd = data;
159
160         *eof = 1;
161         return snprintf(page, count, "%lu\n",
162                         obd->u.mds.mds_group_hash->uc_acquire_expire / HZ);
163 }
164
165 static int lprocfs_wr_group_acquire_expire(struct file *file,const char *buffer,
166                                            unsigned long count, void *data)
167 {
168         struct obd_device *obd = data;
169         int val, rc = 0;
170
171         rc = lprocfs_write_helper(buffer, count, &val);
172         if (rc)
173                 return rc;
174
175         if (val > 2)
176                 obd->u.mds.mds_group_hash->uc_acquire_expire = val * HZ;
177
178         return count;
179 }
180
181 static int lprocfs_rd_group_upcall(char *page, char **start, off_t off,
182                                    int count, int *eof, void *data)
183 {
184         struct obd_device *obd = data;
185
186         *eof = 1;
187         return snprintf(page, count, "%s\n",
188                         obd->u.mds.mds_group_hash->uc_upcall);
189 }
190
191 static int lprocfs_wr_group_upcall(struct file *file, const char *buffer,
192                                    unsigned long count, void *data)
193 {
194         struct obd_device *obd = data;
195         struct upcall_cache *hash = obd->u.mds.mds_group_hash;
196         char kernbuf[UC_CACHE_UPCALL_MAXPATH] = { '\0' };
197
198         if (count >= UC_CACHE_UPCALL_MAXPATH) {
199                 CERROR("%s: group upcall too long\n", obd->obd_name);
200                 return -EINVAL;
201         }
202
203         if (copy_from_user(kernbuf, buffer,
204                            min(count, UC_CACHE_UPCALL_MAXPATH - 1)))
205                 return -EFAULT;
206
207         /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
208         sscanf(kernbuf, "%s", hash->uc_upcall);
209
210         if (strcmp(hash->uc_name, obd->obd_name) != 0)
211                 CWARN("%s: write to upcall name %s for MDS %s\n",
212                       obd->obd_name, hash->uc_upcall, obd->obd_name);
213         CWARN("%s: group upcall set to %s\n", obd->obd_name, hash->uc_upcall);
214
215         return count;
216 }
217
218 static int lprocfs_wr_group_flush(struct file *file, const char *buffer,
219                                   unsigned long count, void *data)
220 {
221         struct obd_device *obd = data;
222
223         upcall_cache_flush_idle(obd->u.mds.mds_group_hash);
224         return count;
225 }
226
227 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
228         { "uuid",            lprocfs_rd_uuid,        0, 0 },
229         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
230         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
231         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
232         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
233         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
234         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
235         { "fstype",          lprocfs_rd_fstype,      0, 0 },
236         { "mntdev",          lprocfs_mds_rd_mntdev,  0, 0 },
237         { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
238         { "evict_client",    0,                lprocfs_mds_wr_evict_client, 0 },
239         { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
240 #ifdef HAVE_QUOTA_SUPPORT
241         { "quota_bunit_sz",  lprocfs_mds_rd_bunit, lprocfs_mds_wr_bunit, 0 },
242         { "quota_btune_sz",  lprocfs_mds_rd_btune, lprocfs_mds_wr_btune, 0 },
243         { "quota_iunit_sz",  lprocfs_mds_rd_iunit, lprocfs_mds_wr_iunit, 0 },
244         { "quota_itune_sz",  lprocfs_mds_rd_itune, lprocfs_mds_wr_itune, 0 },
245 #endif
246         { "group_expire_interval", lprocfs_rd_group_expire,
247                              lprocfs_wr_group_expire, 0},
248         { "group_acquire_expire", lprocfs_rd_group_acquire_expire,
249                              lprocfs_wr_group_acquire_expire, 0},
250         { "group_upcall",    lprocfs_rd_group_upcall,
251                              lprocfs_wr_group_upcall, 0},
252         { "group_flush", 0,  lprocfs_wr_group_flush, 0},
253         { "group_info", 0,   lprocfs_wr_group_info, 0 },
254         { 0 }
255 };
256
257 struct lprocfs_vars lprocfs_mds_module_vars[] = {
258         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
259         { 0 }
260 };
261
262 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
263         { "uuid",         lprocfs_rd_uuid,        0, 0 },
264         { 0 }
265 };
266
267 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
268         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
269         { 0 }
270 };
271
272 LPROCFS_INIT_VARS(mds, lprocfs_mds_module_vars, lprocfs_mds_obd_vars);
273 LPROCFS_INIT_VARS(mdt, lprocfs_mdt_module_vars, lprocfs_mdt_obd_vars);
274 #endif