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) 2004, 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.
33 #define DEBUG_SUBSYSTEM S_CLASS
35 #include <linux/seq_file.h>
36 #include <linux/statfs.h>
37 #include <lprocfs_status.h>
38 #include <obd_class.h>
40 #include "lmv_internal.h"
42 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
45 struct obd_device *dev = container_of(kobj, struct obd_device,
47 struct lmv_desc *desc;
49 desc = &dev->u.lmv.desc;
50 return sprintf(buf, "%u\n", desc->ld_tgt_count);
52 LUSTRE_RO_ATTR(numobd);
54 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
57 struct obd_device *dev = container_of(kobj, struct obd_device,
59 struct lmv_desc *desc;
61 desc = &dev->u.lmv.desc;
62 return sprintf(buf, "%u\n", desc->ld_active_tgt_count);
64 LUSTRE_RO_ATTR(activeobd);
66 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
69 struct obd_device *dev = container_of(kobj, struct obd_device,
71 struct lmv_desc *desc;
73 desc = &dev->u.lmv.desc;
74 return sprintf(buf, "%s\n", desc->ld_uuid.uuid);
76 LUSTRE_RO_ATTR(desc_uuid);
79 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
81 struct obd_device *dev = p->private;
82 struct lmv_obd *lmv = &dev->u.lmv;
84 while (*pos < lmv->tgts_size) {
86 return lmv->tgts[*pos];
93 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
97 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
99 struct obd_device *dev = p->private;
100 struct lmv_obd *lmv = &dev->u.lmv;
103 while (*pos < lmv->tgts_size) {
105 return lmv->tgts[*pos];
112 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
114 struct lmv_tgt_desc *tgt = v;
119 seq_printf(p, "%u: %s %sACTIVE\n",
120 tgt->ltd_idx, tgt->ltd_uuid.uuid,
121 tgt->ltd_active ? "" : "IN");
125 static const struct seq_operations lmv_tgt_sops = {
126 .start = lmv_tgt_seq_start,
127 .stop = lmv_tgt_seq_stop,
128 .next = lmv_tgt_seq_next,
129 .show = lmv_tgt_seq_show,
132 static int lmv_target_seq_open(struct inode *inode, struct file *file)
134 struct seq_file *seq;
137 rc = seq_open(file, &lmv_tgt_sops);
141 seq = file->private_data;
142 seq->private = PDE_DATA(inode);
146 static const struct file_operations lmv_proc_target_fops = {
147 .owner = THIS_MODULE,
148 .open = lmv_target_seq_open,
151 .release = seq_release,
153 #endif /* CONFIG_PROC_FS */
155 static struct attribute *lmv_attrs[] = {
156 &lustre_attr_activeobd.attr,
157 &lustre_attr_desc_uuid.attr,
158 &lustre_attr_numobd.attr,
162 int lmv_tunables_init(struct obd_device *obd)
166 obd->obd_ktype.default_attrs = lmv_attrs;
167 rc = lprocfs_obd_setup(obd, true);
170 #ifdef CONFIG_PROC_FS
171 rc = lprocfs_alloc_md_stats(obd, 0);
173 lprocfs_obd_cleanup(obd);
177 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
178 0444, &lmv_proc_target_fops, obd);
180 lprocfs_free_md_stats(obd);
181 lprocfs_obd_cleanup(obd);
182 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
186 #endif /* CONFIG_PROC_FS */