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