Whamcloud - gitweb
* Compiles after merging b1_4
[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 #ifdef LPROCFS
33 static int lov_rd_stripesize(char *page, char **start, off_t off, int count,
34                              int *eof, void *data)
35 {
36         struct obd_device *dev = (struct obd_device *)data;
37         struct lov_desc *desc;
38
39         LASSERT(dev != NULL);
40         desc = &dev->u.lov.desc;
41         *eof = 1;
42         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
43 }
44
45 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
46                                int *eof, void *data)
47 {
48         struct obd_device *dev = (struct obd_device *)data;
49         struct lov_desc *desc;
50
51         LASSERT(dev != NULL);
52         desc = &dev->u.lov.desc;
53         *eof = 1;
54         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
55 }
56
57 static int lov_rd_stripetype(char *page, char **start, off_t off, int count,
58                              int *eof, void *data)
59 {
60         struct obd_device* dev = (struct obd_device*)data;
61         struct lov_desc *desc;
62
63         LASSERT(dev != NULL);
64         desc = &dev->u.lov.desc;
65         *eof = 1;
66         return snprintf(page, count, "%u\n", desc->ld_pattern);
67 }
68
69 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
70                               int *eof, void *data)
71 {
72         struct obd_device *dev = (struct obd_device *)data;
73         struct lov_desc *desc;
74
75         LASSERT(dev != NULL);
76         desc = &dev->u.lov.desc;
77         *eof = 1;
78         return snprintf(page, count, "%u\n", desc->ld_default_stripe_count);
79 }
80
81 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
82                          int *eof, void *data)
83 {
84         struct obd_device *dev = (struct obd_device*)data;
85         struct lov_desc *desc;
86
87         LASSERT(dev != NULL);
88         desc = &dev->u.lov.desc;
89         *eof = 1;
90         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
91
92 }
93
94 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
95                             int *eof, void *data)
96 {
97         struct obd_device* dev = (struct obd_device*)data;
98         struct lov_desc *desc;
99
100         LASSERT(dev != NULL);
101         desc = &dev->u.lov.desc;
102         *eof = 1;
103         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
104 }
105
106 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
107                             int *eof, void *data)
108 {
109         struct obd_device *dev = (struct obd_device*) data;
110         struct lov_obd *lov;
111
112         LASSERT(dev != NULL);
113         lov = &dev->u.lov;
114         *eof = 1;
115         return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
116 }
117
118 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
119 {
120         struct obd_device *dev = p->private;
121         struct lov_obd *lov = &dev->u.lov;
122
123         return (*pos >= lov->desc.ld_tgt_count) ? NULL : &(lov->tgts[*pos]);
124
125 }
126
127 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
128 {
129 }
130
131 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
132 {
133         struct obd_device *dev = p->private;
134         struct lov_obd *lov = &dev->u.lov;
135
136         ++*pos;
137         return (*pos >=lov->desc.ld_tgt_count) ? NULL : &(lov->tgts[*pos]);
138 }
139
140 static int lov_tgt_seq_show(struct seq_file *p, void *v)
141 {
142         struct lov_tgt_desc *tgt = v;
143         struct obd_device *dev = p->private;
144         struct lov_obd *lov = &dev->u.lov;
145         int idx = tgt - &(lov->tgts[0]);
146         return seq_printf(p, "%d: %s %sACTIVE\n", idx, tgt->uuid.uuid,
147                           tgt->active ? "" : "IN");
148 }
149
150 struct seq_operations lov_tgt_sops = {
151         .start = lov_tgt_seq_start,
152         .stop = lov_tgt_seq_stop,
153         .next = lov_tgt_seq_next,
154         .show = lov_tgt_seq_show,
155 };
156
157 static int lov_target_seq_open(struct inode *inode, struct file *file)
158 {
159         struct proc_dir_entry *dp = PDE(inode);
160         struct seq_file *seq;
161         int rc = seq_open(file, &lov_tgt_sops);
162
163         if (rc)
164                 return rc;
165
166         seq = file->private_data;
167         seq->private = dp->data;
168
169         return 0;
170 }
171
172 struct lprocfs_vars lprocfs_obd_vars[] = {
173         { "uuid",         lprocfs_rd_uuid,        0, 0 },
174         { "stripesize",   lov_rd_stripesize,      0, 0 },
175         { "stripeoffset", lov_rd_stripeoffset,    0, 0 },
176         { "stripecount",  lov_rd_stripecount,     0, 0 },
177         { "stripetype",   lov_rd_stripetype,      0, 0 },
178         { "numobd",       lov_rd_numobd,          0, 0 },
179         { "activeobd",    lov_rd_activeobd,       0, 0 },
180         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
181         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
182         //{ "filegroups",   lprocfs_rd_filegroups,  0, 0 },
183         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
184         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
185         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
186         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
187         { "desc_uuid",    lov_rd_desc_uuid,       0, 0 },
188         { 0 }
189 };
190
191 static struct lprocfs_vars lprocfs_module_vars[] = {
192         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
193         { 0 }
194 };
195
196 struct file_operations lov_proc_target_fops = {
197         .owner   = THIS_MODULE,
198         .open    = lov_target_seq_open,
199         .read    = seq_read,
200         .llseek  = seq_lseek,
201         .release = seq_release,
202 };
203
204 LPROCFS_INIT_VARS(lov, lprocfs_module_vars, lprocfs_obd_vars)
205 #endif /* LPROCFS */