4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 #define DEBUG_SUBSYSTEM S_CLASS
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"
44 static int lov_rd_stripesize(char *page, char **start, off_t off, int count,
47 struct obd_device *dev = (struct obd_device *)data;
48 struct lov_desc *desc;
51 desc = &dev->u.lov.desc;
53 return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
56 static int lov_wr_stripesize(struct file *file, const char *buffer,
57 unsigned long count, void *data)
59 struct obd_device *dev = (struct obd_device *)data;
60 struct lov_desc *desc;
65 desc = &dev->u.lov.desc;
66 rc = lprocfs_write_u64_helper(buffer, count, &val);
70 lov_fix_desc_stripe_size(&val);
71 desc->ld_default_stripe_size = val;
75 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
78 struct obd_device *dev = (struct obd_device *)data;
79 struct lov_desc *desc;
82 desc = &dev->u.lov.desc;
84 return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
87 static int lov_wr_stripeoffset(struct file *file, const char *buffer,
88 unsigned long count, void *data)
90 struct obd_device *dev = (struct obd_device *)data;
91 struct lov_desc *desc;
96 desc = &dev->u.lov.desc;
97 rc = lprocfs_write_u64_helper(buffer, count, &val);
101 desc->ld_default_stripe_offset = val;
105 static int lov_rd_stripetype(char *page, char **start, off_t off, int count,
106 int *eof, void *data)
108 struct obd_device* dev = (struct obd_device*)data;
109 struct lov_desc *desc;
111 LASSERT(dev != NULL);
112 desc = &dev->u.lov.desc;
114 return snprintf(page, count, "%u\n", desc->ld_pattern);
117 static int lov_wr_stripetype(struct file *file, const char *buffer,
118 unsigned long count, void *data)
120 struct obd_device *dev = (struct obd_device *)data;
121 struct lov_desc *desc;
124 LASSERT(dev != NULL);
125 desc = &dev->u.lov.desc;
126 rc = lprocfs_write_helper(buffer, count, &val);
130 lov_fix_desc_pattern(&val);
131 desc->ld_pattern = val;
135 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
136 int *eof, void *data)
138 struct obd_device *dev = (struct obd_device *)data;
139 struct lov_desc *desc;
141 LASSERT(dev != NULL);
142 desc = &dev->u.lov.desc;
144 return snprintf(page, count, "%d\n",
145 (__s16)(desc->ld_default_stripe_count + 1) - 1);
148 static int lov_wr_stripecount(struct file *file, const char *buffer,
149 unsigned long count, void *data)
151 struct obd_device *dev = (struct obd_device *)data;
152 struct lov_desc *desc;
155 LASSERT(dev != NULL);
156 desc = &dev->u.lov.desc;
157 rc = lprocfs_write_helper(buffer, count, &val);
161 lov_fix_desc_stripe_count(&val);
162 desc->ld_default_stripe_count = val;
166 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
167 int *eof, void *data)
169 struct obd_device *dev = (struct obd_device*)data;
170 struct lov_desc *desc;
172 LASSERT(dev != NULL);
173 desc = &dev->u.lov.desc;
175 return snprintf(page, count, "%u\n", desc->ld_tgt_count);
179 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
180 int *eof, void *data)
182 struct obd_device* dev = (struct obd_device*)data;
183 struct lov_desc *desc;
185 LASSERT(dev != NULL);
186 desc = &dev->u.lov.desc;
188 return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
191 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
192 int *eof, void *data)
194 struct obd_device *dev = (struct obd_device*) data;
197 LASSERT(dev != NULL);
200 return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
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)
207 struct obd_device *dev = (struct obd_device*) data;
210 LASSERT(dev != NULL);
213 return snprintf(page, count, "%d%%\n",
214 (lov->lov_qos.lq_prio_free * 100 + 255) >> 8);
217 static int lov_wr_qos_priofree(struct file *file, const char *buffer,
218 unsigned long count, void *data)
220 struct obd_device *dev = (struct obd_device *)data;
223 LASSERT(dev != NULL);
226 rc = lprocfs_write_helper(buffer, count, &val);
232 lov->lov_qos.lq_prio_free = (val << 8) / 100;
233 lov->lov_qos.lq_dirty = 1;
234 lov->lov_qos.lq_reset = 1;
238 static int lov_rd_qos_thresholdrr(char *page, char **start, off_t off,
239 int count, int *eof, void *data)
241 struct obd_device *dev = (struct obd_device*) data;
244 LASSERT(dev != NULL);
247 return snprintf(page, count, "%d%%\n",
248 (lov->lov_qos.lq_threshold_rr * 100 + 255) >> 8);
251 static int lov_wr_qos_thresholdrr(struct file *file, const char *buffer,
252 unsigned long count, void *data)
254 struct obd_device *dev = (struct obd_device *)data;
257 LASSERT(dev != NULL);
260 rc = lprocfs_write_helper(buffer, count, &val);
264 if (val > 100 || val < 0)
267 lov->lov_qos.lq_threshold_rr = (val << 8) / 100;
268 lov->lov_qos.lq_dirty = 1;
272 static int lov_rd_qos_maxage(char *page, char **start, off_t off, int count,
273 int *eof, void *data)
275 struct obd_device *dev = (struct obd_device*) data;
278 LASSERT(dev != NULL);
281 return snprintf(page, count, "%u Sec\n", lov->desc.ld_qos_maxage);
284 static int lov_wr_qos_maxage(struct file *file, const char *buffer,
285 unsigned long count, void *data)
287 struct obd_device *dev = (struct obd_device *)data;
290 LASSERT(dev != NULL);
293 rc = lprocfs_write_helper(buffer, count, &val);
299 lov->desc.ld_qos_maxage = val;
303 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
305 struct obd_device *dev = p->private;
306 struct lov_obd *lov = &dev->u.lov;
308 while (*pos < lov->desc.ld_tgt_count) {
309 if (lov->lov_tgts[*pos])
310 return lov->lov_tgts[*pos];
316 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
320 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
322 struct obd_device *dev = p->private;
323 struct lov_obd *lov = &dev->u.lov;
325 while (++*pos < lov->desc.ld_tgt_count) {
326 if (lov->lov_tgts[*pos])
327 return lov->lov_tgts[*pos];
332 static int lov_tgt_seq_show(struct seq_file *p, void *v)
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");
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,
347 static int lov_target_seq_open(struct inode *inode, struct file *file)
349 struct proc_dir_entry *dp = PDE(inode);
350 struct seq_file *seq;
353 LPROCFS_ENTRY_AND_CHECK(dp);
354 rc = seq_open(file, &lov_tgt_sops);
360 seq = file->private_data;
361 seq->private = dp->data;
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 },
387 static struct lprocfs_vars lprocfs_lov_module_vars[] = {
388 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
392 void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars)
394 lvars->module_vars = lprocfs_lov_module_vars;
395 lvars->obd_vars = lprocfs_lov_obd_vars;
398 struct file_operations lov_proc_target_fops = {
399 .owner = THIS_MODULE,
400 .open = lov_target_seq_open,
403 .release = lprocfs_seq_release,