4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 #define DEBUG_SUBSYSTEM S_CLASS
33 #include <linux/version.h>
34 #include <asm/statfs.h>
36 #include <obd_class.h>
37 #include <lprocfs_status.h>
38 #include <uapi/linux/lustre/lustre_param.h>
39 #include "mgs_internal.h"
43 static int mgs_fs_seq_show(struct seq_file *seq, void *v)
45 struct obd_device *obd = seq->private;
46 struct mgs_device *mgs;
47 struct list_head list;
48 struct mgs_direntry *dirent, *n;
55 LASSERT(obd->obd_lu_dev != NULL);
56 mgs = lu2mgs_dev(obd->obd_lu_dev);
58 rc = lu_env_init(&env, LCT_MG_THREAD);
62 rc = class_dentry_readdir(&env, mgs, &list);
66 list_for_each_entry_safe(dirent, n, &list, mde_list) {
67 list_del_init(&dirent->mde_list);
68 len = strlen(dirent->mde_name);
70 strncmp(dirent->mde_name + len - 7, "-client", len) == 0)
71 seq_printf(seq, "%.*s\n", len - 7, dirent->mde_name);
72 mgs_direntry_free(dirent);
80 LDEBUGFS_SEQ_FOPS_RO(mgs_fs);
82 static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname,
83 struct sptlrpc_rule_set *rset)
85 struct sptlrpc_rule *r;
88 char net_buf[LNET_NIDSTR_SIZE];
92 for (i = 0; i < rset->srs_nrule; i++) {
93 r = &rset->srs_rules[i];
95 if (r->sr_netid == LNET_NET_ANY)
98 net = libcfs_net2str_r(r->sr_netid, net_buf,
101 if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
104 snprintf(dirbuf, sizeof(dirbuf), ".%s2%s",
105 sptlrpc_part2name(r->sr_from),
106 sptlrpc_part2name(r->sr_to));
108 sptlrpc_flavor2name(&r->sr_flvr, flvrbuf, sizeof(flvrbuf));
109 seq_printf(seq, "%s.srpc.flavor.%s%s=%s\n", tgtname,
110 net, dirbuf, flvrbuf);
114 static int mgsself_srpc_seq_show(struct seq_file *seq, void *v)
116 struct obd_device *obd = seq->private;
117 struct mgs_device *mgs = lu2mgs_dev(obd->obd_lu_dev);
118 struct lu_target *tgt = &mgs->mgs_lut;
120 read_lock(&tgt->lut_sptlrpc_lock);
121 seq_show_srpc_rules(seq, MGSSELF_NAME, &tgt->lut_sptlrpc_rset);
122 read_unlock(&tgt->lut_sptlrpc_lock);
126 LDEBUGFS_SEQ_FOPS_RO(mgsself_srpc);
128 static int mgs_live_seq_show(struct seq_file *seq, void *v)
130 struct fs_db *fsdb = seq->private;
131 struct mgs_tgt_srpc_conf *srpc_tgt;
134 mutex_lock(&fsdb->fsdb_mutex);
136 seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
137 seq_printf(seq, "flags: %#lx gen: %d\n",
138 fsdb->fsdb_flags, fsdb->fsdb_gen);
139 for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
140 if (test_bit(i, fsdb->fsdb_mdt_index_map))
141 seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
142 for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
143 if (test_bit(i, fsdb->fsdb_ost_index_map))
144 seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
146 seq_printf(seq, "\nSecure RPC Config Rules:\n");
148 seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name,
149 PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no");
151 for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt;
152 srpc_tgt = srpc_tgt->mtsc_next) {
153 seq_show_srpc_rules(seq, srpc_tgt->mtsc_tgt,
154 &srpc_tgt->mtsc_rset);
156 seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
158 lprocfs_rd_ir_state(seq, fsdb);
160 mutex_unlock(&fsdb->fsdb_mutex);
164 static ssize_t mgs_live_seq_write(struct file *file, const char __user *buf,
165 size_t len, loff_t *off)
167 struct seq_file *seq = file->private_data;
168 struct fs_db *fsdb = seq->private;
171 rc = lprocfs_wr_ir_state(file, buf, len, fsdb);
176 LPROC_SEQ_FOPS(mgs_live);
178 int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
182 if (!mgs->mgs_proc_live || fsdb->fsdb_has_lproc_entry)
185 rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0644,
186 &mgs_live_fops, fsdb);
188 fsdb->fsdb_has_lproc_entry = 1;
193 int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
195 if (!mgs->mgs_proc_live || !fsdb->fsdb_has_lproc_entry)
198 /* didn't create the proc file for MGSSELF_NAME */
199 if (!test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
200 lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
204 LPROC_SEQ_FOPS_RO_TYPE(mgs, hash);
205 LPROC_SEQ_FOPS_WR_ONLY(mgs, evict_client);
206 LPROC_SEQ_FOPS_RW_TYPE(mgs, ir_timeout);
208 static struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
209 { .name = "hash_stats",
210 .fops = &mgs_hash_fops },
211 { .name = "evict_client",
212 .fops = &mgs_evict_client_fops },
213 { .name = "ir_timeout",
214 .fops = &mgs_ir_timeout_fops },
218 LUSTRE_RO_ATTR(num_exports);
220 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
223 struct obd_device *obd = container_of(kobj, struct obd_device,
225 struct mgs_device *mgs = lu2mgs_dev(obd->obd_lu_dev);
226 struct kobject *osd_kobj;
228 if (!mgs || !mgs->mgs_fstype || !mgs->mgs_bottom)
231 osd_kobj = &mgs->mgs_bottom->dd_kobj;
232 return lustre_attr_show(osd_kobj, mgs->mgs_fstype, buf);
234 LUSTRE_RO_ATTR(fstype);
236 static ssize_t mntdev_show(struct kobject *kobj, struct attribute *attr,
239 struct obd_device *obd = container_of(kobj, struct obd_device,
241 struct mgs_device *mgs = lu2mgs_dev(obd->obd_lu_dev);
242 struct kobject *osd_kobj;
244 if (!mgs || !mgs->mgs_mntdev || !mgs->mgs_bottom)
247 osd_kobj = &mgs->mgs_bottom->dd_kobj;
248 return lustre_attr_show(osd_kobj, mgs->mgs_mntdev, buf);
250 LUSTRE_RO_ATTR(mntdev);
252 static struct attribute *mgs_attrs[] = {
253 &lustre_attr_fstype.attr,
254 &lustre_attr_mntdev.attr,
255 &lustre_attr_num_exports.attr,
259 int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name)
261 int osd_len = strlen(osd_name) - strlen("-osd");
262 struct obd_device *obd = mgs->mgs_obd;
263 struct kobj_type *bottom_type;
264 struct obd_device *osd_obd;
268 obd->obd_vars = lprocfs_mgs_obd_vars;
269 obd->obd_ktype.default_attrs = mgs_attrs;
270 rc = lprocfs_obd_setup(obd, true);
274 debugfs_create_file("filesystems", 0444, obd->obd_debugfs_entry, obd,
277 debugfs_create_file("srpc_rules", 0400, obd->obd_debugfs_entry, obd,
280 mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry,
282 if (IS_ERR(mgs->mgs_proc_live)) {
283 rc = PTR_ERR(mgs->mgs_proc_live);
284 mgs->mgs_proc_live = NULL;
288 obd->obd_proc_exports_entry = lprocfs_register("exports",
291 if (IS_ERR(obd->obd_proc_exports_entry)) {
292 rc = PTR_ERR(obd->obd_proc_exports_entry);
293 obd->obd_proc_exports_entry = NULL;
297 rc = sysfs_create_link(&obd->obd_kset.kobj, &mgs->mgs_bottom->dd_kobj,
300 CWARN("%s: failed to create symlink osd -> %s, rc = %d\n",
301 kobject_name(&obd->obd_kset.kobj),
302 kobject_name(&mgs->mgs_bottom->dd_kobj), rc);
306 bottom_type = get_ktype(&mgs->mgs_bottom->dd_kobj);
308 for (i = 0; bottom_type->default_attrs[i]; i++) {
309 if (strcmp(bottom_type->default_attrs[i]->name, "fstype") == 0) {
310 mgs->mgs_fstype = bottom_type->default_attrs[i];
315 for (i = 0; bottom_type->default_attrs[i]; i++) {
316 if (strcmp(bottom_type->default_attrs[i]->name, "mntdev") == 0) {
317 mgs->mgs_mntdev = bottom_type->default_attrs[i];
322 osd_obd = mgs->mgs_bottom->dd_lu_dev.ld_obd;
323 mgs->mgs_proc_osd = lprocfs_add_symlink("osd",
326 osd_obd->obd_type->typ_name,
327 osd_len, /* Strip "-osd". */
329 if (mgs->mgs_proc_osd == NULL)
333 lproc_mgs_cleanup(mgs);
338 void lproc_mgs_cleanup(struct mgs_device *mgs)
340 struct obd_device *obd = mgs->mgs_obd;
345 if (mgs->mgs_proc_osd != NULL)
346 lprocfs_remove(&mgs->mgs_proc_osd);
348 sysfs_remove_link(&obd->obd_kset.kobj, "osd");
350 if (mgs->mgs_proc_live != NULL) {
351 /* Should be no live entries */
352 lprocfs_remove(&mgs->mgs_proc_live);
353 mgs->mgs_proc_live = NULL;
356 lprocfs_free_per_client_stats(obd);
357 lprocfs_obd_cleanup(obd);
358 lprocfs_free_obd_stats(obd);
359 lprocfs_free_md_stats(obd);
362 void mgs_counter_incr(struct obd_export *exp, int opcode)
364 lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
365 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
366 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
369 void mgs_stats_counter_init(struct lprocfs_stats *stats)
371 lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
372 lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
374 lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
376 lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
377 lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");