Whamcloud - gitweb
- make HEAD from b_post_cmd3
[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  * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #define DEBUG_SUBSYSTEM S_CLASS
23
24 #include <linux/version.h>
25 #include <linux/seq_file.h>
26 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
27 #include <asm/statfs.h>
28 #endif
29 #include <lprocfs_status.h>
30 #include <obd_class.h>
31
32 #ifndef LPROCFS
33 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
34 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
35 #else
36 static int lmv_rd_numobd(char *page, char **start, off_t off, int count,
37                          int *eof, void *data)
38 {
39         struct obd_device *dev = (struct obd_device*)data;
40         struct lmv_desc *desc;
41
42         LASSERT(dev != NULL);
43         desc = &dev->u.lmv.desc;
44         *eof = 1;
45         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
46
47 }
48
49 static int lmv_rd_activeobd(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_active_tgt_count);
59 }
60
61 static int lmv_rd_desc_uuid(char *page, char **start, off_t off, int count,
62                             int *eof, void *data)
63 {
64         struct obd_device *dev = (struct obd_device*) data;
65         struct lmv_obd *lmv;
66
67         LASSERT(dev != NULL);
68         lmv = &dev->u.lmv;
69         *eof = 1;
70         return snprintf(page, count, "%s\n", lmv->desc.ld_uuid.uuid);
71 }
72
73 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
74 {
75         struct obd_device *dev = p->private;
76         struct lmv_obd *lmv = &dev->u.lmv;
77
78         return (*pos >= lmv->desc.ld_tgt_count) ? NULL : &(lmv->tgts[*pos]);
79
80 }
81
82 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
83 {
84         return;
85 }
86
87 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
88 {
89         struct obd_device *dev = p->private;
90         struct lmv_obd *lmv = &dev->u.lmv;
91
92         ++*pos;
93         return (*pos >=lmv->desc.ld_tgt_count) ? NULL : &(lmv->tgts[*pos]);
94 }
95
96 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
97 {
98         struct lmv_tgt_desc *tgt = v;
99         struct obd_device *dev = p->private;
100         struct lmv_obd *lmv = &dev->u.lmv;
101         int idx = tgt - &(lmv->tgts[0]);
102         
103         return seq_printf(p, "%d: %s %sACTIVE\n", idx, tgt->ltd_uuid.uuid,
104                           tgt->ltd_active ? "" : "IN");
105 }
106
107 struct seq_operations lmv_tgt_sops = {
108         .start = lmv_tgt_seq_start,
109         .stop = lmv_tgt_seq_stop,
110         .next = lmv_tgt_seq_next,
111         .show = lmv_tgt_seq_show,
112 };
113
114 static int lmv_target_seq_open(struct inode *inode, struct file *file)
115 {
116         struct proc_dir_entry *dp = PDE(inode);
117         struct seq_file *seq;
118         int rc = seq_open(file, &lmv_tgt_sops);
119
120         if (rc)
121                 return rc;
122
123         seq = file->private_data;
124         seq->private = dp->data;
125
126         return 0;
127 }
128
129 struct lprocfs_vars lprocfs_obd_vars[] = {
130         { "numobd",       lmv_rd_numobd,          0, 0 },
131         { "activeobd",    lmv_rd_activeobd,       0, 0 },
132         { "uuid",         lprocfs_rd_uuid,        0, 0 },
133         { "desc_uuid",    lmv_rd_desc_uuid,       0, 0 },
134         { 0 }
135 };
136
137 static struct lprocfs_vars lprocfs_module_vars[] = {
138         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
139         { 0 }
140 };
141
142 struct file_operations lmv_proc_target_fops = {
143         .owner   = THIS_MODULE,
144         .open    = lmv_target_seq_open,
145         .read    = seq_read,
146         .llseek  = seq_lseek,
147         .release = seq_release,
148 };
149
150 #endif /* LPROCFS */
151 LPROCFS_INIT_VARS(lmv, lprocfs_module_vars, lprocfs_obd_vars)