Whamcloud - gitweb
1386670a5b31eba4a8c74d4d7ffe2b731d8cb180
[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_dt_update_config(obd, 0));
97 }
98
99 static int lprocfs_rd_filesopen(char *page, char **start, off_t off,
100                                 int count, int *eof, void *data)
101 {
102         struct obd_device *obd = data;
103         LASSERT(obd != NULL);
104         *eof = 1;
105
106         return snprintf(page, count, "%d\n",
107                         atomic_read(&obd->u.mds.mds_open_count));
108 }
109
110 static int lprocfs_rd_last_fid(char *page, char **start, off_t off,
111                                int count, int *eof, void *data)
112 {
113         struct obd_device *obd = (struct obd_device *)data;
114         struct mds_obd *mds = &obd->u.mds;
115         __u64 last_fid;
116
117         spin_lock(&mds->mds_last_fid_lock);
118         last_fid = mds->mds_last_fid;
119         spin_unlock(&mds->mds_last_fid_lock);
120
121         *eof = 1;
122         return snprintf(page, count, LPD64"\n", last_fid);
123 }
124
125 static int lprocfs_rd_group(char *page, char **start, off_t off,
126                             int count, int *eof, void *data)
127 {
128         struct obd_device *obd = (struct obd_device *)data;
129         struct mds_obd *mds = &obd->u.mds;
130
131         *eof = 1;
132         return snprintf(page, count, "%lu\n",
133                         (unsigned long)mds->mds_num);
134 }
135
136 static int lprocfs_rd_capa(char *page, char **start, off_t off,
137                            int count, int *eof, void *data)
138 {
139         struct obd_device *obd = (struct obd_device *)data;
140         LASSERT(obd != NULL);
141
142         return snprintf(page, count, "%d\n",
143                         obd->u.mds.mds_capa_stat);
144 }
145
146 static int lprocfs_wr_capa(struct file *file, const char *buffer,
147                            unsigned long count, void *data)
148 {
149         struct obd_device *obd = data;
150         int val, rc;
151
152         rc = lprocfs_write_helper(buffer, count, &val);
153         if (rc)
154                 return rc;
155
156         mds_update_capa_stat(obd, val);
157         return count;
158 }
159
160 static int lprocfs_rd_capa_timeout(char *page, char **start, off_t off,
161                                        int count, int *eof, void *data)
162 {
163         struct obd_device *obd = (struct obd_device *)data;
164         LASSERT(obd != NULL);
165
166         return snprintf(page, count, "%lu\n",
167                         obd->u.mds.mds_capa_timeout);
168 }
169
170 static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
171                                        unsigned long count, void *data)
172 {
173         struct obd_device *obd = data;
174         int val, rc;
175
176         rc = lprocfs_write_helper(buffer, count, &val);
177         if (rc)
178                 return rc;
179
180         mds_update_capa_timeout(obd, val);
181         return count;
182 }
183
184 static int lprocfs_rd_capa_key_timeout(char *page, char **start, off_t off,
185                                            int count, int *eof, void *data)
186 {
187         struct obd_device *obd = (struct obd_device *)data;
188         LASSERT(obd != NULL);
189
190         return snprintf(page, count, "%lu\n",
191                         obd->u.mds.mds_capa_key_timeout);
192 }
193
194 static int lprocfs_wr_capa_key_timeout(struct file *file, const char *buffer,
195                                            unsigned long count, void *data)
196 {
197         struct obd_device *obd = data;
198         int val, rc;
199
200         rc = lprocfs_write_helper(buffer, count, &val);
201         if (rc)
202                 return rc;
203
204         rc = mds_update_capa_key_timeout(obd, val);
205         return rc ?: count;
206 }
207
208 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
209         { "uuid",         lprocfs_rd_uuid,        0, 0 },
210         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
211         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
212         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
213         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
214         { "fstype",       lprocfs_rd_fstype,      0, 0 },
215         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
216         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
217         { "filesopen",    lprocfs_rd_filesopen,   0, 0 },
218         { "mntdev",       lprocfs_mds_rd_mntdev,  0, 0 },
219         { "last_fid",     lprocfs_rd_last_fid,    0, 0 },
220         { "group",        lprocfs_rd_group,       0, 0 },
221         { "recovery_status",  lprocfs_obd_rd_recovery_status, 0, 0 },
222         { "evict_client", 0,  lprocfs_mds_wr_evict_client, 0 },
223         { "config_update", 0, lprocfs_mds_wr_config_update, 0 },
224         { "num_exports",      lprocfs_rd_num_exports, 0, 0 },
225         { "capa",             lprocfs_rd_capa,
226                               lprocfs_wr_capa, 0 },
227         { "capa_timeout",     lprocfs_rd_capa_timeout,
228                               lprocfs_wr_capa_timeout, 0 },
229         { "capa_key_timeout", lprocfs_rd_capa_key_timeout,
230                               lprocfs_wr_capa_key_timeout, 0 },
231         { 0 }
232 };
233
234 /*
235  * LSD proc entry handlers
236  */
237 static int lprocfs_wr_lsd_downcall(struct file *file, const char *buffer,
238                                    unsigned long count, void *data)
239 {
240         struct upcall_cache *cache = __mds_get_global_lsd_cache();
241         struct lsd_downcall_args param;
242         gid_t   gids_local[NGROUPS_SMALL];
243         gid_t  *gids = NULL;
244
245         if (count != sizeof(param)) {
246                 CERROR("invalid data size %lu\n", count);
247                 goto do_err_downcall;
248         }
249         if (copy_from_user(&param, buffer, count)) {
250                 CERROR("broken downcall\n");
251                 goto do_err_downcall;
252         }
253
254         if (param.err) {
255                 CERROR("LSD downcall indicate error %d\n", param.err);
256                 goto do_downcall;
257         }
258
259         if (param.ngroups > NGROUPS_MAX) {
260                 CERROR("%d groups too big\n", param.ngroups);
261                 goto do_err_downcall;
262         }
263
264         if (param.ngroups <= NGROUPS_SMALL)
265                 gids = gids_local;
266         else {
267                 OBD_ALLOC(gids, param.ngroups * sizeof(gid_t));
268                 if (!gids) {
269                         CERROR("fail to alloc memory for %d gids\n",
270                                 param.ngroups);
271                         goto do_err_downcall;
272                 }
273         }
274         if (copy_from_user(gids, param.groups,
275                            param.ngroups * sizeof(gid_t))) {
276                 CERROR("broken downcall\n");
277                 goto do_err_downcall;
278         }
279
280         param.groups = gids;
281
282 do_downcall:
283         upcall_cache_downcall(cache, (__u64) param.uid, &param);
284
285         if (gids && gids != gids_local)
286                 OBD_FREE(gids, param.ngroups * sizeof(gid_t));
287         return count;
288
289 do_err_downcall:
290         param.err = -EINVAL;
291         goto do_downcall;
292 }
293
294 static int lprocfs_rd_lsd_expire(char *page, char **start, off_t off, int count,
295                                  int *eof, void *data)
296 {
297         struct upcall_cache *cache= __mds_get_global_lsd_cache();
298
299         *eof = 1;
300         return snprintf(page, count, "%lu\n", cache->uc_entry_expire);
301 }
302 static int lprocfs_wr_lsd_expire(struct file *file, const char *buffer,
303                                  unsigned long count, void *data)
304 {
305         struct upcall_cache *cache= __mds_get_global_lsd_cache();
306         char buf[32];
307
308         if (copy_from_user(buf, buffer, min(count, 32UL)))
309                 return count;
310         buf[31] = 0;
311         sscanf(buf, "%lu", &cache->uc_entry_expire);
312         return count;
313 }
314
315 static int lprocfs_rd_lsd_ac_expire(char *page, char **start, off_t off,
316                                     int count, int *eof, void *data)
317 {
318         struct upcall_cache *cache= __mds_get_global_lsd_cache();
319
320         *eof = 1;
321         return snprintf(page, count, "%lu\n", cache->uc_acquire_expire);
322 }
323 static int lprocfs_wr_lsd_ac_expire(struct file *file, const char *buffer,
324                                     unsigned long count, void *data)
325 {
326         struct upcall_cache *cache= __mds_get_global_lsd_cache();
327         char buf[32];
328
329         if (copy_from_user(buf, buffer, min(count, 32UL)))
330                 return count;
331         buf[31] = 0;
332         sscanf(buf, "%lu", &cache->uc_acquire_expire);
333         return count;
334 }
335
336 static int lprocfs_rd_lsd_upcall(char *page, char **start, off_t off, int count,
337                                  int *eof, void *data)
338 {
339         struct upcall_cache *cache= __mds_get_global_lsd_cache();
340
341         *eof = 1;
342         return snprintf(page, count, "%s\n", cache->uc_upcall);
343 }
344 static int lprocfs_wr_lsd_upcall(struct file *file, const char *buffer,
345                                  unsigned long count, void *data)
346 {
347         struct upcall_cache *cache= __mds_get_global_lsd_cache();
348
349         if (count < UC_CACHE_UPCALL_MAXPATH) {
350                 sscanf(buffer, "%1024s", cache->uc_upcall);
351                 cache->uc_upcall[UC_CACHE_UPCALL_MAXPATH - 1] = 0;
352         }
353         return count;
354 }
355
356 extern void lgss_svc_cache_flush(__u32 uid);
357 static int lprocfs_wr_lsd_flush(struct file *file, const char *buffer,
358                                 unsigned long count, void *data)
359 {
360         char buf[32];
361         __u32 uid;
362
363         if (copy_from_user(buf, buffer, min(count, 32UL)))
364                 return count;
365         buf[31] = 0;
366         sscanf(buf, "%d", &uid);
367
368         mds_flush_lsd(uid);
369 #ifdef ENABLE_GSS
370         lgss_svc_cache_flush(uid);
371 #endif
372         return count;
373 }
374
375 /*
376  * remote acl proc handling
377  */
378 static int lprocfs_rd_lacl_upcall(char *page, char **start, off_t off,
379                                   int count, int *eof, void *data)
380 {
381         struct upcall_cache *cache = __mds_get_global_rmtacl_upcall_cache();
382
383         *eof = 1;
384         return snprintf(page, count, "%s\n", cache->uc_upcall);
385 }
386
387 static int lprocfs_wr_lacl_upcall(struct file *file, const char *buffer,
388                                   unsigned long count, void *data)
389 {
390         struct upcall_cache *cache = __mds_get_global_rmtacl_upcall_cache();
391
392         if (count < UC_CACHE_UPCALL_MAXPATH) {
393                 sscanf(buffer, "%1024s", cache->uc_upcall);
394                 cache->uc_upcall[UC_CACHE_UPCALL_MAXPATH - 1] = 0;
395         }
396         return count;
397 }
398
399 static int lprocfs_wr_lacl_downcall(struct file *file, const char *buffer,
400                                     unsigned long count, void *data)
401 {
402         struct upcall_cache *cache = __mds_get_global_rmtacl_upcall_cache();
403         struct rmtacl_downcall_args param;
404
405         if (count != sizeof(param)) {
406                 CERROR("invalid data size %lu\n", count);
407                 goto do_err_downcall;
408         }
409         if (copy_from_user(&param, buffer, count)) {
410                 CERROR("broken downcall\n");
411                 goto do_err_downcall;
412         }
413
414 do_downcall:
415         upcall_cache_downcall(cache, param.key, &param);
416         return count;
417
418 do_err_downcall:
419         memset(&param, 0, sizeof(param));
420         param.status = -EINVAL;
421         goto do_downcall;
422 }
423
424 struct lprocfs_vars lprocfs_mds_module_vars[] = {
425         { "num_refs",                   lprocfs_rd_numrefs, 0, 0 },
426         /* LSD stuff */
427         { "lsd_expire_interval",        lprocfs_rd_lsd_expire,
428                                         lprocfs_wr_lsd_expire, 0},
429         { "lsd_acquire_expire",         lprocfs_rd_lsd_ac_expire,
430                                         lprocfs_wr_lsd_ac_expire, 0},
431         { "lsd_upcall",                 lprocfs_rd_lsd_upcall,
432                                         lprocfs_wr_lsd_upcall, 0},
433         { "lsd_flush",                  0, lprocfs_wr_lsd_flush, 0},
434         { "lsd_downcall",               0, lprocfs_wr_lsd_downcall, 0},
435         /* remote acl */
436         { "lacl_upcall",                lprocfs_rd_lacl_upcall,
437                                         lprocfs_wr_lacl_upcall, 0},
438         { "lacl_downcall",              0, lprocfs_wr_lacl_downcall, 0},
439         { 0 }
440 };
441
442 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
443         { "uuid",         lprocfs_rd_uuid,        0, 0 },
444         { 0 }
445 };
446
447 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
448         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
449         { 0 }
450 };
451 #endif /* LPROCFS */
452
453 struct lprocfs_static_vars lprocfs_array_vars[] = { {lprocfs_mds_module_vars,
454                                                      lprocfs_mds_obd_vars},
455                                                     {lprocfs_mdt_module_vars,
456                                                      lprocfs_mdt_obd_vars}};
457
458 LPROCFS_INIT_MULTI_VARS(lprocfs_array_vars,
459                         (sizeof(lprocfs_array_vars) /
460                          sizeof(struct lprocfs_static_vars)))