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"
69 #include <lnet/lib-lnet.h>
71 static const char *mdt_proc_names[LPROC_MDT_NR] = {
74 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
76 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
80 LASSERT(name != NULL);
81 mdt->mdt_proc_entry = ld->ld_obd->obd_proc_entry;
82 LASSERT(mdt->mdt_proc_entry != NULL);
84 result = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry,
85 mdt_proc_names, ARRAY_SIZE(mdt_proc_names));
87 result = lu_time_named_init(&ld->ld_site->ls_time_stats,
88 "site_time", mdt->mdt_proc_entry,
90 ARRAY_SIZE(lu_time_names));
94 int mdt_procfs_fini(struct mdt_device *mdt)
96 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
97 lu_time_fini(&ld->ld_site->ls_time_stats);
98 lu_time_fini(&mdt->mdt_stats);
99 mdt->mdt_proc_entry = NULL;
103 void mdt_time_start(const struct mdt_thread_info *info)
105 lu_lprocfs_time_start(info->mti_env);
108 void mdt_time_end(const struct mdt_thread_info *info, int idx)
110 lu_lprocfs_time_end(info->mti_env, info->mti_mdt->mdt_stats, idx);
113 static int lprocfs_rd_identity_expire(char *page, char **start, off_t off,
114 int count, int *eof, void *data)
116 struct obd_device *obd = data;
117 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
120 return snprintf(page, count, "%lu\n",
121 mdt->mdt_identity_cache->uc_entry_expire / HZ);
124 static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
125 unsigned long count, void *data)
127 struct obd_device *obd = data;
128 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
131 rc = lprocfs_write_helper(buffer, count, &val);
135 mdt->mdt_identity_cache->uc_entry_expire = val * HZ;
139 static int lprocfs_rd_identity_acquire_expire(char *page, char **start,
140 off_t off, int count, int *eof,
143 struct obd_device *obd = data;
144 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
147 return snprintf(page, count, "%lu\n",
148 mdt->mdt_identity_cache->uc_acquire_expire / HZ);
151 static int lprocfs_wr_identity_acquire_expire(struct file *file,
156 struct obd_device *obd = data;
157 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
160 rc = lprocfs_write_helper(buffer, count, &val);
164 mdt->mdt_identity_cache->uc_acquire_expire = val * HZ;
168 static int lprocfs_rd_identity_upcall(char *page, char **start, off_t off,
169 int count, int *eof, void *data)
171 struct obd_device *obd = data;
172 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
173 struct upcall_cache *hash = mdt->mdt_identity_cache;
177 read_lock(&hash->uc_upcall_rwlock);
178 len = snprintf(page, count, "%s\n", hash->uc_upcall);
179 read_unlock(&hash->uc_upcall_rwlock);
183 static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
184 unsigned long count, void *data)
186 struct obd_device *obd = data;
187 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
188 struct upcall_cache *hash = mdt->mdt_identity_cache;
189 char kernbuf[UC_CACHE_UPCALL_MAXPATH] = { '\0' };
191 if (count >= UC_CACHE_UPCALL_MAXPATH) {
192 CERROR("%s: identity upcall too long\n", obd->obd_name);
196 if (copy_from_user(kernbuf, buffer, min_t(unsigned long, count,
197 UC_CACHE_UPCALL_MAXPATH - 1)))
200 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
201 write_lock(&hash->uc_upcall_rwlock);
202 sscanf(kernbuf, "%s", hash->uc_upcall);
203 write_unlock(&hash->uc_upcall_rwlock);
205 if (strcmp(hash->uc_name, obd->obd_name) != 0)
206 CWARN("%s: write to upcall name %s\n",
207 obd->obd_name, hash->uc_upcall);
209 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
210 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
211 "cause unexpected \"EACCESS\"\n", obd->obd_name);
213 CWARN("%s: identity upcall set to %s\n", obd->obd_name, hash->uc_upcall);
217 static int lprocfs_wr_identity_flush(struct file *file, const char *buffer,
218 unsigned long count, void *data)
220 struct obd_device *obd = data;
221 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
224 rc = lprocfs_write_helper(buffer, count, &uid);
228 mdt_flush_identity(mdt->mdt_identity_cache, uid);
232 static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
233 unsigned long count, void *data)
235 struct obd_device *obd = data;
236 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
237 struct identity_downcall_data sparam, *param = &sparam;
238 int size = 0, rc = 0;
240 if (count < sizeof(*param)) {
241 CERROR("%s: invalid data size %lu\n", obd->obd_name, count);
245 if (copy_from_user(&sparam, buffer, sizeof(sparam))) {
246 CERROR("%s: bad identity data\n", obd->obd_name);
247 GOTO(out, rc = -EFAULT);
250 if (sparam.idd_magic != IDENTITY_DOWNCALL_MAGIC) {
251 CERROR("%s: MDS identity downcall bad params\n", obd->obd_name);
252 GOTO(out, rc = -EINVAL);
255 if (sparam.idd_nperms > N_PERMS_MAX) {
256 CERROR("%s: perm count %d more than maximum %d\n",
257 obd->obd_name, sparam.idd_nperms, N_PERMS_MAX);
258 GOTO(out, rc = -EINVAL);
261 if (sparam.idd_ngroups > NGROUPS_MAX) {
262 CERROR("%s: group count %d more than maximum %d\n",
263 obd->obd_name, sparam.idd_ngroups, NGROUPS_MAX);
264 GOTO(out, rc = -EINVAL);
267 if (sparam.idd_ngroups) {
268 size = offsetof(struct identity_downcall_data,
269 idd_groups[sparam.idd_ngroups]);
270 OBD_ALLOC(param, size);
272 CERROR("%s: fail to alloc %d bytes for uid %u"
273 " with %d groups\n", obd->obd_name, size,
274 sparam.idd_uid, sparam.idd_ngroups);
276 param->idd_ngroups = 0;
277 } else if (copy_from_user(param, buffer, size)) {
278 CERROR("%s: uid %u bad supplementary group data\n",
279 obd->obd_name, sparam.idd_uid);
280 OBD_FREE(param, size);
282 param->idd_ngroups = 0;
286 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
287 param->idd_uid, param);
290 if (param && (param != &sparam))
291 OBD_FREE(param, size);
297 static int lprocfs_rd_capa(char *page, char **start, off_t off,
298 int count, int *eof, void *data)
300 struct obd_device *obd = data;
301 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
303 return snprintf(page, count, "capability on: %s %s\n",
304 mdt->mdt_opts.mo_oss_capa ? "oss" : "",
305 mdt->mdt_opts.mo_mds_capa ? "mds" : "");
308 static int lprocfs_wr_capa(struct file *file, const char *buffer,
309 unsigned long count, void *data)
311 struct obd_device *obd = data;
312 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
315 rc = lprocfs_write_helper(buffer, count, &val);
319 if (val < 0 || val > 3) {
320 CERROR("invalid capability mode, only 0/2/3 is accepted.\n"
321 " 0: disable fid capability\n"
322 " 2: enable MDS fid capability\n"
323 " 3: enable both MDS and OSS fid capability\n");
327 /* OSS fid capability needs enable both MDS and OSS fid capability on
330 CERROR("can't enable OSS fid capability only, you should use "
331 "'3' to enable both MDS and OSS fid capability.\n");
335 mdt->mdt_opts.mo_oss_capa = (val & 0x1);
336 mdt->mdt_opts.mo_mds_capa = !!(val & 0x2);
337 mdt->mdt_capa_conf = 1;
338 LCONSOLE_INFO("MDS %s %s MDS fid capability.\n",
340 mdt->mdt_opts.mo_mds_capa ? "enabled" : "disabled");
341 LCONSOLE_INFO("MDS %s %s OSS fid capability.\n",
343 mdt->mdt_opts.mo_oss_capa ? "enabled" : "disabled");
347 static int lprocfs_rd_capa_count(char *page, char **start, off_t off,
348 int count, int *eof, void *data)
350 return snprintf(page, count, "%d %d\n",
351 capa_count[CAPA_SITE_CLIENT],
352 capa_count[CAPA_SITE_SERVER]);
355 static int lprocfs_rd_site_stats(char *page, char **start, off_t off,
356 int count, int *eof, void *data)
358 struct obd_device *obd = data;
359 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
361 return lu_site_stats_print(mdt_lu_site(mdt), page, count);
364 static int lprocfs_rd_capa_timeout(char *page, char **start, off_t off,
365 int count, int *eof, void *data)
367 struct obd_device *obd = data;
368 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
370 return snprintf(page, count, "%lu\n", mdt->mdt_capa_timeout);
373 static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
374 unsigned long count, void *data)
376 struct obd_device *obd = data;
377 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
380 rc = lprocfs_write_helper(buffer, count, &val);
384 mdt->mdt_capa_timeout = (unsigned long)val;
385 mdt->mdt_capa_conf = 1;
389 static int lprocfs_rd_ck_timeout(char *page, char **start, off_t off, int count,
390 int *eof, void *data)
392 struct obd_device *obd = data;
393 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
395 return snprintf(page, count, "%lu\n", mdt->mdt_ck_timeout);
398 static int lprocfs_wr_ck_timeout(struct file *file, const char *buffer,
399 unsigned long count, void *data)
401 struct obd_device *obd = data;
402 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
405 rc = lprocfs_write_helper(buffer, count, &val);
409 mdt->mdt_ck_timeout = (unsigned long)val;
410 mdt->mdt_capa_conf = 1;
414 static int lprocfs_mdt_wr_evict_client(struct file *file, const char *buffer,
415 unsigned long count, void *data)
417 char tmpbuf[sizeof(struct obd_uuid)];
419 sscanf(buffer, "%40s", tmpbuf);
421 if (strncmp(tmpbuf, "nid:", 4) != 0)
422 return lprocfs_wr_evict_client(file, buffer, count, data);
424 CERROR("NOT implement evict client by nid %s\n", tmpbuf);
429 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
430 int count, int *eof, void *data)
432 struct obd_device *obd = data;
433 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
435 return snprintf(page, count, "%d\n", mdt->mdt_sec_level);
438 static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
439 unsigned long count, void *data)
441 struct obd_device *obd = data;
442 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
445 rc = lprocfs_write_helper(buffer, count, &val);
449 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
452 if (val == LUSTRE_SEC_SPECIFY) {
453 CWARN("security level %d will be supported in future.\n",
458 mdt->mdt_sec_level = val;
462 static int lprocfs_rd_cos(char *page, char **start, off_t off,
463 int count, int *eof, void *data)
465 struct obd_device *obd = data;
466 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
468 return snprintf(page, count, "%u\n", mdt_cos_is_enabled(mdt));
471 static int lprocfs_wr_cos(struct file *file, const char *buffer,
472 unsigned long count, void *data)
474 struct obd_device *obd = data;
475 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
478 rc = lprocfs_write_helper(buffer, count, &val);
481 mdt_enable_cos(mdt, val);
485 static int lprocfs_rd_root_squash(char *page, char **start, off_t off,
486 int count, int *eof, void *data)
488 struct obd_device *obd = data;
489 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
492 return snprintf(page, count, "%u:%u\n", mdt->mdt_squash_uid,
493 mdt->mdt_squash_gid);
496 static int safe_strtoul(const char *str, char **endp, unsigned long *res)
500 *res = simple_strtoul(str, endp, 0);
504 sprintf(n, "%lu", *res);
505 if (strncmp(n, str, *endp - str))
511 static int lprocfs_wr_root_squash(struct file *file, const char *buffer,
512 unsigned long count, void *data)
514 struct obd_device *obd = data;
515 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
516 char kernbuf[50], *tmp, *end;
517 unsigned long uid, gid;
521 if (count > (sizeof(kernbuf) - 1) ||
522 copy_from_user(kernbuf, buffer, count)) {
523 CWARN("%s: can't copy string to kernel space, "
524 "uid:gid is expected, "
525 "continue with %u:%u, "
526 "there will be 0:0 on MDS restart\n",
527 obd->obd_name, mdt->mdt_squash_uid,
528 mdt->mdt_squash_gid);
532 if (copy_from_user(kernbuf, buffer, count))
535 kernbuf[count] = '\0';
538 if (safe_strtoul(buffer, &tmp, &uid)) {
539 uid = mdt->mdt_squash_uid;
546 if (safe_strtoul(tmp, &end, &gid)) {
547 gid = mdt->mdt_squash_gid;
551 gid = mdt->mdt_squash_gid;
555 mdt->mdt_squash_uid = uid;
556 mdt->mdt_squash_gid = gid;
559 CWARN("%s: can't parse \"\%s\", uid:gid is expected, "
560 "continue with %u:%u, "
561 "there will be %u:%u on MDS restart\n",
563 buffer, mdt->mdt_squash_uid, mdt->mdt_squash_gid,
564 nouid ? 0 : mdt->mdt_squash_uid,
565 nogid ? 0 : mdt->mdt_squash_gid);
567 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
569 mdt->mdt_squash_uid, mdt->mdt_squash_gid);
573 static int lprocfs_rd_nosquash_nids(char *page, char **start, off_t off,
574 int count, int *eof, void *data)
576 struct obd_device *obd = data;
577 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
579 if (mdt->mdt_nosquash_str)
580 return snprintf(page, count, "%s\n", mdt->mdt_nosquash_str);
581 return snprintf(page, count, "NONE\n");
584 static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
585 unsigned long count, void *data)
587 struct obd_device *obd = data;
588 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
591 struct list_head tmp;
594 /* copy to kernel space */
595 OBD_ALLOC(new, count + 1);
597 GOTO(failed, rc = -ENOMEM);
599 if (copy_from_user(new, buffer, count))
600 GOTO(failed, rc = -EFAULT);
603 if (strlen(new) != count)
604 GOTO(failed, rc = -EINVAL);
606 if (!strcmp(new, "NONE") || !strcmp(new, "clear")) {
607 /* empty string is special case */
608 down_write(&mdt->mdt_squash_sem);
609 if (!list_empty(&mdt->mdt_nosquash_nids)) {
610 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
611 OBD_FREE(mdt->mdt_nosquash_str,
612 mdt->mdt_nosquash_strlen);
613 mdt->mdt_nosquash_str = NULL;
614 mdt->mdt_nosquash_strlen = 0;
616 up_write(&mdt->mdt_squash_sem);
617 LCONSOLE_INFO("%s: nosquash_nids is cleared\n",
619 OBD_FREE(new, count + 1);
623 CFS_INIT_LIST_HEAD(&tmp);
624 if (cfs_parse_nidlist(new, count, &tmp) <= 0)
625 GOTO(failed, rc = -EINVAL);
627 down_write(&mdt->mdt_squash_sem);
628 if (!list_empty(&mdt->mdt_nosquash_nids)) {
629 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
630 OBD_FREE(mdt->mdt_nosquash_str, mdt->mdt_nosquash_strlen);
632 mdt->mdt_nosquash_str = new;
633 mdt->mdt_nosquash_strlen = count + 1;
634 list_splice(&tmp, &mdt->mdt_nosquash_nids);
636 LCONSOLE_INFO("%s: nosquash_nids is set to %s\n", obd->obd_name, new);
637 up_write(&mdt->mdt_squash_sem);
641 CWARN("%s: failed to set nosquash_nids (rc %d), "
642 "on MDS restart we will try to set it again, "
643 "continue with current nosquash_nids\n",
646 OBD_FREE(new, count + 1);
650 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
651 { "uuid", lprocfs_rd_uuid, 0, 0 },
652 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
653 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
654 { "identity_expire", lprocfs_rd_identity_expire,
655 lprocfs_wr_identity_expire, 0 },
656 { "identity_acquire_expire", lprocfs_rd_identity_acquire_expire,
657 lprocfs_wr_identity_acquire_expire, 0 },
658 { "identity_upcall", lprocfs_rd_identity_upcall,
659 lprocfs_wr_identity_upcall, 0 },
660 { "identity_flush", 0, lprocfs_wr_identity_flush, 0 },
661 { "identity_info", 0, lprocfs_wr_identity_info, 0 },
662 { "capa", lprocfs_rd_capa,
663 lprocfs_wr_capa, 0 },
664 { "capa_timeout", lprocfs_rd_capa_timeout,
665 lprocfs_wr_capa_timeout, 0 },
666 { "capa_key_timeout", lprocfs_rd_ck_timeout,
667 lprocfs_wr_ck_timeout, 0 },
668 { "capa_count", lprocfs_rd_capa_count, 0, 0 },
669 { "site_stats", lprocfs_rd_site_stats, 0, 0 },
670 { "evict_client", 0, lprocfs_mdt_wr_evict_client, 0 },
671 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
672 { "sec_level", lprocfs_rd_sec_level,
673 lprocfs_wr_sec_level, 0 },
674 { "commit_on_sharing", lprocfs_rd_cos, lprocfs_wr_cos, 0 },
675 { "root_squash", lprocfs_rd_root_squash,
676 lprocfs_wr_root_squash, 0 },
677 { "nosquash_nids", lprocfs_rd_nosquash_nids,
678 lprocfs_wr_nosquash_nids, 0 },
682 static struct lprocfs_vars lprocfs_mdt_module_vars[] = {
683 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
687 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
689 lvars->module_vars = lprocfs_mdt_module_vars;
690 lvars->obd_vars = lprocfs_mdt_obd_vars;