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 * lustre/mdt/mdt_lproc.c
38 * Author: Lai Siyao <lsy@clusterfs.com>
39 * Author: Fan Yong <fanyong@clusterfs.com>
43 # define EXPORT_SYMTAB
45 #define DEBUG_SUBSYSTEM S_MDS
47 #include <linux/version.h>
48 #include <asm/statfs.h>
50 #include <linux/module.h>
52 /* LUSTRE_VERSION_CODE */
53 #include <lustre_ver.h>
55 * struct OBD_{ALLOC,FREE}*()
58 #include <obd_support.h>
59 /* struct obd_export */
60 #include <lustre_export.h>
61 /* struct obd_device */
63 #include <obd_class.h>
64 #include <lustre_mds.h>
65 #include <lustre_mdt.h>
66 #include <lprocfs_status.h>
68 #include "mdt_internal.h"
70 static const char *mdt_proc_names[LPROC_MDT_NR] = {
73 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
75 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
79 LASSERT(name != NULL);
80 mdt->mdt_proc_entry = ld->ld_obd->obd_proc_entry;
81 LASSERT(mdt->mdt_proc_entry != NULL);
83 result = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry,
84 mdt_proc_names, ARRAY_SIZE(mdt_proc_names));
86 result = lu_time_named_init(&ld->ld_site->ls_time_stats,
87 "site_time", mdt->mdt_proc_entry,
89 ARRAY_SIZE(lu_time_names));
93 int mdt_procfs_fini(struct mdt_device *mdt)
95 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
96 lu_time_fini(&ld->ld_site->ls_time_stats);
97 lu_time_fini(&mdt->mdt_stats);
98 mdt->mdt_proc_entry = NULL;
102 void mdt_time_start(const struct mdt_thread_info *info)
104 lu_lprocfs_time_start(info->mti_env);
107 void mdt_time_end(const struct mdt_thread_info *info, int idx)
109 lu_lprocfs_time_end(info->mti_env, info->mti_mdt->mdt_stats, idx);
112 static int lprocfs_rd_identity_expire(char *page, char **start, off_t off,
113 int count, int *eof, void *data)
115 struct obd_device *obd = data;
116 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
119 return snprintf(page, count, "%lu\n",
120 mdt->mdt_identity_cache->uc_entry_expire / HZ);
123 static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
124 unsigned long count, void *data)
126 struct obd_device *obd = data;
127 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
130 rc = lprocfs_write_helper(buffer, count, &val);
134 mdt->mdt_identity_cache->uc_entry_expire = val * HZ;
138 static int lprocfs_rd_identity_acquire_expire(char *page, char **start,
139 off_t off, int count, int *eof,
142 struct obd_device *obd = data;
143 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
146 return snprintf(page, count, "%lu\n",
147 mdt->mdt_identity_cache->uc_acquire_expire / HZ);
150 static int lprocfs_wr_identity_acquire_expire(struct file *file,
155 struct obd_device *obd = data;
156 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
159 rc = lprocfs_write_helper(buffer, count, &val);
163 mdt->mdt_identity_cache->uc_acquire_expire = val * HZ;
167 static int lprocfs_rd_identity_upcall(char *page, char **start, off_t off,
168 int count, int *eof, void *data)
170 struct obd_device *obd = data;
171 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
172 struct upcall_cache *hash = mdt->mdt_identity_cache;
176 read_lock(&hash->uc_upcall_rwlock);
177 len = snprintf(page, count, "%s\n", hash->uc_upcall);
178 read_unlock(&hash->uc_upcall_rwlock);
182 static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
183 unsigned long count, void *data)
185 struct obd_device *obd = data;
186 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
187 struct upcall_cache *hash = mdt->mdt_identity_cache;
188 char kernbuf[UC_CACHE_UPCALL_MAXPATH] = { '\0' };
190 if (count >= UC_CACHE_UPCALL_MAXPATH) {
191 CERROR("%s: identity upcall too long\n", obd->obd_name);
195 if (copy_from_user(kernbuf, buffer, min_t(unsigned long, count,
196 UC_CACHE_UPCALL_MAXPATH - 1)))
199 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
200 write_lock(&hash->uc_upcall_rwlock);
201 sscanf(kernbuf, "%s", hash->uc_upcall);
202 write_unlock(&hash->uc_upcall_rwlock);
204 if (strcmp(hash->uc_name, obd->obd_name) != 0)
205 CWARN("%s: write to upcall name %s\n",
206 obd->obd_name, hash->uc_upcall);
208 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
209 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
210 "cause unexpected \"EACCESS\"\n", obd->obd_name);
212 CWARN("%s: identity upcall set to %s\n", obd->obd_name, hash->uc_upcall);
216 static int lprocfs_wr_identity_flush(struct file *file, const char *buffer,
217 unsigned long count, void *data)
219 struct obd_device *obd = data;
220 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
223 rc = lprocfs_write_helper(buffer, count, &uid);
227 mdt_flush_identity(mdt->mdt_identity_cache, uid);
231 static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
232 unsigned long count, void *data)
234 struct obd_device *obd = data;
235 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
236 struct identity_downcall_data sparam, *param = &sparam;
237 int size = 0, rc = 0;
239 if (count < sizeof(*param)) {
240 CERROR("%s: invalid data size %lu\n", obd->obd_name, count);
244 if (copy_from_user(&sparam, buffer, sizeof(sparam))) {
245 CERROR("%s: bad identity data\n", obd->obd_name);
246 GOTO(out, rc = -EFAULT);
249 if (sparam.idd_magic != IDENTITY_DOWNCALL_MAGIC) {
250 CERROR("%s: MDS identity downcall bad params\n", obd->obd_name);
251 GOTO(out, rc = -EINVAL);
254 if (sparam.idd_nperms > N_PERMS_MAX) {
255 CERROR("%s: perm count %d more than maximum %d\n",
256 obd->obd_name, sparam.idd_nperms, N_PERMS_MAX);
257 GOTO(out, rc = -EINVAL);
260 if (sparam.idd_ngroups > NGROUPS_MAX) {
261 CERROR("%s: group count %d more than maximum %d\n",
262 obd->obd_name, sparam.idd_ngroups, NGROUPS_MAX);
263 GOTO(out, rc = -EINVAL);
266 if (sparam.idd_ngroups) {
267 size = offsetof(struct identity_downcall_data,
268 idd_groups[sparam.idd_ngroups]);
269 OBD_ALLOC(param, size);
271 CERROR("%s: fail to alloc %d bytes for uid %u"
272 " with %d groups\n", obd->obd_name, size,
273 sparam.idd_uid, sparam.idd_ngroups);
275 param->idd_ngroups = 0;
276 } else if (copy_from_user(param, buffer, size)) {
277 CERROR("%s: uid %u bad supplementary group data\n",
278 obd->obd_name, sparam.idd_uid);
279 OBD_FREE(param, size);
281 param->idd_ngroups = 0;
285 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
286 param->idd_uid, param);
289 if (param && (param != &sparam))
290 OBD_FREE(param, size);
296 static int lprocfs_rd_capa(char *page, char **start, off_t off,
297 int count, int *eof, void *data)
299 struct obd_device *obd = data;
300 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
302 return snprintf(page, count, "capability on: %s %s\n",
303 mdt->mdt_opts.mo_oss_capa ? "oss" : "",
304 mdt->mdt_opts.mo_mds_capa ? "mds" : "");
307 static int lprocfs_wr_capa(struct file *file, const char *buffer,
308 unsigned long count, void *data)
310 struct obd_device *obd = data;
311 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
314 rc = lprocfs_write_helper(buffer, count, &val);
318 if (val < 0 || val > 3) {
319 CERROR("invalid capability mode, only 0/2/3 is accepted.\n"
320 " 0: disable fid capability\n"
321 " 2: enable MDS fid capability\n"
322 " 3: enable both MDS and OSS fid capability\n");
326 /* OSS fid capability needs enable both MDS and OSS fid capability on
329 CERROR("can't enable OSS fid capability only, you should use "
330 "'3' to enable both MDS and OSS fid capability.\n");
334 mdt->mdt_opts.mo_oss_capa = (val & 0x1);
335 mdt->mdt_opts.mo_mds_capa = !!(val & 0x2);
336 mdt->mdt_capa_conf = 1;
337 LCONSOLE_INFO("MDS %s %s MDS fid capability.\n",
339 mdt->mdt_opts.mo_mds_capa ? "enabled" : "disabled");
340 LCONSOLE_INFO("MDS %s %s OSS fid capability.\n",
342 mdt->mdt_opts.mo_oss_capa ? "enabled" : "disabled");
346 static int lprocfs_rd_capa_count(char *page, char **start, off_t off,
347 int count, int *eof, void *data)
349 return snprintf(page, count, "%d %d\n",
350 capa_count[CAPA_SITE_CLIENT],
351 capa_count[CAPA_SITE_SERVER]);
354 static int lprocfs_rd_site_stats(char *page, char **start, off_t off,
355 int count, int *eof, void *data)
357 struct obd_device *obd = data;
358 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
360 return lu_site_stats_print(mdt_lu_site(mdt), page, count);
363 static int lprocfs_rd_capa_timeout(char *page, char **start, off_t off,
364 int count, int *eof, void *data)
366 struct obd_device *obd = data;
367 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
369 return snprintf(page, count, "%lu\n", mdt->mdt_capa_timeout);
372 static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
373 unsigned long count, void *data)
375 struct obd_device *obd = data;
376 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
379 rc = lprocfs_write_helper(buffer, count, &val);
383 mdt->mdt_capa_timeout = (unsigned long)val;
384 mdt->mdt_capa_conf = 1;
388 static int lprocfs_rd_ck_timeout(char *page, char **start, off_t off, int count,
389 int *eof, void *data)
391 struct obd_device *obd = data;
392 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
394 return snprintf(page, count, "%lu\n", mdt->mdt_ck_timeout);
397 static int lprocfs_wr_ck_timeout(struct file *file, const char *buffer,
398 unsigned long count, void *data)
400 struct obd_device *obd = data;
401 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
404 rc = lprocfs_write_helper(buffer, count, &val);
408 mdt->mdt_ck_timeout = (unsigned long)val;
409 mdt->mdt_capa_conf = 1;
413 static int lprocfs_mdt_wr_evict_client(struct file *file, const char *buffer,
414 unsigned long count, void *data)
416 char tmpbuf[sizeof(struct obd_uuid)];
418 sscanf(buffer, "%40s", tmpbuf);
420 if (strncmp(tmpbuf, "nid:", 4) != 0)
421 return lprocfs_wr_evict_client(file, buffer, count, data);
423 CERROR("NOT implement evict client by nid %s\n", tmpbuf);
428 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
429 int count, int *eof, void *data)
431 struct obd_device *obd = data;
432 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
434 return snprintf(page, count, "%d\n", mdt->mdt_sec_level);
437 static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
438 unsigned long count, void *data)
440 struct obd_device *obd = data;
441 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
444 rc = lprocfs_write_helper(buffer, count, &val);
448 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
451 if (val == LUSTRE_SEC_SPECIFY) {
452 CWARN("security level %d will be supported in future.\n",
457 mdt->mdt_sec_level = val;
461 static int lprocfs_rd_cos(char *page, char **start, off_t off,
462 int count, int *eof, void *data)
464 struct obd_device *obd = data;
465 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
467 return snprintf(page, count, "%u\n", mdt_cos_is_enabled(mdt));
470 static int lprocfs_wr_cos(struct file *file, const char *buffer,
471 unsigned long count, void *data)
473 struct obd_device *obd = data;
474 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
477 rc = lprocfs_write_helper(buffer, count, &val);
480 mdt_enable_cos(mdt, val);
484 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
485 { "uuid", lprocfs_rd_uuid, 0, 0 },
486 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
487 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
488 { "identity_expire", lprocfs_rd_identity_expire,
489 lprocfs_wr_identity_expire, 0 },
490 { "identity_acquire_expire", lprocfs_rd_identity_acquire_expire,
491 lprocfs_wr_identity_acquire_expire, 0 },
492 { "identity_upcall", lprocfs_rd_identity_upcall,
493 lprocfs_wr_identity_upcall, 0 },
494 { "identity_flush", 0, lprocfs_wr_identity_flush, 0 },
495 { "identity_info", 0, lprocfs_wr_identity_info, 0 },
496 { "capa", lprocfs_rd_capa,
497 lprocfs_wr_capa, 0 },
498 { "capa_timeout", lprocfs_rd_capa_timeout,
499 lprocfs_wr_capa_timeout, 0 },
500 { "capa_key_timeout", lprocfs_rd_ck_timeout,
501 lprocfs_wr_ck_timeout, 0 },
502 { "capa_count", lprocfs_rd_capa_count, 0, 0 },
503 { "site_stats", lprocfs_rd_site_stats, 0, 0 },
504 { "evict_client", 0, lprocfs_mdt_wr_evict_client, 0 },
505 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
506 { "sec_level", lprocfs_rd_sec_level,
507 lprocfs_wr_sec_level, 0 },
508 { "commit_on_sharing", lprocfs_rd_cos, lprocfs_wr_cos, 0 },
512 static struct lprocfs_vars lprocfs_mdt_module_vars[] = {
513 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
517 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
519 lvars->module_vars = lprocfs_mdt_module_vars;
520 lvars->obd_vars = lprocfs_mdt_obd_vars;