1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_CLASS
38 #include <linux/version.h>
39 #include <asm/statfs.h>
41 #include <obd_class.h>
42 #include <lprocfs_status.h>
43 #include "mds_internal.h"
46 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
49 struct obd_device* obd = (struct obd_device *)data;
52 LASSERT(obd->u.mds.mds_vfsmnt->mnt_devname);
55 return snprintf(page, count, "%s\n",obd->u.mds.mds_vfsmnt->mnt_devname);
58 static int lprocfs_mds_rd_evictostnids(char *page, char **start, off_t off,
59 int count, int *eof, void *data)
61 struct obd_device* obd = (struct obd_device *)data;
65 return snprintf(page, count, "%d\n", obd->u.mds.mds_evict_ost_nids);
68 static int lprocfs_mds_wr_evictostnids(struct file *file, const char *buffer,
69 unsigned long count, void *data)
71 struct obd_device *obd = data;
74 rc = lprocfs_write_helper(buffer, count, &val);
78 obd->u.mds.mds_evict_ost_nids = !!val;
83 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
84 unsigned long count, void *data)
86 struct obd_device *obd = data;
87 struct mds_obd *mds = &obd->u.mds;
88 char tmpbuf[sizeof(struct obd_uuid)];
89 struct ptlrpc_request_set *set;
92 sscanf(buffer, "%40s", tmpbuf);
94 if (strncmp(tmpbuf, "nid:", 4) != 0)
95 return lprocfs_wr_evict_client(file, buffer, count, data);
97 set = ptlrpc_prep_set();
101 if (obd->u.mds.mds_evict_ost_nids) {
102 rc = obd_set_info_async(mds->mds_osc_exp,
103 sizeof(KEY_EVICT_BY_NID),
104 KEY_EVICT_BY_NID, strlen(tmpbuf + 4) + 1,
107 CERROR("Failed to evict nid %s from OSTs: rc %d\n",
110 ptlrpc_check_set(set);
113 /* See the comments in function lprocfs_wr_evict_client()
114 * in ptlrpc/lproc_ptlrpc.c for details. - jay */
118 obd_export_evict_by_nid(obd, tmpbuf+4);
121 rc = ptlrpc_set_wait(set);
123 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
129 ptlrpc_set_destroy(set);
134 static int lprocfs_wr_group_info(struct file *file, const char *buffer,
135 unsigned long count, void *data)
137 struct obd_device *obd = data;
138 struct mds_obd *mds = &obd->u.mds;
139 struct mds_grp_downcall_data sparam, *param = &sparam;
140 int size = 0, rc = count;
142 if (count < sizeof(param)) {
143 CERROR("%s: invalid data size %lu\n", obd->obd_name, count);
147 if (copy_from_user(param, buffer, sizeof(*param)) ||
148 param->mgd_magic != MDS_GRP_DOWNCALL_MAGIC) {
149 CERROR("%s: MDS group downcall bad params\n", obd->obd_name);
153 if (param->mgd_ngroups > NGROUPS_MAX) {
154 CWARN("%s: uid %u groups %d more than maximum %d\n",
155 obd->obd_name, param->mgd_uid, param->mgd_ngroups,
157 param->mgd_ngroups = NGROUPS_MAX;
160 if (param->mgd_ngroups > 0) {
161 size = offsetof(struct mds_grp_downcall_data,
162 mgd_groups[param->mgd_ngroups]);
163 OBD_ALLOC(param, size);
165 CERROR("%s: fail to alloc %d bytes for uid %u"
166 " with %d groups\n", obd->obd_name, size,
167 sparam.mgd_uid, sparam.mgd_ngroups);
169 param->mgd_ngroups = 0;
170 } else if (copy_from_user(param, buffer, size)) {
171 CERROR("%s: uid %u bad supplementary group data\n",
172 obd->obd_name, sparam.mgd_uid);
173 OBD_FREE(param, size);
175 param->mgd_ngroups = 0;
178 rc = upcall_cache_downcall(mds->mds_group_hash, param->mgd_err,
179 param->mgd_uid, param->mgd_gid,
180 param->mgd_ngroups, param->mgd_groups);
182 if (param && param != &sparam)
183 OBD_FREE(param, size);
188 static int lprocfs_rd_group_expire(char *page, char **start, off_t off,
189 int count, int *eof, void *data)
191 struct obd_device *obd = data;
194 return snprintf(page, count, "%lu\n",
195 obd->u.mds.mds_group_hash->uc_entry_expire / HZ);
198 static int lprocfs_wr_group_expire(struct file *file, const char *buffer,
199 unsigned long count, void *data)
201 struct obd_device *obd = data;
204 rc = lprocfs_write_helper(buffer, count, &val);
209 obd->u.mds.mds_group_hash->uc_entry_expire = val * HZ;
211 CERROR("invalid expire time %u for group cache\n", val);
216 static int lprocfs_rd_group_acquire_expire(char *page, char **start, off_t off,
217 int count, int *eof, void *data)
219 struct obd_device *obd = data;
222 return snprintf(page, count, "%lu\n",
223 obd->u.mds.mds_group_hash->uc_acquire_expire / HZ);
226 static int lprocfs_wr_group_acquire_expire(struct file *file,const char *buffer,
227 unsigned long count, void *data)
229 struct obd_device *obd = data;
232 rc = lprocfs_write_helper(buffer, count, &val);
237 obd->u.mds.mds_group_hash->uc_acquire_expire = val * HZ;
242 static int lprocfs_rd_group_upcall(char *page, char **start, off_t off,
243 int count, int *eof, void *data)
245 struct obd_device *obd = data;
248 return snprintf(page, count, "%s\n",
249 obd->u.mds.mds_group_hash->uc_upcall);
252 static int lprocfs_wr_group_upcall(struct file *file, const char *buffer,
253 unsigned long count, void *data)
255 struct obd_device *obd = data;
256 struct upcall_cache *hash = obd->u.mds.mds_group_hash;
257 char kernbuf[UC_CACHE_UPCALL_MAXPATH] = { '\0' };
259 if (count >= UC_CACHE_UPCALL_MAXPATH) {
260 CERROR("%s: group upcall too long\n", obd->obd_name);
264 if (copy_from_user(kernbuf, buffer,
265 min(count, UC_CACHE_UPCALL_MAXPATH - 1)))
268 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
269 sscanf(kernbuf, "%s", hash->uc_upcall);
271 if (strcmp(hash->uc_name, obd->obd_name) != 0)
272 CWARN("%s: write to upcall name %s for MDS %s\n",
273 obd->obd_name, hash->uc_upcall, obd->obd_name);
274 CWARN("%s: group upcall set to %s\n", obd->obd_name, hash->uc_upcall);
279 static int lprocfs_wr_group_flush(struct file *file, const char *buffer,
280 unsigned long count, void *data)
282 struct obd_device *obd = data;
284 upcall_cache_flush_idle(obd->u.mds.mds_group_hash);
289 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
290 unsigned long count, void *data)
292 struct obd_device *obd = data;
293 struct mds_obd *mds = &obd->u.mds;
294 char kernbuf[20], *end;
295 unsigned long diff = 0;
297 if (count > (sizeof(kernbuf) - 1))
300 if (copy_from_user(kernbuf, buffer, count))
303 kernbuf[count] = '\0';
305 diff = simple_strtoul(kernbuf, &end, 0);
309 mds->mds_atime_diff = diff;
313 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
314 int count, int *eof, void *data)
316 struct obd_device *obd = data;
317 struct mds_obd *mds = &obd->u.mds;
320 return snprintf(page, count, "%lu\n", mds->mds_atime_diff);
323 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
324 { "uuid", lprocfs_rd_uuid, 0, 0 },
325 { "blocksize", lprocfs_rd_blksize, 0, 0 },
326 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
327 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
328 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
329 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
330 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
331 { "fstype", lprocfs_rd_fstype, 0, 0 },
332 { "mntdev", lprocfs_mds_rd_mntdev, 0, 0 },
333 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
334 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
335 { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
336 { "evict_ost_nids", lprocfs_mds_rd_evictostnids,
337 lprocfs_mds_wr_evictostnids, 0 },
338 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
339 #ifdef HAVE_QUOTA_SUPPORT
340 { "quota_bunit_sz", lprocfs_rd_bunit, lprocfs_wr_bunit, 0 },
341 { "quota_btune_sz", lprocfs_rd_btune, lprocfs_wr_btune, 0 },
342 { "quota_iunit_sz", lprocfs_rd_iunit, lprocfs_wr_iunit, 0 },
343 { "quota_itune_sz", lprocfs_rd_itune, lprocfs_wr_itune, 0 },
344 { "quota_type", lprocfs_rd_type, lprocfs_wr_type, 0 },
347 { "group_expire_interval", lprocfs_rd_group_expire,
348 lprocfs_wr_group_expire, 0},
349 { "group_acquire_expire", lprocfs_rd_group_acquire_expire,
350 lprocfs_wr_group_acquire_expire, 0},
351 { "group_upcall", lprocfs_rd_group_upcall,
352 lprocfs_wr_group_upcall, 0},
353 { "group_flush", 0, lprocfs_wr_group_flush, 0},
354 { "group_info", 0, lprocfs_wr_group_info, 0 },
356 { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
360 struct lprocfs_vars lprocfs_mds_module_vars[] = {
361 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
365 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
366 { "uuid", lprocfs_rd_uuid, 0, 0 },
370 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
371 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
375 void mds_counter_incr(struct obd_export *exp, int opcode)
377 if (exp->exp_obd && exp->exp_obd->obd_stats)
378 lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
379 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
380 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
384 void mds_stats_counter_init(struct lprocfs_stats *stats)
386 lprocfs_counter_init(stats, LPROC_MDS_OPEN, 0, "open", "reqs");
387 lprocfs_counter_init(stats, LPROC_MDS_CLOSE, 0, "close", "reqs");
388 lprocfs_counter_init(stats, LPROC_MDS_MKNOD, 0, "mknod", "reqs");
389 lprocfs_counter_init(stats, LPROC_MDS_LINK, 0, "link", "reqs");
390 lprocfs_counter_init(stats, LPROC_MDS_UNLINK, 0, "unlink", "reqs");
391 lprocfs_counter_init(stats, LPROC_MDS_MKDIR, 0, "mkdir", "reqs");
392 lprocfs_counter_init(stats, LPROC_MDS_RMDIR, 0, "rmdir", "reqs");
393 lprocfs_counter_init(stats, LPROC_MDS_RENAME, 0, "rename", "reqs");
394 lprocfs_counter_init(stats, LPROC_MDS_GETXATTR, 0, "getxattr", "reqs");
395 lprocfs_counter_init(stats, LPROC_MDS_SETXATTR, 0, "setxattr", "reqs");
398 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars)
400 lvars->module_vars = lprocfs_mds_module_vars;
401 lvars->obd_vars = lprocfs_mds_obd_vars;
404 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
406 lvars->module_vars = lprocfs_mdt_module_vars;
407 lvars->obd_vars = lprocfs_mdt_obd_vars;