*
* 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
- *
- * 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.
+ * http://www.gnu.org/licenses/gpl-2.0.html
*
* GPL HEADER END
*/
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, Whamcloud, Inc.
+ * Copyright (c) 2011, 2017, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#include <obd.h>
#include <obd_class.h>
#include <lprocfs_status.h>
-#include <lustre_param.h>
+#include <uapi/linux/lustre/lustre_param.h>
#include "mgs_internal.h"
-#ifdef LPROCFS
+#ifdef CONFIG_PROC_FS
static int mgs_fs_seq_show(struct seq_file *seq, void *v)
{
- struct obd_device *obd = seq->private;
- struct mgs_device *mgs;
- cfs_list_t list;
- struct mgs_direntry *dirent, *n;
- struct lu_env env;
- int rc, len;
- ENTRY;
-
- LASSERT(obd != NULL);
+ 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;
+
+ ENTRY;
+
+ LASSERT(obd != NULL);
LASSERT(obd->obd_lu_dev != NULL);
mgs = lu2mgs_dev(obd->obd_lu_dev);
RETURN(rc);
rc = class_dentry_readdir(&env, mgs, &list);
- if (rc) {
- CERROR("Can't read config dir\n");
+ if (rc)
GOTO(out, rc);
- }
- cfs_list_for_each_entry_safe(dirent, n, &list, list) {
- cfs_list_del(&dirent->list);
- len = strlen(dirent->name);
+
+ 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->name + len - 7, "-client", len) == 0)
- seq_printf(seq, "%.*s\n", len - 7, dirent->name);
+ strncmp(dirent->mde_name + len - 7, "-client", len) == 0)
+ seq_printf(seq, "%.*s\n", len - 7, dirent->mde_name);
mgs_direntry_free(dirent);
- }
+ }
out:
lu_env_fini(&env);
- RETURN(0);
+ RETURN(0);
}
LPROC_SEQ_FOPS_RO(mgs_fs);
static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname,
- struct sptlrpc_rule_set *rset)
+ struct sptlrpc_rule_set *rset)
{
- struct sptlrpc_rule *r;
- char dirbuf[10];
- char flvrbuf[40];
- char *net;
- int i;
-
- for (i = 0; i < rset->srs_nrule; i++) {
- r = &rset->srs_rules[i];
-
- if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
- net = "default";
- else
- net = libcfs_net2str(r->sr_netid);
+ struct sptlrpc_rule *r;
+ char dirbuf[10];
+ char flvrbuf[40];
+ char net_buf[LNET_NIDSTR_SIZE];
+ const char *net;
+ int i;
+
+ for (i = 0; i < rset->srs_nrule; i++) {
+ r = &rset->srs_rules[i];
+
+ if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
+ net = "default";
+ else
+ net = libcfs_net2str_r(r->sr_netid, net_buf,
+ sizeof(net_buf));
if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
dirbuf[0] = '\0';
static int mgsself_srpc_seq_show(struct seq_file *seq, void *v)
{
- struct obd_device *obd = seq->private;
- struct mgs_device *mgs;
- struct fs_db *fsdb;
- struct lu_env env;
- int rc;
+ struct obd_device *obd = seq->private;
+ struct mgs_device *mgs = lu2mgs_dev(obd->obd_lu_dev);
+ struct lu_target *tgt = &mgs->mgs_lut;
- LASSERT(obd != NULL);
- LASSERT(obd->obd_lu_dev != NULL);
- mgs = lu2mgs_dev(obd->obd_lu_dev);
+ read_lock(&tgt->lut_sptlrpc_lock);
+ seq_show_srpc_rules(seq, MGSSELF_NAME, &tgt->lut_sptlrpc_rset);
+ read_unlock(&tgt->lut_sptlrpc_lock);
- rc = lu_env_init(&env, LCT_MG_THREAD);
- if (rc)
- return rc;
+ return 0;
+}
+LPROC_SEQ_FOPS_RO(mgsself_srpc);
- rc = mgs_find_or_make_fsdb(&env, mgs, MGSSELF_NAME, &fsdb);
- if (rc)
- goto out;
+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_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
+
+ 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;
+}
-out:
- lu_env_fini(&env);
- return 0;
+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);
-LPROC_SEQ_FOPS_RO(mgsself_srpc);
+int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
+{
+ int rc;
+
+ if (!mgs->mgs_proc_live || fsdb->fsdb_has_lproc_entry)
+ return 0;
+
+ rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0644,
+ &mgs_live_fops, fsdb);
+ if (!rc)
+ fsdb->fsdb_has_lproc_entry = 1;
+
+ return rc;
+}
+
+int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
+{
+ if (!mgs->mgs_proc_live || !fsdb->fsdb_has_lproc_entry)
+ 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;
+}
-int lproc_mgs_setup(struct mgs_device *mgs, char *osd_name)
+LPROC_SEQ_FOPS_RO_TYPE(mgs, hash);
+LPROC_SEQ_FOPS_WR_ONLY(mgs, evict_client);
+LPROC_SEQ_FOPS_RW_TYPE(mgs, ir_timeout);
+
+static struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
+ { .name = "hash_stats",
+ .fops = &mgs_hash_fops },
+ { .name = "evict_client",
+ .fops = &mgs_evict_client_fops },
+ { .name = "ir_timeout",
+ .fops = &mgs_ir_timeout_fops },
+ { NULL }
+};
+
+LUSTRE_RO_ATTR(num_exports);
+
+static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
{
+ struct obd_device *obd = container_of(kobj, struct obd_device,
+ obd_kset.kobj);
+ struct mgs_device *mgs = lu2mgs_dev(obd->obd_lu_dev);
+ struct kobject *osd_kobj;
+
+ if (!mgs || !mgs->mgs_fstype || !mgs->mgs_bottom)
+ return -ENODEV;
+
+ osd_kobj = &mgs->mgs_bottom->dd_kobj;
+ return lustre_attr_show(osd_kobj, mgs->mgs_fstype, buf);
+}
+LUSTRE_RO_ATTR(fstype);
+
+static ssize_t mntdev_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ struct obd_device *obd = container_of(kobj, struct obd_device,
+ obd_kset.kobj);
+ struct mgs_device *mgs = lu2mgs_dev(obd->obd_lu_dev);
+ struct kobject *osd_kobj;
+
+ if (!mgs || !mgs->mgs_mntdev || !mgs->mgs_bottom)
+ return -ENODEV;
+
+ osd_kobj = &mgs->mgs_bottom->dd_kobj;
+ return lustre_attr_show(osd_kobj, mgs->mgs_mntdev, buf);
+}
+LUSTRE_RO_ATTR(mntdev);
+
+static struct attribute *mgs_attrs[] = {
+ &lustre_attr_fstype.attr,
+ &lustre_attr_mntdev.attr,
+ &lustre_attr_num_exports.attr,
+ NULL,
+};
+
+int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name)
+{
+ int osd_len = strlen(osd_name) - strlen("-osd");
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;
+ struct kobj_type *bottom_type;
+ struct obd_device *osd_obd;
+ int rc;
+ int i;
+
+ obd->obd_vars = lprocfs_mgs_obd_vars;
+ obd->obd_ktype.default_attrs = mgs_attrs;
+ rc = lprocfs_obd_setup(obd, true);
+ if (rc != 0)
+ GOTO(out, rc);
+
+ rc = ldebugfs_seq_create(obd->obd_debugfs_entry, "filesystems", 0444,
+ &mgs_fs_fops, obd);
+ if (rc != 0)
+ GOTO(out, rc);
- rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
- &mgs_fs_fops, obd);
- rc = lprocfs_obd_seq_create(obd, "srpc_rules", 0600,
- &mgsself_srpc_fops, obd);
+ rc = ldebugfs_seq_create(obd->obd_debugfs_entry, "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);
+ 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);
- CERROR("error %d setting up lprocfs for %s\n", rc, "live");
mgs->mgs_proc_live = NULL;
+ GOTO(out, rc);
}
- obd->obd_proc_exports_entry = lprocfs_register("exports",
- obd->obd_proc_entry,
- NULL, NULL);
+ 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);
- CERROR("error %d setting up lprocfs for %s\n", rc, "exports");
obd->obd_proc_exports_entry = NULL;
+ GOTO(out, rc);
}
+ rc = sysfs_create_link(&obd->obd_kset.kobj, &mgs->mgs_bottom->dd_kobj,
+ "osd");
+ if (rc) {
+ CWARN("%s: failed to create symlink osd -> %s, rc = %d\n",
+ kobject_name(&obd->obd_kset.kobj),
+ kobject_name(&mgs->mgs_bottom->dd_kobj), rc);
+ rc = 0;
+ }
+
+ bottom_type = get_ktype(&mgs->mgs_bottom->dd_kobj);
+
+ for (i = 0; bottom_type->default_attrs[i]; i++) {
+ if (strcmp(bottom_type->default_attrs[i]->name, "fstype") == 0) {
+ mgs->mgs_fstype = bottom_type->default_attrs[i];
+ break;
+ }
+ }
+
+ for (i = 0; bottom_type->default_attrs[i]; i++) {
+ if (strcmp(bottom_type->default_attrs[i]->name, "mntdev") == 0) {
+ mgs->mgs_mntdev = bottom_type->default_attrs[i];
+ break;
+ }
+ }
+
+ osd_obd = mgs->mgs_bottom->dd_lu_dev.ld_obd;
mgs->mgs_proc_osd = lprocfs_add_symlink("osd",
obd->obd_proc_entry,
"../../%s/%.*s",
osd_name);
if (mgs->mgs_proc_osd == NULL)
rc = -ENOMEM;
-
- mgs->mgs_proc_mntdev = lprocfs_add_symlink("mntdev",
- obd->obd_proc_entry,
- "osd/mntdev");
- if (mgs->mgs_proc_mntdev == NULL)
- rc = -ENOMEM;
-
- mgs->mgs_proc_fstype = lprocfs_add_symlink("fstype",
- obd->obd_proc_entry,
- "osd/fstype");
- if (mgs->mgs_proc_fstype == NULL)
- rc = -ENOMEM;
+out:
+ if (rc != 0)
+ lproc_mgs_cleanup(mgs);
return rc;
}
-int lproc_mgs_cleanup(struct mgs_device *mgs)
+void lproc_mgs_cleanup(struct mgs_device *mgs)
{
struct obd_device *obd = mgs->mgs_obd;
- if (!obd)
- return -EINVAL;
+ 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);
+ sysfs_remove_link(&obd->obd_kset.kobj, "osd");
+
+ if (mgs->mgs_proc_live != NULL) {
+ /* Should be no live entries */
+ lprocfs_remove(&mgs->mgs_proc_live);
+ mgs->mgs_proc_live = NULL;
+ }
- if (mgs->mgs_proc_mntdev)
- lprocfs_remove(&mgs->mgs_proc_mntdev);
- if (mgs->mgs_proc_live) {
- /* Should be no live entries */
- LASSERT(mgs->mgs_proc_live->subdir == NULL);
- 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);
-
- return lprocfs_obd_cleanup(obd);
-}
-
-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;
-}
-
-static ssize_t mgs_live_seq_write(struct file *file, const char *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 mgs_device *mgs, struct fs_db *fsdb)
-{
- 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);
-
- return 0;
-}
-
-int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
-{
- if (!mgs->mgs_proc_live)
- return 0;
-
- 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 },
- { "num_exports", lprocfs_rd_num_exports, 0, 0 },
- { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
- { "evict_client", 0, lprocfs_wr_evict_client, 0 },
- { "ir_timeout", lprocfs_rd_ir_timeout, lprocfs_wr_ir_timeout, 0 },
- { 0 }
-};
-
-struct lprocfs_vars lprocfs_mgs_module_vars[] = {
- { 0 }
-};
-
void mgs_counter_incr(struct obd_export *exp, int opcode)
{
lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
}
-
-void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
-{
- lvars->module_vars = lprocfs_mgs_module_vars;
- lvars->obd_vars = lprocfs_mgs_obd_vars;
-}
#endif