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) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_CLASS
39 #include <linux/seq_file.h>
40 #include <linux/statfs.h>
41 #include "../include/lprocfs_status.h"
42 #include "../include/obd_class.h"
43 #include "lmv_internal.h"
45 static int lmv_numobd_seq_show(struct seq_file *m, void *v)
47 struct obd_device *dev = (struct obd_device *)m->private;
48 struct lmv_desc *desc;
51 desc = &dev->u.lmv.desc;
52 seq_printf(m, "%u\n", desc->ld_tgt_count);
55 LPROC_SEQ_FOPS_RO(lmv_numobd);
57 static const char *placement_name[] = {
58 [PLACEMENT_CHAR_POLICY] = "CHAR",
59 [PLACEMENT_NID_POLICY] = "NID",
60 [PLACEMENT_INVAL_POLICY] = "INVAL"
63 static enum placement_policy placement_name2policy(char *name, int len)
67 for (i = 0; i < PLACEMENT_MAX_POLICY; i++) {
68 if (!strncmp(placement_name[i], name, len))
71 return PLACEMENT_INVAL_POLICY;
74 static const char *placement_policy2name(enum placement_policy placement)
76 LASSERT(placement < PLACEMENT_MAX_POLICY);
77 return placement_name[placement];
80 static int lmv_placement_seq_show(struct seq_file *m, void *v)
82 struct obd_device *dev = (struct obd_device *)m->private;
87 seq_printf(m, "%s\n", placement_policy2name(lmv->lmv_placement));
91 #define MAX_POLICY_STRING_SIZE 64
93 static ssize_t lmv_placement_seq_write(struct file *file,
94 const char __user *buffer,
95 size_t count, loff_t *off)
97 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
98 char dummy[MAX_POLICY_STRING_SIZE + 1];
100 enum placement_policy policy;
103 if (copy_from_user(dummy, buffer, MAX_POLICY_STRING_SIZE))
106 LASSERT(dev != NULL);
109 if (len > MAX_POLICY_STRING_SIZE)
110 len = MAX_POLICY_STRING_SIZE;
112 if (dummy[len - 1] == '\n')
116 policy = placement_name2policy(dummy, len);
117 if (policy != PLACEMENT_INVAL_POLICY) {
118 spin_lock(&lmv->lmv_lock);
119 lmv->lmv_placement = policy;
120 spin_unlock(&lmv->lmv_lock);
122 CERROR("Invalid placement policy \"%s\"!\n", dummy);
127 LPROC_SEQ_FOPS(lmv_placement);
129 static int lmv_activeobd_seq_show(struct seq_file *m, void *v)
131 struct obd_device *dev = (struct obd_device *)m->private;
132 struct lmv_desc *desc;
134 LASSERT(dev != NULL);
135 desc = &dev->u.lmv.desc;
136 seq_printf(m, "%u\n", desc->ld_active_tgt_count);
139 LPROC_SEQ_FOPS_RO(lmv_activeobd);
141 static int lmv_desc_uuid_seq_show(struct seq_file *m, void *v)
143 struct obd_device *dev = (struct obd_device *)m->private;
146 LASSERT(dev != NULL);
148 seq_printf(m, "%s\n", lmv->desc.ld_uuid.uuid);
151 LPROC_SEQ_FOPS_RO(lmv_desc_uuid);
153 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
155 struct obd_device *dev = p->private;
156 struct lmv_obd *lmv = &dev->u.lmv;
157 return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos];
160 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
165 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
167 struct obd_device *dev = p->private;
168 struct lmv_obd *lmv = &dev->u.lmv;
170 return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos];
173 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
175 struct lmv_tgt_desc *tgt = v;
179 seq_printf(p, "%d: %s %sACTIVE\n",
180 tgt->ltd_idx, tgt->ltd_uuid.uuid,
181 tgt->ltd_active ? "" : "IN");
185 static struct seq_operations lmv_tgt_sops = {
186 .start = lmv_tgt_seq_start,
187 .stop = lmv_tgt_seq_stop,
188 .next = lmv_tgt_seq_next,
189 .show = lmv_tgt_seq_show,
192 static int lmv_target_seq_open(struct inode *inode, struct file *file)
194 struct seq_file *seq;
197 rc = seq_open(file, &lmv_tgt_sops);
201 seq = file->private_data;
202 seq->private = PDE_DATA(inode);
207 LPROC_SEQ_FOPS_RO_TYPE(lmv, uuid);
209 static struct lprocfs_vars lprocfs_lmv_obd_vars[] = {
210 { "numobd", &lmv_numobd_fops, NULL, 0 },
211 { "placement", &lmv_placement_fops, NULL, 0 },
212 { "activeobd", &lmv_activeobd_fops, NULL, 0 },
213 { "uuid", &lmv_uuid_fops, NULL, 0 },
214 { "desc_uuid", &lmv_desc_uuid_fops, NULL, 0 },
218 LPROC_SEQ_FOPS_RO_TYPE(lmv, numrefs);
220 static struct lprocfs_vars lprocfs_lmv_module_vars[] = {
221 { "num_refs", &lmv_numrefs_fops, NULL, 0 },
225 struct file_operations lmv_proc_target_fops = {
226 .owner = THIS_MODULE,
227 .open = lmv_target_seq_open,
230 .release = seq_release,
233 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
235 lvars->module_vars = lprocfs_lmv_module_vars;
236 lvars->obd_vars = lprocfs_lmv_obd_vars;