Whamcloud - gitweb
- landing of b_hd_cleanup_merge to 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 struct lprocfs_vars lprocfs_mds_obd_vars[]  = { {0} };
35 struct lprocfs_vars lprocfs_mds_module_vars[] = { {0} };
36 struct lprocfs_vars lprocfs_mdt_obd_vars[] = { {0} };
37 struct lprocfs_vars lprocfs_mdt_module_vars[] = { {0} };
38
39 atomic_t * lprocfs_alloc_mds_counters()
40 {
41         return NULL;
42 }
43 void lprocfs_free_mds_counters(atomic_t *ptr)
44 {
45         return;
46 }
47
48 #else
49
50 struct ll_mdscounters_opcode {
51      __u32       opcode;
52      const char *opname;
53 } ll_mdscounters_opcode_table[MDS_LAST_OPC_COUNT] = {
54        { MDS_OPEN_COUNT,          "mds_open" },
55        { MDS_CREATE_COUNT,        "mds_create" },
56        { MDS_CLOSE_COUNT,         "mds_close" },
57        { MDS_LINK_COUNT,          "mds_link" },
58        { MDS_UNLINK_COUNT,        "mds_unlink" },
59        { MDS_GETATTR_COUNT,       "mds_getattr" },
60        { MDS_GETATTR_NAME_COUNT,  "mds_getattr_name" },
61        { MDS_SETATTR_COUNT,       "mds_setattr" },
62        { MDS_RENAME_COUNT,        "mds_rename" },
63        { MDS_STATFS_COUNT,        "mds_statfs" },
64 };
65
66 const char* ll_mds_count_opcode2str(__u32 opcode)
67 {
68         __u32 offset = opcode;
69
70         LASSERT(offset < MDS_LAST_OPC_COUNT);
71         LASSERT(ll_mdscounters_opcode_table[offset].opcode == opcode);
72         return ll_mdscounters_opcode_table[offset].opname;
73 }
74
75 struct lprocfs_stats * lprocfs_alloc_mds_counters()
76 {
77         struct lprocfs_stats *counters;
78         int i;
79
80         counters = lprocfs_alloc_stats(MDS_LAST_OPC_COUNT);
81
82         for (i = 0; i < MDS_LAST_OPC_COUNT; i ++) {         
83             lprocfs_counter_init(counters, i, 0, 
84                                  (char *)ll_mds_count_opcode2str(i), "reqs");
85         }
86         return counters;
87 }
88
89 void lprocfs_free_mds_counters(struct lprocfs_stats *ptr)
90 {
91         lprocfs_free_stats(ptr);
92 }
93
94 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
95                                  int *eof, void *data)
96 {
97         struct obd_device* obd = (struct obd_device *)data;
98
99         LASSERT(obd != NULL);
100         LASSERT(obd->u.mds.mds_vfsmnt->mnt_devname);
101         *eof = 1;
102
103         return snprintf(page, count, "%s\n",obd->u.mds.mds_vfsmnt->mnt_devname);
104 }
105
106 static int lprocfs_rd_mds_counters(char *page, char **start, off_t off,
107                                           int count, int *eof, void *data)
108 {
109         struct obd_device* obd = (struct obd_device *)data;
110         int len = 0, n, i, j;
111         struct lprocfs_counter  t, ret = { .lc_min = ~(__u64)0 };
112         struct lprocfs_stats *stats;
113         struct timeval now;
114
115         LASSERT(obd != NULL);
116         if (obd->u.mds.mds_counters == NULL)
117                 return 0;
118
119         do_gettimeofday(&now);
120
121         n = snprintf(page, count, "%-25s %lu.%lu secs.usecs\n",
122                                "snapshot_time", now.tv_sec, now.tv_usec);
123         page += n; len +=n; count -=n;
124
125         stats = obd->u.mds.mds_counters;
126
127         *eof = 1;
128         for (i = 0; i < MDS_LAST_OPC_COUNT; i ++) {
129                 ret.lc_count = 0; 
130                 for (j = 0; j < num_online_cpus(); j++) {
131                         struct lprocfs_counter *percpu_cntr =
132                                 &(stats->ls_percpu[j])->lp_cntr[i];
133                         int centry;
134                         do {
135                                 centry = 
136                                    atomic_read(&percpu_cntr->lc_cntl.la_entry); 
137                                 t.lc_count = percpu_cntr->lc_count;
138                         } while (centry != 
139                                  atomic_read(&percpu_cntr->lc_cntl.la_entry) &&
140                                  centry != 
141                                  atomic_read(&percpu_cntr->lc_cntl.la_exit));
142                         ret.lc_count += t.lc_count;
143                } 
144                 n = snprintf(page, count, "%-25s "LPU64" \n", 
145                                    ll_mds_count_opcode2str(i), ret.lc_count);
146                 page += n; len +=n; count -=n;
147         }
148         return (len);
149 }
150
151 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
152                                        unsigned long count, void *data)
153 {
154         struct obd_device *obd = data;
155         struct obd_export *doomed_exp = NULL;
156         struct obd_uuid doomed;
157         struct list_head *p;
158         char tmpbuf[sizeof(doomed)];
159
160         sscanf(buffer, "%40s", tmpbuf);
161         obd_str2uuid(&doomed, tmpbuf);
162
163         spin_lock(&obd->obd_dev_lock);
164         list_for_each(p, &obd->obd_exports) {
165                 doomed_exp = list_entry(p, struct obd_export, exp_obd_chain);
166                 if (obd_uuid_equals(&doomed, &doomed_exp->exp_client_uuid)) {
167                         class_export_get(doomed_exp);
168                         break;
169                 }
170                 doomed_exp = NULL;
171         }
172         spin_unlock(&obd->obd_dev_lock);
173
174         if (doomed_exp == NULL) {
175                 CERROR("can't disconnect %s: no export found\n",
176                        doomed.uuid);
177         } else {
178                 CERROR("evicting %s at adminstrative request\n",
179                        doomed.uuid);
180                 ptlrpc_fail_export(doomed_exp);
181                 class_export_put(doomed_exp);
182         }
183         return count;
184 }
185
186 static int lprocfs_mds_wr_config_update(struct file *file, const char *buffer,
187                                         unsigned long count, void *data)
188 {
189         struct obd_device *obd = data;
190         ENTRY;
191
192         RETURN(mds_lov_update_config(obd, 0));
193 }
194
195 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
196         { "uuid",         lprocfs_rd_uuid,        0, 0 },
197         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
198         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
199         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
200         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
201         { "fstype",       lprocfs_rd_fstype,      0, 0 },
202         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
203         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
204         { "mntdev",       lprocfs_mds_rd_mntdev,  0, 0 },
205         { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
206         { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
207         { "config_update", 0, lprocfs_mds_wr_config_update, 0 },
208         { "num_exports",  lprocfs_rd_num_exports, 0, 0 },
209         { "counters", lprocfs_rd_mds_counters, 0, 0 },
210         { 0 }
211 };
212
213 /*
214  * group hash proc entries handler
215  */
216 static int lprocfs_wr_group_info(struct file *file, const char *buffer,
217                                  unsigned long count, void *data)
218 {
219         struct {
220                 int             err;
221                 uid_t           uid;
222                 uint32_t        ngroups;
223                 gid_t          *groups;
224         } param;
225         gid_t   gids_local[NGROUPS_SMALL];
226         gid_t  *gids = NULL;
227
228         if (count != sizeof(param)) {
229                 CERROR("invalid data size %lu\n", count);
230                 return count;
231         }
232         if (copy_from_user(&param, buffer, count)) {
233                 CERROR("broken downcall\n");
234                 return count;
235         }
236         if (param.ngroups > NGROUPS_MAX) {
237                 CERROR("%d groups?\n", param.ngroups);
238                 return count;
239         }
240
241         if (param.ngroups <= NGROUPS_SMALL)
242                 gids = gids_local;
243         else {
244                 OBD_ALLOC(gids, param.ngroups * sizeof(gid_t));
245                 if (!gids) {
246                         CERROR("fail to alloc memory for %d gids\n",
247                                 param.ngroups);
248                         return count;
249                 }
250         }
251         if (copy_from_user(gids, param.groups,
252                            param.ngroups * sizeof(gid_t))) {
253                 CERROR("broken downcall\n");
254                 goto out;
255         }
256
257         mds_handle_group_downcall(param.err, param.uid,
258                                   param.ngroups, gids);
259
260 out:
261         if (gids && gids != gids_local)
262                 OBD_FREE(gids, param.ngroups * sizeof(gid_t));
263         return count;
264 }
265 static int lprocfs_rd_expire(char *page, char **start, off_t off, int count,
266                              int *eof, void *data)
267 {
268         struct mds_grp_hash *hash = __mds_get_global_group_hash();
269
270         *eof = 1;
271         return snprintf(page, count, "%d\n", hash->gh_entry_expire);
272 }
273 static int lprocfs_wr_expire(struct file *file, const char *buffer,
274                              unsigned long count, void *data)
275 {
276         struct mds_grp_hash *hash = __mds_get_global_group_hash();
277         char buf[32];
278
279         if (copy_from_user(buf, buffer, min(count, 32UL)))
280                 return count;
281         buf[31] = 0;
282         sscanf(buf, "%d", &hash->gh_entry_expire);
283         return count;
284 }
285 static int lprocfs_rd_ac_expire(char *page, char **start, off_t off, int count,
286                                 int *eof, void *data)
287 {
288         struct mds_grp_hash *hash = __mds_get_global_group_hash();
289
290         *eof = 1;
291         return snprintf(page, count, "%d\n", hash->gh_acquire_expire);
292 }
293 static int lprocfs_wr_ac_expire(struct file *file, const char *buffer,
294                                 unsigned long count, void *data)
295 {
296         struct mds_grp_hash *hash = __mds_get_global_group_hash();
297         char buf[32];
298
299         if (copy_from_user(buf, buffer, min(count, 32UL)))
300                 return count;
301         buf[31] = 0;
302         sscanf(buf, "%d", &hash->gh_acquire_expire);
303         return count;
304 }
305 static int lprocfs_rd_hash_upcall(char *page, char **start, off_t off, int count,
306                                 int *eof, void *data)
307 {
308         struct mds_grp_hash *hash = __mds_get_global_group_hash();
309
310         *eof = 1;
311         return snprintf(page, count, "%s\n", hash->gh_upcall);
312 }
313 static int lprocfs_wr_hash_upcall(struct file *file, const char *buffer,
314                                   unsigned long count, void *data)
315 {
316         struct mds_grp_hash *hash = __mds_get_global_group_hash();
317
318         if (count < MDSGRP_UPCALL_MAXPATH) {
319                 sscanf(buffer, "%1024s", hash->gh_upcall);
320                 hash->gh_upcall[MDSGRP_UPCALL_MAXPATH-1] = 0;
321         }
322         return count;
323 }
324 static int lprocfs_wr_hash_flush(struct file *file, const char *buffer,
325                                   unsigned long count, void *data)
326 {
327         mds_group_hash_flush_idle();
328         return count;
329 }
330 static int lprocfs_rd_allow_setgroups(char *page, char **start, off_t off,
331                                       int count, int *eof, void *data)
332 {
333         struct mds_grp_hash *hash = __mds_get_global_group_hash();
334
335         *eof = 1;
336         return snprintf(page, count, "%d\n", hash->gh_allow_setgroups);
337 }
338 static int lprocfs_wr_allow_setgroups(struct file *file, const char *buffer,
339                                       unsigned long count, void *data)
340 {
341         struct mds_grp_hash *hash = __mds_get_global_group_hash();
342         char buf[8];
343         int val;
344
345         if (copy_from_user(buf, buffer, min(count, 8UL)))
346                 return count;
347         buf[7] = 0;
348         sscanf(buf, "%d", &val);
349         hash->gh_allow_setgroups = (val != 0);
350         return count;
351 }
352
353 struct lprocfs_vars lprocfs_mds_module_vars[] = {
354         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
355         { "grp_hash_expire_interval", lprocfs_rd_expire, lprocfs_wr_expire, 0},
356         { "grp_hash_acquire_expire", lprocfs_rd_ac_expire,
357                                      lprocfs_wr_ac_expire, 0},
358         { "grp_hash_upcall", lprocfs_rd_hash_upcall, lprocfs_wr_hash_upcall, 0},
359         { "grp_hash_flush", 0, lprocfs_wr_hash_flush, 0},
360         { "group_info", 0,  lprocfs_wr_group_info,   0 },
361         { "allow_setgroups", lprocfs_rd_allow_setgroups,
362                              lprocfs_wr_allow_setgroups, 0},
363         { 0 }
364 };
365
366 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
367         { "uuid",         lprocfs_rd_uuid,        0, 0 },
368         { 0 }
369 };
370
371 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
372         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
373         { 0 }
374 };
375
376 #endif /* LPROCFS */
377
378 struct lprocfs_static_vars lprocfs_array_vars[] = { {lprocfs_mds_module_vars,
379                                                      lprocfs_mds_obd_vars},
380                                                     {lprocfs_mdt_module_vars,
381                                                      lprocfs_mdt_obd_vars}};
382
383 LPROCFS_INIT_MULTI_VARS(lprocfs_array_vars,
384                         (sizeof(lprocfs_array_vars) /
385                          sizeof(struct lprocfs_static_vars)))