Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lustre / lmv / lproc_lmv.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see [sun.com URL with a
20  * copy of GPLv2].
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
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 #ifndef LPROCFS
46 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
47 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
48 #else
49 static int lmv_rd_numobd(char *page, char **start, off_t off, int count,
50                          int *eof, void *data)
51 {
52         struct obd_device *dev = (struct obd_device*)data;
53         struct lmv_desc *desc;
54
55         LASSERT(dev != NULL);
56         desc = &dev->u.lmv.desc;
57         *eof = 1;
58         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
59
60 }
61
62 static int lmv_rd_activeobd(char *page, char **start, off_t off, int count,
63                             int *eof, void *data)
64 {
65         struct obd_device* dev = (struct obd_device*)data;
66         struct lmv_desc *desc;
67
68         LASSERT(dev != NULL);
69         desc = &dev->u.lmv.desc;
70         *eof = 1;
71         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
72 }
73
74 static int lmv_rd_desc_uuid(char *page, char **start, off_t off, int count,
75                             int *eof, void *data)
76 {
77         struct obd_device *dev = (struct obd_device*) data;
78         struct lmv_obd *lmv;
79
80         LASSERT(dev != NULL);
81         lmv = &dev->u.lmv;
82         *eof = 1;
83         return snprintf(page, count, "%s\n", lmv->desc.ld_uuid.uuid);
84 }
85
86 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
87 {
88         struct obd_device *dev = p->private;
89         struct lmv_obd *lmv = &dev->u.lmv;
90
91         return (*pos >= lmv->desc.ld_tgt_count) ? NULL : &(lmv->tgts[*pos]);
92
93 }
94
95 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
96 {
97         return;
98 }
99
100 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
101 {
102         struct obd_device *dev = p->private;
103         struct lmv_obd *lmv = &dev->u.lmv;
104
105         ++*pos;
106         return (*pos >=lmv->desc.ld_tgt_count) ? NULL : &(lmv->tgts[*pos]);
107 }
108
109 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
110 {
111         struct lmv_tgt_desc *tgt = v;
112         struct obd_device *dev = p->private;
113         struct lmv_obd *lmv = &dev->u.lmv;
114         int idx = tgt - &(lmv->tgts[0]);
115         
116         return seq_printf(p, "%d: %s %sACTIVE\n", idx, tgt->ltd_uuid.uuid,
117                           tgt->ltd_active ? "" : "IN");
118 }
119
120 struct seq_operations lmv_tgt_sops = {
121         .start = lmv_tgt_seq_start,
122         .stop = lmv_tgt_seq_stop,
123         .next = lmv_tgt_seq_next,
124         .show = lmv_tgt_seq_show,
125 };
126
127 static int lmv_target_seq_open(struct inode *inode, struct file *file)
128 {
129         struct proc_dir_entry *dp = PDE(inode);
130         struct seq_file *seq;
131         int rc = seq_open(file, &lmv_tgt_sops);
132
133         if (rc)
134                 return rc;
135
136         seq = file->private_data;
137         seq->private = dp->data;
138
139         return 0;
140 }
141
142 struct lprocfs_vars lprocfs_lmv_obd_vars[] = {
143         { "numobd",       lmv_rd_numobd,          0, 0 },
144         { "activeobd",    lmv_rd_activeobd,       0, 0 },
145         { "uuid",         lprocfs_rd_uuid,        0, 0 },
146         { "desc_uuid",    lmv_rd_desc_uuid,       0, 0 },
147         { 0 }
148 };
149
150 static struct lprocfs_vars lprocfs_lmv_module_vars[] = {
151         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
152         { 0 }
153 };
154
155 struct file_operations lmv_proc_target_fops = {
156         .owner   = THIS_MODULE,
157         .open    = lmv_target_seq_open,
158         .read    = seq_read,
159         .llseek  = seq_lseek,
160         .release = seq_release,
161 };
162
163 #endif /* LPROCFS */
164 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
165 {
166     lvars->module_vars  = lprocfs_lmv_module_vars;
167     lvars->obd_vars     = lprocfs_lmv_obd_vars;
168 }