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_last_fid(char *page, char **start, off_t off,
100 int count, int *eof, void *data)
102 struct obd_device *obd = (struct obd_device *)data;
103 struct mds_obd *mds = &obd->u.mds;
106 spin_lock(&mds->mds_last_fid_lock);
107 last_fid = mds->mds_last_fid;
108 spin_unlock(&mds->mds_last_fid_lock);
111 return snprintf(page, count, LPD64"\n", last_fid);
114 static int lprocfs_rd_group(char *page, char **start, off_t off,
115 int count, int *eof, void *data)
117 struct obd_device *obd = (struct obd_device *)data;
118 struct mds_obd *mds = &obd->u.mds;
121 return snprintf(page, count, "%lu\n",
122 (unsigned long)mds->mds_num);
125 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
126 { "uuid", lprocfs_rd_uuid, 0, 0 },
127 { "blocksize", lprocfs_rd_blksize, 0, 0 },
128 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
129 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
130 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
131 { "fstype", lprocfs_rd_fstype, 0, 0 },
132 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
133 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
134 { "mntdev", lprocfs_mds_rd_mntdev, 0, 0 },
135 { "last_fid", lprocfs_rd_last_fid, 0, 0 },
136 { "group", lprocfs_rd_group, 0, 0 },
137 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
138 { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
139 { "config_update", 0, lprocfs_mds_wr_config_update, 0 },
140 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
145 * LSD proc entry handlers
147 static int lprocfs_wr_lsd_downcall(struct file *file, const char *buffer,
148 unsigned long count, void *data)
150 struct upcall_cache *cache = __mds_get_global_lsd_cache();
151 struct lsd_downcall_args param;
152 gid_t gids_local[NGROUPS_SMALL];
155 if (count != sizeof(param)) {
156 CERROR("invalid data size %lu\n", count);
159 if (copy_from_user(¶m, buffer, count)) {
160 CERROR("broken downcall\n");
165 CERROR("LSD downcall indicate error %d\n", param.err);
169 if (param.ngroups > NGROUPS_MAX) {
170 CERROR("%d groups?\n", param.ngroups);
175 if (param.ngroups <= NGROUPS_SMALL)
178 OBD_ALLOC(gids, param.ngroups * sizeof(gid_t));
180 CERROR("fail to alloc memory for %d gids\n",
186 if (copy_from_user(gids, param.groups,
187 param.ngroups * sizeof(gid_t))) {
188 CERROR("broken downcall\n");
196 upcall_cache_downcall(cache, (__u64) param.uid, param.err, ¶m);
198 if (gids && gids != gids_local)
199 OBD_FREE(gids, param.ngroups * sizeof(gid_t));
203 static int lprocfs_rd_lsd_expire(char *page, char **start, off_t off, int count,
204 int *eof, void *data)
206 struct upcall_cache *cache= __mds_get_global_lsd_cache();
209 return snprintf(page, count, "%lu\n", cache->uc_entry_expire);
211 static int lprocfs_wr_lsd_expire(struct file *file, const char *buffer,
212 unsigned long count, void *data)
214 struct upcall_cache *cache= __mds_get_global_lsd_cache();
217 if (copy_from_user(buf, buffer, min(count, 32UL)))
220 sscanf(buf, "%lu", &cache->uc_entry_expire);
224 static int lprocfs_rd_lsd_ac_expire(char *page, char **start, off_t off,
225 int count, int *eof, void *data)
227 struct upcall_cache *cache= __mds_get_global_lsd_cache();
230 return snprintf(page, count, "%lu\n", cache->uc_acquire_expire);
232 static int lprocfs_wr_lsd_ac_expire(struct file *file, const char *buffer,
233 unsigned long count, void *data)
235 struct upcall_cache *cache= __mds_get_global_lsd_cache();
238 if (copy_from_user(buf, buffer, min(count, 32UL)))
241 sscanf(buf, "%lu", &cache->uc_acquire_expire);
245 static int lprocfs_rd_lsd_upcall(char *page, char **start, off_t off, int count,
246 int *eof, void *data)
248 struct upcall_cache *cache= __mds_get_global_lsd_cache();
251 return snprintf(page, count, "%s\n", cache->uc_upcall);
253 static int lprocfs_wr_lsd_upcall(struct file *file, const char *buffer,
254 unsigned long count, void *data)
256 struct upcall_cache *cache= __mds_get_global_lsd_cache();
258 if (count < UC_CACHE_UPCALL_MAXPATH) {
259 sscanf(buffer, "%1024s", cache->uc_upcall);
260 cache->uc_upcall[UC_CACHE_UPCALL_MAXPATH - 1] = 0;
265 extern void lgss_svc_cache_flush(__u32 uid);
266 static int lprocfs_wr_lsd_flush(struct file *file, const char *buffer,
267 unsigned long count, void *data)
272 if (copy_from_user(buf, buffer, min(count, 32UL)))
275 sscanf(buf, "%d", &uid);
279 lgss_svc_cache_flush(uid);
284 struct lprocfs_vars lprocfs_mds_module_vars[] = {
285 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
287 { "lsd_expire_interval", lprocfs_rd_lsd_expire,
288 lprocfs_wr_lsd_expire, 0},
289 { "lsd_acquire_expire", lprocfs_rd_lsd_ac_expire,
290 lprocfs_wr_lsd_ac_expire, 0},
291 { "lsd_upcall", lprocfs_rd_lsd_upcall,
292 lprocfs_wr_lsd_upcall, 0},
293 { "lsd_flush", 0, lprocfs_wr_lsd_flush, 0},
294 { "lsd_downcall", 0, lprocfs_wr_lsd_downcall, 0},
298 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
299 { "uuid", lprocfs_rd_uuid, 0, 0 },
303 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
304 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
309 struct lprocfs_static_vars lprocfs_array_vars[] = { {lprocfs_mds_module_vars,
310 lprocfs_mds_obd_vars},
311 {lprocfs_mdt_module_vars,
312 lprocfs_mdt_obd_vars}};
314 LPROCFS_INIT_MULTI_VARS(lprocfs_array_vars,
315 (sizeof(lprocfs_array_vars) /
316 sizeof(struct lprocfs_static_vars)))