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