Whamcloud - gitweb
95fe927d839a0fa56e49d12d4f34f5f4d099dc38
[fs/lustre-release.git] / lustre / lmv / lproc_lmv.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32
33 #define DEBUG_SUBSYSTEM S_CLASS
34
35 #include <linux/seq_file.h>
36 #include <linux/statfs.h>
37 #include <lprocfs_status.h>
38 #include <obd_class.h>
39
40 #include "lmv_internal.h"
41
42 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
43                            char *buf)
44 {
45         struct obd_device *dev = container_of(kobj, struct obd_device,
46                                               obd_kset.kobj);
47         struct lmv_desc *desc;
48
49         desc = &dev->u.lmv.desc;
50         return sprintf(buf, "%u\n", desc->ld_tgt_count);
51 }
52 LUSTRE_RO_ATTR(numobd);
53
54 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
55                               char *buf)
56 {
57         struct obd_device *dev = container_of(kobj, struct obd_device,
58                                               obd_kset.kobj);
59         struct lmv_desc *desc;
60
61         desc = &dev->u.lmv.desc;
62         return sprintf(buf, "%u\n", desc->ld_active_tgt_count);
63 }
64 LUSTRE_RO_ATTR(activeobd);
65
66 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
67                               char *buf)
68 {
69         struct obd_device *dev = container_of(kobj, struct obd_device,
70                                               obd_kset.kobj);
71         struct lmv_desc *desc;
72
73         desc = &dev->u.lmv.desc;
74         return sprintf(buf, "%s\n", desc->ld_uuid.uuid);
75 }
76 LUSTRE_RO_ATTR(desc_uuid);
77
78 #ifdef CONFIG_PROC_FS
79 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
80 {
81         struct obd_device       *dev = p->private;
82         struct lmv_obd          *lmv = &dev->u.lmv;
83
84         while (*pos < lmv->tgts_size) {
85                 if (lmv->tgts[*pos])
86                         return lmv->tgts[*pos];
87                 ++*pos;
88         }
89
90         return  NULL;
91 }
92
93 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
94 {
95 }
96
97 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
98 {
99         struct obd_device       *dev = p->private;
100         struct lmv_obd          *lmv = &dev->u.lmv;
101
102         ++*pos;
103         while (*pos < lmv->tgts_size) {
104                 if (lmv->tgts[*pos])
105                         return lmv->tgts[*pos];
106                 ++*pos;
107         }
108
109         return  NULL;
110 }
111
112 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
113 {
114         struct lmv_tgt_desc     *tgt = v;
115
116         if (!tgt)
117                 return 0;
118
119         seq_printf(p, "%u: %s %sACTIVE\n",
120                    tgt->ltd_idx, tgt->ltd_uuid.uuid,
121                    tgt->ltd_active ? "" : "IN");
122         return 0;
123 }
124
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,
130 };
131
132 static int lmv_target_seq_open(struct inode *inode, struct file *file)
133 {
134         struct seq_file         *seq;
135         int                     rc;
136
137         rc = seq_open(file, &lmv_tgt_sops);
138         if (rc)
139                 return rc;
140
141         seq = file->private_data;
142         seq->private = PDE_DATA(inode);
143         return 0;
144 }
145
146 static const struct file_operations lmv_proc_target_fops = {
147         .owner                = THIS_MODULE,
148         .open                 = lmv_target_seq_open,
149         .read                 = seq_read,
150         .llseek               = seq_lseek,
151         .release              = seq_release,
152 };
153 #endif /* CONFIG_PROC_FS */
154
155 static struct attribute *lmv_attrs[] = {
156         &lustre_attr_activeobd.attr,
157         &lustre_attr_desc_uuid.attr,
158         &lustre_attr_numobd.attr,
159         NULL,
160 };
161
162 int lmv_tunables_init(struct obd_device *obd)
163 {
164         int rc;
165
166         obd->obd_ktype.default_attrs = lmv_attrs;
167         rc = lprocfs_obd_setup(obd, true);
168         if (rc)
169                 goto out_failed;
170 #ifdef CONFIG_PROC_FS
171         rc = lprocfs_alloc_md_stats(obd, 0);
172         if (rc) {
173                 lprocfs_obd_cleanup(obd);
174                 goto out_failed;
175         }
176
177         rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
178                                 0444, &lmv_proc_target_fops, obd);
179         if (rc) {
180                 lprocfs_free_md_stats(obd);
181                 lprocfs_obd_cleanup(obd);
182                 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
183                       obd->obd_name, rc);
184                 rc = 0;
185         }
186 #endif /* CONFIG_PROC_FS */
187 out_failed:
188         return rc;
189 }