Whamcloud - gitweb
b7f519ed532b32da4520a141486efd5ef03a2990
[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 #include "mds_internal.h"
32
33 #ifndef LPROCFS
34 struct lprocfs_vars lprocfs_mds_obd_vars[]  = { {0} };
35 struct lprocfs_vars lprocfs_mds_module_vars[] = { {0} };
36 struct lprocfs_vars lprocfs_mdt_obd_vars[] = { {0} };
37 struct lprocfs_vars lprocfs_mdt_module_vars[] = { {0} };
38
39 #else
40
41 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
42                                  int *eof, void *data)
43 {
44         struct obd_device* obd = (struct obd_device *)data;
45
46         LASSERT(obd != NULL);
47         LASSERT(obd->u.mds.mds_vfsmnt->mnt_devname);
48         *eof = 1;
49
50         return snprintf(page, count, "%s\n",obd->u.mds.mds_vfsmnt->mnt_devname);
51 }
52
53 static int lprocfs_mds_rd_recovery_status(char *page, char **start, off_t off,
54                                           int count, int *eof, void *data)
55 {
56         struct obd_device *obd = data;
57         int len = 0, n,
58                 connected = obd->obd_connected_clients,
59                 max_recoverable = obd->obd_max_recoverable_clients,
60                 recoverable = obd->obd_recoverable_clients,
61                 completed = max_recoverable - recoverable,
62                 queue_len = obd->obd_requests_queued_for_recovery,
63                 replayed = obd->obd_replayed_requests;
64         __u64 next_transno = obd->obd_next_recovery_transno;
65
66         LASSERT(obd != NULL);
67         *eof = 1;
68
69         n = snprintf(page, count, "status: ");
70         page += n; len += n; count -= n;
71         if (obd->obd_max_recoverable_clients == 0) {
72                 n = snprintf(page, count, "INACTIVE\n");
73                 return len + n;
74         }
75
76         if (obd->obd_recoverable_clients == 0) {
77                 n = snprintf(page, count, "COMPLETE\n");
78                 page += n; len += n; count -= n;
79                 n = snprintf(page, count, "recovered_clients: %d\n",
80                              max_recoverable);
81                 page += n; len += n; count -= n;
82                 n = snprintf(page, count, "last_transno: "LPD64"\n",
83                              next_transno - 1);
84                 page += n; len += n; count -= n;
85                 n = snprintf(page, count, "replayed_requests: %d\n", replayed);
86                 return len + n;
87         }
88
89         /* sampled unlocked, but really... */
90         if (obd->obd_recovering == 0) {
91                 n = snprintf(page, count, "ABORTED\n");
92                 return len + n;
93         }
94
95         n = snprintf(page, count, "RECOVERING\n");
96         page += n; len += n; count -= n;
97         n = snprintf(page, count, "connected_clients: %d/%d\n",
98                      connected, max_recoverable);
99         page += n; len += n; count -= n;
100         n = snprintf(page, count, "completed_clients: %d/%d\n",
101                      completed, max_recoverable);
102         page += n; len += n; count -= n;
103         n = snprintf(page, count, "replayed_requests: %d/??\n", replayed);
104         page += n; len += n; count -= n;
105         n = snprintf(page, count, "queued_requests: %d\n", queue_len);
106         page += n; len += n; count -= n;
107         n = snprintf(page, count, "next_transno: "LPD64"\n", next_transno);
108         return len + n;
109 }
110
111 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
112                                        unsigned long count, void *data)
113 {
114         struct obd_device *obd = data;
115         struct obd_export *doomed_exp = NULL;
116         struct obd_uuid doomed;
117         struct list_head *p;
118         char tmpbuf[sizeof(doomed)];
119
120         sscanf(buffer, "%40s", tmpbuf);
121         obd_str2uuid(&doomed, tmpbuf);
122
123         spin_lock(&obd->obd_dev_lock);
124         list_for_each(p, &obd->obd_exports) {
125                 doomed_exp = list_entry(p, struct obd_export, exp_obd_chain);
126                 if (obd_uuid_equals(&doomed, &doomed_exp->exp_client_uuid)) {
127                         class_export_get(doomed_exp);
128                         break;
129                 }
130                 doomed_exp = NULL;
131         }
132         spin_unlock(&obd->obd_dev_lock);
133
134         if (doomed_exp == NULL) {
135                 CERROR("can't disconnect %s: no export found\n",
136                        doomed.uuid);
137         } else {
138                 CERROR("evicting %s at adminstrative request\n",
139                        doomed.uuid);
140                 ptlrpc_fail_export(doomed_exp);
141                 class_export_put(doomed_exp);
142         }
143         return count;
144 }
145
146 static int lprocfs_mds_wr_config_update(struct file *file, const char *buffer,
147                                         unsigned long count, void *data)
148 {
149         struct obd_device *obd = data;
150         ENTRY;
151
152         RETURN(mds_lov_update_config(obd, 0));
153 }
154
155 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
156         { "uuid",         lprocfs_rd_uuid,        0, 0 },
157         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
158         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
159         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
160         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
161         { "fstype",       lprocfs_rd_fstype,      0, 0 },
162         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
163         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
164         { "mntdev",       lprocfs_mds_rd_mntdev,  0, 0 },
165         { "recovery_status", lprocfs_mds_rd_recovery_status, 0, 0 },
166         { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
167         { "config_update", 0, lprocfs_mds_wr_config_update, 0 },
168         { "num_exports",  lprocfs_rd_num_exports, 0, 0 },
169         { 0 }
170 };
171
172 struct lprocfs_vars lprocfs_mds_module_vars[] = {
173         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
174         { 0 }
175 };
176
177 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
178         { "uuid",         lprocfs_rd_uuid,        0, 0 },
179         { 0 }
180 };
181
182 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
183         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
184         { 0 }
185 };
186
187 #endif
188
189 struct lprocfs_static_vars lprocfs_array_vars[] = { {lprocfs_mds_module_vars,
190                                                      lprocfs_mds_obd_vars},
191                                                     {lprocfs_mdt_module_vars,
192                                                      lprocfs_mdt_obd_vars}};
193
194 LPROCFS_INIT_MULTI_VARS(lprocfs_array_vars,
195                         (sizeof(lprocfs_array_vars) /
196                          sizeof(struct lprocfs_static_vars)))