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.sun.com/software/products/lustre/docs/GPLv2.pdf
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
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_CLASS
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"
44 static int lov_stripesize_seq_show(struct seq_file *m, void *v)
46 struct obd_device *dev = (struct obd_device *)m->private;
47 struct lov_desc *desc;
50 desc = &dev->u.lov.desc;
51 seq_printf(m, "%llu\n", desc->ld_default_stripe_size);
55 static ssize_t lov_stripesize_seq_write(struct file *file,
56 const char __user *buffer,
57 size_t count, loff_t *off)
59 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
60 struct lov_desc *desc;
65 desc = &dev->u.lov.desc;
66 rc = lprocfs_write_u64_helper(buffer, count, &val);
70 lov_fix_desc_stripe_size(&val);
71 desc->ld_default_stripe_size = val;
75 LPROC_SEQ_FOPS(lov_stripesize);
77 static int lov_stripeoffset_seq_show(struct seq_file *m, void *v)
79 struct obd_device *dev = (struct obd_device *)m->private;
80 struct lov_desc *desc;
83 desc = &dev->u.lov.desc;
84 seq_printf(m, "%llu\n", desc->ld_default_stripe_offset);
88 static ssize_t lov_stripeoffset_seq_write(struct file *file,
89 const char __user *buffer,
90 size_t count, loff_t *off)
92 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
93 struct lov_desc *desc;
98 desc = &dev->u.lov.desc;
99 rc = lprocfs_write_u64_helper(buffer, count, &val);
103 desc->ld_default_stripe_offset = val;
107 LPROC_SEQ_FOPS(lov_stripeoffset);
109 static int lov_stripetype_seq_show(struct seq_file *m, void *v)
111 struct obd_device *dev = (struct obd_device *)m->private;
112 struct lov_desc *desc;
114 LASSERT(dev != NULL);
115 desc = &dev->u.lov.desc;
116 seq_printf(m, "%u\n", desc->ld_pattern);
120 static ssize_t lov_stripetype_seq_write(struct file *file,
121 const char __user *buffer,
122 size_t count, loff_t *off)
124 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
125 struct lov_desc *desc;
128 LASSERT(dev != NULL);
129 desc = &dev->u.lov.desc;
130 rc = lprocfs_write_helper(buffer, count, &val);
134 lov_fix_desc_pattern(&val);
135 desc->ld_pattern = val;
139 LPROC_SEQ_FOPS(lov_stripetype);
141 static int lov_stripecount_seq_show(struct seq_file *m, void *v)
143 struct obd_device *dev = (struct obd_device *)m->private;
144 struct lov_desc *desc;
146 LASSERT(dev != NULL);
147 desc = &dev->u.lov.desc;
148 seq_printf(m, "%d\n", (__s16)(desc->ld_default_stripe_count + 1) - 1);
152 static ssize_t lov_stripecount_seq_write(struct file *file,
153 const char __user *buffer,
154 size_t count, loff_t *off)
156 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
157 struct lov_desc *desc;
160 LASSERT(dev != NULL);
161 desc = &dev->u.lov.desc;
162 rc = lprocfs_write_helper(buffer, count, &val);
166 lov_fix_desc_stripe_count(&val);
167 desc->ld_default_stripe_count = val;
171 LPROC_SEQ_FOPS(lov_stripecount);
173 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
176 struct obd_device *dev = container_of(kobj, struct obd_device,
178 struct lov_desc *desc;
180 desc = &dev->u.lov.desc;
181 return sprintf(buf, "%u\n", desc->ld_tgt_count);
183 LUSTRE_RO_ATTR(numobd);
185 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
188 struct obd_device *dev = container_of(kobj, struct obd_device,
190 struct lov_desc *desc;
192 desc = &dev->u.lov.desc;
193 return sprintf(buf, "%u\n", desc->ld_active_tgt_count);
195 LUSTRE_RO_ATTR(activeobd);
197 static int lov_desc_uuid_seq_show(struct seq_file *m, void *v)
199 struct obd_device *dev = (struct obd_device *)m->private;
202 LASSERT(dev != NULL);
204 seq_printf(m, "%s\n", lov->desc.ld_uuid.uuid);
208 LPROC_SEQ_FOPS_RO(lov_desc_uuid);
210 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
212 struct obd_device *dev = p->private;
213 struct lov_obd *lov = &dev->u.lov;
215 while (*pos < lov->desc.ld_tgt_count) {
216 if (lov->lov_tgts[*pos])
217 return lov->lov_tgts[*pos];
223 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
227 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
229 struct obd_device *dev = p->private;
230 struct lov_obd *lov = &dev->u.lov;
232 while (++*pos < lov->desc.ld_tgt_count) {
233 if (lov->lov_tgts[*pos])
234 return lov->lov_tgts[*pos];
239 static int lov_tgt_seq_show(struct seq_file *p, void *v)
241 struct lov_tgt_desc *tgt = v;
243 seq_printf(p, "%d: %s %sACTIVE\n",
244 tgt->ltd_index, obd_uuid2str(&tgt->ltd_uuid),
245 tgt->ltd_active ? "" : "IN");
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,
256 static int lov_target_seq_open(struct inode *inode, struct file *file)
258 struct seq_file *seq;
261 rc = seq_open(file, &lov_tgt_sops);
265 seq = file->private_data;
266 seq->private = inode->i_private;
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 },
280 static struct attribute *lov_attrs[] = {
281 &lustre_attr_activeobd.attr,
282 &lustre_attr_numobd.attr,
286 static struct attribute_group lov_attr_group = {
290 void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars)
292 lvars->sysfs_vars = &lov_attr_group;
293 lvars->obd_vars = lprocfs_lov_obd_vars;
296 const struct file_operations lov_proc_target_fops = {
297 .owner = THIS_MODULE,
298 .open = lov_target_seq_open,
301 .release = lprocfs_seq_release,