Whamcloud - gitweb
b2c407062d74e4d84b80e8c8384b9bbcc2856464
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2014, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #define DEBUG_SUBSYSTEM S_CLASS
38
39 #include <linux/version.h>
40 #include <linux/seq_file.h>
41 #include <asm/statfs.h>
42 #include <lprocfs_status.h>
43 #include <obd_class.h>
44
45 #include "lmv_internal.h"
46
47 #ifndef CONFIG_PROC_FS
48 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
49 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
50 #else
51 static int lmv_numobd_seq_show(struct seq_file *m, void *v)
52 {
53         struct obd_device       *dev = (struct obd_device *)m->private;
54         struct lmv_desc         *desc;
55
56         LASSERT(dev != NULL);
57         desc = &dev->u.lmv.desc;
58         seq_printf(m, "%u\n", desc->ld_tgt_count);
59         return 0;
60 }
61 LPROC_SEQ_FOPS_RO(lmv_numobd);
62
63 static int lmv_activeobd_seq_show(struct seq_file *m, void *v)
64 {
65         struct obd_device       *dev = (struct obd_device *)m->private;
66         struct lmv_desc         *desc;
67
68         LASSERT(dev != NULL);
69         desc = &dev->u.lmv.desc;
70         seq_printf(m, "%u\n", desc->ld_active_tgt_count);
71         return 0;
72 }
73 LPROC_SEQ_FOPS_RO(lmv_activeobd);
74
75 static int lmv_desc_uuid_seq_show(struct seq_file *m, void *v)
76 {
77         struct obd_device       *dev = (struct obd_device*)m->private;
78         struct lmv_obd          *lmv;
79
80         LASSERT(dev != NULL);
81         lmv = &dev->u.lmv;
82         seq_printf(m, "%s\n", lmv->desc.ld_uuid.uuid);
83         return 0;
84 }
85 LPROC_SEQ_FOPS_RO(lmv_desc_uuid);
86
87 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
88 {
89         struct obd_device       *dev = p->private;
90         struct lmv_obd          *lmv = &dev->u.lmv;
91
92         while (*pos < lmv->tgts_size) {
93                 if (lmv->tgts[*pos] != NULL)
94                         return lmv->tgts[*pos];
95
96                 ++*pos;
97         }
98
99         return  NULL;
100 }
101
102 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
103 {
104         return;
105 }
106
107 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
108 {
109         struct obd_device       *dev = p->private;
110         struct lmv_obd          *lmv = &dev->u.lmv;
111
112         ++*pos;
113         while (*pos < lmv->tgts_size) {
114                 if (lmv->tgts[*pos] != NULL)
115                         return lmv->tgts[*pos];
116
117                 ++*pos;
118         }
119
120         return  NULL;
121 }
122
123 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
124 {
125         struct lmv_tgt_desc     *tgt = v;
126
127         if (tgt == NULL)
128                 return 0;
129         seq_printf(p, "%u: %s %sACTIVE\n", tgt->ltd_idx,
130                   tgt->ltd_uuid.uuid, tgt->ltd_active ? "" : "IN");
131         return 0;
132 }
133
134 static const struct seq_operations lmv_tgt_sops = {
135         .start                 = lmv_tgt_seq_start,
136         .stop                  = lmv_tgt_seq_stop,
137         .next                  = lmv_tgt_seq_next,
138         .show                  = lmv_tgt_seq_show,
139 };
140
141 static int lmv_target_seq_open(struct inode *inode, struct file *file)
142 {
143         struct seq_file         *seq;
144         int                     rc;
145
146         rc = seq_open(file, &lmv_tgt_sops);
147         if (rc)
148                 return rc;
149
150         seq = file->private_data;
151         seq->private = PDE_DATA(inode);
152         return 0;
153 }
154
155 LPROC_SEQ_FOPS_RO_TYPE(lmv, uuid);
156
157 struct lprocfs_vars lprocfs_lmv_obd_vars[] = {
158         { .name =       "numobd",
159           .fops =       &lmv_numobd_fops        },
160         { .name =       "activeobd",
161           .fops =       &lmv_activeobd_fops     },
162         { .name =       "uuid",
163           .fops =       &lmv_uuid_fops          },
164         { .name =       "desc_uuid",
165           .fops =       &lmv_desc_uuid_fops     },
166         { NULL }
167 };
168
169 struct file_operations lmv_proc_target_fops = {
170         .owner                = THIS_MODULE,
171         .open                 = lmv_target_seq_open,
172         .read                 = seq_read,
173         .llseek               = seq_lseek,
174         .release              = seq_release,
175 };
176 #endif /* CONFIG_PROC_FS */