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 2008 Sun Microsystems, Inc. All rights reserved
28 * Use is subject to license terms.
30 * Copyright (c) 2011,2012 Whamcloud, Inc.
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 <lprocfs_status.h>
39 #include <obd_class.h>
40 #include <linux/seq_file.h>
41 #include "lod_internal.h"
42 #include <lustre_param.h>
45 static int lod_rd_stripesize(char *page, char **start, off_t off, int count,
48 struct obd_device *dev = (struct obd_device *)data;
49 struct lod_device *lod;
52 lod = lu2lod_dev(dev->obd_lu_dev);
54 return snprintf(page, count, LPU64"\n",
55 lod->lod_desc.ld_default_stripe_size);
58 static int lod_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 lod_device *lod;
67 lod = lu2lod_dev(dev->obd_lu_dev);
68 rc = lprocfs_write_u64_helper(buffer, count, &val);
72 lod_fix_desc_stripe_size(&val);
73 lod->lod_desc.ld_default_stripe_size = val;
77 static int lod_rd_stripeoffset(char *page, char **start, off_t off, int count,
80 struct obd_device *dev = (struct obd_device *)data;
81 struct lod_device *lod;
84 lod = lu2lod_dev(dev->obd_lu_dev);
86 return snprintf(page, count, LPU64"\n",
87 lod->lod_desc.ld_default_stripe_offset);
90 static int lod_wr_stripeoffset(struct file *file, const char *buffer,
91 unsigned long count, void *data)
93 struct obd_device *dev = (struct obd_device *)data;
94 struct lod_device *lod;
99 lod = lu2lod_dev(dev->obd_lu_dev);
100 rc = lprocfs_write_u64_helper(buffer, count, &val);
104 lod->lod_desc.ld_default_stripe_offset = val;
108 static int lod_rd_stripetype(char *page, char **start, off_t off, int count,
109 int *eof, void *data)
111 struct obd_device *dev = (struct obd_device *)data;
112 struct lod_device *lod;
114 LASSERT(dev != NULL);
115 lod = lu2lod_dev(dev->obd_lu_dev);
117 return snprintf(page, count, "%u\n", lod->lod_desc.ld_pattern);
120 static int lod_wr_stripetype(struct file *file, const char *buffer,
121 unsigned long count, void *data)
123 struct obd_device *dev = (struct obd_device *)data;
124 struct lod_device *lod;
127 LASSERT(dev != NULL);
128 lod = lu2lod_dev(dev->obd_lu_dev);
129 rc = lprocfs_write_helper(buffer, count, &val);
133 lod_fix_desc_pattern(&val);
134 lod->lod_desc.ld_pattern = val;
138 static int lod_rd_stripecount(char *page, char **start, off_t off, int count,
139 int *eof, void *data)
141 struct obd_device *dev = (struct obd_device *)data;
142 struct lod_device *lod;
144 LASSERT(dev != NULL);
145 lod = lu2lod_dev(dev->obd_lu_dev);
147 return snprintf(page, count, "%d\n",
148 (__s16)(lod->lod_desc.ld_default_stripe_count + 1) - 1);
151 static int lod_wr_stripecount(struct file *file, const char *buffer,
152 unsigned long count, void *data)
154 struct obd_device *dev = (struct obd_device *)data;
155 struct lod_device *lod;
158 LASSERT(dev != NULL);
159 lod = lu2lod_dev(dev->obd_lu_dev);
160 rc = lprocfs_write_helper(buffer, count, &val);
164 lod_fix_desc_stripe_count(&val);
165 lod->lod_desc.ld_default_stripe_count = val;
169 static int lod_rd_numobd(char *page, char **start, off_t off, int count,
170 int *eof, void *data)
172 struct obd_device *dev = (struct obd_device*)data;
173 struct lod_device *lod;
175 LASSERT(dev != NULL);
176 lod = lu2lod_dev(dev->obd_lu_dev);
178 return snprintf(page, count, "%u\n", lod->lod_desc.ld_tgt_count);
182 static int lod_rd_activeobd(char *page, char **start, off_t off, int count,
183 int *eof, void *data)
185 struct obd_device* dev = (struct obd_device*)data;
186 struct lod_device *lod;
188 LASSERT(dev != NULL);
189 lod = lu2lod_dev(dev->obd_lu_dev);
191 return snprintf(page, count, "%u\n",
192 lod->lod_desc.ld_active_tgt_count);
195 static int lod_rd_desc_uuid(char *page, char **start, off_t off, int count,
196 int *eof, void *data)
198 struct obd_device *dev = (struct obd_device*) data;
199 struct lod_device *lod;
201 LASSERT(dev != NULL);
202 lod = lu2lod_dev(dev->obd_lu_dev);
204 return snprintf(page, count, "%s\n", lod->lod_desc.ld_uuid.uuid);
207 /* free priority (0-255): how badly user wants to choose empty osts */
208 static int lod_rd_qos_priofree(char *page, char **start, off_t off, int count,
209 int *eof, void *data)
211 struct obd_device *dev = (struct obd_device*) data;
212 struct lod_device *lod = lu2lod_dev(dev->obd_lu_dev);
214 LASSERT(lod != NULL);
216 return snprintf(page, count, "%d%%\n",
217 (lod->lod_qos.lq_prio_free * 100 + 255) >> 8);
220 static int lod_wr_qos_priofree(struct file *file, const char *buffer,
221 unsigned long count, void *data)
223 struct obd_device *dev = (struct obd_device *)data;
224 struct lod_device *lod;
227 LASSERT(dev != NULL);
228 lod = lu2lod_dev(dev->obd_lu_dev);
230 rc = lprocfs_write_helper(buffer, count, &val);
236 lod->lod_qos.lq_prio_free = (val << 8) / 100;
237 lod->lod_qos.lq_dirty = 1;
238 lod->lod_qos.lq_reset = 1;
242 static int lod_rd_qos_thresholdrr(char *page, char **start, off_t off,
243 int count, int *eof, void *data)
245 struct obd_device *dev = (struct obd_device*) data;
246 struct lod_device *lod;
248 LASSERT(dev != NULL);
249 lod = lu2lod_dev(dev->obd_lu_dev);
251 return snprintf(page, count, "%d%%\n",
252 (lod->lod_qos.lq_threshold_rr * 100 + 255) >> 8);
255 static int lod_wr_qos_thresholdrr(struct file *file, const char *buffer,
256 unsigned long count, void *data)
258 struct obd_device *dev = (struct obd_device *)data;
259 struct lod_device *lod;
262 LASSERT(dev != NULL);
263 lod = lu2lod_dev(dev->obd_lu_dev);
265 rc = lprocfs_write_helper(buffer, count, &val);
269 if (val > 100 || val < 0)
272 lod->lod_qos.lq_threshold_rr = (val << 8) / 100;
273 lod->lod_qos.lq_dirty = 1;
277 static int lod_rd_qos_maxage(char *page, char **start, off_t off, int count,
278 int *eof, void *data)
280 struct obd_device *dev = (struct obd_device*) data;
281 struct lod_device *lod;
283 LASSERT(dev != NULL);
284 lod = lu2lod_dev(dev->obd_lu_dev);
286 return snprintf(page, count, "%u Sec\n", lod->lod_desc.ld_qos_maxage);
289 static int lod_wr_qos_maxage(struct file *file, const char *buffer,
290 unsigned long count, void *data)
292 struct obd_device *dev = (struct obd_device *)data;
293 struct lustre_cfg_bufs bufs;
294 struct lod_device *lod;
295 struct lu_device *next;
296 struct lustre_cfg *lcfg;
300 LASSERT(dev != NULL);
301 lod = lu2lod_dev(dev->obd_lu_dev);
303 rc = lprocfs_write_helper(buffer, count, &val);
309 lod->lod_desc.ld_qos_maxage = val;
312 * propogate the value down to OSPs
314 lustre_cfg_bufs_reset(&bufs, NULL);
315 sprintf(str, "%smaxage=%d", PARAM_OSP, val);
316 lustre_cfg_bufs_set_string(&bufs, 1, str);
317 lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
319 lod_foreach_ost(lod, i) {
320 next = &OST_TGT(lod,i)->ltd_ost->dd_lu_dev;
321 rc = next->ld_ops->ldo_process_config(NULL, next, lcfg);
323 CERROR("can't set maxage on #%d: %d\n", i, rc);
326 lustre_cfg_free(lcfg);
331 static void *lod_osts_seq_start(struct seq_file *p, loff_t *pos)
333 struct obd_device *dev = p->private;
334 struct lod_device *lod;
336 LASSERT(dev != NULL);
337 lod = lu2lod_dev(dev->obd_lu_dev);
339 lod_getref(lod); /* released in lod_osts_seq_stop */
340 if (*pos >= lod->lod_ost_bitmap->size)
343 *pos = cfs_find_next_bit(lod->lod_ost_bitmap->data,
344 lod->lod_ost_bitmap->size, *pos);
345 if (*pos < lod->lod_ost_bitmap->size)
346 return OST_TGT(lod,*pos);
351 static void lod_osts_seq_stop(struct seq_file *p, void *v)
353 struct obd_device *dev = p->private;
354 struct lod_device *lod;
356 LASSERT(dev != NULL);
357 lod = lu2lod_dev(dev->obd_lu_dev);
361 static void *lod_osts_seq_next(struct seq_file *p, void *v, loff_t *pos)
363 struct obd_device *dev = p->private;
364 struct lod_device *lod = lu2lod_dev(dev->obd_lu_dev);
366 if (*pos >= lod->lod_ost_bitmap->size - 1)
369 *pos = cfs_find_next_bit(lod->lod_ost_bitmap->data,
370 lod->lod_ost_bitmap->size, *pos + 1);
371 if (*pos < lod->lod_ost_bitmap->size)
372 return OST_TGT(lod,*pos);
377 static int lod_osts_seq_show(struct seq_file *p, void *v)
379 struct obd_device *obd = p->private;
380 struct lod_ost_desc *ost_desc = v;
381 struct lod_device *lod;
383 struct dt_device *next;
384 struct obd_statfs sfs;
386 LASSERT(obd->obd_lu_dev);
387 lod = lu2lod_dev(obd->obd_lu_dev);
389 idx = ost_desc->ltd_index;
390 next = OST_TGT(lod,idx)->ltd_ost;
394 /* XXX: should be non-NULL env, but it's very expensive */
396 rc = dt_statfs(NULL, next, &sfs);
397 if (rc == -ENOTCONN) {
403 return seq_printf(p, "%d: %s %sACTIVE\n", idx,
404 obd_uuid2str(&ost_desc->ltd_uuid),
408 struct seq_operations lod_osts_sops = {
409 .start = lod_osts_seq_start,
410 .stop = lod_osts_seq_stop,
411 .next = lod_osts_seq_next,
412 .show = lod_osts_seq_show,
415 static int lod_osts_seq_open(struct inode *inode, struct file *file)
417 struct proc_dir_entry *dp = PDE(inode);
418 struct seq_file *seq;
421 LPROCFS_ENTRY_AND_CHECK(dp);
422 rc = seq_open(file, &lod_osts_sops);
428 seq = file->private_data;
429 seq->private = dp->data;
433 struct lprocfs_vars lprocfs_lod_obd_vars[] = {
434 { "uuid", lprocfs_rd_uuid, 0, 0 },
435 { "stripesize", lod_rd_stripesize, lod_wr_stripesize, 0 },
436 { "stripeoffset", lod_rd_stripeoffset, lod_wr_stripeoffset, 0 },
437 { "stripecount", lod_rd_stripecount, lod_wr_stripecount, 0 },
438 { "stripetype", lod_rd_stripetype, lod_wr_stripetype, 0 },
439 { "numobd", lod_rd_numobd, 0, 0 },
440 { "activeobd", lod_rd_activeobd, 0, 0 },
441 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
442 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
443 /*{ "filegroups", lprocfs_rd_filegroups, 0, 0 },*/
444 { "blocksize", lprocfs_rd_blksize, 0, 0 },
445 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
446 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
447 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
448 { "desc_uuid", lod_rd_desc_uuid, 0, 0 },
449 { "qos_prio_free",lod_rd_qos_priofree, lod_wr_qos_priofree, 0 },
450 { "qos_threshold_rr", lod_rd_qos_thresholdrr, lod_wr_qos_thresholdrr, 0 },
451 { "qos_maxage", lod_rd_qos_maxage, lod_wr_qos_maxage, 0 },
455 static struct lprocfs_vars lprocfs_lod_module_vars[] = {
456 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
460 void lprocfs_lod_init_vars(struct lprocfs_static_vars *lvars)
462 lvars->module_vars = lprocfs_lod_module_vars;
463 lvars->obd_vars = lprocfs_lod_obd_vars;
466 struct file_operations lod_proc_target_fops = {
467 .owner = THIS_MODULE,
468 .open = lod_osts_seq_open,
471 .release = lprocfs_seq_release,