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