Whamcloud - gitweb
LU-1770 ptlrpc: introducing OBD_CONNECT_FLOCK_OWNER flag
[fs/lustre-release.git] / lustre / lov / lproc_lov.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34 #define DEBUG_SUBSYSTEM S_CLASS
35
36 #include <linux/version.h>
37 #include <asm/statfs.h>
38 #include <lprocfs_status.h>
39 #include <obd_class.h>
40 #include <linux/seq_file.h>
41 #include "lov_internal.h"
42
43 #ifdef LPROCFS
44 static int lov_rd_stripesize(char *page, char **start, off_t off, int count,
45                              int *eof, 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 static int lov_wr_stripesize(struct file *file, const char *buffer,
57                                unsigned long count, void *data)
58 {
59         struct obd_device *dev = (struct obd_device *)data;
60         struct lov_desc *desc;
61         __u64 val;
62         int rc;
63         
64         LASSERT(dev != NULL);
65         desc = &dev->u.lov.desc;
66         rc = lprocfs_write_u64_helper(buffer, count, &val);
67         if (rc)
68                 return rc;
69
70         lov_fix_desc_stripe_size(&val);
71         desc->ld_default_stripe_size = val;
72         return count;
73 }
74
75 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
76                                int *eof, void *data)
77 {
78         struct obd_device *dev = (struct obd_device *)data;
79         struct lov_desc *desc;
80
81         LASSERT(dev != NULL);
82         desc = &dev->u.lov.desc;
83         *eof = 1;
84         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
85 }
86
87 static int lov_wr_stripeoffset(struct file *file, const char *buffer,
88                                unsigned long count, void *data)
89 {
90         struct obd_device *dev = (struct obd_device *)data;
91         struct lov_desc *desc;
92         __u64 val;
93         int rc;
94         
95         LASSERT(dev != NULL);
96         desc = &dev->u.lov.desc;
97         rc = lprocfs_write_u64_helper(buffer, count, &val);
98         if (rc)
99                 return rc;
100
101         desc->ld_default_stripe_offset = val;
102         return count;
103 }
104
105 static int lov_rd_stripetype(char *page, char **start, off_t off, int count,
106                              int *eof, 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_pattern);
115 }
116
117 static int lov_wr_stripetype(struct file *file, const char *buffer,
118                              unsigned long count, void *data)
119 {
120         struct obd_device *dev = (struct obd_device *)data;
121         struct lov_desc *desc;
122         int val, rc;
123         
124         LASSERT(dev != NULL);
125         desc = &dev->u.lov.desc;
126         rc = lprocfs_write_helper(buffer, count, &val);
127         if (rc)
128                 return rc;
129
130         lov_fix_desc_pattern(&val);
131         desc->ld_pattern = val;
132         return count;
133 }
134
135 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
136                               int *eof, void *data)
137 {
138         struct obd_device *dev = (struct obd_device *)data;
139         struct lov_desc *desc;
140
141         LASSERT(dev != NULL);
142         desc = &dev->u.lov.desc;
143         *eof = 1;
144         return snprintf(page, count, "%d\n",
145                         (__s16)(desc->ld_default_stripe_count + 1) - 1);
146 }
147
148 static int lov_wr_stripecount(struct file *file, const char *buffer,
149                               unsigned long count, void *data)
150 {
151         struct obd_device *dev = (struct obd_device *)data;
152         struct lov_desc *desc;
153         int val, rc;
154         
155         LASSERT(dev != NULL);
156         desc = &dev->u.lov.desc;
157         rc = lprocfs_write_helper(buffer, count, &val);
158         if (rc)
159                 return rc;
160
161         lov_fix_desc_stripe_count(&val);
162         desc->ld_default_stripe_count = val;
163         return count;
164 }
165
166 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
167                          int *eof, void *data)
168 {
169         struct obd_device *dev = (struct obd_device*)data;
170         struct lov_desc *desc;
171
172         LASSERT(dev != NULL);
173         desc = &dev->u.lov.desc;
174         *eof = 1;
175         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
176
177 }
178
179 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
180                             int *eof, void *data)
181 {
182         struct obd_device* dev = (struct obd_device*)data;
183         struct lov_desc *desc;
184
185         LASSERT(dev != NULL);
186         desc = &dev->u.lov.desc;
187         *eof = 1;
188         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
189 }
190
191 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
192                             int *eof, void *data)
193 {
194         struct obd_device *dev = (struct obd_device*) data;
195         struct lov_obd *lov;
196
197         LASSERT(dev != NULL);
198         lov = &dev->u.lov;
199         *eof = 1;
200         return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
201 }
202
203 /* free priority (0-255): how badly user wants to choose empty osts */ 
204 static int lov_rd_qos_priofree(char *page, char **start, off_t off, int count,
205                                int *eof, void *data)
206 {
207         struct obd_device *dev = (struct obd_device*) data;
208         struct lov_obd *lov;
209
210         LASSERT(dev != NULL);
211         lov = &dev->u.lov;
212         *eof = 1;
213         return snprintf(page, count, "%d%%\n", 
214                         (lov->lov_qos.lq_prio_free * 100 + 255) >> 8);
215 }
216
217 static int lov_wr_qos_priofree(struct file *file, const char *buffer,
218                                unsigned long count, void *data)
219 {
220         struct obd_device *dev = (struct obd_device *)data;
221         struct lov_obd *lov;
222         int val, rc;
223         LASSERT(dev != NULL);
224
225         lov = &dev->u.lov;
226         rc = lprocfs_write_helper(buffer, count, &val);
227         if (rc)
228                 return rc;
229
230         if (val > 100)
231                 return -EINVAL;
232         lov->lov_qos.lq_prio_free = (val << 8) / 100;
233         lov->lov_qos.lq_dirty = 1;
234         lov->lov_qos.lq_reset = 1;
235         return count;
236 }
237
238 static int lov_rd_qos_thresholdrr(char *page, char **start, off_t off,
239                                   int count, int *eof, void *data)
240 {
241         struct obd_device *dev = (struct obd_device*) data;
242         struct lov_obd *lov;
243
244         LASSERT(dev != NULL);
245         lov = &dev->u.lov;
246         *eof = 1;
247         return snprintf(page, count, "%d%%\n",
248                         (lov->lov_qos.lq_threshold_rr * 100 + 255) >> 8);
249 }
250
251 static int lov_wr_qos_thresholdrr(struct file *file, const char *buffer,
252                                   unsigned long count, void *data)
253 {
254         struct obd_device *dev = (struct obd_device *)data;
255         struct lov_obd *lov;
256         int val, rc;
257         LASSERT(dev != NULL);
258
259         lov = &dev->u.lov;
260         rc = lprocfs_write_helper(buffer, count, &val);
261         if (rc)
262                 return rc;
263
264         if (val > 100 || val < 0)
265                 return -EINVAL;
266
267         lov->lov_qos.lq_threshold_rr = (val << 8) / 100;
268         lov->lov_qos.lq_dirty = 1;
269         return count;
270 }
271
272 static int lov_rd_qos_maxage(char *page, char **start, off_t off, int count,
273                              int *eof, void *data)
274 {
275         struct obd_device *dev = (struct obd_device*) data;
276         struct lov_obd *lov;
277
278         LASSERT(dev != NULL);
279         lov = &dev->u.lov;
280         *eof = 1;
281         return snprintf(page, count, "%u Sec\n", lov->desc.ld_qos_maxage);
282 }
283
284 static int lov_wr_qos_maxage(struct file *file, const char *buffer,
285                              unsigned long count, void *data)
286 {
287         struct obd_device *dev = (struct obd_device *)data;
288         struct lov_obd *lov;
289         int val, rc;
290         LASSERT(dev != NULL);
291
292         lov = &dev->u.lov;
293         rc = lprocfs_write_helper(buffer, count, &val);
294         if (rc)
295                 return rc;
296
297         if (val <= 0)
298                 return -EINVAL;
299         lov->desc.ld_qos_maxage = val;
300         return count;
301 }
302
303 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
304 {
305         struct obd_device *dev = p->private;
306         struct lov_obd *lov = &dev->u.lov;
307
308         while (*pos < lov->desc.ld_tgt_count) {
309                 if (lov->lov_tgts[*pos])
310                         return lov->lov_tgts[*pos];
311                 ++*pos;
312         }
313         return NULL;
314 }
315
316 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
317 {
318 }
319
320 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
321 {
322         struct obd_device *dev = p->private;
323         struct lov_obd *lov = &dev->u.lov;
324
325         while (++*pos < lov->desc.ld_tgt_count) {
326                 if (lov->lov_tgts[*pos])
327                         return lov->lov_tgts[*pos];
328         }
329         return NULL;
330 }
331
332 static int lov_tgt_seq_show(struct seq_file *p, void *v)
333 {
334         struct lov_tgt_desc *tgt = v;
335         return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index, 
336                           obd_uuid2str(&tgt->ltd_uuid), 
337                           tgt->ltd_active ? "" : "IN");
338 }
339
340 struct seq_operations lov_tgt_sops = {
341         .start = lov_tgt_seq_start,
342         .stop = lov_tgt_seq_stop,
343         .next = lov_tgt_seq_next,
344         .show = lov_tgt_seq_show,
345 };
346
347 static int lov_target_seq_open(struct inode *inode, struct file *file)
348 {
349         struct proc_dir_entry *dp = PDE(inode);
350         struct seq_file *seq;
351         int rc;
352
353         LPROCFS_ENTRY_AND_CHECK(dp);
354         rc = seq_open(file, &lov_tgt_sops);
355         if (rc) {
356                 LPROCFS_EXIT();
357                 return rc;
358         }
359
360         seq = file->private_data;
361         seq->private = dp->data;
362         return 0;
363 }
364
365 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
366         { "uuid",         lprocfs_rd_uuid,        0, 0 },
367         { "stripesize",   lov_rd_stripesize,      lov_wr_stripesize, 0 },
368         { "stripeoffset", lov_rd_stripeoffset,    lov_wr_stripeoffset, 0 },
369         { "stripecount",  lov_rd_stripecount,     lov_wr_stripecount, 0 },
370         { "stripetype",   lov_rd_stripetype,      lov_wr_stripetype, 0 },
371         { "numobd",       lov_rd_numobd,          0, 0 },
372         { "activeobd",    lov_rd_activeobd,       0, 0 },
373         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
374         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
375         /*{ "filegroups", lprocfs_rd_filegroups,  0, 0 },*/
376         { "blocksize",    lprocfs_rd_blksize,     0, 0 },
377         { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
378         { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
379         { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
380         { "desc_uuid",    lov_rd_desc_uuid,       0, 0 },
381         { "qos_prio_free",lov_rd_qos_priofree,    lov_wr_qos_priofree, 0 },
382         { "qos_threshold_rr",  lov_rd_qos_thresholdrr, lov_wr_qos_thresholdrr, 0 },
383         { "qos_maxage",   lov_rd_qos_maxage,      lov_wr_qos_maxage, 0 },
384         { 0 }
385 };
386
387 static struct lprocfs_vars lprocfs_lov_module_vars[] = {
388         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
389         { 0 }
390 };
391
392 void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars)
393 {
394     lvars->module_vars  = lprocfs_lov_module_vars;
395     lvars->obd_vars     = lprocfs_lov_obd_vars;
396 }
397
398 struct file_operations lov_proc_target_fops = {
399         .owner   = THIS_MODULE,
400         .open    = lov_target_seq_open,
401         .read    = seq_read,
402         .llseek  = seq_lseek,
403         .release = lprocfs_seq_release,
404 };
405 #endif /* LPROCFS */