Whamcloud - gitweb
b=13557 (author Adilger)
[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 #include <asm/statfs.h>
29 #include <lprocfs_status.h>
30 #include <obd_class.h>
31 #include <linux/seq_file.h>
32 #include "lov_internal.h"
33
34 #ifdef LPROCFS
35 static int lov_rd_stripesize(char *page, char **start, off_t off, int count,
36                              int *eof, void *data)
37 {
38         struct obd_device *dev = (struct obd_device *)data;
39         struct lov_desc *desc;
40
41         LASSERT(dev != NULL);
42         desc = &dev->u.lov.desc;
43         *eof = 1;
44         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
45 }
46
47 static int lov_wr_stripesize(struct file *file, const char *buffer,
48                                unsigned long count, void *data)
49 {
50         struct obd_device *dev = (struct obd_device *)data;
51         struct lov_desc *desc;
52         __u64 val;
53         int rc;
54         
55         LASSERT(dev != NULL);
56         desc = &dev->u.lov.desc;
57         rc = lprocfs_write_u64_helper(buffer, count, &val);
58         if (rc)
59                 return rc;
60
61         desc->ld_default_stripe_size = val;
62         lov_fix_desc(desc);
63         return count;
64 }
65
66 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
67                                int *eof, void *data)
68 {
69         struct obd_device *dev = (struct obd_device *)data;
70         struct lov_desc *desc;
71
72         LASSERT(dev != NULL);
73         desc = &dev->u.lov.desc;
74         *eof = 1;
75         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
76 }
77
78 static int lov_wr_stripeoffset(struct file *file, const char *buffer,
79                                unsigned long count, void *data)
80 {
81         struct obd_device *dev = (struct obd_device *)data;
82         struct lov_desc *desc;
83         __u64 val;
84         int rc;
85         
86         LASSERT(dev != NULL);
87         desc = &dev->u.lov.desc;
88         rc = lprocfs_write_u64_helper(buffer, count, &val);
89         if (rc)
90                 return rc;
91
92         desc->ld_default_stripe_offset = val;
93         lov_fix_desc(desc);
94         return count;
95 }
96
97 static int lov_rd_stripetype(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_pattern);
107 }
108
109 static int lov_wr_stripetype(struct file *file, const char *buffer,
110                              unsigned long count, void *data)
111 {
112         struct obd_device *dev = (struct obd_device *)data;
113         struct lov_desc *desc;
114         int val, rc;
115         
116         LASSERT(dev != NULL);
117         desc = &dev->u.lov.desc;
118         rc = lprocfs_write_helper(buffer, count, &val);
119         if (rc)
120                 return rc;
121
122         desc->ld_pattern = val;
123         lov_fix_desc(desc);
124         return count;
125 }
126
127 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
128                               int *eof, void *data)
129 {
130         struct obd_device *dev = (struct obd_device *)data;
131         struct lov_desc *desc;
132
133         LASSERT(dev != NULL);
134         desc = &dev->u.lov.desc;
135         *eof = 1;
136         return snprintf(page, count, "%ld\n",
137                         (long)(desc->ld_default_stripe_count + 1) - 1);
138 }
139
140 static int lov_wr_stripecount(struct file *file, const char *buffer,
141                               unsigned long count, void *data)
142 {
143         struct obd_device *dev = (struct obd_device *)data;
144         struct lov_desc *desc;
145         int val, rc;
146         
147         LASSERT(dev != NULL);
148         desc = &dev->u.lov.desc;
149         rc = lprocfs_write_helper(buffer, count, &val);
150         if (rc)
151                 return rc;
152
153         desc->ld_default_stripe_count = val;
154         lov_fix_desc(desc);
155         return count;
156 }
157
158 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
159                          int *eof, void *data)
160 {
161         struct obd_device *dev = (struct obd_device*)data;
162         struct lov_desc *desc;
163
164         LASSERT(dev != NULL);
165         desc = &dev->u.lov.desc;
166         *eof = 1;
167         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
168
169 }
170
171 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
172                             int *eof, void *data)
173 {
174         struct obd_device* dev = (struct obd_device*)data;
175         struct lov_desc *desc;
176
177         LASSERT(dev != NULL);
178         desc = &dev->u.lov.desc;
179         *eof = 1;
180         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
181 }
182
183 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
184                             int *eof, void *data)
185 {
186         struct obd_device *dev = (struct obd_device*) data;
187         struct lov_obd *lov;
188
189         LASSERT(dev != NULL);
190         lov = &dev->u.lov;
191         *eof = 1;
192         return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
193 }
194
195 /* free priority (0-255): how badly user wants to choose empty osts */ 
196 static int lov_rd_qos_priofree(char *page, char **start, off_t off, int count,
197                                int *eof, void *data)
198 {
199         struct obd_device *dev = (struct obd_device*) data;
200         struct lov_obd *lov;
201
202         LASSERT(dev != NULL);
203         lov = &dev->u.lov;
204         *eof = 1;
205         return snprintf(page, count, "%d%%\n", 
206                         (lov->lov_qos.lq_prio_free * 100) >> 8);
207 }
208
209 static int lov_wr_qos_priofree(struct file *file, const char *buffer,
210                                unsigned long count, void *data)
211 {
212         struct obd_device *dev = (struct obd_device *)data;
213         struct lov_obd *lov;
214         int val, rc;
215         LASSERT(dev != NULL);
216
217         lov = &dev->u.lov;
218         rc = lprocfs_write_helper(buffer, count, &val);
219         if (rc)
220                 return rc;
221
222         if (val > 100)
223                 return -EINVAL;
224         lov->lov_qos.lq_prio_free = (val << 8) / 100;
225         lov->lov_qos.lq_dirty = 1;
226         lov->lov_qos.lq_reset = 1;
227         return count;
228 }
229
230 static int lov_rd_qos_maxage(char *page, char **start, off_t off, int count,
231                              int *eof, void *data)
232 {
233         struct obd_device *dev = (struct obd_device*) data;
234         struct lov_obd *lov;
235
236         LASSERT(dev != NULL);
237         lov = &dev->u.lov;
238         *eof = 1;
239         return snprintf(page, count, "%u Sec\n", lov->desc.ld_qos_maxage);
240 }
241
242 static int lov_wr_qos_maxage(struct file *file, const char *buffer,
243                              unsigned long count, void *data)
244 {
245         struct obd_device *dev = (struct obd_device *)data;
246         struct lov_obd *lov;
247         int val, rc;
248         LASSERT(dev != NULL);
249
250         lov = &dev->u.lov;
251         rc = lprocfs_write_helper(buffer, count, &val);
252         if (rc)
253                 return rc;
254
255         if (val <= 0)
256                 return -EINVAL;
257         lov->desc.ld_qos_maxage = val;
258         return count;
259 }
260
261 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
262 {
263         struct obd_device *dev = p->private;
264         struct lov_obd *lov = &dev->u.lov;
265
266         while (*pos < lov->desc.ld_tgt_count) {
267                 if (lov->lov_tgts[*pos])
268                         return lov->lov_tgts[*pos];
269                 ++*pos;
270         }
271         return NULL;
272 }
273
274 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
275 {
276 }
277
278 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
279 {
280         struct obd_device *dev = p->private;
281         struct lov_obd *lov = &dev->u.lov;
282
283         while (++*pos < lov->desc.ld_tgt_count) {
284                 if (lov->lov_tgts[*pos])
285                         return lov->lov_tgts[*pos];
286         }
287         return NULL;
288 }
289
290 static int lov_tgt_seq_show(struct seq_file *p, void *v)
291 {
292         struct lov_tgt_desc *tgt = v;
293         return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index, 
294                           obd_uuid2str(&tgt->ltd_uuid), 
295                           tgt->ltd_active ? "" : "IN");
296 }
297
298 struct seq_operations lov_tgt_sops = {
299         .start = lov_tgt_seq_start,
300         .stop = lov_tgt_seq_stop,
301         .next = lov_tgt_seq_next,
302         .show = lov_tgt_seq_show,
303 };
304
305 static int lov_target_seq_open(struct inode *inode, struct file *file)
306 {
307         struct proc_dir_entry *dp = PDE(inode);
308         struct seq_file *seq;
309         int rc;
310
311         LPROCFS_ENTRY_AND_CHECK(dp);
312         rc = seq_open(file, &lov_tgt_sops);
313         if (rc) {
314                 LPROCFS_EXIT();
315                 return rc;
316         }
317
318         seq = file->private_data;
319         seq->private = dp->data;
320         return 0;
321 }
322
323 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
324         { "uuid",         lprocfs_rd_uuid,        0, 0 },
325         { "stripesize",   lov_rd_stripesize,      lov_wr_stripesize, 0 },
326         { "stripeoffset", lov_rd_stripeoffset,    lov_wr_stripeoffset, 0 },
327         { "stripecount",  lov_rd_stripecount,     lov_wr_stripecount, 0 },
328         { "stripetype",   lov_rd_stripetype,      lov_wr_stripetype, 0 },
329         { "numobd",       lov_rd_numobd,          0, 0 },
330         { "activeobd",    lov_rd_activeobd,       0, 0 },
331         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
332         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
333         /*{ "filegroups", lprocfs_rd_filegroups,  0, 0 },*/
334         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
335         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
336         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
337         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
338         { "desc_uuid",    lov_rd_desc_uuid,       0, 0 },
339         { "qos_prio_free",lov_rd_qos_priofree,    lov_wr_qos_priofree, 0 },
340         { "qos_maxage",   lov_rd_qos_maxage,      lov_wr_qos_maxage, 0 },
341         { 0 }
342 };
343
344 static struct lprocfs_vars lprocfs_lov_module_vars[] = {
345         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
346         { 0 }
347 };
348
349 void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars)
350 {
351     lvars->module_vars  = lprocfs_lov_module_vars;
352     lvars->obd_vars     = lprocfs_lov_obd_vars;
353 }
354
355 struct file_operations lov_proc_target_fops = {
356         .owner   = THIS_MODULE,
357         .open    = lov_target_seq_open,
358         .read    = seq_read,
359         .llseek  = seq_lseek,
360         .release = lprocfs_seq_release,
361 };
362 #endif /* LPROCFS */
363