1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_CLASS
38 #include <linux/version.h>
39 #include <asm/statfs.h>
40 #include <lprocfs_status.h>
41 #include <obd_class.h>
42 #include <linux/seq_file.h>
43 #include "lov_internal.h"
46 static int lov_rd_stripesize(char *page, char **start, off_t off, int count,
49 struct obd_device *dev = (struct obd_device *)data;
50 struct lov_desc *desc;
53 desc = &dev->u.lov.desc;
55 return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
58 static int lov_wr_stripesize(struct file *file, const char *buffer,
59 unsigned long count, void *data)
61 struct obd_device *dev = (struct obd_device *)data;
62 struct lov_desc *desc;
67 desc = &dev->u.lov.desc;
68 rc = lprocfs_write_u64_helper(buffer, count, &val);
72 lov_fix_desc_stripe_size(&val);
73 desc->ld_default_stripe_size = val;
77 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
80 struct obd_device *dev = (struct obd_device *)data;
81 struct lov_desc *desc;
84 desc = &dev->u.lov.desc;
86 return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
89 static int lov_wr_stripeoffset(struct file *file, const char *buffer,
90 unsigned long count, void *data)
92 struct obd_device *dev = (struct obd_device *)data;
93 struct lov_desc *desc;
98 desc = &dev->u.lov.desc;
99 rc = lprocfs_write_u64_helper(buffer, count, &val);
103 desc->ld_default_stripe_offset = val;
107 static int lov_rd_stripetype(char *page, char **start, off_t off, int count,
108 int *eof, void *data)
110 struct obd_device* dev = (struct obd_device*)data;
111 struct lov_desc *desc;
113 LASSERT(dev != NULL);
114 desc = &dev->u.lov.desc;
116 return snprintf(page, count, "%u\n", desc->ld_pattern);
119 static int lov_wr_stripetype(struct file *file, const char *buffer,
120 unsigned long count, void *data)
122 struct obd_device *dev = (struct obd_device *)data;
123 struct lov_desc *desc;
126 LASSERT(dev != NULL);
127 desc = &dev->u.lov.desc;
128 rc = lprocfs_write_helper(buffer, count, &val);
132 lov_fix_desc_pattern(&val);
133 desc->ld_pattern = val;
137 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
138 int *eof, void *data)
140 struct obd_device *dev = (struct obd_device *)data;
141 struct lov_desc *desc;
143 LASSERT(dev != NULL);
144 desc = &dev->u.lov.desc;
146 return snprintf(page, count, "%d\n",
147 (__s16)(desc->ld_default_stripe_count + 1) - 1);
150 static int lov_wr_stripecount(struct file *file, const char *buffer,
151 unsigned long count, void *data)
153 struct obd_device *dev = (struct obd_device *)data;
154 struct lov_desc *desc;
157 LASSERT(dev != NULL);
158 desc = &dev->u.lov.desc;
159 rc = lprocfs_write_helper(buffer, count, &val);
163 lov_fix_desc_stripe_count(&val);
164 desc->ld_default_stripe_count = val;
168 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
169 int *eof, void *data)
171 struct obd_device *dev = (struct obd_device*)data;
172 struct lov_desc *desc;
174 LASSERT(dev != NULL);
175 desc = &dev->u.lov.desc;
177 return snprintf(page, count, "%u\n", desc->ld_tgt_count);
181 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
182 int *eof, void *data)
184 struct obd_device* dev = (struct obd_device*)data;
185 struct lov_desc *desc;
187 LASSERT(dev != NULL);
188 desc = &dev->u.lov.desc;
190 return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
193 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
194 int *eof, void *data)
196 struct obd_device *dev = (struct obd_device*) data;
199 LASSERT(dev != NULL);
202 return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
205 /* free priority (0-255): how badly user wants to choose empty osts */
206 static int lov_rd_qos_priofree(char *page, char **start, off_t off, int count,
207 int *eof, void *data)
209 struct obd_device *dev = (struct obd_device*) data;
212 LASSERT(dev != NULL);
215 return snprintf(page, count, "%d%%\n",
216 (lov->lov_qos.lq_prio_free * 100) >> 8);
219 static int lov_wr_qos_priofree(struct file *file, const char *buffer,
220 unsigned long count, void *data)
222 struct obd_device *dev = (struct obd_device *)data;
225 LASSERT(dev != NULL);
228 rc = lprocfs_write_helper(buffer, count, &val);
234 lov->lov_qos.lq_prio_free = (val << 8) / 100;
235 lov->lov_qos.lq_dirty = 1;
236 lov->lov_qos.lq_reset = 1;
240 static int lov_rd_qos_thresholdrr(char *page, char **start, off_t off,
241 int count, int *eof, void *data)
243 struct obd_device *dev = (struct obd_device*) data;
246 LASSERT(dev != NULL);
249 return snprintf(page, count, "%d%%\n",
250 (lov->lov_qos.lq_threshold_rr * 100) >> 8);
253 static int lov_wr_qos_thresholdrr(struct file *file, const char *buffer,
254 unsigned long count, void *data)
256 struct obd_device *dev = (struct obd_device *)data;
259 LASSERT(dev != NULL);
262 rc = lprocfs_write_helper(buffer, count, &val);
266 if (val > 100 || val < 0)
269 lov->lov_qos.lq_threshold_rr = (val << 8) / 100;
270 lov->lov_qos.lq_dirty = 1;
274 static int lov_rd_qos_maxage(char *page, char **start, off_t off, int count,
275 int *eof, void *data)
277 struct obd_device *dev = (struct obd_device*) data;
280 LASSERT(dev != NULL);
283 return snprintf(page, count, "%u Sec\n", lov->desc.ld_qos_maxage);
286 static int lov_wr_qos_maxage(struct file *file, const char *buffer,
287 unsigned long count, void *data)
289 struct obd_device *dev = (struct obd_device *)data;
292 LASSERT(dev != NULL);
295 rc = lprocfs_write_helper(buffer, count, &val);
301 lov->desc.ld_qos_maxage = val;
305 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
307 struct obd_device *dev = p->private;
308 struct lov_obd *lov = &dev->u.lov;
310 while (*pos < lov->desc.ld_tgt_count) {
311 if (lov->lov_tgts[*pos])
312 return lov->lov_tgts[*pos];
318 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
322 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
324 struct obd_device *dev = p->private;
325 struct lov_obd *lov = &dev->u.lov;
327 while (++*pos < lov->desc.ld_tgt_count) {
328 if (lov->lov_tgts[*pos])
329 return lov->lov_tgts[*pos];
334 static int lov_tgt_seq_show(struct seq_file *p, void *v)
336 struct lov_tgt_desc *tgt = v;
337 return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
338 obd_uuid2str(&tgt->ltd_uuid),
339 tgt->ltd_active ? "" : "IN");
342 struct seq_operations lov_tgt_sops = {
343 .start = lov_tgt_seq_start,
344 .stop = lov_tgt_seq_stop,
345 .next = lov_tgt_seq_next,
346 .show = lov_tgt_seq_show,
349 static int lov_target_seq_open(struct inode *inode, struct file *file)
351 struct proc_dir_entry *dp = PDE(inode);
352 struct seq_file *seq;
355 LPROCFS_ENTRY_AND_CHECK(dp);
356 rc = seq_open(file, &lov_tgt_sops);
362 seq = file->private_data;
363 seq->private = dp->data;
367 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
368 { "uuid", lprocfs_rd_uuid, 0, 0 },
369 { "stripesize", lov_rd_stripesize, lov_wr_stripesize, 0 },
370 { "stripeoffset", lov_rd_stripeoffset, lov_wr_stripeoffset, 0 },
371 { "stripecount", lov_rd_stripecount, lov_wr_stripecount, 0 },
372 { "stripetype", lov_rd_stripetype, lov_wr_stripetype, 0 },
373 { "numobd", lov_rd_numobd, 0, 0 },
374 { "activeobd", lov_rd_activeobd, 0, 0 },
375 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
376 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
377 /*{ "filegroups", lprocfs_rd_filegroups, 0, 0 },*/
378 { "blocksize", lprocfs_rd_blksize, 0, 0 },
379 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
380 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
381 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
382 { "desc_uuid", lov_rd_desc_uuid, 0, 0 },
383 { "qos_prio_free",lov_rd_qos_priofree, lov_wr_qos_priofree, 0 },
384 { "qos_threshold_rr", lov_rd_qos_thresholdrr, lov_wr_qos_thresholdrr, 0 },
385 { "qos_maxage", lov_rd_qos_maxage, lov_wr_qos_maxage, 0 },
389 static struct lprocfs_vars lprocfs_lov_module_vars[] = {
390 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
394 void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars)
396 lvars->module_vars = lprocfs_lov_module_vars;
397 lvars->obd_vars = lprocfs_lov_obd_vars;
400 struct file_operations lov_proc_target_fops = {
401 .owner = THIS_MODULE,
402 .open = lov_target_seq_open,
405 .release = lprocfs_seq_release,