Whamcloud - gitweb
LU-5275 lprocfs: remove last of non seq data structs and functions.
[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  * 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 <linux/version.h>
39 #include <asm/statfs.h>
40 #include <lprocfs_status.h>
41 #include <obd_class.h>
42 #include <lustre_param.h>
43 #include "lov_internal.h"
44
45 #ifdef LPROCFS
46 static int lov_stripesize_seq_show(struct seq_file *m, void *v)
47 {
48         struct obd_device *dev = (struct obd_device *)m->private;
49         struct lov_desc *desc;
50
51         LASSERT(dev != NULL);
52         desc = &dev->u.lov.desc;
53
54         return seq_printf(m, LPU64"\n", desc->ld_default_stripe_size);
55 }
56
57 static ssize_t lov_stripesize_seq_write(struct file *file,
58                                         const char __user *buffer,
59                                         size_t count, loff_t *off)
60 {
61         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
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 LPROC_SEQ_FOPS(lov_stripesize);
77
78 static int lov_stripeoffset_seq_show(struct seq_file *m, void *v)
79 {
80         struct obd_device *dev = (struct obd_device *)m->private;
81         struct lov_desc *desc;
82
83         LASSERT(dev != NULL);
84         desc = &dev->u.lov.desc;
85         return seq_printf(m, LPU64"\n", desc->ld_default_stripe_offset);
86 }
87
88 static ssize_t lov_stripeoffset_seq_write(struct file *file,
89                                           const char __user *buffer,
90                                           size_t count, loff_t *off)
91 {
92         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
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 LPROC_SEQ_FOPS(lov_stripeoffset);
107
108 static int lov_stripetype_seq_show(struct seq_file *m, void *v)
109 {
110         struct obd_device* dev = (struct obd_device*)m->private;
111         struct lov_desc *desc;
112
113         LASSERT(dev != NULL);
114         desc = &dev->u.lov.desc;
115         return seq_printf(m, "%u\n", desc->ld_pattern);
116 }
117
118 static ssize_t lov_stripetype_seq_write(struct file *file,
119                                         const char __user *buffer,
120                                         size_t count, loff_t *off)
121 {
122         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
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 LPROC_SEQ_FOPS(lov_stripetype);
137
138 static int lov_stripecount_seq_show(struct seq_file *m, void *v)
139 {
140         struct obd_device *dev = (struct obd_device *)m->private;
141         struct lov_desc *desc;
142
143         LASSERT(dev != NULL);
144         desc = &dev->u.lov.desc;
145         return seq_printf(m, "%d\n",
146                           (__s16)(desc->ld_default_stripe_count + 1) - 1);
147 }
148
149 static ssize_t lov_stripecount_seq_write(struct file *file,
150                                          const char __user *buffer,
151                                          size_t count, loff_t *off)
152 {
153         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
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 LPROC_SEQ_FOPS(lov_stripecount);
168
169 static int lov_numobd_seq_show(struct seq_file *m, void *v)
170 {
171         struct obd_device *dev = (struct obd_device*)m->private;
172         struct lov_desc *desc;
173
174         LASSERT(dev != NULL);
175         desc = &dev->u.lov.desc;
176         return seq_printf(m, "%u\n", desc->ld_tgt_count);
177 }
178 LPROC_SEQ_FOPS_RO(lov_numobd);
179
180 static int lov_activeobd_seq_show(struct seq_file *m, void *v)
181 {
182         struct obd_device* dev = (struct obd_device*)m->private;
183         struct lov_desc *desc;
184
185         LASSERT(dev != NULL);
186         desc = &dev->u.lov.desc;
187         return seq_printf(m, "%u\n", desc->ld_active_tgt_count);
188 }
189 LPROC_SEQ_FOPS_RO(lov_activeobd);
190
191 static int lov_desc_uuid_seq_show(struct seq_file *m, void *v)
192 {
193         struct obd_device *dev = m->private;
194         struct lov_obd *lov;
195
196         LASSERT(dev != NULL);
197         lov = &dev->u.lov;
198         return seq_printf(m, "%s\n", lov->desc.ld_uuid.uuid);
199 }
200 LPROC_SEQ_FOPS_RO(lov_desc_uuid);
201
202 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
203 {
204         struct obd_device *dev = p->private;
205         struct lov_obd *lov = &dev->u.lov;
206
207         while (*pos < lov->desc.ld_tgt_count) {
208                 if (lov->lov_tgts[*pos])
209                         return lov->lov_tgts[*pos];
210                 ++*pos;
211         }
212         return NULL;
213 }
214
215 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
216 {
217 }
218
219 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
220 {
221         struct obd_device *dev = p->private;
222         struct lov_obd *lov = &dev->u.lov;
223
224         while (++*pos < lov->desc.ld_tgt_count) {
225                 if (lov->lov_tgts[*pos])
226                         return lov->lov_tgts[*pos];
227         }
228         return NULL;
229 }
230
231 static int lov_tgt_seq_show(struct seq_file *p, void *v)
232 {
233         struct lov_tgt_desc *tgt = v;
234         return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
235                           obd_uuid2str(&tgt->ltd_uuid),
236                           tgt->ltd_active ? "" : "IN");
237 }
238
239 struct seq_operations lov_tgt_sops = {
240         .start = lov_tgt_seq_start,
241         .stop = lov_tgt_seq_stop,
242         .next = lov_tgt_seq_next,
243         .show = lov_tgt_seq_show,
244 };
245
246 static int lov_target_seq_open(struct inode *inode, struct file *file)
247 {
248         struct seq_file *seq;
249         int rc;
250
251         LPROCFS_ENTRY_CHECK(PDE(inode));
252         rc = seq_open(file, &lov_tgt_sops);
253         if (rc)
254                 return rc;
255
256         seq = file->private_data;
257         seq->private = PDE_DATA(inode);
258         return 0;
259 }
260
261 LPROC_SEQ_FOPS_RO_TYPE(lov, uuid);
262 LPROC_SEQ_FOPS_RO_TYPE(lov, filestotal);
263 LPROC_SEQ_FOPS_RO_TYPE(lov, filesfree);
264 LPROC_SEQ_FOPS_RO_TYPE(lov, blksize);
265 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytestotal);
266 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytesfree);
267 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytesavail);
268
269 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
270         { .name =       "uuid",
271           .fops =       &lov_uuid_fops          },
272         { .name =       "stripesize",
273           .fops =       &lov_stripesize_fops    },
274         { .name =       "stripeoffset",
275           .fops =       &lov_stripeoffset_fops  },
276         { .name =       "stripecount",
277           .fops =       &lov_stripecount_fops   },
278         { .name =       "stripetype",
279           .fops =       &lov_stripetype_fops    },
280         { .name =       "numobd",
281           .fops =       &lov_numobd_fops        },
282         { .name =       "activeobd",
283           .fops =       &lov_activeobd_fops     },
284         { .name =       "filestotal",
285           .fops =       &lov_filestotal_fops    },
286         { .name =       "filesfree",
287           .fops =       &lov_filesfree_fops     },
288         { .name =       "blocksize",
289           .fops =       &lov_blksize_fops       },
290         { .name =       "kbytestotal",
291           .fops =       &lov_kbytestotal_fops   },
292         { .name =       "kbytesfree",
293           .fops =       &lov_kbytesfree_fops    },
294         { .name =       "kbytesavail",
295           .fops =       &lov_kbytesavail_fops   },
296         { .name =       "desc_uuid",
297           .fops =       &lov_desc_uuid_fops     },
298         { 0 }
299 };
300
301 struct file_operations lov_proc_target_fops = {
302         .owner   = THIS_MODULE,
303         .open    = lov_target_seq_open,
304         .read    = seq_read,
305         .llseek  = seq_lseek,
306         .release = lprocfs_seq_release,
307 };
308 #endif /* LPROCFS */