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"
41 static int lov_stripesize_seq_show(struct seq_file *m, void *v)
43 struct obd_device *dev = (struct obd_device *)m->private;
44 struct lov_desc *desc;
47 desc = &dev->u.lov.desc;
49 seq_printf(m, "%llu\n", desc->ld_default_stripe_size);
53 static ssize_t lov_stripesize_seq_write(struct file *file,
54 const char __user *buffer,
55 size_t count, loff_t *off)
57 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
58 struct lov_desc *desc;
63 desc = &dev->u.lov.desc;
64 rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
70 lov_fix_desc_stripe_size(&val);
71 desc->ld_default_stripe_size = val;
75 LPROC_SEQ_FOPS(lov_stripesize);
77 static ssize_t stripeoffset_show(struct kobject *kobj, struct attribute *attr,
80 struct obd_device *dev = container_of(kobj, struct obd_device,
82 struct lov_desc *desc = &dev->u.lov.desc;
84 return sprintf(buf, "%lld\n", desc->ld_default_stripe_offset);
87 static ssize_t stripeoffset_store(struct kobject *kobj, struct attribute *attr,
88 const char *buf, size_t count)
90 struct obd_device *dev = container_of(kobj, struct obd_device,
92 struct lov_desc *desc = &dev->u.lov.desc;
96 rc = kstrtol(buf, 0, &val);
99 if (val < -1 || val > LOV_MAX_STRIPE_COUNT)
102 desc->ld_default_stripe_offset = val;
106 LUSTRE_RW_ATTR(stripeoffset);
108 static ssize_t stripetype_show(struct kobject *kobj, struct attribute *attr,
111 struct obd_device *dev = container_of(kobj, struct obd_device,
113 struct lov_desc *desc = &dev->u.lov.desc;
115 return sprintf(buf, "%u\n", desc->ld_pattern);
118 static ssize_t stripetype_store(struct kobject *kobj, struct attribute *attr,
119 const char *buffer, size_t count)
121 struct obd_device *dev = container_of(kobj, struct obd_device,
123 struct lov_desc *desc = &dev->u.lov.desc;
127 rc = kstrtouint(buffer, 0, &pattern);
131 lov_fix_desc_pattern(&pattern);
132 desc->ld_pattern = pattern;
136 LUSTRE_RW_ATTR(stripetype);
138 static ssize_t stripecount_show(struct kobject *kobj, struct attribute *attr,
141 struct obd_device *dev = container_of(kobj, struct obd_device,
143 struct lov_desc *desc = &dev->u.lov.desc;
145 return sprintf(buf, "%d\n",
146 (__s16)(desc->ld_default_stripe_count + 1) - 1);
149 static ssize_t stripecount_store(struct kobject *kobj, struct attribute *attr,
150 const char *buffer, size_t count)
152 struct obd_device *dev = container_of(kobj, struct obd_device,
154 struct lov_desc *desc = &dev->u.lov.desc;
158 rc = kstrtoint(buffer, 0, &stripe_count);
162 if (stripe_count < -1)
165 lov_fix_desc_stripe_count(&stripe_count);
166 desc->ld_default_stripe_count = stripe_count;
170 LUSTRE_RW_ATTR(stripecount);
172 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
175 struct obd_device *dev = container_of(kobj, struct obd_device,
177 struct lov_desc *desc = &dev->u.lov.desc;
179 return sprintf(buf, "%u\n", desc->ld_tgt_count);
181 LUSTRE_RO_ATTR(numobd);
183 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
186 struct obd_device *dev = container_of(kobj, struct obd_device,
188 struct lov_desc *desc = &dev->u.lov.desc;
190 return sprintf(buf, "%u\n", desc->ld_active_tgt_count);
192 LUSTRE_RO_ATTR(activeobd);
194 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
197 struct obd_device *dev = container_of(kobj, struct obd_device,
199 struct lov_desc *desc = &dev->u.lov.desc;
201 return sprintf(buf, "%s\n", desc->ld_uuid.uuid);
203 LUSTRE_RO_ATTR(desc_uuid);
205 #ifdef CONFIG_PROC_FS
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", tgt->ltd_index,
240 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 = PDE_DATA(inode);
266 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
267 { .name = "stripesize",
268 .fops = &lov_stripesize_fops },
272 const struct file_operations lov_proc_target_fops = {
273 .owner = THIS_MODULE,
274 .open = lov_target_seq_open,
277 .release = lprocfs_seq_release,
279 #endif /* CONFIG_PROC_FS */
281 static struct attribute *lov_attrs[] = {
282 &lustre_attr_activeobd.attr,
283 &lustre_attr_numobd.attr,
284 &lustre_attr_desc_uuid.attr,
285 &lustre_attr_stripeoffset.attr,
286 &lustre_attr_stripetype.attr,
287 &lustre_attr_stripecount.attr,
291 int lov_tunables_init(struct obd_device *obd)
293 struct lov_obd *lov = &obd->u.lov;
296 obd->obd_vars = lprocfs_lov_obd_vars;
297 obd->obd_ktype.default_attrs = lov_attrs;
298 rc = lprocfs_obd_setup(obd, false);
302 #ifdef CONFIG_PROC_FS
303 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd", 0444,
304 &lov_proc_target_fops, obd);
306 CWARN("%s: Error adding the target_obd file : rc %d\n",
309 lov->lov_pool_proc_entry = lprocfs_register("pools",
312 if (IS_ERR(lov->lov_pool_proc_entry)) {
313 rc = PTR_ERR(lov->lov_pool_proc_entry);
314 CERROR("%s: error setting up debugfs for pools : rc %d\n",
316 lov->lov_pool_proc_entry = NULL;
318 #endif /* CONFIG_FS_PROC */