Whamcloud - gitweb
- update from b1_4_mountconf
[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 the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
9  *   You may have signed or agreed to another license before downloading
10  *   this software.  If so, you are bound by the terms and conditions
11  *   of that agreement, and the following does not apply to you.  See the
12  *   LICENSE file included with this distribution for more information.
13  *
14  *   If you did not agree to a different license, then this copy of Lustre
15  *   is open source software; you can redistribute it and/or modify it
16  *   under the terms of version 2 of the GNU General Public License as
17  *   published by the Free Software Foundation.
18  *
19  *   In either case, Lustre is distributed in the hope that it will be
20  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   license text for more details.
23  *
24  */
25 #define DEBUG_SUBSYSTEM S_CLASS
26
27 #include <linux/version.h>
28 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
29 #include <asm/statfs.h>
30 #endif
31 #include <lprocfs_status.h>
32 #include <obd_class.h>
33 #include <linux/seq_file.h>
34
35 #ifdef LPROCFS
36 static int lov_rd_stripesize(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 lov_desc *desc;
41
42         LASSERT(dev != NULL);
43         desc = &dev->u.lov.desc;
44         *eof = 1;
45         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
46 }
47
48 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
49                                int *eof, void *data)
50 {
51         struct obd_device *dev = (struct obd_device *)data;
52         struct lov_desc *desc;
53
54         LASSERT(dev != NULL);
55         desc = &dev->u.lov.desc;
56         *eof = 1;
57         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
58 }
59
60 static int lov_rd_stripetype(char *page, char **start, off_t off, int count,
61                              int *eof, void *data)
62 {
63         struct obd_device* dev = (struct obd_device*)data;
64         struct lov_desc *desc;
65
66         LASSERT(dev != NULL);
67         desc = &dev->u.lov.desc;
68         *eof = 1;
69         return snprintf(page, count, "%u\n", desc->ld_pattern);
70 }
71
72 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
73                               int *eof, void *data)
74 {
75         struct obd_device *dev = (struct obd_device *)data;
76         struct lov_desc *desc;
77
78         LASSERT(dev != NULL);
79         desc = &dev->u.lov.desc;
80         *eof = 1;
81         return snprintf(page, count, "%u\n", desc->ld_default_stripe_count);
82 }
83
84 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
85                          int *eof, void *data)
86 {
87         struct obd_device *dev = (struct obd_device*)data;
88         struct lov_desc *desc;
89
90         LASSERT(dev != NULL);
91         desc = &dev->u.lov.desc;
92         *eof = 1;
93         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
94
95 }
96
97 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
98                             int *eof, void *data)
99 {
100         struct obd_device* dev = (struct obd_device*)data;
101         struct lov_desc *desc;
102
103         LASSERT(dev != NULL);
104         desc = &dev->u.lov.desc;
105         *eof = 1;
106         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
107 }
108
109 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
110                             int *eof, void *data)
111 {
112         struct obd_device *dev = (struct obd_device*) data;
113         struct lov_obd *lov;
114
115         LASSERT(dev != NULL);
116         lov = &dev->u.lov;
117         *eof = 1;
118         return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
119 }
120
121 static int lov_rd_qos_threshold(char *page, char **start, off_t off, int count,
122                                 int *eof, void *data)
123 {
124         struct obd_device *dev = (struct obd_device*) data;
125         struct lov_obd *lov;
126
127         LASSERT(dev != NULL);
128         lov = &dev->u.lov;
129         *eof = 1;
130         return snprintf(page, count, "%u MB\n", lov->desc.ld_qos_threshold);
131 }
132
133 static int lov_wr_qos_threshold(struct file *file, const char *buffer,
134                                 unsigned long count, void *data)
135 {
136         struct obd_device *dev = (struct obd_device *)data;
137         struct lov_obd *lov;
138         int val, rc;
139         LASSERT(dev != NULL);
140
141         lov = &dev->u.lov;
142         rc = lprocfs_write_helper(buffer, count, &val);
143         if (rc)
144                 return rc;
145
146         if (val <= 0)
147                 return -EINVAL;
148         lov->desc.ld_qos_threshold = val;
149         return count;
150 }
151
152 static int lov_rd_qos_maxage(char *page, char **start, off_t off, int count,
153                              int *eof, void *data)
154 {
155         struct obd_device *dev = (struct obd_device*) data;
156         struct lov_obd *lov;
157
158         LASSERT(dev != NULL);
159         lov = &dev->u.lov;
160         *eof = 1;
161         return snprintf(page, count, "%u Sec\n", lov->desc.ld_qos_maxage);
162 }
163
164 static int lov_wr_qos_maxage(struct file *file, const char *buffer,
165                              unsigned long count, void *data)
166 {
167         struct obd_device *dev = (struct obd_device *)data;
168         struct lov_obd *lov;
169         int val, rc;
170         LASSERT(dev != NULL);
171
172         lov = &dev->u.lov;
173         rc = lprocfs_write_helper(buffer, count, &val);
174         if (rc)
175                 return rc;
176
177         if (val <= 0)
178                 return -EINVAL;
179         lov->desc.ld_qos_maxage = val;
180         return count;
181 }
182
183 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
184 {
185         struct obd_device *dev = p->private;
186         struct lov_obd *lov = &dev->u.lov;
187
188         return (*pos >= lov->desc.ld_tgt_count) ? NULL : &(lov->tgts[*pos]);
189
190 }
191
192 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
193 {
194 }
195
196 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
197 {
198         struct obd_device *dev = p->private;
199         struct lov_obd *lov = &dev->u.lov;
200
201         ++*pos;
202         return (*pos >=lov->desc.ld_tgt_count) ? NULL : &(lov->tgts[*pos]);
203 }
204
205 static int lov_tgt_seq_show(struct seq_file *p, void *v)
206 {
207         struct lov_tgt_desc *tgt = v;
208         struct obd_device *dev = p->private;
209         struct lov_obd *lov = &dev->u.lov;
210         int idx = tgt - &(lov->tgts[0]);
211         return seq_printf(p, "%d: %s %sACTIVE\n", idx, tgt->uuid.uuid,
212                           tgt->active ? "" : "IN");
213 }
214
215 struct seq_operations lov_tgt_sops = {
216         .start = lov_tgt_seq_start,
217         .stop = lov_tgt_seq_stop,
218         .next = lov_tgt_seq_next,
219         .show = lov_tgt_seq_show,
220 };
221
222 static int lov_target_seq_open(struct inode *inode, struct file *file)
223 {
224         struct proc_dir_entry *dp = PDE(inode);
225         struct seq_file *seq;
226         int rc = seq_open(file, &lov_tgt_sops);
227
228         if (rc)
229                 return rc;
230
231         seq = file->private_data;
232         seq->private = dp->data;
233
234         return 0;
235 }
236
237 struct lprocfs_vars lprocfs_obd_vars[] = {
238         { "uuid",         lprocfs_rd_uuid,        0, 0 },
239         { "stripesize",   lov_rd_stripesize,      0, 0 },
240         { "stripeoffset", lov_rd_stripeoffset,    0, 0 },
241         { "stripecount",  lov_rd_stripecount,     0, 0 },
242         { "stripetype",   lov_rd_stripetype,      0, 0 },
243         { "numobd",       lov_rd_numobd,          0, 0 },
244         { "activeobd",    lov_rd_activeobd,       0, 0 },
245         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
246         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
247         //{ "filegroups",   lprocfs_rd_filegroups,  0, 0 },
248         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
249         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
250         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
251         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
252         { "desc_uuid",    lov_rd_desc_uuid,       0, 0 },
253         { "qos_threshold",lov_rd_qos_threshold, lov_wr_qos_threshold, 0 },
254         { "qos_maxage",   lov_rd_qos_maxage, lov_wr_qos_maxage, 0 },
255         { 0 }
256 };
257
258 static struct lprocfs_vars lprocfs_module_vars[] = {
259         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
260         { 0 }
261 };
262
263 struct file_operations lov_proc_target_fops = {
264         .owner   = THIS_MODULE,
265         .open    = lov_target_seq_open,
266         .read    = seq_read,
267         .llseek  = seq_lseek,
268         .release = seq_release,
269 };
270
271 LPROCFS_INIT_VARS(lov, lprocfs_module_vars, lprocfs_obd_vars)
272 #endif /* LPROCFS */