Whamcloud - gitweb
LU-2244 lov: remove unused bits from lov, osc
[fs/lustre-release.git] / 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 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34 #define DEBUG_SUBSYSTEM S_CLASS
35
36 #include <linux/version.h>
37 #include <asm/statfs.h>
38 #include <lprocfs_status.h>
39 #include <obd_class.h>
40 #include <linux/seq_file.h>
41 #include "lov_internal.h"
42
43 #ifdef LPROCFS
44 static int lov_rd_stripesize(char *page, char **start, off_t off, int count,
45                              int *eof, void *data)
46 {
47         struct obd_device *dev = (struct obd_device *)data;
48         struct lov_desc *desc;
49
50         LASSERT(dev != NULL);
51         desc = &dev->u.lov.desc;
52         *eof = 1;
53         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
54 }
55
56 static int lov_wr_stripesize(struct file *file, const char *buffer,
57                                unsigned long count, void *data)
58 {
59         struct obd_device *dev = (struct obd_device *)data;
60         struct lov_desc *desc;
61         __u64 val;
62         int rc;
63         
64         LASSERT(dev != NULL);
65         desc = &dev->u.lov.desc;
66         rc = lprocfs_write_u64_helper(buffer, count, &val);
67         if (rc)
68                 return rc;
69
70         lov_fix_desc_stripe_size(&val);
71         desc->ld_default_stripe_size = val;
72         return count;
73 }
74
75 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
76                                int *eof, void *data)
77 {
78         struct obd_device *dev = (struct obd_device *)data;
79         struct lov_desc *desc;
80
81         LASSERT(dev != NULL);
82         desc = &dev->u.lov.desc;
83         *eof = 1;
84         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
85 }
86
87 static int lov_wr_stripeoffset(struct file *file, const char *buffer,
88                                unsigned long count, void *data)
89 {
90         struct obd_device *dev = (struct obd_device *)data;
91         struct lov_desc *desc;
92         __u64 val;
93         int rc;
94         
95         LASSERT(dev != NULL);
96         desc = &dev->u.lov.desc;
97         rc = lprocfs_write_u64_helper(buffer, count, &val);
98         if (rc)
99                 return rc;
100
101         desc->ld_default_stripe_offset = val;
102         return count;
103 }
104
105 static int lov_rd_stripetype(char *page, char **start, off_t off, int count,
106                              int *eof, void *data)
107 {
108         struct obd_device* dev = (struct obd_device*)data;
109         struct lov_desc *desc;
110
111         LASSERT(dev != NULL);
112         desc = &dev->u.lov.desc;
113         *eof = 1;
114         return snprintf(page, count, "%u\n", desc->ld_pattern);
115 }
116
117 static int lov_wr_stripetype(struct file *file, const char *buffer,
118                              unsigned long count, void *data)
119 {
120         struct obd_device *dev = (struct obd_device *)data;
121         struct lov_desc *desc;
122         int val, rc;
123         
124         LASSERT(dev != NULL);
125         desc = &dev->u.lov.desc;
126         rc = lprocfs_write_helper(buffer, count, &val);
127         if (rc)
128                 return rc;
129
130         lov_fix_desc_pattern(&val);
131         desc->ld_pattern = val;
132         return count;
133 }
134
135 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
136                               int *eof, void *data)
137 {
138         struct obd_device *dev = (struct obd_device *)data;
139         struct lov_desc *desc;
140
141         LASSERT(dev != NULL);
142         desc = &dev->u.lov.desc;
143         *eof = 1;
144         return snprintf(page, count, "%d\n",
145                         (__s16)(desc->ld_default_stripe_count + 1) - 1);
146 }
147
148 static int lov_wr_stripecount(struct file *file, const char *buffer,
149                               unsigned long count, void *data)
150 {
151         struct obd_device *dev = (struct obd_device *)data;
152         struct lov_desc *desc;
153         int val, rc;
154         
155         LASSERT(dev != NULL);
156         desc = &dev->u.lov.desc;
157         rc = lprocfs_write_helper(buffer, count, &val);
158         if (rc)
159                 return rc;
160
161         lov_fix_desc_stripe_count(&val);
162         desc->ld_default_stripe_count = val;
163         return count;
164 }
165
166 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
167                          int *eof, void *data)
168 {
169         struct obd_device *dev = (struct obd_device*)data;
170         struct lov_desc *desc;
171
172         LASSERT(dev != NULL);
173         desc = &dev->u.lov.desc;
174         *eof = 1;
175         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
176
177 }
178
179 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
180                             int *eof, void *data)
181 {
182         struct obd_device* dev = (struct obd_device*)data;
183         struct lov_desc *desc;
184
185         LASSERT(dev != NULL);
186         desc = &dev->u.lov.desc;
187         *eof = 1;
188         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
189 }
190
191 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
192                             int *eof, void *data)
193 {
194         struct obd_device *dev = (struct obd_device*) data;
195         struct lov_obd *lov;
196
197         LASSERT(dev != NULL);
198         lov = &dev->u.lov;
199         *eof = 1;
200         return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
201 }
202
203 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
204 {
205         struct obd_device *dev = p->private;
206         struct lov_obd *lov = &dev->u.lov;
207
208         while (*pos < lov->desc.ld_tgt_count) {
209                 if (lov->lov_tgts[*pos])
210                         return lov->lov_tgts[*pos];
211                 ++*pos;
212         }
213         return NULL;
214 }
215
216 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
217 {
218 }
219
220 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
221 {
222         struct obd_device *dev = p->private;
223         struct lov_obd *lov = &dev->u.lov;
224
225         while (++*pos < lov->desc.ld_tgt_count) {
226                 if (lov->lov_tgts[*pos])
227                         return lov->lov_tgts[*pos];
228         }
229         return NULL;
230 }
231
232 static int lov_tgt_seq_show(struct seq_file *p, void *v)
233 {
234         struct lov_tgt_desc *tgt = v;
235         return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index, 
236                           obd_uuid2str(&tgt->ltd_uuid), 
237                           tgt->ltd_active ? "" : "IN");
238 }
239
240 struct seq_operations lov_tgt_sops = {
241         .start = lov_tgt_seq_start,
242         .stop = lov_tgt_seq_stop,
243         .next = lov_tgt_seq_next,
244         .show = lov_tgt_seq_show,
245 };
246
247 static int lov_target_seq_open(struct inode *inode, struct file *file)
248 {
249         struct proc_dir_entry *dp = PDE(inode);
250         struct seq_file *seq;
251         int rc;
252
253         LPROCFS_ENTRY_AND_CHECK(dp);
254         rc = seq_open(file, &lov_tgt_sops);
255         if (rc) {
256                 LPROCFS_EXIT();
257                 return rc;
258         }
259
260         seq = file->private_data;
261         seq->private = dp->data;
262         return 0;
263 }
264
265 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
266         { "uuid",         lprocfs_rd_uuid,        0, 0 },
267         { "stripesize",   lov_rd_stripesize,      lov_wr_stripesize, 0 },
268         { "stripeoffset", lov_rd_stripeoffset,    lov_wr_stripeoffset, 0 },
269         { "stripecount",  lov_rd_stripecount,     lov_wr_stripecount, 0 },
270         { "stripetype",   lov_rd_stripetype,      lov_wr_stripetype, 0 },
271         { "numobd",       lov_rd_numobd,          0, 0 },
272         { "activeobd",    lov_rd_activeobd,       0, 0 },
273         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
274         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
275         /*{ "filegroups", lprocfs_rd_filegroups,  0, 0 },*/
276         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
277         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
278         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
279         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
280         { "desc_uuid",    lov_rd_desc_uuid,       0, 0 },
281         { 0 }
282 };
283
284 static struct lprocfs_vars lprocfs_lov_module_vars[] = {
285         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
286         { 0 }
287 };
288
289 void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars)
290 {
291     lvars->module_vars  = lprocfs_lov_module_vars;
292     lvars->obd_vars     = lprocfs_lov_obd_vars;
293 }
294
295 struct file_operations lov_proc_target_fops = {
296         .owner   = THIS_MODULE,
297         .open    = lov_target_seq_open,
298         .read    = seq_read,
299         .llseek  = seq_lseek,
300         .release = lprocfs_seq_release,
301 };
302 #endif /* LPROCFS */