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