]> Pileus Git - ~andy/linux/blob - drivers/staging/lustre/lustre/lov/lproc_lov.c
Merge branches 'fixes' and 'misc' into for-linus
[~andy/linux] / drivers / staging / lustre / lustre / lov / lproc_lov.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
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 <asm/statfs.h>
39 #include <lprocfs_status.h>
40 #include <obd_class.h>
41 #include <linux/seq_file.h>
42 #include "lov_internal.h"
43
44 static int lov_stripesize_seq_show(struct seq_file *m, void *v)
45 {
46         struct obd_device *dev = (struct obd_device *)m->private;
47         struct lov_desc *desc;
48
49         LASSERT(dev != NULL);
50         desc = &dev->u.lov.desc;
51         return seq_printf(m, LPU64"\n", desc->ld_default_stripe_size);
52 }
53
54 static ssize_t lov_stripesize_seq_write(struct file *file, const char *buffer,
55                                     size_t count, loff_t *off)
56 {
57         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
58         struct lov_desc *desc;
59         __u64 val;
60         int rc;
61
62         LASSERT(dev != NULL);
63         desc = &dev->u.lov.desc;
64         rc = lprocfs_write_u64_helper(buffer, count, &val);
65         if (rc)
66                 return rc;
67
68         lov_fix_desc_stripe_size(&val);
69         desc->ld_default_stripe_size = val;
70         return count;
71 }
72 LPROC_SEQ_FOPS(lov_stripesize);
73
74 static int lov_stripeoffset_seq_show(struct seq_file *m, void *v)
75 {
76         struct obd_device *dev = (struct obd_device *)m->private;
77         struct lov_desc *desc;
78
79         LASSERT(dev != NULL);
80         desc = &dev->u.lov.desc;
81         return seq_printf(m, LPU64"\n", desc->ld_default_stripe_offset);
82 }
83
84 static ssize_t lov_stripeoffset_seq_write(struct file *file, const char *buffer,
85                                       size_t count, loff_t *off)
86 {
87         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
88         struct lov_desc *desc;
89         __u64 val;
90         int rc;
91
92         LASSERT(dev != NULL);
93         desc = &dev->u.lov.desc;
94         rc = lprocfs_write_u64_helper(buffer, count, &val);
95         if (rc)
96                 return rc;
97
98         desc->ld_default_stripe_offset = val;
99         return count;
100 }
101 LPROC_SEQ_FOPS(lov_stripeoffset);
102
103 static int lov_stripetype_seq_show(struct seq_file *m, void *v)
104 {
105         struct obd_device *dev = (struct obd_device *)m->private;
106         struct lov_desc *desc;
107
108         LASSERT(dev != NULL);
109         desc = &dev->u.lov.desc;
110         return seq_printf(m, "%u\n", desc->ld_pattern);
111 }
112
113 static ssize_t lov_stripetype_seq_write(struct file *file, const char *buffer,
114                                     size_t count, loff_t *off)
115 {
116         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
117         struct lov_desc *desc;
118         int val, rc;
119
120         LASSERT(dev != NULL);
121         desc = &dev->u.lov.desc;
122         rc = lprocfs_write_helper(buffer, count, &val);
123         if (rc)
124                 return rc;
125
126         lov_fix_desc_pattern(&val);
127         desc->ld_pattern = val;
128         return count;
129 }
130 LPROC_SEQ_FOPS(lov_stripetype);
131
132 static int lov_stripecount_seq_show(struct seq_file *m, void *v)
133 {
134         struct obd_device *dev = (struct obd_device *)m->private;
135         struct lov_desc *desc;
136
137         LASSERT(dev != NULL);
138         desc = &dev->u.lov.desc;
139         return seq_printf(m, "%d\n",
140                         (__s16)(desc->ld_default_stripe_count + 1) - 1);
141 }
142
143 static ssize_t lov_stripecount_seq_write(struct file *file, const char *buffer,
144                                      size_t count, loff_t *off)
145 {
146         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
147         struct lov_desc *desc;
148         int val, rc;
149
150         LASSERT(dev != NULL);
151         desc = &dev->u.lov.desc;
152         rc = lprocfs_write_helper(buffer, count, &val);
153         if (rc)
154                 return rc;
155
156         lov_fix_desc_stripe_count(&val);
157         desc->ld_default_stripe_count = val;
158         return count;
159 }
160 LPROC_SEQ_FOPS(lov_stripecount);
161
162 static int lov_numobd_seq_show(struct seq_file *m, void *v)
163 {
164         struct obd_device *dev = (struct obd_device *)m->private;
165         struct lov_desc *desc;
166
167         LASSERT(dev != NULL);
168         desc = &dev->u.lov.desc;
169         return seq_printf(m, "%u\n", desc->ld_tgt_count);
170 }
171 LPROC_SEQ_FOPS_RO(lov_numobd);
172
173 static int lov_activeobd_seq_show(struct seq_file *m, void *v)
174 {
175         struct obd_device *dev = (struct obd_device *)m->private;
176         struct lov_desc *desc;
177
178         LASSERT(dev != NULL);
179         desc = &dev->u.lov.desc;
180         return seq_printf(m, "%u\n", desc->ld_active_tgt_count);
181 }
182 LPROC_SEQ_FOPS_RO(lov_activeobd);
183
184 static int lov_desc_uuid_seq_show(struct seq_file *m, void *v)
185 {
186         struct obd_device *dev = (struct obd_device *)m->private;
187         struct lov_obd *lov;
188
189         LASSERT(dev != NULL);
190         lov = &dev->u.lov;
191         return seq_printf(m, "%s\n", lov->desc.ld_uuid.uuid);
192 }
193 LPROC_SEQ_FOPS_RO(lov_desc_uuid);
194
195 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
196 {
197         struct obd_device *dev = p->private;
198         struct lov_obd *lov = &dev->u.lov;
199
200         while (*pos < lov->desc.ld_tgt_count) {
201                 if (lov->lov_tgts[*pos])
202                         return lov->lov_tgts[*pos];
203                 ++*pos;
204         }
205         return NULL;
206 }
207
208 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
209 {
210 }
211
212 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
213 {
214         struct obd_device *dev = p->private;
215         struct lov_obd *lov = &dev->u.lov;
216
217         while (++*pos < lov->desc.ld_tgt_count) {
218                 if (lov->lov_tgts[*pos])
219                         return lov->lov_tgts[*pos];
220         }
221         return NULL;
222 }
223
224 static int lov_tgt_seq_show(struct seq_file *p, void *v)
225 {
226         struct lov_tgt_desc *tgt = v;
227         return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
228                           obd_uuid2str(&tgt->ltd_uuid),
229                           tgt->ltd_active ? "" : "IN");
230 }
231
232 struct seq_operations lov_tgt_sops = {
233         .start = lov_tgt_seq_start,
234         .stop = lov_tgt_seq_stop,
235         .next = lov_tgt_seq_next,
236         .show = lov_tgt_seq_show,
237 };
238
239 static int lov_target_seq_open(struct inode *inode, struct file *file)
240 {
241         struct seq_file *seq;
242         int rc;
243
244         rc = seq_open(file, &lov_tgt_sops);
245         if (rc)
246                 return rc;
247
248         seq = file->private_data;
249         seq->private = PDE_DATA(inode);
250         return 0;
251 }
252
253 LPROC_SEQ_FOPS_RO_TYPE(lov, uuid);
254 LPROC_SEQ_FOPS_RO_TYPE(lov, filestotal);
255 LPROC_SEQ_FOPS_RO_TYPE(lov, filesfree);
256 LPROC_SEQ_FOPS_RO_TYPE(lov, blksize);
257 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytestotal);
258 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytesfree);
259 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytesavail);
260
261 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
262         { "uuid",         &lov_uuid_fops,         NULL, 0 },
263         { "stripesize",   &lov_stripesize_fops,   NULL },
264         { "stripeoffset", &lov_stripeoffset_fops, NULL },
265         { "stripecount",  &lov_stripecount_fops,  NULL },
266         { "stripetype",   &lov_stripetype_fops,   NULL },
267         { "numobd",       &lov_numobd_fops,       NULL, 0 },
268         { "activeobd",    &lov_activeobd_fops,    NULL, 0 },
269         { "filestotal",   &lov_filestotal_fops,   NULL, 0 },
270         { "filesfree",    &lov_filesfree_fops,    NULL, 0 },
271         /*{ "filegroups", lprocfs_rd_filegroups,  NULL, 0 },*/
272         { "blocksize",    &lov_blksize_fops,      NULL, 0 },
273         { "kbytestotal",  &lov_kbytestotal_fops,  NULL, 0 },
274         { "kbytesfree",   &lov_kbytesfree_fops,   NULL, 0 },
275         { "kbytesavail",  &lov_kbytesavail_fops,  NULL, 0 },
276         { "desc_uuid",    &lov_desc_uuid_fops,    NULL, 0 },
277         { NULL }
278 };
279
280 LPROC_SEQ_FOPS_RO_TYPE(lov, numrefs);
281
282 static struct lprocfs_vars lprocfs_lov_module_vars[] = {
283         { "num_refs",     &lov_numrefs_fops,     NULL, 0 },
284         { NULL }
285 };
286
287 void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars)
288 {
289     lvars->module_vars  = lprocfs_lov_module_vars;
290     lvars->obd_vars     = lprocfs_lov_obd_vars;
291 }
292
293 const struct file_operations lov_proc_target_fops = {
294         .owner   = THIS_MODULE,
295         .open    = lov_target_seq_open,
296         .read    = seq_read,
297         .llseek  = seq_lseek,
298         .release = lprocfs_seq_release,
299 };