GNU Linux-libre 4.9.315-gnu1
[releases.git] / drivers / staging / lustre / 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, 2015 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/statfs.h>
35 #include "../include/lprocfs_status.h"
36 #include "../include/obd_class.h"
37 #include <linux/seq_file.h>
38 #include "lov_internal.h"
39
40 static int lov_stripesize_seq_show(struct seq_file *m, void *v)
41 {
42         struct obd_device *dev = (struct obd_device *)m->private;
43         struct lov_desc *desc;
44
45         LASSERT(dev);
46         desc = &dev->u.lov.desc;
47         seq_printf(m, "%llu\n", desc->ld_default_stripe_size);
48         return 0;
49 }
50
51 static ssize_t lov_stripesize_seq_write(struct file *file,
52                                         const char __user *buffer,
53                                         size_t count, loff_t *off)
54 {
55         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
56         struct lov_desc *desc;
57         __u64 val;
58         int rc;
59
60         LASSERT(dev);
61         desc = &dev->u.lov.desc;
62         rc = lprocfs_write_u64_helper(buffer, count, &val);
63         if (rc)
64                 return rc;
65
66         lov_fix_desc_stripe_size(&val);
67         desc->ld_default_stripe_size = val;
68         return count;
69 }
70
71 LPROC_SEQ_FOPS(lov_stripesize);
72
73 static int lov_stripeoffset_seq_show(struct seq_file *m, void *v)
74 {
75         struct obd_device *dev = (struct obd_device *)m->private;
76         struct lov_desc *desc;
77
78         LASSERT(dev);
79         desc = &dev->u.lov.desc;
80         seq_printf(m, "%llu\n", desc->ld_default_stripe_offset);
81         return 0;
82 }
83
84 static ssize_t lov_stripeoffset_seq_write(struct file *file,
85                                           const char __user *buffer,
86                                           size_t count, loff_t *off)
87 {
88         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
89         struct lov_desc *desc;
90         __u64 val;
91         int rc;
92
93         LASSERT(dev);
94         desc = &dev->u.lov.desc;
95         rc = lprocfs_write_u64_helper(buffer, count, &val);
96         if (rc)
97                 return rc;
98
99         desc->ld_default_stripe_offset = val;
100         return count;
101 }
102
103 LPROC_SEQ_FOPS(lov_stripeoffset);
104
105 static int lov_stripetype_seq_show(struct seq_file *m, void *v)
106 {
107         struct obd_device *dev = (struct obd_device *)m->private;
108         struct lov_desc *desc;
109
110         LASSERT(dev);
111         desc = &dev->u.lov.desc;
112         seq_printf(m, "%u\n", desc->ld_pattern);
113         return 0;
114 }
115
116 static ssize_t lov_stripetype_seq_write(struct file *file,
117                                         const char __user *buffer,
118                                         size_t count, loff_t *off)
119 {
120         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
121         struct lov_desc *desc;
122         int val, rc;
123
124         LASSERT(dev);
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 LPROC_SEQ_FOPS(lov_stripetype);
136
137 static int lov_stripecount_seq_show(struct seq_file *m, void *v)
138 {
139         struct obd_device *dev = (struct obd_device *)m->private;
140         struct lov_desc *desc;
141
142         LASSERT(dev);
143         desc = &dev->u.lov.desc;
144         seq_printf(m, "%d\n", (__s16)(desc->ld_default_stripe_count + 1) - 1);
145         return 0;
146 }
147
148 static ssize_t lov_stripecount_seq_write(struct file *file,
149                                          const char __user *buffer,
150                                          size_t count, loff_t *off)
151 {
152         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
153         struct lov_desc *desc;
154         int val, rc;
155
156         LASSERT(dev);
157         desc = &dev->u.lov.desc;
158         rc = lprocfs_write_helper(buffer, count, &val);
159         if (rc)
160                 return rc;
161
162         lov_fix_desc_stripe_count(&val);
163         desc->ld_default_stripe_count = val;
164         return count;
165 }
166
167 LPROC_SEQ_FOPS(lov_stripecount);
168
169 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
170                            char *buf)
171 {
172         struct obd_device *dev = container_of(kobj, struct obd_device,
173                                               obd_kobj);
174         struct lov_desc *desc;
175
176         desc = &dev->u.lov.desc;
177         return sprintf(buf, "%u\n", desc->ld_tgt_count);
178 }
179 LUSTRE_RO_ATTR(numobd);
180
181 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
182                               char *buf)
183 {
184         struct obd_device *dev = container_of(kobj, struct obd_device,
185                                               obd_kobj);
186         struct lov_desc *desc;
187
188         desc = &dev->u.lov.desc;
189         return sprintf(buf, "%u\n", desc->ld_active_tgt_count);
190 }
191 LUSTRE_RO_ATTR(activeobd);
192
193 static int lov_desc_uuid_seq_show(struct seq_file *m, void *v)
194 {
195         struct obd_device *dev = (struct obd_device *)m->private;
196         struct lov_obd *lov;
197
198         LASSERT(dev);
199         lov = &dev->u.lov;
200         seq_printf(m, "%s\n", lov->desc.ld_uuid.uuid);
201         return 0;
202 }
203
204 LPROC_SEQ_FOPS_RO(lov_desc_uuid);
205
206 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
207 {
208         struct obd_device *dev = p->private;
209         struct lov_obd *lov = &dev->u.lov;
210
211         while (*pos < lov->desc.ld_tgt_count) {
212                 if (lov->lov_tgts[*pos])
213                         return lov->lov_tgts[*pos];
214                 ++*pos;
215         }
216         return NULL;
217 }
218
219 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
220 {
221 }
222
223 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
224 {
225         struct obd_device *dev = p->private;
226         struct lov_obd *lov = &dev->u.lov;
227
228         while (++*pos < lov->desc.ld_tgt_count) {
229                 if (lov->lov_tgts[*pos])
230                         return lov->lov_tgts[*pos];
231         }
232         return NULL;
233 }
234
235 static int lov_tgt_seq_show(struct seq_file *p, void *v)
236 {
237         struct lov_tgt_desc *tgt = v;
238
239         seq_printf(p, "%d: %s %sACTIVE\n",
240                    tgt->ltd_index, obd_uuid2str(&tgt->ltd_uuid),
241                    tgt->ltd_active ? "" : "IN");
242         return 0;
243 }
244
245 static const struct seq_operations lov_tgt_sops = {
246         .start = lov_tgt_seq_start,
247         .stop = lov_tgt_seq_stop,
248         .next = lov_tgt_seq_next,
249         .show = lov_tgt_seq_show,
250 };
251
252 static int lov_target_seq_open(struct inode *inode, struct file *file)
253 {
254         struct seq_file *seq;
255         int rc;
256
257         rc = seq_open(file, &lov_tgt_sops);
258         if (rc)
259                 return rc;
260
261         seq = file->private_data;
262         seq->private = inode->i_private;
263         return 0;
264 }
265
266 static struct lprocfs_vars lprocfs_lov_obd_vars[] = {
267         { "stripesize",   &lov_stripesize_fops,   NULL },
268         { "stripeoffset", &lov_stripeoffset_fops, NULL },
269         { "stripecount",  &lov_stripecount_fops,  NULL },
270         { "stripetype",   &lov_stripetype_fops,   NULL },
271         /*{ "filegroups", lprocfs_rd_filegroups,  NULL, 0 },*/
272         { "desc_uuid",    &lov_desc_uuid_fops,    NULL, 0 },
273         { NULL }
274 };
275
276 static struct attribute *lov_attrs[] = {
277         &lustre_attr_activeobd.attr,
278         &lustre_attr_numobd.attr,
279         NULL,
280 };
281
282 static struct attribute_group lov_attr_group = {
283         .attrs = lov_attrs,
284 };
285
286 void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars)
287 {
288         lvars->sysfs_vars = &lov_attr_group;
289         lvars->obd_vars = lprocfs_lov_obd_vars;
290 }
291
292 const struct file_operations lov_proc_target_fops = {
293         .owner   = THIS_MODULE,
294         .open    = lov_target_seq_open,
295         .read    = seq_read,
296         .llseek  = seq_lseek,
297         .release = lprocfs_seq_release,
298 };