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 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
29 #include <asm/statfs.h>
31 #include <linux/obd.h>
32 #include <linux/obd_class.h>
33 #include <linux/lprocfs_status.h>
34 #include "mds_internal.h"
37 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
40 struct obd_device* obd = (struct obd_device *)data;
43 LASSERT(obd->u.mds.mds_vfsmnt->mnt_devname);
46 return snprintf(page, count, "%s\n",obd->u.mds.mds_vfsmnt->mnt_devname);
49 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
50 unsigned long count, void *data)
52 struct obd_device *obd = data;
53 struct mds_obd *mds = &obd->u.mds;
54 char tmpbuf[sizeof(struct obd_uuid)];
57 sscanf(buffer, "%40s", tmpbuf);
59 if (strncmp(tmpbuf, "nid:", 4) != 0)
60 return lprocfs_wr_evict_client(file, buffer, count, data);
62 obd_export_evict_by_nid(obd, tmpbuf+4);
64 rc = obd_set_info(mds->mds_osc_exp, strlen("evict_by_nid"),
65 "evict_by_nid", strlen(tmpbuf + 4) + 1, tmpbuf + 4);
67 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
73 static int lprocfs_wr_group_info(struct file *file, const char *buffer,
74 unsigned long count, void *data)
76 struct obd_device *obd = data;
77 struct mds_obd *mds = &obd->u.mds;
78 struct mds_grp_downcall_data sparam, *param = &sparam;
79 int size = 0, rc = count;
81 if (count < sizeof(param)) {
82 CERROR("%s: invalid data size %lu\n", obd->obd_name, count);
86 if (copy_from_user(param, buffer, sizeof(*param)) ||
87 param->mgd_magic != MDS_GRP_DOWNCALL_MAGIC) {
88 CERROR("%s: MDS group downcall bad params\n", obd->obd_name);
92 if (param->mgd_ngroups > NGROUPS_MAX) {
93 CWARN("%s: uid %u groups %d more than maximum %d\n",
94 obd->obd_name, param->mgd_uid, param->mgd_ngroups,
96 param->mgd_ngroups = NGROUPS_MAX;
99 if (param->mgd_ngroups > 0) {
100 size = offsetof(struct mds_grp_downcall_data,
101 mgd_groups[param->mgd_ngroups]);
102 OBD_ALLOC(param, size);
104 CERROR("%s: fail to alloc %d bytes for uid %u"
105 " with %d groups\n", obd->obd_name, size,
106 sparam.mgd_uid, sparam.mgd_ngroups);
108 param->mgd_ngroups = 0;
109 } else if (copy_from_user(param, buffer, size)) {
110 CERROR("%s: uid %u bad supplementary group data\n",
111 obd->obd_name, sparam.mgd_uid);
112 OBD_FREE(param, size);
114 param->mgd_ngroups = 0;
117 rc = upcall_cache_downcall(mds->mds_group_hash, param->mgd_err,
118 param->mgd_uid, param->mgd_gid,
119 param->mgd_ngroups, param->mgd_groups);
121 if (param && param != &sparam)
122 OBD_FREE(param, size);
127 static int lprocfs_rd_group_expire(char *page, char **start, off_t off,
128 int count, int *eof, void *data)
130 struct obd_device *obd = data;
133 return snprintf(page, count, "%lu\n",
134 obd->u.mds.mds_group_hash->uc_entry_expire / HZ);
137 static int lprocfs_wr_group_expire(struct file *file, const char *buffer,
138 unsigned long count, void *data)
140 struct obd_device *obd = data;
143 rc = lprocfs_write_helper(buffer, count, &val);
148 obd->u.mds.mds_group_hash->uc_entry_expire = val * HZ;
150 CERROR("invalid expire time %u for group cache\n", val);
155 static int lprocfs_rd_group_acquire_expire(char *page, char **start, off_t off,
156 int count, int *eof, void *data)
158 struct obd_device *obd = data;
161 return snprintf(page, count, "%lu\n",
162 obd->u.mds.mds_group_hash->uc_acquire_expire / HZ);
165 static int lprocfs_wr_group_acquire_expire(struct file *file,const char *buffer,
166 unsigned long count, void *data)
168 struct obd_device *obd = data;
171 rc = lprocfs_write_helper(buffer, count, &val);
176 obd->u.mds.mds_group_hash->uc_acquire_expire = val * HZ;
181 static int lprocfs_rd_group_upcall(char *page, char **start, off_t off,
182 int count, int *eof, void *data)
184 struct obd_device *obd = data;
187 return snprintf(page, count, "%s\n",
188 obd->u.mds.mds_group_hash->uc_upcall);
191 static int lprocfs_wr_group_upcall(struct file *file, const char *buffer,
192 unsigned long count, void *data)
194 struct obd_device *obd = data;
195 struct upcall_cache *hash = obd->u.mds.mds_group_hash;
196 char kernbuf[UC_CACHE_UPCALL_MAXPATH] = { '\0' };
198 if (count >= UC_CACHE_UPCALL_MAXPATH) {
199 CERROR("%s: group upcall too long\n", obd->obd_name);
203 if (copy_from_user(kernbuf, buffer,
204 min(count, UC_CACHE_UPCALL_MAXPATH - 1)))
207 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
208 sscanf(kernbuf, "%s", hash->uc_upcall);
210 if (strcmp(hash->uc_name, obd->obd_name) != 0)
211 CWARN("%s: write to upcall name %s for MDS %s\n",
212 obd->obd_name, hash->uc_upcall, obd->obd_name);
213 CWARN("%s: group upcall set to %s\n", obd->obd_name, hash->uc_upcall);
218 static int lprocfs_wr_group_flush(struct file *file, const char *buffer,
219 unsigned long count, void *data)
221 struct obd_device *obd = data;
223 upcall_cache_flush_idle(obd->u.mds.mds_group_hash);
227 #ifdef HAVE_QUOTA_SUPPORT
228 static int lprocfs_mds_rd_bunit(char *page, char **start, off_t off, int count,
229 int *eof, void *data)
231 struct obd_device *obd = (struct obd_device *)data;
232 LASSERT(obd != NULL);
234 return snprintf(page, count, "%lu\n",
235 obd->u.obt.obt_qctxt.lqc_bunit_sz);
238 static int lprocfs_mds_rd_iunit(char *page, char **start, off_t off, int count,
239 int *eof, void *data)
241 struct obd_device *obd = (struct obd_device *)data;
242 LASSERT(obd != NULL);
244 return snprintf(page, count, "%lu\n",
245 obd->u.obt.obt_qctxt.lqc_iunit_sz);
248 static int lprocfs_mds_wr_bunit(struct file *file, const char *buffer,
249 unsigned long count, void *data)
251 struct obd_device *obd = (struct obd_device *)data;
253 LASSERT(obd != NULL);
255 rc = lprocfs_write_helper(buffer, count, &val);
259 if (val % QUOTABLOCK_SIZE ||
260 val <= obd->u.obt.obt_qctxt.lqc_btune_sz)
263 obd->u.obt.obt_qctxt.lqc_bunit_sz = val;
267 static int lprocfs_mds_wr_iunit(struct file *file, const char *buffer,
268 unsigned long count, void *data)
270 struct obd_device *obd = (struct obd_device *)data;
272 LASSERT(obd != NULL);
274 rc = lprocfs_write_helper(buffer, count, &val);
278 if (val <= obd->u.obt.obt_qctxt.lqc_itune_sz)
281 obd->u.obt.obt_qctxt.lqc_iunit_sz = val;
285 static int lprocfs_mds_rd_btune(char *page, char **start, off_t off, int count,
286 int *eof, void *data)
288 struct obd_device *obd = (struct obd_device *)data;
289 LASSERT(obd != NULL);
291 return snprintf(page, count, "%lu\n",
292 obd->u.obt.obt_qctxt.lqc_btune_sz);
295 static int lprocfs_mds_rd_itune(char *page, char **start, off_t off, int count,
296 int *eof, void *data)
298 struct obd_device *obd = (struct obd_device *)data;
299 LASSERT(obd != NULL);
301 return snprintf(page, count, "%lu\n",
302 obd->u.obt.obt_qctxt.lqc_itune_sz);
305 static int lprocfs_mds_wr_btune(struct file *file, const char *buffer,
306 unsigned long count, void *data)
308 struct obd_device *obd = (struct obd_device *)data;
310 LASSERT(obd != NULL);
312 rc = lprocfs_write_helper(buffer, count, &val);
316 if (val <= QUOTABLOCK_SIZE * MIN_QLIMIT || val % QUOTABLOCK_SIZE ||
317 val >= obd->u.obt.obt_qctxt.lqc_bunit_sz)
320 obd->u.obt.obt_qctxt.lqc_btune_sz = val;
324 static int lprocfs_mds_wr_itune(struct file *file, const char *buffer,
325 unsigned long count, void *data)
327 struct obd_device *obd = (struct obd_device *)data;
329 LASSERT(obd != NULL);
331 rc = lprocfs_write_helper(buffer, count, &val);
335 if (val <= MIN_QLIMIT ||
336 val >= obd->u.obt.obt_qctxt.lqc_iunit_sz)
339 obd->u.obt.obt_qctxt.lqc_itune_sz = val;
344 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
345 unsigned long count, void *data)
347 struct obd_device *obd = data;
348 struct mds_obd *mds = &obd->u.mds;
349 char kernbuf[20], *end;
350 unsigned long diff = 0;
352 if (count > (sizeof(kernbuf) - 1))
355 if (copy_from_user(kernbuf, buffer, count))
358 kernbuf[count] = '\0';
360 diff = simple_strtoul(kernbuf, &end, 0);
364 mds->mds_atime_diff = diff;
368 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
369 int count, int *eof, void *data)
371 struct obd_device *obd = data;
372 struct mds_obd *mds = &obd->u.mds;
375 return snprintf(page, count, "%lu\n", mds->mds_atime_diff);
378 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
379 { "uuid", lprocfs_rd_uuid, 0, 0 },
380 { "blocksize", lprocfs_rd_blksize, 0, 0 },
381 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
382 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
383 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
384 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
385 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
386 { "fstype", lprocfs_rd_fstype, 0, 0 },
387 { "mntdev", lprocfs_mds_rd_mntdev, 0, 0 },
388 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
389 { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
390 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
391 #ifdef HAVE_QUOTA_SUPPORT
392 { "quota_bunit_sz", lprocfs_mds_rd_bunit, lprocfs_mds_wr_bunit, 0 },
393 { "quota_btune_sz", lprocfs_mds_rd_btune, lprocfs_mds_wr_btune, 0 },
394 { "quota_iunit_sz", lprocfs_mds_rd_iunit, lprocfs_mds_wr_iunit, 0 },
395 { "quota_itune_sz", lprocfs_mds_rd_itune, lprocfs_mds_wr_itune, 0 },
397 { "group_expire_interval", lprocfs_rd_group_expire,
398 lprocfs_wr_group_expire, 0},
399 { "group_acquire_expire", lprocfs_rd_group_acquire_expire,
400 lprocfs_wr_group_acquire_expire, 0},
401 { "group_upcall", lprocfs_rd_group_upcall,
402 lprocfs_wr_group_upcall, 0},
403 { "group_flush", 0, lprocfs_wr_group_flush, 0},
404 { "group_info", 0, lprocfs_wr_group_info, 0 },
405 { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
409 struct lprocfs_vars lprocfs_mds_module_vars[] = {
410 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
414 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
415 { "uuid", lprocfs_rd_uuid, 0, 0 },
419 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
420 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
424 LPROCFS_INIT_VARS(mds, lprocfs_mds_module_vars, lprocfs_mds_obd_vars);
425 LPROCFS_INIT_VARS(mdt, lprocfs_mdt_module_vars, lprocfs_mdt_obd_vars);