Whamcloud - gitweb
land b_md onto HEAD. the highlights:
[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/lustre_lite.h>
25 #include <linux/lustre_fsfilt.h>
26 #include <linux/lprocfs_status.h>
27
28 int rd_uuid(char* page, char **start, off_t off, int count, int *eof, 
29             void *data)
30 {
31         struct obd_device* temp = (struct obd_device*)data;
32         int len = 0;
33         len += snprintf(page, count, "%s\n", temp->obd_uuid); 
34         return len;  
35 }
36 int rd_blksize(char* page, char **start, off_t off, int count, int *eof, 
37                void *data)
38 {
39         struct obd_device* temp = (struct obd_device*)data;
40         struct mds_obd *mds = &temp->u.mds;
41         struct statfs mystats;
42         int rc, len = 0;
43         
44         rc = vfs_statfs(mds->mds_sb, &mystats);
45         if (rc) {
46                 CERROR("mds: statfs failed: rc %d\n", rc);
47                 return 0;
48         }
49         len += snprintf(page, count, LPU64"\n", (__u64)(mystats.f_bsize)); 
50         return len;
51
52 }
53 int rd_kbtotal(char* page, char **start, off_t off, int count, int *eof, 
54                void *data)
55 {
56         struct obd_device* temp = (struct obd_device*)data;
57         struct mds_obd *mds = &temp->u.mds;
58         struct statfs mystats;
59         int rc, len = 0;
60         __u32 blk_size;
61         __u64 result;
62         
63         rc = vfs_statfs(mds->mds_sb, &mystats);
64         if (rc) {
65                 CERROR("mds: statfs failed: rc %d\n", rc);
66                 return 0;
67         }
68         
69         blk_size = mystats.f_bsize;
70         blk_size >>= 10;
71         result = mystats.f_blocks;
72         while(blk_size >>= 1){
73                 result <<= 1;
74         }
75         len += snprintf(page, count, LPU64"\n", result); 
76         return len;  
77         
78 }
79
80 int rd_kbfree(char* page, char **start, off_t off, int count, int *eof, 
81               void *data)
82 {
83         struct obd_device* temp = (struct obd_device*)data;
84         struct mds_obd *mds = &temp->u.mds;
85         struct statfs mystats;
86         int rc, len = 0;
87         __u32 blk_size;
88         __u64 result;
89         
90
91         rc = vfs_statfs(mds->mds_sb, &mystats);
92         if (rc) {
93                 CERROR("mds: statfs failed: rc %d\n", rc);
94                 return 0;
95         }
96         blk_size = mystats.f_bsize;
97         blk_size >>= 10;
98         result = mystats.f_blocks;
99         while(blk_size >>= 1){
100                 result <<= 1;
101         }
102         len += snprintf(page, count, LPU64"\n", result);
103         return len;  
104         
105 }
106
107 int rd_fstype(char *page, char **start, off_t off, int count, int *eof,
108               void *data)
109 {
110         struct obd_device *obd = (struct obd_device *)data;
111
112         return snprintf(page, count, "%s\n", obd->obd_fsops->fs_type);
113 }
114
115 int rd_filestotal(char* page, char **start, off_t off, int count, int *eof, 
116                   void *data)
117 {
118         struct obd_device* temp = (struct obd_device*)data;
119         struct mds_obd *mds = &temp->u.mds;
120         struct statfs mystats;
121         int rc, len = 0;
122         
123         rc = vfs_statfs(mds->mds_sb, &mystats);
124         if (rc) {
125                 CERROR("mds: statfs failed: rc %d\n", rc);
126                 return 0;
127         }
128         
129         len += snprintf(page, count, LPU64"\n", (__u64)(mystats.f_files));
130         return len;  
131
132         
133 }
134
135 int rd_filesfree(char* page, char **start, off_t off, int count, int *eof, 
136                   void *data)
137 {
138         struct obd_device* temp = (struct obd_device*)data;
139         struct mds_obd *mds = &temp->u.mds;
140         struct statfs mystats;
141         int rc, len = 0;
142         
143         rc = vfs_statfs(mds->mds_sb, &mystats);
144         if (rc) {
145                 CERROR("mds: statfs failed: rc %d\n", rc);
146                 return 0;
147         }
148         
149         len += snprintf(page, count, LPU64"\n", (__u64)(mystats.f_ffree));
150         return len; 
151 }
152
153 int rd_filegroups(char* page, char **start, off_t off, int count, int *eof, 
154                   void *data)
155 {
156         return 0;
157 }
158 struct lprocfs_vars status_var_nm_1[]={
159         {"status/uuid", rd_uuid, 0, 0},
160         {"status/blocksize",rd_blksize, 0, 0},
161         {"status/kbytestotal",rd_kbtotal, 0, 0},
162         {"status/kbytesfree", rd_kbfree, 0, 0},
163         {"status/fstype", rd_fstype, 0, 0},
164         {"status/filestotal", rd_filestotal, 0, 0},
165         {"status/filesfree", rd_filesfree, 0, 0},
166         {"status/filegroups", rd_filegroups, 0, 0},
167         {0}
168 };
169 int rd_numrefs(char* page, char **start, off_t off, int count, int *eof, 
170                void *data)
171 {
172         struct obd_type* class = (struct obd_type*)data;
173         int len = 0;
174         len += snprintf(page, count, "%d\n", class->typ_refcnt);
175         return len;
176 }
177
178 struct lprocfs_vars status_class_var[]={
179         {"status/num_refs", rd_numrefs, 0, 0},
180         {0}
181 };