4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2015 Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 #define DEBUG_SUBSYSTEM S_CLASS
34 #include <linux/statfs.h>
35 #include <lprocfs_status.h>
36 #include <obd_class.h>
37 #include <linux/seq_file.h>
38 #include "lov_internal.h"
40 static int lov_stripesize_seq_show(struct seq_file *m, void *v)
42 struct obd_device *dev = (struct obd_device *)m->private;
43 struct lov_desc *desc;
46 desc = &dev->u.lov.desc;
47 seq_printf(m, "%llu\n", desc->ld_default_stripe_size);
51 static ssize_t lov_stripesize_seq_write(struct file *file,
52 const char __user *buffer,
53 size_t count, loff_t *off)
55 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
56 struct lov_desc *desc;
61 desc = &dev->u.lov.desc;
62 rc = lprocfs_write_u64_helper(buffer, count, &val);
66 lov_fix_desc_stripe_size(&val);
67 desc->ld_default_stripe_size = val;
71 LPROC_SEQ_FOPS(lov_stripesize);
73 static int lov_stripeoffset_seq_show(struct seq_file *m, void *v)
75 struct obd_device *dev = (struct obd_device *)m->private;
76 struct lov_desc *desc;
79 desc = &dev->u.lov.desc;
80 seq_printf(m, "%llu\n", desc->ld_default_stripe_offset);
84 static ssize_t lov_stripeoffset_seq_write(struct file *file,
85 const char __user *buffer,
86 size_t count, loff_t *off)
88 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
89 struct lov_desc *desc;
94 desc = &dev->u.lov.desc;
95 rc = lprocfs_write_u64_helper(buffer, count, &val);
99 desc->ld_default_stripe_offset = val;
103 LPROC_SEQ_FOPS(lov_stripeoffset);
105 static int lov_stripetype_seq_show(struct seq_file *m, void *v)
107 struct obd_device *dev = (struct obd_device *)m->private;
108 struct lov_desc *desc;
111 desc = &dev->u.lov.desc;
112 seq_printf(m, "%u\n", desc->ld_pattern);
116 static ssize_t lov_stripetype_seq_write(struct file *file,
117 const char __user *buffer,
118 size_t count, loff_t *off)
120 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
121 struct lov_desc *desc;
125 desc = &dev->u.lov.desc;
126 rc = lprocfs_write_helper(buffer, count, &val);
130 lov_fix_desc_pattern(&val);
131 desc->ld_pattern = val;
135 LPROC_SEQ_FOPS(lov_stripetype);
137 static int lov_stripecount_seq_show(struct seq_file *m, void *v)
139 struct obd_device *dev = (struct obd_device *)m->private;
140 struct lov_desc *desc;
143 desc = &dev->u.lov.desc;
144 seq_printf(m, "%d\n", (__s16)(desc->ld_default_stripe_count + 1) - 1);
148 static ssize_t lov_stripecount_seq_write(struct file *file,
149 const char __user *buffer,
150 size_t count, loff_t *off)
152 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
153 struct lov_desc *desc;
157 desc = &dev->u.lov.desc;
158 rc = lprocfs_write_helper(buffer, count, &val);
162 lov_fix_desc_stripe_count(&val);
163 desc->ld_default_stripe_count = val;
167 LPROC_SEQ_FOPS(lov_stripecount);
169 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
172 struct obd_device *dev = container_of(kobj, struct obd_device,
174 struct lov_desc *desc;
176 desc = &dev->u.lov.desc;
177 return sprintf(buf, "%u\n", desc->ld_tgt_count);
179 LUSTRE_RO_ATTR(numobd);
181 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
184 struct obd_device *dev = container_of(kobj, struct obd_device,
186 struct lov_desc *desc;
188 desc = &dev->u.lov.desc;
189 return sprintf(buf, "%u\n", desc->ld_active_tgt_count);
191 LUSTRE_RO_ATTR(activeobd);
193 static int lov_desc_uuid_seq_show(struct seq_file *m, void *v)
195 struct obd_device *dev = (struct obd_device *)m->private;
200 seq_printf(m, "%s\n", lov->desc.ld_uuid.uuid);
204 LPROC_SEQ_FOPS_RO(lov_desc_uuid);
206 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
208 struct obd_device *dev = p->private;
209 struct lov_obd *lov = &dev->u.lov;
211 while (*pos < lov->desc.ld_tgt_count) {
212 if (lov->lov_tgts[*pos])
213 return lov->lov_tgts[*pos];
219 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
223 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
225 struct obd_device *dev = p->private;
226 struct lov_obd *lov = &dev->u.lov;
228 while (++*pos < lov->desc.ld_tgt_count) {
229 if (lov->lov_tgts[*pos])
230 return lov->lov_tgts[*pos];
235 static int lov_tgt_seq_show(struct seq_file *p, void *v)
237 struct lov_tgt_desc *tgt = v;
239 seq_printf(p, "%d: %s %sACTIVE\n",
240 tgt->ltd_index, obd_uuid2str(&tgt->ltd_uuid),
241 tgt->ltd_active ? "" : "IN");
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,
252 static int lov_target_seq_open(struct inode *inode, struct file *file)
254 struct seq_file *seq;
257 rc = seq_open(file, &lov_tgt_sops);
261 seq = file->private_data;
262 seq->private = inode->i_private;
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 },
276 static struct attribute *lov_attrs[] = {
277 &lustre_attr_activeobd.attr,
278 &lustre_attr_numobd.attr,
282 static const struct attribute_group lov_attr_group = {
286 void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars)
288 lvars->sysfs_vars = &lov_attr_group;
289 lvars->obd_vars = lprocfs_lov_obd_vars;
292 const struct file_operations lov_proc_target_fops = {
293 .owner = THIS_MODULE,
294 .open = lov_target_seq_open,
297 .release = lprocfs_seq_release,