Whamcloud - gitweb
- one more fid management correctness test.
[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 Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22 #define DEBUG_SUBSYSTEM S_CLASS
23
24 #include <linux/version.h>
25 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 #include <asm/statfs.h>
27 #endif
28 #include <linux/obd.h>
29 #include <linux/obd_class.h>
30 #include <linux/lprocfs_status.h>
31 #include "mds_internal.h"
32
33 #ifndef LPROCFS
34
35 struct lprocfs_vars lprocfs_mds_obd_vars[]  = { {0} };
36 struct lprocfs_vars lprocfs_mds_module_vars[] = { {0} };
37 struct lprocfs_vars lprocfs_mdt_obd_vars[] = { {0} };
38 struct lprocfs_vars lprocfs_mdt_module_vars[] = { {0} };
39
40 #else
41
42 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off,
43                                  int count, int *eof, void *data)
44 {
45         struct obd_device* obd = (struct obd_device *)data;
46
47         LASSERT(obd != NULL);
48         LASSERT(obd->u.mds.mds_vfsmnt->mnt_devname);
49         *eof = 1;
50
51         return snprintf(page, count, "%s\n",
52                         obd->u.mds.mds_vfsmnt->mnt_devname);
53 }
54
55 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
56                                        unsigned long count, void *data)
57 {
58         struct obd_device *obd = data;
59         struct obd_export *doomed_exp = NULL;
60         struct obd_uuid doomed;
61         struct list_head *p;
62         char tmpbuf[sizeof(doomed)];
63
64         sscanf(buffer, "%40s", tmpbuf);
65         obd_str2uuid(&doomed, tmpbuf);
66
67         spin_lock(&obd->obd_dev_lock);
68         list_for_each(p, &obd->obd_exports) {
69                 doomed_exp = list_entry(p, struct obd_export, exp_obd_chain);
70                 if (obd_uuid_equals(&doomed, &doomed_exp->exp_client_uuid)) {
71                         class_export_get(doomed_exp);
72                         break;
73                 }
74                 doomed_exp = NULL;
75         }
76         spin_unlock(&obd->obd_dev_lock);
77
78         if (doomed_exp == NULL) {
79                 CERROR("can't disconnect %s: no export found\n",
80                        doomed.uuid);
81         } else {
82                 CERROR("evicting %s at adminstrative request\n",
83                        doomed.uuid);
84                 ptlrpc_fail_export(doomed_exp);
85                 class_export_put(doomed_exp);
86         }
87         return count;
88 }
89
90 static int lprocfs_mds_wr_config_update(struct file *file, const char *buffer,
91                                         unsigned long count, void *data)
92 {
93         struct obd_device *obd = data;
94         ENTRY;
95
96         RETURN(mds_lov_update_config(obd, 0));
97 }
98
99 static int lprocfs_rd_last_fid(char *page, char **start, off_t off,
100                                unsigned long count, int *eof, void *data)
101 {
102         struct obd_device *obd = (struct obd_device *)data;
103         struct mds_obd *mds = &obd->u.mds;
104         __u64 last_fid;
105
106         down(&mds->mds_last_fid_sem);
107         last_fid = mds->mds_last_fid;
108         up(&mds->mds_last_fid_sem);
109
110         *eof = 1;
111         return snprintf(page, count, LPD64"\n", last_fid);
112 }
113
114 static int lprocfs_rd_group(char *page, char **start, off_t off,
115                             unsigned long count, int *eof, void *data)
116 {
117         struct obd_device *obd = (struct obd_device *)data;
118         struct mds_obd *mds = &obd->u.mds;
119
120         *eof = 1;
121         return snprintf(page, count, LPD64"\n", mds->mds_num);
122 }
123
124 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
125         { "uuid",         lprocfs_rd_uuid,        0, 0 },
126         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
127         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
128         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
129         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
130         { "fstype",       lprocfs_rd_fstype,      0, 0 },
131         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
132         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
133         { "mntdev",       lprocfs_mds_rd_mntdev,  0, 0 },
134         { "last_fid",     lprocfs_rd_last_fid,    0, 0 },
135         { "group",        lprocfs_rd_group,       0, 0 },
136         { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
137         { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
138         { "config_update", 0, lprocfs_mds_wr_config_update, 0 },
139         { "num_exports",  lprocfs_rd_num_exports, 0, 0 },
140         { 0 }
141 };
142
143 /*
144  * group hash proc entries handler
145  */
146 static int lprocfs_wr_group_info(struct file *file, const char *buffer,
147                                  unsigned long count, void *data)
148 {
149         struct {
150                 int             err;
151                 uid_t           uid;
152                 uint32_t        ngroups;
153                 gid_t          *groups;
154         } param;
155         gid_t   gids_local[NGROUPS_SMALL];
156         gid_t  *gids = NULL;
157
158         if (count != sizeof(param)) {
159                 CERROR("invalid data size %lu\n", count);
160                 return count;
161         }
162         if (copy_from_user(&param, buffer, count)) {
163                 CERROR("broken downcall\n");
164                 return count;
165         }
166         if (param.ngroups > NGROUPS_MAX) {
167                 CERROR("%d groups?\n", param.ngroups);
168                 return count;
169         }
170
171         if (param.ngroups <= NGROUPS_SMALL)
172                 gids = gids_local;
173         else {
174                 OBD_ALLOC(gids, param.ngroups * sizeof(gid_t));
175                 if (!gids) {
176                         CERROR("fail to alloc memory for %d gids\n",
177                                 param.ngroups);
178                         return count;
179                 }
180         }
181         if (copy_from_user(gids, param.groups,
182                            param.ngroups * sizeof(gid_t))) {
183                 CERROR("broken downcall\n");
184                 goto out;
185         }
186
187         mds_handle_group_downcall(param.err, param.uid,
188                                   param.ngroups, gids);
189
190 out:
191         if (gids && gids != gids_local)
192                 OBD_FREE(gids, param.ngroups * sizeof(gid_t));
193         return count;
194 }
195
196 static int lprocfs_rd_expire(char *page, char **start, off_t off, int count,
197                              int *eof, void *data)
198 {
199         struct mds_grp_hash *hash = __mds_get_global_group_hash();
200
201         *eof = 1;
202         return snprintf(page, count, "%d\n", hash->gh_entry_expire);
203 }
204
205 static int lprocfs_wr_expire(struct file *file, const char *buffer,
206                              unsigned long count, void *data)
207 {
208         struct mds_grp_hash *hash = __mds_get_global_group_hash();
209         char buf[32];
210
211         if (copy_from_user(buf, buffer, min(count, 32UL)))
212                 return count;
213         buf[31] = 0;
214         sscanf(buf, "%d", &hash->gh_entry_expire);
215         return count;
216 }
217
218 static int lprocfs_rd_ac_expire(char *page, char **start, off_t off, int count,
219                                 int *eof, void *data)
220 {
221         struct mds_grp_hash *hash = __mds_get_global_group_hash();
222
223         *eof = 1;
224         return snprintf(page, count, "%d\n", hash->gh_acquire_expire);
225 }
226
227 static int lprocfs_wr_ac_expire(struct file *file, const char *buffer,
228                                 unsigned long count, void *data)
229 {
230         struct mds_grp_hash *hash = __mds_get_global_group_hash();
231         char buf[32];
232
233         if (copy_from_user(buf, buffer, min(count, 32UL)))
234                 return count;
235         buf[31] = 0;
236         sscanf(buf, "%d", &hash->gh_acquire_expire);
237         return count;
238 }
239
240 static int lprocfs_rd_hash_upcall(char *page, char **start, off_t off, int count,
241                                 int *eof, void *data)
242 {
243         struct mds_grp_hash *hash = __mds_get_global_group_hash();
244
245         *eof = 1;
246         return snprintf(page, count, "%s\n", hash->gh_upcall);
247 }
248
249 static int lprocfs_wr_hash_upcall(struct file *file, const char *buffer,
250                                   unsigned long count, void *data)
251 {
252         struct mds_grp_hash *hash = __mds_get_global_group_hash();
253
254         if (count < MDSGRP_UPCALL_MAXPATH) {
255                 sscanf(buffer, "%1024s", hash->gh_upcall);
256                 hash->gh_upcall[MDSGRP_UPCALL_MAXPATH-1] = 0;
257         }
258         return count;
259 }
260
261 static int lprocfs_wr_hash_flush(struct file *file, const char *buffer,
262                                   unsigned long count, void *data)
263 {
264         mds_group_hash_flush_idle();
265         return count;
266 }
267
268 static int lprocfs_rd_allow_setgroups(char *page, char **start, off_t off,
269                                       int count, int *eof, void *data)
270 {
271         struct mds_grp_hash *hash = __mds_get_global_group_hash();
272
273         *eof = 1;
274         return snprintf(page, count, "%d\n", hash->gh_allow_setgroups);
275 }
276
277 static int lprocfs_wr_allow_setgroups(struct file *file, const char *buffer,
278                                       unsigned long count, void *data)
279 {
280         struct mds_grp_hash *hash = __mds_get_global_group_hash();
281         char buf[8];
282         int val;
283
284         if (copy_from_user(buf, buffer, min(count, 8UL)))
285                 return count;
286         buf[7] = 0;
287         sscanf(buf, "%d", &val);
288         hash->gh_allow_setgroups = (val != 0);
289         return count;
290 }
291
292 struct lprocfs_vars lprocfs_mds_module_vars[] = {
293         { "num_refs", lprocfs_rd_numrefs, 0, 0 },
294         { "grp_hash_expire_interval",lprocfs_rd_expire,
295           lprocfs_wr_expire, 0},
296         { "grp_hash_acquire_expire", lprocfs_rd_ac_expire,
297           lprocfs_wr_ac_expire, 0},
298         { "grp_hash_upcall", lprocfs_rd_hash_upcall,
299           lprocfs_wr_hash_upcall, 0},
300         { "grp_hash_flush", 0, lprocfs_wr_hash_flush, 0},
301         { "group_info", 0, lprocfs_wr_group_info, 0 },
302         { "allow_setgroups", lprocfs_rd_allow_setgroups,
303           lprocfs_wr_allow_setgroups, 0},
304         { 0 }
305 };
306
307 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
308         { "uuid",         lprocfs_rd_uuid,        0, 0 },
309         { 0 }
310 };
311
312 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
313         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
314         { 0 }
315 };
316 #endif /* LPROCFS */
317
318 struct lprocfs_static_vars lprocfs_array_vars[] = { {lprocfs_mds_module_vars,
319                                                      lprocfs_mds_obd_vars},
320                                                     {lprocfs_mdt_module_vars,
321                                                      lprocfs_mdt_obd_vars}};
322
323 LPROCFS_INIT_MULTI_VARS(lprocfs_array_vars,
324                         (sizeof(lprocfs_array_vars) /
325                          sizeof(struct lprocfs_static_vars)))