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