Whamcloud - gitweb
LU-6635 lfsck: block replacing the OST-object for test
[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, 2014, 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/version.h>
36 #include <linux/seq_file.h>
37 #include <asm/statfs.h>
38 #include <lprocfs_status.h>
39 #include <obd_class.h>
40
41 #include "lmv_internal.h"
42
43 #ifndef CONFIG_PROC_FS
44 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
45 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
46 #else
47 static int lmv_numobd_seq_show(struct seq_file *m, void *v)
48 {
49         struct obd_device       *dev = (struct obd_device *)m->private;
50         struct lmv_desc         *desc;
51
52         LASSERT(dev != NULL);
53         desc = &dev->u.lmv.desc;
54         seq_printf(m, "%u\n", desc->ld_tgt_count);
55         return 0;
56 }
57 LPROC_SEQ_FOPS_RO(lmv_numobd);
58
59 static int lmv_activeobd_seq_show(struct seq_file *m, void *v)
60 {
61         struct obd_device       *dev = (struct obd_device *)m->private;
62         struct lmv_desc         *desc;
63
64         LASSERT(dev != NULL);
65         desc = &dev->u.lmv.desc;
66         seq_printf(m, "%u\n", desc->ld_active_tgt_count);
67         return 0;
68 }
69 LPROC_SEQ_FOPS_RO(lmv_activeobd);
70
71 static int lmv_desc_uuid_seq_show(struct seq_file *m, void *v)
72 {
73         struct obd_device       *dev = (struct obd_device*)m->private;
74         struct lmv_obd          *lmv;
75
76         LASSERT(dev != NULL);
77         lmv = &dev->u.lmv;
78         seq_printf(m, "%s\n", lmv->desc.ld_uuid.uuid);
79         return 0;
80 }
81 LPROC_SEQ_FOPS_RO(lmv_desc_uuid);
82
83 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
84 {
85         struct obd_device       *dev = p->private;
86         struct lmv_obd          *lmv = &dev->u.lmv;
87
88         while (*pos < lmv->tgts_size) {
89                 if (lmv->tgts[*pos] != NULL)
90                         return lmv->tgts[*pos];
91
92                 ++*pos;
93         }
94
95         return  NULL;
96 }
97
98 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
99 {
100         return;
101 }
102
103 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
104 {
105         struct obd_device       *dev = p->private;
106         struct lmv_obd          *lmv = &dev->u.lmv;
107
108         ++*pos;
109         while (*pos < lmv->tgts_size) {
110                 if (lmv->tgts[*pos] != NULL)
111                         return lmv->tgts[*pos];
112
113                 ++*pos;
114         }
115
116         return  NULL;
117 }
118
119 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
120 {
121         struct lmv_tgt_desc     *tgt = v;
122
123         if (tgt == NULL)
124                 return 0;
125         seq_printf(p, "%u: %s %sACTIVE\n", tgt->ltd_idx,
126                   tgt->ltd_uuid.uuid, tgt->ltd_active ? "" : "IN");
127         return 0;
128 }
129
130 static const struct seq_operations lmv_tgt_sops = {
131         .start                 = lmv_tgt_seq_start,
132         .stop                  = lmv_tgt_seq_stop,
133         .next                  = lmv_tgt_seq_next,
134         .show                  = lmv_tgt_seq_show,
135 };
136
137 static int lmv_target_seq_open(struct inode *inode, struct file *file)
138 {
139         struct seq_file         *seq;
140         int                     rc;
141
142         rc = seq_open(file, &lmv_tgt_sops);
143         if (rc)
144                 return rc;
145
146         seq = file->private_data;
147         seq->private = PDE_DATA(inode);
148         return 0;
149 }
150
151 LPROC_SEQ_FOPS_RO_TYPE(lmv, uuid);
152
153 struct lprocfs_vars lprocfs_lmv_obd_vars[] = {
154         { .name =       "numobd",
155           .fops =       &lmv_numobd_fops        },
156         { .name =       "activeobd",
157           .fops =       &lmv_activeobd_fops     },
158         { .name =       "uuid",
159           .fops =       &lmv_uuid_fops          },
160         { .name =       "desc_uuid",
161           .fops =       &lmv_desc_uuid_fops     },
162         { NULL }
163 };
164
165 struct file_operations lmv_proc_target_fops = {
166         .owner                = THIS_MODULE,
167         .open                 = lmv_target_seq_open,
168         .read                 = seq_read,
169         .llseek               = seq_lseek,
170         .release              = seq_release,
171 };
172 #endif /* CONFIG_PROC_FS */