Whamcloud - gitweb
77cab15f5f23d7834fc3a3f25262149aea714570
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32 #define DEBUG_SUBSYSTEM S_CLASS
33
34 #include <linux/version.h>
35 #include <asm/statfs.h>
36 #include <lprocfs_status.h>
37 #include <obd_class.h>
38 #include <uapi/linux/lustre/lustre_param.h>
39 #include "lov_internal.h"
40
41 #ifdef CONFIG_PROC_FS
42 static int lov_stripesize_seq_show(struct seq_file *m, void *v)
43 {
44         struct obd_device *dev = (struct obd_device *)m->private;
45         struct lov_desc *desc;
46
47         LASSERT(dev != NULL);
48         desc = &dev->u.lov.desc;
49
50         seq_printf(m, "%llu\n", desc->ld_default_stripe_size);
51         return 0;
52 }
53
54 static ssize_t lov_stripesize_seq_write(struct file *file,
55                                         const char __user *buffer,
56                                         size_t count, loff_t *off)
57 {
58         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
59         struct lov_desc *desc;
60         __s64 val;
61         int rc;
62
63         LASSERT(dev != NULL);
64         desc = &dev->u.lov.desc;
65         rc = lprocfs_str_to_s64(buffer, count, &val);
66         if (rc)
67                 return rc;
68         if (val < 0)
69                 return -ERANGE;
70
71         lov_fix_desc_stripe_size(&val);
72         desc->ld_default_stripe_size = val;
73
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         seq_printf(m, "%lld\n", desc->ld_default_stripe_offset);
86         return 0;
87 }
88
89 static ssize_t lov_stripeoffset_seq_write(struct file *file,
90                                           const char __user *buffer,
91                                           size_t count, loff_t *off)
92 {
93         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
94         struct lov_desc *desc;
95         __s64 val;
96         int rc;
97
98         LASSERT(dev != NULL);
99         desc = &dev->u.lov.desc;
100         rc = lprocfs_str_to_s64(buffer, count, &val);
101         if (rc)
102                 return rc;
103         if (val < -1)
104                 return -ERANGE;
105
106         desc->ld_default_stripe_offset = val;
107
108         return count;
109 }
110 LPROC_SEQ_FOPS(lov_stripeoffset);
111
112 static int lov_stripetype_seq_show(struct seq_file *m, void *v)
113 {
114         struct obd_device* dev = (struct obd_device*)m->private;
115         struct lov_desc *desc;
116
117         LASSERT(dev != NULL);
118         desc = &dev->u.lov.desc;
119         seq_printf(m, "%u\n", desc->ld_pattern);
120         return 0;
121 }
122
123 static ssize_t lov_stripetype_seq_write(struct file *file,
124                                         const char __user *buffer,
125                                         size_t count, loff_t *off)
126 {
127         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
128         struct lov_desc *desc;
129         int pattern, rc;
130         __s64 val;
131
132         LASSERT(dev != NULL);
133         desc = &dev->u.lov.desc;
134         rc = lprocfs_str_to_s64(buffer, count, &val);
135         if (rc)
136                 return rc;
137         if (val < INT_MIN || val > INT_MAX)
138                 return -ERANGE;
139
140         pattern = val;
141         lov_fix_desc_pattern(&pattern);
142         desc->ld_pattern = pattern;
143
144         return count;
145 }
146 LPROC_SEQ_FOPS(lov_stripetype);
147
148 static int lov_stripecount_seq_show(struct seq_file *m, void *v)
149 {
150         struct obd_device *dev = (struct obd_device *)m->private;
151         struct lov_desc *desc;
152
153         LASSERT(dev != NULL);
154         desc = &dev->u.lov.desc;
155         seq_printf(m, "%d\n",
156                   (__s16)(desc->ld_default_stripe_count + 1) - 1);
157         return 0;
158 }
159
160 static ssize_t lov_stripecount_seq_write(struct file *file,
161                                          const char __user *buffer,
162                                          size_t count, loff_t *off)
163 {
164         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
165         struct lov_desc *desc;
166         int rc;
167         __u32 stripe_count;
168         __s64 val;
169
170         LASSERT(dev != NULL);
171         desc = &dev->u.lov.desc;
172         rc = lprocfs_str_to_s64(buffer, count, &val);
173         if (rc)
174                 return rc;
175         if (val < -1)
176                 return -ERANGE;
177
178         stripe_count = val;
179         lov_fix_desc_stripe_count(&stripe_count);
180         desc->ld_default_stripe_count = stripe_count;
181
182         return count;
183 }
184 LPROC_SEQ_FOPS(lov_stripecount);
185
186 static int lov_numobd_seq_show(struct seq_file *m, void *v)
187 {
188         struct obd_device *dev = (struct obd_device*)m->private;
189         struct lov_desc *desc;
190
191         LASSERT(dev != NULL);
192         desc = &dev->u.lov.desc;
193         seq_printf(m, "%u\n", desc->ld_tgt_count);
194         return 0;
195 }
196 LPROC_SEQ_FOPS_RO(lov_numobd);
197
198 static int lov_activeobd_seq_show(struct seq_file *m, void *v)
199 {
200         struct obd_device* dev = (struct obd_device*)m->private;
201         struct lov_desc *desc;
202
203         LASSERT(dev != NULL);
204         desc = &dev->u.lov.desc;
205         seq_printf(m, "%u\n", desc->ld_active_tgt_count);
206         return 0;
207 }
208 LPROC_SEQ_FOPS_RO(lov_activeobd);
209
210 static int lov_desc_uuid_seq_show(struct seq_file *m, void *v)
211 {
212         struct obd_device *dev = m->private;
213         struct lov_obd *lov;
214
215         LASSERT(dev != NULL);
216         lov = &dev->u.lov;
217         seq_printf(m, "%s\n", lov->desc.ld_uuid.uuid);
218         return 0;
219 }
220 LPROC_SEQ_FOPS_RO(lov_desc_uuid);
221
222 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
223 {
224         struct obd_device *dev = p->private;
225         struct lov_obd *lov = &dev->u.lov;
226
227         while (*pos < lov->desc.ld_tgt_count) {
228                 if (lov->lov_tgts[*pos])
229                         return lov->lov_tgts[*pos];
230                 ++*pos;
231         }
232         return NULL;
233 }
234
235 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
236 {
237 }
238
239 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
240 {
241         struct obd_device *dev = p->private;
242         struct lov_obd *lov = &dev->u.lov;
243
244         while (++*pos < lov->desc.ld_tgt_count) {
245                 if (lov->lov_tgts[*pos])
246                         return lov->lov_tgts[*pos];
247         }
248         return NULL;
249 }
250
251 static int lov_tgt_seq_show(struct seq_file *p, void *v)
252 {
253         struct lov_tgt_desc *tgt = v;
254         seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
255                    obd_uuid2str(&tgt->ltd_uuid),
256                    tgt->ltd_active ? "" : "IN");
257         return 0;
258 }
259
260 static const struct seq_operations lov_tgt_sops = {
261         .start = lov_tgt_seq_start,
262         .stop = lov_tgt_seq_stop,
263         .next = lov_tgt_seq_next,
264         .show = lov_tgt_seq_show,
265 };
266
267 static int lov_target_seq_open(struct inode *inode, struct file *file)
268 {
269         struct seq_file *seq;
270         int rc;
271
272         rc = LPROCFS_ENTRY_CHECK(inode);
273         if (rc < 0)
274                 return rc;
275
276         rc = seq_open(file, &lov_tgt_sops);
277         if (rc)
278                 return rc;
279
280         seq = file->private_data;
281         seq->private = PDE_DATA(inode);
282         return 0;
283 }
284
285 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
286         { .name =       "stripesize",
287           .fops =       &lov_stripesize_fops    },
288         { .name =       "stripeoffset",
289           .fops =       &lov_stripeoffset_fops  },
290         { .name =       "stripecount",
291           .fops =       &lov_stripecount_fops   },
292         { .name =       "stripetype",
293           .fops =       &lov_stripetype_fops    },
294         { .name =       "numobd",
295           .fops =       &lov_numobd_fops        },
296         { .name =       "activeobd",
297           .fops =       &lov_activeobd_fops     },
298         { .name =       "desc_uuid",
299           .fops =       &lov_desc_uuid_fops     },
300         { NULL }
301 };
302
303 struct file_operations lov_proc_target_fops = {
304         .owner   = THIS_MODULE,
305         .open    = lov_target_seq_open,
306         .read    = seq_read,
307         .llseek  = seq_lseek,
308         .release = lprocfs_seq_release,
309 };
310 #endif /* CONFIG_PROC_FS */