Whamcloud - gitweb
- landed b_hd_cray_merge3
[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 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
137         { "uuid",         lprocfs_rd_uuid,        0, 0 },
138         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
139         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
140         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
141         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
142         { "fstype",       lprocfs_rd_fstype,      0, 0 },
143         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
144         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
145         { "filesopen",    lprocfs_rd_filesopen,   0, 0 },
146         { "mntdev",       lprocfs_mds_rd_mntdev,  0, 0 },
147         { "last_fid",     lprocfs_rd_last_fid,    0, 0 },
148         { "group",        lprocfs_rd_group,       0, 0 },
149         { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
150         { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
151         { "config_update", 0, lprocfs_mds_wr_config_update, 0 },
152         { "num_exports",  lprocfs_rd_num_exports, 0, 0 },
153         { 0 }
154 };
155
156 /*
157  * LSD proc entry handlers
158  */
159 static int lprocfs_wr_lsd_downcall(struct file *file, const char *buffer,
160                                    unsigned long count, void *data)
161 {
162         struct upcall_cache *cache = __mds_get_global_lsd_cache();
163         struct lsd_downcall_args param;
164         gid_t   gids_local[NGROUPS_SMALL];
165         gid_t  *gids = NULL;
166
167         if (count != sizeof(param)) {
168                 CERROR("invalid data size %lu\n", count);
169                 return count;
170         }
171         if (copy_from_user(&param, buffer, count)) {
172                 CERROR("broken downcall\n");
173                 return count;
174         }
175
176         if (param.err) {
177                 CERROR("LSD downcall indicate error %d\n", param.err);
178                 goto do_downcall;
179         }
180
181         if (param.ngroups > NGROUPS_MAX) {
182                 CERROR("%d groups?\n", param.ngroups);
183                 param.err = -EINVAL;
184                 goto do_downcall;
185         }
186
187         if (param.ngroups <= NGROUPS_SMALL)
188                 gids = gids_local;
189         else {
190                 OBD_ALLOC(gids, param.ngroups * sizeof(gid_t));
191                 if (!gids) {
192                         CERROR("fail to alloc memory for %d gids\n",
193                                 param.ngroups);
194                         param.err = -ENOMEM;
195                         goto do_downcall;
196                 }
197         }
198         if (copy_from_user(gids, param.groups,
199                            param.ngroups * sizeof(gid_t))) {
200                 CERROR("broken downcall\n");
201                 param.err = -EFAULT;
202                 goto do_downcall;
203         }
204
205         param.groups = gids;
206
207 do_downcall:
208         upcall_cache_downcall(cache, (__u64) param.uid, param.err, &param);
209
210         if (gids && gids != gids_local)
211                 OBD_FREE(gids, param.ngroups * sizeof(gid_t));
212         return count;
213 }
214
215 static int lprocfs_rd_lsd_expire(char *page, char **start, off_t off, int count,
216                                  int *eof, void *data)
217 {
218         struct upcall_cache *cache= __mds_get_global_lsd_cache();
219
220         *eof = 1;
221         return snprintf(page, count, "%lu\n", cache->uc_entry_expire);
222 }
223 static int lprocfs_wr_lsd_expire(struct file *file, const char *buffer,
224                                  unsigned long count, void *data)
225 {
226         struct upcall_cache *cache= __mds_get_global_lsd_cache();
227         char buf[32];
228
229         if (copy_from_user(buf, buffer, min(count, 32UL)))
230                 return count;
231         buf[31] = 0;
232         sscanf(buf, "%lu", &cache->uc_entry_expire);
233         return count;
234 }
235
236 static int lprocfs_rd_lsd_ac_expire(char *page, char **start, off_t off,
237                                     int count, int *eof, void *data)
238 {
239         struct upcall_cache *cache= __mds_get_global_lsd_cache();
240
241         *eof = 1;
242         return snprintf(page, count, "%lu\n", cache->uc_acquire_expire);
243 }
244 static int lprocfs_wr_lsd_ac_expire(struct file *file, const char *buffer,
245                                     unsigned long count, void *data)
246 {
247         struct upcall_cache *cache= __mds_get_global_lsd_cache();
248         char buf[32];
249
250         if (copy_from_user(buf, buffer, min(count, 32UL)))
251                 return count;
252         buf[31] = 0;
253         sscanf(buf, "%lu", &cache->uc_acquire_expire);
254         return count;
255 }
256
257 static int lprocfs_rd_lsd_upcall(char *page, char **start, off_t off, int count,
258                                  int *eof, void *data)
259 {
260         struct upcall_cache *cache= __mds_get_global_lsd_cache();
261
262         *eof = 1;
263         return snprintf(page, count, "%s\n", cache->uc_upcall);
264 }
265 static int lprocfs_wr_lsd_upcall(struct file *file, const char *buffer,
266                                  unsigned long count, void *data)
267 {
268         struct upcall_cache *cache= __mds_get_global_lsd_cache();
269
270         if (count < UC_CACHE_UPCALL_MAXPATH) {
271                 sscanf(buffer, "%1024s", cache->uc_upcall);
272                 cache->uc_upcall[UC_CACHE_UPCALL_MAXPATH - 1] = 0;
273         }
274         return count;
275 }
276
277 extern void lgss_svc_cache_flush(__u32 uid);
278 static int lprocfs_wr_lsd_flush(struct file *file, const char *buffer,
279                                 unsigned long count, void *data)
280 {
281         char buf[32];
282         __u32 uid;
283
284         if (copy_from_user(buf, buffer, min(count, 32UL)))
285                 return count;
286         buf[31] = 0;
287         sscanf(buf, "%d", &uid);
288
289         mds_flush_lsd(uid);
290 #ifdef ENABLE_GSS
291         lgss_svc_cache_flush(uid);
292 #endif
293         return count;
294 }
295
296 struct lprocfs_vars lprocfs_mds_module_vars[] = {
297         { "num_refs",                   lprocfs_rd_numrefs, 0, 0 },
298         /* LSD stuff */
299         { "lsd_expire_interval",        lprocfs_rd_lsd_expire,
300                                         lprocfs_wr_lsd_expire, 0},
301         { "lsd_acquire_expire",         lprocfs_rd_lsd_ac_expire,
302                                         lprocfs_wr_lsd_ac_expire, 0},
303         { "lsd_upcall",                 lprocfs_rd_lsd_upcall,
304                                         lprocfs_wr_lsd_upcall, 0},
305         { "lsd_flush",                  0, lprocfs_wr_lsd_flush, 0},
306         { "lsd_downcall",               0, lprocfs_wr_lsd_downcall, 0},
307         { 0 }
308 };
309
310 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
311         { "uuid",         lprocfs_rd_uuid,        0, 0 },
312         { 0 }
313 };
314
315 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
316         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
317         { 0 }
318 };
319 #endif /* LPROCFS */
320
321 struct lprocfs_static_vars lprocfs_array_vars[] = { {lprocfs_mds_module_vars,
322                                                      lprocfs_mds_obd_vars},
323                                                     {lprocfs_mdt_module_vars,
324                                                      lprocfs_mdt_obd_vars}};
325
326 LPROCFS_INIT_MULTI_VARS(lprocfs_array_vars,
327                         (sizeof(lprocfs_array_vars) /
328                          sizeof(struct lprocfs_static_vars)))