Whamcloud - gitweb
Fixes and cleanups in lmv.
[fs/lustre-release.git] / lustre / mds / lproc_mds.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 Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22 #define DEBUG_SUBSYSTEM S_CLASS
23
24 #include <linux/version.h>
25 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 #include <asm/statfs.h>
27 #endif
28 #include <linux/obd.h>
29 #include <linux/obd_class.h>
30 #include <linux/lprocfs_status.h>
31
32 #ifndef LPROCFS
33 struct lprocfs_vars lprocfs_mds_obd_vars[]  = { {0} };
34 struct lprocfs_vars lprocfs_mds_module_vars[] = { {0} };
35 struct lprocfs_vars lprocfs_mdt_obd_vars[] = { {0} };
36 struct lprocfs_vars lprocfs_mdt_module_vars[] = { {0} };
37
38 #else
39
40 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
41                                  int *eof, void *data)
42 {
43         struct obd_device* obd = (struct obd_device *)data;
44
45         LASSERT(obd != NULL);
46         LASSERT(obd->u.mds.mds_vfsmnt->mnt_devname);
47         *eof = 1;
48
49         return snprintf(page, count, "%s\n",obd->u.mds.mds_vfsmnt->mnt_devname);
50 }
51
52 static int lprocfs_mds_rd_filesopen(char *page, char **start, off_t off,
53                                     int count, int *eof, void *data)
54 {
55         struct obd_device *obd = data;
56         LASSERT(obd != NULL);
57         *eof = 1;
58
59         return snprintf(page, count, "%d\n",
60                         atomic_read(&obd->u.mds.mds_open_count));
61 }
62
63 static int lprocfs_mds_rd_recovery_status(char *page, char **start, off_t off,
64                                           int count, int *eof, void *data)
65 {
66         struct obd_device *obd = data;
67         int len = 0, n,
68                 connected = obd->obd_connected_clients,
69                 max_recoverable = obd->obd_max_recoverable_clients,
70                 recoverable = obd->obd_recoverable_clients,
71                 completed = max_recoverable - recoverable,
72                 queue_len = obd->obd_requests_queued_for_recovery,
73                 replayed = obd->obd_replayed_requests;
74         __u64 next_transno = obd->obd_next_recovery_transno;
75
76         LASSERT(obd != NULL);
77         *eof = 1;
78
79         n = snprintf(page, count, "status: ");
80         page += n; len += n; count -= n;
81         if (obd->obd_max_recoverable_clients == 0) {
82                 n = snprintf(page, count, "INACTIVE\n");
83                 return len + n;
84         }
85
86         if (obd->obd_recoverable_clients == 0) {
87                 n = snprintf(page, count, "COMPLETE\n");
88                 page += n; len += n; count -= n;
89                 n = snprintf(page, count, "recovered_clients: %d\n",
90                              max_recoverable);
91                 page += n; len += n; count -= n;
92                 n = snprintf(page, count, "last_transno: "LPD64"\n",
93                              next_transno - 1);
94                 page += n; len += n; count -= n;
95                 n = snprintf(page, count, "replayed_requests: %d\n", replayed);
96                 return len + n;
97         }
98
99         /* sampled unlocked, but really... */
100         if (obd->obd_recovering == 0) {
101                 n = snprintf(page, count, "ABORTED\n");
102                 return len + n;
103         }
104
105         n = snprintf(page, count, "RECOVERING\n");
106         page += n; len += n; count -= n;
107         n = snprintf(page, count, "connected_clients: %d/%d\n",
108                      connected, max_recoverable);
109         page += n; len += n; count -= n;
110         n = snprintf(page, count, "completed_clients: %d/%d\n",
111                      completed, max_recoverable);
112         page += n; len += n; count -= n;
113         n = snprintf(page, count, "replayed_requests: %d/??\n", replayed);
114         page += n; len += n; count -= n;
115         n = snprintf(page, count, "queued_requests: %d\n", queue_len);
116         page += n; len += n; count -= n;
117         n = snprintf(page, count, "next_transno: "LPD64"\n", next_transno);
118         return len + n;
119 }
120
121 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
122                                        unsigned long count, void *data)
123 {
124         struct obd_device *obd = data;
125         struct obd_export *doomed_exp = NULL;
126         struct obd_uuid doomed;
127         struct list_head *p;
128         char tmpbuf[sizeof(doomed)];
129
130         sscanf(buffer, "%40s", tmpbuf);
131         obd_str2uuid(&doomed, tmpbuf);
132
133         spin_lock(&obd->obd_dev_lock);
134         list_for_each(p, &obd->obd_exports) {
135                 doomed_exp = list_entry(p, struct obd_export, exp_obd_chain);
136                 if (obd_uuid_equals(&doomed, &doomed_exp->exp_client_uuid)) {
137                         class_export_get(doomed_exp);
138                         break;
139                 }
140                 doomed_exp = NULL;
141         }
142         spin_unlock(&obd->obd_dev_lock);
143
144         if (doomed_exp == NULL) {
145                 CERROR("can't disconnect %s: no export found\n",
146                        doomed.uuid);
147         } else {
148                 CERROR("evicting %s at adminstrative request\n",
149                        doomed.uuid);
150                 ptlrpc_fail_export(doomed_exp);
151                 class_export_put(doomed_exp);
152         }
153         return count;
154 }
155
156 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
157         { "uuid",         lprocfs_rd_uuid,        0, 0 },
158         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
159         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
160         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
161         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
162         { "fstype",       lprocfs_rd_fstype,      0, 0 },
163         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
164         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
165         { "filesopen",    lprocfs_mds_rd_filesopen,   0, 0 },
166         { "mntdev",       lprocfs_mds_rd_mntdev,  0, 0 },
167         { "recovery_status", lprocfs_mds_rd_recovery_status, 0, 0 },
168         { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
169         { "num_exports",  lprocfs_rd_num_exports, 0, 0 },
170         { 0 }
171 };
172
173 struct lprocfs_vars lprocfs_mds_module_vars[] = {
174         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
175         { 0 }
176 };
177
178 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
179         { "uuid",         lprocfs_rd_uuid,        0, 0 },
180         { 0 }
181 };
182
183 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
184         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
185         { 0 }
186 };
187
188 #endif
189
190 struct lprocfs_static_vars lprocfs_array_vars[] = { {lprocfs_mds_module_vars,
191                                                      lprocfs_mds_obd_vars},
192                                                     {lprocfs_mdt_module_vars,
193                                                      lprocfs_mdt_obd_vars}};
194
195 LPROCFS_INIT_MULTI_VARS(lprocfs_array_vars,
196                         (sizeof(lprocfs_array_vars) /
197                          sizeof(struct lprocfs_static_vars)))