GNU Linux-libre 4.14.251-gnu1
[releases.git] / drivers / staging / lustre / 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, 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 #include "lmv_internal.h"
40
41 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
42                            char *buf)
43 {
44         struct obd_device *dev = container_of(kobj, struct obd_device,
45                                               obd_kobj);
46         struct lmv_desc *desc;
47
48         desc = &dev->u.lmv.desc;
49         return sprintf(buf, "%u\n", desc->ld_tgt_count);
50 }
51 LUSTRE_RO_ATTR(numobd);
52
53 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
54                               char *buf)
55 {
56         struct obd_device *dev = container_of(kobj, struct obd_device,
57                                               obd_kobj);
58         struct lmv_desc *desc;
59
60         desc = &dev->u.lmv.desc;
61         return sprintf(buf, "%u\n", desc->ld_active_tgt_count);
62 }
63 LUSTRE_RO_ATTR(activeobd);
64
65 static int lmv_desc_uuid_seq_show(struct seq_file *m, void *v)
66 {
67         struct obd_device *dev = (struct obd_device *)m->private;
68         struct lmv_obd    *lmv;
69
70         LASSERT(dev);
71         lmv = &dev->u.lmv;
72         seq_printf(m, "%s\n", lmv->desc.ld_uuid.uuid);
73         return 0;
74 }
75
76 LPROC_SEQ_FOPS_RO(lmv_desc_uuid);
77
78 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
79 {
80         struct obd_device       *dev = p->private;
81         struct lmv_obd    *lmv = &dev->u.lmv;
82
83         while (*pos < lmv->tgts_size) {
84                 if (lmv->tgts[*pos])
85                         return lmv->tgts[*pos];
86                 ++*pos;
87         }
88
89         return  NULL;
90 }
91
92 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
93 {
94 }
95
96 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
97 {
98         struct obd_device       *dev = p->private;
99         struct lmv_obd    *lmv = &dev->u.lmv;
100
101         ++*pos;
102         while (*pos < lmv->tgts_size) {
103                 if (lmv->tgts[*pos])
104                         return lmv->tgts[*pos];
105                 ++*pos;
106         }
107
108         return  NULL;
109 }
110
111 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
112 {
113         struct lmv_tgt_desc     *tgt = v;
114
115         if (!tgt)
116                 return 0;
117         seq_printf(p, "%u: %s %sACTIVE\n",
118                    tgt->ltd_idx, tgt->ltd_uuid.uuid,
119                    tgt->ltd_active ? "" : "IN");
120         return 0;
121 }
122
123 static const struct seq_operations lmv_tgt_sops = {
124         .start           = lmv_tgt_seq_start,
125         .stop             = lmv_tgt_seq_stop,
126         .next             = lmv_tgt_seq_next,
127         .show             = lmv_tgt_seq_show,
128 };
129
130 static int lmv_target_seq_open(struct inode *inode, struct file *file)
131 {
132         struct seq_file  *seq;
133         int                  rc;
134
135         rc = seq_open(file, &lmv_tgt_sops);
136         if (rc)
137                 return rc;
138
139         seq = file->private_data;
140         seq->private = inode->i_private;
141
142         return 0;
143 }
144
145 static struct lprocfs_vars lprocfs_lmv_obd_vars[] = {
146         { "desc_uuid",    &lmv_desc_uuid_fops,    NULL, 0 },
147         { NULL }
148 };
149
150 const struct file_operations lmv_proc_target_fops = {
151         .owner          = THIS_MODULE,
152         .open            = lmv_target_seq_open,
153         .read            = seq_read,
154         .llseek        = seq_lseek,
155         .release              = seq_release,
156 };
157
158 static struct attribute *lmv_attrs[] = {
159         &lustre_attr_activeobd.attr,
160         &lustre_attr_numobd.attr,
161         NULL,
162 };
163
164 static const struct attribute_group lmv_attr_group = {
165         .attrs = lmv_attrs,
166 };
167
168 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
169 {
170         lvars->sysfs_vars     = &lmv_attr_group;
171         lvars->obd_vars       = lprocfs_lmv_obd_vars;
172 }