1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
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.
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.
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.
25 #define DEBUG_SUBSYSTEM S_CLASS
27 #include <linux/version.h>
28 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
29 #include <asm/statfs.h>
31 #include <lprocfs_status.h>
32 #include <obd_class.h>
33 #include <linux/seq_file.h>
34 #include "lov_internal.h"
37 static int lov_rd_stripesize(char *page, char **start, off_t off, int count,
40 struct obd_device *dev = (struct obd_device *)data;
41 struct lov_desc *desc;
44 desc = &dev->u.lov.desc;
46 return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
49 static int lov_wr_stripesize(struct file *file, const char *buffer,
50 unsigned long count, void *data)
52 struct obd_device *dev = (struct obd_device *)data;
53 struct lov_desc *desc;
58 desc = &dev->u.lov.desc;
59 rc = lprocfs_write_u64_helper(buffer, count, &val);
63 lov_fix_desc_stripe_size(&val);
64 desc->ld_default_stripe_size = val;
68 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
71 struct obd_device *dev = (struct obd_device *)data;
72 struct lov_desc *desc;
75 desc = &dev->u.lov.desc;
77 return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
80 static int lov_wr_stripeoffset(struct file *file, const char *buffer,
81 unsigned long count, void *data)
83 struct obd_device *dev = (struct obd_device *)data;
84 struct lov_desc *desc;
89 desc = &dev->u.lov.desc;
90 rc = lprocfs_write_u64_helper(buffer, count, &val);
94 desc->ld_default_stripe_offset = val;
98 static int lov_rd_stripetype(char *page, char **start, off_t off, int count,
101 struct obd_device* dev = (struct obd_device*)data;
102 struct lov_desc *desc;
104 LASSERT(dev != NULL);
105 desc = &dev->u.lov.desc;
107 return snprintf(page, count, "%u\n", desc->ld_pattern);
110 static int lov_wr_stripetype(struct file *file, const char *buffer,
111 unsigned long count, void *data)
113 struct obd_device *dev = (struct obd_device *)data;
114 struct lov_desc *desc;
117 LASSERT(dev != NULL);
118 desc = &dev->u.lov.desc;
119 rc = lprocfs_write_helper(buffer, count, &val);
123 lov_fix_desc_pattern(&val);
124 desc->ld_pattern = val;
128 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
129 int *eof, void *data)
131 struct obd_device *dev = (struct obd_device *)data;
132 struct lov_desc *desc;
134 LASSERT(dev != NULL);
135 desc = &dev->u.lov.desc;
137 return snprintf(page, count, "%ld\n",
138 (long)(desc->ld_default_stripe_count + 1) - 1);
141 static int lov_wr_stripecount(struct file *file, const char *buffer,
142 unsigned long count, void *data)
144 struct obd_device *dev = (struct obd_device *)data;
145 struct lov_desc *desc;
148 LASSERT(dev != NULL);
149 desc = &dev->u.lov.desc;
150 rc = lprocfs_write_helper(buffer, count, &val);
154 lov_fix_desc_stripe_count(&val);
155 desc->ld_default_stripe_count = val;
159 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
160 int *eof, void *data)
162 struct obd_device *dev = (struct obd_device*)data;
163 struct lov_desc *desc;
165 LASSERT(dev != NULL);
166 desc = &dev->u.lov.desc;
168 return snprintf(page, count, "%u\n", desc->ld_tgt_count);
172 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
173 int *eof, void *data)
175 struct obd_device* dev = (struct obd_device*)data;
176 struct lov_desc *desc;
178 LASSERT(dev != NULL);
179 desc = &dev->u.lov.desc;
181 return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
184 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
185 int *eof, void *data)
187 struct obd_device *dev = (struct obd_device*) data;
190 LASSERT(dev != NULL);
193 return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
196 /* free priority (0-255): how badly user wants to choose empty osts */
197 static int lov_rd_qos_priofree(char *page, char **start, off_t off, int count,
198 int *eof, void *data)
200 struct obd_device *dev = (struct obd_device*) data;
203 LASSERT(dev != NULL);
206 return snprintf(page, count, "%d%%\n",
207 (lov->lov_qos.lq_prio_free * 100) >> 8);
210 static int lov_wr_qos_priofree(struct file *file, const char *buffer,
211 unsigned long count, void *data)
213 struct obd_device *dev = (struct obd_device *)data;
216 LASSERT(dev != NULL);
219 rc = lprocfs_write_helper(buffer, count, &val);
225 lov->lov_qos.lq_prio_free = (val << 8) / 100;
226 lov->lov_qos.lq_dirty = 1;
227 lov->lov_qos.lq_reset = 1;
231 static int lov_rd_qos_maxage(char *page, char **start, off_t off, int count,
232 int *eof, void *data)
234 struct obd_device *dev = (struct obd_device*) data;
237 LASSERT(dev != NULL);
240 return snprintf(page, count, "%u Sec\n", lov->desc.ld_qos_maxage);
243 static int lov_wr_qos_maxage(struct file *file, const char *buffer,
244 unsigned long count, void *data)
246 struct obd_device *dev = (struct obd_device *)data;
249 LASSERT(dev != NULL);
252 rc = lprocfs_write_helper(buffer, count, &val);
258 lov->desc.ld_qos_maxage = val;
262 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
264 struct obd_device *dev = p->private;
265 struct lov_obd *lov = &dev->u.lov;
267 while (*pos < lov->desc.ld_tgt_count) {
268 if (lov->lov_tgts[*pos])
269 return lov->lov_tgts[*pos];
275 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
279 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
281 struct obd_device *dev = p->private;
282 struct lov_obd *lov = &dev->u.lov;
284 while (++*pos < lov->desc.ld_tgt_count) {
285 if (lov->lov_tgts[*pos])
286 return lov->lov_tgts[*pos];
291 static int lov_tgt_seq_show(struct seq_file *p, void *v)
293 struct lov_tgt_desc *tgt = v;
294 return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
295 obd_uuid2str(&tgt->ltd_uuid),
296 tgt->ltd_active ? "" : "IN");
299 struct seq_operations lov_tgt_sops = {
300 .start = lov_tgt_seq_start,
301 .stop = lov_tgt_seq_stop,
302 .next = lov_tgt_seq_next,
303 .show = lov_tgt_seq_show,
306 static int lov_target_seq_open(struct inode *inode, struct file *file)
308 struct proc_dir_entry *dp = PDE(inode);
309 struct seq_file *seq;
312 LPROCFS_ENTRY_AND_CHECK(dp);
313 rc = seq_open(file, &lov_tgt_sops);
319 seq = file->private_data;
320 seq->private = dp->data;
324 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
325 { "uuid", lprocfs_rd_uuid, 0, 0 },
326 { "stripesize", lov_rd_stripesize, lov_wr_stripesize, 0 },
327 { "stripeoffset", lov_rd_stripeoffset, lov_wr_stripeoffset, 0 },
328 { "stripecount", lov_rd_stripecount, lov_wr_stripecount, 0 },
329 { "stripetype", lov_rd_stripetype, lov_wr_stripetype, 0 },
330 { "numobd", lov_rd_numobd, 0, 0 },
331 { "activeobd", lov_rd_activeobd, 0, 0 },
332 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
333 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
334 /*{ "filegroups", lprocfs_rd_filegroups, 0, 0 },*/
335 { "blocksize", lprocfs_rd_blksize, 0, 0 },
336 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
337 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
338 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
339 { "desc_uuid", lov_rd_desc_uuid, 0, 0 },
340 { "qos_prio_free",lov_rd_qos_priofree, lov_wr_qos_priofree, 0 },
341 { "qos_maxage", lov_rd_qos_maxage, lov_wr_qos_maxage, 0 },
345 static struct lprocfs_vars lprocfs_lov_module_vars[] = {
346 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
350 void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars)
352 lvars->module_vars = lprocfs_lov_module_vars;
353 lvars->obd_vars = lprocfs_lov_obd_vars;
356 struct file_operations lov_proc_target_fops = {
357 .owner = THIS_MODULE,
358 .open = lov_target_seq_open,
361 .release = lprocfs_seq_release,