Whamcloud - gitweb
44a35cd35171a8c0161e19a41ed3f53189365bd9
[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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #define DEBUG_SUBSYSTEM S_CLASS
37
38 #include <linux/version.h>
39 #include <asm/statfs.h>
40 #include <lprocfs_status.h>
41 #include <obd_class.h>
42 #include <linux/seq_file.h>
43 #include "lov_internal.h"
44
45 #ifdef LPROCFS
46 static int lov_rd_stripesize(char *page, char **start, off_t off, int count,
47                              int *eof, void *data)
48 {
49         struct obd_device *dev = (struct obd_device *)data;
50         struct lov_desc *desc;
51
52         LASSERT(dev != NULL);
53         desc = &dev->u.lov.desc;
54         *eof = 1;
55         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
56 }
57
58 static int lov_wr_stripesize(struct file *file, const char *buffer,
59                                unsigned long count, void *data)
60 {
61         struct obd_device *dev = (struct obd_device *)data;
62         struct lov_desc *desc;
63         __u64 val;
64         int rc;
65
66         LASSERT(dev != NULL);
67         desc = &dev->u.lov.desc;
68         rc = lprocfs_write_u64_helper(buffer, count, &val);
69         if (rc)
70                 return rc;
71
72         lov_fix_desc_stripe_size(&val);
73         desc->ld_default_stripe_size = val;
74         return count;
75 }
76
77 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
78                                int *eof, void *data)
79 {
80         struct obd_device *dev = (struct obd_device *)data;
81         struct lov_desc *desc;
82
83         LASSERT(dev != NULL);
84         desc = &dev->u.lov.desc;
85         *eof = 1;
86         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
87 }
88
89 static int lov_wr_stripeoffset(struct file *file, const char *buffer,
90                                unsigned long count, void *data)
91 {
92         struct obd_device *dev = (struct obd_device *)data;
93         struct lov_desc *desc;
94         __u64 val;
95         int rc;
96
97         LASSERT(dev != NULL);
98         desc = &dev->u.lov.desc;
99         rc = lprocfs_write_u64_helper(buffer, count, &val);
100         if (rc)
101                 return rc;
102
103         desc->ld_default_stripe_offset = val;
104         return count;
105 }
106
107 static int lov_rd_stripetype(char *page, char **start, off_t off, int count,
108                              int *eof, void *data)
109 {
110         struct obd_device* dev = (struct obd_device*)data;
111         struct lov_desc *desc;
112
113         LASSERT(dev != NULL);
114         desc = &dev->u.lov.desc;
115         *eof = 1;
116         return snprintf(page, count, "%u\n", desc->ld_pattern);
117 }
118
119 static int lov_wr_stripetype(struct file *file, const char *buffer,
120                              unsigned long count, void *data)
121 {
122         struct obd_device *dev = (struct obd_device *)data;
123         struct lov_desc *desc;
124         int val, rc;
125
126         LASSERT(dev != NULL);
127         desc = &dev->u.lov.desc;
128         rc = lprocfs_write_helper(buffer, count, &val);
129         if (rc)
130                 return rc;
131
132         lov_fix_desc_pattern(&val);
133         desc->ld_pattern = val;
134         return count;
135 }
136
137 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
138                               int *eof, void *data)
139 {
140         struct obd_device *dev = (struct obd_device *)data;
141         struct lov_desc *desc;
142
143         LASSERT(dev != NULL);
144         desc = &dev->u.lov.desc;
145         *eof = 1;
146         return snprintf(page, count, "%d\n",
147                         (__s16)(desc->ld_default_stripe_count + 1) - 1);
148 }
149
150 static int lov_wr_stripecount(struct file *file, const char *buffer,
151                               unsigned long count, void *data)
152 {
153         struct obd_device *dev = (struct obd_device *)data;
154         struct lov_desc *desc;
155         int val, rc;
156
157         LASSERT(dev != NULL);
158         desc = &dev->u.lov.desc;
159         rc = lprocfs_write_helper(buffer, count, &val);
160         if (rc)
161                 return rc;
162
163         lov_fix_desc_stripe_count(&val);
164         desc->ld_default_stripe_count = val;
165         return count;
166 }
167
168 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
169                          int *eof, void *data)
170 {
171         struct obd_device *dev = (struct obd_device*)data;
172         struct lov_desc *desc;
173
174         LASSERT(dev != NULL);
175         desc = &dev->u.lov.desc;
176         *eof = 1;
177         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
178
179 }
180
181 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
182                             int *eof, void *data)
183 {
184         struct obd_device* dev = (struct obd_device*)data;
185         struct lov_desc *desc;
186
187         LASSERT(dev != NULL);
188         desc = &dev->u.lov.desc;
189         *eof = 1;
190         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
191 }
192
193 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
194                             int *eof, void *data)
195 {
196         struct obd_device *dev = (struct obd_device*) data;
197         struct lov_obd *lov;
198
199         LASSERT(dev != NULL);
200         lov = &dev->u.lov;
201         *eof = 1;
202         return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
203 }
204
205 /* free priority (0-256): how badly user wants to choose empty osts */
206 static int lov_rd_qos_priofree(char *page, char **start, off_t off, int count,
207                                int *eof, void *data)
208 {
209         struct obd_device *dev = (struct obd_device*) data;
210         struct lov_obd *lov;
211
212         LASSERT(dev != NULL);
213         lov = &dev->u.lov;
214         *eof = 1;
215         /* Round the conversion; see below */
216         return snprintf(page, count, "%d%%\n",
217                         (lov->lov_qos.lq_prio_free * 100 + 128) >> 8);
218 }
219
220 static int lov_wr_qos_priofree(struct file *file, const char *buffer,
221                                unsigned long count, void *data)
222 {
223         struct obd_device *dev = (struct obd_device *)data;
224         struct lov_obd *lov;
225         int val, rc;
226         LASSERT(dev != NULL);
227
228         lov = &dev->u.lov;
229         rc = lprocfs_write_helper(buffer, count, &val);
230         if (rc)
231                 return rc;
232
233         if (val > 100 || val < 0)
234                 return -EINVAL;
235         /* We're converting a 0-100% range to 0-256.
236          * Add some rounding so that when we convert back to %
237          * for printout below, we end up with the original value */
238         lov->lov_qos.lq_prio_free = ((val << 8) + 50) / 100;
239         lov->lov_qos.lq_dirty = 1;
240         lov->lov_qos.lq_reset = 1;
241         return count;
242 }
243
244 static int lov_rd_qos_thresholdrr(char *page, char **start, off_t off,
245                                   int count, int *eof, void *data)
246 {
247         struct obd_device *dev = (struct obd_device*) data;
248         struct lov_obd *lov;
249
250         LASSERT(dev != NULL);
251         lov = &dev->u.lov;
252         *eof = 1;
253         return snprintf(page, count, "%d%%\n",
254                         ((lov->lov_qos.lq_threshold_rr * 100) + 128) >> 8);
255 }
256
257 static int lov_wr_qos_thresholdrr(struct file *file, const char *buffer,
258                                   unsigned long count, void *data)
259 {
260         struct obd_device *dev = (struct obd_device *)data;
261         struct lov_obd *lov;
262         int val, rc;
263         LASSERT(dev != NULL);
264
265         lov = &dev->u.lov;
266         rc = lprocfs_write_helper(buffer, count, &val);
267         if (rc)
268                 return rc;
269
270         if (val > 100 || val < 0)
271                 return -EINVAL;
272
273         lov->lov_qos.lq_threshold_rr = ((val << 8) + 50) / 100;
274         lov->lov_qos.lq_dirty = 1;
275         return count;
276 }
277
278 static int lov_rd_qos_maxage(char *page, char **start, off_t off, int count,
279                              int *eof, void *data)
280 {
281         struct obd_device *dev = (struct obd_device*) data;
282         struct lov_obd *lov;
283
284         LASSERT(dev != NULL);
285         lov = &dev->u.lov;
286         *eof = 1;
287         return snprintf(page, count, "%u Sec\n", lov->desc.ld_qos_maxage);
288 }
289
290 static int lov_wr_qos_maxage(struct file *file, const char *buffer,
291                              unsigned long count, void *data)
292 {
293         struct obd_device *dev = (struct obd_device *)data;
294         struct lov_obd *lov;
295         int val, rc;
296         LASSERT(dev != NULL);
297
298         lov = &dev->u.lov;
299         rc = lprocfs_write_helper(buffer, count, &val);
300         if (rc)
301                 return rc;
302
303         if (val <= 0)
304                 return -EINVAL;
305         lov->desc.ld_qos_maxage = val;
306         return count;
307 }
308
309 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
310 {
311         struct obd_device *dev = p->private;
312         struct lov_obd *lov = &dev->u.lov;
313
314         while (*pos < lov->desc.ld_tgt_count) {
315                 if (lov->lov_tgts[*pos])
316                         return lov->lov_tgts[*pos];
317                 ++*pos;
318         }
319         return NULL;
320 }
321
322 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
323 {
324 }
325
326 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
327 {
328         struct obd_device *dev = p->private;
329         struct lov_obd *lov = &dev->u.lov;
330
331         while (++*pos < lov->desc.ld_tgt_count) {
332                 if (lov->lov_tgts[*pos])
333                         return lov->lov_tgts[*pos];
334         }
335         return NULL;
336 }
337
338 static int lov_tgt_seq_show(struct seq_file *p, void *v)
339 {
340         struct lov_tgt_desc *tgt = v;
341         return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
342                           obd_uuid2str(&tgt->ltd_uuid),
343                           tgt->ltd_active ? "" : "IN");
344 }
345
346 struct seq_operations lov_tgt_sops = {
347         .start = lov_tgt_seq_start,
348         .stop = lov_tgt_seq_stop,
349         .next = lov_tgt_seq_next,
350         .show = lov_tgt_seq_show,
351 };
352
353 static int lov_target_seq_open(struct inode *inode, struct file *file)
354 {
355         struct proc_dir_entry *dp = PDE(inode);
356         struct seq_file *seq;
357         int rc;
358
359         LPROCFS_ENTRY_AND_CHECK(dp);
360         rc = seq_open(file, &lov_tgt_sops);
361         if (rc) {
362                 LPROCFS_EXIT();
363                 return rc;
364         }
365
366         seq = file->private_data;
367         seq->private = dp->data;
368         return 0;
369 }
370
371 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
372         { "uuid",         lprocfs_rd_uuid,        0, 0 },
373         { "stripesize",   lov_rd_stripesize,      lov_wr_stripesize, 0 },
374         { "stripeoffset", lov_rd_stripeoffset,    lov_wr_stripeoffset, 0 },
375         { "stripecount",  lov_rd_stripecount,     lov_wr_stripecount, 0 },
376         { "stripetype",   lov_rd_stripetype,      lov_wr_stripetype, 0 },
377         { "numobd",       lov_rd_numobd,          0, 0 },
378         { "activeobd",    lov_rd_activeobd,       0, 0 },
379         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
380         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
381         /*{ "filegroups", lprocfs_rd_filegroups,  0, 0 },*/
382         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
383         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
384         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
385         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
386         { "desc_uuid",    lov_rd_desc_uuid,       0, 0 },
387         { "qos_prio_free",lov_rd_qos_priofree,    lov_wr_qos_priofree, 0 },
388         { "qos_threshold_rr",  lov_rd_qos_thresholdrr, lov_wr_qos_thresholdrr, 0 },
389         { "qos_maxage",   lov_rd_qos_maxage,      lov_wr_qos_maxage, 0 },
390         { 0 }
391 };
392
393 static struct lprocfs_vars lprocfs_lov_module_vars[] = {
394         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
395         { 0 }
396 };
397
398 void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars)
399 {
400     lvars->module_vars  = lprocfs_lov_module_vars;
401     lvars->obd_vars     = lprocfs_lov_obd_vars;
402 }
403
404 struct file_operations lov_proc_target_fops = {
405         .owner   = THIS_MODULE,
406         .open    = lov_target_seq_open,
407         .read    = seq_read,
408         .llseek  = seq_lseek,
409         .release = lprocfs_seq_release,
410 };
411 #endif /* LPROCFS */