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