Whamcloud - gitweb
Branch b1_6
[fs/lustre-release.git] / lustre / mgs / lproc_mgs.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
9  *   You may have signed or agreed to another license before downloading
10  *   this software.  If so, you are bound by the terms and conditions
11  *   of that agreement, and the following does not apply to you.  See the
12  *   LICENSE file included with this distribution for more information.
13  *
14  *   If you did not agree to a different license, then this copy of Lustre
15  *   is open source software; you can redistribute it and/or modify it
16  *   under the terms of version 2 of the GNU General Public License as
17  *   published by the Free Software Foundation.
18  *
19  *   In either case, Lustre is distributed in the hope that it will be
20  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   license text for more details.
23  *
24  */
25 #define DEBUG_SUBSYSTEM S_CLASS
26
27 #include <linux/version.h>
28 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
29 #include <asm/statfs.h>
30 #endif
31 #include <obd.h>
32 #include <obd_class.h>
33 #include <lprocfs_status.h>
34 #include "mgs_internal.h"
35
36
37 #ifdef LPROCFS
38
39 static int lprocfs_mgs_rd_mntdev(char *page, char **start, off_t off, int count,
40                                  int *eof, void *data)
41 {
42         struct obd_device* obd = (struct obd_device *)data;
43
44         LASSERT(obd != NULL);
45         LASSERT(obd->u.mgs.mgs_vfsmnt->mnt_devname);
46         *eof = 1;
47
48         return snprintf(page, count, "%s\n",obd->u.mgs.mgs_vfsmnt->mnt_devname);
49 }
50
51 static int mgs_fs_seq_show(struct seq_file *seq, void *v)
52 {
53         struct obd_device *obd = seq->private;
54         struct mgs_obd *mgs = &obd->u.mgs;
55         struct list_head dentry_list;
56         struct l_linux_dirent *dirent, *n;
57         int rc, len;
58         ENTRY;
59
60         LASSERT(obd != NULL);
61         rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
62                                   mgs->mgs_vfsmnt, &dentry_list);
63         if (rc) {
64                 CERROR("Can't read config dir\n");
65                 RETURN(rc);
66         }
67         list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
68                 list_del(&dirent->lld_list);
69                 len = strlen(dirent->lld_name);
70                 if ((len > 7) && (strncmp(dirent->lld_name + len - 7, "-client",
71                                           len) == 0)) {
72                         seq_printf(seq, "%.*s\n", len - 7, dirent->lld_name);
73                 }
74                 OBD_FREE(dirent, sizeof(*dirent));
75         }
76
77         RETURN(0);
78 }
79
80 LPROC_SEQ_FOPS_RO(mgs_fs);
81
82 int lproc_mgs_setup(struct obd_device *obd)
83 {
84         struct mgs_obd *mgs = &obd->u.mgs;
85         int rc;
86
87         rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
88                                     &mgs_fs_fops, obd);
89         mgs->mgs_proc_live = proc_mkdir("live", obd->obd_proc_entry);
90         obd->obd_proc_exports_entry = proc_mkdir("exports",
91                                                  obd->obd_proc_entry);
92
93         return rc;
94 }
95
96 int lproc_mgs_cleanup(struct obd_device *obd)
97 {
98         struct mgs_obd *mgs;
99
100         if (!obd)
101                 return -EINVAL;
102
103         mgs = &obd->u.mgs;
104         if (mgs->mgs_proc_live) {
105                 /* Should be no live entries */
106                 LASSERT(mgs->mgs_proc_live->subdir == NULL);
107                 lprocfs_remove(&mgs->mgs_proc_live);
108                 mgs->mgs_proc_live = NULL;
109         }
110         lprocfs_free_per_client_stats(obd);
111         lprocfs_free_obd_stats(obd);
112
113         return lprocfs_obd_cleanup(obd);
114 }
115
116 static int mgs_live_seq_show(struct seq_file *seq, void *v) 
117 {
118         struct fs_db *fsdb = seq->private;
119         int i;
120         
121         down(&fsdb->fsdb_sem);
122
123         seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
124         seq_printf(seq, "flags: %#x     gen: %d\n", 
125                    fsdb->fsdb_flags, fsdb->fsdb_gen);
126         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
127                  if (test_bit(i, fsdb->fsdb_mdt_index_map)) 
128                          seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
129         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
130                  if (test_bit(i, fsdb->fsdb_ost_index_map)) 
131                          seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
132
133         up(&fsdb->fsdb_sem);
134         return 0;
135 }
136
137 LPROC_SEQ_FOPS_RO(mgs_live);
138
139 int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
140 {
141         struct mgs_obd *mgs = &obd->u.mgs;
142         int rc;
143
144         if (!mgs->mgs_proc_live) 
145                 return 0;
146         rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0444, 
147                                 &mgs_live_fops, fsdb);
148
149         return 0;
150 }
151
152 int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
153 {
154         struct mgs_obd *mgs = &obd->u.mgs;
155
156         if (!mgs->mgs_proc_live) 
157                 return 0;
158         remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
159         return 0;
160 }
161
162 struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
163         { "uuid",            lprocfs_rd_uuid,        0, 0 },
164         { "fstype",          lprocfs_rd_fstype,      0, 0 },
165         { "mntdev",          lprocfs_mgs_rd_mntdev,  0, 0 },
166         { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
167         { "evict_client",    0, lprocfs_wr_evict_client, 0 },
168         { 0 }
169 };
170
171 struct lprocfs_vars lprocfs_mgs_module_vars[] = {
172         { 0 }
173 };
174
175 void mgs_counter_incr(struct obd_export *exp, int opcode)
176 {
177         lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
178         lprocfs_counter_incr(exp->exp_ops_stats, opcode);
179 }
180
181 void mgs_stats_counter_init(struct lprocfs_stats *stats)
182 {
183         lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
184         lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
185                              "reqs");
186         lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
187                              "reqs");
188         lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
189         lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
190 }
191
192 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
193 {
194     lvars->module_vars  = lprocfs_mgs_module_vars;
195     lvars->obd_vars     = lprocfs_mgs_obd_vars;
196 }
197 #endif