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 the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * You may have signed or agreed to another license before downloading
10 * this software. If so, you are bound by the terms and conditions
11 * of that agreement, and the following does not apply to you. See the
12 * LICENSE file included with this distribution for more information.
14 * If you did not agree to a different license, then this copy of Lustre
15 * is open source software; you can redistribute it and/or modify it
16 * under the terms of version 2 of the GNU General Public License as
17 * published by the Free Software Foundation.
19 * In either case, Lustre is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * license text for more details.
25 #define DEBUG_SUBSYSTEM S_CLASS
27 #include <linux/version.h>
28 #include <asm/statfs.h>
30 #include <obd_class.h>
31 #include <lprocfs_status.h>
32 #include "mds_internal.h"
35 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
38 struct obd_device* obd = (struct obd_device *)data;
41 LASSERT(obd->u.mds.mds_vfsmnt->mnt_devname);
44 return snprintf(page, count, "%s\n",obd->u.mds.mds_vfsmnt->mnt_devname);
47 static int lprocfs_mds_rd_evictostnids(char *page, char **start, off_t off,
48 int count, int *eof, void *data)
50 struct obd_device* obd = (struct obd_device *)data;
54 return snprintf(page, count, "%d\n", obd->u.mds.mds_evict_ost_nids);
57 static int lprocfs_mds_wr_evictostnids(struct file *file, const char *buffer,
58 unsigned long count, void *data)
60 struct obd_device *obd = data;
63 rc = lprocfs_write_helper(buffer, count, &val);
67 obd->u.mds.mds_evict_ost_nids = !!val;
72 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
73 unsigned long count, void *data)
75 struct obd_device *obd = data;
76 struct mds_obd *mds = &obd->u.mds;
77 char tmpbuf[sizeof(struct obd_uuid)];
78 struct ptlrpc_request_set *set;
81 sscanf(buffer, "%40s", tmpbuf);
83 if (strncmp(tmpbuf, "nid:", 4) != 0)
84 return lprocfs_wr_evict_client(file, buffer, count, data);
86 set = ptlrpc_prep_set();
90 if (obd->u.mds.mds_evict_ost_nids) {
91 rc = obd_set_info_async(mds->mds_osc_exp,
92 sizeof(KEY_EVICT_BY_NID),
93 KEY_EVICT_BY_NID, strlen(tmpbuf + 4) + 1,
96 CERROR("Failed to evict nid %s from OSTs: rc %d\n",
99 ptlrpc_check_set(set);
102 /* See the comments in function lprocfs_wr_evict_client()
103 * in ptlrpc/lproc_ptlrpc.c for details. - jay */
107 obd_export_evict_by_nid(obd, tmpbuf+4);
110 rc = ptlrpc_set_wait(set);
112 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
118 ptlrpc_set_destroy(set);
123 static int lprocfs_wr_group_info(struct file *file, const char *buffer,
124 unsigned long count, void *data)
126 struct obd_device *obd = data;
127 struct mds_obd *mds = &obd->u.mds;
128 struct mds_grp_downcall_data sparam, *param = &sparam;
129 int size = 0, rc = count;
131 if (count < sizeof(param)) {
132 CERROR("%s: invalid data size %lu\n", obd->obd_name, count);
136 if (copy_from_user(param, buffer, sizeof(*param)) ||
137 param->mgd_magic != MDS_GRP_DOWNCALL_MAGIC) {
138 CERROR("%s: MDS group downcall bad params\n", obd->obd_name);
142 if (param->mgd_ngroups > NGROUPS_MAX) {
143 CWARN("%s: uid %u groups %d more than maximum %d\n",
144 obd->obd_name, param->mgd_uid, param->mgd_ngroups,
146 param->mgd_ngroups = NGROUPS_MAX;
149 if (param->mgd_ngroups > 0) {
150 size = offsetof(struct mds_grp_downcall_data,
151 mgd_groups[param->mgd_ngroups]);
152 OBD_ALLOC(param, size);
154 CERROR("%s: fail to alloc %d bytes for uid %u"
155 " with %d groups\n", obd->obd_name, size,
156 sparam.mgd_uid, sparam.mgd_ngroups);
158 param->mgd_ngroups = 0;
159 } else if (copy_from_user(param, buffer, size)) {
160 CERROR("%s: uid %u bad supplementary group data\n",
161 obd->obd_name, sparam.mgd_uid);
162 OBD_FREE(param, size);
164 param->mgd_ngroups = 0;
167 rc = upcall_cache_downcall(mds->mds_group_hash, param->mgd_err,
168 param->mgd_uid, param->mgd_gid,
169 param->mgd_ngroups, param->mgd_groups);
171 if (param && param != &sparam)
172 OBD_FREE(param, size);
177 static int lprocfs_rd_group_expire(char *page, char **start, off_t off,
178 int count, int *eof, void *data)
180 struct obd_device *obd = data;
183 return snprintf(page, count, "%lu\n",
184 obd->u.mds.mds_group_hash->uc_entry_expire / HZ);
187 static int lprocfs_wr_group_expire(struct file *file, const char *buffer,
188 unsigned long count, void *data)
190 struct obd_device *obd = data;
193 rc = lprocfs_write_helper(buffer, count, &val);
198 obd->u.mds.mds_group_hash->uc_entry_expire = val * HZ;
200 CERROR("invalid expire time %u for group cache\n", val);
205 static int lprocfs_rd_group_acquire_expire(char *page, char **start, off_t off,
206 int count, int *eof, void *data)
208 struct obd_device *obd = data;
211 return snprintf(page, count, "%lu\n",
212 obd->u.mds.mds_group_hash->uc_acquire_expire / HZ);
215 static int lprocfs_wr_group_acquire_expire(struct file *file,const char *buffer,
216 unsigned long count, void *data)
218 struct obd_device *obd = data;
221 rc = lprocfs_write_helper(buffer, count, &val);
226 obd->u.mds.mds_group_hash->uc_acquire_expire = val * HZ;
231 static int lprocfs_rd_group_upcall(char *page, char **start, off_t off,
232 int count, int *eof, void *data)
234 struct obd_device *obd = data;
237 return snprintf(page, count, "%s\n",
238 obd->u.mds.mds_group_hash->uc_upcall);
241 static int lprocfs_wr_group_upcall(struct file *file, const char *buffer,
242 unsigned long count, void *data)
244 struct obd_device *obd = data;
245 struct upcall_cache *hash = obd->u.mds.mds_group_hash;
246 char kernbuf[UC_CACHE_UPCALL_MAXPATH] = { '\0' };
248 if (count >= UC_CACHE_UPCALL_MAXPATH) {
249 CERROR("%s: group upcall too long\n", obd->obd_name);
253 if (copy_from_user(kernbuf, buffer,
254 min(count, UC_CACHE_UPCALL_MAXPATH - 1)))
257 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
258 sscanf(kernbuf, "%s", hash->uc_upcall);
260 if (strcmp(hash->uc_name, obd->obd_name) != 0)
261 CWARN("%s: write to upcall name %s for MDS %s\n",
262 obd->obd_name, hash->uc_upcall, obd->obd_name);
263 CWARN("%s: group upcall set to %s\n", obd->obd_name, hash->uc_upcall);
268 static int lprocfs_wr_group_flush(struct file *file, const char *buffer,
269 unsigned long count, void *data)
271 struct obd_device *obd = data;
273 upcall_cache_flush_idle(obd->u.mds.mds_group_hash);
278 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
279 unsigned long count, void *data)
281 struct obd_device *obd = data;
282 struct mds_obd *mds = &obd->u.mds;
283 char kernbuf[20], *end;
284 unsigned long diff = 0;
286 if (count > (sizeof(kernbuf) - 1))
289 if (copy_from_user(kernbuf, buffer, count))
292 kernbuf[count] = '\0';
294 diff = simple_strtoul(kernbuf, &end, 0);
298 mds->mds_atime_diff = diff;
302 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
303 int count, int *eof, void *data)
305 struct obd_device *obd = data;
306 struct mds_obd *mds = &obd->u.mds;
309 return snprintf(page, count, "%lu\n", mds->mds_atime_diff);
312 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
313 { "uuid", lprocfs_rd_uuid, 0, 0 },
314 { "blocksize", lprocfs_rd_blksize, 0, 0 },
315 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
316 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
317 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
318 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
319 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
320 { "fstype", lprocfs_rd_fstype, 0, 0 },
321 { "mntdev", lprocfs_mds_rd_mntdev, 0, 0 },
322 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
323 { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
324 { "evict_ost_nids", lprocfs_mds_rd_evictostnids,
325 lprocfs_mds_wr_evictostnids, 0 },
326 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
327 #ifdef HAVE_QUOTA_SUPPORT
328 { "quota_bunit_sz", lprocfs_rd_bunit, lprocfs_wr_bunit, 0 },
329 { "quota_btune_sz", lprocfs_rd_btune, lprocfs_wr_btune, 0 },
330 { "quota_iunit_sz", lprocfs_rd_iunit, lprocfs_wr_iunit, 0 },
331 { "quota_itune_sz", lprocfs_rd_itune, lprocfs_wr_itune, 0 },
332 { "quota_type", lprocfs_rd_type, lprocfs_wr_type, 0 },
335 { "group_expire_interval", lprocfs_rd_group_expire,
336 lprocfs_wr_group_expire, 0},
337 { "group_acquire_expire", lprocfs_rd_group_acquire_expire,
338 lprocfs_wr_group_acquire_expire, 0},
339 { "group_upcall", lprocfs_rd_group_upcall,
340 lprocfs_wr_group_upcall, 0},
341 { "group_flush", 0, lprocfs_wr_group_flush, 0},
342 { "group_info", 0, lprocfs_wr_group_info, 0 },
344 { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
348 struct lprocfs_vars lprocfs_mds_module_vars[] = {
349 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
353 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
354 { "uuid", lprocfs_rd_uuid, 0, 0 },
358 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
359 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
363 void mds_counter_incr(struct obd_export *exp, int opcode)
365 if (exp->exp_obd && exp->exp_obd->obd_stats)
366 lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
367 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
368 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
372 void mds_stats_counter_init(struct lprocfs_stats *stats)
374 lprocfs_counter_init(stats, LPROC_MDS_OPEN, 0, "open", "reqs");
375 lprocfs_counter_init(stats, LPROC_MDS_CLOSE, 0, "close", "reqs");
376 lprocfs_counter_init(stats, LPROC_MDS_MKNOD, 0, "mknod", "reqs");
377 lprocfs_counter_init(stats, LPROC_MDS_LINK, 0, "link", "reqs");
378 lprocfs_counter_init(stats, LPROC_MDS_UNLINK, 0, "unlink", "reqs");
379 lprocfs_counter_init(stats, LPROC_MDS_MKDIR, 0, "mkdir", "reqs");
380 lprocfs_counter_init(stats, LPROC_MDS_RMDIR, 0, "rmdir", "reqs");
381 lprocfs_counter_init(stats, LPROC_MDS_RENAME, 0, "rename", "reqs");
382 lprocfs_counter_init(stats, LPROC_MDS_GETXATTR, 0, "getxattr", "reqs");
383 lprocfs_counter_init(stats, LPROC_MDS_SETXATTR, 0, "setxattr", "reqs");
386 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars)
388 lvars->module_vars = lprocfs_mds_module_vars;
389 lvars->obd_vars = lprocfs_mds_obd_vars;
392 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
394 lvars->module_vars = lprocfs_mdt_module_vars;
395 lvars->obd_vars = lprocfs_mdt_obd_vars;