]> Pileus Git - ~andy/linux/blob - drivers/staging/lustre/lustre/lmv/lproc_lmv.c
Linux 3.14
[~andy/linux] / drivers / staging / lustre / lustre / lmv / lproc_lmv.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #define DEBUG_SUBSYSTEM S_CLASS
38
39 #include <linux/seq_file.h>
40 #include <asm/statfs.h>
41 #include <lprocfs_status.h>
42 #include <obd_class.h>
43
44 static int lmv_numobd_seq_show(struct seq_file *m, void *v)
45 {
46         struct obd_device       *dev = (struct obd_device *)m->private;
47         struct lmv_desc  *desc;
48
49         LASSERT(dev != NULL);
50         desc = &dev->u.lmv.desc;
51         return seq_printf(m, "%u\n", desc->ld_tgt_count);
52 }
53 LPROC_SEQ_FOPS_RO(lmv_numobd);
54
55 static const char *placement_name[] = {
56         [PLACEMENT_CHAR_POLICY] = "CHAR",
57         [PLACEMENT_NID_POLICY]  = "NID",
58         [PLACEMENT_INVAL_POLICY]  = "INVAL"
59 };
60
61 static placement_policy_t placement_name2policy(char *name, int len)
62 {
63         int                  i;
64
65         for (i = 0; i < PLACEMENT_MAX_POLICY; i++) {
66                 if (!strncmp(placement_name[i], name, len))
67                         return i;
68         }
69         return PLACEMENT_INVAL_POLICY;
70 }
71
72 static const char *placement_policy2name(placement_policy_t placement)
73 {
74         LASSERT(placement < PLACEMENT_MAX_POLICY);
75         return placement_name[placement];
76 }
77
78 static int lmv_placement_seq_show(struct seq_file *m, void *v)
79 {
80         struct obd_device       *dev = (struct obd_device *)m->private;
81         struct lmv_obd    *lmv;
82
83         LASSERT(dev != NULL);
84         lmv = &dev->u.lmv;
85         return seq_printf(m, "%s\n", placement_policy2name(lmv->lmv_placement));
86 }
87
88 #define MAX_POLICY_STRING_SIZE 64
89
90 static ssize_t lmv_placement_seq_write(struct file *file, const char *buffer,
91                                    size_t count, loff_t *off)
92 {
93         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
94         char                 dummy[MAX_POLICY_STRING_SIZE + 1];
95         int                   len = count;
96         placement_policy_t       policy;
97         struct lmv_obd    *lmv;
98
99         if (copy_from_user(dummy, buffer, MAX_POLICY_STRING_SIZE))
100                 return -EFAULT;
101
102         LASSERT(dev != NULL);
103         lmv = &dev->u.lmv;
104
105         if (len > MAX_POLICY_STRING_SIZE)
106                 len = MAX_POLICY_STRING_SIZE;
107
108         if (dummy[len - 1] == '\n')
109                 len--;
110         dummy[len] = '\0';
111
112         policy = placement_name2policy(dummy, len);
113         if (policy != PLACEMENT_INVAL_POLICY) {
114                 spin_lock(&lmv->lmv_lock);
115                 lmv->lmv_placement = policy;
116                 spin_unlock(&lmv->lmv_lock);
117         } else {
118                 CERROR("Invalid placement policy \"%s\"!\n", dummy);
119                 return -EINVAL;
120         }
121         return count;
122 }
123 LPROC_SEQ_FOPS(lmv_placement);
124
125 static int lmv_activeobd_seq_show(struct seq_file *m, void *v)
126 {
127         struct obd_device       *dev = (struct obd_device *)m->private;
128         struct lmv_desc  *desc;
129
130         LASSERT(dev != NULL);
131         desc = &dev->u.lmv.desc;
132         return seq_printf(m, "%u\n", desc->ld_active_tgt_count);
133 }
134 LPROC_SEQ_FOPS_RO(lmv_activeobd);
135
136 static int lmv_desc_uuid_seq_show(struct seq_file *m, void *v)
137 {
138         struct obd_device *dev = (struct obd_device *)m->private;
139         struct lmv_obd    *lmv;
140
141         LASSERT(dev != NULL);
142         lmv = &dev->u.lmv;
143         return seq_printf(m, "%s\n", lmv->desc.ld_uuid.uuid);
144 }
145 LPROC_SEQ_FOPS_RO(lmv_desc_uuid);
146
147 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
148 {
149         struct obd_device       *dev = p->private;
150         struct lmv_obd    *lmv = &dev->u.lmv;
151         return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos];
152 }
153
154 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
155 {
156         return;
157 }
158
159 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
160 {
161         struct obd_device       *dev = p->private;
162         struct lmv_obd    *lmv = &dev->u.lmv;
163         ++*pos;
164         return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos];
165 }
166
167 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
168 {
169         struct lmv_tgt_desc     *tgt = v;
170
171         if (tgt == NULL)
172                 return 0;
173         return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_idx,
174                           tgt->ltd_uuid.uuid, tgt->ltd_active ? "" : "IN");
175 }
176
177 struct seq_operations lmv_tgt_sops = {
178         .start           = lmv_tgt_seq_start,
179         .stop             = lmv_tgt_seq_stop,
180         .next             = lmv_tgt_seq_next,
181         .show             = lmv_tgt_seq_show,
182 };
183
184 static int lmv_target_seq_open(struct inode *inode, struct file *file)
185 {
186         struct seq_file  *seq;
187         int                  rc;
188
189         rc = seq_open(file, &lmv_tgt_sops);
190         if (rc)
191                 return rc;
192
193         seq = file->private_data;
194         seq->private = PDE_DATA(inode);
195
196         return 0;
197 }
198
199 LPROC_SEQ_FOPS_RO_TYPE(lmv, uuid);
200
201 struct lprocfs_vars lprocfs_lmv_obd_vars[] = {
202         { "numobd",       &lmv_numobd_fops,       0, 0 },
203         { "placement",    &lmv_placement_fops,    0, 0 },
204         { "activeobd",    &lmv_activeobd_fops,    0, 0 },
205         { "uuid",         &lmv_uuid_fops,         0, 0 },
206         { "desc_uuid",    &lmv_desc_uuid_fops,    0, 0 },
207         { 0 }
208 };
209
210 LPROC_SEQ_FOPS_RO_TYPE(lmv, numrefs);
211
212 static struct lprocfs_vars lprocfs_lmv_module_vars[] = {
213         { "num_refs",      &lmv_numrefs_fops, 0, 0 },
214         { 0 }
215 };
216
217 struct file_operations lmv_proc_target_fops = {
218         .owner          = THIS_MODULE,
219         .open            = lmv_target_seq_open,
220         .read            = seq_read,
221         .llseek        = seq_lseek,
222         .release              = seq_release,
223 };
224
225 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
226 {
227         lvars->module_vars    = lprocfs_lmv_module_vars;
228         lvars->obd_vars       = lprocfs_lmv_obd_vars;
229 }