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 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
228 { "uuid", lprocfs_rd_uuid, 0, 0 },
229 { "blocksize", lprocfs_rd_blksize, 0, 0 },
230 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
231 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
232 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
233 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
234 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
235 { "fstype", lprocfs_rd_fstype, 0, 0 },
236 { "mntdev", lprocfs_mds_rd_mntdev, 0, 0 },
237 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
238 { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
239 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
240 #ifdef HAVE_QUOTA_SUPPORT
241 { "quota_bunit_sz", lprocfs_mds_rd_bunit, lprocfs_mds_wr_bunit, 0 },
242 { "quota_btune_sz", lprocfs_mds_rd_btune, lprocfs_mds_wr_btune, 0 },
243 { "quota_iunit_sz", lprocfs_mds_rd_iunit, lprocfs_mds_wr_iunit, 0 },
244 { "quota_itune_sz", lprocfs_mds_rd_itune, lprocfs_mds_wr_itune, 0 },
246 { "group_expire_interval", lprocfs_rd_group_expire,
247 lprocfs_wr_group_expire, 0},
248 { "group_acquire_expire", lprocfs_rd_group_acquire_expire,
249 lprocfs_wr_group_acquire_expire, 0},
250 { "group_upcall", lprocfs_rd_group_upcall,
251 lprocfs_wr_group_upcall, 0},
252 { "group_flush", 0, lprocfs_wr_group_flush, 0},
253 { "group_info", 0, lprocfs_wr_group_info, 0 },
257 struct lprocfs_vars lprocfs_mds_module_vars[] = {
258 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
262 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
263 { "uuid", lprocfs_rd_uuid, 0, 0 },
267 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
268 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
272 LPROCFS_INIT_VARS(mds, lprocfs_mds_module_vars, lprocfs_mds_obd_vars);
273 LPROCFS_INIT_VARS(mdt, lprocfs_mdt_module_vars, lprocfs_mdt_obd_vars);