1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
22 #define DEBUG_SUBSYSTEM S_CLASS
24 #include <linux/version.h>
25 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 #include <asm/statfs.h>
28 #include <linux/obd.h>
29 #include <linux/obd_class.h>
30 #include <linux/lprocfs_status.h>
31 #include "mds_internal.h"
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} };
39 atomic_t * lprocfs_alloc_mds_counters()
43 void lprocfs_free_mds_counters(atomic_t *ptr)
50 struct ll_mdscounters_opcode {
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" },
66 const char* ll_mds_count_opcode2str(__u32 opcode)
68 __u32 offset = opcode;
70 LASSERT(offset < MDS_LAST_OPC_COUNT);
71 LASSERT(ll_mdscounters_opcode_table[offset].opcode == opcode);
72 return ll_mdscounters_opcode_table[offset].opname;
75 struct lprocfs_stats * lprocfs_alloc_mds_counters()
77 struct lprocfs_stats *counters;
80 counters = lprocfs_alloc_stats(MDS_LAST_OPC_COUNT);
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");
89 void lprocfs_free_mds_counters(struct lprocfs_stats *ptr)
91 lprocfs_free_stats(ptr);
94 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
97 struct obd_device* obd = (struct obd_device *)data;
100 LASSERT(obd->u.mds.mds_vfsmnt->mnt_devname);
103 return snprintf(page, count, "%s\n",obd->u.mds.mds_vfsmnt->mnt_devname);
106 static int lprocfs_rd_mds_counters(char *page, char **start, off_t off,
107 int count, int *eof, void *data)
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;
115 LASSERT(obd != NULL);
116 if (obd->u.mds.mds_counters == NULL)
119 do_gettimeofday(&now);
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;
125 stats = obd->u.mds.mds_counters;
128 for (i = 0; i < MDS_LAST_OPC_COUNT; i ++) {
130 for (j = 0; j < num_online_cpus(); j++) {
131 struct lprocfs_counter *percpu_cntr =
132 &(stats->ls_percpu[j])->lp_cntr[i];
136 atomic_read(&percpu_cntr->lc_cntl.la_entry);
137 t.lc_count = percpu_cntr->lc_count;
139 atomic_read(&percpu_cntr->lc_cntl.la_entry) &&
141 atomic_read(&percpu_cntr->lc_cntl.la_exit));
142 ret.lc_count += t.lc_count;
144 n = snprintf(page, count, "%-25s "LPU64" \n",
145 ll_mds_count_opcode2str(i), ret.lc_count);
146 page += n; len +=n; count -=n;
151 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
152 unsigned long count, void *data)
154 struct obd_device *obd = data;
155 struct obd_export *doomed_exp = NULL;
156 struct obd_uuid doomed;
158 char tmpbuf[sizeof(doomed)];
160 sscanf(buffer, "%40s", tmpbuf);
161 obd_str2uuid(&doomed, tmpbuf);
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);
172 spin_unlock(&obd->obd_dev_lock);
174 if (doomed_exp == NULL) {
175 CERROR("can't disconnect %s: no export found\n",
178 CERROR("evicting %s at adminstrative request\n",
180 ptlrpc_fail_export(doomed_exp);
181 class_export_put(doomed_exp);
186 static int lprocfs_mds_wr_config_update(struct file *file, const char *buffer,
187 unsigned long count, void *data)
189 struct obd_device *obd = data;
192 RETURN(mds_lov_update_config(obd, 0));
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 },
214 * group hash proc entries handler
216 static int lprocfs_wr_group_info(struct file *file, const char *buffer,
217 unsigned long count, void *data)
225 gid_t gids_local[NGROUPS_SMALL];
228 if (count != sizeof(param)) {
229 CERROR("invalid data size %lu\n", count);
232 if (copy_from_user(¶m, buffer, count)) {
233 CERROR("broken downcall\n");
236 if (param.ngroups > NGROUPS_MAX) {
237 CERROR("%d groups?\n", param.ngroups);
241 if (param.ngroups <= NGROUPS_SMALL)
244 OBD_ALLOC(gids, param.ngroups * sizeof(gid_t));
246 CERROR("fail to alloc memory for %d gids\n",
251 if (copy_from_user(gids, param.groups,
252 param.ngroups * sizeof(gid_t))) {
253 CERROR("broken downcall\n");
257 mds_handle_group_downcall(param.err, param.uid,
258 param.ngroups, gids);
261 if (gids && gids != gids_local)
262 OBD_FREE(gids, param.ngroups * sizeof(gid_t));
265 static int lprocfs_rd_expire(char *page, char **start, off_t off, int count,
266 int *eof, void *data)
268 struct mds_grp_hash *hash = __mds_get_global_group_hash();
271 return snprintf(page, count, "%d\n", hash->gh_entry_expire);
273 static int lprocfs_wr_expire(struct file *file, const char *buffer,
274 unsigned long count, void *data)
276 struct mds_grp_hash *hash = __mds_get_global_group_hash();
279 if (copy_from_user(buf, buffer, min(count, 32UL)))
282 sscanf(buf, "%d", &hash->gh_entry_expire);
285 static int lprocfs_rd_ac_expire(char *page, char **start, off_t off, int count,
286 int *eof, void *data)
288 struct mds_grp_hash *hash = __mds_get_global_group_hash();
291 return snprintf(page, count, "%d\n", hash->gh_acquire_expire);
293 static int lprocfs_wr_ac_expire(struct file *file, const char *buffer,
294 unsigned long count, void *data)
296 struct mds_grp_hash *hash = __mds_get_global_group_hash();
299 if (copy_from_user(buf, buffer, min(count, 32UL)))
302 sscanf(buf, "%d", &hash->gh_acquire_expire);
305 static int lprocfs_rd_hash_upcall(char *page, char **start, off_t off, int count,
306 int *eof, void *data)
308 struct mds_grp_hash *hash = __mds_get_global_group_hash();
311 return snprintf(page, count, "%s\n", hash->gh_upcall);
313 static int lprocfs_wr_hash_upcall(struct file *file, const char *buffer,
314 unsigned long count, void *data)
316 struct mds_grp_hash *hash = __mds_get_global_group_hash();
318 if (count < MDSGRP_UPCALL_MAXPATH) {
319 sscanf(buffer, "%1024s", hash->gh_upcall);
320 hash->gh_upcall[MDSGRP_UPCALL_MAXPATH-1] = 0;
324 static int lprocfs_wr_hash_flush(struct file *file, const char *buffer,
325 unsigned long count, void *data)
327 mds_group_hash_flush_idle();
330 static int lprocfs_rd_allow_setgroups(char *page, char **start, off_t off,
331 int count, int *eof, void *data)
333 struct mds_grp_hash *hash = __mds_get_global_group_hash();
336 return snprintf(page, count, "%d\n", hash->gh_allow_setgroups);
338 static int lprocfs_wr_allow_setgroups(struct file *file, const char *buffer,
339 unsigned long count, void *data)
341 struct mds_grp_hash *hash = __mds_get_global_group_hash();
345 if (copy_from_user(buf, buffer, min(count, 8UL)))
348 sscanf(buf, "%d", &val);
349 hash->gh_allow_setgroups = (val != 0);
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},
366 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
367 { "uuid", lprocfs_rd_uuid, 0, 0 },
371 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
372 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
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}};
383 LPROCFS_INIT_MULTI_VARS(lprocfs_array_vars,
384 (sizeof(lprocfs_array_vars) /
385 sizeof(struct lprocfs_static_vars)))