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