-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/*
+ * GPL HEADER START
*
- * Copyright (C) 2002 Cluster File Systems, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * This file is part of the Lustre file system, http://www.lustre.org
- * Lustre is a trademark of Cluster File Systems, Inc.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
*
- * You may have signed or agreed to another license before downloading
- * this software. If so, you are bound by the terms and conditions
- * of that agreement, and the following does not apply to you. See the
- * LICENSE file included with this distribution for more information.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
*
- * If you did not agree to a different license, then this copy of Lustre
- * is open source software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
*
- * In either case, Lustre is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * license text for more details.
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
*
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2015, Intel Corporation.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
*/
#define DEBUG_SUBSYSTEM S_CLASS
#include <linux/version.h>
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
#include <asm/statfs.h>
-#endif
#include <obd.h>
#include <obd_class.h>
#include <lprocfs_status.h>
+#include <lustre_param.h>
#include "mgs_internal.h"
+#ifdef CONFIG_PROC_FS
-#ifdef LPROCFS
-
-static int lprocfs_mgs_rd_mntdev(char *page, char **start, off_t off, int count,
- int *eof, void *data)
+static int mgs_fs_seq_show(struct seq_file *seq, void *v)
{
- struct obd_device* obd = (struct obd_device *)data;
+ struct obd_device *obd = seq->private;
+ struct mgs_device *mgs;
+ struct list_head list;
+ struct mgs_direntry *dirent, *n;
+ struct lu_env env;
+ int rc, len;
- LASSERT(obd != NULL);
- LASSERT(obd->u.mgs.mgs_vfsmnt->mnt_devname);
- *eof = 1;
+ ENTRY;
- return snprintf(page, count, "%s\n",obd->u.mgs.mgs_vfsmnt->mnt_devname);
-}
+ LASSERT(obd != NULL);
+ LASSERT(obd->obd_lu_dev != NULL);
+ mgs = lu2mgs_dev(obd->obd_lu_dev);
-static int mgs_fs_seq_show(struct seq_file *seq, void *v)
-{
- struct obd_device *obd = seq->private;
- struct mgs_obd *mgs = &obd->u.mgs;
- struct list_head dentry_list;
- struct l_linux_dirent *dirent, *n;
- int rc, len;
- ENTRY;
-
- LASSERT(obd != NULL);
- rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
- mgs->mgs_vfsmnt, &dentry_list);
- if (rc) {
- CERROR("Can't read config dir\n");
- RETURN(rc);
- }
- list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
- list_del(&dirent->lld_list);
- len = strlen(dirent->lld_name);
- if ((len > 7) && (strncmp(dirent->lld_name + len - 7, "-client",
- len) == 0)) {
- seq_printf(seq, "%.*s\n", len - 7, dirent->lld_name);
- }
- OBD_FREE(dirent, sizeof(*dirent));
- }
+ rc = lu_env_init(&env, LCT_MG_THREAD);
+ if (rc)
+ RETURN(rc);
+
+ rc = class_dentry_readdir(&env, mgs, &list);
+ if (rc)
+ GOTO(out, rc);
+
+ list_for_each_entry_safe(dirent, n, &list, mde_list) {
+ list_del_init(&dirent->mde_list);
+ len = strlen(dirent->mde_name);
+ if (len > 7 &&
+ strncmp(dirent->mde_name + len - 7, "-client", len) == 0)
+ seq_printf(seq, "%.*s\n", len - 7, dirent->mde_name);
+ mgs_direntry_free(dirent);
+ }
- RETURN(0);
+out:
+ lu_env_fini(&env);
+ RETURN(0);
}
LPROC_SEQ_FOPS_RO(mgs_fs);
-int lproc_mgs_setup(struct obd_device *obd)
+static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname,
+ struct sptlrpc_rule_set *rset)
{
- struct mgs_obd *mgs = &obd->u.mgs;
- int rc;
+ struct sptlrpc_rule *r;
+ char dirbuf[10];
+ char flvrbuf[40];
+ char net[LNET_NIDSTR_SIZE] = "default";
+ int i;
- rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
- &mgs_fs_fops, obd);
- mgs->mgs_proc_live = proc_mkdir("live", obd->obd_proc_entry);
+ for (i = 0; i < rset->srs_nrule; i++) {
+ r = &rset->srs_rules[i];
+
+ if (r->sr_netid != LNET_NIDNET(LNET_NID_ANY))
+ libcfs_net2str_r(r->sr_netid, net, sizeof(net));
+
+ if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
+ dirbuf[0] = '\0';
+ else
+ snprintf(dirbuf, sizeof(dirbuf), ".%s2%s",
+ sptlrpc_part2name(r->sr_from),
+ sptlrpc_part2name(r->sr_to));
- return rc;
+ sptlrpc_flavor2name(&r->sr_flvr, flvrbuf, sizeof(flvrbuf));
+ seq_printf(seq, "%s.srpc.flavor.%s%s=%s\n", tgtname,
+ net, dirbuf, flvrbuf);
+ }
}
-static int mgs_live_seq_show(struct seq_file *seq, void *v)
+static int mgsself_srpc_seq_show(struct seq_file *seq, void *v)
{
- struct fs_db *fsdb = seq->private;
- int i;
-
- down(&fsdb->fsdb_sem);
-
- seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
- seq_printf(seq, "flags: %#x gen: %d\n",
- fsdb->fsdb_flags, fsdb->fsdb_gen);
- for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
- if (test_bit(i, fsdb->fsdb_mdt_index_map))
- seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
- for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
- if (test_bit(i, fsdb->fsdb_ost_index_map))
- seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
-
- up(&fsdb->fsdb_sem);
+ struct obd_device *obd = seq->private;
+ struct mgs_device *mgs = lu2mgs_dev(obd->obd_lu_dev);
+ struct lu_target *tgt = &mgs->mgs_lut;
+
+ read_lock(&tgt->lut_sptlrpc_lock);
+ seq_show_srpc_rules(seq, MGSSELF_NAME, &tgt->lut_sptlrpc_rset);
+ read_unlock(&tgt->lut_sptlrpc_lock);
+
return 0;
}
+LPROC_SEQ_FOPS_RO(mgsself_srpc);
+
+static int mgs_live_seq_show(struct seq_file *seq, void *v)
+{
+ struct fs_db *fsdb = seq->private;
+ struct mgs_tgt_srpc_conf *srpc_tgt;
+ int i;
+
+ mutex_lock(&fsdb->fsdb_mutex);
+
+ seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
+ seq_printf(seq, "flags: %#lx gen: %d\n",
+ fsdb->fsdb_flags, fsdb->fsdb_gen);
+ for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
+ if (test_bit(i, fsdb->fsdb_mdt_index_map))
+ seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
+ for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
+ if (test_bit(i, fsdb->fsdb_ost_index_map))
+ seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
+
+ seq_printf(seq, "\nSecure RPC Config Rules:\n");
+#if 0
+ seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name,
+ PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no");
+#endif
+ for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt;
+ srpc_tgt = srpc_tgt->mtsc_next) {
+ seq_show_srpc_rules(seq, srpc_tgt->mtsc_tgt,
+ &srpc_tgt->mtsc_rset);
+ }
+ seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
+
+ lprocfs_rd_ir_state(seq, fsdb);
+
+ mutex_unlock(&fsdb->fsdb_mutex);
+ return 0;
+}
-LPROC_SEQ_FOPS_RO(mgs_live);
+static ssize_t mgs_live_seq_write(struct file *file, const char __user *buf,
+ size_t len, loff_t *off)
+{
+ struct seq_file *seq = file->private_data;
+ struct fs_db *fsdb = seq->private;
+ ssize_t rc;
+
+ rc = lprocfs_wr_ir_state(file, buf, len, fsdb);
+ if (rc >= 0)
+ rc = len;
+ return rc;
+}
+LPROC_SEQ_FOPS(mgs_live);
-int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
+int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
{
- struct mgs_obd *mgs = &obd->u.mgs;
- int rc;
+ int rc;
- if (!mgs->mgs_proc_live)
- return 0;
- rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0444,
- &mgs_live_fops, fsdb);
+ if (!mgs->mgs_proc_live)
+ return 0;
+ rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0644,
+ &mgs_live_fops, fsdb);
- return 0;
+ return 0;
}
-int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
+int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
{
- struct mgs_obd *mgs = &obd->u.mgs;
+ if (!mgs->mgs_proc_live)
+ return 0;
- if (!mgs->mgs_proc_live)
- return 0;
- remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
- return 0;
+ /* didn't create the proc file for MGSSELF_NAME */
+ if (!test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
+ lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
+ return 0;
}
-struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
- { "uuid", lprocfs_rd_uuid, 0, 0 },
- { "fstype", lprocfs_rd_fstype, 0, 0 },
- { "mntdev", lprocfs_mgs_rd_mntdev, 0, 0 },
- { "num_exports", lprocfs_rd_num_exports, 0, 0 },
- { 0 }
-};
+LPROC_SEQ_FOPS_RO_TYPE(mgs, uuid);
+LPROC_SEQ_FOPS_RO_TYPE(mgs, num_exports);
+LPROC_SEQ_FOPS_RO_TYPE(mgs, hash);
+LPROC_SEQ_FOPS_WO_TYPE(mgs, evict_client);
+LPROC_SEQ_FOPS_RW_TYPE(mgs, ir_timeout);
-struct lprocfs_vars lprocfs_mgs_module_vars[] = {
- { 0 }
+static struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
+ { .name = "uuid",
+ .fops = &mgs_uuid_fops },
+ { .name = "num_exports",
+ .fops = &mgs_num_exports_fops },
+ { .name = "hash_stats",
+ .fops = &mgs_hash_fops },
+ { .name = "evict_client",
+ .fops = &mgs_evict_client_fops },
+ { .name = "ir_timeout",
+ .fops = &mgs_ir_timeout_fops },
+ { NULL }
};
-LPROCFS_INIT_VARS(mgs, lprocfs_mgs_module_vars, lprocfs_mgs_obd_vars);
+int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name)
+{
+ struct obd_device *obd = mgs->mgs_obd;
+ struct obd_device *osd_obd = mgs->mgs_bottom->dd_lu_dev.ld_obd;
+ int osd_len = strlen(osd_name) - strlen("-osd");
+ int rc;
+
+ obd->obd_vars = lprocfs_mgs_obd_vars;
+ rc = lprocfs_obd_setup(obd);
+ if (rc != 0)
+ GOTO(out, rc);
+
+ rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
+ &mgs_fs_fops, obd);
+ if (rc != 0)
+ GOTO(out, rc);
+
+ rc = lprocfs_obd_seq_create(obd, "srpc_rules", 0400,
+ &mgsself_srpc_fops, obd);
+ if (rc != 0)
+ GOTO(out, rc);
+
+ mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry,
+ NULL, NULL);
+ if (IS_ERR(mgs->mgs_proc_live)) {
+ rc = PTR_ERR(mgs->mgs_proc_live);
+ mgs->mgs_proc_live = NULL;
+ GOTO(out, rc);
+ }
+
+ obd->obd_proc_exports_entry = lprocfs_register("exports",
+ obd->obd_proc_entry,
+ NULL, NULL);
+ if (IS_ERR(obd->obd_proc_exports_entry)) {
+ rc = PTR_ERR(obd->obd_proc_exports_entry);
+ obd->obd_proc_exports_entry = NULL;
+ GOTO(out, rc);
+ }
+
+ mgs->mgs_proc_osd = lprocfs_add_symlink("osd",
+ obd->obd_proc_entry,
+ "../../%s/%.*s",
+ osd_obd->obd_type->typ_name,
+ osd_len, /* Strip "-osd". */
+ osd_name);
+ if (mgs->mgs_proc_osd == NULL)
+ GOTO(out, rc = -ENOMEM);
+
+ mgs->mgs_proc_mntdev = lprocfs_add_symlink("mntdev",
+ obd->obd_proc_entry,
+ "osd/mntdev");
+ if (mgs->mgs_proc_mntdev == NULL)
+ GOTO(out, rc = -ENOMEM);
+
+ mgs->mgs_proc_fstype = lprocfs_add_symlink("fstype",
+ obd->obd_proc_entry,
+ "osd/fstype");
+ if (mgs->mgs_proc_fstype == NULL)
+ GOTO(out, rc = -ENOMEM);
+
+out:
+ if (rc != 0)
+ lproc_mgs_cleanup(mgs);
+
+ return rc;
+}
+
+void lproc_mgs_cleanup(struct mgs_device *mgs)
+{
+ struct obd_device *obd = mgs->mgs_obd;
+
+ if (obd == NULL)
+ return;
+
+ if (mgs->mgs_proc_osd != NULL)
+ lprocfs_remove(&mgs->mgs_proc_osd);
+
+ if (mgs->mgs_proc_fstype != NULL)
+ lprocfs_remove(&mgs->mgs_proc_fstype);
+
+ if (mgs->mgs_proc_mntdev != NULL)
+ lprocfs_remove(&mgs->mgs_proc_mntdev);
+
+ if (mgs->mgs_proc_live != NULL) {
+ /* Should be no live entries */
+ lprocfs_remove(&mgs->mgs_proc_live);
+ mgs->mgs_proc_live = NULL;
+ }
+
+ lprocfs_free_per_client_stats(obd);
+ lprocfs_obd_cleanup(obd);
+ lprocfs_free_obd_stats(obd);
+ lprocfs_free_md_stats(obd);
+}
+
+void mgs_counter_incr(struct obd_export *exp, int opcode)
+{
+ lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
+ if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
+ lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
+}
+
+void mgs_stats_counter_init(struct lprocfs_stats *stats)
+{
+ lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
+ lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
+ "reqs");
+ lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
+ "reqs");
+ lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
+ lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
+}
#endif