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"
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} };
42 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off,
43 int count, int *eof, void *data)
45 struct obd_device* obd = (struct obd_device *)data;
48 LASSERT(obd->u.mds.mds_vfsmnt->mnt_devname);
51 return snprintf(page, count, "%s\n",
52 obd->u.mds.mds_vfsmnt->mnt_devname);
55 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
56 unsigned long count, void *data)
58 struct obd_device *obd = data;
59 struct obd_export *doomed_exp = NULL;
60 struct obd_uuid doomed;
62 char tmpbuf[sizeof(doomed)];
64 sscanf(buffer, "%40s", tmpbuf);
65 obd_str2uuid(&doomed, tmpbuf);
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);
76 spin_unlock(&obd->obd_dev_lock);
78 if (doomed_exp == NULL) {
79 CERROR("can't disconnect %s: no export found\n",
82 CERROR("evicting %s at adminstrative request\n",
84 ptlrpc_fail_export(doomed_exp);
85 class_export_put(doomed_exp);
90 static int lprocfs_mds_wr_config_update(struct file *file, const char *buffer,
91 unsigned long count, void *data)
93 struct obd_device *obd = data;
96 RETURN(mds_dt_update_config(obd, 0));
99 static int lprocfs_rd_filesopen(char *page, char **start, off_t off,
100 int count, int *eof, void *data)
102 struct obd_device *obd = data;
103 LASSERT(obd != NULL);
106 return snprintf(page, count, "%d\n",
107 atomic_read(&obd->u.mds.mds_open_count));
110 static int lprocfs_rd_last_fid(char *page, char **start, off_t off,
111 int count, int *eof, void *data)
113 struct obd_device *obd = (struct obd_device *)data;
114 struct mds_obd *mds = &obd->u.mds;
117 spin_lock(&mds->mds_last_fid_lock);
118 last_fid = mds->mds_last_fid;
119 spin_unlock(&mds->mds_last_fid_lock);
122 return snprintf(page, count, LPD64"\n", last_fid);
125 static int lprocfs_rd_group(char *page, char **start, off_t off,
126 int count, int *eof, void *data)
128 struct obd_device *obd = (struct obd_device *)data;
129 struct mds_obd *mds = &obd->u.mds;
132 return snprintf(page, count, "%lu\n",
133 (unsigned long)mds->mds_num);
136 static int lprocfs_rd_capa(char *page, char **start, off_t off,
137 int count, int *eof, void *data)
139 struct obd_device *obd = (struct obd_device *)data;
140 LASSERT(obd != NULL);
142 return snprintf(page, count, "%d\n",
143 obd->u.mds.mds_capa_stat);
146 static int lprocfs_wr_capa(struct file *file, const char *buffer,
147 unsigned long count, void *data)
149 struct obd_device *obd = data;
152 rc = lprocfs_write_helper(buffer, count, &val);
156 obd->u.mds.mds_capa_stat = val;
160 static int lprocfs_rd_capa_timeout(char *page, char **start, off_t off,
161 int count, int *eof, void *data)
163 struct obd_device *obd = (struct obd_device *)data;
164 LASSERT(obd != NULL);
166 return snprintf(page, count, "%lu\n",
167 obd->u.mds.mds_capa_timeout);
170 static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
171 unsigned long count, void *data)
173 struct obd_device *obd = data;
176 rc = lprocfs_write_helper(buffer, count, &val);
180 obd->u.mds.mds_capa_timeout = val;
184 static int lprocfs_rd_capa_key_timeout(char *page, char **start, off_t off,
185 int count, int *eof, void *data)
187 struct obd_device *obd = (struct obd_device *)data;
188 LASSERT(obd != NULL);
190 return snprintf(page, count, "%lu\n",
191 obd->u.mds.mds_capa_key_timeout);
194 static int lprocfs_wr_capa_key_timeout(struct file *file, const char *buffer,
195 unsigned long count, void *data)
197 struct obd_device *obd = data;
200 rc = lprocfs_write_helper(buffer, count, &val);
204 obd->u.mds.mds_capa_key_timeout = val;
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 },
235 * LSD proc entry handlers
237 static int lprocfs_wr_lsd_downcall(struct file *file, const char *buffer,
238 unsigned long count, void *data)
240 struct upcall_cache *cache = __mds_get_global_lsd_cache();
241 struct lsd_downcall_args param;
242 gid_t gids_local[NGROUPS_SMALL];
245 if (count != sizeof(param)) {
246 CERROR("invalid data size %lu\n", count);
247 goto do_err_downcall;
249 if (copy_from_user(¶m, buffer, count)) {
250 CERROR("broken downcall\n");
251 goto do_err_downcall;
255 CERROR("LSD downcall indicate error %d\n", param.err);
259 if (param.ngroups > NGROUPS_MAX) {
260 CERROR("%d groups too big\n", param.ngroups);
261 goto do_err_downcall;
264 if (param.ngroups <= NGROUPS_SMALL)
267 OBD_ALLOC(gids, param.ngroups * sizeof(gid_t));
269 CERROR("fail to alloc memory for %d gids\n",
271 goto do_err_downcall;
274 if (copy_from_user(gids, param.groups,
275 param.ngroups * sizeof(gid_t))) {
276 CERROR("broken downcall\n");
277 goto do_err_downcall;
283 upcall_cache_downcall(cache, (__u64) param.uid, ¶m);
285 if (gids && gids != gids_local)
286 OBD_FREE(gids, param.ngroups * sizeof(gid_t));
294 static int lprocfs_rd_lsd_expire(char *page, char **start, off_t off, int count,
295 int *eof, void *data)
297 struct upcall_cache *cache= __mds_get_global_lsd_cache();
300 return snprintf(page, count, "%lu\n", cache->uc_entry_expire);
302 static int lprocfs_wr_lsd_expire(struct file *file, const char *buffer,
303 unsigned long count, void *data)
305 struct upcall_cache *cache= __mds_get_global_lsd_cache();
308 if (copy_from_user(buf, buffer, min(count, 32UL)))
311 sscanf(buf, "%lu", &cache->uc_entry_expire);
315 static int lprocfs_rd_lsd_ac_expire(char *page, char **start, off_t off,
316 int count, int *eof, void *data)
318 struct upcall_cache *cache= __mds_get_global_lsd_cache();
321 return snprintf(page, count, "%lu\n", cache->uc_acquire_expire);
323 static int lprocfs_wr_lsd_ac_expire(struct file *file, const char *buffer,
324 unsigned long count, void *data)
326 struct upcall_cache *cache= __mds_get_global_lsd_cache();
329 if (copy_from_user(buf, buffer, min(count, 32UL)))
332 sscanf(buf, "%lu", &cache->uc_acquire_expire);
336 static int lprocfs_rd_lsd_upcall(char *page, char **start, off_t off, int count,
337 int *eof, void *data)
339 struct upcall_cache *cache= __mds_get_global_lsd_cache();
342 return snprintf(page, count, "%s\n", cache->uc_upcall);
344 static int lprocfs_wr_lsd_upcall(struct file *file, const char *buffer,
345 unsigned long count, void *data)
347 struct upcall_cache *cache= __mds_get_global_lsd_cache();
349 if (count < UC_CACHE_UPCALL_MAXPATH) {
350 sscanf(buffer, "%1024s", cache->uc_upcall);
351 cache->uc_upcall[UC_CACHE_UPCALL_MAXPATH - 1] = 0;
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)
363 if (copy_from_user(buf, buffer, min(count, 32UL)))
366 sscanf(buf, "%d", &uid);
370 lgss_svc_cache_flush(uid);
376 * remote acl proc handling
378 static int lprocfs_rd_lacl_upcall(char *page, char **start, off_t off,
379 int count, int *eof, void *data)
381 struct upcall_cache *cache = __mds_get_global_rmtacl_upcall_cache();
384 return snprintf(page, count, "%s\n", cache->uc_upcall);
387 static int lprocfs_wr_lacl_upcall(struct file *file, const char *buffer,
388 unsigned long count, void *data)
390 struct upcall_cache *cache = __mds_get_global_rmtacl_upcall_cache();
392 if (count < UC_CACHE_UPCALL_MAXPATH) {
393 sscanf(buffer, "%1024s", cache->uc_upcall);
394 cache->uc_upcall[UC_CACHE_UPCALL_MAXPATH - 1] = 0;
399 static int lprocfs_wr_lacl_downcall(struct file *file, const char *buffer,
400 unsigned long count, void *data)
402 struct upcall_cache *cache = __mds_get_global_rmtacl_upcall_cache();
403 struct rmtacl_downcall_args param;
405 if (count != sizeof(param)) {
406 CERROR("invalid data size %lu\n", count);
407 goto do_err_downcall;
409 if (copy_from_user(¶m, buffer, count)) {
410 CERROR("broken downcall\n");
411 goto do_err_downcall;
415 upcall_cache_downcall(cache, param.key, ¶m);
419 memset(¶m, 0, sizeof(param));
420 param.status = -EINVAL;
424 struct lprocfs_vars lprocfs_mds_module_vars[] = {
425 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
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},
436 { "lacl_upcall", lprocfs_rd_lacl_upcall,
437 lprocfs_wr_lacl_upcall, 0},
438 { "lacl_downcall", 0, lprocfs_wr_lacl_downcall, 0},
442 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
443 { "uuid", lprocfs_rd_uuid, 0, 0 },
447 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
448 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
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}};
458 LPROCFS_INIT_MULTI_VARS(lprocfs_array_vars,
459 (sizeof(lprocfs_array_vars) /
460 sizeof(struct lprocfs_static_vars)))