Whamcloud - gitweb
LU-4129 libcfs: Only dump log once per sec. to avoid EEXIST
[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  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #define DEBUG_SUBSYSTEM S_CLASS
37
38 #include <linux/version.h>
39 #include <asm/statfs.h>
40 #include <lprocfs_status.h>
41 #include <obd_class.h>
42 #include <lustre_param.h>
43 #include "lov_internal.h"
44
45 #ifdef LPROCFS
46 static int lov_stripesize_seq_show(struct seq_file *m, void *v)
47 {
48         struct obd_device *dev = (struct obd_device *)m->private;
49         struct lov_desc *desc;
50
51         LASSERT(dev != NULL);
52         desc = &dev->u.lov.desc;
53
54         return seq_printf(m, LPU64"\n", desc->ld_default_stripe_size);
55 }
56
57 static ssize_t lov_stripesize_seq_write(struct file *file, const char *buffer,
58                                         size_t count, loff_t *off)
59 {
60         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
61         struct lov_desc *desc;
62         __u64 val;
63         int rc;
64
65         LASSERT(dev != NULL);
66         desc = &dev->u.lov.desc;
67         rc = lprocfs_write_u64_helper(buffer, count, &val);
68         if (rc)
69                 return rc;
70
71         lov_fix_desc_stripe_size(&val);
72         desc->ld_default_stripe_size = val;
73         return count;
74 }
75 LPROC_SEQ_FOPS(lov_stripesize);
76
77 static int lov_stripeoffset_seq_show(struct seq_file *m, void *v)
78 {
79         struct obd_device *dev = (struct obd_device *)m->private;
80         struct lov_desc *desc;
81
82         LASSERT(dev != NULL);
83         desc = &dev->u.lov.desc;
84         return seq_printf(m, LPU64"\n", desc->ld_default_stripe_offset);
85 }
86
87 static ssize_t lov_stripeoffset_seq_write(struct file *file, const char *buffer,
88                                           size_t count, loff_t *off)
89 {
90         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
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 LPROC_SEQ_FOPS(lov_stripeoffset);
105
106 static int lov_stripetype_seq_show(struct seq_file *m, void *v)
107 {
108         struct obd_device* dev = (struct obd_device*)m->private;
109         struct lov_desc *desc;
110
111         LASSERT(dev != NULL);
112         desc = &dev->u.lov.desc;
113         return seq_printf(m, "%u\n", desc->ld_pattern);
114 }
115
116 static ssize_t lov_stripetype_seq_write(struct file *file, const char *buffer,
117                                         size_t count, loff_t *off)
118 {
119         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
120         struct lov_desc *desc;
121         int val, rc;
122
123         LASSERT(dev != NULL);
124         desc = &dev->u.lov.desc;
125         rc = lprocfs_write_helper(buffer, count, &val);
126         if (rc)
127                 return rc;
128
129         lov_fix_desc_pattern(&val);
130         desc->ld_pattern = val;
131         return count;
132 }
133 LPROC_SEQ_FOPS(lov_stripetype);
134
135 static int lov_stripecount_seq_show(struct seq_file *m, void *v)
136 {
137         struct obd_device *dev = (struct obd_device *)m->private;
138         struct lov_desc *desc;
139
140         LASSERT(dev != NULL);
141         desc = &dev->u.lov.desc;
142         return seq_printf(m, "%d\n",
143                           (__s16)(desc->ld_default_stripe_count + 1) - 1);
144 }
145
146 static ssize_t lov_stripecount_seq_write(struct file *file, const char *buffer,
147                                          size_t count, loff_t *off)
148 {
149         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
150         struct lov_desc *desc;
151         int val, rc;
152
153         LASSERT(dev != NULL);
154         desc = &dev->u.lov.desc;
155         rc = lprocfs_write_helper(buffer, count, &val);
156         if (rc)
157                 return rc;
158
159         lov_fix_desc_stripe_count(&val);
160         desc->ld_default_stripe_count = val;
161         return count;
162 }
163 LPROC_SEQ_FOPS(lov_stripecount);
164
165 static int lov_numobd_seq_show(struct seq_file *m, void *v)
166 {
167         struct obd_device *dev = (struct obd_device*)m->private;
168         struct lov_desc *desc;
169
170         LASSERT(dev != NULL);
171         desc = &dev->u.lov.desc;
172         return seq_printf(m, "%u\n", desc->ld_tgt_count);
173 }
174 LPROC_SEQ_FOPS_RO(lov_numobd);
175
176 static int lov_activeobd_seq_show(struct seq_file *m, void *v)
177 {
178         struct obd_device* dev = (struct obd_device*)m->private;
179         struct lov_desc *desc;
180
181         LASSERT(dev != NULL);
182         desc = &dev->u.lov.desc;
183         return seq_printf(m, "%u\n", desc->ld_active_tgt_count);
184 }
185 LPROC_SEQ_FOPS_RO(lov_activeobd);
186
187 static int lov_desc_uuid_seq_show(struct seq_file *m, void *v)
188 {
189         struct obd_device *dev = m->private;
190         struct lov_obd *lov;
191
192         LASSERT(dev != NULL);
193         lov = &dev->u.lov;
194         return seq_printf(m, "%s\n", lov->desc.ld_uuid.uuid);
195 }
196 LPROC_SEQ_FOPS_RO(lov_desc_uuid);
197
198 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
199 {
200         struct obd_device *dev = p->private;
201         struct lov_obd *lov = &dev->u.lov;
202
203         while (*pos < lov->desc.ld_tgt_count) {
204                 if (lov->lov_tgts[*pos])
205                         return lov->lov_tgts[*pos];
206                 ++*pos;
207         }
208         return NULL;
209 }
210
211 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
212 {
213 }
214
215 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
216 {
217         struct obd_device *dev = p->private;
218         struct lov_obd *lov = &dev->u.lov;
219
220         while (++*pos < lov->desc.ld_tgt_count) {
221                 if (lov->lov_tgts[*pos])
222                         return lov->lov_tgts[*pos];
223         }
224         return NULL;
225 }
226
227 static int lov_tgt_seq_show(struct seq_file *p, void *v)
228 {
229         struct lov_tgt_desc *tgt = v;
230         return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index, 
231                           obd_uuid2str(&tgt->ltd_uuid), 
232                           tgt->ltd_active ? "" : "IN");
233 }
234
235 struct seq_operations lov_tgt_sops = {
236         .start = lov_tgt_seq_start,
237         .stop = lov_tgt_seq_stop,
238         .next = lov_tgt_seq_next,
239         .show = lov_tgt_seq_show,
240 };
241
242 static int lov_target_seq_open(struct inode *inode, struct file *file)
243 {
244         struct seq_file *seq;
245         int rc;
246
247         LPROCFS_ENTRY_CHECK(PDE(inode));
248         rc = seq_open(file, &lov_tgt_sops);
249         if (rc)
250                 return rc;
251
252         seq = file->private_data;
253         seq->private = PDE_DATA(inode);
254         return 0;
255 }
256
257 LPROC_SEQ_FOPS_RO_TYPE(lov, uuid);
258 LPROC_SEQ_FOPS_RO_TYPE(lov, filestotal);
259 LPROC_SEQ_FOPS_RO_TYPE(lov, filesfree);
260 LPROC_SEQ_FOPS_RO_TYPE(lov, blksize);
261 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytestotal);
262 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytesfree);
263 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytesavail);
264
265 struct lprocfs_seq_vars lprocfs_lov_obd_vars[] = {
266         { "uuid",               &lov_uuid_fops          },
267         { "stripesize",         &lov_stripesize_fops    },
268         { "stripeoffset",       &lov_stripeoffset_fops  },
269         { "stripecount",        &lov_stripecount_fops   },
270         { "stripetype",         &lov_stripetype_fops    },
271         { "numobd",             &lov_numobd_fops        },
272         { "activeobd",          &lov_activeobd_fops     },
273         { "filestotal",         &lov_filestotal_fops    },
274         { "filesfree",          &lov_filesfree_fops     },
275         { "blocksize",          &lov_blksize_fops       },
276         { "kbytestotal",        &lov_kbytestotal_fops   },
277         { "kbytesfree",         &lov_kbytesfree_fops    },
278         { "kbytesavail",        &lov_kbytesavail_fops   },
279         { "desc_uuid",          &lov_desc_uuid_fops     },
280         { 0 }
281 };
282
283 struct file_operations lov_proc_target_fops = {
284         .owner   = THIS_MODULE,
285         .open    = lov_target_seq_open,
286         .read    = seq_read,
287         .llseek  = seq_lseek,
288         .release = lprocfs_seq_release,
289 };
290 #endif /* LPROCFS */