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, 2017, 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/version.h>
35 #include <asm/statfs.h>
36 #include <lprocfs_status.h>
37 #include <obd_class.h>
38 #include <uapi/linux/lustre/lustre_param.h>
39 #include "lov_internal.h"
42 static int lov_stripesize_seq_show(struct seq_file *m, void *v)
44 struct obd_device *dev = (struct obd_device *)m->private;
45 struct lov_desc *desc;
48 desc = &dev->u.lov.desc;
50 seq_printf(m, "%llu\n", desc->ld_default_stripe_size);
54 static ssize_t lov_stripesize_seq_write(struct file *file,
55 const char __user *buffer,
56 size_t count, loff_t *off)
58 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
59 struct lov_desc *desc;
64 desc = &dev->u.lov.desc;
65 rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
71 lov_fix_desc_stripe_size(&val);
72 desc->ld_default_stripe_size = val;
76 LPROC_SEQ_FOPS(lov_stripesize);
78 static int lov_stripeoffset_seq_show(struct seq_file *m, void *v)
80 struct obd_device *dev = (struct obd_device *)m->private;
81 struct lov_desc *desc;
84 desc = &dev->u.lov.desc;
85 seq_printf(m, "%lld\n", desc->ld_default_stripe_offset);
89 static ssize_t lov_stripeoffset_seq_write(struct file *file,
90 const char __user *buffer,
91 size_t count, loff_t *off)
93 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
94 struct lov_desc *desc;
99 desc = &dev->u.lov.desc;
100 rc = kstrtol_from_user(buffer, count, 0, &val);
103 if (val < -1 || val > LOV_MAX_STRIPE_COUNT)
106 desc->ld_default_stripe_offset = val;
110 LPROC_SEQ_FOPS(lov_stripeoffset);
112 static int lov_stripetype_seq_show(struct seq_file *m, void *v)
114 struct obd_device* dev = (struct obd_device*)m->private;
115 struct lov_desc *desc;
117 LASSERT(dev != NULL);
118 desc = &dev->u.lov.desc;
119 seq_printf(m, "%u\n", desc->ld_pattern);
123 static ssize_t lov_stripetype_seq_write(struct file *file,
124 const char __user *buffer,
125 size_t count, loff_t *off)
127 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
128 struct lov_desc *desc;
132 LASSERT(dev != NULL);
133 desc = &dev->u.lov.desc;
134 rc = kstrtouint_from_user(buffer, count, 0, &pattern);
138 lov_fix_desc_pattern(&pattern);
139 desc->ld_pattern = pattern;
143 LPROC_SEQ_FOPS(lov_stripetype);
145 static int lov_stripecount_seq_show(struct seq_file *m, void *v)
147 struct obd_device *dev = (struct obd_device *)m->private;
148 struct lov_desc *desc;
150 LASSERT(dev != NULL);
151 desc = &dev->u.lov.desc;
152 seq_printf(m, "%d\n",
153 (__s16)(desc->ld_default_stripe_count + 1) - 1);
157 static ssize_t lov_stripecount_seq_write(struct file *file,
158 const char __user *buffer,
159 size_t count, loff_t *off)
161 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
162 struct lov_desc *desc;
166 LASSERT(dev != NULL);
167 desc = &dev->u.lov.desc;
168 rc = kstrtoint_from_user(buffer, count, 0, &stripe_count);
172 if (stripe_count < -1)
175 lov_fix_desc_stripe_count(&stripe_count);
176 desc->ld_default_stripe_count = stripe_count;
180 LPROC_SEQ_FOPS(lov_stripecount);
182 static int lov_numobd_seq_show(struct seq_file *m, void *v)
184 struct obd_device *dev = (struct obd_device*)m->private;
185 struct lov_desc *desc;
187 LASSERT(dev != NULL);
188 desc = &dev->u.lov.desc;
189 seq_printf(m, "%u\n", desc->ld_tgt_count);
192 LPROC_SEQ_FOPS_RO(lov_numobd);
194 static int lov_activeobd_seq_show(struct seq_file *m, void *v)
196 struct obd_device* dev = (struct obd_device*)m->private;
197 struct lov_desc *desc;
199 LASSERT(dev != NULL);
200 desc = &dev->u.lov.desc;
201 seq_printf(m, "%u\n", desc->ld_active_tgt_count);
204 LPROC_SEQ_FOPS_RO(lov_activeobd);
206 static int lov_desc_uuid_seq_show(struct seq_file *m, void *v)
208 struct obd_device *dev = m->private;
211 LASSERT(dev != NULL);
213 seq_printf(m, "%s\n", lov->desc.ld_uuid.uuid);
216 LPROC_SEQ_FOPS_RO(lov_desc_uuid);
218 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
220 struct obd_device *dev = p->private;
221 struct lov_obd *lov = &dev->u.lov;
223 while (*pos < lov->desc.ld_tgt_count) {
224 if (lov->lov_tgts[*pos])
225 return lov->lov_tgts[*pos];
231 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
235 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
237 struct obd_device *dev = p->private;
238 struct lov_obd *lov = &dev->u.lov;
240 while (++*pos < lov->desc.ld_tgt_count) {
241 if (lov->lov_tgts[*pos])
242 return lov->lov_tgts[*pos];
247 static int lov_tgt_seq_show(struct seq_file *p, void *v)
249 struct lov_tgt_desc *tgt = v;
250 seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
251 obd_uuid2str(&tgt->ltd_uuid),
252 tgt->ltd_active ? "" : "IN");
256 static const struct seq_operations lov_tgt_sops = {
257 .start = lov_tgt_seq_start,
258 .stop = lov_tgt_seq_stop,
259 .next = lov_tgt_seq_next,
260 .show = lov_tgt_seq_show,
263 static int lov_target_seq_open(struct inode *inode, struct file *file)
265 struct seq_file *seq;
268 rc = LPROCFS_ENTRY_CHECK(inode);
272 rc = seq_open(file, &lov_tgt_sops);
276 seq = file->private_data;
277 seq->private = PDE_DATA(inode);
281 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
282 { .name = "stripesize",
283 .fops = &lov_stripesize_fops },
284 { .name = "stripeoffset",
285 .fops = &lov_stripeoffset_fops },
286 { .name = "stripecount",
287 .fops = &lov_stripecount_fops },
288 { .name = "stripetype",
289 .fops = &lov_stripetype_fops },
291 .fops = &lov_numobd_fops },
292 { .name = "activeobd",
293 .fops = &lov_activeobd_fops },
294 { .name = "desc_uuid",
295 .fops = &lov_desc_uuid_fops },
299 const struct file_operations lov_proc_target_fops = {
300 .owner = THIS_MODULE,
301 .open = lov_target_seq_open,
304 .release = lprocfs_seq_release,
306 #endif /* CONFIG_PROC_FS */