Whamcloud - gitweb
Branch b1_6
[fs/lustre-release.git] / lustre / lov / lproc_lov.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 the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
9  *   You may have signed or agreed to another license before downloading
10  *   this software.  If so, you are bound by the terms and conditions
11  *   of that agreement, and the following does not apply to you.  See the
12  *   LICENSE file included with this distribution for more information.
13  *
14  *   If you did not agree to a different license, then this copy of Lustre
15  *   is open source software; you can redistribute it and/or modify it
16  *   under the terms of version 2 of the GNU General Public License as
17  *   published by the Free Software Foundation.
18  *
19  *   In either case, Lustre is distributed in the hope that it will be
20  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   license text for more details.
23  *
24  */
25 #define DEBUG_SUBSYSTEM S_CLASS
26
27 #include <linux/version.h>
28 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
29 #include <asm/statfs.h>
30 #endif
31 #include <lprocfs_status.h>
32 #include <obd_class.h>
33 #include <linux/seq_file.h>
34 #include "lov_internal.h"
35
36 #ifdef LPROCFS
37 static int lov_rd_stripesize(char *page, char **start, off_t off, int count,
38                              int *eof, void *data)
39 {
40         struct obd_device *dev = (struct obd_device *)data;
41         struct lov_desc *desc;
42
43         LASSERT(dev != NULL);
44         desc = &dev->u.lov.desc;
45         *eof = 1;
46         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
47 }
48
49 static int lov_wr_stripesize(struct file *file, const char *buffer,
50                                unsigned long count, void *data)
51 {
52         struct obd_device *dev = (struct obd_device *)data;
53         struct lov_desc *desc;
54         __u64 val;
55         int rc;
56         
57         LASSERT(dev != NULL);
58         desc = &dev->u.lov.desc;
59         rc = lprocfs_write_u64_helper(buffer, count, &val);
60         if (rc)
61                 return rc;
62
63         desc->ld_default_stripe_size = val;
64         lov_fix_desc(desc);
65         return count;
66 }
67
68 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
69                                int *eof, void *data)
70 {
71         struct obd_device *dev = (struct obd_device *)data;
72         struct lov_desc *desc;
73
74         LASSERT(dev != NULL);
75         desc = &dev->u.lov.desc;
76         *eof = 1;
77         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
78 }
79
80 static int lov_wr_stripeoffset(struct file *file, const char *buffer,
81                                unsigned long count, void *data)
82 {
83         struct obd_device *dev = (struct obd_device *)data;
84         struct lov_desc *desc;
85         __u64 val;
86         int rc;
87         
88         LASSERT(dev != NULL);
89         desc = &dev->u.lov.desc;
90         rc = lprocfs_write_u64_helper(buffer, count, &val);
91         if (rc)
92                 return rc;
93
94         desc->ld_default_stripe_offset = val;
95         lov_fix_desc(desc);
96         return count;
97 }
98
99 static int lov_rd_stripetype(char *page, char **start, off_t off, int count,
100                              int *eof, void *data)
101 {
102         struct obd_device* dev = (struct obd_device*)data;
103         struct lov_desc *desc;
104
105         LASSERT(dev != NULL);
106         desc = &dev->u.lov.desc;
107         *eof = 1;
108         return snprintf(page, count, "%u\n", desc->ld_pattern);
109 }
110
111 static int lov_wr_stripetype(struct file *file, const char *buffer,
112                              unsigned long count, void *data)
113 {
114         struct obd_device *dev = (struct obd_device *)data;
115         struct lov_desc *desc;
116         int val, rc;
117         
118         LASSERT(dev != NULL);
119         desc = &dev->u.lov.desc;
120         rc = lprocfs_write_helper(buffer, count, &val);
121         if (rc)
122                 return rc;
123
124         desc->ld_pattern = val;
125         lov_fix_desc(desc);
126         return count;
127 }
128
129 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
130                               int *eof, void *data)
131 {
132         struct obd_device *dev = (struct obd_device *)data;
133         struct lov_desc *desc;
134
135         LASSERT(dev != NULL);
136         desc = &dev->u.lov.desc;
137         *eof = 1;
138         return snprintf(page, count, "%ld\n",
139                         (long)(desc->ld_default_stripe_count + 1) - 1);
140 }
141
142 static int lov_wr_stripecount(struct file *file, const char *buffer,
143                               unsigned long count, void *data)
144 {
145         struct obd_device *dev = (struct obd_device *)data;
146         struct lov_desc *desc;
147         int val, rc;
148         
149         LASSERT(dev != NULL);
150         desc = &dev->u.lov.desc;
151         rc = lprocfs_write_helper(buffer, count, &val);
152         if (rc)
153                 return rc;
154
155         desc->ld_default_stripe_count = val;
156         lov_fix_desc(desc);
157         return count;
158 }
159
160 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
161                          int *eof, void *data)
162 {
163         struct obd_device *dev = (struct obd_device*)data;
164         struct lov_desc *desc;
165
166         LASSERT(dev != NULL);
167         desc = &dev->u.lov.desc;
168         *eof = 1;
169         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
170
171 }
172
173 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
174                             int *eof, void *data)
175 {
176         struct obd_device* dev = (struct obd_device*)data;
177         struct lov_desc *desc;
178
179         LASSERT(dev != NULL);
180         desc = &dev->u.lov.desc;
181         *eof = 1;
182         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
183 }
184
185 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
186                             int *eof, void *data)
187 {
188         struct obd_device *dev = (struct obd_device*) data;
189         struct lov_obd *lov;
190
191         LASSERT(dev != NULL);
192         lov = &dev->u.lov;
193         *eof = 1;
194         return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
195 }
196
197 /* free priority (0-255): how badly user wants to choose empty osts */ 
198 static int lov_rd_qos_priofree(char *page, char **start, off_t off, int count,
199                                int *eof, void *data)
200 {
201         struct obd_device *dev = (struct obd_device*) data;
202         struct lov_obd *lov;
203
204         LASSERT(dev != NULL);
205         lov = &dev->u.lov;
206         *eof = 1;
207         return snprintf(page, count, "%d%%\n", 
208                         (lov->lov_qos.lq_prio_free * 100) >> 8);
209 }
210
211 static int lov_wr_qos_priofree(struct file *file, const char *buffer,
212                                unsigned long count, void *data)
213 {
214         struct obd_device *dev = (struct obd_device *)data;
215         struct lov_obd *lov;
216         int val, rc;
217         LASSERT(dev != NULL);
218
219         lov = &dev->u.lov;
220         rc = lprocfs_write_helper(buffer, count, &val);
221         if (rc)
222                 return rc;
223
224         if (val > 100)
225                 return -EINVAL;
226         lov->lov_qos.lq_prio_free = (val << 8) / 100;
227         lov->lov_qos.lq_dirty = 1;
228         lov->lov_qos.lq_reset = 1;
229         return count;
230 }
231
232 static int lov_rd_qos_maxage(char *page, char **start, off_t off, int count,
233                              int *eof, void *data)
234 {
235         struct obd_device *dev = (struct obd_device*) data;
236         struct lov_obd *lov;
237
238         LASSERT(dev != NULL);
239         lov = &dev->u.lov;
240         *eof = 1;
241         return snprintf(page, count, "%u Sec\n", lov->desc.ld_qos_maxage);
242 }
243
244 static int lov_wr_qos_maxage(struct file *file, const char *buffer,
245                              unsigned long count, void *data)
246 {
247         struct obd_device *dev = (struct obd_device *)data;
248         struct lov_obd *lov;
249         int val, rc;
250         LASSERT(dev != NULL);
251
252         lov = &dev->u.lov;
253         rc = lprocfs_write_helper(buffer, count, &val);
254         if (rc)
255                 return rc;
256
257         if (val <= 0)
258                 return -EINVAL;
259         lov->desc.ld_qos_maxage = val;
260         return count;
261 }
262
263 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
264 {
265         struct obd_device *dev = p->private;
266         struct lov_obd *lov = &dev->u.lov;
267
268         while (*pos < lov->desc.ld_tgt_count) {
269                 if (lov->lov_tgts[*pos])
270                         return lov->lov_tgts[*pos];
271                 ++*pos;
272         }
273         return NULL;
274 }
275
276 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
277 {
278 }
279
280 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
281 {
282         struct obd_device *dev = p->private;
283         struct lov_obd *lov = &dev->u.lov;
284
285         while (++*pos < lov->desc.ld_tgt_count) {
286                 if (lov->lov_tgts[*pos])
287                         return lov->lov_tgts[*pos];
288         }
289         return NULL;
290 }
291
292 static int lov_tgt_seq_show(struct seq_file *p, void *v)
293 {
294         struct lov_tgt_desc *tgt = v;
295         return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index, 
296                           obd_uuid2str(&tgt->ltd_uuid), 
297                           tgt->ltd_active ? "" : "IN");
298 }
299
300 struct seq_operations lov_tgt_sops = {
301         .start = lov_tgt_seq_start,
302         .stop = lov_tgt_seq_stop,
303         .next = lov_tgt_seq_next,
304         .show = lov_tgt_seq_show,
305 };
306
307 static int lov_target_seq_open(struct inode *inode, struct file *file)
308 {
309         struct proc_dir_entry *dp = PDE(inode);
310         struct seq_file *seq;
311         int rc;
312
313         LPROCFS_ENTRY_AND_CHECK(dp);
314         rc = seq_open(file, &lov_tgt_sops);
315         if (rc) {
316                 LPROCFS_EXIT();
317                 return rc;
318         }
319
320         seq = file->private_data;
321         seq->private = dp->data;
322         return 0;
323 }
324
325 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
326         { "uuid",         lprocfs_rd_uuid,        0, 0 },
327         { "stripesize",   lov_rd_stripesize,      lov_wr_stripesize, 0 },
328         { "stripeoffset", lov_rd_stripeoffset,    lov_wr_stripeoffset, 0 },
329         { "stripecount",  lov_rd_stripecount,     lov_wr_stripecount, 0 },
330         { "stripetype",   lov_rd_stripetype,      lov_wr_stripetype, 0 },
331         { "numobd",       lov_rd_numobd,          0, 0 },
332         { "activeobd",    lov_rd_activeobd,       0, 0 },
333         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
334         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
335         /*{ "filegroups", lprocfs_rd_filegroups,  0, 0 },*/
336         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
337         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
338         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
339         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
340         { "desc_uuid",    lov_rd_desc_uuid,       0, 0 },
341         { "qos_prio_free",lov_rd_qos_priofree,    lov_wr_qos_priofree, 0 },
342         { "qos_maxage",   lov_rd_qos_maxage,      lov_wr_qos_maxage, 0 },
343         { 0 }
344 };
345
346 static struct lprocfs_vars lprocfs_lov_module_vars[] = {
347         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
348         { 0 }
349 };
350
351 void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars)
352 {
353     lvars->module_vars  = lprocfs_lov_module_vars;
354     lvars->obd_vars     = lprocfs_lov_obd_vars;
355 }
356
357 struct file_operations lov_proc_target_fops = {
358         .owner   = THIS_MODULE,
359         .open    = lov_target_seq_open,
360         .read    = seq_read,
361         .llseek  = seq_lseek,
362         .release = lprocfs_seq_release,
363 };
364 #endif /* LPROCFS */
365