Whamcloud - gitweb
LU-6215 lprocfs: handle seq_printf api change
[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, 2015, 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 CONFIG_PROC_FS
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         seq_printf(m, LPU64"\n", desc->ld_default_stripe_size);
55         return 0;
56 }
57
58 static ssize_t lov_stripesize_seq_write(struct file *file,
59                                         const char __user *buffer,
60                                         size_t count, loff_t *off)
61 {
62         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
63         struct lov_desc *desc;
64         __u64 val;
65         int rc;
66
67         LASSERT(dev != NULL);
68         desc = &dev->u.lov.desc;
69         rc = lprocfs_write_u64_helper(buffer, count, &val);
70         if (rc)
71                 return rc;
72
73         lov_fix_desc_stripe_size(&val);
74         desc->ld_default_stripe_size = val;
75         return count;
76 }
77 LPROC_SEQ_FOPS(lov_stripesize);
78
79 static int lov_stripeoffset_seq_show(struct seq_file *m, void *v)
80 {
81         struct obd_device *dev = (struct obd_device *)m->private;
82         struct lov_desc *desc;
83
84         LASSERT(dev != NULL);
85         desc = &dev->u.lov.desc;
86         seq_printf(m, LPU64"\n", desc->ld_default_stripe_offset);
87         return 0;
88 }
89
90 static ssize_t lov_stripeoffset_seq_write(struct file *file,
91                                           const char __user *buffer,
92                                           size_t count, loff_t *off)
93 {
94         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
95         struct lov_desc *desc;
96         __u64 val;
97         int rc;
98
99         LASSERT(dev != NULL);
100         desc = &dev->u.lov.desc;
101         rc = lprocfs_write_u64_helper(buffer, count, &val);
102         if (rc)
103                 return rc;
104
105         desc->ld_default_stripe_offset = val;
106         return count;
107 }
108 LPROC_SEQ_FOPS(lov_stripeoffset);
109
110 static int lov_stripetype_seq_show(struct seq_file *m, void *v)
111 {
112         struct obd_device* dev = (struct obd_device*)m->private;
113         struct lov_desc *desc;
114
115         LASSERT(dev != NULL);
116         desc = &dev->u.lov.desc;
117         seq_printf(m, "%u\n", desc->ld_pattern);
118         return 0;
119 }
120
121 static ssize_t lov_stripetype_seq_write(struct file *file,
122                                         const char __user *buffer,
123                                         size_t count, loff_t *off)
124 {
125         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
126         struct lov_desc *desc;
127         int val, rc;
128
129         LASSERT(dev != NULL);
130         desc = &dev->u.lov.desc;
131         rc = lprocfs_write_helper(buffer, count, &val);
132         if (rc)
133                 return rc;
134
135         lov_fix_desc_pattern(&val);
136         desc->ld_pattern = val;
137         return count;
138 }
139 LPROC_SEQ_FOPS(lov_stripetype);
140
141 static int lov_stripecount_seq_show(struct seq_file *m, void *v)
142 {
143         struct obd_device *dev = (struct obd_device *)m->private;
144         struct lov_desc *desc;
145
146         LASSERT(dev != NULL);
147         desc = &dev->u.lov.desc;
148         seq_printf(m, "%d\n",
149                   (__s16)(desc->ld_default_stripe_count + 1) - 1);
150         return 0;
151 }
152
153 static ssize_t lov_stripecount_seq_write(struct file *file,
154                                          const char __user *buffer,
155                                          size_t count, loff_t *off)
156 {
157         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
158         struct lov_desc *desc;
159         int val, rc;
160
161         LASSERT(dev != NULL);
162         desc = &dev->u.lov.desc;
163         rc = lprocfs_write_helper(buffer, count, &val);
164         if (rc)
165                 return rc;
166
167         lov_fix_desc_stripe_count(&val);
168         desc->ld_default_stripe_count = val;
169         return count;
170 }
171 LPROC_SEQ_FOPS(lov_stripecount);
172
173 static int lov_numobd_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         seq_printf(m, "%u\n", desc->ld_tgt_count);
181         return 0;
182 }
183 LPROC_SEQ_FOPS_RO(lov_numobd);
184
185 static int lov_activeobd_seq_show(struct seq_file *m, void *v)
186 {
187         struct obd_device* dev = (struct obd_device*)m->private;
188         struct lov_desc *desc;
189
190         LASSERT(dev != NULL);
191         desc = &dev->u.lov.desc;
192         seq_printf(m, "%u\n", desc->ld_active_tgt_count);
193         return 0;
194 }
195 LPROC_SEQ_FOPS_RO(lov_activeobd);
196
197 static int lov_desc_uuid_seq_show(struct seq_file *m, void *v)
198 {
199         struct obd_device *dev = m->private;
200         struct lov_obd *lov;
201
202         LASSERT(dev != NULL);
203         lov = &dev->u.lov;
204         seq_printf(m, "%s\n", lov->desc.ld_uuid.uuid);
205         return 0;
206 }
207 LPROC_SEQ_FOPS_RO(lov_desc_uuid);
208
209 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
210 {
211         struct obd_device *dev = p->private;
212         struct lov_obd *lov = &dev->u.lov;
213
214         while (*pos < lov->desc.ld_tgt_count) {
215                 if (lov->lov_tgts[*pos])
216                         return lov->lov_tgts[*pos];
217                 ++*pos;
218         }
219         return NULL;
220 }
221
222 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
223 {
224 }
225
226 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
227 {
228         struct obd_device *dev = p->private;
229         struct lov_obd *lov = &dev->u.lov;
230
231         while (++*pos < lov->desc.ld_tgt_count) {
232                 if (lov->lov_tgts[*pos])
233                         return lov->lov_tgts[*pos];
234         }
235         return NULL;
236 }
237
238 static int lov_tgt_seq_show(struct seq_file *p, void *v)
239 {
240         struct lov_tgt_desc *tgt = v;
241         seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
242                    obd_uuid2str(&tgt->ltd_uuid),
243                    tgt->ltd_active ? "" : "IN");
244         return 0;
245 }
246
247 static const struct seq_operations lov_tgt_sops = {
248         .start = lov_tgt_seq_start,
249         .stop = lov_tgt_seq_stop,
250         .next = lov_tgt_seq_next,
251         .show = lov_tgt_seq_show,
252 };
253
254 static int lov_target_seq_open(struct inode *inode, struct file *file)
255 {
256         struct seq_file *seq;
257         int rc;
258
259         rc = LPROCFS_ENTRY_CHECK(inode);
260         if (rc < 0)
261                 return rc;
262
263         rc = seq_open(file, &lov_tgt_sops);
264         if (rc)
265                 return rc;
266
267         seq = file->private_data;
268         seq->private = PDE_DATA(inode);
269         return 0;
270 }
271
272 LPROC_SEQ_FOPS_RO_TYPE(lov, uuid);
273 LPROC_SEQ_FOPS_RO_TYPE(lov, filestotal);
274 LPROC_SEQ_FOPS_RO_TYPE(lov, filesfree);
275 LPROC_SEQ_FOPS_RO_TYPE(lov, blksize);
276 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytestotal);
277 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytesfree);
278 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytesavail);
279
280 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
281         { .name =       "uuid",
282           .fops =       &lov_uuid_fops          },
283         { .name =       "stripesize",
284           .fops =       &lov_stripesize_fops    },
285         { .name =       "stripeoffset",
286           .fops =       &lov_stripeoffset_fops  },
287         { .name =       "stripecount",
288           .fops =       &lov_stripecount_fops   },
289         { .name =       "stripetype",
290           .fops =       &lov_stripetype_fops    },
291         { .name =       "numobd",
292           .fops =       &lov_numobd_fops        },
293         { .name =       "activeobd",
294           .fops =       &lov_activeobd_fops     },
295         { .name =       "filestotal",
296           .fops =       &lov_filestotal_fops    },
297         { .name =       "filesfree",
298           .fops =       &lov_filesfree_fops     },
299         { .name =       "blocksize",
300           .fops =       &lov_blksize_fops       },
301         { .name =       "kbytestotal",
302           .fops =       &lov_kbytestotal_fops   },
303         { .name =       "kbytesfree",
304           .fops =       &lov_kbytesfree_fops    },
305         { .name =       "kbytesavail",
306           .fops =       &lov_kbytesavail_fops   },
307         { .name =       "desc_uuid",
308           .fops =       &lov_desc_uuid_fops     },
309         { NULL }
310 };
311
312 struct file_operations lov_proc_target_fops = {
313         .owner   = THIS_MODULE,
314         .open    = lov_target_seq_open,
315         .read    = seq_read,
316         .llseek  = seq_lseek,
317         .release = lprocfs_seq_release,
318 };
319 #endif /* CONFIG_PROC_FS */