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, 2013, 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/version.h>
40 #include <linux/seq_file.h>
41 #include <asm/statfs.h>
42 #include <lprocfs_status.h>
43 #include <obd_class.h>
46 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
47 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
49 static int lmv_numobd_seq_show(struct seq_file *m, void *v)
51 struct obd_device *dev = (struct obd_device *)m->private;
52 struct lmv_desc *desc;
55 desc = &dev->u.lmv.desc;
56 return seq_printf(m, "%u\n", desc->ld_tgt_count);
58 LPROC_SEQ_FOPS_RO(lmv_numobd);
60 static const char *placement_name[] = {
61 [PLACEMENT_CHAR_POLICY] = "CHAR",
62 [PLACEMENT_NID_POLICY] = "NID",
63 [PLACEMENT_INVAL_POLICY] = "INVAL"
66 static placement_policy_t placement_name2policy(char *name, int len)
70 for (i = 0; i < PLACEMENT_MAX_POLICY; i++) {
71 if (!strncmp(placement_name[i], name, len))
74 return PLACEMENT_INVAL_POLICY;
77 static const char *placement_policy2name(placement_policy_t placement)
79 LASSERT(placement < PLACEMENT_MAX_POLICY);
80 return placement_name[placement];
83 static int lmv_placement_seq_show(struct seq_file *m, void *v)
85 struct obd_device *dev = (struct obd_device *)m->private;
90 return seq_printf(m, "%s\n", placement_policy2name(lmv->lmv_placement));
93 #define MAX_POLICY_STRING_SIZE 64
95 static ssize_t lmv_placement_seq_write(struct file *file,
96 const char __user *buffer,
97 size_t count, loff_t *off)
99 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
100 char dummy[MAX_POLICY_STRING_SIZE + 1];
102 placement_policy_t policy;
105 if (copy_from_user(dummy, buffer, MAX_POLICY_STRING_SIZE))
108 LASSERT(dev != NULL);
111 if (len > MAX_POLICY_STRING_SIZE)
112 len = MAX_POLICY_STRING_SIZE;
114 if (dummy[len - 1] == '\n')
118 policy = placement_name2policy(dummy, len);
119 if (policy != PLACEMENT_INVAL_POLICY) {
120 spin_lock(&lmv->lmv_lock);
121 lmv->lmv_placement = policy;
122 spin_unlock(&lmv->lmv_lock);
124 CERROR("Invalid placement policy \"%s\"!\n", dummy);
129 LPROC_SEQ_FOPS(lmv_placement);
131 static int lmv_activeobd_seq_show(struct seq_file *m, void *v)
133 struct obd_device *dev = (struct obd_device *)m->private;
134 struct lmv_desc *desc;
136 LASSERT(dev != NULL);
137 desc = &dev->u.lmv.desc;
138 return seq_printf(m, "%u\n", desc->ld_active_tgt_count);
140 LPROC_SEQ_FOPS_RO(lmv_activeobd);
142 static int lmv_desc_uuid_seq_show(struct seq_file *m, void *v)
144 struct obd_device *dev = (struct obd_device*)m->private;
147 LASSERT(dev != NULL);
149 return 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 return seq_printf(p, "%u: %s %sACTIVE\n", tgt->ltd_idx,
180 tgt->ltd_uuid.uuid, tgt->ltd_active ? "" : "IN");
183 struct seq_operations lmv_tgt_sops = {
184 .start = lmv_tgt_seq_start,
185 .stop = lmv_tgt_seq_stop,
186 .next = lmv_tgt_seq_next,
187 .show = lmv_tgt_seq_show,
190 static int lmv_target_seq_open(struct inode *inode, struct file *file)
192 struct seq_file *seq;
195 rc = seq_open(file, &lmv_tgt_sops);
199 seq = file->private_data;
200 seq->private = PDE_DATA(inode);
204 LPROC_SEQ_FOPS_RO_TYPE(lmv, uuid);
206 struct lprocfs_seq_vars lprocfs_lmv_obd_vars[] = {
208 .fops = &lmv_numobd_fops },
209 { .name = "placement",
210 .fops = &lmv_placement_fops },
211 { .name = "activeobd",
212 .fops = &lmv_activeobd_fops },
214 .fops = &lmv_uuid_fops },
215 { .name = "desc_uuid",
216 .fops = &lmv_desc_uuid_fops },
220 struct file_operations lmv_proc_target_fops = {
221 .owner = THIS_MODULE,
222 .open = lmv_target_seq_open,
225 .release = seq_release,