Whamcloud - gitweb
LU-4974 lod: Change pool_desc to "[lod|lov]_pool_desc"
[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  */
31 #define DEBUG_SUBSYSTEM S_CLASS
32
33 #include <linux/version.h>
34 #include <asm/statfs.h>
35 #include <lprocfs_status.h>
36 #include <obd_class.h>
37 #include <uapi/linux/lustre/lustre_param.h>
38 #include "lov_internal.h"
39
40 static ssize_t stripesize_show(struct kobject *kobj, struct attribute *attr,
41                                char *buf)
42 {
43         struct obd_device *obd = container_of(kobj, struct obd_device,
44                                               obd_kset.kobj);
45         struct lov_desc *desc = &obd->u.lov.desc;
46
47         return scnprintf(buf, PAGE_SIZE, "%llu\n", desc->ld_default_stripe_size);
48 }
49
50 static ssize_t stripesize_store(struct kobject *kobj, struct attribute *attr,
51                                 const char *buf, size_t count)
52 {
53         struct obd_device *obd = container_of(kobj, struct obd_device,
54                                               obd_kset.kobj);
55         struct lov_desc *desc = &obd->u.lov.desc;
56         u64 val;
57         int rc;
58
59         rc = sysfs_memparse(buf, count, &val, "B");
60         if (rc < 0)
61                 return rc;
62
63         lov_fix_desc_stripe_size(&val);
64         desc->ld_default_stripe_size = val;
65
66         return count;
67 }
68 LUSTRE_RW_ATTR(stripesize);
69
70 static ssize_t stripeoffset_show(struct kobject *kobj, struct attribute *attr,
71                                  char *buf)
72 {
73         struct obd_device *obd = container_of(kobj, struct obd_device,
74                                               obd_kset.kobj);
75         struct lov_desc *desc = &obd->u.lov.desc;
76
77         return sprintf(buf, "%lld\n", desc->ld_default_stripe_offset);
78 }
79
80 static ssize_t stripeoffset_store(struct kobject *kobj, struct attribute *attr,
81                                   const char *buf, size_t count)
82 {
83         struct obd_device *obd = container_of(kobj, struct obd_device,
84                                               obd_kset.kobj);
85         struct lov_desc *desc = &obd->u.lov.desc;
86         long val;
87         int rc;
88
89         rc = kstrtol(buf, 0, &val);
90         if (rc)
91                 return rc;
92         if (val < -1 || val > LOV_MAX_STRIPE_COUNT)
93                 return -ERANGE;
94
95         desc->ld_default_stripe_offset = val;
96
97         return count;
98 }
99 LUSTRE_RW_ATTR(stripeoffset);
100
101 static ssize_t stripetype_show(struct kobject *kobj, struct attribute *attr,
102                                char *buf)
103 {
104         struct obd_device *obd = container_of(kobj, struct obd_device,
105                                               obd_kset.kobj);
106         struct lov_desc *desc = &obd->u.lov.desc;
107
108         return sprintf(buf, "%u\n", desc->ld_pattern);
109 }
110
111 static ssize_t stripetype_store(struct kobject *kobj, struct attribute *attr,
112                                 const char *buffer, size_t count)
113 {
114         struct obd_device *obd = container_of(kobj, struct obd_device,
115                                               obd_kset.kobj);
116         struct lov_desc *desc = &obd->u.lov.desc;
117         u32 pattern;
118         int rc;
119
120         rc = kstrtouint(buffer, 0, &pattern);
121         if (rc)
122                 return rc;
123
124         lov_fix_desc_pattern(&pattern);
125         desc->ld_pattern = pattern;
126
127         return count;
128 }
129 LUSTRE_RW_ATTR(stripetype);
130
131 static ssize_t stripecount_show(struct kobject *kobj, struct attribute *attr,
132                                 char *buf)
133 {
134         struct obd_device *obd = container_of(kobj, struct obd_device,
135                                               obd_kset.kobj);
136         struct lov_desc *desc = &obd->u.lov.desc;
137
138         return sprintf(buf, "%d\n",
139                        (__s16)(desc->ld_default_stripe_count + 1) - 1);
140 }
141
142 static ssize_t stripecount_store(struct kobject *kobj, struct attribute *attr,
143                                  const char *buffer, size_t count)
144 {
145         struct obd_device *obd = container_of(kobj, struct obd_device,
146                                               obd_kset.kobj);
147         struct lov_desc *desc = &obd->u.lov.desc;
148         int stripe_count;
149         int rc;
150
151         rc = kstrtoint(buffer, 0, &stripe_count);
152         if (rc)
153                 return rc;
154
155         if (stripe_count < -1)
156                 return -ERANGE;
157
158         lov_fix_desc_stripe_count(&stripe_count);
159         desc->ld_default_stripe_count = stripe_count;
160
161         return count;
162 }
163 LUSTRE_RW_ATTR(stripecount);
164
165 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
166                            char *buf)
167 {
168         struct obd_device *obd = container_of(kobj, struct obd_device,
169                                               obd_kset.kobj);
170         struct lov_desc *desc = &obd->u.lov.desc;
171
172         return sprintf(buf, "%u\n", desc->ld_tgt_count);
173 }
174 LUSTRE_RO_ATTR(numobd);
175
176 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
177                               char *buf)
178 {
179         struct obd_device *obd = container_of(kobj, struct obd_device,
180                                               obd_kset.kobj);
181         struct lov_desc *desc = &obd->u.lov.desc;
182
183         return sprintf(buf, "%u\n", desc->ld_active_tgt_count);
184 }
185 LUSTRE_RO_ATTR(activeobd);
186
187 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
188                               char *buf)
189 {
190         struct obd_device *obd = container_of(kobj, struct obd_device,
191                                               obd_kset.kobj);
192         struct lov_desc *desc = &obd->u.lov.desc;
193
194         return sprintf(buf, "%s\n", desc->ld_uuid.uuid);
195 }
196 LUSTRE_RO_ATTR(desc_uuid);
197
198 #ifdef CONFIG_PROC_FS
199 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
200 {
201         struct obd_device *obd = p->private;
202         struct lov_obd *lov = &obd->u.lov;
203
204         while (*pos < lov->desc.ld_tgt_count) {
205                 if (lov->lov_tgts[*pos])
206                         return lov->lov_tgts[*pos];
207                 ++*pos;
208         }
209         return NULL;
210 }
211
212 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
213 {
214 }
215
216 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
217 {
218         struct obd_device *obd = p->private;
219         struct lov_obd *lov = &obd->u.lov;
220
221         while (++*pos < lov->desc.ld_tgt_count) {
222                 if (lov->lov_tgts[*pos])
223                         return lov->lov_tgts[*pos];
224         }
225         return NULL;
226 }
227
228 static int lov_tgt_seq_show(struct seq_file *p, void *v)
229 {
230         struct lov_tgt_desc *tgt = v;
231
232         seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
233                    obd_uuid2str(&tgt->ltd_uuid),
234                    tgt->ltd_active ? "" : "IN");
235         return 0;
236 }
237
238 static const struct seq_operations lov_tgt_sops = {
239         .start = lov_tgt_seq_start,
240         .stop = lov_tgt_seq_stop,
241         .next = lov_tgt_seq_next,
242         .show = lov_tgt_seq_show,
243 };
244
245 static int lov_target_seq_open(struct inode *inode, struct file *file)
246 {
247         struct seq_file *seq;
248         int rc;
249
250         rc = seq_open(file, &lov_tgt_sops);
251         if (rc)
252                 return rc;
253
254         seq = file->private_data;
255         seq->private = pde_data(inode);
256         return 0;
257 }
258
259 static const struct proc_ops lov_proc_target_fops = {
260         PROC_OWNER(THIS_MODULE)
261         .proc_open      = lov_target_seq_open,
262         .proc_read      = seq_read,
263         .proc_lseek     = seq_lseek,
264         .proc_release   = lprocfs_seq_release,
265 };
266 #endif /* CONFIG_PROC_FS */
267
268 static struct attribute *lov_attrs[] = {
269         &lustre_attr_activeobd.attr,
270         &lustre_attr_numobd.attr,
271         &lustre_attr_desc_uuid.attr,
272         &lustre_attr_stripesize.attr,
273         &lustre_attr_stripeoffset.attr,
274         &lustre_attr_stripetype.attr,
275         &lustre_attr_stripecount.attr,
276         NULL,
277 };
278
279 KOBJ_ATTRIBUTE_GROUPS(lov); /* creates lov_groups */
280
281 int lov_tunables_init(struct obd_device *obd)
282 {
283         struct lov_obd *lov = &obd->u.lov;
284         int rc;
285
286         obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(lov);
287         rc = lprocfs_obd_setup(obd, false);
288         if (rc)
289                 GOTO(out, rc);
290
291 #ifdef CONFIG_PROC_FS
292         rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd", 0444,
293                                 &lov_proc_target_fops, obd);
294         if (rc)
295                 CWARN("%s: Error adding the target_obd file : rc %d\n",
296                       obd->obd_name, rc);
297
298         lov->lov_pool_proc_entry = lprocfs_register("pools",
299                                                     obd->obd_proc_entry,
300                                                     NULL, NULL);
301         if (IS_ERR(lov->lov_pool_proc_entry)) {
302                 rc = PTR_ERR(lov->lov_pool_proc_entry);
303                 CERROR("%s: error setting up debugfs for pools : rc %d\n",
304                        obd->obd_name, rc);
305                 lov->lov_pool_proc_entry = NULL;
306         }
307 #endif /* CONFIG_FS_PROC */
308 out:
309         return rc;
310 }