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 #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"
35 static int lov_rd_stripesize(char *page, char **start, off_t off, int count,
38 struct obd_device *dev = (struct obd_device *)data;
39 struct lov_desc *desc;
42 desc = &dev->u.lov.desc;
44 return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
47 static int lov_wr_stripesize(struct file *file, const char *buffer,
48 unsigned long count, void *data)
50 struct obd_device *dev = (struct obd_device *)data;
51 struct lov_desc *desc;
56 desc = &dev->u.lov.desc;
57 rc = lprocfs_write_u64_helper(buffer, count, &val);
61 desc->ld_default_stripe_size = val;
66 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
69 struct obd_device *dev = (struct obd_device *)data;
70 struct lov_desc *desc;
73 desc = &dev->u.lov.desc;
75 return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
78 static int lov_wr_stripeoffset(struct file *file, const char *buffer,
79 unsigned long count, void *data)
81 struct obd_device *dev = (struct obd_device *)data;
82 struct lov_desc *desc;
87 desc = &dev->u.lov.desc;
88 rc = lprocfs_write_u64_helper(buffer, count, &val);
92 desc->ld_default_stripe_offset = val;
97 static int lov_rd_stripetype(char *page, char **start, off_t off, int count,
100 struct obd_device* dev = (struct obd_device*)data;
101 struct lov_desc *desc;
103 LASSERT(dev != NULL);
104 desc = &dev->u.lov.desc;
106 return snprintf(page, count, "%u\n", desc->ld_pattern);
109 static int lov_wr_stripetype(struct file *file, const char *buffer,
110 unsigned long count, void *data)
112 struct obd_device *dev = (struct obd_device *)data;
113 struct lov_desc *desc;
116 LASSERT(dev != NULL);
117 desc = &dev->u.lov.desc;
118 rc = lprocfs_write_helper(buffer, count, &val);
122 desc->ld_pattern = val;
127 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
128 int *eof, void *data)
130 struct obd_device *dev = (struct obd_device *)data;
131 struct lov_desc *desc;
133 LASSERT(dev != NULL);
134 desc = &dev->u.lov.desc;
136 return snprintf(page, count, "%u\n", desc->ld_default_stripe_count);
139 static int lov_wr_stripecount(struct file *file, const char *buffer,
140 unsigned long count, void *data)
142 struct obd_device *dev = (struct obd_device *)data;
143 struct lov_desc *desc;
146 LASSERT(dev != NULL);
147 desc = &dev->u.lov.desc;
148 rc = lprocfs_write_helper(buffer, count, &val);
152 desc->ld_default_stripe_count = val;
157 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
158 int *eof, void *data)
160 struct obd_device *dev = (struct obd_device*)data;
161 struct lov_desc *desc;
163 LASSERT(dev != NULL);
164 desc = &dev->u.lov.desc;
166 return snprintf(page, count, "%u\n", desc->ld_tgt_count);
170 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
171 int *eof, void *data)
173 struct obd_device* dev = (struct obd_device*)data;
174 struct lov_desc *desc;
176 LASSERT(dev != NULL);
177 desc = &dev->u.lov.desc;
179 return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
182 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
183 int *eof, void *data)
185 struct obd_device *dev = (struct obd_device*) data;
188 LASSERT(dev != NULL);
191 return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
194 /* free priority (0-255): how badly user wants to choose empty osts */
195 static int lov_rd_qos_priofree(char *page, char **start, off_t off, int count,
196 int *eof, void *data)
198 struct obd_device *dev = (struct obd_device*) data;
201 LASSERT(dev != NULL);
204 return snprintf(page, count, "%d%%\n",
205 (lov->lov_qos.lq_prio_free * 100) >> 8);
208 static int lov_wr_qos_priofree(struct file *file, const char *buffer,
209 unsigned long count, void *data)
211 struct obd_device *dev = (struct obd_device *)data;
214 LASSERT(dev != NULL);
217 rc = lprocfs_write_helper(buffer, count, &val);
223 lov->lov_qos.lq_prio_free = (val << 8) / 100;
224 lov->lov_qos.lq_dirty = 1;
225 lov->lov_qos.lq_reset = 1;
229 static int lov_rd_qos_maxage(char *page, char **start, off_t off, int count,
230 int *eof, void *data)
232 struct obd_device *dev = (struct obd_device*) data;
235 LASSERT(dev != NULL);
238 return snprintf(page, count, "%u Sec\n", lov->desc.ld_qos_maxage);
241 static int lov_wr_qos_maxage(struct file *file, const char *buffer,
242 unsigned long count, void *data)
244 struct obd_device *dev = (struct obd_device *)data;
247 LASSERT(dev != NULL);
250 rc = lprocfs_write_helper(buffer, count, &val);
256 lov->desc.ld_qos_maxage = val;
260 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
262 struct obd_device *dev = p->private;
263 struct lov_obd *lov = &dev->u.lov;
265 return (*pos >= lov->desc.ld_tgt_count) ? NULL : lov->lov_tgts[*pos];
269 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
273 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
275 struct obd_device *dev = p->private;
276 struct lov_obd *lov = &dev->u.lov;
278 while (++*pos < lov->desc.ld_tgt_count) {
279 if (lov->lov_tgts[*pos])
280 return lov->lov_tgts[*pos];
285 static int lov_tgt_seq_show(struct seq_file *p, void *v)
287 struct lov_tgt_desc *tgt = v;
288 return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
289 obd_uuid2str(&tgt->ltd_uuid),
290 tgt->ltd_active ? "" : "IN");
293 struct seq_operations lov_tgt_sops = {
294 .start = lov_tgt_seq_start,
295 .stop = lov_tgt_seq_stop,
296 .next = lov_tgt_seq_next,
297 .show = lov_tgt_seq_show,
300 static int lov_target_seq_open(struct inode *inode, struct file *file)
302 struct proc_dir_entry *dp = PDE(inode);
303 struct seq_file *seq;
306 LPROCFS_ENTRY_AND_CHECK(dp);
307 rc = seq_open(file, &lov_tgt_sops);
313 seq = file->private_data;
314 seq->private = dp->data;
318 struct lprocfs_vars lprocfs_obd_vars[] = {
319 { "uuid", lprocfs_rd_uuid, 0, 0 },
320 { "stripesize", lov_rd_stripesize, lov_wr_stripesize, 0 },
321 { "stripeoffset", lov_rd_stripeoffset, lov_wr_stripeoffset, 0 },
322 { "stripecount", lov_rd_stripecount, lov_wr_stripecount, 0 },
323 { "stripetype", lov_rd_stripetype, lov_wr_stripetype, 0 },
324 { "numobd", lov_rd_numobd, 0, 0 },
325 { "activeobd", lov_rd_activeobd, 0, 0 },
326 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
327 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
328 /*{ "filegroups", lprocfs_rd_filegroups, 0, 0 },*/
329 { "blocksize", lprocfs_rd_blksize, 0, 0 },
330 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
331 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
332 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
333 { "desc_uuid", lov_rd_desc_uuid, 0, 0 },
334 { "qos_prio_free",lov_rd_qos_priofree, lov_wr_qos_priofree, 0 },
335 { "qos_maxage", lov_rd_qos_maxage, lov_wr_qos_maxage, 0 },
339 static struct lprocfs_vars lprocfs_module_vars[] = {
340 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
344 struct file_operations lov_proc_target_fops = {
345 .owner = THIS_MODULE,
346 .open = lov_target_seq_open,
349 .release = lprocfs_seq_release,
352 LPROCFS_INIT_VARS(lov, lprocfs_module_vars, lprocfs_obd_vars)