Whamcloud - gitweb
* 1st attempt to prevent duplicate devices being started.
[fs/lustre-release.git] / lustre / ost / lproc_ost.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_OST
23 #include <linux/obd_support.h>
24 #include <linux/obd_class.h>
25 #include <linux/lprocfs.h>
26 #include <linux/string.h>
27 #include <linux/lustre_lib.h>
28
29 /* Required for 64 bit division */
30 #include <asm/div64.h>
31
32 int rd_uuid(char* page, char **start, off_t off,
33                int count, int *eof, void *data)
34 {
35          
36         struct obd_device* temp=(struct obd_device*)data;
37         int len=0;
38         len+=snprintf(page, count, "%s\n", temp->obd_uuid); 
39         return len;
40         
41
42 }
43 int rd_blksize(char* page, char **start, off_t off,
44                int count, int *eof, void *data)
45 {
46         
47         struct obd_device* temp=(struct obd_device*)data;
48         struct ost_obd *ost=&temp->u.ost;
49         struct lustre_handle *conn=&ost->ost_conn;
50         struct obd_statfs mystats;
51         int rc, len=0;
52         
53         rc = obd_statfs(conn, &mystats);
54         if (rc) {
55                 CERROR("ost: statfs failed: rc %d\n", rc);
56                 return 0;
57         }
58         len+=snprintf(page, count, LPU64"\n", (__u64)(mystats.os_bsize)); 
59         return len;
60         
61 }
62 int rd_blktotal(char* page, char **start, off_t off,
63                 int count, int *eof, void *data)
64 {
65         
66         struct obd_device* temp=(struct obd_device*)data;
67         struct ost_obd *ost=&temp->u.ost;
68         struct lustre_handle *conn=&ost->ost_conn;
69         struct obd_statfs mystats;
70         int rc, len=0;
71         
72         rc = obd_statfs(conn, &mystats);
73         if (rc) {
74                 CERROR("ost: statfs failed: rc %d\n", rc);
75                 return 0;
76         }
77         len+=snprintf(page, count, LPU64"\n", (__u64)(mystats.os_blocks)); 
78         return len;
79         
80 }
81
82 int rd_blkfree(char* page, char **start, off_t off,
83                int count, int *eof, void *data)
84 {
85         
86         struct obd_device* temp=(struct obd_device*)data;
87         struct ost_obd *ost=&temp->u.ost;
88         struct lustre_handle *conn=&ost->ost_conn;
89         struct obd_statfs mystats;
90         int rc, len=0;
91         
92         rc = obd_statfs(conn, &mystats);
93         if (rc) {
94                 CERROR("ost: statfs failed: rc %d\n", rc);
95                 return 0;
96         }
97         len+=snprintf(page, count, LPU64"\n", (__u64)(mystats.os_bfree)); 
98         return len;
99         
100 }
101
102 int rd_kbfree(char* page, char **start, off_t off,
103               int count, int *eof, void *data)
104 {
105         
106         struct obd_device* temp=(struct obd_device*)data;
107         struct ost_obd *ost=&temp->u.ost;
108         struct lustre_handle *conn=&ost->ost_conn;
109         struct obd_statfs mystats;
110         int rc, len=0;
111         __u32 blk_size;
112         __u64 result;
113         __u32 remainder;
114
115         rc = obd_statfs(conn, &mystats);
116         if (rc) {
117                 CERROR("ost: statfs failed: rc %d\n", rc);
118                 return 0;
119         }
120         blk_size=mystats.os_bsize;
121         blk_size*=1024;
122         result=mystats.os_bfree;
123         remainder=do_div(result, blk_size);
124
125         len+=snprintf(page, count, LPU64"\n", \
126                       result);
127         
128         return len;  
129         
130        
131 }
132
133 int rd_numobjects(char* page, char **start, off_t off,
134                   int count, int *eof, void *data)
135 {
136         
137         struct obd_device* temp=(struct obd_device*)data;
138         struct ost_obd *ost=&temp->u.ost;
139         struct lustre_handle *conn=&ost->ost_conn;
140         struct obd_statfs mystats;
141         int rc, len=0;
142         
143         rc = obd_statfs(conn, &mystats);
144         if (rc) {
145                 CERROR("ost: statfs failed: rc %d\n", rc);
146                 return 0;
147         }
148         len+=snprintf(page, count, LPU64"\n", (__u64)(mystats.os_files)); 
149         return len;
150         
151 }
152
153 int rd_objfree(char* page, char **start, off_t off,
154                int count, int *eof, void *data)
155 {
156         
157         struct obd_device* temp=(struct obd_device*)data;
158         struct ost_obd *ost=&temp->u.ost;
159         struct lustre_handle *conn=&ost->ost_conn;
160         struct obd_statfs mystats;
161         int rc, len=0;
162         
163         rc = obd_statfs(conn, &mystats);
164         if (rc) {
165                 CERROR("ost: statfs failed: rc %d\n", rc);
166                 return 0;
167         }
168         len+=snprintf(page, count, LPU64"\n", (__u64)(mystats.os_ffree)); 
169         return len;
170         
171 }
172
173 int rd_objgroups(char* page, char **start, off_t off,
174                  int count, int *eof, void *data)
175 {
176         return 0;
177 }
178
179 lprocfs_vars_t snmp_var_nm_1[]={
180         {"snmp/uuid", rd_uuid, 0},
181         {"snmp/f_blocksize",rd_blksize, 0},
182         {"snmp/f_blockstotal",rd_blktotal, 0},
183         {"snmp/f_blocksfree",rd_blkfree, 0},
184         {"snmp/f_kbytesfree", rd_kbfree, 0},
185         {"snmp/f_objects", rd_numobjects, 0},
186         {"snmp/f_objectsfree", rd_objfree, 0},
187         {"snmp/f_objectgroups", rd_objgroups, 0},
188         {0}
189 };