Whamcloud - gitweb
Bug Fix for Bug #369
[fs/lustre-release.git] / lustre / llite / lproc_llite.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_LLITE
23
24 #include <linux/lustre_lite.h>
25 #include <linux/lprocfs_status.h>
26
27
28 int rd_path(char* page, char **start, off_t off, int count, int *eof, 
29             void *data)
30 {
31         return 0;
32 }
33 int rd_fstype(char* page, char **start, off_t off, int count, int *eof, 
34               void *data)
35 {
36         int len = 0;
37         struct super_block *sb = (struct super_block*)data;
38         
39         len += snprintf(page, count, "%s\n", sb->s_type->name); 
40         return len;
41 }
42 int rd_blksize(char* page, char **start, off_t off, int count, int *eof, 
43                void *data)
44 {
45         int len = 0;
46         struct super_block *sb = (struct super_block*)data;
47         struct statfs mystats;
48
49         (sb->s_op->statfs)(sb, &mystats);
50         len += snprintf(page, count, LPU64"\n", (__u64)(mystats.f_bsize)); 
51         return len;
52
53 }
54 int rd_kbytestotal(char* page, char **start, off_t off, int count, int *eof, 
55                    void *data)
56 {
57         int len = 0;
58         struct super_block *sb = (struct super_block*)data;
59         struct statfs mystats;
60         __u32 blk_size;
61         __u64 result;
62
63         (sb->s_op->statfs)(sb, &mystats);
64         blk_size = mystats.f_bsize;
65         blk_size >>= 10;
66         result = mystats.f_blocks;
67         
68         while(blk_size >>= 1){
69                 result <<= 1;
70         }
71        
72         len += snprintf(page, count, LPU64"\n", result); 
73         return len;
74         
75 }
76
77
78 int rd_kbytesfree(char* page, char **start, off_t off, int count, int *eof, 
79                   void *data)
80 {
81         int len = 0;
82         struct super_block *sb = (struct super_block*)data;
83         struct statfs mystats; 
84         __u32 blk_size;
85         __u64 result;
86
87         (sb->s_op->statfs)(sb, &mystats);
88         blk_size = mystats.f_bsize;
89         blk_size >>= 10;
90         result = mystats.f_bfree;
91         
92         while(blk_size >>= 1){
93                 result <<= 1;
94         }
95        
96         len += snprintf(page, count, LPU64"\n", result); 
97         return len;
98
99         
100 }
101
102 int rd_filestotal(char* page, char **start, off_t off, int count, int *eof, 
103                   void *data)
104 {
105         
106         int len = 0;
107         struct super_block *sb = (struct super_block*)data;
108         struct statfs mystats; 
109         
110         (sb->s_op->statfs)(sb, &mystats);
111         len += snprintf(page, count, LPU64"\n", (__u64)(mystats.f_files)); 
112         return len;
113 }
114
115 int rd_filesfree(char* page, char **start, off_t off, int count, int *eof, 
116                  void *data)
117 {
118         
119         int len = 0;
120         struct super_block *sb = (struct super_block*)data;
121         struct statfs mystats; 
122         
123         (sb->s_op->statfs)(sb, &mystats);
124         len += snprintf(page, count, LPU64"\n", (__u64)(mystats.f_ffree)); 
125         return len;
126 }
127
128 int rd_filegroups(char* page, char **start, off_t off, int count, int *eof, 
129                   void *data)
130 {
131         return 0;
132 }
133 int rd_uuid(char* page, char **start, off_t off, int count, int *eof, 
134             void *data)
135 {
136         int len = 0;
137         struct super_block *sb = (struct super_block*)data;
138         struct ll_sb_info *sbi = ll_s2sbi(sb);
139         len += snprintf(page, count, "%s\n", sbi->ll_sb_uuid); 
140         return len;    
141
142 }
143 int rd_dev_name(char* page, char **start, off_t off, int count, int *eof, 
144                 void *data)
145 {
146         int len = 0;
147         struct obd_device* dev = (struct obd_device*)data;
148         len += snprintf(page, count, "%s\n", dev->obd_name);
149         return len;
150 }
151
152 int rd_dev_uuid(char* page, char **start, off_t off, int count, int *eof, 
153                 void *data)
154 {
155         int len = 0;
156         struct obd_device* dev = (struct obd_device*)data;
157         len += snprintf(page, count, "%s\n", dev->obd_uuid);
158         return len;
159 }
160
161
162 struct lprocfs_vars status_var_nm_1[] = {
163         {"status/uuid", rd_uuid, 0, 0},
164         {"status/mntpt_path", rd_path, 0, 0},
165         {"status/fstype", rd_fstype, 0, 0},
166         {"status/blocksize",rd_blksize, 0, 0},
167         {"status/kbytestotal",rd_kbytestotal, 0, 0},
168         {"status/kbytesfree", rd_kbytesfree, 0, 0},
169         {"status/filestotal", rd_filestotal, 0, 0},
170         {"status/filesfree", rd_filesfree, 0, 0},
171         {"status/filegroups", rd_filegroups, 0, 0},
172         {0}
173 };
174
175 /* 
176  * Proc registration function for Lustre
177  * file system
178  */
179
180
181 #define MAX_STRING_SIZE 100
182 void ll_proc_namespace(struct super_block* sb, char* osc, char* mdc)
183 {
184         char mnt_name[MAX_STRING_SIZE+1];
185         char uuid_name[MAX_STRING_SIZE+1];
186         struct lprocfs_vars d_vars[3];
187         struct ll_sb_info *sbi = ll_s2sbi(sb);
188         struct obd_device* obd;
189         int err;
190
191         
192         /* Register this mount instance with LProcFS */
193         snprintf(mnt_name, MAX_STRING_SIZE, "mount_%s", sbi->ll_sb_uuid);
194         mnt_name[MAX_STRING_SIZE] = '\0';
195         sbi->ll_proc_root = lprocfs_reg_mnt(mnt_name);
196         if (sbi->ll_proc_root == NULL) {
197                 CDEBUG(D_OTHER, "Could not register FS");
198                 return;
199         }
200         /* Add the static configuration info */
201         err = lprocfs_add_vars(sbi->ll_proc_root,status_var_nm_1, sb);
202         if (err) {
203                 CDEBUG(D_OTHER, "Unable to add procfs variables\n");
204                 return;
205         }
206         /* MDC */
207         obd = class_uuid2obd(mdc);
208         snprintf(mnt_name, MAX_STRING_SIZE, "status/%s/common_name", 
209                  obd->obd_type->typ_name);
210         mnt_name[MAX_STRING_SIZE] = '\0';
211         memset(d_vars, 0, sizeof(d_vars));
212         d_vars[0].read_fptr = rd_dev_name;
213         d_vars[0].write_fptr = NULL;
214         d_vars[0].name = mnt_name;
215         snprintf(uuid_name, MAX_STRING_SIZE, "status/%s/uuid",
216                  obd->obd_type->typ_name);
217         uuid_name[MAX_STRING_SIZE] = '\0';
218         d_vars[1].read_fptr = rd_dev_uuid;
219         d_vars[1].write_fptr = NULL;
220         d_vars[1].name = uuid_name;
221
222         err = lprocfs_add_vars(sbi->ll_proc_root, d_vars, obd);
223         if (err) {
224                 CDEBUG(D_OTHER, "Unable to add fs proc dynamic variables\n");
225                 return;
226         }
227         /* OSC or LOV*/
228         obd = class_uuid2obd(osc);
229
230         /* Reuse mnt_name */
231         snprintf(mnt_name, MAX_STRING_SIZE, 
232                  "status/%s/common_name", obd->obd_type->typ_name);
233         mnt_name[MAX_STRING_SIZE] = '\0';
234         memset(d_vars, 0, sizeof(d_vars));
235         d_vars[0].read_fptr = rd_dev_name;
236         d_vars[0].write_fptr = NULL;
237         d_vars[0].name = mnt_name;
238
239         snprintf(uuid_name, MAX_STRING_SIZE, "status/%s/uuid",
240                  obd->obd_type->typ_name);
241         uuid_name[MAX_STRING_SIZE] = '\0';
242         d_vars[1].read_fptr = rd_dev_uuid;
243         d_vars[1].write_fptr = NULL;
244         d_vars[1].name = uuid_name;
245
246         err = lprocfs_add_vars(sbi->ll_proc_root, d_vars, obd);
247         if (err) {
248                 CDEBUG(D_OTHER, "Unable to add fs proc dynamic variables\n");
249                 return;
250         }
251 }
252 #undef MAX_STRING_SIZE