Whamcloud - gitweb
merge b_devel into HEAD (20030626 merge tag) for 0.7.1
[fs/lustre-release.git] / lustre / lov / lproc_lov.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 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 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 #include <asm/statfs.h>
27 #endif
28 #include <linux/lprocfs_status.h>
29 #include <linux/obd_class.h>
30 #include <linux/seq_file.h>
31
32 #ifndef LPROCFS
33 struct lprocfs_vars lprocfs_module_vars[] = { {0} };
34 struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
35 #else
36
37 DEFINE_LPROCFS_STATFS_FCT(rd_blksize,     obd_self_statfs);
38 DEFINE_LPROCFS_STATFS_FCT(rd_kbytestotal, obd_self_statfs);
39 DEFINE_LPROCFS_STATFS_FCT(rd_kbytesfree,  obd_self_statfs);
40 DEFINE_LPROCFS_STATFS_FCT(rd_filestotal,  obd_self_statfs);
41 DEFINE_LPROCFS_STATFS_FCT(rd_filesfree,   obd_self_statfs);
42 DEFINE_LPROCFS_STATFS_FCT(rd_filegroups,  obd_self_statfs);
43
44 int rd_stripesize(char *page, char **start, off_t off, int count, int *eof,
45                   void *data)
46 {
47         struct obd_device *dev = (struct obd_device *)data;
48         struct lov_desc *desc;
49
50         LASSERT(dev != NULL);
51         desc = &dev->u.lov.desc;
52         *eof = 1;
53         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
54 }
55
56 int rd_stripeoffset(char *page, char **start, off_t off, int count, int *eof,
57                     void *data)
58 {
59         struct obd_device *dev = (struct obd_device *)data;
60         struct lov_desc *desc;
61
62         LASSERT(dev != NULL);
63         desc = &dev->u.lov.desc;
64         *eof = 1;
65         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
66 }
67
68 int rd_stripetype(char *page, char **start, off_t off, int count, int *eof,
69                   void *data)
70 {
71         struct obd_device* dev = (struct obd_device*)data;
72         struct lov_desc *desc;
73
74         LASSERT(dev != NULL);
75         desc = &dev->u.lov.desc;
76         *eof = 1;
77         return snprintf(page, count, "%u\n", desc->ld_pattern);
78 }
79
80 int rd_stripecount(char *page, char **start, off_t off, int count, int *eof,
81                    void *data)
82 {
83         struct obd_device *dev = (struct obd_device *)data;
84         struct lov_desc *desc;
85
86         LASSERT(dev != NULL);
87         desc = &dev->u.lov.desc;
88         *eof = 1;
89         return snprintf(page, count, "%u\n", desc->ld_default_stripe_count);
90 }
91
92 int rd_numobd(char *page, char **start, off_t off, int count, int *eof,
93               void *data)
94 {
95         struct obd_device *dev = (struct obd_device*)data;
96         struct lov_desc *desc;
97
98         LASSERT(dev != NULL);
99         desc = &dev->u.lov.desc;
100         *eof = 1;
101         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
102
103 }
104
105 int rd_activeobd(char *page, char **start, off_t off, int count, int *eof,
106                  void *data)
107 {
108         struct obd_device* dev = (struct obd_device*)data;
109         struct lov_desc *desc;
110
111         LASSERT(dev != NULL);
112         desc = &dev->u.lov.desc;
113         *eof = 1;
114         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
115 }
116
117 int rd_mdc(char *page, char **start, off_t off, int count, int *eof, void *data)
118 {
119         struct obd_device *dev = (struct obd_device*) data;
120         struct lov_obd *lov;
121
122         LASSERT(dev != NULL);
123         lov = &dev->u.lov;
124         *eof = 1;
125         return snprintf(page, count, "%s\n", lov->mdcobd->obd_uuid.uuid);
126 }
127
128 static void *ll_tgt_seq_start(struct seq_file *p, loff_t *pos)
129 {
130         struct obd_device *dev = p->private;
131         struct lov_obd *lov = &dev->u.lov;
132
133         return (*pos >= lov->desc.ld_tgt_count) ? NULL : &(lov->tgts[*pos]);
134
135 }
136 static void ll_tgt_seq_stop(struct seq_file *p, void *v)
137 {
138
139 }
140
141 static void *ll_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
142 {
143         struct obd_device *dev = p->private;
144         struct lov_obd *lov = &dev->u.lov;
145
146         ++*pos;
147         return (*pos >=lov->desc.ld_tgt_count) ? NULL : &(lov->tgts[*pos]);
148 }
149
150 static int ll_tgt_seq_show(struct seq_file *p, void *v)
151 {
152         struct lov_tgt_desc *tgt = v;
153         struct obd_device *dev = p->private;
154         struct lov_obd *lov = &dev->u.lov;
155         int idx = tgt - &(lov->tgts[0]);
156         return seq_printf(p, "%d: %s %sACTIVE\n", idx+1, tgt->uuid.uuid,
157                           tgt->active ? "" : "IN");
158 }
159
160 struct seq_operations ll_tgt_sops = {
161         .start = ll_tgt_seq_start,
162         .stop = ll_tgt_seq_stop,
163         .next = ll_tgt_seq_next,
164         .show = ll_tgt_seq_show,
165 };
166
167 static int ll_target_seq_open(struct inode *inode, struct file *file)
168 {
169         struct proc_dir_entry *dp = inode->u.generic_ip;
170         struct seq_file *seq;
171         int rc = seq_open(file, &ll_tgt_sops);
172
173         if (rc)
174                 return rc;
175
176         seq = file->private_data;
177         seq->private = dp->data;
178
179         return 0;
180 }
181 struct lprocfs_vars lprocfs_obd_vars[] = {
182         { "uuid",         lprocfs_rd_uuid, 0, 0 },
183         { "stripesize",   rd_stripesize,   0, 0 },
184         { "stripeoffset", rd_stripeoffset, 0, 0 },
185         { "stripecount",  rd_stripecount,  0, 0 },
186         { "stripetype",   rd_stripetype,   0, 0 },
187         { "numobd",       rd_numobd,       0, 0 },
188         { "activeobd",    rd_activeobd,    0, 0 },
189         { "filestotal",   rd_filestotal,   0, 0 },
190         { "filesfree",    rd_filesfree,    0, 0 },
191         { "filegroups",   rd_filegroups,   0, 0 },
192         { "blocksize",    rd_blksize,      0, 0 },
193         { "kbytestotal",  rd_kbytestotal,  0, 0 },
194         { "kbytesfree",   rd_kbytesfree,   0, 0 },
195         { "target_mdc",   rd_mdc,          0, 0 },
196         { 0 }
197 };
198
199 struct lprocfs_vars lprocfs_module_vars[] = {
200         { "num_refs",     lprocfs_rd_numrefs, 0, 0 },
201         { 0 }
202 };
203
204 struct file_operations ll_proc_target_fops = {
205         .open = ll_target_seq_open,
206         .read = seq_read,
207         .llseek = seq_lseek,
208         .release = seq_release,
209 };
210
211 #endif /* LPROCFS */
212 LPROCFS_INIT_VARS(lprocfs_module_vars, lprocfs_obd_vars)